Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4595846rwe; Tue, 30 Aug 2022 13:07:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR4nCwClZIZc2k108UaO8pZ4ZWxSaM+HPmlKeAEE9H05J6oM2CJg4ZOonYsyZqLfKK6aB8dF X-Received: by 2002:aa7:cfcb:0:b0:447:b4e5:22fb with SMTP id r11-20020aa7cfcb000000b00447b4e522fbmr20902454edy.190.1661890052043; Tue, 30 Aug 2022 13:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661890052; cv=none; d=google.com; s=arc-20160816; b=bH7OGDV52+orYzzAOfpkvojArbPnYyFYt3kPXQgY6qbCRrbTgvRkg1xzBRi84d0vUc J+T4kAXuQnrnMBGbjRTqzRPC+IFU2SHsPPPKgMXkBQ64uyT+5DE0wYiMVm90RaWXyjGY WIMOg/2xaM5teMlA5PiOU/7L9qeblMOClpwSW9xQJ/sposh+2gn6GQuWG5al3OGd//re NfT0ReCpNBtJmLXqCEKoXmLzhIzyjMWZSt5MSvXAPUhgBLDoACZHx+OETQGNyBEjU+ut u5j1b/H1+FMtkXoPGGd+BhV42FJouCjxorNtcuFWrEJ4kO5C6rm92/D+2u6l8FI/45wI J3Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PAa+cBkl9mtwNYK8/w+PcWpN4aBBuzKZQpA5735hA3U=; b=FjwOm8cSAWEto4RKJZomVPmfdMWTaMUbu7Q3KPTJnV6qzcwM18IjBT7nE9GNXbnDDG 69OvKRqou9xQsdwqqnasZvQ/QgqR6Na79xQhN8H8D0vXNWehGn4jY2t6SrSeRaJroqoe W0nrvJ0kJjMzWVky3tCJ5wgfWZ/pxB6zey54WGV4CE54NnO1AyRvdNjl6ob7f+LgRoEn pgFsG260RlLc1VU/PhVKkY+Mu/XBJrKVPmhfPMPumpng0YHWBWNkiFVGqWOHKmWBCkx3 1Ak4/Pli5MjOaRwNpuwczqVs7AIYSCRSP8FJcCV+mjNbDxDFJgvh9eIH8qFm3+e+3oMH uXQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZLs5MEMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs18-20020a170906dc9200b006feb76dbd51si8439248ejc.289.2022.08.30.13.06.49; Tue, 30 Aug 2022 13:07:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZLs5MEMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbiH3Tmy (ORCPT + 99 others); Tue, 30 Aug 2022 15:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231555AbiH3Tmi (ORCPT ); Tue, 30 Aug 2022 15:42:38 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 598047B7AF; Tue, 30 Aug 2022 12:42:24 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 { -- 2.37.2.672.g94769d06f0-goog