[RFC PATCH 6/7] linux-user: Handle SIGSEGV/SIGBUS in host_to_target_siginfo_noswap

Richard Henderson posted 7 patches 4 years, 4 months ago
Maintainers: Chris Wulff <crwulff@gmail.com>, Richard Henderson <richard.henderson@linaro.org>, Marek Vasut <marex@denx.de>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Riku Voipio <riku.voipio@iki.fi>, David Hildenbrand <david@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Stafford Horne <shorne@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Bin Meng <bin.meng@windriver.com>, Artyom Tarasenko <atar4qemu@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Jiaxun Yang <jiaxun.yang@flygoat.com>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Thomas Huth <thuth@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>, Palmer Dabbelt <palmer@dabbelt.com>, Greg Kurz <groug@kaod.org>, Alistair Francis <alistair.francis@wdc.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Taylor Simpson <tsimpson@quicinc.com>, Max Filippov <jcmvbkbc@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Michael Rolnik <mrolnik@gmail.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
[RFC PATCH 6/7] linux-user: Handle SIGSEGV/SIGBUS in host_to_target_siginfo_noswap
Posted by Richard Henderson 4 years, 4 months ago
Remap the faulting address from the host address space into
the guest address space.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/signal.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index a8faea6f09..73c0f9066b 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -405,6 +405,15 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
             tinfo->_sifields._sigpoll._fd = info->si_fd;
             si_type = QEMU_SI_POLL;
             break;
+        case TARGET_SIGSEGV:
+        case TARGET_SIGBUS:
+            /*
+             * Remap the host address into the target space.
+             * Even an invalid guest address is still valid for a fault.
+             */
+            tinfo->_sifields._sigfault._addr = h2g_nocheck(info->si_addr);
+            si_type = QEMU_SI_FAULT;
+            break;
         default:
             /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
             tinfo->_sifields._rt._pid = info->si_pid;
-- 
2.25.1


Re: [RFC PATCH 6/7] linux-user: Handle SIGSEGV/SIGBUS in host_to_target_siginfo_noswap
Posted by Warner Losh 4 years, 4 months ago
On Mon, Sep 13, 2021 at 4:05 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> Remap the faulting address from the host address space into
> the guest address space.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/signal.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>

If I'm understanding this right, the FreeBSD code in the bsd-user fork
won't be affected by this change.
(or conversely, it's so far behind the linux stuff that it will need to be
completely
revamped).

Warner


> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index a8faea6f09..73c0f9066b 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -405,6 +405,15 @@ static inline void
> host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
>              tinfo->_sifields._sigpoll._fd = info->si_fd;
>              si_type = QEMU_SI_POLL;
>              break;
> +        case TARGET_SIGSEGV:
> +        case TARGET_SIGBUS:
> +            /*
> +             * Remap the host address into the target space.
> +             * Even an invalid guest address is still valid for a fault.
> +             */
> +            tinfo->_sifields._sigfault._addr = h2g_nocheck(info->si_addr);
> +            si_type = QEMU_SI_FAULT;
> +            break;
>          default:
>              /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source.
> */
>              tinfo->_sifields._rt._pid = info->si_pid;
> --
> 2.25.1
>
>
Re: [RFC PATCH 6/7] linux-user: Handle SIGSEGV/SIGBUS in host_to_target_siginfo_noswap
Posted by Richard Henderson 4 years, 4 months ago
On 9/15/21 9:23 AM, Warner Losh wrote:
> 
> 
> On Mon, Sep 13, 2021 at 4:05 PM Richard Henderson <richard.henderson@linaro.org 
> <mailto:richard.henderson@linaro.org>> wrote:
> 
>     Remap the faulting address from the host address space into
>     the guest address space.
> 
>     Signed-off-by: Richard Henderson <richard.henderson@linaro.org
>     <mailto:richard.henderson@linaro.org>>
>     ---
>       linux-user/signal.c | 9 +++++++++
>       1 file changed, 9 insertions(+)
> 
> 
> Reviewed-by: Warner Losh <imp@bsdimp.com <mailto:imp@bsdimp.com>>
> 
> If I'm understanding this right, the FreeBSD code in the bsd-user fork won't be affected 
> by this change.
> (or conversely, it's so far behind the linux stuff that it will need to be completely
> revamped).

The converse, yes.  I haven't looked at your branch, but I assume that it'll be easier 
with this cleanup than without.  FWIW.


r~