]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/pf: Add _locked variants of the VF PT config functions
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Thu, 30 Oct 2025 22:23:35 +0000 (23:23 +0100)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Fri, 31 Oct 2025 19:01:35 +0000 (20:01 +0100)
In upcoming patches we will want to configure VF's preemption
timeout (PT) on all GTs under single lock to avoid potential
races due to parallel GT configuration attempts.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://patch.msgid.link/20251030222348.186658-5-michal.wajdeczko@intel.com
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h

index f3e79a30d8ecef794f8b785e025d49536d0bd545..ce733bde43e3fffa3f20fea32eaf5e52b61dea6f 100644 (file)
@@ -1835,47 +1835,78 @@ static int pf_get_preempt_timeout(struct xe_gt *gt, unsigned int vfid)
 }
 
 /**
- * xe_gt_sriov_pf_config_set_preempt_timeout - Configure preemption timeout for the VF.
+ * xe_gt_sriov_pf_config_set_preempt_timeout_locked() - Configure PF/VF preemption timeout.
  * @gt: the &xe_gt
- * @vfid: the VF identifier
+ * @vfid: the PF or VF identifier
  * @preempt_timeout: requested preemption timeout in microseconds (0 is infinity)
  *
- * This function can only be called on PF.
+ * This function can only be called on PF with the master mutex hold.
+ * It will log the provisioned value or an error in case of the failure.
  *
  * Return: 0 on success or a negative error code on failure.
  */
-int xe_gt_sriov_pf_config_set_preempt_timeout(struct xe_gt *gt, unsigned int vfid,
-                                             u32 preempt_timeout)
+int xe_gt_sriov_pf_config_set_preempt_timeout_locked(struct xe_gt *gt, unsigned int vfid,
+                                                    u32 preempt_timeout)
 {
        int err;
 
-       mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
+       lockdep_assert_held(xe_gt_sriov_pf_master_mutex(gt));
+
        err = pf_provision_preempt_timeout(gt, vfid, preempt_timeout);
-       mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
 
        return pf_config_set_u32_done(gt, vfid, preempt_timeout,
-                                     xe_gt_sriov_pf_config_get_preempt_timeout(gt, vfid),
+                                     pf_get_preempt_timeout(gt, vfid),
                                      "preemption timeout", preempt_timeout_unit, err);
 }
 
 /**
- * xe_gt_sriov_pf_config_get_preempt_timeout - Get VF's preemption timeout.
+ * xe_gt_sriov_pf_config_set_preempt_timeout() - Configure PF/VF preemption timeout.
  * @gt: the &xe_gt
- * @vfid: the VF identifier
+ * @vfid: the PF or VF identifier
+ * @preempt_timeout: requested preemption timeout in microseconds (0 is infinity)
  *
  * This function can only be called on PF.
  *
- * Return: VF's (or PF's) preemption timeout in microseconds.
+ * Return: 0 on success or a negative error code on failure.
  */
-u32 xe_gt_sriov_pf_config_get_preempt_timeout(struct xe_gt *gt, unsigned int vfid)
+int xe_gt_sriov_pf_config_set_preempt_timeout(struct xe_gt *gt, unsigned int vfid,
+                                             u32 preempt_timeout)
 {
-       u32 preempt_timeout;
+       guard(mutex)(xe_gt_sriov_pf_master_mutex(gt));
 
-       mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
-       preempt_timeout = pf_get_preempt_timeout(gt, vfid);
-       mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
+       return xe_gt_sriov_pf_config_set_preempt_timeout_locked(gt, vfid, preempt_timeout);
+}
+
+/**
+ * xe_gt_sriov_pf_config_get_preempt_timeout_locked() - Get PF/VF preemption timeout.
+ * @gt: the &xe_gt
+ * @vfid: the PF or VF identifier
+ *
+ * This function can only be called on PF with the master mutex hold.
+ *
+ * Return: preemption timeout in microseconds (or 0 if infinity).
+ */
+u32 xe_gt_sriov_pf_config_get_preempt_timeout_locked(struct xe_gt *gt, unsigned int vfid)
+{
+       lockdep_assert_held(xe_gt_sriov_pf_master_mutex(gt));
+
+       return pf_get_preempt_timeout(gt, vfid);
+}
+
+/**
+ * xe_gt_sriov_pf_config_get_preempt_timeout() - Get PF/VF preemption timeout.
+ * @gt: the &xe_gt
+ * @vfid: the PF or VF identifier
+ *
+ * This function can only be called on PF.
+ *
+ * Return: preemption timeout in microseconds (or 0 if infinity).
+ */
+u32 xe_gt_sriov_pf_config_get_preempt_timeout(struct xe_gt *gt, unsigned int vfid)
+{
+       guard(mutex)(xe_gt_sriov_pf_master_mutex(gt));
 
-       return preempt_timeout;
+       return pf_get_preempt_timeout(gt, vfid);
 }
 
 static const char *sched_priority_unit(u32 priority)
index b4beb5a97031b2e70f1eca9ee4f4f266d4fd09c1..6bab5ad6c849f69707e23da7880e9a70fad0f243 100644 (file)
@@ -48,6 +48,10 @@ u32 xe_gt_sriov_pf_config_get_preempt_timeout(struct xe_gt *gt, unsigned int vfi
 int xe_gt_sriov_pf_config_set_preempt_timeout(struct xe_gt *gt, unsigned int vfid,
                                              u32 preempt_timeout);
 
+u32 xe_gt_sriov_pf_config_get_preempt_timeout_locked(struct xe_gt *gt, unsigned int vfid);
+int xe_gt_sriov_pf_config_set_preempt_timeout_locked(struct xe_gt *gt, unsigned int vfid,
+                                                    u32 preempt_timeout);
+
 u32 xe_gt_sriov_pf_config_get_sched_priority(struct xe_gt *gt, unsigned int vfid);
 int xe_gt_sriov_pf_config_set_sched_priority(struct xe_gt *gt, unsigned int vfid, u32 priority);