From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: Re: [PATCH] drm/shmem-helper: Fix Map huge page mapping in fault handler
Date: Fri, 13 Mar 2026 13:58:40 +1000 [thread overview]
Message-ID: <review-patch1-20260312173227.7e9f0389@fedora> (raw)
In-Reply-To: <20260312173227.7e9f0389@fedora>
Patch Review
**Commit message**: The bug report and analysis are well described. The subject line has an odd capitalization: "Fix Map huge page mapping" — should probably be "Fix huge page mapping" or "fix map huge page race in fault handler".
**Missing `#ifdef` around the function definition itself:**
The new `drm_gem_shmem_huge_fault()` function calls `vmf_insert_pfn_pmd()` and references `PMD_ORDER`/`PMD_MASK`/`folio_test_pmd_mappable()` unconditionally. While `PMD_ORDER` is always defined (from `pgtable.h`), `vmf_insert_pfn_pmd()` is only declared when `CONFIG_TRANSPARENT_HUGEPAGE` is enabled (it's in `huge_mm.h` inside the `#ifdef CONFIG_TRANSPARENT_HUGEPAGE` section). The function body should be guarded by `#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP` (or at minimum `CONFIG_TRANSPARENT_HUGEPAGE`) to avoid build failures on configs without THP support. The `#ifdef` is only on the struct member assignment, but the function body itself will fail to compile without the declarations.
**Removed `pmd_none()` check:**
The original code had:
```c
if (aligned &&
pmd_none(*vmf->pmd) &&
folio_test_pmd_mappable(page_folio(page))) {
```
The new code drops the `pmd_none(*vmf->pmd)` check:
```c
if (aligned &&
folio_test_pmd_mappable(page_folio(page))) {
```
This is likely intentional because in the `huge_fault` path, the MM core handles the PMD-level locking differently, and `vmf_insert_pfn_pmd()` itself should handle the case where the PMD is already populated. However, this should be explicitly called out in the commit message as an intentional change.
**Coding style — `#ifdef` indentation inside struct:**
```c
const struct vm_operations_struct drm_gem_shmem_vm_ops = {
.fault = drm_gem_shmem_fault,
#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP
.huge_fault = drm_gem_shmem_huge_fault,
#endif
```
Kernel coding style requires preprocessor directives to start at column 0, not be indented with the struct members. This should be:
```c
#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP
.huge_fault = drm_gem_shmem_huge_fault,
#endif
```
**`drm_gem_shmem_huge_fault` only handles `PMD_ORDER`:**
The function explicitly checks `if (order != PMD_ORDER)` and falls back. This is fine for the current use case, but the vfio implementation (which this mirrors) handles both `PMD_ORDER` and `PUD_ORDER` with a `switch` statement. For DRM shmem this is probably fine since folio sizes wouldn't reach PUD scale, but it's worth noting.
**Return value from `vmf_insert_pfn_pmd` not fully handled:**
When the alignment/mappability check fails, `ret` remains `VM_FAULT_FALLBACK`, which will cause the MM core to retry with the regular `.fault` handler at PTE granularity. This is correct behavior.
**Missing `CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP` from the original `CONFIG_ARCH_SUPPORTS_PMD_PFNMAP`:**
The old code guarded the PMD insertion with `CONFIG_ARCH_SUPPORTS_PMD_PFNMAP`. The new code uses `CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP` for the struct member. These are different Kconfig symbols — `HUGE_PFNMAP` is a superset that also selects `PMD_PFNMAP` (via `mm/Kconfig`). This is the correct symbol to use for the `.huge_fault` callback, matching the pattern in `vfio_pci_core.c`.
**Overall**: The fix is correct in principle and addresses a real race. The main issues to fix before merge are: (1) wrap the function body in `#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP` to avoid build breakage, (2) fix the preprocessor directive indentation, and (3) clean up the commit subject line.
---
Generated by Claude Code Patch Reviewer
prev parent reply other threads:[~2026-03-13 3:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 15:50 [PATCH] drm/shmem-helper: Fix Map huge page mapping in fault handler Pedro Demarchi Gomes
2026-03-12 16:32 ` Boris Brezillon
2026-03-13 3:58 ` Claude review: " Claude Code Review Bot
2026-03-13 3:58 ` Claude Code Review Bot [this message]
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-patch1-20260312173227.7e9f0389@fedora \
--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