* [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates
@ 2016-06-22 0:32 Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386 Richard Henderson
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: Richard Henderson @ 2016-06-22 0:32 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio
Rebased on Riku's linux-user-for-upstream branch.
Fixed some nits that Peter pointed out.
Fixed the ppc64 version to properly return -errno.
Retested all except s390x, which is, at the moment, inconvenient.
r~
Richard Henderson (5):
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 | 23 ++++++
linux-user/host/aarch64/safe-syscall.inc.S | 75 +++++++++++++++++++
linux-user/host/arm/hostdep.h | 23 ++++++
linux-user/host/arm/safe-syscall.inc.S | 90 +++++++++++++++++++++++
linux-user/host/i386/hostdep.h | 23 ++++++
linux-user/host/i386/safe-syscall.inc.S | 112 +++++++++++++++++++++++++++++
linux-user/host/ppc64/hostdep.h | 23 ++++++
linux-user/host/ppc64/safe-syscall.inc.S | 92 ++++++++++++++++++++++++
linux-user/host/s390x/hostdep.h | 23 ++++++
linux-user/host/s390x/safe-syscall.inc.S | 90 +++++++++++++++++++++++
10 files changed, 574 insertions(+)
create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S
create mode 100644 linux-user/host/arm/safe-syscall.inc.S
create mode 100644 linux-user/host/i386/safe-syscall.inc.S
create mode 100644 linux-user/host/ppc64/safe-syscall.inc.S
create mode 100644 linux-user/host/s390x/safe-syscall.inc.S
--
2.5.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
@ 2016-06-22 0:32 ` Richard Henderson
2016-06-23 12:06 ` Peter Maydell
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 2/5] linux-user: Provide safe_syscall for arm Richard Henderson
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Richard Henderson @ 2016-06-22 0:32 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
linux-user/host/i386/hostdep.h | 23 +++++++
linux-user/host/i386/safe-syscall.inc.S | 112 ++++++++++++++++++++++++++++++++
2 files changed, 135 insertions(+)
create mode 100644 linux-user/host/i386/safe-syscall.inc.S
diff --git a/linux-user/host/i386/hostdep.h b/linux-user/host/i386/hostdep.h
index 7609bf5..5a12f4a 100644
--- a/linux-user/host/i386/hostdep.h
+++ b/linux-user/host/i386/hostdep.h
@@ -12,4 +12,27 @@
#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
diff --git a/linux-user/host/i386/safe-syscall.inc.S b/linux-user/host/i386/safe-syscall.inc.S
new file mode 100644
index 0000000..766d0de
--- /dev/null
+++ b/linux-user/host/i386/safe-syscall.inc.S
@@ -0,0 +1,112 @@
+/*
+ * 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
+ *
+ * Written by Richard Henderson <rth@twiddle.net>
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * 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
+
+ /* 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
+ 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
+ .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'
+ * 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)
+ jnz 1f
+ mov 8+16(%esp), %eax /* syscall number */
+ int $0x80
+safe_syscall_end:
+ /* code path for having successfully executed the syscall */
+ pop %ebx
+ .cfi_remember_state
+ .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
+
+1:
+ /* code path when we didn't execute the syscall */
+ .cfi_restore_state
+ mov $-TARGET_ERESTARTSYS, %eax
+ pop %ebx
+ .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
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v2 2/5] linux-user: Provide safe_syscall for arm
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386 Richard Henderson
@ 2016-06-22 0:32 ` Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64 Richard Henderson
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Richard Henderson @ 2016-06-22 0:32 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
linux-user/host/arm/hostdep.h | 23 +++++++++
linux-user/host/arm/safe-syscall.inc.S | 90 ++++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
create mode 100644 linux-user/host/arm/safe-syscall.inc.S
diff --git a/linux-user/host/arm/hostdep.h b/linux-user/host/arm/hostdep.h
index 7609bf5..8e1ff2f 100644
--- a/linux-user/host/arm/hostdep.h
+++ b/linux-user/host/arm/hostdep.h
@@ -12,4 +12,27 @@
#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
diff --git a/linux-user/host/arm/safe-syscall.inc.S b/linux-user/host/arm/safe-syscall.inc.S
new file mode 100644
index 0000000..88c4958
--- /dev/null
+++ b/linux-user/host/arm/safe-syscall.inc.S
@@ -0,0 +1,90 @@
+/*
+ * 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
+ *
+ * Written by Richard Henderson <rth@twiddle.net>
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * 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
+
+ .cfi_sections .debug_frame
+
+ .text
+ .syntax unified
+ .arm
+ .align 2
+
+ /* 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:
+ .fnstart
+ .cfi_startproc
+ mov r12, sp /* save entry stack */
+ 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 r12, { 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.
+ */
+safe_syscall_start:
+ /* if signal_pending is non-zero, don't do the call */
+ ldr r12, [r8] /* signal_pending */
+ tst r12, r12
+ bne 1f
+ swi 0
+safe_syscall_end:
+ /* code path for having successfully executed the syscall */
+ pop { r4, r5, r6, r7, r8, pc }
+
+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
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386 Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 2/5] linux-user: Provide safe_syscall for arm Richard Henderson
@ 2016-06-22 0:32 ` Richard Henderson
2016-06-23 12:06 ` Peter Maydell
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 4/5] linux-user: Provide safe_syscall for s390x Richard Henderson
` (2 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Richard Henderson @ 2016-06-22 0:32 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
linux-user/host/aarch64/hostdep.h | 23 +++++++++
linux-user/host/aarch64/safe-syscall.inc.S | 75 ++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S
diff --git a/linux-user/host/aarch64/hostdep.h b/linux-user/host/aarch64/hostdep.h
index 7609bf5..b79eaf1 100644
--- a/linux-user/host/aarch64/hostdep.h
+++ b/linux-user/host/aarch64/hostdep.h
@@ -12,4 +12,27 @@
#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
diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/linux-user/host/aarch64/safe-syscall.inc.S
new file mode 100644
index 0000000..e4058bb
--- /dev/null
+++ b/linux-user/host/aarch64/safe-syscall.inc.S
@@ -0,0 +1,75 @@
+/*
+ * 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
+ *
+ * Written by Richard Henderson <rth@twiddle.net>
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * 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
+
+ /* 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:
+ * 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.
+ */
+ mov x9, x0 /* signal_pending pointer */
+ mov x8, x1 /* syscall number */
+ 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
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v2 4/5] linux-user: Provide safe_syscall for s390x
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
` (2 preceding siblings ...)
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64 Richard Henderson
@ 2016-06-22 0:32 ` Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 5/5] linux-user: Provide safe_syscall for ppc64 Richard Henderson
2016-06-23 12:10 ` [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Peter Maydell
5 siblings, 0 replies; 10+ messages in thread
From: Richard Henderson @ 2016-06-22 0:32 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
linux-user/host/s390x/hostdep.h | 23 ++++++++
linux-user/host/s390x/safe-syscall.inc.S | 90 ++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
create mode 100644 linux-user/host/s390x/safe-syscall.inc.S
diff --git a/linux-user/host/s390x/hostdep.h b/linux-user/host/s390x/hostdep.h
index 7609bf5..e95871c 100644
--- a/linux-user/host/s390x/hostdep.h
+++ b/linux-user/host/s390x/hostdep.h
@@ -12,4 +12,27 @@
#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
diff --git a/linux-user/host/s390x/safe-syscall.inc.S b/linux-user/host/s390x/safe-syscall.inc.S
new file mode 100644
index 0000000..f1b446a
--- /dev/null
+++ b/linux-user/host/s390x/safe-syscall.inc.S
@@ -0,0 +1,90 @@
+/*
+ * 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
+ *
+ * Written by Richard Henderson <rth@twiddle.net>
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * 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
+
+ /* 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
+ stmg %r6,%r15,48(%r15) /* save all call-saved registers */
+ .cfi_offset %r15,-40
+ .cfi_offset %r14,-48
+ .cfi_offset %r13,-56
+ .cfi_offset %r12,-64
+ .cfi_offset %r11,-72
+ .cfi_offset %r10,-80
+ .cfi_offset %r9,-88
+ .cfi_offset %r8,-96
+ .cfi_offset %r7,-104
+ .cfi_offset %r6,-112
+ lgr %r1,%r15
+ lg %r0,8(%r15) /* load eos */
+ aghi %r15,-160
+ .cfi_adjust_cfa_offset 160
+ stg %r1,0(%r15) /* store back chain */
+ stg %r0,8(%r15) /* store eos */
+
+ /* The syscall calling convention isn't the same as the
+ * C one:
+ * we enter with r2 == *signal_pending
+ * r3 == syscall number
+ * r4, r5, r6, (stack) == syscall arguments
+ * and return the result in r2
+ * and the syscall instruction needs
+ * r1 == syscall number
+ * r2 ... r7 == syscall arguments
+ * and returns the result in r2
+ * Shuffle everything around appropriately.
+ */
+ lgr %r8,%r2 /* signal_pending pointer */
+ lgr %r1,%r3 /* syscall number */
+ lgr %r2,%r4 /* syscall args */
+ lgr %r3,%r5
+ lgr %r4,%r6
+ lmg %r5,%r7,320(%r15)
+
+ /* 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 */
+ lt %r0,0(%r8)
+ jne 2f
+ svc 0
+safe_syscall_end:
+
+1: lg %r15,0(%r15) /* load back chain */
+ .cfi_remember_state
+ .cfi_adjust_cfa_offset -160
+ lmg %r6,%r15,48(%r15) /* load saved registers */
+ br %r14
+ .cfi_restore_state
+2: lghi %r2, -TARGET_ERESTARTSYS
+ j 1b
+ .cfi_endproc
+
+ .size safe_syscall_base, .-safe_syscall_base
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v2 5/5] linux-user: Provide safe_syscall for ppc64
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
` (3 preceding siblings ...)
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 4/5] linux-user: Provide safe_syscall for s390x Richard Henderson
@ 2016-06-22 0:32 ` Richard Henderson
2016-06-23 12:10 ` [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Peter Maydell
5 siblings, 0 replies; 10+ messages in thread
From: Richard Henderson @ 2016-06-22 0:32 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
linux-user/host/ppc64/hostdep.h | 23 ++++++++
linux-user/host/ppc64/safe-syscall.inc.S | 92 ++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+)
create mode 100644 linux-user/host/ppc64/safe-syscall.inc.S
diff --git a/linux-user/host/ppc64/hostdep.h b/linux-user/host/ppc64/hostdep.h
index 7609bf5..310e7d1 100644
--- a/linux-user/host/ppc64/hostdep.h
+++ b/linux-user/host/ppc64/hostdep.h
@@ -12,4 +12,27 @@
#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
diff --git a/linux-user/host/ppc64/safe-syscall.inc.S b/linux-user/host/ppc64/safe-syscall.inc.S
new file mode 100644
index 0000000..d30050a
--- /dev/null
+++ b/linux-user/host/ppc64/safe-syscall.inc.S
@@ -0,0 +1,92 @@
+/*
+ * 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
+ *
+ * Written by Richard Henderson <rth@twiddle.net>
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * 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
+
+ .text
+
+ /* 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.
+ */
+#if _CALL_ELF == 2
+safe_syscall_base:
+ .cfi_startproc
+ .localentry safe_syscall_base,0
+#else
+ .section ".opd","aw"
+ .align 3
+safe_syscall_base:
+ .quad .L.safe_syscall_base,.TOC.@tocbase,0
+ .previous
+.L.safe_syscall_base:
+ .cfi_startproc
+#endif
+ /* We enter with r3 == *signal_pending
+ * r4 == syscall number
+ * r5 ... r10 == syscall arguments
+ * and return the result in r3
+ * and the syscall instruction needs
+ * r0 == syscall number
+ * r3 ... r8 == syscall arguments
+ * and returns the result in r3
+ * Shuffle everything around appropriately.
+ */
+ mr 11, 3 /* signal_pending */
+ mr 0, 4 /* syscall number */
+ mr 3, 5 /* syscall arguments */
+ mr 4, 6
+ mr 5, 7
+ mr 6, 8
+ mr 7, 9
+ mr 8, 10
+
+ /* 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 */
+ lwz 12, 0(11)
+ cmpwi 0, 12, 0
+ bne- 0f
+ sc
+safe_syscall_end:
+ /* code path when we did execute the syscall */
+ bnslr+
+
+ /* syscall failed; return negative errno */
+ neg 3, 3
+ blr
+
+ /* code path when we didn't execute the syscall */
+0: addi 3, 0, -TARGET_ERESTARTSYS
+ blr
+ .cfi_endproc
+
+#if _CALL_ELF == 2
+ .size safe_syscall_base, .-safe_syscall_base
+#else
+ .size safe_syscall_base, .-.L.safe_syscall_base
+ .size .L.safe_syscall_base, .-.L.safe_syscall_base
+#endif
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64 Richard Henderson
@ 2016-06-23 12:06 ` Peter Maydell
0 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2016-06-23 12:06 UTC (permalink / raw)
To: Richard Henderson; +Cc: QEMU Developers, Riku Voipio
On 22 June 2016 at 01:32, Richard Henderson <rth@twiddle.net> wrote:
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
> linux-user/host/aarch64/hostdep.h | 23 +++++++++
> linux-user/host/aarch64/safe-syscall.inc.S | 75 ++++++++++++++++++++++++++++++
> 2 files changed, 98 insertions(+)
> create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S
> +safe_syscall_base:
> + .cfi_startproc
> + /* The syscall calling convention isn't the same as the
> + * C one:
> + * 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.
> + */
> + mov x9, x0 /* signal_pending pointer */
> + mov x8, x1 /* syscall number */
> + mov x0, x2 /* syscall arguments */
> + mov x1, x3
> + mov x2, x4
> + mov x3, x5
> + mov x4, x6
> + mov x6, x7
> + ldr x7, [sp]
Comment says "x0 ... x6 == syscall arguments" but the code loads x7 too.
Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386 Richard Henderson
@ 2016-06-23 12:06 ` Peter Maydell
0 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2016-06-23 12:06 UTC (permalink / raw)
To: Richard Henderson; +Cc: QEMU Developers, Riku Voipio
On 22 June 2016 at 01:32, Richard Henderson <rth@twiddle.net> wrote:
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
> linux-user/host/i386/hostdep.h | 23 +++++++
> linux-user/host/i386/safe-syscall.inc.S | 112 ++++++++++++++++++++++++++++++++
> 2 files changed, 135 insertions(+)
> create mode 100644 linux-user/host/i386/safe-syscall.inc.S
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
` (4 preceding siblings ...)
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 5/5] linux-user: Provide safe_syscall for ppc64 Richard Henderson
@ 2016-06-23 12:10 ` Peter Maydell
2016-06-24 9:08 ` Riku Voipio
5 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2016-06-23 12:10 UTC (permalink / raw)
To: Richard Henderson; +Cc: QEMU Developers, Riku Voipio
On 22 June 2016 at 01:32, Richard Henderson <rth@twiddle.net> wrote:
> Rebased on Riku's linux-user-for-upstream branch.
> Fixed some nits that Peter pointed out.
> Fixed the ppc64 version to properly return -errno.
>
> Retested all except s390x, which is, at the moment, inconvenient.
I don't know enough s390/ppc to really review those two patches
but they look right to me.
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates
2016-06-23 12:10 ` [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Peter Maydell
@ 2016-06-24 9:08 ` Riku Voipio
0 siblings, 0 replies; 10+ messages in thread
From: Riku Voipio @ 2016-06-24 9:08 UTC (permalink / raw)
To: Peter Maydell; +Cc: Richard Henderson, QEMU Developers
On Thu, Jun 23, 2016 at 01:10:40PM +0100, Peter Maydell wrote:
> On 22 June 2016 at 01:32, Richard Henderson <rth@twiddle.net> wrote:
> > Rebased on Riku's linux-user-for-upstream branch.
> > Fixed some nits that Peter pointed out.
> > Fixed the ppc64 version to properly return -errno.
> >
> > Retested all except s390x, which is, at the moment, inconvenient.
> I don't know enough s390/ppc to really review those two patches
> but they look right to me.
All pushed to linux-user, thanks!
https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/linux-user-for-upstream
I'll craft a pull req to get these in well before soft freeze.
Riku
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-06-24 9:09 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-22 0:32 [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386 Richard Henderson
2016-06-23 12:06 ` Peter Maydell
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 2/5] linux-user: Provide safe_syscall for arm Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64 Richard Henderson
2016-06-23 12:06 ` Peter Maydell
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 4/5] linux-user: Provide safe_syscall for s390x Richard Henderson
2016-06-22 0:32 ` [Qemu-devel] [PATCH v2 5/5] linux-user: Provide safe_syscall for ppc64 Richard Henderson
2016-06-23 12:10 ` [Qemu-devel] [PATCH v2 0/5] linux-user: safe_syscall updates Peter Maydell
2016-06-24 9:08 ` Riku Voipio
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.