From: sashiko-bot@kernel.org
To: "Zhi Wang" <zhiw@nvidia.com>
Cc: gary@garyguo.net, linux-pci@vger.kernel.org, ojeda@kernel.org
Subject: Re: [PATCH v2 1/8] rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability
Date: Thu, 24 Sep 2026 19:20:47 +0000 [thread overview]
Message-ID: <20260924192048.583471F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924190556.1620886-2-zhiw@nvidia.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] pci: forcefully disabling SR-IOV on driver unbind crashes assigned guest VMs
- [Medium] rust: pci: missing C wrapper causes compilation failure on !CONFIG_PCI_IOV
- [Low] rust: pci: missing inline attribute on enable_sriov and disable_sriov
--
commit 3eb63d8034c8f8f4a7b4af84ac17b76c3927a676
Author: Peter Colberg <pcolberg@redhat.com>
rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability
This commit adds Rust methods to enable and disable the SR-IOV capability
for a PCI device by wrapping pci_enable_sriov() and pci_disable_sriov().
It also modifies the PCI remove callback to synchronously disable SR-IOV
before unbinding the Physical Function (PF) driver.
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 3ec897709e890..e6dac919f02d6 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -133,6 +133,10 @@ extern "C" fn remove_callback(pdev: *mut bindings::pci_dev) {
> // INVARIANT: `pdev` is valid for the duration of `remove_callback()`.
> let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal<'_>>>() };
>
> + // Keep PF data installed until all VF remove callbacks have completed.
> + #[cfg(CONFIG_PCI_IOV)]
> + pdev.disable_sriov();
[Severity: High]
Does this code safely handle the case where VFs are currently assigned to a
guest VM?
In the C PCI subsystem, standard drivers check pci_vfs_assigned(pdev) before
disabling SR-IOV during removal. If pdev.disable_sriov() is called
unconditionally here, won't it forcefully destroy the VF devices without
checking their assignment state?
This could forcefully remove the hardware from running guest VMs, leading to
fatal guest crashes or Advanced Error Reporting (AER) events.
[ ... ]
> @@ -472,6 +476,38 @@ pub fn set_master(&self) {
> // SAFETY: `self.as_raw` is guaranteed to be a pointer to a valid `struct pci_dev`.
> unsafe { bindings::pci_set_master(self.as_raw()) };
> }
> +
> + /// Enable the Single Root I/O Virtualization (SR-IOV) capability for this device,
> + /// where `nr_virtfn` is number of Virtual Functions (VF) to enable.
> + #[cfg(CONFIG_PCI_IOV)]
> + pub fn enable_sriov(&self, nr_virtfn: i32) -> Result {
[Severity: Medium]
Will this regression cause compilation failures for drivers when CONFIG_PCI_IOV
is disabled?
Since #[cfg(CONFIG_PCI_IOV)] entirely removes the enable_sriov() method when
the config is unset, drivers calling it without explicit #[cfg] gating will
fail to compile.
The C API provides static inline fallbacks that safely return -ENODEV or
do nothing when the config is disabled.
Could we expose these functions via rust/helpers/pci.c so bindgen can
generate bindings for the fallbacks, rather than completely removing the
method here?
[Severity: Low]
This isn't a bug, but should this method include an #[inline] attribute?
Since this is a small abstraction function forwarding directly to a C binding
call, adding #[inline] helps avoid minor performance overhead from missed
optimizations.
> + // SAFETY:
> + // `self.as_raw` returns a valid pointer to a `struct pci_dev`.
[ ... ]
> + // The Core device context inherits from the Bound device context,
> + // which guarantees that the PF device is bound to a driver.
> + to_result(unsafe { bindings::pci_enable_sriov(self.as_raw(), nr_virtfn) })
> + }
> +
> + /// Disable the Single Root I/O Virtualization (SR-IOV) capability for this device.
> + #[cfg(CONFIG_PCI_IOV)]
> + pub fn disable_sriov(&self) {
[Severity: Medium]
Can this code also break builds on !CONFIG_PCI_IOV configurations?
Similar to enable_sriov(), hiding this method behind #[cfg(CONFIG_PCI_IOV)]
can break drivers that call disable_sriov() without their own cfg gating.
[Severity: Low]
This isn't a bug, but could we add an #[inline] attribute here as well for
the same reason as enable_sriov()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924190556.1620886-1-zhiw@nvidia.com?part=1
next prev parent reply other threads:[~2026-09-24 19:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 19:05 [PATCH v2 0/8] Add Rust PCI SR-IOV support Zhi Wang
2026-09-24 19:05 ` [PATCH v2 1/8] rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability Zhi Wang
2026-09-24 19:20 ` sashiko-bot [this message]
2026-09-25 20:43 ` Peter Colberg
2026-09-28 19:32 ` Zhi Wang
2026-09-27 16:37 ` Danilo Krummrich
2026-09-28 19:45 ` Zhi Wang
2026-09-24 19:05 ` [PATCH v2 2/8] rust: pci: add vtable attribute to pci::Driver trait Zhi Wang
2026-09-24 19:13 ` sashiko-bot
2026-09-24 19:05 ` [PATCH v2 3/8] rust: pci: add is_virtfn(), to check for VFs Zhi Wang
2026-09-24 19:14 ` sashiko-bot
2026-09-24 19:05 ` [PATCH v2 4/8] rust: pci: add is_physfn(), to check for PFs Zhi Wang
2026-09-24 19:12 ` sashiko-bot
2026-09-24 19:05 ` [PATCH v2 5/8] rust: pci: add num_vf(), to return number of VFs Zhi Wang
2026-09-24 19:13 ` sashiko-bot
2026-09-24 19:05 ` [PATCH v2 6/8] rust: pci: add bus callback sriov_configure(), to control SR-IOV from sysfs Zhi Wang
2026-09-24 19:19 ` sashiko-bot
2026-09-24 19:05 ` [PATCH v2 7/8] rust: pci: add typed SR-IOV PF registration data Zhi Wang
2026-09-24 19:27 ` sashiko-bot
2026-09-28 20:08 ` Danilo Krummrich
2026-09-29 7:27 ` Zhi Wang
2026-09-29 8:35 ` Danilo Krummrich
2026-09-24 19:05 ` [PATCH v2 8/8] samples: rust: add Rust SR-IOV VF driver sample Zhi Wang
2026-09-24 19:22 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924192048.583471F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox