lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210312094009.GC32016@willie-the-truck>
Date:   Fri, 12 Mar 2021 09:40:09 +0000
From:   Will Deacon <will@...nel.org>
To:     Quentin Perret <qperret@...gle.com>
Cc:     catalin.marinas@....com, maz@...nel.org, james.morse@....com,
        julien.thierry.kdev@...il.com, suzuki.poulose@....com,
        android-kvm@...gle.com, linux-kernel@...r.kernel.org,
        kernel-team@...roid.com, kvmarm@...ts.cs.columbia.edu,
        linux-arm-kernel@...ts.infradead.org, tabba@...gle.com,
        mark.rutland@....com, dbrazdil@...gle.com, mate.toth-pal@....com,
        seanjc@...gle.com, robh+dt@...nel.org, ardb@...nel.org
Subject: Re: [PATCH v4 30/34] KVM: arm64: Add kvm_pgtable_stage2_find_range()

On Fri, Mar 12, 2021 at 05:32:13AM +0000, Quentin Perret wrote:
> On Thursday 11 Mar 2021 at 19:04:07 (+0000), Will Deacon wrote:
> > On Wed, Mar 10, 2021 at 05:57:47PM +0000, Quentin Perret wrote:
> > > +	for (level = pgt->start_level; level < KVM_PGTABLE_MAX_LEVELS; level++) {
> > > +		granule = kvm_granule_size(level);
> > > +		start = ALIGN_DOWN(addr, granule);
> > > +		end = start + granule;
> > > +
> > > +		if (!kvm_level_support_block_mappings(level))
> > > +			continue;
> > > +
> > > +		if (start < range->start || range->end < end)
> > > +			continue;
> > > +
> > > +		/*
> > > +		 * Check the presence of existing mappings with incompatible
> > > +		 * permissions within the current block range, and try one level
> > > +		 * deeper if one is found.
> > > +		 */
> > > +		ret = kvm_pgtable_walk(pgt, start, granule, &check_perm_walker);
> > > +		if (ret != -EEXIST)
> > > +			break;
> > > +	}
> > 
> > Can you write this as a:
> > 
> > 	do {
> > 		...
> > 	} while (level < KVM_PGTABLE_MAX_LEVELS && ret == -EEXIST);
> > 
> > loop?
> 
> I tried it but found it a little less pretty -- the pre-assignment of
> level and the increment at the end make it really feel like a for loop
> to me:
> 
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -1098,26 +1098,23 @@ int kvm_pgtable_stage2_find_range(struct kvm_pgtable *pgt, u64 addr,
>                 return ret;
>         attr &= KVM_PTE_LEAF_S2_COMPAT_MASK;
>  
> -       for (level = pgt->start_level; level < KVM_PGTABLE_MAX_LEVELS; level++) {
> +       ret = -EEXIST;
> +       level = pgt->start_level;
> +       do {
>                 granule = kvm_granule_size(level);
>                 start = ALIGN_DOWN(addr, granule);
>                 end = start + granule;
>  
> -               if (!kvm_level_support_block_mappings(level))
> -                       continue;
> -
> -               if (start < range->start || range->end < end)
> -                       continue;

Urgh, yes, sorry, I hadn't appreciated what a mess it causes for these guys.

Stick with the 'for' loop.

Will

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ