qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
	"Kirill Batuzov" <batuzovk@ispras.ru>,
	maria.klimushenkova@ispras.ru,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Денис Дмитриев" <zealot351@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] arm: fix TB alignment check
Date: Sat, 19 Sep 2015 11:00:50 +0100	[thread overview]
Message-ID: <CAFEAcA9fGpsSme4cGe8X-Rd-8kD+QJBYQRDa8NYP6HtODTXMjQ@mail.gmail.com> (raw)
In-Reply-To: <20141021121453.7268.529.stgit@PASHA-ISP>

On 21 October 2014 at 13:14, Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru> wrote:
> Sometimes page faults happen during the translation of the target instructions.
> To avoid the faults in the middle of the TB we have to stop translation at
> the end of the page. Current implementation of ARM translation assumes that
> instructions are aligned to their own size (4 or 2 bytes). But in thumb2 mode
> 4-byte instruction can be aligned to 2 bytes. In some cases such an alignment
> leads to page fault.
> This patch adds check that allows translation of such instructions only in
> the beginning of the TB.
>
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> ---
>  target-arm/translate.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/target-arm/translate.c b/target-arm/translate.c
> index 2c0b1de..bc3a16b 100644
> --- a/target-arm/translate.c
> +++ b/target-arm/translate.c
> @@ -11124,7 +11124,8 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
>               !cs->singlestep_enabled &&
>               !singlestep &&
>               !dc->ss_active &&
> -             dc->pc < next_page_start &&
> +             /* +3 is for unaligned Thumb2 instructions */
> +             dc->pc + 3 < next_page_start &&
>               num_insns < max_insns);
>
>      if (tb->cflags & CF_LAST_IO) {

I finally got round to looking again at this patch from last year, which
I didn't really understand the first time round. Having investigated
more closely, this is a correctness issue (we report the page fault
with the wrong guest PC). Those get my attention much quicker if
clearly described as such :-)

As Laurent suggested, this code will give an awkward stub TB with
a single 16bit Thumb insn in it if the last insn in the page
happens to be a 16 bit Thumb insn. I'll post a patch shortly which
avoids this effect (and which has more commentary on why we need
to do this).

Incidentally, this remark by rth:
> To be honest qemu doesn't attempt to care about that much for targets that have
> insns that span pages.  We've proven[2] that there are no branches or forced
> exceptions that would change control flow earlier, therefore any time execution
> begins at pc_start, it will likely fall through to the next page.

fails to consider the case of non-forced exceptions (like those
on loads or stores). I think every target has to care about this
otherwise for situations like:
 load/store insn that should fault
 other insn that spans page boundary into a non-executable page

we will report the fault for the execution on the non-executable
page, when we should have reported the fault for the load/store
(and we'll get the faulting PC wrong too).

thanks
-- PMM

      parent reply	other threads:[~2015-09-19 10:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21 12:14 [Qemu-devel] [PATCH] arm: fix TB alignment check Pavel Dovgalyuk
2014-10-23 13:18 ` Peter Maydell
2014-10-23 13:42 ` Laurent Desnogues
2014-10-23 16:15 ` Richard Henderson
2014-10-23 16:25   ` Peter Maydell
2014-10-23 16:33     ` Richard Henderson
2014-10-24  5:24   ` Pavel Dovgaluk
2014-10-24 16:08   ` Leon Alrae
2015-09-19 10:00 ` Peter Maydell [this message]

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=CAFEAcA9fGpsSme4cGe8X-Rd-8kD+QJBYQRDa8NYP6HtODTXMjQ@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=Pavel.Dovgaluk@ispras.ru \
    --cc=alex.bennee@linaro.org \
    --cc=batuzovk@ispras.ru \
    --cc=maria.klimushenkova@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=zealot351@gmail.com \
    /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).