[PATCH] hw/loongarch/virt: Fix virt_to_phys_addr function

Tianrui Zhao posted 1 patch 1 year, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230327112313.3042829-1-zhaotianrui@loongson.cn
Maintainers: Xiaojuan Yang <yangxiaojuan@loongson.cn>, Song Gao <gaosong@loongson.cn>
hw/loongarch/virt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] hw/loongarch/virt: Fix virt_to_phys_addr function
Posted by Tianrui Zhao 1 year, 1 month ago
The virt addr should mask TARGET_PHYS_ADDR_SPACE_BITS to
get the phys addr, and this is used by loading kernel elf.

Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
 hw/loongarch/virt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index b702c3f51e..f4bf14c1c8 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -399,7 +399,7 @@ static struct _loaderparams {
 
 static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
 {
-    return addr & 0x1fffffffll;
+    return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
 }
 
 static int64_t load_kernel_info(void)
-- 
2.31.1
Re: [PATCH] hw/loongarch/virt: Fix virt_to_phys_addr function
Posted by Richard Henderson 1 year ago
On 3/27/23 04:23, Tianrui Zhao wrote:
> The virt addr should mask TARGET_PHYS_ADDR_SPACE_BITS to
> get the phys addr, and this is used by loading kernel elf.
> 
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
>   hw/loongarch/virt.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index b702c3f51e..f4bf14c1c8 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -399,7 +399,7 @@ static struct _loaderparams {
>   
>   static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>   {
> -    return addr & 0x1fffffffll;
> +    return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>   }
>   
>   static int64_t load_kernel_info(void)

Looks correct.  Any idea where this 29-bit value originated?

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

r~
Re: [PATCH] hw/loongarch/virt: Fix virt_to_phys_addr function
Posted by gaosong 1 year ago
在 2023/3/28 上午1:44, Richard Henderson 写道:
> On 3/27/23 04:23, Tianrui Zhao wrote:
>> The virt addr should mask TARGET_PHYS_ADDR_SPACE_BITS to
>> get the phys addr, and this is used by loading kernel elf.
>>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> ---
>>   hw/loongarch/virt.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
>> index b702c3f51e..f4bf14c1c8 100644
>> --- a/hw/loongarch/virt.c
>> +++ b/hw/loongarch/virt.c
>> @@ -399,7 +399,7 @@ static struct _loaderparams {
>>     static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t 
>> addr)
>>   {
>> -    return addr & 0x1fffffffll;
>> +    return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>>   }
>>     static int64_t load_kernel_info(void)
>
> Looks correct.  Any idea where this 29-bit value originated?
We just considered using  256M low-memory to load the kernel and did not 
consider using the high-memory.

Thanks.
Song Gao
>
> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>
> r~