Re: [PATCH] riscv: check leaf entry alignment in pageattr_pxd_entry()

From: Austin Kim

Date: Mon May 25 2026 - 09:26:07 EST


Hello Paul,

2026년 5월 23일 (토) 오전 8:34, Paul Walmsley <pjw@xxxxxxxxxx>님이 작성:
>
> Hi Austin,
>
> On Mon, 20 Apr 2026, Austin Kim wrote:
>
> > During page table walking, ensure the range being processed matches
> > the expected size of a leaf entry (P4D, PUD, or PMD). While pxd_addr_end()
> > functions handle boundary checks, they do not inherently validate whether
> > the entry is a leaf node of the expected size.
> >
> > Add WARN_ON_ONCE() to detect misalignments or partial updates of huge
> > pages. If a mismatch is detected, return -EINVAL to prevent potential
> > corruption of page table entries.
> >
> > Signed-off-by: Austin Kim <austindh.kim@xxxxxxxxx>
>
> Is this in response to a failure mode that you've seen? Or is it simply
> prophylactic?
>
> Seems like a better place for this might be in common code, so other
> architectures could benefit as well?

The answer is that this change is mainly prophylactic,
although it was tested on a RISC-V board to make sure
it does not introduce any unexpected side effects.

The pageattr_p4d_entry() function is registered as a callback
and is called from the page walker code:

mm/pagewalk.c
static int walk_p4d_range(pgd_t *pgd, unsigned long addr,
unsigned long end,
struct mm_walk *walk)
{
...
if (ops->p4d_entry) {
err = ops->p4d_entry(p4d, addr, next, walk);

With the current code flow, this condition should not be reachable in
normal operation.
The WARN_ON() is intended to catch unexpected situations if the page
walker behavior changes
in the future or if related code is modified.

I will also look for a more common place where a similar check
could be implemented so that other architectures may benefit as well.

Thank you for your feedback.

BR,
Austin Kim

>
>
> - Paul