From: "Alex Bennée" <alex.bennee@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, laurent@vivier.eu
Subject: Re: [PATCH v2 3/5] linux-user/i386: Emulate x86_64 vsyscalls
Date: Mon, 20 Jan 2020 11:48:06 +0000 [thread overview]
Message-ID: <87v9p62vt5.fsf@linaro.org> (raw)
In-Reply-To: <20200116194341.402-4-richard.henderson@linaro.org>
Richard Henderson <richard.henderson@linaro.org> writes:
> Notice the magic page during translate, much like we already
> do for the arm32 commpage. At runtime, raise an exception to
> return cpu_loop for emulation.
>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> target/i386/cpu.h | 1 +
> linux-user/i386/cpu_loop.c | 105 +++++++++++++++++++++++++++++++++++++
> target/i386/translate.c | 16 +++++-
> 3 files changed, 121 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index 164d038d1f..3fb2d2a986 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -1000,6 +1000,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
>
> #define EXCP_VMEXIT 0x100 /* only for system emulation */
> #define EXCP_SYSCALL 0x101 /* only for user emulation */
> +#define EXCP_VSYSCALL 0x102 /* only for user emulation */
>
> /* i386-specific interrupt pending bits. */
> #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1
> diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
> index e217cca5ee..f9bf6cec27 100644
> --- a/linux-user/i386/cpu_loop.c
> +++ b/linux-user/i386/cpu_loop.c
> @@ -92,6 +92,106 @@ static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr)
> queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
> }
>
> +#ifdef TARGET_X86_64
> +static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len)
> +{
> + /*
> + * For all the vsyscalls, NULL means "don't write anything" not
> + * "write it at address 0".
> + */
> + if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) {
> + return true;
> + }
> +
> + env->error_code = PG_ERROR_W_MASK | PG_ERROR_U_MASK;
> + gen_signal(env, TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr);
> + return false;
> +}
> +
> +/*
> + * Since v3.1, the kernel traps and emulates the vsyscall page.
> + * Entry points other than the official generate SIGSEGV.
> + */
> +static void emulate_vsyscall(CPUX86State *env)
> +{
> + int syscall;
> + abi_ulong ret;
> + uint64_t caller;
> +
> + /*
> + * Validate the entry point. We have already validated the page
> + * during translation, now verify the offset.
> + */
> + switch (env->eip & ~TARGET_PAGE_MASK) {
> + case 0x000:
> + syscall = TARGET_NR_gettimeofday;
> + break;
> + case 0x400:
> + syscall = TARGET_NR_time;
> + break;
> + case 0x800:
> + syscall = TARGET_NR_getcpu;
> + break;
> + default:
> + sigsegv:
this label looks a little extraneous.
Otherwise:
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
next prev parent reply other threads:[~2020-01-20 11:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 19:43 [PATCH v2 0/5] linux-user: Implement x86_64 vsyscalls Richard Henderson
2020-01-16 19:43 ` [PATCH v2 1/5] target/i386: Renumber EXCP_SYSCALL Richard Henderson
2020-01-16 19:43 ` [PATCH v2 2/5] linux-user/i386: Split out gen_signal Richard Henderson
2020-01-16 19:43 ` [PATCH v2 3/5] linux-user/i386: Emulate x86_64 vsyscalls Richard Henderson
2020-01-20 11:48 ` Alex Bennée [this message]
2020-01-21 3:38 ` Richard Henderson
2020-01-21 10:13 ` Alex Bennée
2020-01-21 15:51 ` Richard Henderson
2020-01-21 16:15 ` Alex Bennée
2020-01-21 16:23 ` Paolo Bonzini
2020-01-16 19:43 ` [PATCH v2 4/5] linux-user: Add x86_64 vsyscall page to /proc/self/maps Richard Henderson
2020-01-17 6:39 ` Philippe Mathieu-Daudé
2020-01-20 14:41 ` Alex Bennée
2020-01-16 19:43 ` [PATCH v2 5/5] linux-user: Flush out implementation of gettimeofday Richard Henderson
2020-01-17 6:37 ` Philippe Mathieu-Daudé
2020-01-20 13:27 ` Alex Bennée
2020-01-16 19:46 ` [PATCH v2 0/5] linux-user: Implement x86_64 vsyscalls Richard Henderson
2020-01-28 17:26 ` 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=87v9p62vt5.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--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).