All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues
@ 2022-10-06  8:55 WANG Xuerui
  2022-10-06 11:13 ` Philippe Mathieu-Daudé via
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: WANG Xuerui @ 2022-10-06  8:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: WANG Xuerui, Philippe Mathieu-Daudé,
	Jiaxun Yang, Andreas K . Hüttel, Joshua Kinard

In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for
MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed,
but still some cases remain where the n32 is incorrectly treated as any
other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by
excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks.

Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Andreas K. Hüttel <dilfridge@gentoo.org>
Cc: Joshua Kinard <kumba@gentoo.org>
---

Note: I can't reproduce the crash with neither MIPS n32 sysroot at my hand
(a self-built one for Loongson-2F, and stage3-mips64_n32-openrc-20221001T170527Z),
so I can only verify by looking at the (host and qemu) strace outputs, and
would have to ask you to review/test this harder. Thanks.

 linux-user/syscall.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2e954d8dbd..8b2d39fe73 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11793,7 +11793,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         return -host_to_target_errno(ret);
 #endif
 
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
 
 #ifdef TARGET_NR_fadvise64_64
     case TARGET_NR_fadvise64_64:
@@ -11920,7 +11920,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         return get_errno(sys_gettid());
 #ifdef TARGET_NR_readahead
     case TARGET_NR_readahead:
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
         if (regpairs_aligned(cpu_env, num)) {
             arg2 = arg3;
             arg3 = arg4;
@@ -12612,7 +12612,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #endif /* CONFIG_EVENTFD  */
 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
     case TARGET_NR_fallocate:
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
         ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
                                   target_offset64(arg5, arg6)));
 #else
@@ -12623,7 +12623,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #if defined(CONFIG_SYNC_FILE_RANGE)
 #if defined(TARGET_NR_sync_file_range)
     case TARGET_NR_sync_file_range:
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
 #if defined(TARGET_MIPS)
         ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
                                         target_offset64(arg5, arg6), arg7));
@@ -12645,7 +12645,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     case TARGET_NR_arm_sync_file_range:
 #endif
         /* This is like sync_file_range but the arguments are reordered */
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
         ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
                                         target_offset64(arg5, arg6), arg2));
 #else
-- 
2.38.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues
  2022-10-06  8:55 [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues WANG Xuerui
@ 2022-10-06 11:13 ` Philippe Mathieu-Daudé via
  2022-10-06 13:39 ` Jiaxun Yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-10-06 11:13 UTC (permalink / raw)
  To: WANG Xuerui, qemu-devel
  Cc: Jiaxun Yang, Andreas K . Hüttel, Joshua Kinard

On 6/10/22 10:55, WANG Xuerui wrote:
> In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for
> MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed,
> but still some cases remain where the n32 is incorrectly treated as any
> other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by
> excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks.
> 
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238
> Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Andreas K. Hüttel <dilfridge@gentoo.org>
> Cc: Joshua Kinard <kumba@gentoo.org>
> ---
> 
> Note: I can't reproduce the crash with neither MIPS n32 sysroot at my hand
> (a self-built one for Loongson-2F, and stage3-mips64_n32-openrc-20221001T170527Z),
> so I can only verify by looking at the (host and qemu) strace outputs, and
> would have to ask you to review/test this harder. Thanks.
> 
>   linux-user/syscall.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues
  2022-10-06  8:55 [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues WANG Xuerui
  2022-10-06 11:13 ` Philippe Mathieu-Daudé via
@ 2022-10-06 13:39 ` Jiaxun Yang
  2022-10-07 20:48 ` Andreas K. Huettel
  2022-10-21 14:38 ` Laurent Vivier
  3 siblings, 0 replies; 5+ messages in thread
From: Jiaxun Yang @ 2022-10-06 13:39 UTC (permalink / raw)
  To: WANG Xuerui
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	"Andreas K . Hüttel",
	Joshua Kinard



> 2022年10月6日 09:55,WANG Xuerui <xen0n@gentoo.org> 写道:
> 
> In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for
> MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed,
> but still some cases remain where the n32 is incorrectly treated as any
> other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by
> excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks.
> 
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238
> Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Andreas K. Hüttel <dilfridge@gentoo.org>
> Cc: Joshua Kinard <kumba@gentoo.org>

Good catch.

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

Managed to chroot into a n32 “共创 Linux” rootfs and ran some test.
Looks good.

Thanks
- Jiaxun


> ---
> 
> Note: I can't reproduce the crash with neither MIPS n32 sysroot at my hand
> (a self-built one for Loongson-2F, and stage3-mips64_n32-openrc-20221001T170527Z),
> so I can only verify by looking at the (host and qemu) strace outputs, and
> would have to ask you to review/test this harder. Thanks.
> 
> linux-user/syscall.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 2e954d8dbd..8b2d39fe73 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11793,7 +11793,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>         return -host_to_target_errno(ret);
> #endif
> 
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
> 
> #ifdef TARGET_NR_fadvise64_64
>     case TARGET_NR_fadvise64_64:
> @@ -11920,7 +11920,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>         return get_errno(sys_gettid());
> #ifdef TARGET_NR_readahead
>     case TARGET_NR_readahead:
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>         if (regpairs_aligned(cpu_env, num)) {
>             arg2 = arg3;
>             arg3 = arg4;
> @@ -12612,7 +12612,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> #endif /* CONFIG_EVENTFD  */
> #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
>     case TARGET_NR_fallocate:
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>         ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
>                                   target_offset64(arg5, arg6)));
> #else
> @@ -12623,7 +12623,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> #if defined(CONFIG_SYNC_FILE_RANGE)
> #if defined(TARGET_NR_sync_file_range)
>     case TARGET_NR_sync_file_range:
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
> #if defined(TARGET_MIPS)
>         ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
>                                         target_offset64(arg5, arg6), arg7));
> @@ -12645,7 +12645,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>     case TARGET_NR_arm_sync_file_range:
> #endif
>         /* This is like sync_file_range but the arguments are reordered */
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>         ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
>                                         target_offset64(arg5, arg6), arg2));
> #else
> -- 
> 2.38.0
> 

---
Jiaxun Yang



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues
  2022-10-06  8:55 [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues WANG Xuerui
  2022-10-06 11:13 ` Philippe Mathieu-Daudé via
  2022-10-06 13:39 ` Jiaxun Yang
@ 2022-10-07 20:48 ` Andreas K. Huettel
  2022-10-21 14:38 ` Laurent Vivier
  3 siblings, 0 replies; 5+ messages in thread
From: Andreas K. Huettel @ 2022-10-07 20:48 UTC (permalink / raw)
  To: qemu-devel, WANG Xuerui
  Cc: WANG Xuerui, Philippe Mathieu-Daudé, Jiaxun Yang, Joshua Kinard

[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]

Am Donnerstag, 6. Oktober 2022, 10:55:00 CEST schrieb WANG Xuerui:
> In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for
> MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed,
> but still some cases remain where the n32 is incorrectly treated as any
> other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by
> excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks.
> 
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238
> Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Andreas K. Hüttel <dilfridge@gentoo.org>
> Cc: Joshua Kinard <kumba@gentoo.org>
> ---
> 
> Note: I can't reproduce the crash with neither MIPS n32 sysroot at my hand
> (a self-built one for Loongson-2F, and stage3-mips64_n32-openrc-20221001T170527Z),
> so I can only verify by looking at the (host and qemu) strace outputs, and
> would have to ask you to review/test this harder. Thanks.

This solves the problem I observed in 
https://gitlab.com/qemu-project/qemu/-/issues/1238
Thank you!!

Tested by having one mipsel n32 chroot rebuild itself completely.

Tested-by: Andreas K. Huettel <dilfridge@gentoo.org>

-- 
Andreas K. Hüttel
dilfridge@gentoo.org
Gentoo Linux developer
(council, toolchain, base-system, perl, libreoffice)

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 981 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues
  2022-10-06  8:55 [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues WANG Xuerui
                   ` (2 preceding siblings ...)
  2022-10-07 20:48 ` Andreas K. Huettel
@ 2022-10-21 14:38 ` Laurent Vivier
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2022-10-21 14:38 UTC (permalink / raw)
  To: WANG Xuerui, qemu-devel
  Cc: Philippe Mathieu-Daudé,
	Jiaxun Yang, Andreas K . Hüttel, Joshua Kinard

Le 06/10/2022 à 10:55, WANG Xuerui a écrit :
> In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for
> MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed,
> but still some cases remain where the n32 is incorrectly treated as any
> other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by
> excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks.
> 
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238
> Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Andreas K. Hüttel <dilfridge@gentoo.org>
> Cc: Joshua Kinard <kumba@gentoo.org>
> ---
> 
> Note: I can't reproduce the crash with neither MIPS n32 sysroot at my hand
> (a self-built one for Loongson-2F, and stage3-mips64_n32-openrc-20221001T170527Z),
> so I can only verify by looking at the (host and qemu) strace outputs, and
> would have to ask you to review/test this harder. Thanks.
> 
>   linux-user/syscall.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 2e954d8dbd..8b2d39fe73 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11793,7 +11793,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>           return -host_to_target_errno(ret);
>   #endif
>   
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>   
>   #ifdef TARGET_NR_fadvise64_64
>       case TARGET_NR_fadvise64_64:
> @@ -11920,7 +11920,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>           return get_errno(sys_gettid());
>   #ifdef TARGET_NR_readahead
>       case TARGET_NR_readahead:
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>           if (regpairs_aligned(cpu_env, num)) {
>               arg2 = arg3;
>               arg3 = arg4;
> @@ -12612,7 +12612,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>   #endif /* CONFIG_EVENTFD  */
>   #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
>       case TARGET_NR_fallocate:
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>           ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
>                                     target_offset64(arg5, arg6)));
>   #else
> @@ -12623,7 +12623,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>   #if defined(CONFIG_SYNC_FILE_RANGE)
>   #if defined(TARGET_NR_sync_file_range)
>       case TARGET_NR_sync_file_range:
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>   #if defined(TARGET_MIPS)
>           ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
>                                           target_offset64(arg5, arg6), arg7));
> @@ -12645,7 +12645,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>       case TARGET_NR_arm_sync_file_range:
>   #endif
>           /* This is like sync_file_range but the arguments are reordered */
> -#if TARGET_ABI_BITS == 32
> +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
>           ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
>                                           target_offset64(arg5, arg6), arg2));
>   #else

Applied to my linux-user-for-7.2 branch.

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-21 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06  8:55 [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues WANG Xuerui
2022-10-06 11:13 ` Philippe Mathieu-Daudé via
2022-10-06 13:39 ` Jiaxun Yang
2022-10-07 20:48 ` Andreas K. Huettel
2022-10-21 14:38 ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.