Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1100614pxf; Fri, 12 Mar 2021 01:44:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyl7GGqHzHGyKc7/ioVEecrlzhiG/RW+Ywah3xle0eENQCggoW4aaT/OjkyZV2BkqugPOA6 X-Received: by 2002:a05:6402:b48:: with SMTP id bx8mr13596457edb.162.1615542271329; Fri, 12 Mar 2021 01:44:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615542271; cv=none; d=google.com; s=arc-20160816; b=Yhl26Hv1s7rWyu0ERLbFKaoWD03GVuvsfdo5n+5tMr6mC9TbAgyw/8Quj4UgTHw55E c0EXVXBqbR6qv8QXnRnlH9IOTDp6R91GUnH1RDyOCmJqI8W+UELFmLmBORSuCQs957dr R7h6hL9uR0N950YcUjG/W3ZbdYF7IQCwSmAxBhZPSEyQsATHZSauc7qoIkNYM1JFxgGK kX3mHz3K8qeNjjnGQY1w4g5B07xfG4/kM0m6gP3KB1IHtDOy3TdqMwT02ecgZPFYgmPA s65+K6MZsK3IMqah5aZUbDP2uDnlBbnZ3KT7iKQM2gQng6/VczBawp2bZWByBBSJLMZQ 1iaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HridtMMXC8vScc9kZT8PyMJ7G5JC59isSxPDwf/Twi8=; b=rrkdhW9RSQ0HSGMungNlqSwi8DGfruf90ubbujkxqEgW78V8Y8nxgtVZAO5TI8a2Jb dAzIyP5tF0yxOO9AmT5y038l4pvdHFhKTC6VH+aPjMMFAXtOgkxTDzEwDRgxi76CckXy eFAJQrwYOvWuI9bkt5+MSRLS9s5GNIn09eEGENLusStbDFG3VEn3l+e7/nM8CIegICth 9Sj37NkM1TU+jmFU8XUl+hwIGsIcf+E+xDJctsyfFFDOPZ+6l1RyB4USH2dTP04XWRdv BR1/IKeIBng4AML6Vy+sMLWNOCKYvOlDT5NmoORV1t+i1Q5h53GY0RjFhySEkirmzqnD jQfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FttZZGnG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si3703132edw.367.2021.03.12.01.44.08; Fri, 12 Mar 2021 01:44:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FttZZGnG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbhCLJke (ORCPT + 99 others); Fri, 12 Mar 2021 04:40:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:49842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbhCLJkR (ORCPT ); Fri, 12 Mar 2021 04:40:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3961E64FDD; Fri, 12 Mar 2021 09:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615542017; bh=IhMRNUcJYwCkDReHSF76lISid/6+vJxJRq5TrqpWgk8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FttZZGnGm4GqH4u+TmUc57P5wbD6izysvvsuuknHB0t9tFFQ2cQUyxJP/LmMkMDPj pBaaPhflRrPTYmpAiwT0ngHHanDpHmZPoRs7X+JJnQ9lmsdsaUrapQE8/wHB66L3Hu aVesI5HypLmSPbqdaaWqDr25iEvI5DhjopJJ0hEA3yEeNosk9xaawcrEhTcWRKRiSJ byZmtWoB7mUSOf5wgOLjHY3cp9Q9veMVqbG3NIvjswUAA8acTGGr0x/S3V/DniQx4j 0+d4EafNVWpjsvT9E+2S9Uv0D5JTLHwiVdzh+eQOaEL5QjPeEq0Xn9UUd3EPKbRAWz EWOc5VUiGsXxg== Date: Fri, 12 Mar 2021 09:40:09 +0000 From: Will Deacon To: Quentin Perret Cc: catalin.marinas@arm.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, robh+dt@kernel.org, ardb@kernel.org Subject: Re: [PATCH v4 30/34] KVM: arm64: Add kvm_pgtable_stage2_find_range() Message-ID: <20210312094009.GC32016@willie-the-truck> References: <20210310175751.3320106-1-qperret@google.com> <20210310175751.3320106-31-qperret@google.com> <20210311190406.GB31586@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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