mbox series

[RFC,00/11] Add UEFI support for RISC-V

Message ID 20200625234516.31406-1-atish.patra@wdc.com
Headers show
Series Add UEFI support for RISC-V | expand

Message

Atish Patra June 25, 2020, 11:45 p.m. UTC
This series adds UEFI support for RISC-V.

Linux kernel: 5.8-rc2
U-Boot: master
OpenSBI: master

Patch 1-6 are preparatory patches that fixes some of the geric efi and riscv issues.

Patch 7-9 adds the efi stub support for RISC-V which was reviewed few months back.
http://lists.infradead.org/pipermail/linux-riscv/2020-April/009586.html

Patch 10 just renames arm-init code so that it can be used across different
architectures. Patch 11 adds the runtime services for RISC-V.

The patches can also be found in following git repo.
https://github.com/atishp04/linux/tree/uefi_riscv_5.9_v1

The patches have been verified on Qemu using bootefi command in U-Boot for both
RV32 and RV64.

For RV32, maximum allocated memory should be 1G as RISC-V kernel can not map
beyond 1G of physical memory for RV32.

EDK2 can boot quite far into Linux with current series. Currently, we are seeing
some traps from drivers (spi/network). At first glance, they don't seem to be
caused by efi. I thought it is better to get some early feedback on the series
while EDK2 issue is being debugged.

That's why uefi runtime services are not actually well tested in RISC-V.
Any suggestions to test the efi run time services are appreciated. 

Changes from previous version:
1. Added full ioremap support. 
2. Added efi runtime services support. 
3. Fixes mm issues

Anup Patel (1):
RISC-V: Move DT mapping outof fixmap

Atish Patra (10):
efi: Fix gcc error around __umoddi3 for 32 bit builds
RISC-V: Setup exception vector early
RISC-V: Add early ioremap support
RISC-V: Set maximum number of mapped pages correctly
riscv: Parse all memory blocks to remove unusable memory
include: pe.h: Add RISC-V related PE definition
RISC-V: Add PE/COFF header for EFI stub
RISC-V: Add EFI stub support.
efi: Rename arm-init to efi-init common for all arch
RISC-V: Add EFI runtime services

arch/riscv/Kconfig                            |  25 ++++
arch/riscv/Makefile                           |   1 +
arch/riscv/configs/defconfig                  |   1 +
arch/riscv/include/asm/Kbuild                 |   1 +
arch/riscv/include/asm/efi.h                  |  56 +++++++
arch/riscv/include/asm/fixmap.h               |  16 +-
arch/riscv/include/asm/io.h                   |   1 +
arch/riscv/include/asm/mmu.h                  |   2 +
arch/riscv/include/asm/pgalloc.h              |  12 ++
arch/riscv/include/asm/pgtable.h              |   4 +
arch/riscv/include/asm/sections.h             |  13 ++
arch/riscv/kernel/Makefile                    |   5 +
arch/riscv/kernel/efi-header.S                | 104 +++++++++++++
arch/riscv/kernel/efi.c                       | 106 +++++++++++++
arch/riscv/kernel/head.S                      |  27 +++-
arch/riscv/kernel/head.h                      |   2 -
arch/riscv/kernel/image-vars.h                |  51 +++++++
arch/riscv/kernel/setup.c                     |  16 +-
arch/riscv/kernel/smpboot.c                   |   1 -
arch/riscv/kernel/traps.c                     |   8 +-
arch/riscv/kernel/vmlinux.lds.S               |  22 ++-
arch/riscv/mm/init.c                          | 104 ++++++++-----
drivers/firmware/efi/Kconfig                  |   3 +-
drivers/firmware/efi/Makefile                 |   4 +-
.../firmware/efi/{arm-init.c => efi-init.c}   |   0
drivers/firmware/efi/libstub/Makefile         |  10 ++
drivers/firmware/efi/libstub/alignedmem.c     |   2 +-
drivers/firmware/efi/libstub/efi-stub.c       |  11 +-
drivers/firmware/efi/libstub/riscv-stub.c     | 110 ++++++++++++++
drivers/firmware/efi/riscv-runtime.c          | 141 ++++++++++++++++++
include/linux/pe.h                            |   3 +
31 files changed, 796 insertions(+), 66 deletions(-)
create mode 100644 arch/riscv/include/asm/efi.h
create mode 100644 arch/riscv/include/asm/sections.h
create mode 100644 arch/riscv/kernel/efi-header.S
create mode 100644 arch/riscv/kernel/efi.c
create mode 100644 arch/riscv/kernel/image-vars.h
rename drivers/firmware/efi/{arm-init.c => efi-init.c} (100%)
create mode 100644 drivers/firmware/efi/libstub/riscv-stub.c
create mode 100644 drivers/firmware/efi/riscv-runtime.c

--
2.24.0

Comments

Atish Patra June 26, 2020, 9:56 p.m. UTC | #1
On Thu, Jun 25, 2020 at 7:43 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 6/26/20 1:45 AM, Atish Patra wrote:
> > 32bit gcc doesn't support modulo operation on 64 bit data. It results in
> > a __umoddi3 error while building EFI for 32 bit.
> >
> > Use bitwise operations instead of modulo operations to fix the issue.
> >
> > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > ---
> >  drivers/firmware/efi/libstub/alignedmem.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/firmware/efi/libstub/alignedmem.c b/drivers/firmware/efi/libstub/alignedmem.c
> > index cc89c4d6196f..1de9878ddd3a 100644
> > --- a/drivers/firmware/efi/libstub/alignedmem.c
> > +++ b/drivers/firmware/efi/libstub/alignedmem.c
> > @@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
> >       *addr = ALIGN((unsigned long)alloc_addr, align);
> >
> >       if (slack > 0) {
> > -             int l = (alloc_addr % align) / EFI_PAGE_SIZE;
> > +             int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
>
> Here you rely on the compiler to silently convert the division by
> EFI_PAGE_SIZE into a right shift. Wouldn't it be cleaner to use
> EFI_PAGE_SHIFT to explicitly avoid a dependency on __udivdi3()?
>
> slack = (align >> EFI_PAGE_SHIFT) - 1;
> ...
> int l = (alloc_addr & (align - 1)) >> EFI_PAGE_SHIFT;
>

Sure. I will update it in the next version. Thanks for the suggestion.
> Best regards
>
> Heinrich
>
> >
> >               if (l) {
> >                       efi_bs_call(free_pages, alloc_addr, slack - l + 1);
> >
>
Ard Biesheuvel June 26, 2020, 10:03 p.m. UTC | #2
On Fri, 26 Jun 2020 at 23:56, Atish Patra <atishp@atishpatra.org> wrote:
>
> On Thu, Jun 25, 2020 at 7:43 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > On 6/26/20 1:45 AM, Atish Patra wrote:
> > > 32bit gcc doesn't support modulo operation on 64 bit data. It results in
> > > a __umoddi3 error while building EFI for 32 bit.
> > >
> > > Use bitwise operations instead of modulo operations to fix the issue.
> > >
> > > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > > ---
> > >  drivers/firmware/efi/libstub/alignedmem.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/firmware/efi/libstub/alignedmem.c b/drivers/firmware/efi/libstub/alignedmem.c
> > > index cc89c4d6196f..1de9878ddd3a 100644
> > > --- a/drivers/firmware/efi/libstub/alignedmem.c
> > > +++ b/drivers/firmware/efi/libstub/alignedmem.c
> > > @@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
> > >       *addr = ALIGN((unsigned long)alloc_addr, align);
> > >
> > >       if (slack > 0) {
> > > -             int l = (alloc_addr % align) / EFI_PAGE_SIZE;
> > > +             int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
> >
> > Here you rely on the compiler to silently convert the division by
> > EFI_PAGE_SIZE into a right shift. Wouldn't it be cleaner to use
> > EFI_PAGE_SHIFT to explicitly avoid a dependency on __udivdi3()?
> >
> > slack = (align >> EFI_PAGE_SHIFT) - 1;
> > ...
> > int l = (alloc_addr & (align - 1)) >> EFI_PAGE_SHIFT;
> >
>
> Sure. I will update it in the next version. Thanks for the suggestion.

Please don't. Dividing by EFI_PAGE_SIZE is perfectly fine, and is more readable.
Ard Biesheuvel June 27, 2020, 9:22 a.m. UTC | #3
On Sat, 27 Jun 2020 at 00:03, Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Fri, 26 Jun 2020 at 23:56, Atish Patra <atishp@atishpatra.org> wrote:
> >
> > On Thu, Jun 25, 2020 at 7:43 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> > >
> > > On 6/26/20 1:45 AM, Atish Patra wrote:
> > > > 32bit gcc doesn't support modulo operation on 64 bit data. It results in
> > > > a __umoddi3 error while building EFI for 32 bit.
> > > >
> > > > Use bitwise operations instead of modulo operations to fix the issue.
> > > >
> > > > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > > > ---
> > > >  drivers/firmware/efi/libstub/alignedmem.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/firmware/efi/libstub/alignedmem.c b/drivers/firmware/efi/libstub/alignedmem.c
> > > > index cc89c4d6196f..1de9878ddd3a 100644
> > > > --- a/drivers/firmware/efi/libstub/alignedmem.c
> > > > +++ b/drivers/firmware/efi/libstub/alignedmem.c
> > > > @@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
> > > >       *addr = ALIGN((unsigned long)alloc_addr, align);
> > > >
> > > >       if (slack > 0) {
> > > > -             int l = (alloc_addr % align) / EFI_PAGE_SIZE;
> > > > +             int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
> > >
> > > Here you rely on the compiler to silently convert the division by
> > > EFI_PAGE_SIZE into a right shift. Wouldn't it be cleaner to use
> > > EFI_PAGE_SHIFT to explicitly avoid a dependency on __udivdi3()?
> > >
> > > slack = (align >> EFI_PAGE_SHIFT) - 1;
> > > ...
> > > int l = (alloc_addr & (align - 1)) >> EFI_PAGE_SHIFT;
> > >
> >
> > Sure. I will update it in the next version. Thanks for the suggestion.
>
> Please don't. Dividing by EFI_PAGE_SIZE is perfectly fine, and is more readable.

Actually, I will take this patch as a fix right away - 32-bit ARM has
the same issue (although it does not actually incorporate this object
file)

In the meantime, please check how the stub gets pulled into your
kernel: the idea of a static library is that only the objects that are
used are included in the final build, but this turned out to be broken
for arm64 [0]. IOW, simply applying a similar change might fix your
build issue as well (assuming RISC-V does not actually call
efi_allocate_pages_aligned() anywhere)

[0] https://lore.kernel.org/linux-arm-kernel/20200604022031.164207-1-masahiroy@kernel.org/
Atish Patra June 29, 2020, 8:09 p.m. UTC | #4
On Sat, Jun 27, 2020 at 2:22 AM Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Sat, 27 Jun 2020 at 00:03, Ard Biesheuvel <ardb@kernel.org> wrote:
> >
> > On Fri, 26 Jun 2020 at 23:56, Atish Patra <atishp@atishpatra.org> wrote:
> > >
> > > On Thu, Jun 25, 2020 at 7:43 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> > > >
> > > > On 6/26/20 1:45 AM, Atish Patra wrote:
> > > > > 32bit gcc doesn't support modulo operation on 64 bit data. It results in
> > > > > a __umoddi3 error while building EFI for 32 bit.
> > > > >
> > > > > Use bitwise operations instead of modulo operations to fix the issue.
> > > > >
> > > > > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > > > > ---
> > > > >  drivers/firmware/efi/libstub/alignedmem.c | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/firmware/efi/libstub/alignedmem.c b/drivers/firmware/efi/libstub/alignedmem.c
> > > > > index cc89c4d6196f..1de9878ddd3a 100644
> > > > > --- a/drivers/firmware/efi/libstub/alignedmem.c
> > > > > +++ b/drivers/firmware/efi/libstub/alignedmem.c
> > > > > @@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
> > > > >       *addr = ALIGN((unsigned long)alloc_addr, align);
> > > > >
> > > > >       if (slack > 0) {
> > > > > -             int l = (alloc_addr % align) / EFI_PAGE_SIZE;
> > > > > +             int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
> > > >
> > > > Here you rely on the compiler to silently convert the division by
> > > > EFI_PAGE_SIZE into a right shift. Wouldn't it be cleaner to use
> > > > EFI_PAGE_SHIFT to explicitly avoid a dependency on __udivdi3()?
> > > >
> > > > slack = (align >> EFI_PAGE_SHIFT) - 1;
> > > > ...
> > > > int l = (alloc_addr & (align - 1)) >> EFI_PAGE_SHIFT;
> > > >
> > >
> > > Sure. I will update it in the next version. Thanks for the suggestion.
> >
> > Please don't. Dividing by EFI_PAGE_SIZE is perfectly fine, and is more readable.
>
> Actually, I will take this patch as a fix right away - 32-bit ARM has
> the same issue (although it does not actually incorporate this object
> file)
>

Thanks. I will drop it from my next version in that case.

> In the meantime, please check how the stub gets pulled into your
> kernel: the idea of a static library is that only the objects that are
> used are included in the final build, but this turned out to be broken
> for arm64 [0]. IOW, simply applying a similar change might fix your
> build issue as well (assuming RISC-V does not actually call
> efi_allocate_pages_aligned() anywhere)
>
Sorry. I missed this thread earlier. Yes. Applying a similar change
fixes the static library linking for RISC-V. I don't see
efi_allocate_pages_aligned or efi_random_alloc
in vmlinux anymore. I will update my patch. Thanks.

I did not see any new version of the next patch in that series [1].
Thus, I am leaving libstub/Makefile changes
as it is. Please let me know if I missed something.

[1] https://lore.kernel.org/linux-efi/CAMj1kXGg-w6N7jyG0pBJmeRctAhG2wWGoU=ryWj+Qi2UH-_m9Q@mail.gmail.com/

> [0] https://lore.kernel.org/linux-arm-kernel/20200604022031.164207-1-masahiroy@kernel.org/