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: Re: [PATCH] drm/panthor: extend timestamp query with flags
Date: Sun, 22 Mar 2026 04:32:33 +1000	[thread overview]
Message-ID: <review-patch3-abq75MJM5n-U33Fl@e129842.arm.com> (raw)
In-Reply-To: <abq75MJM5n-U33Fl@e129842.arm.com>

Patch Review

This is the current version. Review follows:

**1. Typo in UAPI header**

```c
/** @cpu_timestamp_nsec: Nanseconds part of CPU timestamp. */
```
Should be "Nanoseconds".

**2. `duration_nsec` is `__u32` but assigned from `u64` subtraction**

```c
	if (flags & DRM_PANTHOR_TIMESTAMP_DURATION)
		arg->duration_nsec = local_clock() - query_start_time;
```

`local_clock()` returns `u64`, so the subtraction result is `u64` and gets silently truncated to `__u32`. While a u32 in nanoseconds (~4.2 seconds) is more than enough for a few MMIO reads, the truncation should be documented in the UAPI header comment for `duration_nsec`, or alternatively consider making it `__u64` for future-proofing since there's space (the struct has a `__u64 cpu_timestamp_nsec` right after, so alignment works either way).

**3. `gpu_read64_counter` in an IRQ-disabled, preempt-disabled section contains a retry loop**

```c
static inline u64 gpu_read64_counter(struct panthor_device *ptdev, u32 reg)
{
	u32 lo, hi1, hi2;
	do {
		hi1 = gpu_read(ptdev, reg + 4);
		lo = gpu_read(ptdev, reg);
		hi2 = gpu_read(ptdev, reg + 4);
	} while (hi1 != hi2);
	return lo | ((u64)hi2 << 32);
}
```

The patch calls this up to twice (once for `GPU_TIMESTAMP`, once for `GPU_CYCLE_COUNT`) inside `local_irq_save`/`preempt_disable`. The retry loop is theoretically unbounded. In practice the high word changes extremely rarely, so this is very unlikely to be an issue, but worth noting.

**4. Ordering: `gpu_read64` for `GPU_TIMESTAMP_OFFSET` is done outside the critical section**

```c
	if (flags & DRM_PANTHOR_TIMESTAMP_GPU_OFFSET)
		arg->timestamp_offset = gpu_read64(ptdev, GPU_TIMESTAMP_OFFSET);

	if (minimize_interruption) {
		preempt_disable();
		local_irq_save(irq_flags);
	}
```

The `GPU_TIMESTAMP_OFFSET` read happens before disabling preemption/IRQs. If userspace requests both `GPU_OFFSET` and `GPU` timestamp in the same query, the offset and the timestamp might not be perfectly correlated. This is probably fine since the offset is presumably static or slow-changing, but the design rationale should be documented.

**5. `timens_add_monotonic` called for `MONOTONIC_RAW` — correct but potentially surprising**

```c
	if (flags & DRM_PANTHOR_TIMESTAMP_CPU_TYPE_MASK) {
		timens_add_monotonic(&cpu_ts);
		...
	}
```

This applies the time namespace monotonic offset to both `CLOCK_MONOTONIC` and `CLOCK_MONOTONIC_RAW` timestamps. This matches the kernel's own `posix_get_monotonic_raw()` behavior in `kernel/time/posix-timers.c`, so it's correct. However, a brief comment here would help readers understand this is intentional and follows kernel convention.

**6. Missing `PANTHOR_UOBJ_MIN_SIZE` update consideration**

The `PANTHOR_UOBJ_MIN_SIZE` for `drm_panthor_timestamp_info` remains anchored at `current_timestamp` (line 175 of the existing code). Since the struct is extended with new fields after `timestamp_offset`, old userspace that passes `size = 24` (the old struct size) will:
- `copy_struct_from_user`: copy 24 bytes, zero-fill the rest → `flags == 0` → legacy path. Correct.
- `PANTHOR_UOBJ_SET`: copy back `min(24, new_size) = 24` bytes. Correct.

This works, but the `PANTHOR_UOBJ_MIN_SIZE` min-size is currently set to end at `current_timestamp` (offset 16), not `timestamp_offset` (offset 24). This means userspace could theoretically pass a 16-byte struct and get no `timestamp_offset` back. This was already the case before this patch, so not a regression — just noting the pre-existing behavior.

**7. Multi-line comment style**

```c
	/* If user asked to obtain timestamps from more than one source,
	 * then it very likely means they want them to be as close as possible.
```

Kernel comment style for multi-line comments prefers:
```c
	/*
	 * If user asked to obtain timestamps from more than one source,
	 * then it very likely means they want them to be as close as possible.
```

**8. `ktime_get_ts64` / `ktime_get_raw_ts64` called with IRQs disabled**

These functions are safe to call with IRQs disabled (they use seqcount-based lockless reads), so this is fine.

**9. No `default` case in the CPU type switch inside the critical section**

```c
	switch (flags & DRM_PANTHOR_TIMESTAMP_CPU_TYPE_MASK) {
	case DRM_PANTHOR_TIMESTAMP_CPU_MONOTONIC:
		ktime_get_ts64(&cpu_ts);
		break;
	case DRM_PANTHOR_TIMESTAMP_CPU_MONOTONIC_RAW:
		ktime_get_raw_ts64(&cpu_ts);
		break;
	default:
		break;
	}
```

v3 correctly added `default: break;` here (v2 was missing it). Good.

**10. No validation that args->size is large enough for copy_struct_from_user before powering up GPU**

In the current flow, `copy_struct_from_user` succeeds even for very small `args->size` (zero-fills the rest), then `panthor_query_timestamp_info` powers up the GPU and does MMIO reads, and only then `PANTHOR_UOBJ_SET` would reject the small `usr_size`. This matches the pre-existing behavior (the old code also powered up the GPU before the size check in PANTHOR_UOBJ_SET), so it's not a regression. Minor optimization opportunity for future work.

**Summary of actionable items:**
1. Fix "Nanseconds" → "Nanoseconds" typo
2. Consider making `duration_nsec` `__u64` or document truncation behavior
3. Fix multi-line comment style to match kernel convention
4. Add a brief comment explaining `timens_add_monotonic` applies to both clock types

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-03-21 18:32 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 11:29 [PATCH] drm/panthor: extend timestamp query with flags Marcin Slusarz
2026-03-18 12:10 ` Boris Brezillon
2026-03-18 14:51   ` Marcin Ślusarz
2026-03-18 15:20     ` Steven Price
2026-03-18 16:06       ` Boris Brezillon
2026-03-18 16:27         ` Marcin Ślusarz
2026-03-18 16:37           ` Boris Brezillon
2026-03-18 16:34       ` Boris Brezillon
2026-03-24 20:49       ` Claude review: " Claude Code Review Bot
2026-03-21 18:32     ` Claude Code Review Bot [this message]
2026-03-21 18:32   ` Claude Code Review Bot
2026-03-19  8:25 ` [PATCH v2] " Marcin Slusarz
2026-03-19 10:15   ` Boris Brezillon
2026-03-19 11:00 ` [PATCH v3] " Marcin Slusarz
2026-03-19 11:10   ` Boris Brezillon
2026-03-19 11:43   ` Liviu Dudau
2026-03-19 12:39     ` Marcin Ślusarz
2026-03-19 15:17       ` Liviu Dudau
2026-03-19 15:33         ` Marcin Ślusarz
2026-03-23 13:16           ` Liviu Dudau
2026-03-23 16:12             ` Marcin Ślusarz
2026-03-24 10:41               ` Liviu Dudau
2026-03-24 13:26                 ` Marcin Ślusarz
2026-03-21 18:24 ` Claude review: " Claude Code Review Bot
2026-03-21 18:32 ` Claude Code Review Bot
2026-03-24 13:25 ` [PATCH v4] " Marcin Slusarz
2026-03-24 15:25   ` Liviu Dudau
2026-03-24 16:05   ` Liviu Dudau

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-patch3-abq75MJM5n-U33Fl@e129842.arm.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