[PATCH] armv8: mmu: don't panic when unmapping a page which isn't mapped
Ilias Apalodimas
ilias.apalodimas at linaro.org
Tue Jun 23 16:33:31 CEST 2026
On Tue, 23 Jun 2026 at 12:17, Ilias Apalodimas
<ilias.apalodimas at linaro.org> wrote:
>
> On Tue, 23 Jun 2026 at 12:07, Ilias Apalodimas
> <ilias.apalodimas at linaro.org> wrote:
> >
> > On Fri, 12 Jun 2026 at 14:32, Casey Connolly <casey.connolly at linaro.org> wrote:
> > >
> > > If a caller tries to unmap a single page which is already part of an
> > > unmapped block, set_one_region() will panic since there isn't a valid
> > > block or table to contain the page. Detect this case explicitly and
> > > return since no action needs to be taken.
> > >
> > > Signed-off-by: Casey Connolly <casey.connolly at linaro.org>
> > > ---
> > > Depends on my previous series which fixes unmapping regions
> > >
> > > https://lore.kernel.org/u-boot/20260608-b4-mmu-unmap-fixes-v6-0-ac0764cccf40@linaro.org/
> > > ---
> >
> > Acked-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> >
> > > arch/arm/cpu/armv8/cache_v8.c | 5 +++++
> > > 1 file changed, 5 insertions(+)
> > >
> > > diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c
> > > index 6c85022556ad..472887b5d99b 100644
> > > --- a/arch/arm/cpu/armv8/cache_v8.c
> > > +++ b/arch/arm/cpu/armv8/cache_v8.c
> > > @@ -1003,8 +1003,13 @@ static u64 set_one_region(u64 start, u64 size, u64 attrs, bool flag, int level)
> > > int levelshift = level2shift(level);
> > > u64 levelsize = 1ULL << levelshift;
> > > u64 *pte = find_pte(start, level);
> > >
> > > + /* Trying to unmap a region which is part of an already unmapped block, nothing to do */
> > > + if (pte_type(pte) == PTE_TYPE_FAULT && attrs == PTE_TYPE_FAULT && size < levelsize) {
> > > + return size;
> > > + }
>
> On a second thought, you should check the size of the region as well.
> What if the user starts from an unmapped region with size X but
> requests to unmap a size Y with Y > X?
Just to make the response a bit clearer.
Add these on the qemu board_late_init()
mmu_change_region_attr_nobreak(0x40200000, 0x200000, PTE_TYPE_FAULT);
mmu_change_region_attr_nobreak(0x40200000, 0x2000, PTE_TYPE_FAULT);
mmu_change_region_attr_nobreak(0x40300000, 0x101000, PTE_TYPE_FAULT);
meminfo says:
[0x0000013ffea000] | Table | |
|
[0x00000040000000 - 0x00000040200000] | Block | RWX |
Normal | Inner-shareable
[0x00000040200000 - 0x00000040400000] | Fault | RWX |
Normal | Inner-shareable
[0x00000040400000 - 0x00000080000000] | Block | RWX |
Normal | Inner-shareable
Cheers
/Ilias
>
> Thanks
> /Ilias
> > > +
> > > /* Can we can just modify the current level block/page? */
> > > if (is_aligned(start, size, levelsize)) {
> > > if (attrs == PTE_TYPE_FAULT) {
> > > if (pte_type(pte) == PTE_TYPE_TABLE && level < 3)
> > > --
> > > 2.53.0
> > >
More information about the U-Boot
mailing list