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=-15.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 A3040C4320A for ; Tue, 27 Jul 2021 15:24:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2A4DE61B3C for ; Tue, 27 Jul 2021 15:24:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2A4DE61B3C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BA9626B0036; Tue, 27 Jul 2021 11:24:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B59778D0001; Tue, 27 Jul 2021 11:24:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A486B6B006C; Tue, 27 Jul 2021 11:24:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 8B87F6B0036 for ; Tue, 27 Jul 2021 11:24:31 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4A75D8249980 for ; Tue, 27 Jul 2021 15:24:31 +0000 (UTC) X-FDA: 78408739542.08.C4E6DE2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf10.hostedemail.com (Postfix) with ESMTP id A26AB60065D2 for ; Tue, 27 Jul 2021 15:24:30 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8DAF131B; Tue, 27 Jul 2021 08:24:29 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 782673F66F; Tue, 27 Jul 2021 08:24:27 -0700 (PDT) Subject: Re: [PATCH v2 1/6] KVM: arm64: Introduce helper to retrieve a PTE and its level To: Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org Cc: Sean Christopherson , Matthew Wilcox , Paolo Bonzini , Will Deacon , Quentin Perret , James Morse , Suzuki K Poulose , kernel-team@android.com References: <20210726153552.1535838-1-maz@kernel.org> <20210726153552.1535838-2-maz@kernel.org> From: Alexandru Elisei Message-ID: <11d5e176-ac47-e215-b82a-b8f074220bd6@arm.com> Date: Tue, 27 Jul 2021 16:25:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210726153552.1535838-2-maz@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A26AB60065D2 Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf10.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com X-Stat-Signature: jb6h4gd3t1t7skgbs4pefbby5i6pbb3w X-HE-Tag: 1627399470-798720 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. > + * @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. Otherwise, the patch looks good to me: Reviewed-by: Alexandru Elisei Thanks, Alex > + if (!ret) { > + if (ptep) > + *ptep = data.pte; > + if (level) > + *level = data.level; > + } > + > + return ret; > +} > + > struct hyp_map_data { > u64 phys; > kvm_pte_t attr;