Skip to contentSkip to conversation

linux-user: safe_syscall updates

PATCH In review Richard Henderson 3 participants 10 messages Jun 22, 2016 – Jun 24, 2016

lore
Share & tools
lore
#4 lore raw

PATCH v2 3/5 linux-user: Provide safe_syscall for aarch64

In reply to Richard Henderson
---
 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
linux-user/host/aarch64/hostdep.h +23 -0
index 7609bf5..b79eaf1 100644
@@ -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
linux-user/host/aarch64/safe-syscall.inc.S new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
2.5.5
#6 lore raw

PATCH v2 4/5 linux-user: Provide safe_syscall for s390x

In reply to Richard Henderson
---
 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
linux-user/host/s390x/hostdep.h +23 -0
index 7609bf5..e95871c 100644
@@ -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
linux-user/host/s390x/safe-syscall.inc.S new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.5.5
#0 lore raw

v2 cover linux-user: safe_syscall updates

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
Signature · 1 line
2.5.5
#3 lore raw

PATCH v2 2/5 linux-user: Provide safe_syscall for arm

---
 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
linux-user/host/arm/hostdep.h +23 -0
index 7609bf5..8e1ff2f 100644
@@ -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
linux-user/host/arm/safe-syscall.inc.S new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.5.5
#7 lore raw

PATCH v2 5/5 linux-user: Provide safe_syscall for ppc64

In reply to Richard Henderson
---
 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
linux-user/host/ppc64/hostdep.h +23 -0
index 7609bf5..310e7d1 100644
@@ -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
linux-user/host/ppc64/safe-syscall.inc.S new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.5.5
#1 lore raw

PATCH v2 1/5 linux-user: Provide safe_syscall for i386

In reply to Richard Henderson
---
 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
linux-user/host/i386/hostdep.h +23 -0
index 7609bf5..5a12f4a 100644
@@ -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
linux-user/host/i386/safe-syscall.inc.S new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.5.5
Reviewed-by on v2 3/5
#5 lore raw

Re: [Qemu-devel] [PATCH v2 3/5] linux-user: Provide safe_syscall for aarch64

In reply to Richard Henderson
Quoted 20 lines · Richard Henderson
---
 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
linux-user/host/aarch64/safe-syscall.inc.S new file +13 -0
+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.

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

Quoted 10 lines
linux-user/host/aarch64/safe-syscall.inc.S new file +10 -0
+        */
+       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

thanks
-- PMM

Reviewed-by on v2 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] linux-user: Provide safe_syscall for i386

In reply to Richard Henderson
Quoted 6 lines · Richard Henderson
---
 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

thanks
-- PMM

#8 lore raw
In reply to Richard Henderson
Quoted 5 lines · Richard Henderson

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

#9 lore raw
Quoted 9 lines · Peter Maydell
Quoted 5 lines · Richard Henderson

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