From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.61 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796135251; b=vZ8bFsqAVjky1ga3R6sKlNgLGbwEgBEjHMmiu7yKk7m3HQ4csQFByzvtFzTN14jBQRTD Pd2o0gmjwp1CnhS9F9sFbb6drt2qxBNaQdhoXAaxKF1aCWxJC/AbFGyWsLMKVvv7q/1yN fIkDvtmBCN3OwGkiB576TATYH2qV7abMOoVk4ADtk7wra+YKb8yTjtimHB4qtOWCvratl vNFgtiWTtKYW9gbaWcrS/sevH0C1NjoviSirCSG2tO3sLMByB4BXQaoBBCMZWf+hMG5ge eUg5qY8KzeN/ZK+W1TCO/mkVXKNxqAnHZypGJl6KVyqiq39/ut09jaruSGhdWLaFDEw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135251; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=4Kg4g2sQy0b1jPo8xTtiKAdvnJPmTtbY1ARqp9pWMK8=; b=CXOfzRU5YKmHcUKOYr/C3lUQFIOlCXxuqzgQl7MHZXg7UfWWLPB3J83iMiVUszoWhUFO bzvqWnPsaVZQ5jBNmwdZWOoI4TQgPTruRGWsSTbfMnZAFU2XF1en2gb1Qb6uawro6Aq6n 2A1YvfGNwzUOlcct3uEsZrUaIfMaDrUs3Fn3wtTmjUBjook9M22Jx+bHDAxSOk/KEGQFs Gbh5SMiM8Hmws/Q8rW6wnV3VMQYizO6tgxG9PqRGUXlqFxPSKdQsbSGGpa68rN6K9fkOb uKRkVQvvL+xITcUgaeLBOohzdE6E5+BaTSfeZXZdUNR2y6zvH46i4LlkjBi4fKiSd0Q== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=MlHAeNks; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.61 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012061.outbound.protection.outlook.com [40.93.195.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF49B606A32D for ; Tue, 1 Dec 2026 14:27:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF49B606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=MlHAeNks ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zNXbe4Eli+CY7FMapkkGBWUwWn/EUBN4F3paFARu8lbOr9l5m0aisDOu1MuoO9T0ctpxTj0kws/DSeP8WlgLBqoKP3GXMVgiWN9sRlaLWKUyrCH0SRWCkIcK0RmGstwtJ+dwDH7vB4jxS1P2HG8VFfAIV4qfejZU6tYrfvLfXmIPZGtF+6UTNYSM8nKhn1JRHVKNFstndQmQcONFCqKwfk8P8TLUVa64yHQjoiZYpIM8a7VFvXVoYSDRMGce6QQEn9udkhmduh0jtHvCDaJTGCSwFuRCWN384wCoUTzQ8r6J518j3nDVaNG0hsPTdso2lTq4Asa7WmgIFrDMJyZiKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4Kg4g2sQy0b1jPo8xTtiKAdvnJPmTtbY1ARqp9pWMK8=; b=RN9Vw/euHuzuoEmmsPDPuoRZzLSHukgPVHDw8hGbj2Z7uxaDLCemZSXhRAl6a9ZqcXOTDGkzGohPTLoJCdZMyYIethLfjUcV8dMYqw7TscpWRd7y2n+FDq7K9bKyWBskvSGSn+DUVbqbwJwSAd+od4rQBGu8egI0RCoc3y/q1kWyy2xNzY+04cpoAoqB+WXPwa7YPfs+0ZdVA1sLaD6Agc+pr0kwUcrHCHMs62gTY6QtjyUy+kE7dDU+cvF/09kuRza5zSegRPv7E35oTp/iFRNpA5fhtOgm+v+AnNjcNZ/CNBcOmFQ+2IAtVRRqusW4E9xRmJDaUH1VPMBz/uSAyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Kg4g2sQy0b1jPo8xTtiKAdvnJPmTtbY1ARqp9pWMK8=; b=MlHAeNks+39SoSEtqztCJ5Qi1qgZYUb2QXzu4gBhe49Cix6zQr8a/5pFj3C/poHMkNBiLYCT65sCXISP08Dt65hABNhfwL3SCwuz0ipsaS2710pQH8d1ES/gfdZeg5BIA5EuROqKvV9vI9tWu+8hqGKE4UmiKo4gILMhvL2hOVVhCiFAZfsrz4+BIz+vo8n8l7Ueb3oCERIo8eDUk9Kj7xHng8fLZ4HuhVi6XKSMgrpeDKo6v5bK/i4oK6iIn3g/OhznqRlhapq9BLh+dSzu4vFe9ql6DVT5wDNrCAUKudvHdbvrwv+L1sFbMfKq7t+mI16qwmVrFWBCOndzQqT3jw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5505.namprd12.prod.outlook.com (2603:10b6:208:1ce::7) by MN6PR12MB8590.namprd12.prod.outlook.com (2603:10b6:208:47c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 14:27:18 +0000 Received: from BL0PR12MB5505.namprd12.prod.outlook.com ([fe80::9329:96cf:507a:eb21]) by BL0PR12MB5505.namprd12.prod.outlook.com ([fe80::9329:96cf:507a:eb21%5]) with mapi id 15.21.0688.009; Tue, 1 Dec 2026 14:27:18 +0000 Message-ID: <0fd021c9-a3ee-4f20-a547-f9d5106eaaf2@nvidia.com> Date: Tue, 1 Dec 2026 16:27:11 +0200 User-Agent: Mozilla Thunderbird Subject: Re: [net-next,v23,02/14] virtio_pci: Fix sleeping under spinlock in admin command path To: netdev-bot+sashiko@kernel.org Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, virtualization@lists.linux.dev, parav@nvidia.com, yohadt@nvidia.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com, kuba@kernel.org, andrew+netdev@lunn.ch, edumazet@google.com, danielj@nvidia.com References: <20260831161109.2999926-3-shshitrit@nvidia.com> <178835473723.3394541.8002424749068111766@kernel.org> Content-Language: en-US From: Shahar Shitrit In-Reply-To: <178835473723.3394541.8002424749068111766@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: TL2P290CA0018.ISRP290.PROD.OUTLOOK.COM (2603:1096:950:3::17) To BL0PR12MB5505.namprd12.prod.outlook.com (2603:10b6:208:1ce::7) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR12MB5505:EE_|MN6PR12MB8590:EE_ X-MS-Office365-Filtering-Correlation-Id: 20529d9b-1be9-444c-185c-08df4fb733d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|1800799024|7416014|376014|366016|6133799003|22082099003|18002099003|3023799007|56012099006|5023799004|11063799006|4143699003|261022105027099003|261022075727099003|261026121527099003|261026140227099003|261028144727099003|261102123227099003|261009223027099003|261021123027099003|261021121427099003|10067099003; X-Microsoft-Antispam-Message-Info: NeFs8beBG7VV1muPCj/cwivSVfkUrSUl0ua9IiOS/XTKgjhGswcxfXeYXc0jz1Xr+p/ozHpjugMyJrDoLtCbpUrMDJLzw+DYN+Ubv43fjY7sWzG4wyKEewn2AVHl+O9j99La8tQq/0Sd20ZDQURnbuLHgE56UWvmfJEwe2tCh9s9ShZunzdI9yknGaksmVWeIc/bySHoBNqNw94HGDPi00jG5GNSTzHPG1x1T5NbYAyf7NhA3IGpJIiNorW+Sbpaww+45pX35QiB6dMAq9Q0F3FXZldn85Sdgix7ANJIkN3IcYbjN/ZLV/k8/t5/ZYz7tAgZEz0PZYBn7fbVe0NuA/6AXV1cs0v0YIsswz1X2u8GzQmiCLMTmaEFHLXYxweeY333ldw28b8DV3YW3Pjg8YL5NO0nUHp2kgRkEvPwB5hLyUz1mNGE/UEeVz6QJT6LtqS1yU5UVoxhcpja/6zR/2cgZacXkxS8lJreLnU6+/Mz6hfhWm63mt+/WBBi1EPGHIi9yt47lJx8oOGPWdjr4Rp2WD21EoBvh9+gud8mF7qIPUfqhUyum8Ye3EJ5pW162w3aeWSGPsuWiW2uqxTR5d2rj6gTzVJP27hi+OGF/75N7kyGMoLUZmfQq25kU3AT8zssr3aZAzgHkbXhwcTEEfoS6EPNfT8EK4aNk7Eee3I= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5505.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(1800799024)(7416014)(376014)(366016)(6133799003)(22082099003)(18002099003)(3023799007)(56012099006)(5023799004)(11063799006)(4143699003)(261022105027099003)(261022075727099003)(261026121527099003)(261026140227099003)(261028144727099003)(261102123227099003)(261009223027099003)(261021123027099003)(261021121427099003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WVZJUmlRN2lEV3VmeUd0YTg1ZXVMVVUyQUE5czlRczMxK3MrR2ZKUWhUSG41?= =?utf-8?B?ZUhMbDVxdXhtWVIyelVPSzRtRTlFUEVabDVLbWJwa0JDbXFzSXFtUHZMZ3ZJ?= =?utf-8?B?aUlWOFFMaDhCMGIydXYrelRQc3pJOGp3dGsvb1NwT0JHckE0Ti90NXl4Qzl6?= =?utf-8?B?SEg0RDdIdXY1NTdrbjRBTF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TFBjZWJYcGlCbFVH?= =?utf-8?B?emF6bmRJeUdBaXBXZ1pacXdaaCsvcUtvQUhxaUtrMzVUTVhwa216SERBdmtn?= =?utf-8?B?dklWeXdSUU5RK28xNVFiVG9NTnFuWm5wSytsRkZZSGZXVGh1VEswVDdtY0FJ?= =?utf-8?B?cWNrVXM0elRjTjRWSmY0TW42aEFvVWhiYVlxRVFCNjFzU01ra29ZQVcrZHlo?= =?utf-8?B?SldmMDBLRWxBNmpMNnNBVklDMHFFczZ5Nm9mc3VTbnJ4QW0rMVhHZERWcTYz?= =?utf-8?B?c0M5N0dqSDYvamFXYTE2S0o0NHVpWWYwRnpEVlVGVW5sNXZFbVAxQ2l0MFRw?= =?utf-8?B?azVETHF6SEMvWDE1TllMWEI2ZzF4L081dG43TWgrbmZoYVkzTE10QT09?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20529d9b-1be9-444c-185c-08df4fb733d7 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5505.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 14:27:18.0494 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VEBS7fGxhAnl/oCdgLGiSyh+Yssxmt/yMZqqRmhqi+p3hydLVOJmbQ3gPkI6arsylfSZoTe2ow/gaJYAo1tyiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8590 On 02/09/2026 16:12, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 5 potential > issue(s) to consider: > > Critical: 0 · High: 2 (2) · Medium: 2 · Low: 1 > > - [High] The patch adds a new `vp_dev->admin_vq.info = NULL` store in > vp_del_vq() (drivers/virtio/virtio_pci_common.c:261) but does not… > - [High] Forward-progress regression / livelock in the -ENOSPC retry loop > of virtqueue_exec_admin_cmd(). > - [Medium] Missing `Fixes:` tag and `Cc: stable` for a live sleep-in- > atomic defect. > - [Medium] vp_modern_avq_work() dereferences admin_vq->info at function > entry (drivers/virtio/virtio_pci_modern.c:59) with no NULL check, but… > - [Low] vp_modern_avq_done() no longer touches the virtqueue at all - it > only calls schedule_work() (drivers/virtio/virtio_pci_modern.c:47-52). > > Pre-existing issues: > - [High] Admin-command submission, reset cleanup and queue deletion do > not share the admin_vq lock, so teardown can run concurrently with… > - [High] The admin-queue completion path converts the device-supplied > used length into a result size without bounding it against the… > > -- > > virtio_pci: Fix sleeping under spinlock in admin command path > > Replaces the admin virtqueue spinlock with a mutex so that > virtqueue_add_sgs() may use GFP_KERNEL, and moves the admin virtqueue > completion handling out of the interrupt callback into a work item, since a > mutex cannot be taken from interrupt context. > > No Link: tags present in the commit header. > > A few questions below about the new teardown/NULL handling, the -ENOSPC > retry loop, and the missing Fixes: tag. > >> virtqueue_exec_admin_cmd() calls virtqueue_add_sgs() with GFP_KERNEL >> while holding a spinlock. GFP_KERNEL allocations can sleep, which is >> illegal in atomic context. >> >> The issue becomes more significant with the next commit, which exposes >> vp_modern_admin_cmd_exec() through virtio_config_ops. This makes the >> admin command path available to device drivers and potentially reachable >> from userspace, increasing the likelihood of hitting the invalid sleep >> under memory pressure. > > [Severity: Medium] > Should this patch carry a Fixes: tag and a stable Cc? Will add a Fixes: tag. > > Both the spin_lock_irqsave(&admin_vq->lock, flags) and the > virtqueue_add_sgs(..., GFP_KERNEL) it wraps in virtqueue_exec_admin_cmd() > were added by: > > 4c3b54af907e ("virtio_pci_modern: use completion instead of busy loop to > wait on admin cmd result") > > The sleep looks reachable on released kernels rather than only after the > follow-up commit: virtqueue_add_split() allocates before the -ENOSPC check, > > drivers/virtio/virtio_ring.c:virtqueue_add_split() { > ... > if (virtqueue_use_indirect(vq, total_sg)) > desc = alloc_indirect_split(vq, total_sg, gfp); > ... > } > > and alloc_indirect_split() does a kmalloc(size, gfp), so any admin command > with total_sg > 1 on a device that negotiated VIRTIO_RING_F_INDIRECT_DESC > does a GFP_KERNEL kmalloc with interrupts disabled and the spinlock held. > The vfio-virtio migration ioctls already drive that path today. Would the > wording "becomes more significant with the next commit" be better phrased > as the bug being reachable now, with a Fixes: tag so backporting tooling > can pick it up? > >> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c >> index 10371ecbc054c..6bc0c0f6ac503 100644 >> --- a/drivers/virtio/virtio_pci_common.c >> +++ b/drivers/virtio/virtio_pci_common.c >> @@ -256,6 +256,11 @@ static void vp_del_vq(struct virtqueue *vq, struct virtio_pci_vq_info *info) >> spin_unlock_irqrestore(&vp_dev->lock, flags); >> } >> >> + if (vp_is_avq(vq->vdev, vq->index)) { >> + cancel_work_sync(&vp_dev->admin_vq.work); >> + vp_dev->admin_vq.info = NULL; >> + } >> + > > [Severity: High] > Can this NULL store oops the next reset? > > All three consumers of admin_vq.info dereference it and only test the > member, not the container pointer: > > drivers/virtio/virtio_pci_modern.c:vp_modern_avq_cleanup() { > ... > vq = vp_dev->admin_vq.info->vq; > if (!vq) > return; > ... > } > > drivers/virtio/virtio_pci_modern.c:virtqueue_exec_admin_cmd() { > ... > vq = admin_vq->info->vq; > if (!vq) > return -EIO; > ... > } > > drivers/virtio/virtio_pci_modern.c:vp_modern_avq_work() { > ... > struct virtqueue *vq = admin_vq->info->vq; > ... > } > > The suspend/reset flows appear to reach the first one with info == NULL: > > virtblk_freeze_priv() (also used for .reset_prepare) > virtio_reset_device() > vdev->config->del_vqs() > vp_del_vqs() -> vp_del_vq() -> admin_vq.info = NULL > > then on restore/reset_done: > > virtio_device_restore_priv() > virtio_reset_device() > vp_reset() -> vp_modern_avq_cleanup() -> admin_vq.info->vq > > virtio_reset_device() only writes status 0, so vdev->features still has > VIRTIO_F_ADMIN_VQ set and the feature-bit guard at the top of > vp_modern_avq_cleanup() does not stop it. virtnet_freeze() -> > remove_vq_common() has the same shape. > > Would it make sense to check info itself at every consumer, and to > publish/clear it under the same lock the readers use? Right now the store > is done with no lock at all while the completion worker and command > submitters can be reading it. > > Also, the reordering of vp_synchronize_vectors() and > vp_modern_avq_cleanup() in vp_reset() is explained only in the added code > comment. Could the commit message mention that behavioural change too? > >> vp_dev->del_vq(info); >> kfree(info); >> } V24 will be rebased on the series that moves avq cleanup from reset to del_vqs and syncs callbacks in the core, so vp_reset() doesn't touch the admin vq. I will drop the admin_vq.info = NULL store and the extra locking and NULL checks. > > [ ... ] > >> diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c >> index ef4a64eb99824..dab63b044a312 100644 >> --- a/drivers/virtio/virtio_pci_modern.c >> +++ b/drivers/virtio/virtio_pci_modern.c >> @@ -47,13 +47,20 @@ static int vp_avq_index(struct virtio_device *vdev, u16 *index, u16 *num) >> void vp_modern_avq_done(struct virtqueue *vq) >> { >> struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); >> - struct virtio_pci_admin_vq *admin_vq = &vp_dev->admin_vq; >> + >> + schedule_work(&vp_dev->admin_vq.work); >> +} > > [Severity: Low] > This isn't a bug, but should the callback suppress further notifications > before deferring? > > virtqueue_disable_cb() now runs only inside vp_modern_avq_work(), so > VRING_AVAIL_F_NO_INTERRUPT (or used_event with VIRTIO_RING_F_EVENT_IDX) is > not armed for the whole window between the device notification and the > worker being picked up. During that window every completed admin command > raises an interrupt whose only effect is a schedule_work() that returns > false because the work is already pending. > > Since the admin queue normally shares the config/slow-path MSI-X vector > (vp_find_one_vq_msix() with slow_path=true uses VP_MSIX_CONFIG_VECTOR), > those extra interrupts also re-walk slow_virtqueues under vp_dev->lock with > interrupts disabled. > > The usual virtio pattern is to disable the callback first, as > virtqueue_napi_schedule() does in virtio_net: > > if (napi_schedule_prep(napi)) { > virtqueue_disable_cb(vq); > ... > } > >> + >> +static void vp_modern_avq_work(struct work_struct *work) >> +{ >> unsigned int status_size = sizeof(struct virtio_admin_cmd_status); >> + struct virtio_pci_admin_vq *admin_vq = >> + container_of(work, struct virtio_pci_admin_vq, work); >> + struct virtqueue *vq = admin_vq->info->vq; > > [Severity: Medium] > Can this dereference run before admin_vq.info has been published? > > vp_setup_vq() enables the queue and links it into the dispatch list before > assigning the admin info pointer: > > drivers/virtio/virtio_pci_common.c:vp_setup_vq() { > ... > if (!vp_is_slow_path_vector(msix_vec)) > list_add(&info->node, &vp_dev->virtqueues); > else > list_add(&info->node, &vp_dev->slow_virtqueues); > ... > *p_info = info; > ... > } > > In the shared-vector and INTx configurations the handler is registered > before any virtqueue exists, so vp_vring_interrupt() / > vp_vring_slow_path_interrupt() can call vring_interrupt() on the admin vq > inside that window if the device has advanced the used index. That runs > vp_modern_avq_done() -> schedule_work(), and the worker then reads > admin_vq->info->vq while info is still NULL (vp_dev is zero-allocated). > > The old callback was immune because it received the vq as its argument and > never touched admin_vq->info. Would a NULL check on info here, or > publishing info before the queue is exposed to interrupt dispatch, be > preferable? > >> struct virtio_admin_cmd *cmd; >> - unsigned long flags; >> unsigned int len; >> >> - spin_lock_irqsave(&admin_vq->lock, flags); >> + mutex_lock(&admin_vq->lock); >> do { >> virtqueue_disable_cb(vq); >> while ((cmd = virtqueue_get_buf(vq, &len))) { The work is only scheduled from the avq callback, which requires a used buffer, so it needs a submitted admin command. Commands can't be issued, and the queue isn't enabled, until find_vqs() has returned and admin_vq.info is set. So the work can't run before info is set. > > [Severity: High] > This isn't a bug introduced by this patch, since the length handling was > moved verbatim from vp_modern_avq_done() into the new work item, but can > this leak uninitialized page contents to userspace? > > The length written by the device is only checked against a lower bound, and > never against the size of the result scatterlist that was submitted: > > drivers/virtio/virtio_pci_modern.c:vp_modern_avq_work() { > ... > if (len < status_size) > cmd->result_sg_size = 0; > else > cmd->result_sg_size = len - status_size; > ... > } > > virtqueue_get_buf() validates the descriptor id, not the length, and > virtio_pci_admin_dev_parts_get() passes the value straight out: > > ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd); > if (!ret) > *res_size = cmd.result_sg_size; > > drivers/vfio/pci/virtio/migrate.c then trusts it: > > virtiovf_read_device_context_chunk() { > ... > buf->length = res_size; > ... > } > > virtiovf_buf_read() { > ... > copy_len = min_t(size_t, > vhca_buf->start_pos + vhca_buf->length - *pos, *len); > ... > } > > and the backing pages are not zeroed: > > virtiovf_add_migration_pages() { > ... > filled = alloc_pages_bulk(GFP_KERNEL_ACCOUNT, to_fill, > page_list); > ... > } > > So a device reporting a used length larger than what it actually wrote gets > stale kernel page contents copied to the migration fd reader; the page > lookup only fails past allocated_length, after earlier copy_to_user() calls > have already run. Should result_sg_size be clamped to the length of the > result scatterlist that was submitted? > > [ ... ] > >> @@ -100,11 +106,11 @@ static int virtqueue_exec_admin_cmd(struct virtio_pci_admin_vq *admin_vq, >> if (virtqueue_is_broken(vq)) >> return -EIO; >> >> - spin_lock_irqsave(&admin_vq->lock, flags); >> + mutex_lock(&admin_vq->lock); >> ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, cmd, GFP_KERNEL); >> if (ret < 0) { >> if (ret == -ENOSPC) { >> - spin_unlock_irqrestore(&admin_vq->lock, flags); >> + mutex_unlock(&admin_vq->lock); >> cpu_relax(); >> goto again; >> } > > [Severity: High] > Can this retry loop stop making progress now? > > Before the patch, descriptors were reclaimed inline in the interrupt > callback, so the hard interrupt preempted the spinning task and freed ring > slots. After the patch the only remaining caller of virtqueue_get_buf() on > the admin vq is vp_modern_avq_work(), which has to be picked up by a > per-CPU bound worker on system_percpu_wq: > > vp_modern_avq_done() > schedule_work(&vp_dev->admin_vq.work) /* system_percpu_wq */ > vp_modern_avq_work() > virtqueue_get_buf() /* only reclaim site */ > > The retry path has no guaranteed scheduling point: virtqueue_is_broken() is > a READ_ONCE, the uncontended mutex_lock()/mutex_unlock() fast paths only > reach might_sleep(), and cpu_relax() does not yield. With > CONFIG_PREEMPT_NONE=y (or PREEMPT_DYNAMIC booted with preempt=none), if the > work item is queued to the CPU running the busy loop, the bound worker > never gets to run, no descriptors are freed, and virtqueue_add_sgs() keeps > returning -ENOSPC. On a single-vCPU guest that CPU match is automatic. > > The loop's only exits are success, virtqueue_is_broken() and a non-ENOSPC > error, none of which can become true without the worker running. Would a > cond_resched() here, or waiting on an event signalled by the completion > worker, or an unbound/WQ_MEM_RECLAIM workqueue, address this? Related: the > untimed wait_for_completion() below now also depends on worker > availability, and system_percpu_wq is not WQ_MEM_RECLAIM. Will replace cpu_relax() with cond_resched() in the -ENOSPC retry, so the worker can run. > > [ ... ] > >> @@ -350,6 +356,8 @@ static void vp_modern_avq_cleanup(struct virtio_device *vdev) >> if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ)) >> return; >> >> + cancel_work_sync(&vp_dev->admin_vq.work); >> + >> vq = vp_dev->admin_vq.info->vq; >> if (!vq) >> return; > > [Severity: High] > This is a pre-existing issue, as the cleanup path and vp_del_vq() ignored > the former spinlock too, but does the new cancel_work_sync() cover enough? > It serializes the completion worker only, not command submitters. > > Nothing holds admin_vq->lock on the teardown side: > > drivers/virtio/virtio_pci_modern.c:vp_modern_avq_cleanup() { > ... > while ((cmd = virtqueue_detach_unused_buf(vq))) { > cmd->ret = -EIO; > complete(&cmd->completion); > } > } > > drivers/virtio/virtio_pci_common.c:vp_del_vq() { > ... > vp_dev->del_vq(info); > kfree(info); > } > > while a submitter caches the queue pointer outside the lock: > > drivers/virtio/virtio_pci_modern.c:virtqueue_exec_admin_cmd() { > ... > vq = admin_vq->info->vq; > if (!vq) > return -EIO; > ... > mutex_lock(&admin_vq->lock); > ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, cmd, GFP_KERNEL); > ... > } > > So a vp_reset() (suspend, FLR, unbind) on one CPU can detach descriptors > while another CPU is inside virtqueue_add_sgs() on the same vring, or free > the virtqueue and info after a submitter cached vq, or leave a command > waiting forever on a queue that was reset. The "caller must serialize > access for the given device" note on virtio_pci_admin_dev_parts_*() only > covers admin-command callers among themselves, not the PM/reset path. > Should the teardown side take admin_vq->lock as well? > > [ ... ] >