From: sashiko-bot@kernel.org
To: "Michal Hlavac" <miso@hlavki.eu>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH RFC 2/2] drm/xe/pmu: Don't hold forcewake while events are open
Date: Thu, 03 Dec 2026 13:45:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-247880@kernel.org> (raw)
In-Reply-To: <20261202-xe-pmu-forcewake-rfc-v1-2-d048943a313f@hlavki.eu>
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 <miso@hlavki.eu>
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-frequency
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=527160
> diff --git a/drivers/gpu/drm/xe/xe_guc_engine_activity.c b/drivers/gpu/drm/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 freq)
> #define read_metadata_record(xe_, map_, field_) \
> xe_map_rd_field(xe_, map_, 0, struct guc_engine_activity_metadata, field_)
>
> +/*
> + * The PMU reads the engine activity without forcewake, and the GPM timestamp
> + * can only be read while the GT is awake. The GT is normally awake while 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 reading
> + * it.
> + */
> +static bool read_gpm_timestamp(struct xe_guc *guc, u32 *gpm_ts)
> +{
> + struct xe_gt *gt = guc_to_gt(guc);
> +
> + if (xe_guc_pc_c_status(&guc->pc) != GT_IDLE_C0)
> + return false;
> +
> + *gpm_ts = 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) == 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 callback,
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() == C0
xe_mmio_read64_2x32():
oldudw = read(udw) (GT in C0, real upper dword)
engine goes idle -> GT enters C6
ldw = read(ldw) <-- unforced read in C6 (0 or ~0)
CPU1 submits work -> GT wakes to C0
udw = read(udw) (matches oldudw, loop exits)
xe_guc_pc_c_status() == 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 *guc, struct xe_hw_engine *hwe,
> cached_activity->active_ticks = active_ticks;
>
> update:
> - if (ea->running) {
> - gpm_ts = xe_mmio_read64_2x32(>->mmio, MISC_STATUS_0) >>
> - engine_activity->gpm_timestamp_shift;
> - ea->active = lower_32_bits(gpm_ts) - cached_activity->last_update_tick;
> - }
> + if (ea->running && read_gpm_timestamp(guc, &gpm_ts))
> + ea->active = gpm_ts - cached_activity->last_update_tick;
>
> 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=1, last=1000
checkpoint at 1400: change_num=2,
active_ticks=400, last=1400
read MISC_STATUS_0 at 1500
ea->active = 500, returns 500
...next read...
read change_num=2:
ea->total = 400, ea->active = 0
engine finishes -> GT enters C6
read_gpm_timestamp() == 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()).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-xe-pmu-forcewake-rfc-v1-0-d048943a313f@hlavki.eu?part=2
next prev parent reply other threads:[~2026-12-03 13:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 20:51 [PATCH RFC 0/2] drm/xe/pmu: Don't let open PMU events block S0ix and GT C6 Michal Hlavac
2026-12-02 20:51 ` [PATCH RFC 1/2] drm/xe/pmu: Release forcewake across system suspend Michal Hlavac
2026-12-02 20:51 ` [PATCH RFC 2/2] drm/xe/pmu: Don't hold forcewake while events are open Michal Hlavac
2026-12-03 13:45 ` sashiko-bot [this message]
2026-12-03 14:02 ` ✗ LGCI.VerificationFailed: failure for drm/xe/pmu: Don't let open PMU events block S0ix and GT C6 Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-247880@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=miso@hlavki.eu \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox