[PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only

Miao Wang via B4 Relay posted 1 patch 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260630-loong64-vary-page-sz-v1-1-1d1a894674be@gmail.com
Maintainers: Song Gao <gaosong@loongson.cn>
target/loongarch/cpu-param.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Posted by Miao Wang via B4 Relay 3 weeks, 5 days ago
From: Miao Wang <shankerwangmiao@gmail.com>

Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
working on hosts with 16K page size.

Fixes: 1d832c19db1e ("target/loongarch: Support 4K page size")
Fixes: qemu-project/qemu#3651

Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>
---
 target/loongarch/cpu-param.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/target/loongarch/cpu-param.h b/target/loongarch/cpu-param.h
index 3bcf77b3755abdc302699c22c7aa99e2e8c3bbf3..6abe72ff5cab46e246fde4fa76bce05ba7c1cd20 100644
--- a/target/loongarch/cpu-param.h
+++ b/target/loongarch/cpu-param.h
@@ -10,6 +10,11 @@
 
 #define TARGET_VIRT_ADDR_SPACE_BITS 48
 
-#define TARGET_PAGE_BITS 12
+#ifdef CONFIG_USER_ONLY
+/* Allow user-only to vary page size from 4k */
+# define TARGET_PAGE_BITS_VARY
+#else
+# define TARGET_PAGE_BITS 12
+#endif
 
 #endif

---
base-commit: 30e8a06b64aa58a3990ba39cb5d09531e7d265e0
change-id: 20260630-loong64-vary-page-sz-253ded0be884

Best regards,
-- 
Miao Wang <shankerwangmiao@gmail.com>
Re: [PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Posted by Michael Tokarev 2 weeks, 3 days ago
On 30.06.2026 10:56, Miao Wang via B4 Relay wrote:
> From: Miao Wang <shankerwangmiao@gmail.com>
> 
> Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
> working on hosts with 16K page size.

Doesn't the same apply to all other targets - hard-coding PAGE_SIZE to
4k for any linux-user target will prevent this target from working on
hosts with 16k page size?

Meanwhile, I'm picking this up for qemu-stable (11.0.x only, since
TARGET_PAGE_BITS_VARY is not handled in earlier releases).

Thanks,

/mjt

> Fixes: 1d832c19db1e ("target/loongarch: Support 4K page size")
> Fixes: qemu-project/qemu#3651
> 
> Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>
> ---
>   target/loongarch/cpu-param.h | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/target/loongarch/cpu-param.h b/target/loongarch/cpu-param.h
> index 3bcf77b3755abdc302699c22c7aa99e2e8c3bbf3..6abe72ff5cab46e246fde4fa76bce05ba7c1cd20 100644
> --- a/target/loongarch/cpu-param.h
> +++ b/target/loongarch/cpu-param.h
> @@ -10,6 +10,11 @@
>   
>   #define TARGET_VIRT_ADDR_SPACE_BITS 48
>   
> -#define TARGET_PAGE_BITS 12
> +#ifdef CONFIG_USER_ONLY
> +/* Allow user-only to vary page size from 4k */
> +# define TARGET_PAGE_BITS_VARY
> +#else
> +# define TARGET_PAGE_BITS 12
> +#endif
>   
>   #endif
> 
> ---
> base-commit: 30e8a06b64aa58a3990ba39cb5d09531e7d265e0
> change-id: 20260630-loong64-vary-page-sz-253ded0be884
> 
> Best regards,
Re: [PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Posted by Richard Henderson 2 weeks, 3 days ago
On 7/8/26 04:38, Michael Tokarev wrote:
> On 30.06.2026 10:56, Miao Wang via B4 Relay wrote:
>> From: Miao Wang <shankerwangmiao@gmail.com>
>>
>> Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
>> working on hosts with 16K page size.
> 
> Doesn't the same apply to all other targets - hard-coding PAGE_SIZE to
> 4k for any linux-user target will prevent this target from working on
> hosts with 16k page size?

But some targets really have a fixed page size and aren't prepared for any changes.  E.g. 
x86 and m68k.  Thus it's up to the target to decide if variable page size is ok.


r~
Re: [PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Posted by Miao Wang 2 weeks, 3 days ago
Hi,

> 2026年7月8日 19:38,Michael Tokarev <mjt@tls.msk.ru> 写道:
> 
> On 30.06.2026 10:56, Miao Wang via B4 Relay wrote:
>> From: Miao Wang <shankerwangmiao@gmail.com>
>> Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
>> working on hosts with 16K page size.
> 
> Doesn't the same apply to all other targets - hard-coding PAGE_SIZE to
> 4k for any linux-user target will prevent this target from working on
> hosts with 16k page size?

I believe so. It seem that qemu-user might have trouble handling guest
with smaller page size than the host, IIUC. If a certain target requires
4K page size while the host has a larger page size, then there will
be no way to handle this. Using this patch just allows to use the
same page size as the host when possible. 

BTW, in Debian, there are currently two "special" architectures,
which are s390x and loong64. S390x is the only one with big-endianness
while loong64 is the only one with 16K page size by default. As a 
result, testing results on these two architectures can catch more
cross-architecture related bugs.

Cheers,

Miao Wang
Re: [PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Posted by Helge Deller 2 weeks ago
On 7/8/26 14:09, Miao Wang wrote:
> Hi,
> 
>> 2026年7月8日 19:38,Michael Tokarev <mjt@tls.msk.ru> 写道:
>>
>> On 30.06.2026 10:56, Miao Wang via B4 Relay wrote:
>>> From: Miao Wang <shankerwangmiao@gmail.com>
>>> Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
>>> working on hosts with 16K page size.
>>
>> Doesn't the same apply to all other targets - hard-coding PAGE_SIZE to
>> 4k for any linux-user target will prevent this target from working on
>> hosts with 16k page size?
> 
> I believe so. It seem that qemu-user might have trouble handling guest
> with smaller page size than the host, IIUC. If a certain target requires
> 4K page size while the host has a larger page size, then there will
> be no way to handle this. Using this patch just allows to use the
> same page size as the host when possible.
> 
> BTW, in Debian, there are currently two "special" architectures,
> which are s390x and loong64. S390x is the only one with big-endianness

Just for the record:
hppa is big-endian as well, and in addition it's a 32-bit arch (for linux-user).

> while loong64 is the only one with 16K page size by default. As a
> result, testing results on these two architectures can catch more
> cross-architecture related bugs.
> 
> Cheers,
> 
> Miao Wang
Re: [PATCH] target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Posted by gaosong 3 weeks, 4 days ago
在 2026/6/30 下午3:56, Miao Wang via B4 Relay 写道:
> From: Miao Wang <shankerwangmiao@gmail.com>
>
> Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
> working on hosts with 16K page size.
>
> Fixes: 1d832c19db1e ("target/loongarch: Support 4K page size")
> Fixes: qemu-project/qemu#3651
>
> Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>
> ---
>   target/loongarch/cpu-param.h | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/target/loongarch/cpu-param.h b/target/loongarch/cpu-param.h
> index 3bcf77b3755abdc302699c22c7aa99e2e8c3bbf3..6abe72ff5cab46e246fde4fa76bce05ba7c1cd20 100644
> --- a/target/loongarch/cpu-param.h
> +++ b/target/loongarch/cpu-param.h
> @@ -10,6 +10,11 @@
>   
>   #define TARGET_VIRT_ADDR_SPACE_BITS 48
>   
> -#define TARGET_PAGE_BITS 12
> +#ifdef CONFIG_USER_ONLY
> +/* Allow user-only to vary page size from 4k */
> +# define TARGET_PAGE_BITS_VARY
> +#else
> +# define TARGET_PAGE_BITS 12
> +#endif
>   
>   #endif
>
> ---
> base-commit: 30e8a06b64aa58a3990ba39cb5d09531e7d265e0
> change-id: 20260630-loong64-vary-page-sz-253ded0be884
>
> Best regards,