* [PATCH] target/loongarch: Fix valid virtual address checking
@ 2025-07-14 1:54 Bibo Mao
2025-07-14 2:20 ` gaosong
2025-07-31 7:54 ` gaosong
0 siblings, 2 replies; 3+ messages in thread
From: Bibo Mao @ 2025-07-14 1:54 UTC (permalink / raw)
To: Song Gao; +Cc: qemu-devel, qemu-stable
On LoongArch64 system, the high 32 bit of 64 bit virtual address should be
0x00000[0-7]yyy or 0xffff8yyy. The bit from 47 to 63 should be all 0 or
all 1.
Function get_physical_address() only checks bit 48 to 63, there will be
problem with the following test case. On physical machine, there is bus
error report and program exits abnormally. However on qemu TCG system
emulation mode, the program runs normally. The virtual address
0xffff000000000000ULL + addr and addr are treated the same on TLB entry
checking. This patch fixes this issue.
void main()
{
void *addr, *addr1;
int val;
addr = malloc(100);
*(int *)addr = 1;
addr1 = 0xffff000000000000ULL + addr;
val = *(int *)addr1;
printf("val %d \n", val);
}
Cc: qemu-stable@nongnu.org
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu_helper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c
index e172b11ce1..b5f732f15b 100644
--- a/target/loongarch/cpu_helper.c
+++ b/target/loongarch/cpu_helper.c
@@ -196,8 +196,8 @@ int get_physical_address(CPULoongArchState *env, hwaddr *physical,
}
/* Check valid extension */
- addr_high = sextract64(address, TARGET_VIRT_ADDR_SPACE_BITS, 16);
- if (!(addr_high == 0 || addr_high == -1)) {
+ addr_high = (int64_t)address >> (TARGET_VIRT_ADDR_SPACE_BITS - 1);
+ if (!(addr_high == 0 || addr_high == -1ULL)) {
return TLBRET_BADADDR;
}
base-commit: 9a4e273ddec3927920c5958d2226c6b38b543336
--
2.39.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] target/loongarch: Fix valid virtual address checking
2025-07-14 1:54 [PATCH] target/loongarch: Fix valid virtual address checking Bibo Mao
@ 2025-07-14 2:20 ` gaosong
2025-07-31 7:54 ` gaosong
1 sibling, 0 replies; 3+ messages in thread
From: gaosong @ 2025-07-14 2:20 UTC (permalink / raw)
To: Bibo Mao; +Cc: qemu-devel, qemu-stable
在 2025/7/14 上午9:54, Bibo Mao 写道:
> On LoongArch64 system, the high 32 bit of 64 bit virtual address should be
> 0x00000[0-7]yyy or 0xffff8yyy. The bit from 47 to 63 should be all 0 or
> all 1.
>
> Function get_physical_address() only checks bit 48 to 63, there will be
> problem with the following test case. On physical machine, there is bus
> error report and program exits abnormally. However on qemu TCG system
> emulation mode, the program runs normally. The virtual address
> 0xffff000000000000ULL + addr and addr are treated the same on TLB entry
> checking. This patch fixes this issue.
>
> void main()
> {
> void *addr, *addr1;
> int val;
>
> addr = malloc(100);
> *(int *)addr = 1;
> addr1 = 0xffff000000000000ULL + addr;
> val = *(int *)addr1;
> printf("val %d \n", val);
> }
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> target/loongarch/cpu_helper.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Acked-by: Song Gao <gaosong@loongson.cn>
thanks.
Song Gao
> diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c
> index e172b11ce1..b5f732f15b 100644
> --- a/target/loongarch/cpu_helper.c
> +++ b/target/loongarch/cpu_helper.c
> @@ -196,8 +196,8 @@ int get_physical_address(CPULoongArchState *env, hwaddr *physical,
> }
>
> /* Check valid extension */
> - addr_high = sextract64(address, TARGET_VIRT_ADDR_SPACE_BITS, 16);
> - if (!(addr_high == 0 || addr_high == -1)) {
> + addr_high = (int64_t)address >> (TARGET_VIRT_ADDR_SPACE_BITS - 1);
> + if (!(addr_high == 0 || addr_high == -1ULL)) {
> return TLBRET_BADADDR;
> }
>
>
> base-commit: 9a4e273ddec3927920c5958d2226c6b38b543336
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] target/loongarch: Fix valid virtual address checking
2025-07-14 1:54 [PATCH] target/loongarch: Fix valid virtual address checking Bibo Mao
2025-07-14 2:20 ` gaosong
@ 2025-07-31 7:54 ` gaosong
1 sibling, 0 replies; 3+ messages in thread
From: gaosong @ 2025-07-31 7:54 UTC (permalink / raw)
To: Bibo Mao; +Cc: qemu-devel, qemu-stable
在 2025/7/14 上午9:54, Bibo Mao 写道:
> On LoongArch64 system, the high 32 bit of 64 bit virtual address should be
> 0x00000[0-7]yyy or 0xffff8yyy. The bit from 47 to 63 should be all 0 or
> all 1.
>
> Function get_physical_address() only checks bit 48 to 63, there will be
> problem with the following test case. On physical machine, there is bus
> error report and program exits abnormally. However on qemu TCG system
> emulation mode, the program runs normally. The virtual address
> 0xffff000000000000ULL + addr and addr are treated the same on TLB entry
> checking. This patch fixes this issue.
>
> void main()
> {
> void *addr, *addr1;
> int val;
>
> addr = malloc(100);
> *(int *)addr = 1;
> addr1 = 0xffff000000000000ULL + addr;
> val = *(int *)addr1;
> printf("val %d \n", val);
> }
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> target/loongarch/cpu_helper.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Song Gao <gaosong@loongson.cn>
Thanks.
Song Gao
> diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c
> index e172b11ce1..b5f732f15b 100644
> --- a/target/loongarch/cpu_helper.c
> +++ b/target/loongarch/cpu_helper.c
> @@ -196,8 +196,8 @@ int get_physical_address(CPULoongArchState *env, hwaddr *physical,
> }
>
> /* Check valid extension */
> - addr_high = sextract64(address, TARGET_VIRT_ADDR_SPACE_BITS, 16);
> - if (!(addr_high == 0 || addr_high == -1)) {
> + addr_high = (int64_t)address >> (TARGET_VIRT_ADDR_SPACE_BITS - 1);
> + if (!(addr_high == 0 || addr_high == -1ULL)) {
> return TLBRET_BADADDR;
> }
>
>
> base-commit: 9a4e273ddec3927920c5958d2226c6b38b543336
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-31 7:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14 1:54 [PATCH] target/loongarch: Fix valid virtual address checking Bibo Mao
2025-07-14 2:20 ` gaosong
2025-07-31 7:54 ` gaosong
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 NNTP newsgroup(s).