Skip to contentSkip to conversation

linux-user: safe_syscall updates

PATCH Applied Richard Henderson 3 participants 24 messages Jun 13, 2016 – Jun 21, 2016

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover linux-user: safe_syscall updates

We added support for x86_64 in 4d330cee37a2; this adds support for 5 more hosts. Also, tweak the signal_pending test for x86_64.

r~

Richard Henderson (6):
linux-user: fix x86_64 safe_syscall
linux-user: Provide safe_syscall for i386
linux-user: Provide safe_syscall for arm
linux-user: Provide safe_syscall for aarch64
linux-user: Provide safe_syscall for s390x
linux-user: Provide safe_syscall for ppc64

 linux-user/host/aarch64/hostdep.h          |  34 +++++++++
 linux-user/host/aarch64/safe-syscall.inc.S |  72 +++++++++++++++++++
 linux-user/host/arm/hostdep.h              |  34 +++++++++
 linux-user/host/arm/safe-syscall.inc.S     |  86 ++++++++++++++++++++++
 linux-user/host/i386/hostdep.h             |  34 +++++++++
 linux-user/host/i386/safe-syscall.inc.S    | 110 +++++++++++++++++++++++++++++
 linux-user/host/ppc64/hostdep.h            |  34 +++++++++
 linux-user/host/ppc64/safe-syscall.inc.S   |  87 +++++++++++++++++++++++
 linux-user/host/s390x/hostdep.h            |  34 +++++++++
 linux-user/host/s390x/safe-syscall.inc.S   |  87 +++++++++++++++++++++++
 linux-user/host/x86_64/safe-syscall.inc.S  |   6 +-
 11 files changed, 615 insertions(+), 3 deletions(-)
 create mode 100644 linux-user/host/aarch64/hostdep.h
 create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S
 create mode 100644 linux-user/host/arm/hostdep.h
 create mode 100644 linux-user/host/arm/safe-syscall.inc.S
 create mode 100644 linux-user/host/i386/hostdep.h
 create mode 100644 linux-user/host/i386/safe-syscall.inc.S
 create mode 100644 linux-user/host/ppc64/hostdep.h
 create mode 100644 linux-user/host/ppc64/safe-syscall.inc.S
 create mode 100644 linux-user/host/s390x/hostdep.h
 create mode 100644 linux-user/host/s390x/safe-syscall.inc.S
Signature · 1 line
2.5.5
#1 lore raw

PATCH 1/6 linux-user: fix x86_64 safe_syscall

Do what the comment says, test for signal_pending non-zero, rather than the current coe which tests for bit 0 non-zero.

---
 linux-user/host/x86_64/safe-syscall.inc.S | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
linux-user/host/x86_64/safe-syscall.inc.S +3 -3
index e09368d..f36992d 100644
@@ -67,8 +67,8 @@ safe_syscall_base:
          */
 safe_syscall_start:
         /* if signal_pending is non-zero, don't do the call */
-        testl   $1, (%rbp)
-        jnz     return_ERESTARTSYS
+        cmpl	$0, (%rbp)
+        jnz     1f
         syscall
 safe_syscall_end:
         /* code path for having successfully executed the syscall */
@@ -78,7 +78,7 @@ safe_syscall_end:
         .cfi_restore rbp
         ret
 
-return_ERESTARTSYS:
+1:
         /* code path when we didn't execute the syscall */
         .cfi_restore_state
         mov     $-TARGET_ERESTARTSYS, %rax
Signature · 1 line
2.5.5
Reviewed-by on v1 1/6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] linux-user: fix x86_64 safe_syscall

Quoted 2 lines · Richard Henderson

Do what the comment says, test for signal_pending non-zero, rather than the current coe which tests for bit 0 non-zero.

"code"

Quoted 22 lines
---
 linux-user/host/x86_64/safe-syscall.inc.S | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
linux-user/host/x86_64/safe-syscall.inc.S +2 -2
index e09368d..f36992d 100644
@@ -67,8 +67,8 @@ safe_syscall_base:
          */
 safe_syscall_start:
         /* if signal_pending is non-zero, don't do the call */
-        testl   $1, (%rbp)
-        jnz     return_ERESTARTSYS
+        cmpl   $0, (%rbp)
+        jnz     1f
         syscall
 safe_syscall_end:
         /* code path for having successfully executed the syscall */

linux-user/host/x86_64/safe-syscall.inc.S safe_syscall_end: · line 84

Quoted 8 lines
linux-user/host/x86_64/safe-syscall.inc.S +1 -1
@@ -78,7 +78,7 @@ safe_syscall_end:
         .cfi_restore rbp
         ret
 
-return_ERESTARTSYS:
+1:
         /* code path when we didn't execute the syscall */
         .cfi_restore_state
         mov     $-TARGET_ERESTARTSYS, %rax

thanks
-- PMM

Applied
#3 lore raw

Re: [Qemu-devel] [PATCH 1/6] linux-user: fix x86_64 safe_syscall

In reply to Richard Henderson
Quoted 2 lines · Richard Henderson

Do what the comment says, test for signal_pending non-zero, rather than the current coe which tests for bit 0 non-zero.

Applied to linux-user with the type fixed,
Thanks

Quoted 32 lines
---
 linux-user/host/x86_64/safe-syscall.inc.S | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
linux-user/host/x86_64/safe-syscall.inc.S +3 -3
index e09368d..f36992d 100644
@@ -67,8 +67,8 @@ safe_syscall_base:
          */
 safe_syscall_start:
         /* if signal_pending is non-zero, don't do the call */
-        testl   $1, (%rbp)
-        jnz     return_ERESTARTSYS
+        cmpl	$0, (%rbp)
+        jnz     1f
         syscall
 safe_syscall_end:
         /* code path for having successfully executed the syscall */
@@ -78,7 +78,7 @@ safe_syscall_end:
         .cfi_restore rbp
         ret
 
-return_ERESTARTSYS:
+1:
         /* code path when we didn't execute the syscall */
         .cfi_restore_state
         mov     $-TARGET_ERESTARTSYS, %rax
Signature · 1 line
2.5.5
#4 lore raw

PATCH 2/6 linux-user: Provide safe_syscall for i386

In reply to Richard Henderson
---
 linux-user/host/i386/hostdep.h          |  34 ++++++++++
 linux-user/host/i386/safe-syscall.inc.S | 110 ++++++++++++++++++++++++++++++++
 2 files changed, 144 insertions(+)
 create mode 100644 linux-user/host/i386/hostdep.h
 create mode 100644 linux-user/host/i386/safe-syscall.inc.S
linux-user/host/i386/hostdep.h new file +34 -0
new file mode 100644
index 0000000..9e2b4d7
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    greg_t *pcreg = &uc->uc_mcontext.gregs[REG_EIP];
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/i386/safe-syscall.inc.S new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.5.5
#5 lore raw

Re: [Qemu-devel] [PATCH 2/6] linux-user: Provide safe_syscall for i386

Quoted 28 lines · Richard Henderson
---
 linux-user/host/i386/hostdep.h          |  34 ++++++++++
 linux-user/host/i386/safe-syscall.inc.S | 110 ++++++++++++++++++++++++++++++++
 2 files changed, 144 insertions(+)
 create mode 100644 linux-user/host/i386/hostdep.h
 create mode 100644 linux-user/host/i386/safe-syscall.inc.S
linux-user/host/i386/hostdep.h new file +14 -0
new file mode 100644
index 0000000..9e2b4d7
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__

linux-user/host/i386/hostdep.h line 24

Quoted 10 lines
linux-user/host/i386/hostdep.h new file +10 -0
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    greg_t *pcreg = &uc->uc_mcontext.gregs[REG_EIP];

user-exec.c has
#ifndef REG_EIP
/* for glibc 2.1 */
#define REG_EIP EIP
#endif

Do we still care about glibc 2.1 ? (Probably not, 2.2 was released fifteen years ago now...)

Quoted 16 lines
linux-user/host/i386/hostdep.h new file +10 -0
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/i386/safe-syscall.inc.S new file +0 -0
new file mode 100644
index 0000000..f5f0c64

linux-user/host/i386/safe-syscall.inc.S line 4

Quoted 4 lines
linux-user/host/i386/safe-syscall.inc.S new file +4 -0
@@ -0,0 +1,110 @@
+/*
+ * safe-syscall.inc.S : host-specific assembly fragment
+ * to handle signals occurring at the same time as system calls.
+ * This is intended to be included by linux-user/safe-syscall.S

Missing copyright/written by attribution ?

linux-user/host/i386/safe-syscall.inc.S line 13

Quoted 9 lines
linux-user/host/i386/safe-syscall.inc.S new file +9 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+        .global safe_syscall_base
+        .global safe_syscall_start
+        .global safe_syscall_end
+        .type   safe_syscall_base, @function

I guess 4-space indent would match the rest of QEMU...

Quoted 9 lines
linux-user/host/i386/safe-syscall.inc.S new file +9 -0
+
+        /* This is the entry point for making a system call. The calling
+         * convention here is that of a C varargs function with the
+         * first argument an 'int *' to the signal_pending flag, the
+         * second one the system call number (as a 'long'), and all further
+         * arguments being syscall arguments (also 'long').
+         * We return a long which is the syscall's return value, which
+         * may be negative-errno on failure. Conversion to the
+         * -1-and-errno-set convention is done by the calling wrapper.

linux-user/host/i386/safe-syscall.inc.S line 32

Quoted 10 lines
linux-user/host/i386/safe-syscall.inc.S new file +10 -0
+         */
+safe_syscall_base:
+        .cfi_startproc
+        push    %ebp
+        .cfi_adjust_cfa_offset 4
+        .cfi_rel_offset ebp, 0
+       push    %esi
+        .cfi_adjust_cfa_offset 4
+        .cfi_rel_offset esi, 0
+       push    %edi

Odd indentation here.

Quoted 29 lines
linux-user/host/i386/safe-syscall.inc.S new file +29 -0
+        .cfi_adjust_cfa_offset 4
+        .cfi_rel_offset edi, 0
+       push    %ebx
+        .cfi_adjust_cfa_offset 4
+        .cfi_rel_offset ebx, 0
+
+        /* The syscall calling convention isn't the same as the C one:
+         * we enter with 0(%esp) == return address
+         *               4(%esp) == *signal_pending
+         *               8(%esp) == syscall number
+         *               12(%esp) ... 32(%esp) == syscall arguments
+         *               and return the result in eax
+         * and the syscall instruction needs
+         *               eax == syscall number
+         *               ebx, ecx, edx, esi, edi, ebp == syscall arguments
+         *               and returns the result in eax
+         * Shuffle everything around appropriately.
+        * Note the 16 bytes that we pushed to save registers.
+         */
+        mov     12+16(%esp), %ebx       /* the syscall arguments */
+        mov     16+16(%esp), %ecx
+        mov     20+16(%esp), %edx
+        mov     24+16(%esp), %esi
+        mov     28+16(%esp), %edi
+        mov     32+16(%esp), %ebp
+
+        /* This next sequence of code works in conjunction with the
+         * rewind_if_safe_syscall_function(). If a signal is taken
+         * and the interrupted PC is anywhere between 'safe_syscall_start'

linux-user/host/i386/safe-syscall.inc.S line 71

Quoted 10 lines
linux-user/host/i386/safe-syscall.inc.S new file +10 -0
+         * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
+         * The code sequence must therefore be able to cope with this, and
+         * the syscall instruction must be the final one in the sequence.
+         */
+safe_syscall_start:
+        /* if signal_pending is non-zero, don't do the call */
+       mov     4+16(%esp), %eax        /* signal_pending */
+        cmp    $0, (%eax)
+        mov     8+16(%esp), %eax        /* syscall number */
+        jnz     1f

Any particular reason for doing the jump after the mov?

linux-user/host/i386/safe-syscall.inc.S line 77

Quoted 6 lines
linux-user/host/i386/safe-syscall.inc.S new file +6 -0
+        int    $0x80
+safe_syscall_end:
+        /* code path for having successfully executed the syscall */
+        pop     %ebx
+        .cfi_remember_state
+        .cfi_def_cfa_offset 4

Shouldn't these all be ".cfi_adjust_cfa_offset -4" ? That's what glibc uses AFAICT.

Quoted 8 lines
linux-user/host/i386/safe-syscall.inc.S new file +8 -0
+        .cfi_restore ebx
+       pop     %edi
+        .cfi_def_cfa_offset 4
+        .cfi_restore edi
+       pop     %esi
+        .cfi_def_cfa_offset 4
+        .cfi_restore esi
+       pop     %ebp

linux-user/host/i386/safe-syscall.inc.S line 95

Quoted 10 lines
linux-user/host/i386/safe-syscall.inc.S new file +10 -0
+        .cfi_def_cfa_offset 4
+        .cfi_restore ebp
+        ret
+
+1:
+        /* code path when we didn't execute the syscall */
+        .cfi_restore_state
+        mov     $-TARGET_ERESTARTSYS, %eax
+        pop     %ebx
+        .cfi_remember_state

We don't need to remember state here I think.

Quoted 16 lines
linux-user/host/i386/safe-syscall.inc.S new file +15 -1
+        .cfi_def_cfa_offset 4
+        .cfi_restore ebx
+       pop     %edi
+        .cfi_def_cfa_offset 4
+        .cfi_restore edi
+       pop     %esi
+        .cfi_def_cfa_offset 4
+        .cfi_restore esi
+       pop     %ebp
+        .cfi_def_cfa_offset 4
+        .cfi_restore ebp
+        ret
+        .cfi_endproc
+
+        .size   safe_syscall_base, .-safe_syscall_base
--
Quoted 1 line

2.5.5

Other than some trivialities like order of register push/pops this is virtually identical code to the version I had, so it must be right :-)

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 2/6] linux-user: Provide safe_syscall for i386

Quoted 11 lines · Peter Maydell
Quoted 1 line

+ greg_t *pcreg = &uc->uc_mcontext.gregs[REG_EIP];

user-exec.c has
#ifndef REG_EIP
/* for glibc 2.1 */
#define REG_EIP EIP
#endif

Do we still care about glibc 2.1 ? (Probably not, 2.2 was released fifteen years ago now...)

Heh. I would say not. We've got other much more recent requirements.

Quoted 11 lines

linux-user/host/i386/safe-syscall.inc.S line 13

Quoted 9 lines

+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */

linux-user/host/i386/safe-syscall.inc.S new file +5 -0
+
+        .global safe_syscall_base
+        .global safe_syscall_start
+        .global safe_syscall_end
+        .type   safe_syscall_base, @function

I guess 4-space indent would match the rest of QEMU...

This is assembler not C. My brain is tied to a 1-tab indent.

Quoted 4 lines

linux-user/host/i386/safe-syscall.inc.S line 32

Quoted 2 lines
linux-user/host/i386/safe-syscall.inc.S new file +2 -0
+        .cfi_rel_offset esi, 0
+       push    %edi

Odd indentation here.

Yeah, that's mixing code from your x86_64 version which uses spaces not tabs.

Quoted 5 lines

linux-user/host/i386/safe-syscall.inc.S line 71

Quoted 3 lines
linux-user/host/i386/safe-syscall.inc.S new file +3 -0
+        cmp    $0, (%eax)
+        mov     8+16(%esp), %eax        /* syscall number */
+        jnz     1f

Any particular reason for doing the jump after the mov?

No. Indeed, recent cpus will fuse the cmp+jnz so they're better off together.

Quoted 4 lines
Quoted 1 line

+ .cfi_def_cfa_offset 4

Shouldn't these all be ".cfi_adjust_cfa_offset -4" ? That's what glibc uses AFAICT.

Typo. Good catch.

Quoted 3 lines
Quoted 1 line

+ .cfi_remember_state

We don't need to remember state here I think.

Correct. Cut and paste.

Quoted 3 lines

Other than some trivialities like order of register push/pops this is virtually identical code to the version I had, so it must be right :-)

Heh.

r~

#7 lore raw

PATCH 3/6 linux-user: Provide safe_syscall for arm

In reply to Richard Henderson
---
 linux-user/host/arm/hostdep.h          | 34 ++++++++++++++
 linux-user/host/arm/safe-syscall.inc.S | 86 ++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 linux-user/host/arm/hostdep.h
 create mode 100644 linux-user/host/arm/safe-syscall.inc.S
linux-user/host/arm/hostdep.h new file +34 -0
new file mode 100644
index 0000000..1426fb6
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    unsigned long *pcreg = &uc->uc_mcontext.arm_pc;
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/arm/safe-syscall.inc.S new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.5.5
Reviewed-by on v1 3/6
#8 lore raw

Re: [Qemu-devel] [PATCH 3/6] linux-user: Provide safe_syscall for arm

Quoted 63 lines · Richard Henderson
---
 linux-user/host/arm/hostdep.h          | 34 ++++++++++++++
 linux-user/host/arm/safe-syscall.inc.S | 86 ++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 linux-user/host/arm/hostdep.h
 create mode 100644 linux-user/host/arm/safe-syscall.inc.S
linux-user/host/arm/hostdep.h new file +34 -0
new file mode 100644
index 0000000..1426fb6
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    unsigned long *pcreg = &uc->uc_mcontext.arm_pc;
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/arm/safe-syscall.inc.S new file +9 -0
new file mode 100644
index 0000000..52f8883
@@ -0,0 +1,86 @@
+/*
+ * safe-syscall.inc.S : host-specific assembly fragment
+ * to handle signals occurring at the same time as system calls.
+ * This is intended to be included by linux-user/safe-syscall.S
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+

linux-user/host/arm/safe-syscall.inc.S line 19

Quoted 10 lines
linux-user/host/arm/safe-syscall.inc.S new file +10 -0
+       .global safe_syscall_base
+       .global safe_syscall_start
+       .global safe_syscall_end
+       .type   safe_syscall_base, %function
+
+       .cfi_sections   .debug_frame
+
+       .text
+       .syntax unified
+       .arm

Do we need a ".align 2" here? glibc has one.

Quoted 4 lines
linux-user/host/arm/safe-syscall.inc.S new file +4 -0
+
+       /* This is the entry point for making a system call. The calling
+        * convention here is that of a C varargs function with the
+        * first argument an 'int *' to the signal_pending flag, the

linux-user/host/arm/safe-syscall.inc.S line 33

Quoted 10 lines
linux-user/host/arm/safe-syscall.inc.S new file +10 -0
+        * second one the system call number (as a 'long'), and all further
+        * arguments being syscall arguments (also 'long').
+        * We return a long which is the syscall's return value, which
+        * may be negative-errno on failure. Conversion to the
+        * -1-and-errno-set convention is done by the calling wrapper.
+        */
+safe_syscall_base:
+       .fnstart
+       .cfi_startproc
+       mov     ip, sp                  /* save entry stack */

Personally I find the numbered registers like "r12" easier to read than the named versions like "ip" (I always have to look the latter up to find out which register they actually are, so it saves effort to just write r12 in the first place IMHO.)

Quoted 34 lines
linux-user/host/arm/safe-syscall.inc.S new file +34 -0
+       push    { r4, r5, r6, r7, r8, lr }
+       .save   { r4, r5, r6, r7, r8, lr }
+       .cfi_adjust_cfa_offset 24
+       .cfi_rel_offset r4, 0
+       .cfi_rel_offset r5, 4
+       .cfi_rel_offset r6, 8
+       .cfi_rel_offset r7, 12
+       .cfi_rel_offset r8, 16
+       .cfi_rel_offset lr, 20
+
+       /* The syscall calling convention isn't the same as the C one:
+        * we enter with r0 == *signal_pending
+        *               r1 == syscall number
+        *               r2, r3, [sp+0] ... [sp+12] == syscall arguments
+        *               and return the result in r0
+        * and the syscall instruction needs
+        *               r7 == syscall number
+        *               r0 ... r6 == syscall arguments
+        *               and returns the result in r0
+        * Shuffle everything around appropriately.
+        * Note the 16 bytes that we pushed to save registers.
+        */
+       mov     r8, r0                  /* copy signal_pending */
+       mov     r7, r1                  /* syscall number */
+       mov     r0, r2                  /* syscall args */
+       mov     r1, r3
+       ldm     ip, { r2, r3, r4, r5, r6 }
+
+       /* This next sequence of code works in conjunction with the
+        * rewind_if_safe_syscall_function(). If a signal is taken
+        * and the interrupted PC is anywhere between 'safe_syscall_start'
+        * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
+        * The code sequence must therefore be able to cope with this, and
+        * the syscall instruction must be the final one in the sequence.

linux-user/host/arm/safe-syscall.inc.S line 77

Quoted 10 lines
linux-user/host/arm/safe-syscall.inc.S new file +10 -0
+        */
+safe_syscall_start:
+       /* if signal_pending is non-zero, don't do the call */
+       ldr     ip, [r8]                /* signal_pending */
+       tst     ip, ip
+       bne     1f
+       swi     0
+safe_syscall_end:
+       /* code path for having successfully executed the syscall */
+       pop     { r4, r5, r6, r7, r8, pc }

Worth commenting here that we assume that we're not trying to do old ARMv4T interworking ?

Quoted 10 lines
linux-user/host/arm/safe-syscall.inc.S new file +9 -1
+
+1:
+       /* code path when we didn't execute the syscall */
+       ldr     r0, =-TARGET_ERESTARTSYS
+       pop     { r4, r5, r6, r7, r8, pc }
+       .fnend
+       .cfi_endproc
+
+       .size   safe_syscall_base, .-safe_syscall_base
--
Quoted 2 lines

2.5.5

Otherwise

thanks
-- PMM

Signature · 2 lines
12345678901234567890123456789012345678901234567890123456789012345678901234567890
         1         2         3         4         5         6         7         8
#9 lore raw

Re: [Qemu-devel] [PATCH 3/6] linux-user: Provide safe_syscall for arm

Quoted 68 lines · Peter Maydell
Quoted 67 lines · Richard Henderson
---
 linux-user/host/arm/hostdep.h          | 34 ++++++++++++++
 linux-user/host/arm/safe-syscall.inc.S | 86 ++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 linux-user/host/arm/hostdep.h
 create mode 100644 linux-user/host/arm/safe-syscall.inc.S
linux-user/host/arm/hostdep.h new file +34 -0
new file mode 100644
index 0000000..1426fb6
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    unsigned long *pcreg = &uc->uc_mcontext.arm_pc;
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/arm/safe-syscall.inc.S new file +13 -0
new file mode 100644
index 0000000..52f8883
@@ -0,0 +1,86 @@
+/*
+ * safe-syscall.inc.S : host-specific assembly fragment
+ * to handle signals occurring at the same time as system calls.
+ * This is intended to be included by linux-user/safe-syscall.S
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+       .global safe_syscall_base
+       .global safe_syscall_start
+       .global safe_syscall_end
+       .type   safe_syscall_base, %function
Quoted 8 lines

linux-user/host/arm/safe-syscall.inc.S line 19

Quoted 6 lines
linux-user/host/arm/safe-syscall.inc.S new file +6 -0
+
+       .cfi_sections   .debug_frame
+
+       .text
+       .syntax unified
+       .arm

Do we need a ".align 2" here? glibc has one.

It's probably best to have one.

Quoted 6 lines

linux-user/host/arm/safe-syscall.inc.S line 33

Quoted 1 line
linux-user/host/arm/safe-syscall.inc.S new file +1 -0
+       mov     ip, sp                  /* save entry stack */

Personally I find the numbered registers like "r12" easier to read than the named versions like "ip" (I always have to look the latter up to find out which register they actually are, so it saves effort to just write r12 in the first place IMHO.)

That's fine.

Quoted 5 lines

linux-user/host/arm/safe-syscall.inc.S line 22

Quoted 2 lines
linux-user/host/arm/safe-syscall.inc.S new file +2 -0
+       /* code path for having successfully executed the syscall */
+       pop     { r4, r5, r6, r7, r8, pc }

Worth commenting here that we assume that we're not trying to do old ARMv4T interworking ?

At one time weren't we talking about dropping host support for really old arm (pre arm5t?). I seem to recall making a note about some possible cleanups to tcg/arm/.

If so, then we shouldn't be noting that specifically here, but somewhere else. Perhaps README (although it forwards most everything to the web site), or even a configure test.

r~

#10 lore raw

PATCH 4/6 linux-user: Provide safe_syscall for aarch64

In reply to Richard Henderson
---
 linux-user/host/aarch64/hostdep.h          | 34 ++++++++++++++
 linux-user/host/aarch64/safe-syscall.inc.S | 72 ++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 linux-user/host/aarch64/hostdep.h
 create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S
linux-user/host/aarch64/hostdep.h new file +34 -0
new file mode 100644
index 0000000..0ff7985
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    __u64 *pcreg = &uc->uc_mcontext.pc;
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/aarch64/safe-syscall.inc.S new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.5.5
#11 lore raw

Re: [Qemu-devel] [PATCH 4/6] linux-user: Provide safe_syscall for aarch64

Quoted 59 lines · Richard Henderson
---
 linux-user/host/aarch64/hostdep.h          | 34 ++++++++++++++
 linux-user/host/aarch64/safe-syscall.inc.S | 72 ++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 linux-user/host/aarch64/hostdep.h
 create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S
linux-user/host/aarch64/hostdep.h new file +34 -0
new file mode 100644
index 0000000..0ff7985
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    __u64 *pcreg = &uc->uc_mcontext.pc;
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/aarch64/safe-syscall.inc.S new file +5 -0
new file mode 100644
index 0000000..5416b90
@@ -0,0 +1,72 @@
+/*
+ * safe-syscall.inc.S : host-specific assembly fragment
+ * to handle signals occurring at the same time as system calls.
+ * This is intended to be included by linux-user/safe-syscall.S
+ *

linux-user/host/aarch64/safe-syscall.inc.S line 15

Quoted 10 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +10 -0
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+        .global safe_syscall_base
+        .global safe_syscall_start
+        .global safe_syscall_end
+        .type   safe_syscall_base, #function
+        .type   safe_syscall_start, #function
+        .type   safe_syscall_end, #function

_start and _end aren't function entry points, so is it OK to mark them as functions?

(The 'as' manual doesn't document what setting .type does in much detail...)

Quoted 14 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +14 -0
+
+        /* This is the entry point for making a system call. The calling
+         * convention here is that of a C varargs function with the
+         * first argument an 'int *' to the signal_pending flag, the
+         * second one the system call number (as a 'long'), and all further
+         * arguments being syscall arguments (also 'long').
+         * We return a long which is the syscall's return value, which
+         * may be negative-errno on failure. Conversion to the
+         * -1-and-errno-set convention is done by the calling wrapper.
+         */
+safe_syscall_base:
+        .cfi_startproc
+        /* The syscall calling convention isn't the same as the
+         * C one:

linux-user/host/aarch64/safe-syscall.inc.S line 39

Quoted 10 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +10 -0
+         * we enter with x0 == *signal_pending
+         *               x1 == syscall number
+         *               x2 ... x7, (stack) == syscall arguments
+         *               and return the result in x0
+         * and the syscall instruction needs
+         *               x8 == syscall number
+         *               x0 ... x6 == syscall arguments
+         *               and returns the result in x0
+         * Shuffle everything around appropriately.
+         */

http://man7.org/linux/man-pages/man2/syscall.2.html
doesn't mention a syscall argument in x7, just x0..x5.

linux-user/host/aarch64/safe-syscall.inc.S line 41

Quoted 2 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +2 -0
+       mov     x9, x0          /* signal_pending pointer */
+       mov     w8, w1          /* syscall number */

Seems a bit odd to use a 32-bit move for this when our input calling convention has it as 64 bits and the kernel's calling convention has it as 64 bits.

Quoted 32 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +31 -1
+       mov     x0, x2          /* syscall arguments */
+       mov     x1, x3
+       mov     x2, x4
+       mov     x3, x5
+       mov     x4, x6
+       mov     x6, x7
+       ldr     x7, [sp]
+
+        /* This next sequence of code works in conjunction with the
+         * rewind_if_safe_syscall_function(). If a signal is taken
+         * and the interrupted PC is anywhere between 'safe_syscall_start'
+         * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
+         * The code sequence must therefore be able to cope with this, and
+         * the syscall instruction must be the final one in the sequence.
+         */
+safe_syscall_start:
+        /* if signal_pending is non-zero, don't do the call */
+       ldr     w10, [x9]
+       cbnz    w10, 0f
+        svc    0x0
+safe_syscall_end:
+        /* code path for having successfully executed the syscall */
+        ret
+
+0:
+        /* code path when we didn't execute the syscall */
+        mov     x0, #-TARGET_ERESTARTSYS
+        ret
+        .cfi_endproc
+
+        .size   safe_syscall_base, .-safe_syscall_base
--
Quoted 2 lines

2.5.5

thanks
-- PMM

#12 lore raw

Re: [Qemu-devel] [PATCH 4/6] linux-user: Provide safe_syscall for aarch64

Quoted 9 lines · Peter Maydell

linux-user/host/aarch64/safe-syscall.inc.S line 15

Quoted 6 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +6 -0
+        .global safe_syscall_base
+        .global safe_syscall_start
+        .global safe_syscall_end
+        .type   safe_syscall_base, #function
+        .type   safe_syscall_start, #function
+        .type   safe_syscall_end, #function

_start and _end aren't function entry points, so is it OK to mark them as functions?

Yes. Indeed, if you don't, the objdump will think these are data symbols and fail to disassemble the instructions that follow.

Quoted 2 lines

(The 'as' manual doesn't document what setting .type does in much detail...)

It sets the Elf_Sym.st_type field.
But what that implies is very host specific.

Quoted 2 lines

http://man7.org/linux/man-pages/man2/syscall.2.html
doesn't mention a syscall argument in x7, just x0..x5.

I took glibc as definitive, since that's code that definitely works.

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/syscall.S;h=98c1b42ee96fe0fb39955849773ca16d095803e0;hb=HEAD

I'll also point you at the kernel's __sys_trace, which does in fact save and restore all 8 registers around the tracing call-outs.

Quoted 6 lines

linux-user/host/aarch64/safe-syscall.inc.S line 41

Quoted 2 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +2 -0
+       mov     x9, x0          /* signal_pending pointer */
+       mov     w8, w1          /* syscall number */

Seems a bit odd to use a 32-bit move for this when our input calling convention has it as 64 bits and the kernel's calling convention has it as 64 bits.

I got that from glibc too.

r~

#13 lore raw

Re: [Qemu-devel] [PATCH 4/6] linux-user: Provide safe_syscall for aarch64

Quoted 10 lines · Richard Henderson
Quoted 9 lines · Peter Maydell
Quoted 7 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +6 -0
+        .global safe_syscall_base
+        .global safe_syscall_start
+        .global safe_syscall_end
+        .type   safe_syscall_base, #function
+        .type   safe_syscall_start, #function
+        .type   safe_syscall_end, #function
Quoted 6 lines
Quoted 2 lines

_start and _end aren't function entry points, so is it OK to mark them as functions?

Yes. Indeed, if you don't, the objdump will think these are data symbols and fail to disassemble the instructions that follow.

I was told this was an objdump bug... it certainly seems like an objdump bug to me, because this works on the other architectures.
https://bugs.linaro.org/show_bug.cgi?id=815

Quoted 11 lines
Quoted 2 lines

(The 'as' manual doesn't document what setting .type does in much detail...)

It sets the Elf_Sym.st_type field.
But what that implies is very host specific.

Quoted 2 lines

http://man7.org/linux/man-pages/man2/syscall.2.html
doesn't mention a syscall argument in x7, just x0..x5.

I took glibc as definitive, since that's code that definitely works.

If we never use the 7th syscall argument (and we can't, since it doesn't exist on some hosts), then it's unnecessary work, though I guess coming back to fix all these host functions later might be tedious.

Quoted 9 lines

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/syscall.S;h=98c1b42ee96fe0fb39955849773ca16d095803e0;hb=HEAD

I'll also point you at the kernel's __sys_trace, which does in fact save and restore all 8 registers around the tracing call-outs.

Quoted 4 lines
Quoted 2 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +2 -0
+       mov     x9, x0          /* signal_pending pointer */
+       mov     w8, w1          /* syscall number */
Quoted 6 lines
Quoted 3 lines

Seems a bit odd to use a 32-bit move for this when our input calling convention has it as 64 bits and the kernel's calling convention has it as 64 bits.

I got that from glibc too.

glibc's syscall() takes the system parameter as an int and does a sign-extending move into x0 with an uxtw. safe_syscall() takes a long, so it's already 64 bits.

thanks
-- PMM

#14 lore raw

Re: [Qemu-devel] [PATCH 4/6] linux-user: Provide safe_syscall for aarch64

Quoted 2 lines · Peter Maydell

glibc's syscall() takes the system parameter as an int and does a sign-extending move into x0 with an uxtw.

...zero-extending...

-- PMM

#15 lore raw

Re: [Qemu-devel] [PATCH 4/6] linux-user: Provide safe_syscall for aarch64

In reply to Peter Maydell
Quoted 15 lines · Peter Maydell
Quoted 14 lines · Richard Henderson
Quoted 11 lines · Peter Maydell

linux-user/host/aarch64/safe-syscall.inc.S line 15

Quoted 7 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +6 -0
+        .global safe_syscall_base
+        .global safe_syscall_start
+        .global safe_syscall_end
+        .type   safe_syscall_base, #function
+        .type   safe_syscall_start, #function
+        .type   safe_syscall_end, #function

_start and _end aren't function entry points, so is it OK to mark them as functions?

Quoted 7 lines
Quoted 2 lines

Yes. Indeed, if you don't, the objdump will think these are data symbols and fail to disassemble the instructions that follow.

I was told this was an objdump bug... it certainly seems like an objdump bug to me, because this works on the other architectures.
https://bugs.linaro.org/show_bug.cgi?id=815

This may be a hold-over from arm32, which as you recall has a rather complicated scheme for annotating data vs instructions.

Quoted 6 lines
Quoted 1 line

I took glibc as definitive, since that's code that definitely works.

If we never use the 7th syscall argument (and we can't, since it doesn't exist on some hosts), then it's unnecessary work, though I guess coming back to fix all these host functions later might be tedious.

You're probably right about the 7th syscall argument on a 64-bit host.

Quoted 3 lines

glibc's syscall() takes the system parameter as an int and does a sign-extending move into x0 with an uxtw. safe_syscall() takes a long, so it's already 64 bits.

Well, uxtw is a zero-extending move. So...

r~

#16 lore raw

Re: [Qemu-devel] [PATCH 4/6] linux-user: Provide safe_syscall for aarch64

Quoted 7 lines · Richard Henderson
Quoted 3 lines · Peter Maydell

glibc's syscall() takes the system parameter as an int and does a sign-extending move into x0 with an uxtw. safe_syscall() takes a long, so it's already 64 bits.

Well, uxtw is a zero-extending move. So...

Yeah 'sign-extending' was a thinko. But the point is that for syscall() the input is 32 bits and the value it feeds to the kernel is 64 bits, hence the extension. For safe_syscall() the input is 64 bits and the value fed to the kernel is also 64 bits, so the most 'natural' thing is just to move a
64 bit value (saves the reader looking up whether mov wX, wY clears the high half or not, if nothing else).

thanks
-- PMM

#17 lore raw

PATCH 5/6 linux-user: Provide safe_syscall for s390x

In reply to Richard Henderson
---
 linux-user/host/s390x/hostdep.h          | 34 +++++++++++++
 linux-user/host/s390x/safe-syscall.inc.S | 87 ++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 linux-user/host/s390x/hostdep.h
 create mode 100644 linux-user/host/s390x/safe-syscall.inc.S
linux-user/host/s390x/hostdep.h new file +34 -0
new file mode 100644
index 0000000..e94745f
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    unsigned long *pcreg = &uc->uc_mcontext.psw.addr;
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/s390x/safe-syscall.inc.S new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.5.5
#18 lore raw

PATCH 6/6 linux-user: Provide safe_syscall for ppc64

In reply to Richard Henderson
---
 linux-user/host/ppc64/hostdep.h          | 34 +++++++++++++
 linux-user/host/ppc64/safe-syscall.inc.S | 87 ++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 linux-user/host/ppc64/hostdep.h
 create mode 100644 linux-user/host/ppc64/safe-syscall.inc.S
linux-user/host/ppc64/hostdep.h new file +34 -0
new file mode 100644
index 0000000..81e3d55
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    unsigned long *pcreg = &uc->uc_mcontext.gp_regs[PT_NIP];
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/ppc64/safe-syscall.inc.S new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.5.5
#19 lore raw

Re: [Qemu-devel] [PATCH 6/6] linux-user: Provide safe_syscall for ppc64

Quoted 54 lines · Richard Henderson
---
 linux-user/host/ppc64/hostdep.h          | 34 +++++++++++++
 linux-user/host/ppc64/safe-syscall.inc.S | 87 ++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 linux-user/host/ppc64/hostdep.h
 create mode 100644 linux-user/host/ppc64/safe-syscall.inc.S
linux-user/host/ppc64/hostdep.h new file +34 -0
new file mode 100644
index 0000000..81e3d55
@@ -0,0 +1,34 @@
+/*
+ * hostdep.h : things which are dependent on the host architecture
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_HOSTDEP_H
+#define QEMU_HOSTDEP_H
+
+/* We have a safe-syscall.inc.S */
+#define HAVE_SAFE_SYSCALL
+
+#ifndef __ASSEMBLER__
+
+/* These are defined by the safe-syscall.inc.S file */
+extern char safe_syscall_start[];
+extern char safe_syscall_end[];
+
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    struct ucontext *uc = puc;
+    unsigned long *pcreg = &uc->uc_mcontext.gp_regs[PT_NIP];
+
+    if (*pcreg > (uintptr_t)safe_syscall_start
+        && *pcreg < (uintptr_t)safe_syscall_end) {
+        *pcreg = (uintptr_t)safe_syscall_start;
+    }
+}
+
+#endif /* __ASSEMBLER__ */
+
+#endif
linux-user/host/ppc64/safe-syscall.inc.S new file +0 -0
new file mode 100644
index 0000000..89e979c

linux-user/host/ppc64/safe-syscall.inc.S line 6

Quoted 6 lines
linux-user/host/ppc64/safe-syscall.inc.S new file +6 -0
@@ -0,0 +1,87 @@
+/*
+ * safe-syscall.inc.S : host-specific assembly fragment
+ * to handle signals occurring at the same time as system calls.
+ * This is intended to be included by linux-user/safe-syscall.S
+ *
+ * Copyright (C) 2015 Timothy Edward Baldwin <[email protected]>

I would say this ppc code was copyright you (or RedHat depending which hat you're wearing), not Timothy.

thanks
-- PMM

#20 lore raw
In reply to Richard Henderson
Quoted 7 lines · Richard Henderson

We added support for x86_64 in 4d330cee37a2; this adds support for 5 more hosts. Also, tweak the signal_pending test for x86_64.

r~

Quoted 7 lines

Richard Henderson (6):
linux-user: fix x86_64 safe_syscall
linux-user: Provide safe_syscall for i386
linux-user: Provide safe_syscall for arm
linux-user: Provide safe_syscall for aarch64
linux-user: Provide safe_syscall for s390x
linux-user: Provide safe_syscall for ppc64

I just spent today writing these for i386, arm and aarch64, so we've duplicated work here :-(

-- PMM

#21 lore raw
Quoted 11 lines · Peter Maydell
Quoted 7 lines · Richard Henderson

Richard Henderson (6):
linux-user: fix x86_64 safe_syscall
linux-user: Provide safe_syscall for i386
linux-user: Provide safe_syscall for arm
linux-user: Provide safe_syscall for aarch64
linux-user: Provide safe_syscall for s390x
linux-user: Provide safe_syscall for ppc64

I just spent today writing these for i386, arm and aarch64, so we've duplicated work here :-(

Also, I have a patchset which moves from the generic/hostdep.h to having explicitly one hostdep.h per supported architecture. That needs to go in before these, otherwise these break compilation unless you do a 'make clean'.

I'll send that out tomorrow, working version in
https://git.linaro.org/people/peter.maydell/qemu-arm.git/shortlog/refs/heads/sigrace-fixes

We also have a bug in the signal.c code which I noticed trying to test my i386 safe_syscall: we call sigfillset() on the uc_sigmask field of the ucontext_t* that the kernel passes us as argument 3 of the signal handler. This trashes a lot of stuff on the stack because the libc headers say "sigset_t is 128 bytes" and the kernel says "it's only 8 bytes", so the sigfillset() writes -1 to a lot of the stack that it shouldn't. (I don't know why glibc exposes a struct that isn't actually what the kernel provides here, but it's a very long standing confusion :-( )

thanks
-- PMM

#22 lore raw
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Richard Henderson

Richard Henderson (6):
linux-user: fix x86_64 safe_syscall
linux-user: Provide safe_syscall for i386
linux-user: Provide safe_syscall for arm
linux-user: Provide safe_syscall for aarch64
linux-user: Provide safe_syscall for s390x
linux-user: Provide safe_syscall for ppc64

Quoted 2 lines
Quoted 2 lines

I just spent today writing these for i386, arm and aarch64, so we've duplicated work here :-(

On the positive side, duplication makes it easier to give a really throughout review :)

Quoted 7 lines

Also, I have a patchset which moves from the generic/hostdep.h to having explicitly one hostdep.h per supported architecture. That needs to go in before these, otherwise these break compilation unless you do a 'make clean'.

I'll send that out tomorrow, working version in
https://git.linaro.org/people/peter.maydell/qemu-arm.git/shortlog/refs/heads/sigrace-fixes

I've merged all pending patches except the safe_syscall ones to:

https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/linux-user-for-upstream

Peter, Richard, do you have an agreement who's versions of the safe_syscall patches should be included?

Riku

Quoted 14 lines

We also have a bug in the signal.c code which I noticed trying to test my i386 safe_syscall: we call sigfillset() on the uc_sigmask field of the ucontext_t* that the kernel passes us as argument 3 of the signal handler. This trashes a lot of stuff on the stack because the libc headers say "sigset_t is 128 bytes" and the kernel says "it's only 8 bytes", so the sigfillset() writes -1 to a lot of the stack that it shouldn't. (I don't know why glibc exposes a struct that isn't actually what the kernel provides here, but it's a very long standing confusion :-( )

thanks
-- PMM

#23 lore raw
Quoted 6 lines · Riku Voipio

I've merged all pending patches except the safe_syscall ones to:

https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/linux-user-for-upstream

Peter, Richard, do you have an agreement who's versions of the safe_syscall patches should be included?

I'm happy to go with Richard's patches (he caught a few issues my versions missed), but
(a) I had code review comments on some of them
(b) they'll have some trivial textual conflicts when they get rebased on top of the patches that provide a hostdep.h for every arch

thanks
-- PMM