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=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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=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 85C5BC4338F for ; Tue, 27 Jul 2021 15:26:35 +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 4CBD761B3F for ; Tue, 27 Jul 2021 15:26:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4CBD761B3F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=wWfs4RRuuHoZ+Iy6q6wdQsmoPzSurdgkpSUs/8jM3Pk=; b=mu8vMMFCc+sIjjUXPmzVPGKaA/ CCLO6hJwMZ8BSMoJPO8Y/QhIQBYbERRxnCp56PwMu2CGsnFPm0OUYTzUZAsPY4QUMmZampjNCb65X jNuQea7ouIPSX0JuvX4LoRTkO5lYJJsk4yy2Dxf2G73geG4/mz5LHm0UWJR/jjV7hUaNo4hlGjzMs jc2KJmfr6N5t/BM+UDyhPQgtC64p0l/mC7LjTsB8DNauTkz5a8es3+6MGgfwAzdYqT3SgmtTozLIZ 9oWQ4aJRQ28P6jeh6dHIxola0PbD4grd0IQ0S39tsfwuDZmOsRJbZjhFpdUpL/8vyaFA4CwDzzo0k U3pn1Pvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8Owg-00FCwU-P1; Tue, 27 Jul 2021 15:24:38 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8Owc-00FCuo-Lz for linux-arm-kernel@lists.infradead.org; Tue, 27 Jul 2021 15:24:36 +0000 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-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210727_082434_884020_573C3998 X-CRM114-Status: GOOD ( 24.81 ) 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 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; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel