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=1796482213; b=LVitUMJ8Nh9mk1UtycDCUslJCN8LzM78w3gTYUhKJTjLKRy+i7j4kpc/uo9IrNQFqfNx obr08uzuCjdo7Lx3Pc0gFnFg3ADswHsR9udSrVRnlavNRAPP1zaALhwEVPz2TPWJNFh8C ihEX0HeWFfXJRBXNcIUUvQWVFVda5qaMcA+wJUYJsUze/QdNLDlr0hiZlA2cdQ1VKJaoZ UP27XhM8b5MXOURrx3/eXNrlW8rMCk8+oxdI17LQTiGnTsaMg8KGe/pRAwuZICqpE8in3 VJlRebBCQ5kpK+SV1CYog8nc674z2/ECzrgJaiMztUQqHpL4xU3p2qxOZ4FD+pcO+IA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796482213; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=e+ChDQ25wMJyJNEVFyJFiDDn6Liv41NxyhsJAuKkhTg=; b=f3E0aiO/QD0RBysHj6FoZV5cCzdLf6vKq8zqNpa/ypFPjw2WHI+MvSXYSrQCyAoNOZT9 l3Wy19wgdQ5ilpe/3i/iwrsbReCFYhxBC5AkOeyskaLALuyioMvxRpysFo0dZ8OQlL1Ru eNts2AJPPOM9Q/vzQ/qo3STOw+suL9Jx1N0eDw3sYumqNRUg1LCj4ru3UPP9mCvc+YIdr O7UcCHm+c/8O0fMj56rZiOBrw/FiWulZKzMEOjb8/u4SVnQ5XcHghPZnFlqKFbdg8d33g cgKZ80rA9pIZsQ4ZqTyeCD+vWbQCxsMxXlMXbNdHNvbnfrz/CYOzMzN0foQBJqB1bbw== 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=CItQOtS2; 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 A79E0606A322; Sat, 5 Dec 2026 14:50:13 +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 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-Mailing-List: kvm@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 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