From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: drm/shmem-helper: Fix Map huge page mapping in fault handler Date: Sat, 14 Mar 2026 06:52:14 +1000 Message-ID: In-Reply-To: <20260313141719.3949700-1-pedrodemargomes@gmail.com> References: <20260313141719.3949700-1-pedrodemargomes@gmail.com> <20260313141719.3949700-1-pedrodemargomes@gmail.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review **Correctness of the fix:** The approach is sound. By moving the PMD mappin= g to `.huge_fault`, the mm subsystem handles the dispatch between PTE-level= and PMD-level faults, eliminating the race. This is the correct way to do = it =E2=80=94 the old code was essentially doing huge page mapping opportuni= stically from the regular `.fault` path, which is inherently racy. **Unused variable warning when `CONFIG_ARCH_SUPPORTS_PMD_PFNMAP` is not set= :** ```c static vm_fault_t drm_gem_shmem_any_fault(struct vm_fault *vmf, unsigned int order) { ... unsigned long paddr; bool aligned; ``` The variables `paddr` and `aligned` are declared at function scope but only= used inside the `#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP` block in `case PM= D_ORDER:`. When that config is disabled, these variables are unused and wil= l produce compiler warnings (`-Wunused-variable`). They should be moved ins= ide the `case PMD_ORDER:` block (with braces around the case body), or `__m= aybe_unused` could be applied, though moving them is cleaner. That said, in practice `drm_gem_shmem_any_fault` is only called with `order= !=3D 0` from `drm_gem_shmem_huge_fault`, which is only compiled when `CONF= IG_ARCH_SUPPORTS_HUGE_PFNMAP` is set, which implies `CONFIG_ARCH_SUPPORTS_P= MD_PFNMAP` is also set (per `mm/Kconfig`). So the code is functionally corr= ect, but the warning is still a build issue for configurations without thes= e options enabled (where `.fault` still calls `drm_gem_shmem_any_fault(vmf,= 0)` and the variables are dead code). **Dropped `pmd_none()` check:** The old 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(pages[page_offset]))) { pfn &=3D PMD_MASK >> PAGE_SHIFT; ret =3D vmf_insert_pfn_pmd(vmf, pfn, false); } ``` This is fine. In the old code, the `pmd_none` check was needed because the = code was being called from the regular `.fault` path where the PMD might al= ready be populated with PTEs. In the new `.huge_fault` path, the mm subsyst= em ensures we're only called when a PMD-level mapping is appropriate, so `v= mf_insert_pfn_pmd()` can handle any existing PMD state internally (returnin= g an appropriate error/fallback if needed). **Minor style nit =E2=80=94 commit subject:** "Fix Map huge page mapping" h= as an odd capitalisation of "Map". Consider: "Fix huge page mapping race in= fault handler". **Missing `default:` case in switch:** ```c switch (order) { case 0: ret =3D vmf_insert_pfn(vma, vmf->address, pfn); break; #ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP case PMD_ORDER: ... break; #endif } ``` There's no `default:` case. If an unexpected order is passed, `ret` remains= `VM_FAULT_FALLBACK` (from initialization), which is the right behavior, bu= t a `default: break;` would be clearer and would silence any `-Wswitch` war= nings if new enum values were ever relevant. The VFIO version (`vfio_pci_vm= f_insert_pfn`) explicitly has a `default: return VM_FAULT_FALLBACK;`. This = is very minor since `drm_gem_shmem_huge_fault` already filters for `PMD_ORD= ER` only. **Overall:** Good fix for a real bug. The pattern matches existing in-tree = usage (VFIO). The unused variable issue should be fixed before merging, but= otherwise the patch looks correct. --- Generated by Claude Code Patch Reviewer