From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Richard Henderson <rth@twiddle.net>,
QEMU Developers <qemu-devel@nongnu.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Christian Borntraeger <borntraeger@de.ibm.com>
Subject: Re: [Qemu-devel] TCG problem with cpu_{st,ld}x_data ?
Date: Tue, 26 Jul 2016 08:42:47 +1000 [thread overview]
Message-ID: <1469486567.5978.67.camel@kernel.crashing.org> (raw)
In-Reply-To: <CAFEAcA-AX99fzPVaikX1sXLp-hmZrqY8gpHkuC9H3S2AQ9LXNg@mail.gmail.com>
On Mon, 2016-07-25 at 23:19 +0100, Peter Maydell wrote:
> > For example we have one in powerpc_excp() to read the faulting
> > instruction, though that *should* never fail it's till not great.
>
> Mmm. Strictly speaking you can't guarantee that that load will
> work, because the code you're executing could be still cached
> in the QEMU TLB while the (perverse) guest rewrites the page table
> so the ldl_code won't work.
Right, it worries me, it's unlikely but possible.
> You might like to take a look at how target-arm handles the
> similar case (wanting to know information about source register
> numbers etc for some memory faults). We use a TCG instruction
> parameter to save the information as we translate the code
> in target-arm/translate-a64.c, then in restore_state_to_opc()
> (called after the fault) we can fish it out and put it in the
> CPU state struct the same way we regain the faulting PC. Then
> in the exception handler it's available for use. Commit aaa1f954d4
> is the meat of it.
We do something a bit different on ppc where we store the access type
before every access, however the DSISR case is special in that on older
CPUs, it's expected to contains a whole subset of the opcode which is
quite a bit more info than what you want here...
I'm thinking maybe we should use a form of load that returns an error
instead of longjmp'ing, and if we do error out, flush the tb for that
instruction and replay which should cause the translate path to reload
the TLB for it but it's still fishy.
> Alternatively if you just want to do "a load at virtual address
> but don't longjump anywhere" you probably need to:
> * do the virt-to-phys translation manually (ie by calling
> some ppc specific function), so you can capture success/failure
> of the MMU access checks (and without setting guest visible
> MMU fault status info)
> * use address_space_ldl() on the result, so you can pass in
> a MemTxResult* to capture success/failure of the phys access
Yup.
> That's pretty clunky. I meant at some point to look at
> whether we could provide versions of the cpu_ldl* type
> functions that allowed a MemTxResult*, but never got to it.
>
> > I haven't completely figured out what code path instruction
> translation faults take, I assume we longjmp out of the translation
> loop the same
> > was as we do out of the execution loop ?
>
> I suggest you step through it in a debugger if you fancy a laugh.
> As I recall it works more by luck than judgement and includes
> rather more repeated work than is actually necessary. (That
> is, we do longjump out, but not necessarily to the most
> sensible point.)
Haha, I was starting to guess that :-) But that isn't a battle I want
to fight today, enough on my plate already !
Cheers,
Ben.
next prev parent reply other threads:[~2016-07-25 23:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-24 12:42 [Qemu-devel] TCG problem with cpu_{st,ld}x_data ? Benjamin Herrenschmidt
2016-07-24 12:51 ` Benjamin Herrenschmidt
2016-07-24 12:52 ` Benjamin Herrenschmidt
2016-07-25 0:36 ` Richard Henderson
2016-07-25 0:46 ` Benjamin Herrenschmidt
2016-07-25 0:51 ` Benjamin Herrenschmidt
2016-07-25 14:00 ` Richard Henderson
2016-07-25 21:42 ` Benjamin Herrenschmidt
2016-07-25 22:19 ` Peter Maydell
2016-07-25 22:42 ` Benjamin Herrenschmidt [this message]
2016-07-25 23:22 ` Benjamin Herrenschmidt
2016-07-25 0:34 ` Richard Henderson
2016-07-25 5:15 ` Benjamin Herrenschmidt
2016-07-25 14:12 ` Richard Henderson
2016-07-25 21:46 ` Benjamin Herrenschmidt
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=1469486567.5978.67.camel@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=borntraeger@de.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.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).