[PATCH v2] hw/loongarch/virt: Get physical entry address with elf file

Bibo Mao posted 1 patch 6 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250425021620.3968737-1-maobibo@loongson.cn
Maintainers: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>
There is a newer version of this series
hw/loongarch/boot.c | 1 +
1 file changed, 1 insertion(+)
[PATCH v2] hw/loongarch/virt: Get physical entry address with elf file
Posted by Bibo Mao 6 months, 3 weeks ago
With load_elf() api, image load low address and high address is converted
to physical address if parameter translate_fn is provided. However
executing entry address is still virtual address. Here convert entry
address into physical address, since MMU is disabled when system power on,
the first PC instruction should be physical address.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
  v1 ... v2:
  1. Only modify LoongArch specified rather than load_elf() API, since
     there is be potential influence with other architectures.
---
 hw/loongarch/boot.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 354cf458c8..0324d6adcb 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -245,6 +245,7 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
                            &kernel_entry, &kernel_low,
                            &kernel_high, NULL, ELFDATA2LSB,
                            EM_LOONGARCH, 1, 0);
+    kernel_entry = cpu_loongarch_virt_to_phys(NULL, kernel_entry);
     if (kernel_size < 0) {
         kernel_size = load_loongarch_linux_image(info->kernel_filename,
                                                  &kernel_entry, &kernel_low,

base-commit: 019fbfa4bcd2d3a835c241295e22ab2b5b56129b
-- 
2.39.3
Re: [PATCH v2] hw/loongarch/virt: Get physical entry address with elf file
Posted by Richard Henderson 6 months, 3 weeks ago
On 4/24/25 19:16, Bibo Mao wrote:
> With load_elf() api, image load low address and high address is converted
> to physical address if parameter translate_fn is provided. However
> executing entry address is still virtual address. Here convert entry
> address into physical address, since MMU is disabled when system power on,
> the first PC instruction should be physical address.
> 
> Signed-off-by: Bibo Mao<maobibo@loongson.cn>
> ---
>    v1 ... v2:
>    1. Only modify LoongArch specified rather than load_elf() API, since
>       there is be potential influence with other architectures.
> ---
>   hw/loongarch/boot.c | 1 +
>   1 file changed, 1 insertion(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Although perhaps we should adjust the API because all users have to do exactly this, and 
it's easy to miss.


r~
Re: [PATCH v2] hw/loongarch/virt: Get physical entry address with elf file
Posted by bibo mao 6 months, 3 weeks ago

On 2025/4/25 下午11:33, Richard Henderson wrote:
> On 4/24/25 19:16, Bibo Mao wrote:
>> With load_elf() api, image load low address and high address is converted
>> to physical address if parameter translate_fn is provided. However
>> executing entry address is still virtual address. Here convert entry
>> address into physical address, since MMU is disabled when system power 
>> on,
>> the first PC instruction should be physical address.
>>
>> Signed-off-by: Bibo Mao<maobibo@loongson.cn>
>> ---
>>    v1 ... v2:
>>    1. Only modify LoongArch specified rather than load_elf() API, since
>>       there is be potential influence with other architectures.
>> ---
>>   hw/loongarch/boot.c | 1 +
>>   1 file changed, 1 insertion(+)
> 
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> Although perhaps we should adjust the API because all users have to do 
> exactly this, and it's easy to miss.
Thanks, that is fair.

Regards
Bibo Mao
> 
> 
> r~