[PATCH i-g-t 3/6] lib/xe/xe_sriov_admin: Lower priority before clearing timeslicing

Marcin Bernatowicz <[email protected]>
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <19f3ef4174e856a83b6915dc19e09da4bab90a5a.1787056235.git.marcin.bernatowicz@linux.intel.com>
Zero execution quantum and zero preemption timeout both mean infinity.
A function left at a scheduling priority above LOW with infinite
timeslicing may never be switched away from by GuC, which is a risky
state that can be left via PAUSE/FLR.

The restore helpers cleared execution quantum and preemption timeout
first and only then dropped priority to LOW, transiting through exactly
that state whenever a test had raised priority. This is reachable from
xe_pmu, which restores defaults while VFs are still enabled, and from
xe_sriov_admin_exit_cleanup_restore_sched_defaults() on abort or signal.

Lower priority first, then clear execution quantum and preemption timeout.

Assisted-by: Copilot:Claude-Opus-5
Signed-off-by: Marcin Bernatowicz <[email protected]>
Cc: Adam Miszczak <[email protected]>
Cc: Jakub Kolakowski <[email protected]>
Cc: Lukasz Laguna <[email protected]>
Cc: Michal Wajdeczko <[email protected]>
---
 lib/xe/xe_sriov_admin.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/lib/xe/xe_sriov_admin.c b/lib/xe/xe_sriov_admin.c
index b03e77b08..0433ddcfc 100644
--- a/lib/xe/xe_sriov_admin.c
+++ b/lib/xe/xe_sriov_admin.c
@@ -547,6 +547,11 @@ void xe_sriov_admin_vf_stop(int pf_fd, unsigned int vf_num)
  *
  * Resets execution quantum, preemption timeout, and priority to driver defaults.
  *
+ * Zero execution quantum and zero preemption timeout both mean infinity, so
+ * priority is lowered first. A function left at a priority above LOW with
+ * infinite timeslicing may never be switched away from by GuC, and can only be
+ * recovered by PAUSE/FLR.
+ *
  * Returns: 0 on success or negative errno on error.
  */
 int __xe_sriov_admin_restore_sched_defaults(int pf_fd, unsigned int vf_num)
@@ -554,6 +559,12 @@ int __xe_sriov_admin_restore_sched_defaults(int pf_fd, unsigned int vf_num)
 	int ret_eq, ret_pt, ret_prio;
 	int ret = 0;
 
+	ret_prio = __xe_sriov_admin_set_sched_priority(pf_fd, vf_num,
+						       XE_SRIOV_SCHED_PRIORITY_LOW);
+	igt_warn_on(ret_prio);
+	if (!ret)
+		ret = ret_prio;
+
 	ret_eq = __xe_sriov_admin_set_exec_quantum_ms(pf_fd, vf_num, 0);
 	igt_warn_on(ret_eq);
 	if (!ret)
@@ -564,12 +575,6 @@ int __xe_sriov_admin_restore_sched_defaults(int pf_fd, unsigned int vf_num)
 	if (!ret)
 		ret = ret_pt;
 
-	ret_prio = __xe_sriov_admin_set_sched_priority(pf_fd, vf_num,
-						       XE_SRIOV_SCHED_PRIORITY_LOW);
-	igt_warn_on(ret_prio);
-	if (!ret)
-		ret = ret_prio;
-
 	return ret;
 }
 
@@ -589,6 +594,9 @@ void xe_sriov_admin_restore_sched_defaults(int pf_fd, unsigned int vf_num)
  *
  * Resets PF and all VFs to driver default scheduling parameters.
  *
+ * Priority is lowered before clearing timeslicing, see
+ * __xe_sriov_admin_restore_sched_defaults().
+ *
  * Returns: 0 on success or negative errno on error.
  */
 int __xe_sriov_admin_bulk_restore_sched_defaults(int pf_fd)
@@ -596,6 +604,12 @@ int __xe_sriov_admin_bulk_restore_sched_defaults(int pf_fd)
 	int ret_eq, ret_pt, ret_prio;
 	int ret = 0;
 
+	ret_prio = __xe_sriov_admin_bulk_set_sched_priority(pf_fd,
+							    XE_SRIOV_SCHED_PRIORITY_LOW);
+	igt_warn_on(ret_prio);
+	if (!ret)
+		ret = ret_prio;
+
 	ret_eq = __xe_sriov_admin_bulk_set_exec_quantum_ms(pf_fd, 0);
 	igt_warn_on(ret_eq);
 	if (!ret)
@@ -606,12 +620,6 @@ int __xe_sriov_admin_bulk_restore_sched_defaults(int pf_fd)
 	if (!ret)
 		ret = ret_pt;
 
-	ret_prio = __xe_sriov_admin_bulk_set_sched_priority(pf_fd,
-							    XE_SRIOV_SCHED_PRIORITY_LOW);
-	igt_warn_on(ret_prio);
-	if (!ret)
-		ret = ret_prio;
-
 	return ret;
 }
 
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.