Re: [RFC V1 07/16] arm64/mm: Convert READ_ONCE() as p4dp_get() while accessing P4D

From: David Hildenbrand (Arm)

Date: Wed Apr 15 2026 - 06:35:19 EST


>>>
>>> @@ -2258,4 +2258,21 @@ int pmdp_test_and_clear_young(struct vm_area_struct *vma,
>>> }
>>> #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG */
>>>
>>> +#if CONFIG_PGTABLE_LEVELS > 3
>>> +phys_addr_t pud_offset_phys(p4d_t *p4dp, unsigned long addr)
>>> +{
>>> + p4d_t p4d = p4dp_get(p4dp);
>>> +
>>> + BUG_ON(!pgtable_l4_enabled());
>>
>> Heh, while at it, convert that to a VM_WARN_ON_ONCE() or anything else
>> that is not a BUG.
>>
>> I strongly assume CONFIG_DEBUG_VM checks are sufficient.
>
> There are multiple similar BUG_ON() instances
>
> arch/arm64/include/asm/pgtable.h: BUG_ON(!pgtable_l4_enabled());
> arch/arm64/include/asm/pgtable.h: BUG_ON(!pgtable_l5_enabled());
>
> arch/arm64/mm/mmu.c: BUG_ON(pmd_val(old_pmd) != 0 &&
> arch/arm64/mm/mmu.c: BUG_ON(pud_val(old_pud) != 0 &&
> arch/arm64/mm/mmu.c: BUG_ON(p4d_val(old_p4d) != 0 &&
>
> Shall we convert all of them as VM_WARN_ON_ONCE() in a separate patch
> as a pre-requisite ?

In MM at least, we fix them up when touching the code, and only
sometimes convert entire files.

As documented in Documentation/process/coding-style.rst, there might be
some exceptions where BUG_ON makes sense (severe data corruption
possible), and some cases would want to use WARN_ON_ONCE() + recovery code.

All of these cases here sound like VM_WARN_ON_ONCE() is more than
sufficient though, so feel free to convert them all in one shot.

--
Cheers,

David