From patchwork Tue Aug 30 19:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12959802 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 A4A55ECAAD5 for ; Tue, 30 Aug 2022 19:45:59 +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=dFjyZJInw0cG9CvZwZI0uND3VPdWgnWsU2goHUQOZV8=; b=xckMUvRpmfsEiw 1GdEIbjCdOVIfMfmdCUosq8blpEolQ3R7Sqkixxp2uWKyenE0coa863g188L+09uFP/eeG3uaEVDs mLrSCp7FA/1GIZVmwUw2Eki/vKFN69wglaOmhzCwn+oK4M9zJHDXJ6/cvdREyZBxkqqeHjCa2M64u UguOVY6zffey7ImplyV7XJ3hPsXbl0gQ4yuTsyAPwEdOZLneOYzhxnXOIPovISW81wOO6pfGrm8/7 Ergr2jpB9W/Tuw424QhKALrOe2YTnL6RzgOAxMO/cdJqneAI9YS8JXWjfv5kYP7icT7T+hKT0exOs s0g65JL2Puy/CA3nnwQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oT7AK-001WHB-Q4; Tue, 30 Aug 2022 19:44:53 +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 1oT77v-001VCV-Cl for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 19:42:25 +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=1661888542; 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=PAa+cBkl9mtwNYK8/w+PcWpN4aBBuzKZQpA5735hA3U=; b=ZLs5MEMDu72sPbf1oddAbPXFBK5HqyrH0LLuSMgJABWcVJhbffI94ChKh6fxlG4PUKb7Vt fp76TAzFIbxRDAKaCkX+hrkh4G3NnP0ojf+1rETVa0eO6qJqWT0Ozz+ovLennkecVRUXjy TzWk0l+KpUzy6uyX60KuJjkrZ/YIBkM= 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 08/14] KVM: arm64: Protect page table traversal with RCU Date: Tue, 30 Aug 2022 19:41:26 +0000 Message-Id: <20220830194132.962932-9-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_124223_660628_CE6B6022 X-CRM114-Status: UNSURE ( 9.88 ) 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 use of RCU is necessary to change the paging structures in parallel. Acquire and release an RCU read lock when traversing the page tables. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 19 ++++++++++++++++++- arch/arm64/kvm/hyp/pgtable.c | 7 ++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 78fbb7be1af6..7d2de0a98ccb 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -578,9 +578,26 @@ enum kvm_pgtable_prot kvm_pgtable_stage2_pte_prot(kvm_pte_t pte); */ enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte); +#if defined(__KVM_NVHE_HYPERVISOR___) + +static inline void kvm_pgtable_walk_begin(void) {} +static inline void kvm_pgtable_walk_end(void) {} + +#define kvm_dereference_ptep rcu_dereference_raw + +#else /* !defined(__KVM_NVHE_HYPERVISOR__) */ + +#define kvm_pgtable_walk_begin rcu_read_lock +#define kvm_pgtable_walk_end rcu_read_unlock +#define kvm_dereference_ptep rcu_dereference + +#endif /* defined(__KVM_NVHE_HYPERVISOR__) */ + static inline kvm_pte_t kvm_pte_read(kvm_pte_t *ptep) { - return READ_ONCE(*ptep); + kvm_pte_t __rcu *p = (kvm_pte_t __rcu *)ptep; + + return READ_ONCE(*kvm_dereference_ptep(p)); } #endif /* __ARM64_KVM_PGTABLE_H__ */ diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index f911509e6512..215a14c434ed 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -284,8 +284,13 @@ int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, .end = PAGE_ALIGN(walk_data.addr + size), .walker = walker, }; + int r; - return _kvm_pgtable_walk(&walk_data); + kvm_pgtable_walk_begin(); + r = _kvm_pgtable_walk(&walk_data); + kvm_pgtable_walk_end(); + + return r; } struct leaf_walk_data {