All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Simon Song" <xinmengs@nvidia.com>
Cc: <acourbot@nvidia.com>, <kvm@vger.kernel.org>,
	<rust-for-linux@vger.kernel.org>, <nova-gpu@lists.linux.dev>,
	<linux-pci@vger.kernel.org>, <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>, <linux-kernel@vger.kernel.org>,
	<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>
Subject: Re: [PATCH v2 07/12] rust: pci: add an error_detected callback
Date: Tue, 10 Nov 2026 01:47:48 +0100	[thread overview]
Message-ID: <DMR481ABCB7M.27TE44YRCBZK2@kernel.org> (raw)
In-Reply-To: <20261023154009.2246627-8-xinmengs@nvidia.com>

On Fri Oct 23, 2026 at 5:40 PM CEST, Simon Song wrote:
> VFIO PCI variant drivers will use error_detected() to notify userspace
> of PCI errors through vfio-pci-core.
>
> Adding error_detected() to pci::Driver lets VFIO variants reuse the PCI
> adapter's error callback dispatch. A following patch removes the
> duplicate vfio::pci::Adapter.
>
> Suggested-by: Zhi Wang <zhiw@nvidia.com>
> Signed-off-by: Simon Song <xinmengs@nvidia.com>
> ---
>  rust/kernel/pci.rs      | 33 +++++++++++++++++++++++++++++++--
>  rust/kernel/vfio/pci.rs |  6 ++++++
>  2 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 1951b3c8a5c..ddc28099087 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -109,7 +109,7 @@ unsafe fn register(
>              (*pdrv.get()).remove = Some(Self::remove_callback);
>              (*pdrv.get()).id_table = T::ID_TABLE.as_ptr();
>              (*pdrv.get()).driver_managed_dma = T::DRIVER_MANAGED_DMA;
> -            if T::HAS_RESET_PREPARE || T::HAS_RESET_DONE {
> +            if T::HAS_ERROR_DETECTED || T::HAS_RESET_PREPARE || T::HAS_RESET_DONE {
>                  (*pdrv.get()).err_handler = &Self::ERROR_HANDLERS;
>              }
>              #[cfg(CONFIG_PCI_IOV)]
> @@ -223,8 +223,27 @@ extern "C" fn reset_done_callback(pdev: *mut bindings::pci_dev) {
>          };
>      }
>  
> +    extern "C" fn error_detected_callback(
> +        pdev: *mut bindings::pci_dev,
> +        state: bindings::pci_channel_state_t,
> +    ) -> bindings::pci_ers_result_t {
> +        // SAFETY: PCI error recovery holds the device lock.
> +        let dev = unsafe { &*pdev.cast::<Device<device::CoreInternal<'_>>>() };
> +        // SAFETY: The device lock prevents removal of installed driver data.
> +        unsafe {
> +            Self::callback_data_with(&raw mut (*pdev).dev, |data| {

Please use Device::drvdata_borrow().

> +                T::error_detected(dev, data, state)
> +            })
> +        }
> +        .unwrap_or(bindings::pci_ers_result_PCI_ERS_RESULT_CAN_RECOVER)
> +    }
> +
>      const ERROR_HANDLERS: bindings::pci_error_handlers = bindings::pci_error_handlers {
> -        error_detected: None,
> +        error_detected: if T::HAS_ERROR_DETECTED {
> +            Some(Self::error_detected_callback)
> +        } else {
> +            None
> +        },
>          mmio_enabled: None,
>          slot_reset: None,
>          reset_prepare: if T::HAS_RESET_PREPARE {
> @@ -461,6 +480,16 @@ fn reset_done<'bound>(dev: &Device<device::Core<'_>>, this: Pin<&Self::Data<'bou
>          build_error!(crate::error::VTABLE_DEFAULT_ERROR)
>      }
>  
> +    /// Handle a PCI error and return the PCI recovery result, with the device lock held.
> +    fn error_detected<'bound>(

This can use #[optional].

> +        dev: &Device<device::Core<'_>>,
> +        this: Pin<&Self::Data<'bound>>,
> +        state: bindings::pci_channel_state_t,

This should be represented as a Rust type, maybe something like:

	#[derive(Clone, Copy, Debug, PartialEq, Eq)]
	pub enum ChannelState {
	    /// The I/O channel remains operational.
	    Normal,
	    /// I/O to the device is blocked.
	    Frozen,
	    /// The device has permanently failed.
	    PermanentFailure,
	}

> +    ) -> bindings::pci_ers_result_t {
> +        let _ = (dev, this, state);
> +        build_error!(crate::error::VTABLE_DEFAULT_ERROR)
> +    }
> +
>      /// Enables Single Root I/O Virtualization (SR-IOV) for a PF.
>      ///
>      /// Called when userspace writes a nonzero VF count to `sriov_numvfs`. The token carries the
> diff --git a/rust/kernel/vfio/pci.rs b/rust/kernel/vfio/pci.rs
> index db30dbce6a8..0fbc6a920dc 100644
> --- a/rust/kernel/vfio/pci.rs
> +++ b/rust/kernel/vfio/pci.rs
> @@ -1096,6 +1096,12 @@ pub fn reset_done(&self) -> Result {
>          // SAFETY: This owner keeps the pinned registration data alive.
>          unsafe { self.dev.registration_data_with(T::reset_done) }
>      }
> +
> +    /// Signal the VFIO error interrupt and return the PCI recovery result.
> +    pub fn error_detected(&self) -> bindings::pci_ers_result_t {

Same for bindings::pci_ers_result_t.

> +        // SAFETY: This owner keeps the initialized VFIO core device alive.
> +        unsafe { bindings::vfio_pci_core_aer_err_detected(self.dev.core_device()) }
> +    }
>  }
>  
>  impl<T: Operations> Drop for Registration<'_, T> {
> -- 
> 2.43.7


  reply	other threads:[~2026-11-10  0:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 15:39 [PATCH v2 00/12] Rust VFIO PCI support and NVIDIA vGPU driver Simon Song
2026-10-23 15:39 ` [PATCH v2 01/12] rust: pci: add VFIO override device IDs Simon Song
2026-10-23 20:07   ` Gary Guo
2026-10-30 20:34     ` Simon Song
2026-10-23 15:39 ` [PATCH v2 02/12] rust: pci: expose the VF index within its PF Simon Song
2026-11-09 22:17   ` Danilo Krummrich
2026-10-23 15:39 ` [PATCH v2 03/12] rust: pci: allow drivers to manage DMA ownership Simon Song
2026-11-09 22:18   ` Danilo Krummrich
2026-10-23 15:39 ` [PATCH v2 04/12] rust: vfio: add PCI variant driver abstractions Simon Song
2026-10-23 15:40 ` [PATCH v2 05/12] rust: pci: add reset callbacks Simon Song
2026-11-09 23:19   ` Danilo Krummrich
2026-10-23 15:40 ` [PATCH v2 06/12] rust: pci: add a bind callback after installing driver data Simon Song
2026-11-10  0:10   ` Danilo Krummrich
2026-10-23 15:40 ` [PATCH v2 07/12] rust: pci: add an error_detected callback Simon Song
2026-11-10  0:47   ` Danilo Krummrich [this message]
2026-10-23 15:40 ` [PATCH v2 08/12] rust: pci: add runtime PM callbacks Simon Song
2026-11-10  0:23   ` Danilo Krummrich
2026-10-23 15:40 ` [PATCH v2 09/12] rust: vfio: use the PCI adapter for variant drivers Simon Song
2026-10-23 15:40 ` [PATCH v2 10/12] rust: vfio: separate common device handling from PCI Simon Song
2026-11-10 19:44   ` Danilo Krummrich
2026-10-23 15:40 ` [PATCH v2 11/12] gpu: nova-core: publish typed SR-IOV PF APIs Simon Song
2026-11-10 15:50   ` Danilo Krummrich
2026-10-23 15:40 ` [PATCH v2 12/12] vfio/nvidia-vgpu: add the Rust VFIO variant driver Simon Song
2026-10-30 20:40 ` [PATCH v2 00/12] Rust VFIO PCI support and NVIDIA vGPU driver Simon Song
2026-10-30 20:49   ` Danilo Krummrich
2026-11-10  1:04 ` Danilo Krummrich

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=DMR481ABCB7M.27TE44YRCBZK2@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=alex@shazbot.org \
    --cc=aliceryhl@google.com \
    --cc=alkumar@nvidia.com \
    --cc=aniketa@nvidia.com \
    --cc=ankita@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=boqun@kernel.org \
    --cc=cjia@nvidia.com \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jgg@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kjaju@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=peter@colberg.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=skolothumtho@nvidia.com \
    --cc=smitra@nvidia.com \
    --cc=tamird@kernel.org \
    --cc=targupta@nvidia.com \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=xinmengs@nvidia.com \
    --cc=yishaih@nvidia.com \
    --cc=zhiw@nvidia.com \
    --cc=zhiwang@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.