grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Kiper <dkiper@net-space.pl>
To: "Wu, Fei" <fei2.wu@intel.com>
Cc: grub-devel@gnu.org, agraf@suse.de,
	Alistair Francis <alistair.francis@wdc.com>,
	atishp@rivosinc.com
Subject: Re: Relocation overflow on RISC-V with multi-range memory layout
Date: Wed, 27 Sep 2023 12:08:26 +0200	[thread overview]
Message-ID: <20230927100826.jeq7cpynjene35zp@tomti.i.net-space.pl> (raw)
In-Reply-To: <97936b34-d2cc-dd3d-c8ee-e40a996c1cb8@intel.com>

Adding Atish...

On Wed, Sep 27, 2023 at 02:16:40PM +0800, Wu, Fei wrote:
> On 9/25/2023 4:51 PM, Wu, Fei wrote:
> > Hi All,
> >
> > I'm enabling PCIe passthrough on qemu riscv, the physical memory
> > range between 3GB and 4GB is reserved. Therefore if guest has 4GB ram,
> > two ranges are created as [2G, 3G) and [4G, 7G). More details can be
> > found here:
> > https://lore.kernel.org/all/CAKmqyKMtAzt5saCUMd4vXYfgAQibpzQJAhtTSuSb+yeKhcYpfw@mail.gmail.com/T/
> >
> > When run grub.efi from uefi shell, a relocation problem happened in
> > grub_arch_dl_relocate_symbols() of grub-core/kern/riscv/dl.c:
> >
> >         case R_RISCV_CALL:
> >         case R_RISCV_CALL_PLT:
> >           {
> >             grub_uint32_t *abs_place = place;
> >             grub_ssize_t off = sym_addr - (grub_addr_t) place;
> >             grub_uint32_t hi20, lo12;
> >
> >             if (off != (grub_int32_t) off)
> >               return grub_error (GRUB_ERR_BAD_MODULE, "relocation
> > overflow");
> >
> > It requires `off' in the range of int32, but it's not enforced since the
> >> 4GB memory can be used. I'm not familiar with grub, but this patch does
> > work for me:
> >
> > --- a/include/grub/riscv64/efi/memory.h
> > +++ b/include/grub/riscv64/efi/memory.h
> > @@ -1,6 +1,6 @@
> >  #ifndef GRUB_MEMORY_CPU_HEADER
> >  #include <grub/efi/memory.h>
> >
> > -#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
> > +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffULL
> >
> Anyone can help take a look? I will send it out for review if this is
> the right fix.
>
> The test I have done against commit db1faedcc:
>
> qemu-system-riscv64 -nographic \
>  -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
>  -m 3G -smp 2 \
>  -blockdev
> node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
>  -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
>  -device vfio-pci,host=01:00.0 -device vfio-pci,host=01:00.1 \
>  -device virtio-blk-device,drive=hd0 \
>  -drive file=fat:rw:/home/wufei/src/fat,id=hd0
>
> then run grubriscv64.efi on uefi shell:
>
> FS0:\> grubriscv64.efi
> ...
> ProtectUefiImageCommon - 0xBED9E540
>   - 0x00000000BDCCB000 - 0x00000000004DF000
> SetUefiImageMemoryAttributes - 0x00000000BDCCB000 - 0x0000000000001000
> (0x0000000000004000)
> CpuSetMemoryAttributes: Set memory attributes not supported yet
> SetUefiImageMemoryAttributes - 0x00000000BDCCC000 - 0x000000000000C000
> (0x0000000000020000)
> CpuSetMemoryAttributes: Set memory attributes not supported yet
> SetUefiImageMemoryAttributes - 0x00000000BDCD8000 - 0x00000000004D2000
> (0x0000000000004000)
> CpuSetMemoryAttributes: Set memory attributes not supported yet
> InstallProtocolInterface: 752F3136-4E16-4FDC-A22A-E5F46812F4CA 83FFF720
> CpuSetMemoryAttributes: Set memory attributes not supported yet
> relocation overflow
> Aborted. Press any key to exit
>
> Thanks,
> Fei.
> > Any comments?
> >
> > Thanks,
> > Fei.

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2023-09-27 10:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25  8:51 Relocation overflow on RISC-V with multi-range memory layout Wu, Fei
2023-09-27  6:16 ` Wu, Fei
2023-09-27 10:08   ` Daniel Kiper [this message]
2023-09-27 15:23 ` Vladimir 'phcoder' Serbinenko
2023-10-09  3:14   ` Wu, Fei
2023-10-11 10:20     ` Wu, Fei
2023-10-11 13:50       ` Vladimir 'phcoder' Serbinenko
2023-10-12  0:29         ` Wu, Fei
2023-10-14 21:16           ` Vladimir 'phcoder' Serbinenko
2023-11-02  6:48             ` Wu, Fei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230927100826.jeq7cpynjene35zp@tomti.i.net-space.pl \
    --to=dkiper@net-space.pl \
    --cc=agraf@suse.de \
    --cc=alistair.francis@wdc.com \
    --cc=atishp@rivosinc.com \
    --cc=fei2.wu@intel.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).