From nobody Mon Dec 02 16:27:26 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 4Y28MM1DRzz5g53F; Mon, 02 Dec 2024 16:27:27 +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 4Y28ML6NZgz4Tds; Mon, 2 Dec 2024 16:27:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733156846; 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=eYr0q8A3Y8zIpyhc0/mKxsC3GlM1EjPvfsT1fNsKHnA=; b=GF2BsmRxIxLW9VpjNM88f2+vEqATf+bIRnA/LMGr1A99bNVw38zwGw4m9rE3TWbgV2aPNS hy9VOpohEBPIq0BKP2g1dSaLOv39ZW7BKP2YjqVXdZfhVuL9YA/yLHlK+BQJ9rdpWSsBhl 0G8GdSDg70QjVEcZA9H0RzllkveTdMSo0+zz35vwmWq6pftoRQcrlzVEcZZ8fGcpT7yfna 2BS1dI+ez0+O2YMOzBEYmGeA3h6a/mAEEkMEP3MaA8B0DWPCWwXr+m/ofcCWC8bIsWqSpH jc5NE9UnIxvlkh7SNOogepzagwD9kwGjQenufmQqxT/y6IgWofhdEyQfKv4gSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733156846; 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=eYr0q8A3Y8zIpyhc0/mKxsC3GlM1EjPvfsT1fNsKHnA=; b=fuLo1+l1HP1p566kKLHiSg5I99690L+fvwNTAeIvB8eNCbxNSZZ/SK7EptMTFZT1q1NpNg 2mfQGcDopfH1DfEuMvatMlyaustKBLOr1VtLz5WTn24lu8eYP9DxPBiqz+ebsZFIn912iD JkxMAt7/mmU0VWK9TVjAaVj/QJcbT5iCWFC0LpFUoSJcQ9HpdIidj/tkPr44runX2HO1l7 IKtqFMr3g68F3Ndn/9dwRb4Lpz3HtQeEU5S5q99dOy2FaNveRaWiPojLeIIn04FBlzDCMs pj5TSVNzqGuD++RX+HWfZL/MINp6LLclQsd6b7PC3rO2jd2kR6GspzBwg4GlIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733156846; a=rsa-sha256; cv=none; b=LupKkA4INqFqfd05n+7J28D9+RR09NOqfCEEpLt77eoaz6kcLwp7Pya+qZDL+WGClIcM4G dev5UMrogB8d+7HxSe6/PDCJflIwq+xkr1xPd47pqDn8mUj9uFLch3Fw4lTEPeR3mGpHHu Bs7EgF7DAc9dlTeyfaygp7erVcOrcHEr2djwnYRKxavhEWFwxSFED5QP+2pwI8G6Q61YHE hdSBKNiE9Igk3TuIY825SOGHTLe0kC9YDmpmfUeTewQfDyrBkyI9tRZwxsrKKVtC6Du+JO A5DMLxAuoAGAv5VovN8NSoSWZVjMXzx5Rm6zC6ke0TJHJ+wuKX9o+7Dr1D54RQ== 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 4Y28ML60sdzlR0; Mon, 2 Dec 2024 16:27:26 +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 4B2GRQHS070954; Mon, 2 Dec 2024 16:27:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B2GRQhd070951; Mon, 2 Dec 2024 16:27:26 GMT (envelope-from git) Date: Mon, 2 Dec 2024 16:27:26 GMT Message-Id: <202412021627.4B2GRQhd070951@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: 46a97b9cd6fd - main - sound: Do not access cv_waiters 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-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: 46a97b9cd6fd4415270afe4070082ae69ee21035 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=46a97b9cd6fd4415270afe4070082ae69ee21035 commit 46a97b9cd6fd4415270afe4070082ae69ee21035 Author: Christos Margiolis AuthorDate: 2024-12-02 16:26:58 +0000 Commit: Christos Margiolis CommitDate: 2024-12-02 16:26:58 +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 --- 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 218147b73db0..2d57852e036d 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 abbfc1111805..fe04898c17a5 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. */