Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe/: Mutual Exclusivity b/w Multi CCS Mode & SRIOV VF Provisioning
@ 2025-09-15 14:33 Nareshkumar Gollakoti
  2025-09-15 15:42 ` ✓ CI.KUnit: success for " Patchwork
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Nareshkumar Gollakoti @ 2025-09-15 14:33 UTC (permalink / raw)
  To: intel-xe; +Cc: naresh.kumar.g, tejas.upadhyay

Multi CCS mode can only be enabled when SRIOV is in PF mode with
no VFs provisioned.
Similarly, provisioning VFs is not allowed when Multi CCS mode is active.

Signed-off-by: Nareshkumar Gollakoti <naresh.kumar.g@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_ccs_mode.c |  7 ++++---
 drivers/gpu/drm/xe/xe_gt_ccs_mode.h | 10 ++++++++++
 drivers/gpu/drm/xe/xe_pci_sriov.c   |  7 +++++++
 drivers/gpu/drm/xe/xe_sriov.h       | 12 ++++++++++++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_ccs_mode.c b/drivers/gpu/drm/xe/xe_gt_ccs_mode.c
index 50fffc9ebf62..39df801e9cd5 100644
--- a/drivers/gpu/drm/xe/xe_gt_ccs_mode.c
+++ b/drivers/gpu/drm/xe/xe_gt_ccs_mode.c
@@ -117,9 +117,10 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 	u32 num_engines, num_slices;
 	int ret;
 
-	if (IS_SRIOV(xe)) {
-		xe_gt_dbg(gt, "Can't change compute mode when running as %s\n",
-			  xe_sriov_mode_to_string(xe_device_sriov_mode(xe)));
+	if (IS_SRIOV_VF_ENABLED(xe)) {
+		xe_gt_dbg(gt, "Can't change compute mode when running as %s / %s\n",
+			  xe_sriov_mode_to_string(xe_device_sriov_mode(xe)),
+			  "One or more VFs enabled");
 		return -EOPNOTSUPP;
 	}
 
diff --git a/drivers/gpu/drm/xe/xe_gt_ccs_mode.h b/drivers/gpu/drm/xe/xe_gt_ccs_mode.h
index f8779852cf0d..1a80a293daa2 100644
--- a/drivers/gpu/drm/xe/xe_gt_ccs_mode.h
+++ b/drivers/gpu/drm/xe/xe_gt_ccs_mode.h
@@ -20,5 +20,15 @@ static inline bool xe_gt_ccs_mode_enabled(const struct xe_gt *gt)
 	return hweight32(CCS_MASK(gt)) > 1;
 }
 
+static inline bool xe_is_primary_gt_multi_ccs_enabled(struct xe_device *xe)
+{
+	/* multi CCS mode supported exclusively on GT0 */
+	struct xe_gt *gt = xe_device_get_gt(xe, 0);
+
+	return (gt->ccs_mode > 1);
+}
+
+#define IS_PRIMARY_GT_MULTI_CCS_ENABLED(xe) xe_is_primary_gt_multi_ccs_enabled(xe)
+
 #endif
 
diff --git a/drivers/gpu/drm/xe/xe_pci_sriov.c b/drivers/gpu/drm/xe/xe_pci_sriov.c
index af05db07162e..96e3fd51b8f5 100644
--- a/drivers/gpu/drm/xe/xe_pci_sriov.c
+++ b/drivers/gpu/drm/xe/xe_pci_sriov.c
@@ -19,6 +19,7 @@
 #include "xe_sriov_pf.h"
 #include "xe_sriov_pf_helpers.h"
 #include "xe_sriov_printk.h"
+#include "xe_gt_ccs_mode.h"
 
 static int pf_needs_provisioning(struct xe_gt *gt, unsigned int num_vfs)
 {
@@ -153,6 +154,12 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
 	xe_assert(xe, IS_SRIOV_PF(xe));
 	xe_assert(xe, num_vfs > 0);
 	xe_assert(xe, num_vfs <= total_vfs);
+
+	if (IS_PRIMARY_GT_MULTI_CCS_ENABLED(xe)) {
+		xe_sriov_info(xe, "Can't change the number of VFs while multi-CCS mode is enabled.");
+
+		return -EOPNOTSUPP;
+	}
 	xe_sriov_dbg(xe, "enabling %u VF%s\n", num_vfs, str_plural(num_vfs));
 
 	err = xe_sriov_pf_wait_ready(xe);
diff --git a/drivers/gpu/drm/xe/xe_sriov.h b/drivers/gpu/drm/xe/xe_sriov.h
index 6db45df55615..78019cee61fe 100644
--- a/drivers/gpu/drm/xe/xe_sriov.h
+++ b/drivers/gpu/drm/xe/xe_sriov.h
@@ -36,6 +36,16 @@ static inline bool xe_device_is_sriov_vf(const struct xe_device *xe)
 	return xe_device_sriov_mode(xe) == XE_SRIOV_MODE_VF;
 }
 
+static inline bool xe_device_is_vf_enabled(const struct xe_device *xe)
+{
+	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+
+	if (xe_device_is_sriov_vf(xe))
+		return true;
+
+	return (pci_num_vf(pdev) > 0);
+}
+
 #ifdef CONFIG_PCI_IOV
 #define IS_SRIOV_PF(xe) xe_device_is_sriov_pf(xe)
 #else
@@ -45,4 +55,6 @@ static inline bool xe_device_is_sriov_vf(const struct xe_device *xe)
 
 #define IS_SRIOV(xe) (IS_SRIOV_PF(xe) || IS_SRIOV_VF(xe))
 
+#define IS_SRIOV_VF_ENABLED(xe) xe_device_is_vf_enabled(xe)
+
 #endif
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [V7 PATCH] drm/xe/xe_gt_ccs_mode:Mutual Exclusivity b/w Multi CCS Mode & SRIOV VF Provisioning
@ 2025-11-25 16:57 Nareshkumar Gollakoti
  2025-11-27 16:10 ` [V8 PATCH] drm/xe: Mutual exclusivity between CCS-mode and PF Nareshkumar Gollakoti
  0 siblings, 1 reply; 9+ messages in thread
From: Nareshkumar Gollakoti @ 2025-11-25 16:57 UTC (permalink / raw)
  To: intel-xe; +Cc: michal.wajdeczko, naresh.kumar.g

Use PF lockdown supported functions to enforce mutual exclusivity between
CCS Mode and SRIOV VF enabling/provisioning during CCS Mode enabling.

v2:
- function xe_device_is_vf_enabled has been refactored to
  xe_sriov_pf_has_vfs_enabled and moved to xe_sriov_pf_helper.h.
- The code now distinctly checks for SR-IOV VF mode and
  SR-IOV PF with VFs enabled.
- Log messages have been updated to explicitly state the current mode.
- The function xe_multi_ccs_mode_enabled is moved to xe_device.h

v3: Described missed arg documentation for xe_sriov_pf_has_vfs_enabled

v4:
- sysfs interface for CCS mode is not initialized
  when operating in SRIOV VF Mode.
- xe_sriov_pf_has_vfs_enabled() check is sufficient while CCS mode
  enablement.
- remove unnecessary comments as flow is self explanatory.

v5:(review comments from Michal)
- Add xe device level CCS mode block with mutex lock and CCS mode state
- necessesary functions to manage ccs mode state to provide strict mutual
  exclusive support b/w CCS mode & SRIOV VF enabling

v6:
- Re modeled implementation based on lockdown the PF using custom guard
  supported functions by Michal

v7:
- Corrected patch style as message written as subject
- Used public PF lockdown functions instead internal funcions(Michal)
- Creating CCS Mode entries only on PF Mode

Signed-off-by: Nareshkumar Gollakoti <naresh.kumar.g@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_ccs_mode.c | 48 +++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_ccs_mode.c b/drivers/gpu/drm/xe/xe_gt_ccs_mode.c
index 50fffc9ebf62..468c3a6790d0 100644
--- a/drivers/gpu/drm/xe/xe_gt_ccs_mode.c
+++ b/drivers/gpu/drm/xe/xe_gt_ccs_mode.c
@@ -13,6 +13,7 @@
 #include "xe_gt_sysfs.h"
 #include "xe_mmio.h"
 #include "xe_sriov.h"
+#include "xe_sriov_pf.h"
 
 static void __xe_gt_apply_ccs_mode(struct xe_gt *gt, u32 num_engines)
 {
@@ -108,6 +109,29 @@ ccs_mode_show(struct device *kdev,
 	return sysfs_emit(buf, "%u\n", gt->ccs_mode);
 }
 
+static int xe_gt_prepare_ccs_mode_enabling(struct xe_device *xe,
+					   struct xe_gt *gt)
+{
+	/*
+	 * The arm guard is only activated during CCS mode enabling,
+	 * and this shuould happen when CCS mode is in default mode.
+	 * lockdown arm guard ensures there is no VFS enabling
+	 * as CCS mode enabling in progress/enabled.
+	 */
+	if (!(gt->ccs_mode > 1))
+		return xe_sriov_pf_lockdown(xe);
+
+	return 0;
+}
+
+static void xe_gt_finish_ccs_mode_enabling(struct xe_device *xe,
+					   struct xe_gt *gt)
+{
+	/* disarm the guard, if CCS mode is reverted to default */
+	if (!(gt->ccs_mode > 1))
+		xe_sriov_pf_end_lockdown(xe);
+}
+
 static ssize_t
 ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 	       const char *buff, size_t count)
@@ -117,15 +141,13 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 	u32 num_engines, num_slices;
 	int ret;
 
-	if (IS_SRIOV(xe)) {
-		xe_gt_dbg(gt, "Can't change compute mode when running as %s\n",
-			  xe_sriov_mode_to_string(xe_device_sriov_mode(xe)));
-		return -EOPNOTSUPP;
-	}
+	ret = xe_gt_prepare_ccs_mode_enabling(xe, gt);
+	if (ret)
+		return ret;
 
 	ret = kstrtou32(buff, 0, &num_engines);
 	if (ret)
-		return ret;
+		goto err;
 
 	/*
 	 * Ensure number of engines specified is valid and there is an
@@ -135,7 +157,8 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 	if (!num_engines || num_engines > num_slices || num_slices % num_engines) {
 		xe_gt_dbg(gt, "Invalid compute config, %d engines %d slices\n",
 			  num_engines, num_slices);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err;
 	}
 
 	/* CCS mode can only be updated when there are no drm clients */
@@ -143,7 +166,8 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 	if (!list_empty(&xe->drm.filelist)) {
 		mutex_unlock(&xe->drm.filelist_mutex);
 		xe_gt_dbg(gt, "Rejecting compute mode change as there are active drm clients\n");
-		return -EBUSY;
+		ret = -EBUSY;
+		goto err;
 	}
 
 	if (gt->ccs_mode != num_engines) {
@@ -155,7 +179,13 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 
 	mutex_unlock(&xe->drm.filelist_mutex);
 
+	xe_gt_finish_ccs_mode_enabling(xe, gt);
+
 	return count;
+err:
+	xe_gt_finish_ccs_mode_enabling(xe, gt);
+
+	return ret;
 }
 
 static DEVICE_ATTR_RW(ccs_mode);
@@ -191,7 +221,7 @@ int xe_gt_ccs_mode_sysfs_init(struct xe_gt *gt)
 	struct xe_device *xe = gt_to_xe(gt);
 	int err;
 
-	if (!xe_gt_ccs_mode_enabled(gt))
+	if (!xe_gt_ccs_mode_enabled(gt) || IS_SRIOV_VF(xe))
 		return 0;
 
 	err = sysfs_create_files(gt->sysfs, gt_ccs_mode_attrs);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-11-27 17:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 14:33 [PATCH] drm/xe/: Mutual Exclusivity b/w Multi CCS Mode & SRIOV VF Provisioning Nareshkumar Gollakoti
2025-09-15 15:42 ` ✓ CI.KUnit: success for " Patchwork
2025-09-15 16:18 ` ✓ Xe.CI.BAT: " Patchwork
2025-09-15 20:17 ` ✗ Xe.CI.Full: failure " Patchwork
2025-09-17  6:37 ` [PATCH] " Varun Gupta
2025-09-22 17:42 ` Michal Wajdeczko
2025-11-27 11:38 ` [V8 PATCH] drm/xe: Mutual exclusivity between CCS-mode and PF Nareshkumar Gollakoti
  -- strict thread matches above, loose matches on Subject: below --
2025-11-25 16:57 [V7 PATCH] drm/xe/xe_gt_ccs_mode:Mutual Exclusivity b/w Multi CCS Mode & SRIOV VF Provisioning Nareshkumar Gollakoti
2025-11-27 16:10 ` [V8 PATCH] drm/xe: Mutual exclusivity between CCS-mode and PF Nareshkumar Gollakoti
2025-11-27 17:02   ` Michal Wajdeczko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox