From nobody Fri Apr 05 10:38:25 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V9w1s4zsKz5G9t5; Fri, 5 Apr 2024 10:38:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V9w1s3msZz4j5G; Fri, 5 Apr 2024 10:38:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712313505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ST0Lj5nT/vulx9C6VLUzwYR5h7KecNas7MlDGmEvM0U=; b=MkMIO58XSmpmk/MVDtW9A+bb8/cClCYbz4nS37p2LQwjDKN3uwKZpxu8ItMbbcsFoqvA3t aCF2BZJBIQzo7YL6oD5DPPUHjKh77X5CioILC8FaNMwIAIBUPgY8AbEtinhCe/h+hUHR64 eJBPWMzmdOyyvWSEOeKBgR8Dre6NB1JW4g6G/2Rkr4q7eTizd39lUvK9T3s+a/3gG7frq+ igcQhRoPWDvUZVdMDotQSd8Z9b+uETbuHt1/+Z1/o+ZBjwcZXFer9j/3+iyxt2TdRnN+3R G/W+shhPxJmh/DJBR61Jw/sk1/kZ7VDuslaLbEyVzq+UiAFmhkpGROPnCfewgA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712313505; a=rsa-sha256; cv=none; b=mul7+q1ZjdJmL4+smB9bJ28+IOhjPHVzHhY1qkusMD4nV5q/phSSSrn9862H+jRjhbG4BS tHIpkmC/QHqhTrQ6TSG7h8FE6YF/y8v2lqOlGhAbQvnKUPtAYur3Bl+rO8L6z3WgkzCXMF pwt6ecsGrwgor85YUUkTLwvJ7OEI6dh2AMt2dyJNZIJWNSf+khB2ZZNSy+O5kvgLQr87La D5wXSOP78pgYrDgFacgyQEXwWUT3IMAKMBXG1SOdZZKY9Mu6mZvnqLSjxWrXrPfVvYcLDU I7svzglSidkGJi2QD+aOKoMGL/glOvN2z0tAU7RFFt9bi5YYn/FxOSavIGYrcw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712313505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ST0Lj5nT/vulx9C6VLUzwYR5h7KecNas7MlDGmEvM0U=; b=TdI0Bg/DgT+wV01x+crom7P//dF31cMoEJwSAQ5wI2/xBKOXq13BD5SHvaqyiThXbHXqZY I5VQ+0QjNka70sCQgf8gUJoFnZND0jx2RGxkMLGXHixV/WN42/cEEeCIiW8MTiz87gWBU6 MPUJ82n3Ozm+PLq1WeM8wZ4rxsqED9Es3f6PKg+JLOkP9T4DuKVL+0jGscSt+4v8e2vkEa vn4Qx2PANKLXFkjpwSHvG8i1OtHnWXvZ/HHqUfI6iBF6YlRIS4cT70HqACVSJsaTc03R0c nWFTomGbPQ7mx7ntgS/96j41n+qwE6cCc1ZrIOVYLWn1SRnMOFJOHD925nuUQw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4V9w1s3PBtzwyY; Fri, 5 Apr 2024 10:38:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 435AcPkW003034; Fri, 5 Apr 2024 10:38:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 435AcPjY003031; Fri, 5 Apr 2024 10:38:25 GMT (envelope-from git) Date: Fri, 5 Apr 2024 10:38:25 GMT Message-Id: <202404051038.435AcPjY003031@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 365067e98e4e - main - Revert "sound: Implement asynchronous device detach" List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 365067e98e4e9deba18070f5ebd4e9eee7149b6d Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=365067e98e4e9deba18070f5ebd4e9eee7149b6d commit 365067e98e4e9deba18070f5ebd4e9eee7149b6d Author: Christos Margiolis AuthorDate: 2024-04-05 10:27:47 +0000 Commit: Christos Margiolis CommitDate: 2024-04-05 10:33:23 +0000 Revert "sound: Implement asynchronous device detach" This reverts commit 9eff58c6d52b66eb8abe7f724dabcd804a566df4. We are reverting dc831e93bad6 ("sound: Get rid of snd_clone and use DEVFS_CDEVPRIV(9)"), so revert this commit as well since it depends dc831e93bad6. --- share/man/man4/snd_uaudio.4 | 11 ++++++++++- sys/dev/sound/pcm/dsp.c | 2 +- sys/dev/sound/pcm/mixer.c | 11 +++++++++++ sys/dev/sound/pcm/sound.c | 24 ++++++++++++++---------- sys/dev/sound/usb/uaudio.c | 13 ++++++++++--- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/share/man/man4/snd_uaudio.4 b/share/man/man4/snd_uaudio.4 index 6e2509b8f2ac..b6a6c06a2312 100644 --- a/share/man/man4/snd_uaudio.4 +++ b/share/man/man4/snd_uaudio.4 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd March 26, 2024 +.Dd January 29, 2024 .Dt SND_UAUDIO 4 .Os .Sh NAME @@ -156,6 +156,15 @@ and modified for by .An Hiten Pandya Aq Mt hmp@FreeBSD.org . .Sh BUGS +The PCM framework in +.Fx +only supports synchronous device detach. +That means all mixer and DSP character devices belonging to a given +USB audio device must be closed when receiving an error on a DSP read, +a DSP write or a DSP IOCTL request. +Else the USB audio driver will wait for this to happen, preventing +enumeration of new devices on the parenting USB controller. +.Pp Some USB audio devices might refuse to work properly unless the sample rate is configured the same for both recording and playback, even if only simplex is used. diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index 754f09c7199e..b9693908da43 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -295,7 +295,7 @@ dsp_close(void *data) d = priv->sc; /* At this point pcm_unregister() will destroy all channels anyway. */ - if (PCM_DETACHING(d)) + if (!PCM_REGISTERED(d)) goto skip; PCM_GIANT_ENTER(d); diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c index cc8cf5b1ceea..ee1ed11a8ed0 100644 --- a/sys/dev/sound/pcm/mixer.c +++ b/sys/dev/sound/pcm/mixer.c @@ -817,6 +817,17 @@ mixer_uninit(device_t dev) KASSERT(m->type == MIXER_TYPE_PRIMARY, ("%s(): illegal mixer type=%d", __func__, m->type)); + snd_mtxlock(m->lock); + + if (m->busy) { + snd_mtxunlock(m->lock); + return EBUSY; + } + + /* destroy dev can sleep --hps */ + + snd_mtxunlock(m->lock); + pdev->si_drv1 = NULL; destroy_dev(pdev); diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c index 1517126210c4..53cde49c4905 100644 --- a/sys/dev/sound/pcm/sound.c +++ b/sys/dev/sound/pcm/sound.c @@ -1001,22 +1001,26 @@ pcm_unregister(device_t dev) CHN_FOREACH(ch, d, channels.pcm) { CHN_LOCK(ch); - if (ch->flags & CHN_F_SLEEPING) { - /* - * We are detaching, so do not wait for the timeout in - * chn_read()/chn_write(). Wake up the thread and kill - * the channel immediately. - */ - CHN_BROADCAST(&ch->intr_cv); - ch->flags |= CHN_F_DEAD; + if (ch->refcount > 0) { + device_printf(dev, + "unregister: channel %s busy (pid %d)\n", + ch->name, ch->pid); + CHN_UNLOCK(ch); + PCM_RELEASE_QUICK(d); + return (EBUSY); } - chn_abort(ch); CHN_UNLOCK(ch); } dsp_destroy_dev(dev); - (void)mixer_uninit(dev); + if (mixer_uninit(dev) == EBUSY) { + device_printf(dev, "unregister: mixer busy\n"); + PCM_LOCK(d); + PCM_RELEASE(d); + PCM_UNLOCK(d); + return (EBUSY); + } /* remove /dev/sndstat entry first */ sndstat_unregister(dev); diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c index 2351c2522021..5d7396c527e0 100644 --- a/sys/dev/sound/usb/uaudio.c +++ b/sys/dev/sound/usb/uaudio.c @@ -1255,13 +1255,20 @@ uaudio_detach_sub(device_t dev) unsigned i = uaudio_get_child_index_by_dev(sc, dev); int error = 0; +repeat: if (sc->sc_child[i].pcm_registered) { error = pcm_unregister(dev); - } else if (sc->sc_child[i].mixer_init) { - error = mixer_uninit(dev); + } else { + if (sc->sc_child[i].mixer_init) + error = mixer_uninit(dev); } - return (error); + if (error) { + device_printf(dev, "Waiting for sound application to exit!\n"); + usb_pause_mtx(NULL, 2 * hz); + goto repeat; /* try again */ + } + return (0); /* success */ } static int