From patchwork Tue Aug 30 19:41:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12959800 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 61A74C0502A for ; Tue, 30 Aug 2022 19:45:23 +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=CQdOmFN7cS+06YmOoj4StcV/h5BlG2dHm5LcPyJ2mnk=; b=1S1Rmj1rOgRGvs MZfkscaSz4avxyvily3ZMF7fp5MYd4by9LNd0lNKqGsRRlFgrhBFXyYmcTBsgTpvQ8lIgE9FlUiVf EjKSV/OSQlIbh/qGWN4/Xwgb6BJm2h3lUsNLAibeERn0Ddz04dfMeAjdTyS+sW4SipbkaMkxNq2c8 Zw/LSp/m66j1rpIlPbXbkcDF2VP6UtKMSKm6k2kFVAneTmwnhxn44TbT/f8lv7aU27PWlTQHn6y5e Lf0wwuhuW82siS8pN+IbBr4gsqWBrsM5dnS/XSzVdVvbzjiCKdgWFvgkZcR3QaLp9FUCdyrriLGsI ykdJCloEQ+LH9KsEkxzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oT79e-001Vy1-4j; Tue, 30 Aug 2022 19:44:10 +0000 Received: from out1.migadu.com ([91.121.223.63]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oT77n-001VA0-BR for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 19:42:16 +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=1661888534; 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=yispcYoWHwz6WUZiyFc9UJ/2hA2X4vwfQ9rtB9AplkE=; b=QKKwh0mZHI3VDDYssNZqIJUh8qzZEqcGK2T3WlXJOjZzzlmkUOBcLFJw1Cstm2IhK1GFIz 0JosO5MJyt2ok6BmAv66t0Zcb9QGbJ1ROXv1n/pZjIFhAB7qdZSTbe5HfblFcESL/uykDN qbUixnxPOgyPrKiBk/pc54SO8HjqpOI= From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Quentin Perret , Ricardo Koller , Reiji Watanabe , David Matlack , Ben Gardon , Paolo Bonzini , Gavin Shan , Peter Xu , Sean Christopherson , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/14] KVM: arm64: Return next table from map callbacks Date: Tue, 30 Aug 2022 19:41:24 +0000 Message-Id: <20220830194132.962932-7-oliver.upton@linux.dev> In-Reply-To: <20220830194132.962932-1-oliver.upton@linux.dev> References: <20220830194132.962932-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220830_124215_590306_A59A855A X-CRM114-Status: UNSURE ( 9.45 ) X-CRM114-Notice: Please train this message. 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 The map walkers install new page tables during their traversal. Return the newly-installed table PTE from the map callbacks to point the walker at the new table w/o rereading the ptep. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 331f6e3b2c20..f911509e6512 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -202,13 +202,12 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, if (!table && (flags & KVM_PGTABLE_WALK_LEAF)) { ret = kvm_pgtable_visitor_cb(data, addr, level, ptep, &pte, KVM_PGTABLE_WALK_LEAF); - pte = *ptep; - table = kvm_pte_table(pte, level); } if (ret) goto out; + table = kvm_pte_table(pte, level); if (!table) { data->addr = ALIGN_DOWN(data->addr, kvm_granule_size(level)); data->addr += kvm_granule_size(level); @@ -427,6 +426,7 @@ static int hyp_map_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, kvm_pte new = kvm_init_table_pte(childp, mm_ops); mm_ops->get_page(ptep); smp_store_release(ptep, new); + *old = new; return 0; } @@ -768,7 +768,7 @@ static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level, } static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, - struct stage2_map_data *data); + kvm_pte_t *old, struct stage2_map_data *data); static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, kvm_pte_t *old, @@ -791,7 +791,7 @@ static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level, */ kvm_call_hyp(__kvm_tlb_flush_vmid, data->mmu); - ret = stage2_map_walk_leaf(addr, end, level, ptep, data); + ret = stage2_map_walk_leaf(addr, end, level, ptep, old, data); mm_ops->put_page(ptep); mm_ops->free_removed_table(childp, level + 1, pgt); @@ -832,6 +832,7 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, new = kvm_init_table_pte(childp, mm_ops); mm_ops->get_page(ptep); smp_store_release(ptep, new); + *old = new; return 0; }