[Qemu-devel] [PATCH] linux-user: Fix register used for 6th syscall argument on aarch64

Guido Günther posted 1 patch 6 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/39441aea4e2d05cc505ed3a373e81d3869eb994a.1516785202.git.agx@sigxcpu.org
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test docker-quick@centos6 passed
Test ppc passed
Test s390x passed
linux-user/host/aarch64/safe-syscall.inc.S | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[Qemu-devel] [PATCH] linux-user: Fix register used for 6th syscall argument on aarch64
Posted by Guido Günther 6 years, 2 months ago
Unbreaks the testcase from

    http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html

Signed-off-by: Guido Günther <agx@sigxcpu.org>
---
 linux-user/host/aarch64/safe-syscall.inc.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/linux-user/host/aarch64/safe-syscall.inc.S
index 58a2329b37..e4fbc31454 100644
--- a/linux-user/host/aarch64/safe-syscall.inc.S
+++ b/linux-user/host/aarch64/safe-syscall.inc.S
@@ -36,7 +36,7 @@ safe_syscall_base:
 	 *               and return the result in x0
 	 * and the syscall instruction needs
 	 *               x8 == syscall number
-	 *               x0 ... x7 == syscall arguments
+	 *               x0 ... x5 == syscall arguments
 	 *               and returns the result in x0
 	 * Shuffle everything around appropriately.
 	 */
@@ -47,7 +47,7 @@ safe_syscall_base:
 	mov	x2, x4
 	mov	x3, x5
 	mov	x4, x6
-	mov	x6, x7
+	mov	x5, x7
 	ldr	x7, [sp]
 
 	/* This next sequence of code works in conjunction with the
-- 
2.15.1


Re: [Qemu-devel] [PATCH] linux-user: Fix register used for 6th syscall argument on aarch64
Posted by Laurent Vivier 6 years, 2 months ago
CC: Richard has he wrote this code.

Thanks,
Laurent

Le 24/01/2018 à 10:14, Guido Günther a écrit :
> Unbreaks the testcase from
> 
>     http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html
> 
> Signed-off-by: Guido Günther <agx@sigxcpu.org>
> ---
>  linux-user/host/aarch64/safe-syscall.inc.S | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/linux-user/host/aarch64/safe-syscall.inc.S
> index 58a2329b37..e4fbc31454 100644
> --- a/linux-user/host/aarch64/safe-syscall.inc.S
> +++ b/linux-user/host/aarch64/safe-syscall.inc.S
> @@ -36,7 +36,7 @@ safe_syscall_base:
>  	 *               and return the result in x0
>  	 * and the syscall instruction needs
>  	 *               x8 == syscall number
> -	 *               x0 ... x7 == syscall arguments
> +	 *               x0 ... x5 == syscall arguments
>  	 *               and returns the result in x0
>  	 * Shuffle everything around appropriately.
>  	 */
> @@ -47,7 +47,7 @@ safe_syscall_base:
>  	mov	x2, x4
>  	mov	x3, x5
>  	mov	x4, x6
> -	mov	x6, x7
> +	mov	x5, x7
>  	ldr	x7, [sp]
>  
>  	/* This next sequence of code works in conjunction with the
> 


Re: [Qemu-devel] [PATCH] linux-user: Fix register used for 6th syscall argument on aarch64
Posted by Laurent Vivier 6 years, 2 months ago
Le 24/01/2018 à 10:14, Guido Günther a écrit :
> Unbreaks the testcase from
> 
>     http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html
> 
> Signed-off-by: Guido Günther <agx@sigxcpu.org>
> ---
>  linux-user/host/aarch64/safe-syscall.inc.S | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/linux-user/host/aarch64/safe-syscall.inc.S
> index 58a2329b37..e4fbc31454 100644
> --- a/linux-user/host/aarch64/safe-syscall.inc.S
> +++ b/linux-user/host/aarch64/safe-syscall.inc.S
> @@ -36,7 +36,7 @@ safe_syscall_base:
>  	 *               and return the result in x0
>  	 * and the syscall instruction needs
>  	 *               x8 == syscall number
> -	 *               x0 ... x7 == syscall arguments
> +	 *               x0 ... x5 == syscall arguments
>  	 *               and returns the result in x0
>  	 * Shuffle everything around appropriately.
>  	 */
> @@ -47,7 +47,7 @@ safe_syscall_base:
>  	mov	x2, x4
>  	mov	x3, x5
>  	mov	x4, x6
> -	mov	x6, x7
> +	mov	x5, x7
>  	ldr	x7, [sp]
>  
>  	/* This next sequence of code works in conjunction with the
> 

According to glibc/unix/sysv/linux/aarch64/syscall.S:

  AArch64 system calls take between 0 and 7 arguments.
  ... and any other system call arguments are in register x1..x7.

And it seems for qemu last argument is on the stack.
...
         x2 ... x7, (stack) == syscall arguments
...

Should we have something like this?

@@ -47,8 +47,8 @@ safe_syscall_base:
        mov     x2, x4
        mov     x3, x5
        mov     x4, x6
-       mov     x6, x7
-       ldr     x7, [sp]
+       mov     x5, x7
+       ldr     x6, [sp]

        /* This next sequence of code works in conjunction with the
         * rewind_if_safe_syscall_function(). If a signal is taken

But do we need to set x7 from the stack too?

Thanks,
Laurent


Re: [Qemu-devel] [PATCH] linux-user: Fix register used for 6th syscall argument on aarch64
Posted by Guido Günther 6 years, 2 months ago
Hi,
On Wed, Jan 24, 2018 at 10:59:05AM +0100, Laurent Vivier wrote:
> Le 24/01/2018 à 10:14, Guido Günther a écrit :
> > Unbreaks the testcase from
> > 
> >     http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html
> > 
> > Signed-off-by: Guido Günther <agx@sigxcpu.org>
> > ---
> >  linux-user/host/aarch64/safe-syscall.inc.S | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/linux-user/host/aarch64/safe-syscall.inc.S
> > index 58a2329b37..e4fbc31454 100644
> > --- a/linux-user/host/aarch64/safe-syscall.inc.S
> > +++ b/linux-user/host/aarch64/safe-syscall.inc.S
> > @@ -36,7 +36,7 @@ safe_syscall_base:
> >  	 *               and return the result in x0
> >  	 * and the syscall instruction needs
> >  	 *               x8 == syscall number
> > -	 *               x0 ... x7 == syscall arguments
> > +	 *               x0 ... x5 == syscall arguments
> >  	 *               and returns the result in x0
> >  	 * Shuffle everything around appropriately.
> >  	 */
> > @@ -47,7 +47,7 @@ safe_syscall_base:
> >  	mov	x2, x4
> >  	mov	x3, x5
> >  	mov	x4, x6
> > -	mov	x6, x7
> > +	mov	x5, x7
> >  	ldr	x7, [sp]
> >  
> >  	/* This next sequence of code works in conjunction with the
> > 
> 
> According to glibc/unix/sysv/linux/aarch64/syscall.S:
> 
>   AArch64 system calls take between 0 and 7 arguments.
>   ... and any other system call arguments are in register x1..x7.
> 
> And it seems for qemu last argument is on the stack.
> ...
>          x2 ... x7, (stack) == syscall arguments
> ...
> 
> Should we have something like this?
> 
> @@ -47,8 +47,8 @@ safe_syscall_base:
>         mov     x2, x4
>         mov     x3, x5
>         mov     x4, x6
> -       mov     x6, x7
> -       ldr     x7, [sp]
> +       mov     x5, x7
> +       ldr     x6, [sp]
> 
>         /* This next sequence of code works in conjunction with the
>          * rewind_if_safe_syscall_function(). If a signal is taken
> 
> But do we need to set x7 from the stack too?

That makes sense. The maximum number of arguments in
linux-user/syscall.c is syscall6 so we won't notice but it's better to
have this correct, I'll send an updated patch.
Cheers
 -- Guido