From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org,
qemu-arm@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Date: Fri, 22 Jan 2016 13:54:20 +0100 [thread overview]
Message-ID: <20160122125420.GE25287@toto> (raw)
In-Reply-To: <87y4bhhm6i.fsf@linaro.org>
On Fri, Jan 22, 2016 at 11:45:57AM +0000, Alex Bennée wrote:
>
> Edgar E. Iglesias <edgar.iglesias@gmail.com> writes:
>
> > On Fri, Jan 22, 2016 at 10:28:43AM +0000, Alex Bennée wrote:
> >>
> >> Edgar E. Iglesias <edgar.iglesias@gmail.com> writes:
> >>
> >> > From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> >> >
> >> > Implement the inputsize > pamax check for Stage 2 translations.
> >> > We have multiple choices for how to respond to errors and
> >> > choose to fault.
> >> >
> >> > Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> >> > ---
> >> > target-arm/helper.c | 16 ++++++++++++----
> >> > 1 file changed, 12 insertions(+), 4 deletions(-)
> >> >
> >> > diff --git a/target-arm/helper.c b/target-arm/helper.c
> >> > index 4abeb4d..9a7ff5e 100644
> >> > --- a/target-arm/helper.c
> >> > +++ b/target-arm/helper.c
> >> > @@ -6808,7 +6808,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,
> >> > */
> >> > int startlevel = extract32(tcr->raw_tcr, 6, 2);
> >> > unsigned int pamax = arm_pamax(cpu);
> >> > - bool ok;
> >> > + bool ok = true;
> >> >
> >> > if (va_size == 32 || stride == 9) {
> >> > /* AArch32 or 4KB pages */
> >> > @@ -6818,9 +6818,17 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,
> >> > level = 3 - startlevel;
> >> > }
> >> >
> >> > - /* Check that the starting level is valid. */
> >> > - ok = check_s2_startlevel(cpu, va_size == 64, level,
> >> > - inputsize, stride, pamax);
> >> > + if (va_size == 64 &&
> >> > + inputsize > pamax &&
> >> > + (arm_el_is_aa64(env, 1) || inputsize > 40)) {
> >>
> >> If va_size == 64 doesn't that imply arm_el_is_aa64(env, 1)? Looking
> >> further up the function it seems that is what sets va_size in the first
> >> place. I think that makes the inputsize > 40 check redundant.
> >
> > va_size == 64 is true if the EL corresponding to the translation _regime_
> > is in 64 bit mode (in this case EL2).
> >
> > EL1 may very well be in 32bit mode.
>
> Ahh yes, I missed that on the first reading. I think it might be clearer
> when reading the code to have the:
>
> bool is_aarch64_regime = (va_size == 64);
>
> And use that to make it clear. And then comment on later check that it's
> incompatible with EL1 being aarch32.
>
> >
> >>
> >> > + /* We have multiple choices but choose to fault. */
> >> > + ok = false;
> >> > + }
> >> > + if (ok) {
> >> > + /* Check that the starting level is valid. */
> >> > + ok = check_s2_startlevel(cpu, va_size == 64, level,
> >> > + inputsize, stride, pamax);
> >> > + }
> >> > if (!ok) {
> >> > /* AArch64 reports these as level 0 faults.
> >> > * AArch32 reports these as level 1 faults.
> >>
> >> I'm not a fan of the ok = true / ok = false / ok =
> >> check_s2_start_level() / if (!ok) ping-pong here as it is hard to
> >> follow. I'm not sure how you could make it cleaner to follow though.
> >> Maybe something like:
> >>
> >> /* For stage 2 translations the starting level is specified by the
> >> * VTCR_EL2.SL0 field (whose interpretation depends on the page size)
> >> */
> >> int startlevel = extract32(tcr->raw_tcr, 6, 2);
> >> unsigned int pamax = arm_pamax(cpu);
> >> bool is_aarch64_regime = (va_size == 64);
> >> bool ok;
> >>
> >> if (va_size == 32 || stride == 9) {
> >> /* AArch32 or 4KB pages */
> >> level = 2 - startlevel;
> >> } else {
> >> /* 16KB or 64KB pages */
> >> level = 3 - startlevel;
> >> }
> >>
> >> if (is_aarch64_regime &&
> >> inputsize > pamax) {
> >> /* We have multiple choices but choose to fault. */
> >> ok = false;
> >> } else {
> >> /* Check that the starting level is valid. */
> >> ok = check_s2_startlevel(cpu, is_aarch64_regime, level,
> >> inputsize, stride, pamax);
> >> }
> >> if (!ok) {
> >> /* AArch64 reports these as level 0 faults.
> >> * AArch32 reports these as level 1 faults.
> >> */
> >> level = is_aarch64_regime ? 0 : 1;
> >> fault_type = translation_fault;
> >> goto do_fault;
> >> }
> >>
> >> But I'm wondering if it just makes more sense to push the:
> >>
> >> is_aarch64_regime && inputsize > pamax
> >>
> >> Check into check_s2_startlevel? Then you could just have a simple call
> >> which succeeds or falls through to a fault?
> >
> > Yeah, I guess we could rename check_s2_startlevel to something more generic
> > and move all the checks there. I don't feel very strongly about either way...
>
> I think it would be cleaner to follow. get_phys_addr_lpae is already a
> bit of a monster so the less conditions to keep track of while reading
> it the better IMHO.
OK, I'll have a look at that for v4.
Thanks!
Edgar
>
> > Thanks,
> > Edgar
> >
> >
> >
> >>
> >> /* Check that the starting level is valid. */
> >> if (!check_s2_startlevel(cpu, is_aarch64_regime, level,
> >> inputsize, stride, pamax) ){
> >> /* AArch64 reports these as level 0 faults.
> >> * AArch32 reports these as level 1 faults.
> >> */
> >> level = is_aarch64_regime ? 0 : 1;
> >> fault_type = translation_fault;
> >> goto do_fault;
> >> }
> >>
> >> --
> >> Alex Bennée
>
>
> --
> Alex Bennée
prev parent reply other threads:[~2016-01-22 12:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-21 11:18 [Qemu-devel] [PATCH v2 0/3] target-arm: Add a few more S2 MMU input checks Edgar E. Iglesias
2016-01-21 11:18 ` [Qemu-devel] [PATCH v2 1/3] target-arm: Apply S2 MMU startlevel table size check to AArch64 Edgar E. Iglesias
2016-01-21 11:18 ` [Qemu-devel] [PATCH v2 2/3] target-arm: Make pamax an argument to check_s2_startlevel Edgar E. Iglesias
2016-01-21 15:54 ` Alex Bennée
2016-01-21 16:07 ` Edgar E. Iglesias
2016-01-21 11:18 ` [Qemu-devel] [PATCH v2 3/3] target-arm: Implement the S2 MMU inputsize > pamax check Edgar E. Iglesias
2016-01-22 10:28 ` Alex Bennée
2016-01-22 11:16 ` Edgar E. Iglesias
2016-01-22 11:45 ` Alex Bennée
2016-01-22 12:54 ` Edgar E. Iglesias [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=20160122125420.GE25287@toto \
--to=edgar.iglesias@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=edgar.iglesias@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.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).