From nobody Wed Dec 04 12:04:17 2024 X-Original-To: dev-commits-src-all@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 4Y3GQr4q1Fz5gS3J; Wed, 04 Dec 2024 12:04:20 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y3GQn5W6Sz46mK; Wed, 4 Dec 2024 12:04:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733313857; 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=E5uRFkDwzhwvpcoUJRZloPy7L8aZteA3zsgjGHhTCfk=; b=N5L+vrudw2tI5N2I1Zy98v5qLXQRsgMaM6KBxodr7uyxQsKGgN+ipqZTTKlFaUjaWwwkTQ hUnUMa1fMGQHrfTSyeQvk1V1sojHf/TNPMCnNvV4njd/YWfnoojOzl/gZH8ahwRzVbGSX5 SOoyphnNCjHSMZeG9UUpc7d6TOUhqwkLQSK2xHSt3l9Bc+SjypqRxvQ9Tj5/e7sFRmbH50 e+0OEEGrzvP4Vcj6W04PItLXzisJBZUAz0Rk1en6RoWeVfHGc9ZtwyFGnGfJSyyQQamUBV /ysagtI9ecv1Y9OHfrXJBi/VEQx1jODfDqXV/g4vTpEqUVoOknS8hU8RM7mJIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733313857; 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=E5uRFkDwzhwvpcoUJRZloPy7L8aZteA3zsgjGHhTCfk=; b=noSmI4ilgnDBX65j5fDXE8+L6JznngWLUVxh6pNnbijKjP/2tqv0R+YLUKRdPsd3VBkiu0 +wGVXdE+KImFLv072vJUkLafWtVtG5in3/0QF6nM7fi5VaH9GE4XjaIxeeKZH3/IUT4C46 lYfF+mADnZWUhEgBb/Fto4Zc+kGEGQi/qi4i5tBWCiAIZcT4YbUjkCohH8+p3M0lVrukXz 5PH4sukp8XDWaR2UTotvyoLk9xhBRURDaYYcw8ScKjiSvGkCtgVMA63QDIt+CnUOyQc1lR lEmImDw710V8DtcSLyjtHXxMvltZAbe1KRtc5LjMp/2r+VnkOhhQIBctRGJMjw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733313857; a=rsa-sha256; cv=none; b=hi39hZHIlztJIoTCRalaKY3tLZZW/09nBHKWMrkfXrdkbrzm0/aB9RzK2RvsTj3rw3nkeY RXDvOMA3SIKSw7+Ic4lcFt/SupILs9dL5piTKr+xpokd9IHPlSJ3hqCvG2LNkw4fDZtuKj F4vS+9zohMVecx8ldU2s5H9vQY0lcVai6rjy+z2eCakEuZeBgEHDcv4GvpdxwL2Iml8Vg0 1cMvNiwUHJ+30iwlU68W36X3JdqkucuA+wUsU9Nj5C39+UTZJvMCOvY2AKQ94H/Zw55mbB lRe8Y8x+jBMzuLBpptlDRmrNxui5p30nJXHOZbY4ia6N8ybjFHRtRdXKy8Jzhw== 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 4Y3GQn4SRWz16Gs; Wed, 4 Dec 2024 12:04:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4B4C4HRi049951; Wed, 4 Dec 2024 12:04:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B4C4Htf049948; Wed, 4 Dec 2024 12:04:17 GMT (envelope-from git) Date: Wed, 4 Dec 2024 12:04:17 GMT Message-Id: <202412041204.4B4C4Htf049948@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 134a275eea7a - stable/14 - sound: Do not access cv_waiters List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 134a275eea7a2edf34b4b98cf6f382d7a3618597 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=134a275eea7a2edf34b4b98cf6f382d7a3618597 commit 134a275eea7a2edf34b4b98cf6f382d7a3618597 Author: Christos Margiolis AuthorDate: 2024-12-02 16:26:58 +0000 Commit: Christos Margiolis CommitDate: 2024-12-04 12:03:36 +0000 sound: Do not access cv_waiters Remove uses of cv_waiters in PCM_RELEASE and CHN_BROADCAST, and also use a counter around cv_timedwait_sig() in chn_sleep(), which is checked in pcm_killchans(), as opposed to reading cv_waiters directly, which is a layering violation. While here, move CHN_BROADCAST below the channel lock operations. Reported by: avg, jhb, markj Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch, avg Differential Revision: https://reviews.freebsd.org/D47780 (cherry picked from commit 46a97b9cd6fd4415270afe4070082ae69ee21035) --- sys/dev/sound/pcm/channel.c | 2 ++ sys/dev/sound/pcm/channel.h | 9 ++++----- sys/dev/sound/pcm/sound.c | 4 ++-- sys/dev/sound/pcm/sound.h | 13 ++----------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index 728284b055e5..925a82bb170f 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -329,7 +329,9 @@ chn_sleep(struct pcm_channel *c, int timeout) if (c->flags & CHN_F_DEAD) return (EINVAL); + c->sleeping++; ret = cv_timedwait_sig(&c->intr_cv, c->lock, timeout); + c->sleeping--; return ((c->flags & CHN_F_DEAD) ? EINVAL : ret); } diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h index 47089aca0745..67f5019f4727 100644 --- a/sys/dev/sound/pcm/channel.h +++ b/sys/dev/sound/pcm/channel.h @@ -117,6 +117,8 @@ struct pcm_channel { * lock. */ unsigned int inprog; + /* Incrememnt/decrement around cv_timedwait_sig() in chn_sleep(). */ + unsigned int sleeping; /** * Special channel operations should examine @c inprog after acquiring * lock. If zero, operations may continue. Else, thread should @@ -242,11 +244,6 @@ struct pcm_channel { (x)->parentchannel->bufhard != NULL) ? \ (x)->parentchannel->bufhard : (y)) -#define CHN_BROADCAST(x) do { \ - if ((x)->cv_waiters != 0) \ - cv_broadcastpri(x, PRIBIO); \ -} while (0) - #include "channel_if.h" int chn_reinit(struct pcm_channel *c); @@ -320,6 +317,8 @@ int chn_getpeaks(struct pcm_channel *c, int *lpeak, int *rpeak); #define CHN_LOCKASSERT(c) mtx_assert((c)->lock, MA_OWNED) #define CHN_UNLOCKASSERT(c) mtx_assert((c)->lock, MA_NOTOWNED) +#define CHN_BROADCAST(x) cv_broadcastpri(x, PRIBIO) + int snd_fmtvalid(uint32_t fmt, uint32_t *fmtlist); uint32_t snd_str2afmt(const char *); diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c index 761c505fd402..b8f4efea8789 100644 --- a/sys/dev/sound/pcm/sound.c +++ b/sys/dev/sound/pcm/sound.c @@ -221,8 +221,8 @@ pcm_killchans(struct snddev_info *d) /* Make sure all channels are stopped. */ CHN_FOREACH(ch, d, channels.pcm) { CHN_LOCK(ch); - if (ch->intr_cv.cv_waiters == 0 && CHN_STOPPED(ch) && - ch->inprog == 0) { + if (ch->inprog == 0 && ch->sleeping == 0 && + CHN_STOPPED(ch)) { CHN_UNLOCK(ch); continue; } diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h index 65e8c3002026..59d9930712b3 100644 --- a/sys/dev/sound/pcm/sound.h +++ b/sys/dev/sound/pcm/sound.h @@ -359,15 +359,7 @@ int sound_oss_card_info(oss_card_info *); __func__, __LINE__); \ if ((x)->flags & SD_F_BUSY) { \ (x)->flags &= ~SD_F_BUSY; \ - if ((x)->cv.cv_waiters != 0) { \ - if ((x)->cv.cv_waiters > 1 && snd_verbose > 3) \ - device_printf((x)->dev, \ - "%s(%d): [PCM RELEASE] " \ - "cv_waiters=%d > 1!\n", \ - __func__, __LINE__, \ - (x)->cv.cv_waiters); \ - cv_broadcast(&(x)->cv); \ - } \ + cv_broadcast(&(x)->cv); \ } else \ panic("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ __func__, __LINE__); \ @@ -459,8 +451,7 @@ int sound_oss_card_info(oss_card_info *); ("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ __func__, __LINE__)); \ (x)->flags &= ~SD_F_BUSY; \ - if ((x)->cv.cv_waiters != 0) \ - cv_broadcast(&(x)->cv); \ + cv_broadcast(&(x)->cv); \ } while (0) /* Quick version, for shorter path. */