Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Piotr Piórkowski" <piotr.piorkowski@intel.com>
To: Lukasz Laguna <lukasz.laguna@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <satyanarayana.k.v.p@intel.com>,
	<tomasz.lis@intel.com>, <raag.jadav@intel.com>
Subject: Re: [PATCH 4/5] drm/xe/pf: Preserve VF PCI config space across PF FLR
Date: Wed, 2 Dec 2026 11:38:40 +0100	[thread overview]
Message-ID: <20261202103840.23psvym3sg6gh2o2@intel.com> (raw)
In-Reply-To: <20261130150315.1954064-5-lukasz.laguna@intel.com>

Lukasz Laguna <lukasz.laguna@intel.com> wrote on pon [2026-lis-30 16:03:14 +0100]:
> On PF FLR, the PCI core doesn't preserve the config space of enabled
> VFs, so it's lost. Save the VF PCI state before PF FLR and restore it
> after the reset completes.
> 
> Add an SR-IOV pre-FLR step to the reset handler for saving the state,
> and restore it in the SR-IOV post-FLR step.
> 
> Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_pci_error.c |  2 ++
>  drivers/gpu/drm/xe/xe_pci_sriov.c | 38 +++++++++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_pci_sriov.h | 10 ++++++++
>  drivers/gpu/drm/xe/xe_sriov.c     | 17 ++++++++++++++
>  drivers/gpu/drm/xe/xe_sriov.h     |  1 +
>  5 files changed, 68 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_pci_error.c b/drivers/gpu/drm/xe/xe_pci_error.c
> index 9b54ae2d392f..ed3060071708 100644
> --- a/drivers/gpu/drm/xe/xe_pci_error.c
> +++ b/drivers/gpu/drm/xe/xe_pci_error.c
> @@ -264,6 +264,8 @@ static void xe_pci_reset_prepare(struct pci_dev *pdev)
>  		return;
>  	}
>  
> +	xe_sriov_pre_flr(xe);
> +
>  	/*
>  	 * The hardware could be in corrupted state and access unreliable, but we try to
>  	 * update data structures and cleanup any pending work to avoid side effects during
> diff --git a/drivers/gpu/drm/xe/xe_pci_sriov.c b/drivers/gpu/drm/xe/xe_pci_sriov.c
> index b0cfa6e46d8b..85454ed6d882 100644
> --- a/drivers/gpu/drm/xe/xe_pci_sriov.c
> +++ b/drivers/gpu/drm/xe/xe_pci_sriov.c
> @@ -307,3 +307,41 @@ struct pci_dev *xe_pci_sriov_get_vf_pdev(struct pci_dev *pdev, unsigned int vfid
>  					   pdev->bus->number,
>  					   pci_iov_virtfn_devfn(pdev, vfid - 1));
>  }
> +
> +/**
> + * xe_pci_sriov_save_vfs_state() - Save PCI state of all enabled VFs.
> + * @pdev: the PF's &pci_dev
> + */
> +void xe_pci_sriov_save_vfs_state(struct pci_dev *pdev)
> +{
> +	unsigned int num_vfs = pci_num_vf(pdev);
> +	struct pci_dev *vf_pdev;
> +	unsigned int n;
> +
> +	for (n = 1; n <= num_vfs; n++) {
> +		vf_pdev = xe_pci_sriov_get_vf_pdev(pdev, n);
> +		if (!vf_pdev)
> +			continue;
> +		pci_save_state(vf_pdev);
> +		pci_dev_put(vf_pdev);
> +	}
> +}
> +
> +/**
> + * xe_pci_sriov_restore_vfs_state() - Restore PCI state of all enabled VFs.
> + * @pdev: the PF's &pci_dev
> + */
> +void xe_pci_sriov_restore_vfs_state(struct pci_dev *pdev)
> +{
> +	unsigned int num_vfs = pci_num_vf(pdev);
> +	struct pci_dev *vf_pdev;
> +	unsigned int n;
> +
> +	for (n = 1; n <= num_vfs; n++) {
> +		vf_pdev = xe_pci_sriov_get_vf_pdev(pdev, n);
> +		if (!vf_pdev)
> +			continue;
> +		pci_restore_state(vf_pdev);
> +		pci_dev_put(vf_pdev);
> +	}
> +}
> diff --git a/drivers/gpu/drm/xe/xe_pci_sriov.h b/drivers/gpu/drm/xe/xe_pci_sriov.h
> index b9105d71dbb1..079edb0d220f 100644
> --- a/drivers/gpu/drm/xe/xe_pci_sriov.h
> +++ b/drivers/gpu/drm/xe/xe_pci_sriov.h
> @@ -11,11 +11,21 @@ struct pci_dev;
>  #ifdef CONFIG_PCI_IOV
>  int xe_pci_sriov_configure(struct pci_dev *pdev, int num_vfs);
>  struct pci_dev *xe_pci_sriov_get_vf_pdev(struct pci_dev *pdev, unsigned int vfid);
> +void xe_pci_sriov_save_vfs_state(struct pci_dev *pdev);
> +void xe_pci_sriov_restore_vfs_state(struct pci_dev *pdev);
>  #else
>  static inline int xe_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
>  {
>  	return 0;
>  }
> +
> +static inline void xe_pci_sriov_save_vfs_state(struct pci_dev *pdev)
> +{
> +}
> +
> +static inline void xe_pci_sriov_restore_vfs_state(struct pci_dev *pdev)
> +{
> +}
>  #endif
>  
>  #endif
> diff --git a/drivers/gpu/drm/xe/xe_sriov.c b/drivers/gpu/drm/xe/xe_sriov.c
> index 51b683abdb4a..af94f785f394 100644
> --- a/drivers/gpu/drm/xe/xe_sriov.c
> +++ b/drivers/gpu/drm/xe/xe_sriov.c
> @@ -13,8 +13,10 @@
>  #include "xe_device.h"
>  #include "xe_gt_sriov_vf.h"
>  #include "xe_mmio.h"
> +#include "xe_pci_sriov.h"
>  #include "xe_sriov.h"
>  #include "xe_sriov_pf.h"
> +#include "xe_sriov_pf_helpers.h"
>  #include "xe_sriov_vf.h"
>  #include "xe_sriov_vf_ccs.h"
>  
> @@ -176,6 +178,18 @@ int xe_sriov_init_late(struct xe_device *xe)
>  	return 0;
>  }
>  
> +/**
> + * xe_sriov_pre_flr() - Perform SR-IOV specific pre-FLR actions.
> + * @xe: the &xe_device
> + *
> + * This function should be called before PCIe FLR.
> + */
> +void xe_sriov_pre_flr(struct xe_device *xe)
> +{
> +	if (IS_SRIOV_PF(xe) && xe_sriov_pf_num_vfs(xe))
> +		xe_pci_sriov_save_vfs_state(to_pci_dev(xe->drm.dev));
> +}
> +
>  /**
>   * xe_sriov_post_flr() - Perform SR-IOV specific post-FLR actions.
>   * @xe: the &xe_device
> @@ -191,6 +205,9 @@ int xe_sriov_post_flr(struct xe_device *xe)
>  	int err;
>  	u8 id;
>  
> +	if (IS_SRIOV_PF(xe) && xe_sriov_pf_num_vfs(xe))
> +		xe_pci_sriov_restore_vfs_state(to_pci_dev(xe->drm.dev));
> +
>  	if (IS_SRIOV_VF(xe)) {
>  		/*
>  		 * Wait for GuC to accept the VF state reset. This indicates that PF
> diff --git a/drivers/gpu/drm/xe/xe_sriov.h b/drivers/gpu/drm/xe/xe_sriov.h
> index 444d1ad74926..609794a8cf9b 100644
> --- a/drivers/gpu/drm/xe/xe_sriov.h
> +++ b/drivers/gpu/drm/xe/xe_sriov.h
> @@ -19,6 +19,7 @@ void xe_sriov_probe_early(struct xe_device *xe);
>  void xe_sriov_print_info(struct xe_device *xe, struct drm_printer *p);
>  int xe_sriov_init(struct xe_device *xe);
>  int xe_sriov_init_late(struct xe_device *xe);
> +void xe_sriov_pre_flr(struct xe_device *xe);
>  int xe_sriov_post_flr(struct xe_device *xe);
>  
>  static inline enum xe_sriov_mode xe_device_sriov_mode(const struct xe_device *xe)

I think the VF config space restore might be too early here. xe_sriov_post_flr() runs before
xe_device_resume(), so the VFs get PCI_COMMAND_MEMORY/MASTER and MSI-X back while
GGTT, LMTT, LMEM_CFG and the VF configs in GuC are not restored yet. 
VF drivers are not stopped during PF FLR, so they could access LMEM before LMTT is set up.

Maybe it would be safer to restore the VFs after a successful xe_device_resume()?

Thanks
Piotr

> -- 
> 2.43.0
> 

-- 

  reply	other threads:[~2026-12-02 10:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 15:03 [PATCH 0/5] drm/xe/pf: Support PCIe FLR when VFs are enabled Lukasz Laguna
2026-11-30 15:03 ` [PATCH 1/5] drm/xe/pf: Add helper to rewrite VF LMTT page table tree Lukasz Laguna
2026-12-02  9:37   ` Piotr Piórkowski
2026-11-30 15:03 ` [PATCH 2/5] drm/xe/pf: Extract VF LMTT pages population into helper Lukasz Laguna
2026-12-02  9:40   ` Piotr Piórkowski
2026-11-30 15:03 ` [PATCH 3/5] drm/xe/pf: Recover VF state after PF FLR Lukasz Laguna
2026-12-02  9:59   ` Piotr Piórkowski
2026-11-30 15:03 ` [PATCH 4/5] drm/xe/pf: Preserve VF PCI config space across " Lukasz Laguna
2026-12-02 10:38   ` Piotr Piórkowski [this message]
2026-11-30 15:03 ` [PATCH 5/5] drm/xe/pf: Support PCIe FLR when VFs are enabled Lukasz Laguna
2026-12-02 10:44   ` Piotr Piórkowski
2026-11-30 17:23 ` ✓ CI.KUnit: success for " Patchwork
2026-11-30 18:13 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-01  2:30 ` ✓ Xe.CI.FULL: " Patchwork

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=20261202103840.23psvym3sg6gh2o2@intel.com \
    --to=piotr.piorkowski@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lukasz.laguna@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=satyanarayana.k.v.p@intel.com \
    --cc=tomasz.lis@intel.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