public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/xe: gate observation streams with perf_allow_cpu()
Date: Mon, 25 May 2026 18:04:51 +1000	[thread overview]
Message-ID: <review-patch2-20260523013326.129491-3-jhubbard@nvidia.com> (raw)
In-Reply-To: <20260523013326.129491-3-jhubbard@nvidia.com>

Patch Review

**Good design:** The introduction of `xe_observation_paranoid_check()` as a single gating function is clean:

```c
int xe_observation_paranoid_check(void)
{
	if (!xe_observation_paranoid)
		return 0;

	return perf_allow_cpu();
}
```

The `xe_observation_paranoid` sysctl remains as an escape hatch (when cleared, bypass all checks), but when enabled it delegates to the proper perf infrastructure instead of open-coding a partial check.

**Good: variable made static.** Since `xe_observation_paranoid` is now only accessed inside `xe_observation.c`, making it `static` and removing the `extern` from the header is the right cleanup:

```c
-u32 xe_observation_paranoid = true;
+static u32 xe_observation_paranoid = true;
```

**All call sites converted consistently.** The five open-coded sites (1 in `xe_eu_stall.c`, 4 in `xe_oa.c`) are all converted to `xe_observation_paranoid_check()`, and the return value is properly propagated instead of always using `-EACCES`. This is correct because `perf_allow_cpu()` itself returns `-EACCES` on the capability check, so the common case is unchanged, but the LSM hook could return a different error code.

**Behavioral change to note:** The `xe_oa_mmap()` path previously checked `xe_observation_paranoid && !perfmon_capable()` at mmap time. Now it calls `perf_allow_cpu()` which also invokes the LSM hook. This is appropriate -- the mmap exposes the same sensitive observation data, so gating it with the same policy is consistent. However, it's worth noting that a process that successfully opened an OA stream might then fail the mmap if the LSM policy changed between open and mmap. This is a theoretical TOCTOU edge case that also exists in the current perf infrastructure and isn't a concern in practice.

**Error code subtlety in xe_oa_stream_open_ioctl:** The restructuring of the privileged_op check is clean:

```c
-	if (privileged_op && xe_observation_paranoid && !perfmon_capable()) {
-		...
-		ret = -EACCES;
-		goto err_exec_q;
+	if (privileged_op) {
+		ret = xe_observation_paranoid_check();
+		if (ret) {
+			...
+			goto err_exec_q;
+		}
 	}
```

This correctly separates the "is this a privileged operation" decision from the "does the caller have permission" decision.

**Doc comment:** The function-level comment on `xe_observation_paranoid_check()` is thorough and accurately describes the behavior. It's on the verbose side for kernel style but not objectionable.

No blocking issues with this patch.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-25  8:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-23  1:33 [PATCH v2 0/2] complete perf_allow_* trio and use in drm/xe John Hubbard
2026-05-23  1:33 ` [PATCH v2 1/2] perf/core: out-of-line and export perf_allow_cpu/tracepoint() John Hubbard
2026-05-25  8:04   ` Claude review: " Claude Code Review Bot
2026-05-23  1:33 ` [PATCH v2 2/2] drm/xe: gate observation streams with perf_allow_cpu() John Hubbard
2026-05-25  8:04   ` Claude Code Review Bot [this message]
2026-05-23  8:40 ` [PATCH v2 0/2] complete perf_allow_* trio and use in drm/xe Peter Zijlstra
2026-05-23 17:52   ` John Hubbard
2026-05-25  8:04 ` Claude review: " Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-05-21  2:49 [PATCH 0/2] perf: " John Hubbard
2026-05-21  2:49 ` [PATCH 2/2] drm/xe: gate observation streams with perf_allow_cpu() John Hubbard
2026-05-25 11:03   ` Claude review: " Claude Code Review Bot

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=review-patch2-20260523013326.129491-3-jhubbard@nvidia.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /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