From patchwork Wed Jan 11 00:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13095778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 24005C54EBC for ; Wed, 11 Jan 2023 00:04:55 +0000 (UTC) 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: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3nvJl4c9A5evk2ZZyIe68MyYvNcE2cnjNVo7PMXqeWk=; b=R0FtvwGJW0JEp2 P1tc8EbFnsiT1M6Jx3ZOwaSt/x0Co2p9aLqqKMHcHCerwgWkxgVpvtgFgOalRWY4dWpUTKCsJBWvn V1+ntk/2UA1slxGCNMxg9Ai3S+fEiutBjESvnJ3le8N61gm7nMzq5aFPALM4kTphu+QnkrpzUtGoG cACEHtQCY2srBjpZS0+EUpzEHRToXeZ4fpTLVTOVmnS6oJYnyS0VFJH/VPb5IsMTclq86GESVBXco qPmqYj5Nhn/wbvLMbZ0jFYVOjY6UL/QL0S2jecbUtIz9TlX+b0ahmfM88V8PmE5U5sXsnsyMWy5IS a9tkhscdLR73kkCW+qrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFOaz-008yCU-0m; Wed, 11 Jan 2023 00:03:57 +0000 Received: from out-19.mta0.migadu.com ([2001:41d0:1004:224b::13]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFOaj-008y7w-05 for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 00:03:42 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1673395417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9DaZ0SEJg/u0gD0sqTLBat7vEekCCjd/sgW7siDQbQc=; b=g/DwgKH8bvg45KPU6YRLGlNUG4UZsdxoNT/dwf28ZG+d3UWG/DlpfhRgo0ONAzBRCdX03F s7ACXEEgRPFxncHXpaNmzVrVTyrzlqLFaasd0vJ9MGAxAYKDNrkLQbq+dM0DOrJgKgwZ4S 1FoFzTi5+7HIsqHTX6RHJTV2DIQKmls= From: Oliver Upton To: Marc Zyngier , James Morse Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Quentin Perret , Will Deacon , Reiji Watanabe , Oliver Upton Subject: [PATCH 3/5] KVM: arm64: Only return attributes from stage2_update_leaf_attrs() Date: Wed, 11 Jan 2023 00:02:58 +0000 Message-Id: <20230111000300.2034799-4-oliver.upton@linux.dev> In-Reply-To: <20230111000300.2034799-1-oliver.upton@linux.dev> References: <20230111000300.2034799-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_160341_231024_6DD0FF67 X-CRM114-Status: GOOD ( 15.75 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Returning a single PTE from stage2_update_leaf_attrs() doesn't make a great deal of sense given that the function could be used to apply a change to a range of PTEs. Instead, return a bitwise OR of attributes from all the visited PTEs. As the walker is no longer returning the full PTE, drop the check for a valid PTE in kvm_age_gfn(). Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 32 +++++++++++++++++--------------- arch/arm64/kvm/mmu.c | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 26f61462527d..a3d599e3af60 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -980,7 +980,7 @@ int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size) struct stage2_attr_data { kvm_pte_t attr_set; kvm_pte_t attr_clr; - kvm_pte_t pte; + kvm_pte_t attr_old; u32 level; }; @@ -995,7 +995,7 @@ static int stage2_attr_walker(const struct kvm_pgtable_visit_ctx *ctx, return 0; data->level = ctx->level; - data->pte = pte; + data->attr_old |= pte & KVM_PTE_LEAF_ATTRS; pte &= ~data->attr_clr; pte |= data->attr_set; @@ -1004,7 +1004,7 @@ static int stage2_attr_walker(const struct kvm_pgtable_visit_ctx *ctx, * but worst-case the access flag update gets lost and will be * set on the next access instead. */ - if (data->pte != pte) { + if (ctx->old != pte) { /* * Invalidate instruction cache before updating the guest * stage-2 PTE if we are going to add executable permission. @@ -1023,7 +1023,7 @@ static int stage2_attr_walker(const struct kvm_pgtable_visit_ctx *ctx, static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr, u64 size, kvm_pte_t attr_set, - kvm_pte_t attr_clr, kvm_pte_t *orig_pte, + kvm_pte_t attr_clr, kvm_pte_t *attr_old, u32 *level, enum kvm_pgtable_walk_flags flags) { int ret; @@ -1041,11 +1041,12 @@ static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr, if (ret) return ret; - if (orig_pte) - *orig_pte = data.pte; + if (attr_old) + *attr_old = data.attr_old; if (level) *level = data.level; + return 0; } @@ -1058,32 +1059,33 @@ int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size) kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) { - kvm_pte_t pte = 0; + kvm_pte_t attr_old = 0; + stage2_update_leaf_attrs(pgt, addr, 1, KVM_PTE_LEAF_ATTR_LO_S2_AF, 0, - &pte, NULL, 0); + &attr_old, NULL, 0); dsb(ishst); - return pte; + return attr_old; } kvm_pte_t kvm_pgtable_stage2_mkold(struct kvm_pgtable *pgt, u64 addr) { - kvm_pte_t pte = 0; + kvm_pte_t attr_old = 0; stage2_update_leaf_attrs(pgt, addr, 1, 0, KVM_PTE_LEAF_ATTR_LO_S2_AF, - &pte, NULL, 0); + &attr_old, NULL, 0); /* * "But where's the TLBI?!", you scream. * "Over in the core code", I sigh. * * See the '->clear_flush_young()' callback on the KVM mmu notifier. */ - return pte; + return attr_old; } bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr) { - kvm_pte_t pte = 0; - stage2_update_leaf_attrs(pgt, addr, 1, 0, 0, &pte, NULL, 0); - return pte & KVM_PTE_LEAF_ATTR_LO_S2_AF; + kvm_pte_t attr_old = 0; + stage2_update_leaf_attrs(pgt, addr, 1, 0, 0, &attr_old, NULL, 0); + return attr_old & KVM_PTE_LEAF_ATTR_LO_S2_AF; } int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr, diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 31d7fa4c7c14..0741f3a8ddca 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1618,7 +1618,7 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt, range->start << PAGE_SHIFT); pte = __pte(kpte); - return pte_valid(pte) && pte_young(pte); + return pte_young(pte); } bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)