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/xe_vm: Implement xe_vm_get_property_ioctl
Date: Tue, 24 Feb 2026 10:00:00 +1000	[thread overview]
Message-ID: <review-patch4-20260223172120.98961-10-jonathan.cavitt@intel.com> (raw)
In-Reply-To: <20260223172120.98961-10-jonathan.cavitt@intel.com>

Patch Review

**Missing UAPI field validation.** The ioctl handler validates `reserved[]` but does not check `pad` or `extensions`:

> +	if (XE_IOCTL_DBG(xe, args->reserved[0] || args->reserved[1] ||
> +			     args->reserved[2]))
> +		return -EINVAL;

Both `pad` (marked MBZ in the UAPI struct) and `extensions` must be validated to be zero for future extensibility. Compare with `xe_vm_create_ioctl` and other xe ioctl handlers which all validate their `extensions` field. This should be:

```c
if (XE_IOCTL_DBG(xe, args->extensions))
    return -EINVAL;
if (XE_IOCTL_DBG(xe, args->pad || args->reserved[0] ||
                 args->reserved[1] || args->reserved[2]))
    return -EINVAL;
```

Failing to reject non-zero `extensions` now means the field cannot be used for extensions in the future without breaking backward compatibility with applications that happen to pass garbage in that field today.

**TOCTOU between size check and fill.** In `xe_vm_get_property_helper`, the faults lock is acquired to read `vm->faults.len`, then released, then `fill_faults` acquires the lock again:

> +		spin_lock(&vm->faults.lock);
> +		size = size_mul(sizeof(struct xe_vm_fault), vm->faults.len);
> +		spin_unlock(&vm->faults.lock);
> +
> +		if (!args->size) {
> +			args->size = size;
> +			return 0;
> +		}
> +
> +		if (args->size > size || args->size % sizeof(struct xe_vm_fault))
> +			return -EINVAL;
> +
> +		return fill_faults(vm, args);

Since faults can only be added (not removed except during VM teardown), and `fill_faults` caps its iteration at `count = args->size / entry_size`, this is safe in practice: there will always be at least `count` entries by the time `fill_faults` runs. However, if `xe_vm_close_and_put` runs between the size check and `fill_faults`, the list could be cleared, resulting in `fill_faults` copying fewer entries than expected (the rest being zero-filled from `kcalloc`). The user would receive zero-filled fault entries with no way to distinguish them from a legitimate fault at address 0. Documenting this race or returning the actual number of entries copied would be an improvement.

**No way to report actual count.** Related to the above, the ioctl provides no mechanism for the kernel to tell userspace how many fault entries were actually copied. If the user queries the size, allocates memory, then calls again, new faults may have been added in between. The user gets back exactly the number they requested, but has no way to know if there are additional faults available. For a query interface, a pattern like "return the total available count in a field so the user can re-query" would be more useful.

**`xe_vm_fault` reserved fields not validated on read-back.** The `struct xe_vm_fault` has `pad` and `reserved` MBZ fields, but since these are output-only structs (kernel writes them, user reads them), validation isn't needed. The kernel correctly zero-fills them via `kcalloc` and zero-initialized `fault_entry`. This is fine.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-02-24  0:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23 17:21 [PATCH v35 0/4] drm/xe/xe_vm: Implement xe_vm_get_property_ioctl Jonathan Cavitt
2026-02-23 17:21 ` [PATCH v35 1/4] drm/xe/xe_pagefault: Disallow writes to read-only VMAs Jonathan Cavitt
2026-02-24  0:00   ` Claude review: " Claude Code Review Bot
2026-02-23 17:21 ` [PATCH v35 2/4] drm/xe/uapi: Define drm_xe_vm_get_property Jonathan Cavitt
2026-02-24  0:00   ` Claude review: " Claude Code Review Bot
2026-02-23 17:21 ` [PATCH v35 3/4] drm/xe/xe_vm: Add per VM fault info Jonathan Cavitt
2026-02-24  0:00   ` Claude review: " Claude Code Review Bot
2026-02-23 17:21 ` [PATCH v35 4/4] drm/xe/xe_vm: Implement xe_vm_get_property_ioctl Jonathan Cavitt
2026-02-24  0:00   ` Claude Code Review Bot [this message]
2026-02-23 23:59 ` Claude review: " Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-03-06 15:55 [PATCH v36 0/4] " Jonathan Cavitt
2026-03-06 15:56 ` [PATCH v36 4/4] " Jonathan Cavitt
2026-03-08 22:42   ` Claude review: " Claude Code Review Bot
2026-03-08 22:42 ` Claude Code Review Bot
2026-03-10 14:49 [PATCH v37 0/4] " Jonathan Cavitt
2026-03-10 14:49 ` [PATCH v37 4/4] " Jonathan Cavitt
2026-03-11  3:13   ` Claude review: " Claude Code Review Bot
2026-03-11  3:12 ` Claude Code Review Bot
2026-03-20 18:35 [PATCH v38 0/4] " Jonathan Cavitt
2026-03-20 18:35 ` [PATCH v38 4/4] " Jonathan Cavitt
2026-03-21 17:27   ` Claude review: " Claude Code Review Bot
2026-03-21 17:27 ` Claude Code Review Bot
2026-03-24 15:29 [PATCH v39 0/4] " Jonathan Cavitt
2026-03-24 15:29 ` [PATCH v39 4/4] " Jonathan Cavitt
2026-03-24 20:46   ` Claude review: " Claude Code Review Bot
2026-03-24 20:46 ` 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-patch4-20260223172120.98961-10-jonathan.cavitt@intel.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