[PATCH v3 08/11] mm/memory: convert print_bad_pte() to print_bad_page_map()
David Hildenbrand
david at redhat.com
Tue Aug 26 16:17:14 AEST 2025
On 26.08.25 07:25, Lorenzo Stoakes wrote:
> On Mon, Aug 25, 2025 at 02:31:00PM +0200, David Hildenbrand wrote:
>> On 11.08.25 13:26, David Hildenbrand wrote:
>>> print_bad_pte() looks like something that should actually be a WARN
>>> or similar, but historically it apparently has proven to be useful to
>>> detect corruption of page tables even on production systems -- report
>>> the issue and keep the system running to make it easier to actually detect
>>> what is going wrong (e.g., multiple such messages might shed a light).
>>>
>>> As we want to unify vm_normal_page_*() handling for PTE/PMD/PUD, we'll have
>>> to take care of print_bad_pte() as well.
>>>
>>> Let's prepare for using print_bad_pte() also for non-PTEs by adjusting the
>>> implementation and renaming the function to print_bad_page_map().
>>> Provide print_bad_pte() as a simple wrapper.
>>>
>>> Document the implicit locking requirements for the page table re-walk.
>>>
>>> To make the function a bit more readable, factor out the ratelimit check
>>> into is_bad_page_map_ratelimited() and place the printing of page
>>> table content into __print_bad_page_map_pgtable(). We'll now dump
>>> information from each level in a single line, and just stop the table
>>> walk once we hit something that is not a present page table.
>>>
>>> The report will now look something like (dumping pgd to pmd values):
>>>
>>> [ 77.943408] BUG: Bad page map in process XXX pte:80000001233f5867
>>> [ 77.944077] addr:00007fd84bb1c000 vm_flags:08100071 anon_vma: ...
>>> [ 77.945186] pgd:10a89f067 p4d:10a89f067 pud:10e5a2067 pmd:105327067
>>>
>>> Not using pgdp_get(), because that does not work properly on some arm
>>> configs where pgd_t is an array. Note that we are dumping all levels
>>> even when levels are folded for simplicity.
>>>
>>> Signed-off-by: David Hildenbrand <david at redhat.com>
>>> ---
>>> include/linux/pgtable.h | 19 ++++++++
>>> mm/memory.c | 104 ++++++++++++++++++++++++++++++++--------
>>> 2 files changed, 103 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
>>> index bff5c4241bf2e..33c84b38b7ec6 100644
>>> --- a/include/linux/pgtable.h
>>> +++ b/include/linux/pgtable.h
>>> @@ -1966,6 +1966,25 @@ enum pgtable_level {
>>> PGTABLE_LEVEL_PGD,
>>> };
>>> +static inline const char *pgtable_level_to_str(enum pgtable_level level)
>>> +{
>>> + switch (level) {
>>> + case PGTABLE_LEVEL_PTE:
>>> + return "pte";
>>> + case PGTABLE_LEVEL_PMD:
>>> + return "pmd";
>>> + case PGTABLE_LEVEL_PUD:
>>> + return "pud";
>>> + case PGTABLE_LEVEL_P4D:
>>> + return "p4d";
>>> + case PGTABLE_LEVEL_PGD:
>>> + return "pgd";
>>> + default:
>>> + VM_WARN_ON_ONCE(1);
>>> + return "unknown";
>>> + }
>>> +}
>>
>> One kernel config doesn't like the VM_WARN_ON_ONCE here, and I don't think we
>> really need it. @Andrew can you squash:
>
> Out of interest do you know why this is happening? xtensa right? Does
> xtensa not like CONFIG_DEBUG_VM?
We don't happen to include mmdebug.h in a xtensa configuration.
Briefly thought about using a BUILD_BUG_ON_INVALID(), but decided to
just drop it completely.
--
Cheers
David / dhildenb
More information about the Linuxppc-dev
mailing list