From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6F0ADCA5FA5 for ; Tue, 29 Sep 2026 19:01:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF69410F047; Tue, 29 Sep 2026 19:01:58 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="IsTRCDEV"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7F56210F047 for ; Tue, 29 Sep 2026 19:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790708514; x=1822244514; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v2Z98pVSjp1/0TZN8uXaJZY254nJuFWe+zIdEFregIo=; b=IsTRCDEVNi7YLcoYSP+eu6PWPj+Q/6S7hueo3MYFHOOvHsTlduU+mZLW 2qbZkGbPjQQSppTdBSD2PIkMZU/ehV6JDRzKwzDogyNWE0Fr+o40I2vG/ 37TzJbUnFbGETck5kupksURzs4xHI0jPx1qUTcWpoyc5erVzZyyMEbwpN O3VXUSpQ61PeOFNxIIX5qRbaOTpITPICIVJohJ2C6ZGZHd+uoX9lFmFYf CuJ7YTTBjUA/LtkF41KQYy8R4YLXQoxBRHpWn5XYBfLQkCtY3gTGD39Fu Vkv1NUavkbQJk7owBPago9/mOEswtOxypiNK+omcps0WxLsHKok6NwUpp w==; X-CSE-ConnectionGUID: OKXKYy8SSbK/ioF1precWA== X-CSE-MsgGUID: HPH/xrlPQ+2ZOQsujj9wNg== X-IronPort-AV: E=McAfee;i="6800,10657,11920"; a="90564112" X-IronPort-AV: E=Sophos;i="6.27,130,1787036400"; d="scan'208";a="90564112" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2026 12:01:54 -0700 X-CSE-ConnectionGUID: J0DCP/c0TMa60Qp4xfNp9g== X-CSE-MsgGUID: 6kTSkrwXRbSl3KXlrl42Aw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,130,1787036400"; d="scan'208";a="274062220" Received: from orsosgc001.jf.intel.com ([10.54.56.63]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2026 12:01:54 -0700 From: Umesh Nerlige Ramappa To: intel-gfx@lists.freedesktop.org, vinay.belgaumkar@intel.com Cc: dev@lankhorst.se Subject: [PATCH 2/3] drm/i915/guc: Use a delayed wakeref put in guc_engine_busyness() Date: Tue, 29 Sep 2026 12:01:50 -0700 Message-ID: <20260929190147.2886670-7-umesh.nerlige.ramappa@intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260929190147.2886670-5-umesh.nerlige.ramappa@intel.com> References: <20260929190147.2886670-5-umesh.nerlige.ramappa@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" perf can invoke the PMU callbacks from the scheduler with the runqueue lock held, e.g. pmu->del() via perf_cgroup_switch() from finish_task_switch(). guc_engine_busyness() drops its GT wakeref there with intel_gt_pm_put_async(), which lands in mod_delayed_work() with a zero delay. That queues the work immediately and wakes a worker via try_to_wake_up(), which then deadlocks on the runqueue lock we are already holding. The put also happens under guc->timestamp.lock, so the stall blocks any concurrent __guc_context_update_stats() too, and the machine hard locks up. Only reachable when a concurrent put drops the refcount to 1 inside the get_if_awake()/put_async() window, which makes it rare and load dependent. Add intel_gt_pm_put_delay() and use it with a 1 jiffy delay. A non-zero delay takes the add_timer_on() path in __queue_delayed_work() instead, so no task is ever woken from here. Fixes: 77cdd054dd2c ("drm/i915/pmu: Connect engine busyness stats from GuC to pmu") Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16984 Signed-off-by: Umesh Nerlige Ramappa Assisted-by: Claude:claude-opus-5 --- drivers/gpu/drm/i915/gt/intel_gt_pm.h | 24 +++++++++++++++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_pm.h b/drivers/gpu/drm/i915/gt/intel_gt_pm.h index 6f25c747bc29..24c8b014864d 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_pm.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.h @@ -72,6 +72,30 @@ static inline void intel_gt_pm_put_async(struct intel_gt *gt, intel_wakeref_t ha intel_gt_pm_put_async_untracked(gt); } +/** + * intel_gt_pm_put_delay - release the GT wakeref, deferred by a timer + * + * @gt: pointer to the gt + * @handle: the handle returned by the matching intel_gt_pm_get*() + * @delay: delay, in jiffies, before the release is processed + * + * As intel_gt_pm_put_async(), except that dropping the last reference arms a + * timer instead of queueing the release immediately. + * + * intel_gt_pm_put_async() ends up in mod_delayed_work() with a zero delay, + * which queues the work straight away and so wakes a workqueue worker through + * try_to_wake_up(). That deadlocks if the caller already holds a runqueue + * lock, since try_to_wake_up() then tries to take it again. Callers which can + * run from inside the scheduler must use this variant with a non-zero @delay, + * which takes the add_timer_on() path and never wakes a task. + */ +static inline void intel_gt_pm_put_delay(struct intel_gt *gt, intel_wakeref_t handle, + unsigned long delay) +{ + intel_wakeref_untrack(>->wakeref, handle); + intel_wakeref_put_delay(>->wakeref, delay); +} + #define with_intel_gt_pm(gt, wf) \ for ((wf) = intel_gt_pm_get(gt); (wf); intel_gt_pm_put((gt), (wf)), (wf) = NULL) diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c index 788e59cdfac9..32d722c378e8 100644 --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c @@ -1361,7 +1361,12 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now) */ guc_update_engine_gt_clks(engine); guc_update_pm_timestamp(guc, now); - intel_gt_pm_put_async(gt, wakeref); + /* + * We are reached from the perf callbacks, which perf may invoke + * from the scheduler with the runqueue lock held. Defer the put + * on a timer so that it can never wake a task from here. + */ + intel_gt_pm_put_delay(gt, wakeref, 1); if (i915_reset_count(gpu_error) != reset_count) { *stats = stats_saved; guc->timestamp.gt_stamp = gt_stamp_saved; -- 2.55.0