From patchwork Wed Jan 11 00:03:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13095780 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 F1911C54EBC for ; Wed, 11 Jan 2023 00:05:03 +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=nVXG5TZCbXbx5I8Lc0nojTHIZGEMzkbUASXaNBuJ8+g=; b=vN0cRsbHNOfDym BPPe9pEdsYM7U1Bqes3CNJkhHVkDK9f2yZSl4jPxrKWcmFk9twljewiNT6MHZ2LFo5X1v4hYbUOZY g4hahL1nIeN20PpVdeIQOQr1jUfvvrl7ACCTuXRwyK9Unwf6XZCXmNEGObCcnD5h5ATRFdS+LvR9r N+bKu4MHo1zwEGH/Y4tQOBtRRvGr5xRh2eV+jWPi05VPMH9H67z6Z2BjVQLmxQSx5ym4w8aqm51o2 soseFIoTthdjruEYAvth6pF/PA+HX1oucALyk42YgrCvTXDO9+l5cGAq9Nt7hophKhdHyRI7wURPr yLpoJbnwzltcqwC0aXdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFObG-008yJo-94; Wed, 11 Jan 2023 00:04:14 +0000 Received: from out-144.mta0.migadu.com ([2001:41d0:1004:224b::90]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFOan-008y9U-22 for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 00:03:46 +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=1673395421; 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=U9eN0QijdqjixC9XiiLLRZwsrIMqmoYrpNGMUYRYtVg=; b=LJOWuMn19pWEgAL4w4hEMCcg67W9vohKbKmHWboakIgUdjI5y+jCNDZhBxkqeDDnG0GU8j 8wAvDtZQsI3oJQRFph8I5DyQX95ZeL5kXX9WZgqwUJiU794zk1DVkslNfNIapFkM3F0Ri9 PxSPCh3prO2G9VIktqYxBoLFk9+qwFk= 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 5/5] KVM: arm64: Consistently use KVM's types/helpers in kvm_age_gfn() Date: Wed, 11 Jan 2023 00:03:00 +0000 Message-Id: <20230111000300.2034799-6-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_160345_257547_D2F7B906 X-CRM114-Status: GOOD ( 11.44 ) 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 There's no real need for indirection through the kernel's PTE types here. Add a new helper to test if the access flag is set on a PTE and use it to roll over kvm_age_gfn() to only using kvm_pte_t. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 5 +++++ arch/arm64/kvm/hyp/pgtable.c | 2 +- arch/arm64/kvm/mmu.c | 12 +++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 81e04a24cc76..a81cd1ea64cb 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -86,6 +86,11 @@ static inline bool kvm_pte_valid(kvm_pte_t pte) return pte & KVM_PTE_VALID; } +static inline bool kvm_pte_young(kvm_pte_t pte) +{ + return pte & KVM_PTE_LEAF_ATTR_LO_S2_AF; +} + static inline u64 kvm_pte_to_phys(kvm_pte_t pte) { u64 pa = pte & KVM_PTE_ADDR_MASK; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 791f7e81671e..19f5094dfd93 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1085,7 +1085,7 @@ bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr, u64 size) { kvm_pte_t attr_old = 0; stage2_update_leaf_attrs(pgt, addr, size, 0, 0, &attr_old, NULL, 0); - return attr_old & KVM_PTE_LEAF_ATTR_LO_S2_AF; + return kvm_pte_young(attr_old); } 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 0b8e2a57f81a..3297475dcfcc 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1607,17 +1607,15 @@ bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range) bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) { u64 size = (range->end - range->start) << PAGE_SHIFT; - kvm_pte_t kpte; - pte_t pte; + kvm_pte_t pte; if (!kvm->arch.mmu.pgt) return false; - kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt, - range->start << PAGE_SHIFT, - size); - pte = __pte(kpte); - return pte_young(pte); + pte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt, + range->start << PAGE_SHIFT, + size); + return kvm_pte_young(pte); } bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)