From mboxrd@z Thu Jan 1 00:00:00 1970 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 27AF3606A32C for ; Thu, 3 Dec 2026 13:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AIyZqhjO Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D7D8210E701; Thu, 3 Dec 2026 13:45:17 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5472F10E712 for ; Thu, 3 Dec 2026 13:45:12 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id C092244305; Thu, 3 Dec 2026 13:45:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EAAF1F00893; Thu, 3 Dec 2026 13:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796305511; bh=ouyc23gyGZvOVFA/he2EbBWjRe0AH01C0mxcq7cPF/k=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=AIyZqhjOjL9YdL6PbWeWC77AYwnFLCA7Gd4027FHagjj1YAbXDLeBqVmkdmN1HZt0 w0N0sD7yWbeeCeZIkCn79QjOPh9GdgLBRZB3IKl85sSbyq2yHwu9FTRGuFdQZ3eads UvpID7PrxZBzhI8sb77zWPj2FKXkj/gkQXC3KmvwZ4EOPJAXut+A7vOwaVntXVEGsH 3RiimqPinWPMAjqBFOdvHTttprkgox4h9U2yLWbNXfCLbzSK1VhgQheQa59svGZS2q QRRLUrtjAGDG72ECTu8cqdqTELLHEIfSEB6fcWmlr4MpQwM22GchDYi4RG29EjcgaL yhPU5qe8YW1Ww== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC 2/2] drm/xe/pmu: Don't hold forcewake while events are open To: "Michal Hlavac" Cc: intel-xe@lists.freedesktop.org In-Reply-To: <20261202-xe-pmu-forcewake-rfc-v1-2-d048943a313f@hlavki.eu> References: <20261202-xe-pmu-forcewake-rfc-v1-0-d048943a313f@hlavki.eu> <20261202-xe-pmu-forcewake-rfc-v1-2-d048943a313f@hlavki.eu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 13:45:11 +0000 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: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/xe/pmu: racy C0 checks allow unforced and torn GT MMIO reads - [Medium] drm/xe/pmu: get_engine_active_ticks() clears active before C0 check -- commit a6af47d823d7e8c9d019a4ccda5e046a28740376 Author: Michal Hlavac drm/xe/pmu: Don't hold forcewake while events are open This commit drops GT forcewake tracking from the Xe PMU and its suspend/resume hooks so open engine activity and frequency events allow the GT to enter C6. Instead, it guards the GPM timestamp and requested-frequen= cy MMIO reads with before-and-after GT_IDLE_C0 status checks. Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/9633 Link: https://bugs.kde.org/show_bug.cgi?id=3D527160 > diff --git a/drivers/gpu/drm/xe/xe_guc_engine_activity.c b/drivers/gpu/dr= m/xe/xe_guc_engine_activity.c > index 729ce8ac140b6..bb978c141b68b 100644 > --- a/drivers/gpu/drm/xe/xe_guc_engine_activity.c > +++ b/drivers/gpu/drm/xe/xe_guc_engine_activity.c [ ... ] > @@ -170,18 +171,36 @@ static u64 cpu_ns_to_guc_tsc_tick(ktime_t ns, u32 f= req) > #define read_metadata_record(xe_, map_, field_) \ > xe_map_rd_field(xe_, map_, 0, struct guc_engine_activity_metadata, fiel= d_) > =20 > +/* > + * The PMU reads the engine activity without forcewake, and the GPM time= stamp > + * can only be read while the GT is awake. The GT is normally awake whil= e an > + * engine is running, but the engine can go idle and let the GT enter C6= at any > + * time. Only trust the timestamp if the GT was in C0 before and after r= eading > + * it. > + */ > +static bool read_gpm_timestamp(struct xe_guc *guc, u32 *gpm_ts) > +{ > + struct xe_gt *gt =3D guc_to_gt(guc); > + > + if (xe_guc_pc_c_status(&guc->pc) !=3D GT_IDLE_C0) > + return false; > + > + *gpm_ts =3D lower_32_bits(xe_mmio_read64_2x32(>->mmio, MISC_STATUS_0)= >> > + guc->engine_activity.gpm_timestamp_shift); > + > + return xe_guc_pc_c_status(&guc->pc) =3D=3D GT_IDLE_C0; > +} [Severity: Medium] Can read_gpm_timestamp() return a bogus or torn MISC_STATUS_0 value across a C0 -> C6 -> C0 transition? MISC_STATUS_0 is in the FORCEWAKE_GT domain, and xe_guc_pc_c_status() only samples the instantaneous C-state rather than pinning forcewake or checking a monotonic residency counter. xe_mmio_read64_2x32() issues at least three sequential MMIO reads, so even with local IRQs disabled in the perf callbac= k, the GT can drop into C6 and be woken back to C0 by another CPU in between: CPU0 (perf read) GT / CPU1 xe_guc_pc_c_status() =3D=3D C0 xe_mmio_read64_2x32(): oldudw =3D read(udw) (GT in C0, real upper dword) engine goes idle -> GT enters C6 ldw =3D read(ldw) <-- unforced read in C6 (0 or ~0) CPU1 submits work -> GT wakes to C0 udw =3D read(udw) (matches oldudw, loop exits) xe_guc_pc_c_status() =3D=3D C0 <-- returns true with torn gpm_ts In get_engine_active_ticks(), subtracting non-zero last_update_tick from a bogus or torn gpm_ts wraps u32 arithmetic into a spike up to U32_MAX ticks in ea->active. If that happens during xe_pmu_enable(), the next xe_pmu_event_update() adds unsigned new - prev and permanently underflows event->count to ~U64_MAX. xe_guc_pc_get_cur_freq_if_awake() has the same C0 -> C6 -> C0 race on FORCEWAKE_GT-gated RPNSWREQ, which can report 0 or 8517 MHz while in C0. [ ... ] > @@ -216,11 +235,8 @@ static u64 get_engine_active_ticks(struct xe_guc *gu= c, struct xe_hw_engine *hwe, > cached_activity->active_ticks =3D active_ticks; > =20 > update: > - if (ea->running) { > - gpm_ts =3D xe_mmio_read64_2x32(>->mmio, MISC_STATUS_0) >> > - engine_activity->gpm_timestamp_shift; > - ea->active =3D lower_32_bits(gpm_ts) - cached_activity->last_update_ti= ck; > - } > + if (ea->running && read_gpm_timestamp(guc, &gpm_ts)) > + ea->active =3D gpm_ts - cached_activity->last_update_tick; > =20 > trace_xe_guc_engine_activity(xe, ea, hwe->name, hwe->instance); [Severity: Medium] Can get_engine_active_ticks() return a smaller total than the previous call when read_gpm_timestamp() fails? Just above update:, when change_num advances, get_engine_active_ticks() updates ea->total and unconditionally zeroes ea->active. Previously, forcewake kept the GT in C0 so ea->active was always recomputed while ea->running was true; now a C6 transition leaves ea->active at 0 instead of keeping the previous value: CPU0 (PMU read) GuC / GT read change_num=3D1, last=3D1000 checkpoint at 1400: change_num=3D2, active_ticks=3D400, last=3D1400 read MISC_STATUS_0 at 1500 ea->active =3D 500, returns 500 ...next read... read change_num=3D2: ea->total =3D 400, ea->active =3D 0 engine finishes -> GT enters C6 read_gpm_timestamp() =3D=3D false returns 400 (< 500) <-- counter goes backwards xe_pmu_event_update() adds unsigned new - prev directly to event->count, so a backward step underflows event->count to ~U64_MAX if event->count is smaller than the drop (for example right after xe_pmu_enable()). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202-xe-pmu-for= cewake-rfc-v1-0-d048943a313f@hlavki.eu?part=3D2