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/appletbdrm: Use kvzalloc for big allocations
Date: Thu, 23 Apr 2026 09:55:24 +1000	[thread overview]
Message-ID: <review-overall-302f22e3-5390-4c0a-aa06-bfd02a3175c0@suse.de> (raw)
In-Reply-To: <302f22e3-5390-4c0a-aa06-bfd02a3175c0@suse.de>

Overall Series Review

Subject: Re: [PATCH] drm/appletbdrm: Use kvzalloc for big allocations
Author: Thomas Zimmermann <tzimmermann@suse.de>
Patches: 4
Reviewed: 2026-04-23T09:55:24.383215

---

This is a single patch that attempts to fix rare OOM failures in the appletbdrm driver by switching the frame request buffer from `kzalloc`/`kfree` to `kvzalloc`/`kvfree`. The motivation is sound — the Apple Touch Bar is ~2000x80 pixels, so a full damage update produces a request buffer on the order of 500-640 KB (depending on format), which requires a high-order contiguous allocation that can fail under memory fragmentation.

**However, the patch introduces a critical correctness bug.** The allocated buffer is passed directly to `usb_bulk_msg()`, which in turn calls `dma_map_single()` on the buffer via the USB HCD DMA mapping path. The kernel's DMA mapping layer **explicitly rejects vmalloc addresses**:

```c
/* include/linux/dma-mapping.h:512-515 */
/* DMA must never operate on areas that might be remapped. */
if (dev_WARN_ONCE(dev, is_vmalloc_addr(ptr),
		  "rejecting DMA map of vmalloc memory\n"))
	return DMA_MAPPING_ERROR;
```

If `kvzalloc` falls back to `vmalloc` (which is the entire point of the change), passing that buffer to `usb_bulk_msg()` will trigger a `WARN_ONCE`, the DMA mapping will fail with `DMA_MAPPING_ERROR`, and the USB transfer will return `-EAGAIN`. This would make the display non-functional under exactly the memory pressure conditions the patch is meant to fix.

**Recommended alternatives:**

1. **`kzalloc(request_size, GFP_KERNEL | __GFP_RETRY_MAYFAIL)`** — instructs the allocator to try harder (compaction, reclaim) without the hard failure semantics, while keeping the allocation physically contiguous and DMA-safe. This is the simplest correct fix.
2. **Restructure to use scatterlist-based USB transfers** — allows fragmented physical pages, but requires significant refactoring.
3. **Use `usb_alloc_coherent()`** — provides a DMA-safe buffer, but changes the allocation/free API.

---

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-04-22 23:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 12:17 [PATCH] drm/appletbdrm: Use kvzalloc for big allocations Sasha Finkelstein
2026-04-20 13:30 ` Thomas Zimmermann
2026-04-22 23:55   ` Claude review: " Claude Code Review Bot
2026-04-22 23:55   ` Claude Code Review Bot [this message]
2026-04-20 13:47 ` Thomas Zimmermann
2026-04-20 14:03 ` Aditya Garg

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-overall-302f22e3-5390-4c0a-aa06-bfd02a3175c0@suse.de \
    --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