From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot 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 Message-ID: In-Reply-To: <20260312173227.7e9f0389@fedora> References: <20260312173227.7e9f0389@fedora> <20260312173227.7e9f0389@fedora> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review **Commit message**: The bug report and analysis are well described. The sub= ject line has an odd capitalization: "Fix Map huge page mapping" =E2=80=94 = should probably be "Fix huge page mapping" or "fix map huge page race in fa= ult 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()` unconditi= onally. 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` sectio= n). The function body should be guarded by `#ifdef CONFIG_ARCH_SUPPORTS_HUG= E_PFNMAP` (or at minimum `CONFIG_TRANSPARENT_HUGEPAGE`) to avoid build fail= ures on configs without THP support. The `#ifdef` is only on the struct mem= ber assignment, but the function body itself will fail to compile without t= he 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 ha= ndles the PMD-level locking differently, and `vmf_insert_pfn_pmd()` itself = should handle the case where the PMD is already populated. However, this sh= ould be explicitly called out in the commit message as an intentional chang= e. **Coding style =E2=80=94 `#ifdef` indentation inside struct:** ```c const struct vm_operations_struct drm_gem_shmem_vm_ops =3D { .fault =3D drm_gem_shmem_fault, #ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP .huge_fault =3D 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 =3D drm_gem_shmem_huge_fault, #endif ``` **`drm_gem_shmem_huge_fault` only handles `PMD_ORDER`:** The function explicitly checks `if (order !=3D PMD_ORDER)` and falls back. = This is fine for the current use case, but the vfio implementation (which t= his mirrors) handles both `PMD_ORDER` and `PUD_ORDER` with a `switch` state= ment. 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_FALLBAC= K`, 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_PFNMA= P`. The new code uses `CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP` for the struct mem= ber. These are different Kconfig symbols =E2=80=94 `HUGE_PFNMAP` is a super= set 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 pre= processor directive indentation, and (3) clean up the commit subject line. --- Generated by Claude Code Patch Reviewer