qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	qemu-arm <qemu-arm@nongnu.org>,
	Richard Henderson <rth@twiddle.net>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Peter Crosthwaite <crosthwaite.peter@gmail.com>
Subject: Re: [Qemu-devel] [PATCH] accel/tcg/translate-all: expand cpu_restore_state retaddr check
Date: Tue, 07 Nov 2017 18:45:10 +0000	[thread overview]
Message-ID: <87r2taq66h.fsf@linaro.org> (raw)
In-Reply-To: <CAFEAcA-E4Tq0gi3q5z+_5JOy0-j0=59p5WiKNFP9qmKG8=r4bg@mail.gmail.com>


Peter Maydell <peter.maydell@linaro.org> writes:

> On 7 November 2017 at 16:52, Alex Bennée <alex.bennee@linaro.org> wrote:
>> We are still seeing signals during translation time when we walk over
>> a page protection boundary. This expands the check to ensure the
>> retaddr is inside the code generation buffer. The original suggestion
>> was to check versus tcg_ctx.code_gen_ptr but as we now segment the
>> translation buffer we have to settle for just a general check for
>> being inside.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reported-by: Peter Maydell <peter.maydell@linaro.org>
>> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Richard Henderson <rth@twiddle.net>
>> ---
>>  accel/tcg/translate-all.c | 20 ++++++++++++--------
>>  1 file changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
>> index 34c5e28d07..eb255af402 100644
>> --- a/accel/tcg/translate-all.c
>> +++ b/accel/tcg/translate-all.c
>> @@ -357,16 +357,20 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)
>>      TranslationBlock *tb;
>>      bool r = false;
>>
>> -    /* A retaddr of zero is invalid so we really shouldn't have ended
>> -     * up here. The target code has likely forgotten to check retaddr
>> -     * != 0 before attempting to restore state. We return early to
>> -     * avoid blowing up on a recursive tb_lock(). The target must have
>> -     * previously survived a failed cpu_restore_state because
>> -     * tb_find_pc(0) would have failed anyway. It still should be
>> -     * fixed though.
>> +    /* The retaddr has to be in the region of current code buffer. If
>> +     * it's not we will not be able to resolve it here. If it is zero
>> +     * the calling code has likely forgotten to check retaddr before
>> +     * calling here.
>
> This part of the comment isn't correct -- it's entirely expected
> that we will get here with a zero retaddr, because that is
> how the rest of the code tells this function "no state restoration
> required".

Then why call cpu_restore_state at all? We should be consistent as there
are plenty of places that do things like:

    if (pc) {
        /* now we have a real cpu fault */
        cpu_restore_state(cs, pc);
    }

I'm happy to make a 0 retaddr officially valid and actually document it
in exec-all.h. It's not like most callers even bother checking the
return code.

>
>> If it is not in the translated code we could be
>> +     * faulting during translation itself.
>> +     *
>> +     * Either way we need return early to avoid blowing up on a
>> +     * recursive tb_lock() as we can't resolve it here.
>>       */
>>
>> -    if (!retaddr) {
>> +    if (!retaddr ||
>> +        (retaddr < (uintptr_t) tcg_init_ctx.code_gen_buffer) ||
>> +        (retaddr > (uintptr_t) (tcg_init_ctx.code_gen_buffer +
>> +                                tcg_init_ctx.code_gen_buffer_size))) {
>>          return r;
>>      }
>
> thanks
> -- PMM


--
Alex Bennée

  reply	other threads:[~2017-11-07 18:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07 16:52 [Qemu-devel] [PATCH] accel/tcg/translate-all: expand cpu_restore_state retaddr check Alex Bennée
2017-11-07 17:04 ` Peter Maydell
2017-11-07 18:45   ` Alex Bennée [this message]
2017-11-07 18:53     ` Peter Maydell
2017-11-08  8:52       ` Richard Henderson

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=87r2taq66h.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=crosthwaite.peter@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --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 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).