Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E628606A322 for ; Fri, 4 Dec 2026 01:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ZKsYEKzn Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F251010E156; Fri, 4 Dec 2026 01:41:56 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 39F9A10E156 for ; Fri, 4 Dec 2026 01:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796348511; x=1827884511; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=j5w9bKVigkhEp2o1gi7l34py1xLMb/sJ7pL2tcG3WX0=; b=ZKsYEKznCQPla8SGqtKun/LWBmd6sa8pnSxNzDNTv9n+X5qhqKH3Z7Q8 sNGbKay8ZYxM8BQgiVvNAqDGru7F4iMr/Xb7aPKboSiUP7bziQM0qM1gg ZzoNj1CUT7tN/N4Xh8Jqe7CTgRr94F7TAjd1F4nK9BbdPuUipNPL+/kcV t0PI0GaRQutXSLn+ZGkrW95JK2b1SJ/6hXwUUl3NZCTZLz1wAyRo25S1i gytZl8RaNHEIYpgyO/TAK18RUZ+MyE4oZKT2nInoQx3ewSj281z/lvwgR gt1Bo0EcHGigxkN9YFkPT5naainQb92fXyDEk10cMe1DeUPowpznUSevH g==; X-CSE-ConnectionGUID: 5MYDatD0RvqQN0xndHsdMA== X-CSE-MsgGUID: np/wZPr6S7iQxBJVnif0yw== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5335150" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5335150" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 17:41:50 -0800 X-CSE-ConnectionGUID: AQ4qA8ZoTOuMIp8p/c8gEg== X-CSE-MsgGUID: 7ZtLRV8jSRyUoMyfvASqIA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="13990548" Received: from vbelgaum-desk1.fm.intel.com ([10.121.64.203]) by orviesa007.jf.intel.com with ESMTP; 03 Dec 2026 17:41:50 -0800 From: Vinay Belgaumkar To: intel-xe@lists.freedesktop.org Cc: Vinay Belgaumkar , Rodrigo Vivi Subject: [PATCH v8 1/2] drm/xe: Disallow freq changes while mert cap is active Date: Thu, 3 Dec 2026 17:41:37 -0800 Message-ID: <20261204014137.2470389-3-vinay.belgaumkar@intel.com> X-Mailer: git-send-email 2.53.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 When Wa_22019338487 is applied, GT freq is capped until GSC load is done. During this time, it is possible that users can access sysfs to set min/max GT frequencies. Modifying the frequencies between save/restore could cause inconsistency. Prevent this by introducing a flag which tracks if the cap is active and defer user min/max requests until the cap is lifted. While we are here, fix the minor issue where mert cap is removed only on a successful GSC load. Also, don't restore mert cap if GT is already in a reset. v2: Restore mert cap even after GSC load fails (Sashiko) v5: Return stashed value for min/max during cap (Sashiko) v6: Fix bug and set mert cap to false in xe_guc_pc_stop() (Sashiko) v7: Don't restore mert cap if freq_ready is false (Sashiko) and other comments (Anirban) Fixes: 3b1592fb7835 ("drm/xe/lnl: Apply Wa_22019338487") Reviewed-by: Rodrigo Vivi Signed-off-by: Vinay Belgaumkar --- drivers/gpu/drm/xe/xe_gsc.c | 6 +- drivers/gpu/drm/xe/xe_guc_pc.c | 89 +++++++++++++++++++++------- drivers/gpu/drm/xe/xe_guc_pc_types.h | 2 + 3 files changed, 73 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_gsc.c b/drivers/gpu/drm/xe/xe_gsc.c index 8edb8cee3cbd..c818a4e7863e 100644 --- a/drivers/gpu/drm/xe/xe_gsc.c +++ b/drivers/gpu/drm/xe/xe_gsc.c @@ -290,9 +290,6 @@ static int gsc_upload_and_init(struct xe_gsc *gsc) xe_uc_fw_change_status(&gsc->fw, XE_UC_FIRMWARE_TRANSFERRED); - /* GSC load is done, restore expected GT frequencies */ - xe_gt_sanitize_freq(gt); - xe_gt_dbg(gt, "GSC FW async load completed\n"); /* HuC auth failure is not fatal */ @@ -376,6 +373,9 @@ static void gsc_work(struct work_struct *work) xe_uc_fw_change_status(&gsc->fw, XE_UC_FIRMWARE_LOAD_FAIL); else xe_uc_fw_change_status(&gsc->fw, XE_UC_FIRMWARE_RUNNING); + + /* Undo the mert cap now that GSC load was attempted */ + xe_gt_sanitize_freq(gt); } if (actions & GSC_ACTION_SW_PROXY) diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c b/drivers/gpu/drm/xe/xe_guc_pc.c index 9558d7196a51..cc1869e6bcbe 100644 --- a/drivers/gpu/drm/xe/xe_guc_pc.c +++ b/drivers/gpu/drm/xe/xe_guc_pc.c @@ -344,13 +344,18 @@ static void pc_set_cur_freq(struct xe_guc_pc *pc, u32 freq) pc_set_manual_rp_ctrl(pc, false); } -static int pc_set_min_freq(struct xe_guc_pc *pc, u32 freq) +static bool pc_freq_in_range(struct xe_guc_pc *pc, u32 freq) { /* * Let's only check for the rpn-rp0 range. If max < min, * min becomes a fixed request. */ - if (freq < pc->rpn_freq || freq > pc->rp0_freq) + return freq >= pc->rpn_freq && freq <= pc->rp0_freq; +} + +static int pc_set_min_freq(struct xe_guc_pc *pc, u32 freq) +{ + if (!pc_freq_in_range(pc, freq)) return -EINVAL; /* @@ -377,12 +382,8 @@ static int pc_get_max_freq(struct xe_guc_pc *pc) static int pc_set_max_freq(struct xe_guc_pc *pc, u32 freq) { - /* - * Let's only check for the rpn-rp0 range. If max < min, - * min becomes a fixed request. - * Also, overclocking is not supported. - */ - if (freq < pc->rpn_freq || freq > pc->rp0_freq) + /* Overclocking is not supported. */ + if (!pc_freq_in_range(pc, freq)) return -EINVAL; return pc_action_set_param(pc, @@ -612,6 +613,12 @@ static int xe_guc_pc_get_min_freq_locked(struct xe_guc_pc *pc, u32 *freq) if (!pc->freq_ready) return -EAGAIN; + /* In the middle of a temporary freq cap, return stashed or min freq */ + if (pc->mert_freq_cap_active) { + *freq = pc->user_requested_min ?: pc->stashed_min_freq; + return 0; + } + ret = pc_action_query_task_state(pc); if (ret) return ret; @@ -638,17 +645,26 @@ int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq) static int xe_guc_pc_set_min_freq_locked(struct xe_guc_pc *pc, u32 freq) { - int ret; - lockdep_assert_held(&pc->freq_lock); /* Might be in the middle of a gt reset */ if (!pc->freq_ready) return -EAGAIN; - ret = pc_set_min_freq(pc, freq); - if (ret) - return ret; + /* + * While the Wa_22019338487 cap is active, defer applying the new min + * to GuC; xe_guc_pc_restore_stashed_freq() will apply it once the + * cap is removed. + */ + if (pc->mert_freq_cap_active) { + if (!pc_freq_in_range(pc, freq)) + return -EINVAL; + } else { + int ret = pc_set_min_freq(pc, freq); + + if (ret) + return ret; + } pc->user_requested_min = freq; @@ -681,6 +697,12 @@ static int xe_guc_pc_get_max_freq_locked(struct xe_guc_pc *pc, u32 *freq) if (!pc->freq_ready) return -EAGAIN; + /* In the middle of a temporary freq cap, return stashed value */ + if (pc->mert_freq_cap_active) { + *freq = pc->user_requested_max ?: pc->stashed_max_freq; + return 0; + } + ret = pc_action_query_task_state(pc); if (ret) return ret; @@ -707,17 +729,26 @@ int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq) static int xe_guc_pc_set_max_freq_locked(struct xe_guc_pc *pc, u32 freq) { - int ret; - lockdep_assert_held(&pc->freq_lock); /* Might be in the middle of a gt reset */ if (!pc->freq_ready) return -EAGAIN; - ret = pc_set_max_freq(pc, freq); - if (ret) - return ret; + /* + * While the Wa_22019338487 cap is active, defer applying the new max + * to GuC; xe_guc_pc_restore_stashed_freq() will apply it once the + * cap is lifted. + */ + if (pc->mert_freq_cap_active) { + if (!pc_freq_in_range(pc, freq)) + return -EINVAL; + } else { + int ret = pc_set_max_freq(pc, freq); + + if (ret) + return ret; + } pc->user_requested_max = freq; @@ -1094,11 +1125,14 @@ static int pc_set_mert_freq_cap(struct xe_guc_pc *pc) if (!ret) ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc))); + if (!ret) + pc->mert_freq_cap_active = true; + return ret; } /** - * xe_guc_pc_restore_stashed_freq - Set min/max back to stashed values + * xe_guc_pc_restore_stashed_freq - Set min/max back to stashed/user requested values * @pc: The GuC PC * * Returns: 0 on success, @@ -1112,9 +1146,20 @@ int xe_guc_pc_restore_stashed_freq(struct xe_guc_pc *pc) return 0; mutex_lock(&pc->freq_lock); - ret = pc_set_max_freq(pc, pc->stashed_max_freq); + + /* Restore not needed any more */ + if (!pc->freq_ready || !pc->mert_freq_cap_active) + goto done; + + /* Apply any user min/max request made while the cap was active, else the stash. */ + ret = pc_set_max_freq(pc, pc->user_requested_max ?: pc->stashed_max_freq); + if (!ret) - ret = pc_set_min_freq(pc, pc->stashed_min_freq); + ret = pc_set_min_freq(pc, pc->user_requested_min ?: pc->stashed_min_freq); + if (!ret) + pc->mert_freq_cap_active = false; + +done: mutex_unlock(&pc->freq_lock); return ret; @@ -1345,6 +1390,8 @@ void xe_guc_pc_stop(struct xe_guc_pc *pc) return; mutex_lock(&pc->freq_lock); + /* GT reset could occur while mert cap is active */ + pc->mert_freq_cap_active = false; pc->freq_ready = false; mutex_unlock(&pc->freq_lock); } diff --git a/drivers/gpu/drm/xe/xe_guc_pc_types.h b/drivers/gpu/drm/xe/xe_guc_pc_types.h index 711bbcdcb0d3..9a6ea2904e33 100644 --- a/drivers/gpu/drm/xe/xe_guc_pc_types.h +++ b/drivers/gpu/drm/xe/xe_guc_pc_types.h @@ -35,6 +35,8 @@ struct xe_guc_pc { bool freq_ready; /** @power_profile: Base or power_saving profile */ u32 power_profile; + /** @mert_freq_cap_active: Wa_22019338487 min/max cap is currently in force */ + bool mert_freq_cap_active; }; #endif /* _XE_GUC_PC_TYPES_H_ */ -- 2.53.0