From: Sergey Fedorov <serge.fdrv@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Riku Voipio <riku.voipio@iki.fi>,
Richard Henderson <rth@twiddle.net>,
Eduardo Habkost <ehabkost@redhat.com>,
patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH 1/5] translate-all.c: Don't pass puc, locked to tb_invalidate_phys_page()
Date: Mon, 16 May 2016 20:13:41 +0300 [thread overview]
Message-ID: <5739FFC5.9010706@gmail.com> (raw)
In-Reply-To: <1463414992-8357-2-git-send-email-peter.maydell@linaro.org>
On 16/05/16 19:09, Peter Maydell wrote:
> The user-mode-only function tb_invalidate_phys_page() is only
> called from two places:
> * page_unprotect(), which passes in a non-zero pc, a puc pointer
> and the value 'true' for the locked argument
> * page_set_flags(), which passes in a zero pc, a NULL puc pointer
> and a 'false' locked argument
>
> If the pc is non-zero then we may call cpu_resume_from_signal(),
> which does a longjmp out of the calling code (and out of the
> signal handler); this is to cover the case of a target CPU with
> "precise self-modifying code" (currently only x86) executing
> a store instruction which modifies code in the same TB as the
> store itself. Rather than doing the longjump directly here,
> return a flag to the caller which indicates whether the current
> TB was modified, and move the longjump to page_unprotect.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> translate-all.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/translate-all.c b/translate-all.c
> index b54f472..4820d2e 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -1438,10 +1438,13 @@ void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
> }
> }
> #else
> -/* Called with mmap_lock held. */
> -static void tb_invalidate_phys_page(tb_page_addr_t addr,
> - uintptr_t pc, void *puc,
> - bool locked)
> +/* Called with mmap_lock held. If pc is not 0 then it indicates the
> + * host PC of the faulting store instruction that caused this invalidate.
> + * Returns true if the caller needs to abort execution of the current
> + * TB (because it was modified by this store and the guest CPU has
> + * precise-SMC semantics).
> + */
> +static bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)
> {
> TranslationBlock *tb;
> PageDesc *p;
> @@ -1459,7 +1462,7 @@ static void tb_invalidate_phys_page(tb_page_addr_t addr,
> addr &= TARGET_PAGE_MASK;
> p = page_find(addr >> TARGET_PAGE_BITS);
> if (!p) {
> - return;
> + return false;
> }
> tb = p->first_tb;
> #ifdef TARGET_HAS_PRECISE_SMC
> @@ -1498,12 +1501,10 @@ static void tb_invalidate_phys_page(tb_page_addr_t addr,
> modifying the memory. It will ensure that it cannot modify
> itself */
> tb_gen_code(cpu, current_pc, current_cs_base, current_flags, 1);
> - if (locked) {
> - mmap_unlock();
> - }
> - cpu_resume_from_signal(cpu, puc);
> + return true;
> }
> #endif
> + return false;
> }
> #endif
>
> @@ -1902,7 +1903,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)
> if (!(p->flags & PAGE_WRITE) &&
> (flags & PAGE_WRITE) &&
> p->first_tb) {
> - tb_invalidate_phys_page(addr, 0, NULL, false);
> + tb_invalidate_phys_page(addr, 0);
> }
> p->flags = flags;
> }
> @@ -1996,7 +1997,10 @@ int page_unprotect(target_ulong address, uintptr_t pc, void *puc)
>
> /* and since the content will be modified, we must invalidate
> the corresponding translated code. */
> - tb_invalidate_phys_page(addr, pc, puc, true);
> + if (tb_invalidate_phys_page(addr, pc)) {
> + mmap_unlock();
> + cpu_resume_from_signal(current_cpu, puc);
> + }
> #ifdef DEBUG_TB_CHECK
> tb_invalidate_check(addr);
> #endif
Just my 2 cents: we could allow that cpu_resume_from_signal() call and
add mmap_lock_reset() similar to tb_lock_reset() to handle resetting
mmap_lock after a long jump.
Kind regards,
Sergey
next prev parent reply other threads:[~2016-05-16 17:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-16 16:09 [Qemu-devel] [PATCH 0/5] user-exec: cpu_resume_from_signal() cleanups Peter Maydell
2016-05-16 16:09 ` [Qemu-devel] [PATCH 1/5] translate-all.c: Don't pass puc, locked to tb_invalidate_phys_page() Peter Maydell
2016-05-16 17:13 ` Sergey Fedorov [this message]
2016-05-16 17:15 ` Peter Maydell
2016-05-16 17:24 ` Sergey Fedorov
2016-05-16 16:09 ` [Qemu-devel] [PATCH 2/5] user-exec: Push resume-from-signal code out to handle_cpu_signal() Peter Maydell
2016-05-16 17:57 ` Sergey Fedorov
2016-05-16 16:09 ` [Qemu-devel] [PATCH 3/5] cpu-exec: Rename cpu_resume_from_signal() to cpu_loop_exit_noexc() Peter Maydell
2016-05-16 17:58 ` Sergey Fedorov
2016-05-16 16:09 ` [Qemu-devel] [PATCH 4/5] user-exec: Don't reextract sigmask from usercontext pointer Peter Maydell
2016-05-16 18:00 ` Sergey Fedorov
2016-05-16 16:09 ` [Qemu-devel] [PATCH 5/5] target-i386: Move user-mode exception actions out of user-exec.c Peter Maydell
2016-05-16 17:54 ` Sergey Fedorov
2016-05-16 18:33 ` Peter Maydell
2016-05-16 20:24 ` Peter Maydell
2016-05-17 13:47 ` Peter Maydell
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=5739FFC5.9010706@gmail.com \
--to=serge.fdrv@gmail.com \
--cc=ehabkost@redhat.com \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
--cc=rth@twiddle.net \
/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 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.