From: sashiko-bot@kernel.org
To: "Zhi Wang" <zhiw@nvidia.com>
Cc: gary@garyguo.net, ojeda@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 10/10] samples: rust: add Rust SR-IOV VF driver sample
Date: Wed, 30 Sep 2026 10:46:51 +0000 [thread overview]
Message-ID: <20260930104652.576FF1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <a50d3eba8fca1ecf094da263a749fa012a512b7f.1790759932.git.zhiw@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] pci: missing pci_disable_device() leaks enable_cnt and bus master state
--
commit 775047d7dfd13478598c3e7650d421010c6a0cef
Author: Peter Colberg <peter@colberg.org>
samples: rust: add Rust SR-IOV VF driver sample
Add a new SR-IOV driver sample that demonstrates how to enable and
disable the Single Root I/O Virtualization capability for a PCI device.
Link: https://www.qemu.org/docs/master/system/devices/igb.html
> diff --git a/samples/rust/rust_driver_sriov.rs b/samples/rust/rust_driver_sriov.rs
> new file mode 100644
> --- /dev/null
> +++ b/samples/rust/rust_driver_sriov.rs
[ ... ]
> + fn probe<'bound>(
> + pdev: &'bound pci::Device<Core<'_>>,
> + _info: Option<&'bound Self::IdInfo>,
> + ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
> + pin_init::pin_init_scope(move || {
> + dev_info!(
> + pdev,
> + "Probe Rust SR-IOV PF sample (PCI ID: {}, 0x{:x}).\n",
> + pdev.vendor_id(),
> + pdev.device_id()
> + );
> +
> + pdev.enable_device_mem()?;
> + pdev.set_master();
> +
> + Ok(try_pin_init!(PfDriverData {
[Severity: Medium]
Does this code leak the enable_cnt and leave bus mastering active if the
subsequent try_pin_init!() block fails?
pdev.enable_device_mem() calls pci_enable_device_mem(), incrementing the
enable_cnt of the PCI device, and pdev.set_master() enables bus mastering.
Returning an error without calling pci_disable_device() or
pci_clear_master() would leave the device in an unbalanced state.
> + // SAFETY:
> + // - probe has exclusive access to this PF before SR-IOV is enabled;
> + // - the registration is pinned in the PF driver data and dropped before `pdev`;
> + // - no other registration is created for this PF; and
> + // - VFs are enabled only after probe by `sriov_enable`.
> + _registration <- unsafe {
> + pci::VfRegistration::new(
[ ... ]
> + fn probe<'bound>(
> + pdev: &'bound pci::Device<Core<'_>>,
> + _info: Option<&'bound Self::IdInfo>,
> + ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
> + pin_init::pin_init_scope(move || {
> + dev_info!(
> + pdev,
> + "Probe Rust SR-IOV VF sample (PCI ID: {}, 0x{:x}).\n",
> + pdev.vendor_id(),
> + pdev.device_id()
> + );
> +
> + let pdev_bound: &'bound pci::Device<Bound> = pdev;
> + let pf_api = pdev_bound.vf_registration_data::<PfApiForLt>()?;
> +
> + pdev.enable_device_mem()?;
> + pdev.set_master();
> +
> + let request = pf_api.submit(pdev)?;
[Severity: Medium]
Similarly, does this code leak the enable_cnt and leave bus mastering
active if pf_api.submit(pdev)? fails and propagates an error?
> + dev_info!(pdev, "Submitted request {} through PF data.\n", request);
> +
> + Ok(try_pin_init!(VfDriverData { pdev: pdev.into() }))
> + })
> + }
> +}
> +
> +#[pinned_drop]
> +impl PinnedDrop for PfDriverData<'_> {
> + fn drop(self: Pin<&mut Self>) {
> + dev_info!(self.pdev, "Remove Rust SR-IOV PF sample.\n");
> + }
> +}
> +
> +#[pinned_drop]
> +impl PinnedDrop for VfDriverData {
> + fn drop(self: Pin<&mut Self>) {
> + dev_info!(self.pdev, "Remove Rust SR-IOV VF sample.\n");
> + }
> +}
[Severity: Medium]
During driver teardown, does the PinnedDrop implementation successfully
execute but fail to disable the device memory and clear the master bit?
Leaving these resources enabled leads to an unbalanced enable_cnt which
prevents correct hot-unplug behavior and resource releasing.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790705494.git.zhiw@nvidia.com?part=10
next prev parent reply other threads:[~2026-09-30 10:46 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 10:18 [PATCH v3 00/10] Add Rust PCI SR-IOV support Zhi Wang
2026-09-30 10:18 ` [PATCH v3 01/10] rust: pci: add internal SR-IOV enable and disable helpers Zhi Wang
2026-09-30 10:34 ` sashiko-bot
2026-09-30 10:58 ` Danilo Krummrich
2026-09-30 10:18 ` [PATCH v3 02/10] rust: pci: add vtable attribute to pci::Driver trait Zhi Wang
2026-09-30 10:36 ` sashiko-bot
2026-09-30 10:18 ` [PATCH v3 03/10] rust: pci: add is_virtfn(), to check for VFs Zhi Wang
2026-09-30 10:34 ` sashiko-bot
2026-09-30 10:18 ` [PATCH v3 04/10] rust: pci: add is_physfn(), to check for PFs Zhi Wang
2026-09-30 10:30 ` sashiko-bot
2026-09-30 10:18 ` [PATCH v3 05/10] rust: pci: add num_vf(), to return number of VFs Zhi Wang
2026-09-30 10:32 ` sashiko-bot
2026-09-30 11:13 ` Danilo Krummrich
2026-10-03 17:12 ` Zhi Wang
2026-09-30 10:18 ` [PATCH v3 06/10] rust: pci: drop driver data before remove returns Zhi Wang
2026-09-30 10:35 ` sashiko-bot
2026-09-30 10:18 ` [PATCH v3 07/10] rust: pci: add typed SR-IOV PF registration data Zhi Wang
2026-09-30 10:36 ` sashiko-bot
2026-09-30 13:59 ` Danilo Krummrich
2026-10-04 6:07 ` Zhi Wang
2026-09-30 10:18 ` [PATCH v3 08/10] rust: pci: add SR-IOV enable and disable tokens Zhi Wang
2026-09-30 10:37 ` sashiko-bot
2026-09-30 14:25 ` Danilo Krummrich
2026-10-04 6:16 ` Zhi Wang
2026-09-30 10:18 ` [PATCH v3 09/10] rust: pci: add SR-IOV enable and disable callbacks Zhi Wang
2026-09-30 10:37 ` sashiko-bot
2026-09-30 14:46 ` Danilo Krummrich
2026-09-30 10:18 ` [PATCH v3 10/10] samples: rust: add Rust SR-IOV VF driver sample Zhi Wang
2026-09-30 10:46 ` sashiko-bot [this message]
2026-09-30 15:15 ` Danilo Krummrich
2026-10-04 6:21 ` Zhi Wang
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=20260930104652.576FF1F000FF@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