From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkH2k-0007ex-4I for qemu-devel@nongnu.org; Thu, 08 Oct 2015 15:39:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkH2f-0004Kc-Nb for qemu-devel@nongnu.org; Thu, 08 Oct 2015 15:39:58 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:32934) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkH2f-0004II-BO for qemu-devel@nongnu.org; Thu, 08 Oct 2015 15:39:53 -0400 Received: by pacex6 with SMTP id ex6so63294921pac.0 for ; Thu, 08 Oct 2015 12:39:52 -0700 (PDT) Date: Thu, 8 Oct 2015 12:35:11 -0700 From: "Edgar E. Iglesias" Message-ID: <20151008193511.GJ24839@toto> References: <1443911939-2825-1-git-send-email-edgar.iglesias@gmail.com> <1443911939-2825-3-git-send-email-edgar.iglesias@gmail.com> <87a8ruyih0.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87a8ruyih0.fsf@linaro.org> Subject: Re: [Qemu-devel] [PATCH v3 2/9] target-arm: Add computation of starting level for S2 PTW List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, qemu-devel@nongnu.org, agraf@suse.de, laurent.desnogues@gmail.com, serge.fdrv@gmail.com On Wed, Oct 07, 2015 at 01:24:27PM +0100, Alex Bennée wrote: > > Edgar E. Iglesias writes: > > > From: "Edgar E. Iglesias" > > > > The starting level for S2 pagetable walks is computed > > differently from the S1 starting level. Implement the S2 > > variant. > > > > Signed-off-by: Edgar E. Iglesias > > --- > > target-arm/helper.c | 39 +++++++++++++++++++++++++++------------ > > 1 file changed, 27 insertions(+), 12 deletions(-) > > > > diff --git a/target-arm/helper.c b/target-arm/helper.c > > index 5a5e5f0..507324f 100644 > > --- a/target-arm/helper.c > > +++ b/target-arm/helper.c > > @@ -6549,18 +6549,33 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, > > goto do_fault; > > } > > > > - /* The starting level depends on the virtual address size (which can be > > - * up to 48 bits) and the translation granule size. It indicates the number > > - * of strides (granule_sz bits at a time) needed to consume the bits > > - * of the input address. In the pseudocode this is: > > - * level = 4 - RoundUp((inputsize - grainsize) / stride) > > - * where their 'inputsize' is our 'va_size - tsz', 'grainsize' is > > - * our 'granule_sz + 3' and 'stride' is our 'granule_sz'. > > - * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying: > > - * = 4 - (va_size - tsz - granule_sz - 3 + granule_sz - 1) / granule_sz > > - * = 4 - (va_size - tsz - 4) / granule_sz; > > - */ > > - level = 4 - (va_size - tsz - 4) / granule_sz; > > + if (mmu_idx != ARMMMUIdx_S2NS) { > > + /* The starting level depends on the virtual address size (which can > > + * be up to 48 bits) and the translation granule size. It indicates > > + * the number of strides (granule_sz bits at a time) needed to > > + * consume the bits of the input address. In the pseudocode this is: > > + * level = 4 - RoundUp((inputsize - grainsize) / stride) > > + * where their 'inputsize' is our 'va_size - tsz', 'grainsize' is > > + * our 'granule_sz + 3' and 'stride' is our 'granule_sz'. > > + * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying: > > + * = 4 - (va_size - tsz - granule_sz - 3 + granule_sz - 1) / granule_sz > > + * = 4 - (va_size - tsz - 4) / granule_sz; > > + */ > > + level = 4 - (va_size - tsz - 4) / granule_sz; > > + } else { > > + unsigned int startlevel = extract32(tcr->raw_tcr, 6, 2); > > Maybe an assert(startlevel<3) would be useful? Good catch here. There is actually a trap for some of the bad startlevel cases. I'll implement that for the next version. > > > + > > + /* For stage 2 translations the starting level is specified by the > > + * VCTR_EL2.SL0 field (whose interpretation depends on the page size) > > + */ > > + if (granule_sz == 9) { > > + /* 4K pages */ > > + level = 2 - startlevel; > > + } else { > > + /* 16K or 64K pages */ > > + level = 3 - startlevel; > > + } > > + } > > > > /* Clear the vaddr bits which aren't part of the within-region address, > > * so that we don't have to special case things when calculating the > > Reviewed-by: Alex Bennée Thanks, I'll hold the RB until you see the next version with the traps for bad start-levels. Cheers, Edgar