qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 3/3] hw/riscv: clear kernel_entry higher bits in load_elf_


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v7 3/3] hw/riscv: clear kernel_entry higher bits in load_elf_ram_sym()
Date: Mon, 16 Jan 2023 10:25:19 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1

On 13/1/23 18:18, Daniel Henrique Barboza wrote:
Recent hw/risc/boot.c changes caused a regression in an use case with
the Xvisor hypervisor. Running a 32 bit QEMU guest with '-kernel'
stopped working. The reason seems to be that Xvisor is using 64 bit to
encode the 32 bit addresses from the guest, and load_elf_ram_sym() is
sign-extending the result with '1's [1].

This can very well be an issue with Xvisor, but since it's not hard to
amend it in our side we're going for it. Use a translate_fn() callback
to be called by load_elf_ram_sym() and clear the higher bits of the
result if we're running a 32 bit CPU.

[1] https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg02281.html

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
  hw/riscv/boot.c            | 23 ++++++++++++++++++++++-
  hw/riscv/microchip_pfsoc.c |  4 ++--
  hw/riscv/opentitan.c       |  3 ++-
  hw/riscv/sifive_e.c        |  3 ++-
  hw/riscv/sifive_u.c        |  4 ++--
  hw/riscv/spike.c           |  2 +-
  hw/riscv/virt.c            |  4 ++--
  include/hw/riscv/boot.h    |  1 +
  8 files changed, 34 insertions(+), 10 deletions(-)

+static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
+{
+    RISCVHartArrayState *harts = opaque;
+
+    /*
+     * For 32 bit CPUs, kernel_load_base is sign-extended (i.e.
+     * it can be padded with '1's) if the hypervisor, for some
+     * reason, is using 64 bit addresses with 32 bit guests.
+     *
+     * Clear the higher bits to avoid the padding if we're
+     * running a 32 bit CPU.
+     */
+    if (riscv_is_32bit(harts)) {
+        return addr & 0x0fffffff;

Instead of this magic mask, can we add some architectural definition
in target/riscv/cpu_bits.h and use it as:

           return extract64(addr, 0, xxx_ADDR_BITS);

to make the code self-descriptive?

Otherwise LGTM, thanks!

+    }
+
+    return addr;
+}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]