lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHVXubgu_Voet_TPB0z+yec4DG8TP2_nSTDUcQdW2yf20wvP1w@mail.gmail.com>
Date:   Tue, 13 Dec 2022 08:56:48 +0100
From:   Alexandre Ghiti <alexghiti@...osinc.com>
To:     Rob Herring <robh+dt@...nel.org>
Cc:     Paul Walmsley <paul.walmsley@...ive.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Albert Ou <aou@...s.berkeley.edu>, Guo Ren <guoren@...nel.org>,
        Frank Rowand <frowand.list@...il.com>,
        linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
        devicetree@...r.kernel.org, linux-arch@...r.kernel.org
Subject: Re: [PATCH v2] riscv: Use PUD/P4D/PGD pages for the linear mapping

Hi Rob,


On Mon, Dec 12, 2022 at 6:54 PM Rob Herring <robh+dt@...nel.org> wrote:
>
> On Mon, Dec 12, 2022 at 8:31 AM Alexandre Ghiti <alexghiti@...osinc.com> wrote:
> >
> > During the early page table creation, we used to set the mapping for
> > PAGE_OFFSET to the kernel load address: but the kernel load address is
> > always offseted by PMD_SIZE which makes it impossible to use PUD/P4D/PGD
> > pages as this physical address is not aligned on PUD/P4D/PGD size (whereas
> > PAGE_OFFSET is).
> >
> > But actually we don't have to establish this mapping (ie set va_pa_offset)
> > that early in the boot process because:
> >
> > - first, setup_vm installs a temporary kernel mapping and among other
> >   things, discovers the system memory,
> > - then, setup_vm_final creates the final kernel mapping and takes
> >   advantage of the discovered system memory to create the linear
> >   mapping.
> >
> > During the first phase, we don't know the start of the system memory and
> > then until the second phase is finished, we can't use the linear mapping at
> > all and phys_to_virt/virt_to_phys translations must not be used because it
> > would result in a different translation from the 'real' one once the final
> > mapping is installed.
> >
> > So here we simply delay the initialization of va_pa_offset to after the
> > system memory discovery. But to make sure noone uses the linear mapping
> > before, we add some guard in the DEBUG_VIRTUAL config.
> >
> > Finally we can use PUD/P4D/PGD hugepages when possible, which will result
> > in a better TLB utilization.
> >
> > Note that we rely on the firmware to protect itself using PMP.
> >
> > Signed-off-by: Alexandre Ghiti <alexghiti@...osinc.com>
> > ---
> >
> > v2:
> > - Add a comment on why RISCV64 does not need to set initrd_start/end that
> >   early in the boot process, as asked by Rob
> >
> > Note that this patch is rebased on top of:
> > [PATCH v1 1/1] riscv: mm: call best_map_size many times during linear-mapping
> >
> >  arch/riscv/include/asm/page.h | 16 ++++++++++++++++
> >  arch/riscv/mm/init.c          | 25 +++++++++++++++++++------
> >  arch/riscv/mm/physaddr.c      | 16 ++++++++++++++++
> >  drivers/of/fdt.c              |  7 ++++++-
> >  4 files changed, 57 insertions(+), 7 deletions(-)
>
> [...]
>
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 7b571a631639..012554445054 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -895,8 +895,13 @@ static void __early_init_dt_declare_initrd(unsigned long start,
> >          * enabled since __va() is called too early. ARM64 does make use
> >          * of phys_initrd_start/phys_initrd_size so we can skip this
> >          * conversion.
> > +        * On RISCV64, the usage of __va() before the linear mapping exists
> > +        * is wrong and RISCV64 rightly calls reserve_initrd_mem after it is
> > +        * available where it actually resets the translation that is done
> > +        * here and re-computes it.
>
> No, I want a single comment that covers both cases (and the next arch
> we add here). Something like this:
>
> __va() is not yet available this early on some platforms. In that
> case, the platform uses phys_initrd_start/phys_initrd_size instead and
> does the VA conversion itself.


I have just sent the v3, thanks for your reviews,

Alex

>
>
> Rob

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ