From: Warner Losh <imp@bsdimp.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: "Laurent Vivier" <laurent@vivier.eu>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Khem Raj" <raj.khem@gmail.com>
Subject: Re: [PATCH for-6.2 2/2] linux-user/signal.c: Create a common rewind_if_in_safe_syscall
Date: Mon, 22 Nov 2021 08:01:02 -0700 [thread overview]
Message-ID: <CANCZdfred9sw_3beK6_eGRJSg9wVhbzotWatCbesEyEh5RGPpQ@mail.gmail.com> (raw)
In-Reply-To: <20211122131200.229286-3-richard.henderson@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 9938 bytes --]
On Mon, Nov 22, 2021 at 6:12 AM Richard Henderson <
richard.henderson@linaro.org> wrote:
> From: Warner Losh <imp@bsdimp.com>
>
> All instances of rewind_if_in_safe_syscall are the same, differing only
> in how the instruction point is fetched from the ucontext and the size
> of the registers. Use host_signal_pc and new host_signal_set_pc
> interfaces to fetch the pointer to the PC and adjust if needed. Delete
> all the old copies of rewind_if_in_safe_syscall.
>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Message-Id: <20211113045603.60391-3-imp@bsdimp.com>
> [rth: include safe-syscall.h, simplify ifdefs]
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/host/aarch64/hostdep.h | 20 --------------------
> linux-user/host/arm/hostdep.h | 20 --------------------
> linux-user/host/i386/hostdep.h | 20 --------------------
> linux-user/host/ppc64/hostdep.h | 20 --------------------
> linux-user/host/riscv/hostdep.h | 20 --------------------
> linux-user/host/s390x/hostdep.h | 20 --------------------
> linux-user/host/x86_64/hostdep.h | 20 --------------------
> linux-user/safe-syscall.h | 3 +++
> linux-user/signal.c | 15 ++++++++++++---
> 9 files changed, 15 insertions(+), 143 deletions(-)
>
Reviewed-by: Warner Losh <imp@bsdimp.com>
The changes to what I wrote look good.
Warner
> diff --git a/linux-user/host/aarch64/hostdep.h
> b/linux-user/host/aarch64/hostdep.h
> index a8d41a21ad..39299d798a 100644
> --- a/linux-user/host/aarch64/hostdep.h
> +++ b/linux-user/host/aarch64/hostdep.h
> @@ -15,24 +15,4 @@
> /* 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)
> -{
> - ucontext_t *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/arm/hostdep.h b/linux-user/host/arm/hostdep.h
> index 9276fe6ceb..86b137875a 100644
> --- a/linux-user/host/arm/hostdep.h
> +++ b/linux-user/host/arm/hostdep.h
> @@ -15,24 +15,4 @@
> /* 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)
> -{
> - ucontext_t *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/i386/hostdep.h
> b/linux-user/host/i386/hostdep.h
> index 073be74d87..ce7136501f 100644
> --- a/linux-user/host/i386/hostdep.h
> +++ b/linux-user/host/i386/hostdep.h
> @@ -15,24 +15,4 @@
> /* 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)
> -{
> - ucontext_t *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/ppc64/hostdep.h
> b/linux-user/host/ppc64/hostdep.h
> index 98979ad917..0c290dd904 100644
> --- a/linux-user/host/ppc64/hostdep.h
> +++ b/linux-user/host/ppc64/hostdep.h
> @@ -15,24 +15,4 @@
> /* 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)
> -{
> - ucontext_t *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/riscv/hostdep.h
> b/linux-user/host/riscv/hostdep.h
> index 2ba07456ae..7f67c22868 100644
> --- a/linux-user/host/riscv/hostdep.h
> +++ b/linux-user/host/riscv/hostdep.h
> @@ -11,24 +11,4 @@
> /* 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)
> -{
> - ucontext_t *uc = puc;
> - unsigned long *pcreg = &uc->uc_mcontext.__gregs[REG_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/s390x/hostdep.h
> b/linux-user/host/s390x/hostdep.h
> index 4f0171f36f..d801145854 100644
> --- a/linux-user/host/s390x/hostdep.h
> +++ b/linux-user/host/s390x/hostdep.h
> @@ -15,24 +15,4 @@
> /* 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)
> -{
> - ucontext_t *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/x86_64/hostdep.h
> b/linux-user/host/x86_64/hostdep.h
> index a4fefb5114..9c62bd26bd 100644
> --- a/linux-user/host/x86_64/hostdep.h
> +++ b/linux-user/host/x86_64/hostdep.h
> @@ -15,24 +15,4 @@
> /* 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)
> -{
> - ucontext_t *uc = puc;
> - greg_t *pcreg = &uc->uc_mcontext.gregs[REG_RIP];
> -
> - 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/safe-syscall.h b/linux-user/safe-syscall.h
> index 6bc0390262..aaa9ffc0e2 100644
> --- a/linux-user/safe-syscall.h
> +++ b/linux-user/safe-syscall.h
> @@ -127,6 +127,9 @@
> #ifdef HAVE_SAFE_SYSCALL
> /* The core part of this function is implemented in assembly */
> extern long safe_syscall_base(int *pending, long number, ...);
> +/* These are defined by the safe-syscall.inc.S file */
> +extern char safe_syscall_start[];
> +extern char safe_syscall_end[];
>
> #define safe_syscall(...) \
> ({ \
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 81c45bfce9..6d5e5b698c 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -31,6 +31,7 @@
> #include "trace.h"
> #include "signal-common.h"
> #include "host-signal.h"
> +#include "safe-syscall.h"
>
> static struct target_sigaction sigact_table[TARGET_NSIG];
>
> @@ -793,12 +794,20 @@ int queue_signal(CPUArchState *env, int sig, int
> si_type,
> return 1; /* indicates that the signal was queued */
> }
>
> -#ifndef HAVE_SAFE_SYSCALL
> +
> +/* 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)
> {
> - /* Default version: never rewind */
> -}
> +#ifdef HAVE_SAFE_SYSCALL
> + ucontext_t *uc = (ucontext_t *)puc;
> + uintptr_t pcreg = host_signal_pc(uc);
> +
> + if (pcreg > (uintptr_t)safe_syscall_start
> + && pcreg < (uintptr_t)safe_syscall_end) {
> + host_signal_set_pc(uc, (uintptr_t)safe_syscall_start);
> + }
> #endif
> +}
>
> static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
> {
> --
> 2.25.1
>
>
[-- Attachment #2: Type: text/html, Size: 11932 bytes --]
next prev parent reply other threads:[~2021-11-22 15:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 13:11 [PATCH for-6.2 0/2] linux-user: Create a common rewind_if_in_safe_syscall Richard Henderson
2021-11-22 13:11 ` [PATCH for-6.2 1/2] linux-user: Add host_signal_set_pc to set pc in mcontext Richard Henderson
2021-11-22 15:02 ` Warner Losh
2021-11-22 13:12 ` [PATCH for-6.2 2/2] linux-user/signal.c: Create a common rewind_if_in_safe_syscall Richard Henderson
2021-11-22 15:01 ` Warner Losh [this message]
2021-11-22 15:43 ` [PATCH for-6.2 0/2] linux-user: " Laurent Vivier
2021-11-22 15:50 ` Richard Henderson
2021-11-22 16:08 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANCZdfred9sw_3beK6_eGRJSg9wVhbzotWatCbesEyEh5RGPpQ@mail.gmail.com \
--to=imp@bsdimp.com \
--cc=f4bug@amsat.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=raj.khem@gmail.com \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).