From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2D97606A322 for ; Sat, 5 Dec 2026 14:50:19 +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=CItQOtS2 Received: by kanga.kvack.org (Postfix) id 441DB6B05B1; Sat, 5 Dec 2026 09:50:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F7326B05B2; Sat, 5 Dec 2026 09:50:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B9396B05B3; Sat, 5 Dec 2026 09:50:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 25CB96B05B1 for ; Sat, 5 Dec 2026 09:50:16 -0500 (EST) Received: from smtpin20.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9A1F016059A for ; Sat, 5 Dec 2026 14:50:15 +0000 (UTC) X-FDA: 85510214790.20.9BBE564 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf28.hostedemail.com (Postfix) with ESMTP id 00F29C0002 for ; Sat, 5 Dec 2026 14:50:13 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=CItQOtS2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796482214; b=f6MFvly1t4r9Y/ED5+z8JM0ythAiaslUTMapHoPtuTDlKe5SFAgftC07gaFJWdIx0zT+v9 FhtpSxWfFQxPHRs3Jp6NesjOltCl23Ek03yB+Kx4u5NJ78mCCcRzkUIsv1Sn1+HjDtFshf dS8YL9X/3VxncPIOQWzpGJlGUbpGoa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796482214; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=e+ChDQ25wMJyJNEVFyJFiDDn6Liv41NxyhsJAuKkhTg=; b=Mn1a3tFXkd7u8bULpzu63b88+bpn4jHQUwCMKWTLpAzaTW7QaXWGS01TyQO63xpV74WjGm ppo0mD6PcZfl9LWdwfwcAi7O0qxtUJ3vizgXjL9jT9gZQUvefj5WzQPyCoiK/UOuj5chy6 Qy175216x9AmFvDJFCMxrvNNkE/Rq6Q= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=CItQOtS2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 72D706146C; Sat, 5 Dec 2026 14:50:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A5F41F00A07; Sat, 5 Dec 2026 14:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796482213; bh=e+ChDQ25wMJyJNEVFyJFiDDn6Liv41NxyhsJAuKkhTg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CItQOtS2NGooAvRGoJgwwkSgWLYyMi552eAu1Cw51pv14raJe2C6GLnpzPplR0tPG qk46+0BzquK5jpqK8o1QK4eZi18MLSNF2HiygQM2O9pGTL6H0ueeuPwwv6MYRaurfT z5AZ/VzW79e/7DcL1HZ7Y5YEcvsareMLfC0F2ukjMFuVO7M4iGmXXprMgwiIdZjsa5 mmbaT1ih7N3yBpHIfaE29Y/ZuXb6+oLkr5TeL03NtXTGvZPGnBvFmPbeKhoucgZ3+y vaQGpJiac5q+F3NQkOSZgGbbOEyketktM2t8BJcD4jgrYMxxe9ROeCfjMRYlZ7iNyw QQFWgu5IVOMMg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 2/2] vfio/nova-vgpu: add the Rust VFIO variant driver Reply-To: sashiko-reviews@lists.linux.dev To: "Simon Song" , dakr@kernel.org, acourbot@nvidia.com, kvm@vger.kernel.org, nova-gpu@lists.linux.dev, linux-pci@vger.kernel.org Cc: alex@shazbot.org, jgg@nvidia.com, yishaih@nvidia.com, skolothumtho@nvidia.com, kevin.tian@intel.com, airlied@gmail.com, simona@ffwll.ch, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, jhubbard@nvidia.com, ecourtney@nvidia.com, cjia@nvidia.com, smitra@nvidia.com, kjaju@nvidia.com, alkumar@nvidia.com, ankita@nvidia.com, aniketa@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, zhiwang@kernel.org, zhiw@nvidia.com, boqun@kernel.org, daniel.almeida@collabora.com, tamird@kernel.org, work@onurozkan.dev, jgg@ziepe.ca, bhelgaas@google.com, kwilczynski@kernel.org, dri-devel@lists.freedesktop.org, peter@colberg.org, "Liam R. Howlett" , linux-mm@kvack.org, "Lorenzo Stoakes" In-Reply-To: <20261204144900.286240-3-xinmengs@nvidia.com> References: <20261204144900.286240-1-xinmengs@nvidia.com> <20261204144900.286240-3-xinmengs@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 14:50:11 +0000 X-Stat-Signature: 5c3ffqq67on8h9z6o4go74bsayohsdoc X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 00F29C0002 X-HE-Tag: 1796482213-755715 X-HE-Meta: U2FsdGVkX1/S3Gr/DCGZ47zuqL37EPUepm0eq2f3g3ccaoP01ovifQGffrUibqV3z5NziPulUgHCMSNP6XrjcgsHwb5CgIChilEZF7HpNvIuTbKwh9XWtYchsg1AQ10DNtPzMZ5zM5NYCrt6BYz/YB4duo72YpaXn2SwEvdL/dUQ2DulUQARQ7BNVPJlMJ4L1EzO6PvB8ZK7hp8ryWXb1vnupl2ivjrrW5MtM2vOQj6ygKz+1SM8rumA5B6mfViGCOmbwP2cPTMMmgsv+/IFhsz9STs9YoabJM4dlyPDrBX81IeERiRSgSb4xddeccXfACZaM2LmEq2fq4pbc8T9u5b4ZT8mCAtX3iAf/6wvJyTFU1O0r3/2AsMWcX/L1rjrF3sQzIrn7r6Mnn2ggL/3gf328HmNGlLc6/cnvv1UwI4ZuPyL1XNqYlB90IqA8vJXQyc9jvydblcF0TRU4USZPvFIVh2m8Jk2lQ0gCxaRxeegkcP7+VZ2RZSH/ndTBNrwgMzMHET4at/8gjHLF8zcmpiPV4W7DnXn7CKXY2rK8K68wkXkNwK80s3khVCEDNwWZNlHjFNaQfjj5XdCHc2bKmkj9Z4dAQckLbd8SoFE3cEWjY9mg9VVd3ok/dVHjdHD22oAHyD6GjMVsja3DoOH7yo4S4RvaIIgmQ/qYonz2qNpE34skESIv3RYa07tGLk8FDB6MggtYmhqwgc0f1AW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fWjCvWnQ8cz9N9XZlCkmAnXOXS7jQO6H7rDOIXbN1dAKXBP7pbgNzsnoUucZ6xMhTPmSh98k/hRikjRW4r/VYlASUp/d/ZoANGjl5j+J48ngahWyJwlgluiGi7JIw== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] vfio/nova-vgpu: drop() tears down vGPU before DMA-BUF revocation and disable - [Medium] vfio/nova-vgpu: zero-sized BAR1 retains non-zero PCI and region flags - [Medium] vfio/nova-vgpu: write() updates fb_bar_reg before core_write() succeeds - [Medium] vfio/nova-vgpu: race on reset_error in NovaVgpuOps::ioctl() -- commit 21acf5012ea5af1ae03f8ee86a48cf46eb6adc1e Author: Danilo Krummrich vfio/nova-vgpu: add the Rust VFIO variant driver This commit adds a Rust VFIO PCI variant driver for NVIDIA vGPU VFs that manages vGPU instances through nova-core, enforces the assigned BAR1 aperture, and resets the active vGPU instance on PCI reset. > diff --git a/drivers/vfio/pci/nova-vgpu/nova_vgpu.rs b/drivers/vfio/pci/n= ova-vgpu/nova_vgpu.rs > new file mode 100644 > index 0000000000000..21d3ad70c84ef > --- /dev/null > +++ b/drivers/vfio/pci/nova-vgpu/nova_vgpu.rs > @@ -0,0 +1,522 @@ [ ... ] > +impl Drop for NovaVgpuOpenData<'_, '_> { > + fn drop(&mut self) { > + let mut state =3D self.registration.lock_instance(); > + state.active =3D false; > + drop(self.instance.take()); > + } > +} [Severity: High] Does dropping self.instance here tear down the vGPU and free its VRAM slot while exported BAR1 DMA-BUFs and VF bus mastering are still active? In rust/kernel/vfio/pci.rs:close_device_cb(), OpenData is dropped before vfio_pci_core_close_device() runs: rust/kernel/vfio/pci.rs:close_device_cb() { let dev =3D unsafe { Device::::from_raw_vfio(vdev) }; unsafe { dev.close() }; unsafe { bindings::vfio_pci_core_close_device(vdev) }; } Because dmabuf_len() enables VFIO_DEVICE_FEATURE_DMA_BUF and exported DMA-BUFs only pin the device registration, userspace can close the last VFIO fd while a peer P2P importer still has BAR1 mapped. InstanceRegistry::destroy_instance() then scrubs guest VRAM and returns VgpuVramSlot to the shared PF pool before vfio_pci_dma_buf_cleanup() revokes peer mappings or vfio_pci_core_disable() clears bus mastering, risking cross-tenant VRAM corruption or disclosure if another VF allocates the slot. [ ... ] > + fn ioctl<'res>( > + dev: &vfio::pci::Device, > + rd: &NovaVgpuRegData<'res>, > + open_data: Pin<&Self::OpenData<'_, 'res>>, > + cmd: u32, > + arg: usize, > + ) -> Result { > + // The core checks ioeventfd bounds against the physical BAR and= writes > + // without calling write(), bypassing the vGPU's bar1_limit() ch= eck. > + // Checking a copy here could race with the core's later copy fr= om userspace. > + // On rejection, QEMU falls back to its userspace eventfd handle= r, whose > + // writes pass through write() and bar1_limit(). > + if cmd =3D=3D vfio::DEVICE_IOEVENTFD && open_data.instance.is_so= me() { > + return Err(ENOTTY); > + } > + let result =3D dev.core_ioctl(cmd, arg)?; > + if cmd =3D=3D vfio::DEVICE_RESET { > + if let Some(error) =3D rd.state.lock().reset_error { > + return Err(error); > + } > + } > + Ok(result) > + } [Severity: Medium] Can reading rd.state.lock().reset_error after dev.core_ioctl() returns race with a concurrent PCI reset and misattribute or clobber the reset error? vfio_pci_ioctl_reset() releases pci_dev_lock() and vdev->memory_lock before returning to ioctl(). In that gap, another VFIO_DEVICE_RESET, a config-space FLR write, or a host sysfs reset can enter reset_prepare() and overwrite the single shared state.reset_error field: CPU0 CPU1 NovaVgpuOps::ioctl(DEVICE_RESET) dev.core_ioctl() vfio_pci_ioctl_reset() reset_prepare() reset_error =3D ETIMEDOUT pci_dev_unlock() up_write(memory_lock) pci_reset_function() reset_prepare() vgpu.api.reset() -> EBUSY reset_error =3D EBUSY rd.state.lock().reset_error <-- returns EBUSY, losing ETIMEDOUT Because InstanceRegistry::reset_instance() latches the first failure and returns EBUSY on subsequent calls, a racing reset overwrites the real firmware error with EBUSY. Similarly, if CPU0's reset succeeded and CPU1's reset fails in the gap, CPU0 can return CPU1's failure for its own reset. [ ... ] > + if let (Some(size), Some(fb_bar)) =3D (open_data.bar= 1_size()?, rd.fb_bar) { > + let reg =3D rd.state.lock().fb_bar_reg & !size.w= rapping_sub(1); > + // Byte 0 holds only the flag bits, which the co= re has filled in. > + overrides.apply( > + u64::from(bindings::PCI_BASE_ADDRESS_0) + 4 = * u64::from(fb_bar) + 1, > + ®.to_le_bytes()[1..], > + )?; > + } [Severity: Medium] When bar1_size() returns Some(0) for a vGPU with bar1_length =3D=3D 0 on a = VF with a non-zero physical BAR1, does skipping byte 0 leave non-zero PCI BAR attribute flags in config space? dev.core_read() runs vfio_bar_fixup(), which populates byte 0 with the physical BAR's type and prefetchable flags. Applying the override starting at byte 1 leaves those flags set alongside an all-zero size mask instead of 0x0 for an unimplemented BAR, breaking standard PCI BAR sizing. NovaVgpuOps::get_region_info() has the same mismatch when size =3D=3D 0: it= sets info.size to 0 without clearing the READ/WRITE/MMAP flags populated by vfio_pci_ioctl_get_region_info(), violating the convention that zero-sized BAR regions report flags =3D=3D 0. [ ... ] > + fn write<'res>( > + dev: &vfio::pci::Device, > + rd: &NovaVgpuRegData<'res>, > + open_data: Pin<&Self::OpenData<'_, 'res>>, > + buf: UserSlice, > + position: &mut Position<'_>, > + ) -> Result { > + let mut reader =3D buf.reader(); > + if let Some(fb_bar) =3D rd.fb_bar { > + if position.region_index() =3D=3D vfio::pci::CONFIG_REGION_I= NDEX { > + let mut written =3D [0; 8]; > + let range =3D peek_write( > + &reader, > + position.region_offset(), > + u64::from(bindings::PCI_BASE_ADDRESS_0) + 4 * u64::f= rom(fb_bar), > + &mut written, > + )?; > + if !range.is_empty() { > + let mut state =3D rd.state.lock(); > + let mut reg =3D state.fb_bar_reg.to_le_bytes(); > + reg[range.clone()].copy_from_slice(&written[range]); > + state.fb_bar_reg =3D u64::from_le_bytes(reg); > + } > + } > + } > + if let Some(limit) =3D open_data.bar1_limit(reader.len(), positi= on)? { > + reader.truncate(limit); > + } > + dev.core_write(&reader, position) > + } [Severity: Medium] Can a failed config-space write corrupt state.fb_bar_reg because it is updated before dev.core_write() runs? If a write overlapping BAR1 extends past pdev->cfg_size, vfio_pci_config_rw_single() rejects it with -EFAULT without modifying vconfig, but state.fb_bar_reg has already been overwritten and subsequent BAR1 reads will return values from the failed write. In addition, if position.region_offset() + reader.len() overflows u64, peek_write() returns EOVERFLOW instead of letting core_write() return EFAULT. Deferring the state.fb_bar_reg update until after dev.core_write() succeeds (clamped to the returned byte count) would avoid both problems. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204144900.2862= 40-1-xinmengs@nvidia.com?part=3D2