From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B62C7C4338F for ; Wed, 28 Jul 2021 12:19:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7529C60F46 for ; Wed, 28 Jul 2021 12:19:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7529C60F46 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rfNFhPq1lzyg4V0dwHc4FmgAwcLNjc/rfjff/3tUpEw=; b=cyf0p3+r0kz0Fr LKSZilVhIZPG4yBmxRTbOwXUuJOpO6oE1lZhhJi5f8osKTDvHfXzpbYqkVL88+dw+QGaqriinofJ3 1pM5c+mkevDf9fp8x2KwA81c6EtcwJ1rPvUxxp7CqXaKLvPfC/asI8xXJkfiBq+OovuBiz2LdYXRb RCuy5N0j9nBQJ3t76oFvKvTj3eVOxIQx4BijH+HQvxgA/LR/LyX9NzRBiQoLIcqRc5qtxstDv3Avt WHacueSRmnvJjxS0vx5dunteua6Ntr+y4uLn5b/ngYKNK42IGJpBA+erJc0NsP4dUwWqtZcLTE5mf Ncx74w8eIBriXZP5Jrww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8iUp-000bqc-NS; Wed, 28 Jul 2021 12:17:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8iUm-000bpw-76 for linux-arm-kernel@lists.infradead.org; Wed, 28 Jul 2021 12:17:09 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E5AE560F46; Wed, 28 Jul 2021 12:17:07 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m8iUj-001Wc7-UM; Wed, 28 Jul 2021 13:17:06 +0100 Date: Wed, 28 Jul 2021 13:17:05 +0100 Message-ID: <87sfzyd45a.wl-maz@kernel.org> From: Marc Zyngier To: Alexandru Elisei Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org, Sean Christopherson , Matthew Wilcox , Paolo Bonzini , Will Deacon , Quentin Perret , James Morse , Suzuki K Poulose , kernel-team@android.com Subject: Re: [PATCH v2 1/6] KVM: arm64: Introduce helper to retrieve a PTE and its level In-Reply-To: <11d5e176-ac47-e215-b82a-b8f074220bd6@arm.com> References: <20210726153552.1535838-1-maz@kernel.org> <20210726153552.1535838-2-maz@kernel.org> <11d5e176-ac47-e215-b82a-b8f074220bd6@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org, seanjc@google.com, willy@infradead.org, pbonzini@redhat.com, will@kernel.org, qperret@google.com, james.morse@arm.com, suzuki.poulose@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210728_051708_337198_DABF391E X-CRM114-Status: GOOD ( 30.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Alex, On Tue, 27 Jul 2021 16:25:34 +0100, Alexandru Elisei wrote: > > Hi Marc, > > On 7/26/21 4:35 PM, Marc Zyngier wrote: > > It is becoming a common need to fetch the PTE for a given address > > together with its level. Add such a helper. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 19 ++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 39 ++++++++++++++++++++++++++++ > > 2 files changed, 58 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index f004c0115d89..082b9d65f40b 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -432,6 +432,25 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size); > > int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, > > struct kvm_pgtable_walker *walker); > > > > +/** > > + * kvm_pgtable_get_leaf() - Walk a page-table and retrieve the leaf entry > > + * with its level. > > + * @pgt: Page-table structure initialised by kvm_pgtable_*_init(). > > Yet in the next patch you use a struct kvm_pgtable_pgt not > initialized by any of the kvm_pgtable_*_init() functions. It doesn't > hurt correctness, but it might confuse potential users of this > function. Fair enough. I'll add something like "[...] or any similar initialisation". > > > + * @addr: Input address for the start of the walk. > > + * @ptep: Pointer to storage for the retrieved PTE. > > + * @level: Pointer to storage for the level of the retrieved PTE. > > + * > > + * The offset of @addr within a page is ignored. > > + * > > + * The walker will walk the page-table entries corresponding to the input > > + * address specified, retrieving the leaf corresponding to this address. > > + * Invalid entries are treated as leaf entries. > > + * > > + * Return: 0 on success, negative error code on failure. > > + */ > > +int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr, > > + kvm_pte_t *ptep, u32 *level); > > + > > /** > > * kvm_pgtable_stage2_find_range() - Find a range of Intermediate Physical > > * Addresses with compatible permission > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index 05321f4165e3..78f36bd5df6c 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -326,6 +326,45 @@ int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, > > return _kvm_pgtable_walk(&walk_data); > > } > > > > +struct leaf_walk_data { > > + kvm_pte_t pte; > > + u32 level; > > +}; > > + > > +static int leaf_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, > > + enum kvm_pgtable_walk_flags flag, void * const arg) > > +{ > > + struct leaf_walk_data *data = arg; > > + > > + data->pte = *ptep; > > + data->level = level; > > + > > + return 0; > > +} > > + > > +int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr, > > + kvm_pte_t *ptep, u32 *level) > > +{ > > + struct leaf_walk_data data; > > + struct kvm_pgtable_walker walker = { > > + .cb = leaf_walker, > > + .flags = KVM_PGTABLE_WALK_LEAF, > > + .arg = &data, > > + }; > > + int ret; > > + > > + ret = kvm_pgtable_walk(pgt, ALIGN_DOWN(addr, PAGE_SIZE), > > + PAGE_SIZE, &walker); > > kvm_pgtable_walk() already aligns addr down to PAGE_SIZE, I don't > think that's needed here. But not harmful either. It is more that if you don't align it down, the size becomes awkward to express. Masking is both cheap and readable. > > Otherwise, the patch looks good to me: > > Reviewed-by: Alexandru Elisei Thanks! M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel