[PATCHv3 0/5] use __create_pgd_mapping() to implement idmap and unify codes

Catalin Marinas catalin.marinas at arm.com
Tue Jun 8 10:38:07 PDT 2021


On Tue, Jun 01, 2021 at 05:25:49PM +0800, Pingfan Liu wrote:
> On Tue, Jun 1, 2021 at 3:50 AM Ard Biesheuvel <ardb at kernel.org> wrote:
> > On Mon, 31 May 2021 at 10:46, Pingfan Liu <kernelfans at gmail.com> wrote:
> > > v2 -> v3:
> > >   -1. leave out the part of redefinition the CONFIG_PGTABLE_LEVEL,
> > > concentrate on sharing __create_pgd_mapping() in head.S as the first
> > > step.
> > >   -2. make IDMAP_PGTABLE_LEVELS use the max value ([3/5])
> > >
> > > rfc -> v2:
> > >   more debug and test
> > >
> > > *** Goal of this series ***
> > >
> > > __create_pgd_mapping() sets up the pgtable for mapping __va(paddr) ->
> > > paddr under the MMU-on situation.  Since pgtable upper level holds the
> > > paddr of the lower level, with a slight adaptation,
> > > __create_pgd_mapping() can also set up the mapping under the MMU-off
> > > situation. ([4/5])
> > >
> > > After that, both idmap_pg_dir and init_pg_dir can be created by
> > > __create_pgd_mapping(). And the counterpart asm code can be simplified.
> >
> > I understand the desire to simplify the page table construction code
> > in head.S, but up until now, we have been very careful to avoid
> > calling into C code with the MMU off. There are simply too many
> > assumptions in the compiler about the context the generated code will
> > execute in: one example is unaligned access, which must be disabled
> > for source files that may be called with the MMU off, as otherwise,
> > the compiler is permitted to emit loads and stores that are not
> > allowed on device memory (which is the default memory type used for
> > all memory with the MMU off)
>
> You are right. These C routines happen to use "unsigned long", which
> can exclude this unaligned case.
> To make an guarantee, is "-mno-unaligned-access" good enough?
> 
> Besides unaligned-access, any further risk originating from compiler
> assumption? (I think that the common optimization: reordering,
> merging, reloading on this "device" memory has no bad effect)

There's also instrumentation that needs disabling (kasan, ubsan, kcov,
gcov). You can look at arch/arm64/kvm/hyp/nvhe/Makefile for various
flags added or filtered out, though the KVM hyp code runs with the MMU
on. I'm not sure what other flags are needed to guarantee the generated
code can run with the MMU off but we can always ask the toolchain folk.

However, I'm still not convinced about sharing __create_pgd_mapping()
with the early head.S code. A better option would be a separate,
stand-alone file where we have more control on what gets called or
accessed (of course, if there's any value in going this route).

> > Do you have a killer use case for this feature? Or is it just a nice cleanup?
>
> Yes, in the omitted part in v2, I had planned to provide an unified
> page table manipulation routine, and provide an create_idmap() API. So
> there can be an handy interface to create a whole RAM addressable
> idmapX where needed.

Where would this be needed?

-- 
Catalin



More information about the linux-arm-kernel mailing list