From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796181930; b=PgltkYZpxNv7ucA1ApvHDNV23ZcCeohJ4dDHo3pD3pzCrImMR8SfQEgdHXFvRjsqQAKK r7Y4w8jxITP+Uk4qLE1I+7wQvM/FXOSookjY1gbfDb4yhkZkmWNW1Qvf0bJeSOoe3G0tH wrHaqLPlhDubitPzFiI3WyxnOybCto8ZxCLXeTwX45K4KKil3oIYG66sh9VT+4ZcsFMe+ RGXlS2EjRZLTnwBJrUGrvR5t5h3+acFvi0IUJZWqcMnrf1eLpnxThHTGrc4/XmphHarJN JMtaa3l8ZWMPp7PfJf08ZSFyfNs52OxDPBgc669j01krucUCLfzVNM9CYaJbF+PhyAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181930; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=S6GchvwYA5KjWMfcq/JfY9fjqPR76j7oktRZ+yXhOB4=; b=3pH7cXsWtLpfa52hJAyswsoZl8ZkjnBVtKZI4u3kcBZ//Ghlz0UaIWJ7kMAqcY/cC2PL C9dAZjC49Z7fNz46urCpBVet3UCp/Dr1eesWovrAluD8jPnSOsB64zxuMIjgXLMTVeNIQ BosypT7XK819TBKJ0g1VZ+u8vIFi/D5+EPfZbtkfvrmXZdf4q7Fx5SLoo5FXE5kvBELaJ 8lXB+dHVtylpDn6cLScpbpmIACDYxaAfxcwHiTFA73/cJy4T5opK5xqnPNvb88YRUGLD+ lbzzcTGoFsF12bsGSDzNOevRpkxrUDLzAezCHIfqRmoJ3Zt0I7Xn6MszfUeTaccrKtg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MWE4xWWy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34E34606A31A for ; Wed, 2 Dec 2026 03:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MWE4xWWy Received: by smtp.kernel.org (Postfix) with ESMTPSA id F39141F00893; Wed, 2 Dec 2026 03:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181930; bh=S6GchvwYA5KjWMfcq/JfY9fjqPR76j7oktRZ+yXhOB4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=MWE4xWWya2YxxRmakN8Cz/KTYax1zoEuSX3B92n5Q8+bk1ULXFFwQ33j4rQu11m49 U7o22TnyxiY1M5t0wulcWO4uN9KkjYQ5Al9NVlptpX30bAppxRxqzS6Q3kZQP5pSmS c2IphbzgjLbABS5DTXswQgZ/1GhkMxNg085u1eZNgsD4qRu4c9YVHk0memcymq9JDm rRRyDM2a4jDWIR4RJsKsitrdH/tarAvDFurYI4jxjG2JSxeje2P7zzF5xitR//zG7X qsHtzi+/JmzGWXi3X2i6v3Lu+PfLOnvomjgI6tZeT/zP2csNZI21huwbBG2tLoUpZZ gxi2hzCksUrZQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: vx: serialize pipe lifecycle against the threaded IRQ pipe walker Reply-To: sashiko-reviews@lists.linux.dev To: "Hanxiang Xu" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202101006.1-1-xuhx@hust.edu.cn> References: <20261202101006.1-1-xuhx@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:25:29 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] ALSA: vx: pipe->prepared not cleared for prepared streams on hw_free or close - [High] ALSA: vx: dangling pipe->substream in vx_pcm_playback_close() with monitoring -- commit 06ea28a410c475a5af72a771d6f540168a3d3d78 Author: Hanxiang Xu ALSA: vx: serialize pipe lifecycle against the threaded IRQ pipe walker This commit adds chip->pcm_lock to serialize pipe allocation, freeing, and threaded IRQ updates, and clears pipe->prepared on trigger STOP and SUSPEND. > diff --git a/sound/drivers/vx/vx_pcm.c b/sound/drivers/vx/vx_pcm.c > index d9b94580704aa..8d4fdf6c153b7 100644 > --- a/sound/drivers/vx/vx_pcm.c > +++ b/sound/drivers/vx/vx_pcm.c [ ... ] > @@ -564,6 +565,7 @@ static int vx_pcm_playback_close(struct snd_pcm_subst= ream *subs) > =20 > pipe =3D subs->runtime->private_data; > =20 > + guard(mutex)(&chip->pcm_lock); > if (--pipe->references =3D=3D 0) { > chip->playback_pipes[pipe->number] =3D NULL; > vx_free_pipe(chip, pipe); [Severity: High] When a playback pipe is shared with capture hardware monitoring, does closing the playback substream leave a detached pipe->substream pointer published in chip->playback_pipes[]? When capture is open with monitoring enabled, pipe->references is 2 once playback opens and sets pipe->substream =3D subs. If playback closes while capture stays open, --pipe->references is 1, so pipe remains in chip->playback_pipes[pipe->number] with pipe->substream still pointing at subs. snd_pcm_release_substream() then calls snd_pcm_detach_substream(), which frees subs->runtime and sets subs->runtime =3D NULL, so a subsequent vx_pcm_update_intr() passing pipe && pipe->substream will dereference a NULL subs->runtime in vx_pcm_playback_transfer(). Clearing pipe->substream =3D NULL and pipe->prepared =3D 0 under chip->pcm_= lock unconditionally in vx_pcm_playback_close() would avoid this. > @@ -749,6 +751,7 @@ static int vx_pcm_trigger(struct snd_pcm_substream *s= ubs, int cmd) > vx_stop_pipe(chip, pipe); > vx_stop_stream(chip, pipe); > chip->pcm_running--; > + pipe->prepared =3D 0; > pipe->running =3D 0; > break; > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: [Severity: High] Can vx_pcm_update_intr() still read from a freed or NULL runtime->dma_area when a stream in SNDRV_PCM_STATE_PREPARED is freed via hw_free or closed? In the ALSA PCM core, snd_pcm_do_stop() only invokes ops->trigger(SNDRV_PCM_TRIGGER_STOP) when snd_pcm_running(substream) is true: sound/core/pcm_native.c:snd_pcm_do_stop() { if (substream->runtime->trigger_master =3D=3D substream && snd_pcm_running(substream)) { substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); substream->runtime->stop_operating =3D true; } return 0; /* unconditionally stop all substreams */ } If a stream was stopped and re-prepared (or if SNDRV_PCM_TRIGGER_START failed after vx_pcm_playback_transfer() queued chunks), pipe->prepared is 1 while the stream is in SNDRV_PCM_STATE_PREPARED. On close (or SNDRV_PCM_IOCTL_HW_FREE), do_hw_free() frees the managed vmalloc runtime->dma_area buffer before vx_pcm_playback_close() takes chip->pcm_lock: CPU0 CPU1 (IRQ thread) snd_pcm_release_substream() snd_pcm_drop() /* not running: trigger skipped */ do_hw_free() snd_pcm_lib_free_pages() /* vfrees runtime->dma_area */ vx_pcm_update_intr() lock(&chip->pcm_lock) vx_pcm_playback_transfer() /* pipe->prepared =3D=3D 1 */ vx_pseudo_dma_write() /* reads freed dma_area */ vx_pcm_playback_close() lock(&chip->pcm_lock) Providing an .hw_free callback that clears pipe->prepared under chip->pcm_lock (or gating transfers in vx_pcm_update_intr() on pipe->running) would prevent vx_pcm_playback_transfer() from touching runtime->dma_area once hw_free begins. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202101006.1-1-= xuhx@hust.edu.cn?part=3D1