Skip to content

Commit 55a271a

Browse files
committed
Merge tag 'topic/xe-vfio-2025-12-01' of https://gitlab.freedesktop.org/drm/xe/kernel into drm-next
Cross-subsystem Changes: - Add device specific vfio_pci driver variant for intel graphics (Michal Winiarski) Driver Changes: - Add scope-based cleanup helper for runtime PM (Matt Roper) - Additional xe driver prerequisites and exports (Michal Winiarski) Signed-off-by: Dave Airlie <airlied@redhat.com> From: Thomas Hellstrom <thomas.hellstrom@linux.intel.com> Link: https://patch.msgid.link/aS1bNpqeem6PIHrA@fedora
2 parents 0692602 + 1f5556e commit 55a271a

17 files changed

Lines changed: 926 additions & 7 deletions

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27022,6 +27022,13 @@ L: virtualization@lists.linux.dev
2702227022
S: Maintained
2702327023
F: drivers/vfio/pci/virtio
2702427024

27025+
VFIO XE PCI DRIVER
27026+
M: Michał Winiarski <michal.winiarski@intel.com>
27027+
L: kvm@vger.kernel.org
27028+
L: intel-xe@lists.freedesktop.org
27029+
S: Supported
27030+
F: drivers/vfio/pci/xe
27031+
2702527032
VGA_SWITCHEROO
2702627033
R: Lukas Wunner <lukas@wunner.de>
2702727034
S: Maintained

drivers/gpu/drm/xe/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ xe-$(CONFIG_PCI_IOV) += \
184184
xe_sriov_pf_sysfs.o \
185185
xe_tile_sriov_pf_debugfs.o
186186

187+
ifeq ($(CONFIG_PCI_IOV),y)
188+
xe-$(CONFIG_XE_VFIO_PCI) += xe_sriov_vfio.o
189+
endif
190+
187191
# include helpers for tests even when XE is built-in
188192
ifdef CONFIG_DRM_XE_KUNIT_TEST
189193
xe-y += tests/xe_kunit_helpers.o

drivers/gpu/drm/xe/xe_gt_sriov_pf_migration.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "xe_gt_sriov_pf_helpers.h"
1818
#include "xe_gt_sriov_pf_migration.h"
1919
#include "xe_gt_sriov_printk.h"
20+
#include "xe_guc.h"
2021
#include "xe_guc_buf.h"
2122
#include "xe_guc_ct.h"
2223
#include "xe_migrate.h"
@@ -1023,6 +1024,12 @@ static void action_ring_cleanup(void *arg)
10231024
ptr_ring_cleanup(r, destroy_pf_packet);
10241025
}
10251026

1027+
static void pf_gt_migration_check_support(struct xe_gt *gt)
1028+
{
1029+
if (GUC_FIRMWARE_VER(&gt->uc.guc) < MAKE_GUC_VER(70, 54, 0))
1030+
xe_sriov_pf_migration_disable(gt_to_xe(gt), "requires GuC version >= 70.54.0");
1031+
}
1032+
10261033
/**
10271034
* xe_gt_sriov_pf_migration_init() - Initialize support for VF migration.
10281035
* @gt: the &xe_gt
@@ -1039,6 +1046,8 @@ int xe_gt_sriov_pf_migration_init(struct xe_gt *gt)
10391046

10401047
xe_gt_assert(gt, IS_SRIOV_PF(xe));
10411048

1049+
pf_gt_migration_check_support(gt);
1050+
10421051
if (!pf_migration_supported(gt))
10431052
return 0;
10441053

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,23 @@ static struct pci_driver xe_pci_driver = {
12231223
#endif
12241224
};
12251225

1226+
/**
1227+
* xe_pci_to_pf_device() - Get PF &xe_device.
1228+
* @pdev: the VF &pci_dev device
1229+
*
1230+
* Return: pointer to PF &xe_device, NULL otherwise.
1231+
*/
1232+
struct xe_device *xe_pci_to_pf_device(struct pci_dev *pdev)
1233+
{
1234+
struct drm_device *drm;
1235+
1236+
drm = pci_iov_get_pf_drvdata(pdev, &xe_pci_driver);
1237+
if (IS_ERR(drm))
1238+
return NULL;
1239+
1240+
return to_xe_device(drm);
1241+
}
1242+
12261243
int xe_register_pci_driver(void)
12271244
{
12281245
return pci_register_driver(&xe_pci_driver);

drivers/gpu/drm/xe/xe_pci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#ifndef _XE_PCI_H_
77
#define _XE_PCI_H_
88

9+
struct pci_dev;
10+
911
int xe_register_pci_driver(void);
1012
void xe_unregister_pci_driver(void);
13+
struct xe_device *xe_pci_to_pf_device(struct pci_dev *pdev);
1114

1215
#endif

drivers/gpu/drm/xe/xe_pm.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ static void xe_pm_runtime_lockdep_prime(void)
726726
/**
727727
* xe_pm_runtime_get - Get a runtime_pm reference and resume synchronously
728728
* @xe: xe device instance
729+
*
730+
* When possible, scope-based runtime PM (through guard(xe_pm_runtime)) is
731+
* be preferred over direct usage of this function. Manual get/put handling
732+
* should only be used when the function contains goto-based logic which
733+
* can break scope-based handling, or when the lifetime of the runtime PM
734+
* reference does not match a specific scope (e.g., runtime PM obtained in one
735+
* function and released in a different one).
729736
*/
730737
void xe_pm_runtime_get(struct xe_device *xe)
731738
{
@@ -758,6 +765,13 @@ void xe_pm_runtime_put(struct xe_device *xe)
758765
* xe_pm_runtime_get_ioctl - Get a runtime_pm reference before ioctl
759766
* @xe: xe device instance
760767
*
768+
* When possible, scope-based runtime PM (through
769+
* ACQUIRE(xe_pm_runtime_ioctl, ...)) is be preferred over direct usage of this
770+
* function. Manual get/put handling should only be used when the function
771+
* contains goto-based logic which can break scope-based handling, or when the
772+
* lifetime of the runtime PM reference does not match a specific scope (e.g.,
773+
* runtime PM obtained in one function and released in a different one).
774+
*
761775
* Returns: Any number greater than or equal to 0 for success, negative error
762776
* code otherwise.
763777
*/
@@ -827,6 +841,13 @@ static bool xe_pm_suspending_or_resuming(struct xe_device *xe)
827841
* It will warn if not protected.
828842
* The reference should be put back after this function regardless, since it
829843
* will always bump the usage counter, regardless.
844+
*
845+
* When possible, scope-based runtime PM (through guard(xe_pm_runtime_noresume))
846+
* is be preferred over direct usage of this function. Manual get/put handling
847+
* should only be used when the function contains goto-based logic which can
848+
* break scope-based handling, or when the lifetime of the runtime PM reference
849+
* does not match a specific scope (e.g., runtime PM obtained in one function
850+
* and released in a different one).
830851
*/
831852
void xe_pm_runtime_get_noresume(struct xe_device *xe)
832853
{

drivers/gpu/drm/xe/xe_pm.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef _XE_PM_H_
77
#define _XE_PM_H_
88

9+
#include <linux/cleanup.h>
910
#include <linux/pm_runtime.h>
1011

1112
#define DEFAULT_VRAM_THRESHOLD 300 /* in MB */
@@ -37,4 +38,20 @@ int xe_pm_block_on_suspend(struct xe_device *xe);
3738
void xe_pm_might_block_on_suspend(void);
3839
int xe_pm_module_init(void);
3940

41+
static inline void __xe_pm_runtime_noop(struct xe_device *xe) {}
42+
43+
DEFINE_GUARD(xe_pm_runtime, struct xe_device *,
44+
xe_pm_runtime_get(_T), xe_pm_runtime_put(_T))
45+
DEFINE_GUARD(xe_pm_runtime_noresume, struct xe_device *,
46+
xe_pm_runtime_get_noresume(_T), xe_pm_runtime_put(_T))
47+
DEFINE_GUARD_COND(xe_pm_runtime, _ioctl, xe_pm_runtime_get_ioctl(_T), _RET >= 0)
48+
49+
/*
50+
* Used when a function needs to release runtime PM in all possible cases
51+
* and error paths, but the wakeref was already acquired by a different
52+
* function (i.e., get() has already happened so only a put() is needed).
53+
*/
54+
DEFINE_GUARD(xe_pm_runtime_release_only, struct xe_device *,
55+
__xe_pm_runtime_noop(_T), xe_pm_runtime_put(_T));
56+
4057
#endif

drivers/gpu/drm/xe/xe_sriov_pf_migration.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,37 @@ bool xe_sriov_pf_migration_supported(struct xe_device *xe)
4646
{
4747
xe_assert(xe, IS_SRIOV_PF(xe));
4848

49-
return xe->sriov.pf.migration.supported;
49+
return IS_ENABLED(CONFIG_DRM_XE_DEBUG) || !xe->sriov.pf.migration.disabled;
5050
}
5151

52-
static bool pf_check_migration_support(struct xe_device *xe)
52+
/**
53+
* xe_sriov_pf_migration_disable() - Turn off SR-IOV VF migration support on PF.
54+
* @xe: the &xe_device instance.
55+
* @fmt: format string for the log message, to be combined with following VAs.
56+
*/
57+
void xe_sriov_pf_migration_disable(struct xe_device *xe, const char *fmt, ...)
58+
{
59+
struct va_format vaf;
60+
va_list va_args;
61+
62+
xe_assert(xe, IS_SRIOV_PF(xe));
63+
64+
va_start(va_args, fmt);
65+
vaf.fmt = fmt;
66+
vaf.va = &va_args;
67+
xe_sriov_notice(xe, "migration %s: %pV\n",
68+
IS_ENABLED(CONFIG_DRM_XE_DEBUG) ?
69+
"missing prerequisite" : "disabled",
70+
&vaf);
71+
va_end(va_args);
72+
73+
xe->sriov.pf.migration.disabled = true;
74+
}
75+
76+
static void pf_migration_check_support(struct xe_device *xe)
5377
{
54-
/* XXX: for now this is for feature enabling only */
55-
return IS_ENABLED(CONFIG_DRM_XE_DEBUG);
78+
if (!xe_device_has_memirq(xe))
79+
xe_sriov_pf_migration_disable(xe, "requires memory-based IRQ support");
5680
}
5781

5882
static void pf_migration_cleanup(void *arg)
@@ -77,7 +101,8 @@ int xe_sriov_pf_migration_init(struct xe_device *xe)
77101

78102
xe_assert(xe, IS_SRIOV_PF(xe));
79103

80-
xe->sriov.pf.migration.supported = pf_check_migration_support(xe);
104+
pf_migration_check_support(xe);
105+
81106
if (!xe_sriov_pf_migration_supported(xe))
82107
return 0;
83108

drivers/gpu/drm/xe/xe_sriov_pf_migration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct xe_sriov_packet;
1414

1515
int xe_sriov_pf_migration_init(struct xe_device *xe);
1616
bool xe_sriov_pf_migration_supported(struct xe_device *xe);
17+
void xe_sriov_pf_migration_disable(struct xe_device *xe, const char *fmt, ...);
1718
int xe_sriov_pf_migration_restore_produce(struct xe_device *xe, unsigned int vfid,
1819
struct xe_sriov_packet *data);
1920
struct xe_sriov_packet *

drivers/gpu/drm/xe/xe_sriov_pf_migration_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* struct xe_sriov_pf_migration - Xe device level VF migration data
1515
*/
1616
struct xe_sriov_pf_migration {
17-
/** @supported: indicates whether VF migration feature is supported */
18-
bool supported;
17+
/** @disabled: indicates whether VF migration feature is disabled */
18+
bool disabled;
1919
};
2020

2121
/**

0 commit comments

Comments
 (0)