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=1796310358; b=2IOy3ioFTnH0b4410uSdGidol4IuJWhQ3gT7M37S1iNJDi5YeLs9/tgZx+uyBM9AqZwh LDRQ6dzLtqo/NmSgMPsrXYpI+sDG0uIuC6rHD43rAO2ZrYReRH3lmPgZQt0tELTaFE9wI aPh2grBE1PLjuFkLbTF6woTEKBdXqi81v2dlAqPEskssMrdItNWxvNLs+g4kF9ok6olXg sNPNEr6m5/asmxpAbNnfhbd0XhQmjPiggcexPji0biBz/ekiNddCgeXxlhu1EcOMiA6vh dialMI0gRQtpj5ye+oBHl2Zv1glNjdiPi9NsuKyn/2U7cXn37/sVdu2hYaHvXkdM2zw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310358; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Ao2fxG/uH1W3kESRfob6TWm6u/27ecM92wwDF29/0MA=; b=H6Sj/oCx66zZf8619JGD0CtK0WMNMq3S+ehjE/ayZ/qnHhv2PLBIIjBG0bwOoAYYQCRN VIyjA4wNI11lVSvx0YXBPxJuxWDT3AgkirEgp5b0rUm3n6BSB2JNZhr0W9TpxbtAI31kh U4NHHchdRAQeltJmNYQtFvl+9hnQIS3DSK/KWETjbcSB0qPak2UxnjbP7BGgFJNFYqiU/ 7gsRjZRIlaehJNIgt+0uaTgcgIz6PvuKCEfvNjMBS4YogSTfr1+Mx0IaXbqBj0OitXHDu UOCjcHIk9Fb6gG1PlWdAShjCBs/pUwv5q2sylrBD1Zvi1Zqrm/bpIR/7+8ejZs+j3MA== 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=gEwxCJhJ; 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 36C98606A333 for ; Thu, 3 Dec 2026 15:05:57 +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=gEwxCJhJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A62021F00896; Thu, 3 Dec 2026 15:05:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796310357; bh=Ao2fxG/uH1W3kESRfob6TWm6u/27ecM92wwDF29/0MA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gEwxCJhJgkFSF1jQRO/pC7C58paPpgQFRhQ/lyy3Vpv4Mk/92IA9vhbAwSHUIzkoP 1OYaFN5WMLpRUjlVjTMbAAAhli/IMG4bCMigpKCzZRiR+qDHIv5ryJOtVCEyuzfmN6 6c5XCLzML1FFFQEDaI89WWY39X77F23wlCwJ1tIP+CA41d4LmdQ5uC9Ph5jGx64rKR 9R6Mnr0DraNlZiVpFgOjEmnVZvhkBObnq5ezWGa+m1ztEeiJ/FboW6KydxGnxJ8Xd+ 21y92ElRwkhZ4v/2Il2NmYML6avsMx/FD6nGHxmfJLw39PO0Ie1irW4870PIjfw/M4 0wgXP0bX1Ucpw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path Reply-To: sashiko-reviews@lists.linux.dev To: "Shahar Shitrit" Cc: virtualization@lists.linux.dev, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261202150502.3350030-3-shshitrit@nvidia.com> References: <20261202150502.3350030-1-shshitrit@nvidia.com> <20261202150502.3350030-3-shshitrit@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:05:57 +0000 X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] virtio_pci: race and premature work cancel in vp_modern_avq_cleanup() -- commit dbe6d2ad6d64e5dddf1bddc940f5ef549b3aca9d Author: Shahar Shitrit virtio_pci: Fix sleeping under spinlock in admin command path This commit replaces the spinlock protecting the admin virtqueue with a mutex to allow GFP_KERNEL allocations in virtqueue_add_sgs(), and defers the completion callback from interrupt context to a work item. > diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_p= ci_modern.c > index 3a97d0471dd27..d5ab2c11d0842 100644 > --- a/drivers/virtio/virtio_pci_modern.c > +++ b/drivers/virtio/virtio_pci_modern.c [ ... ] > @@ -344,20 +352,27 @@ static void vp_modern_avq_activate(struct virtio_de= vice *vdev) > static void vp_modern_avq_cleanup(struct virtio_device *vdev) > { > struct virtio_pci_device *vp_dev =3D to_vp_device(vdev); > + struct virtio_pci_admin_vq *admin_vq; > struct virtio_admin_cmd *cmd; > struct virtqueue *vq; > =20 > + admin_vq =3D &vp_dev->admin_vq; > + > if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ)) > return; > =20 > - vq =3D vp_dev->admin_vq.info->vq; > + vq =3D admin_vq->info->vq; > if (!vq) > return; > =20 > + cancel_work_sync(&admin_vq->work); > + > + mutex_lock(&admin_vq->lock); > while ((cmd =3D virtqueue_detach_unused_buf(vq))) { > cmd->ret =3D -EIO; > complete(&cmd->completion); > } > + mutex_unlock(&admin_vq->lock); > } > =20 > static void vp_modern_del_vqs(struct virtio_device *vdev) [Severity: Medium] Can cancelling admin_vq->work in vp_modern_avq_cleanup() fail already completed commands with -EIO and trigger BAD_RING() in virtqueue_get_buf()? Previously, vp_modern_avq_done() drained the used ring synchronously in vring_interrupt(), so virtio_synchronize_cbs() guaranteed all used entries were consumed and vq->last_used_idx was up to date before cleanup ran. Now vp_modern_avq_done() only schedules admin_vq->work, leaving used entries in the ring (more_used(vq) =3D=3D true) when vring_interrupt() returns. If admin_vq->work is pending when vp_modern_avq_cleanup() runs, cancel_work_sync() drops the work without draining the used ring. virtqueue_detach_unused_buf() then detaches those completed buffers, clearing desc_state[id].data =3D NULL and completing the commands with -EIO, while vq->last_used_idx remains unadvanced. Because vp_modern_del_vqs() calls vp_modern_avq_cleanup() before vp_del_vqs() removes the admin virtqueue from vp_dev->virtqueues or frees its IRQ, an interrupt firing on a shared vector before vp_del_vq() is reached sees more_used(vq) =3D=3D true and reschedules admin_vq->work: CPU0 CPU1 vp_modern_del_vqs() vp_modern_avq_cleanup() cancel_work_sync(&admin_vq->work) virtqueue_detach_unused_buf(vq) desc_state[id].data =3D NULL vring_interrupt() more_used(vq) =3D=3D true vp_modern_avq_done() schedule_work(&admin_vq->work) vp_modern_avq_work() virtqueue_get_buf(vq, &len) !desc_state[id].data BAD_RING() vp_del_vqs() ... vp_del_vq() Flushing admin_vq->work (or draining the used ring) instead of cancelling it, and doing so after the admin virtqueue is unhooked from interrupt dispatch, would avoid both issues. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202150502.3350= 030-1-shshitrit@nvidia.com?part=3D2