Re: [PATCH v2 4/7] ARM: mm: print out correct page table entries

From: Russell King (Oracle)
Date: Wed Jun 02 2021 - 06:45:04 EST


On Wed, Jun 02, 2021 at 03:02:43PM +0800, Kefeng Wang wrote:
> Like commit 67ce16ec15ce ("arm64: mm: print out correct page table entries")
> does, drop the struct mm_struct argument of show_pte(), print the tables
> based on the faulting address.
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>

This can be misleading on 32-bit ARM.

The effective page tables for each thread are the threads *own* page
tables. There is no hardware magic for addresses above PAGE_OFFSET being
directed to the init_mm page tables.

So, when we hit a fault in kernel space, we need to be printing the
currently in-use page tables associated with the running thread.

Hence:

> /*
> - * This is useful to dump out the page tables associated with
> - * 'addr' in mm 'mm'.
> + * Dump out the page tables associated with 'addr' in the currently active mm
> */
> -void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr)
> +void show_pte(const char *lvl, unsigned long addr)
> {
> pgd_t *pgd;
> -
> - if (!mm)
> + struct mm_struct *mm;
> +
> + if (addr < TASK_SIZE) {
> + mm = current->active_mm;
> + if (mm == &init_mm) {
> + printk("%s[%08lx] user address but active_mm is swapper\n",
> + lvl, addr);
> + return;
> + }
> + } else {
> mm = &init_mm;
> + }

is incorrect here.

It's completely fine for architectures where kernel accesses always go
to the init_mm page tables, but for 32-bit ARM that is not the case.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!