Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp212900rwn; Wed, 7 Sep 2022 15:21:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4c8xo0HqB9hWB0Gf38ORjB470PnLyMlvqPHzhySTP1gjqCEUefbWuRdY5L7DrOiI6wlWeF X-Received: by 2002:a62:1505:0:b0:53e:6141:9d90 with SMTP id 5-20020a621505000000b0053e61419d90mr5865420pfv.24.1662589290230; Wed, 07 Sep 2022 15:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662589290; cv=none; d=google.com; s=arc-20160816; b=hAp9rSBTbyqbls5zA+luAUV9CTjanSXfOyWjRUT2DAE4dpzzkzrwAT2Dve2iA9EEmd UX0VVzmp/T8zGlznu4zvoMX50RQtJ04TTmWm5F4XgvA4s3DiIV39biJ+cRDG/zpoBaBK E0eTcYknr8fQgDmw136hyRxzE23zMAB6aUbewQDLkM54+ozO/VPr3lKaA/zKbVL9CIPg zo9xzS7zJcpPaUkkccwib8Z6T32UxOaF8KddODr7r6Kt+w4dLKETIKZENXfNc7oqlrAP d+4TUveTIE0vFmeoEw4hJ82t4DTYKJOwZ9Om8uivu73sCW2poL2jz3H2xWHg6o225Msk SsPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=a0onBmXPphYT3RuqfDE1tfHpBM48udC3uDDfIPbNeqQ=; b=sO0Dzq4RMXALoADKuzcRjlC5Z49zLWXQhR2uw78I/2Js2cF/uH7xcbRoKs0YORywlW MBztei3UCVfIcxf4LxFDGgQfgDyE21dZAR/+o6SrHvv288BjcjO0xZaRBVjpiL5Ngw5E Lqknu3K/Ege6mACNfESv/dCJwfE9Y3BJAxpAsskvmcUXKnGkbGhYVm1anHICMCw/+C70 sZPRrbkefUJDea8F12XRJUkiJWF668fsmPsbPzx65/w8kKsu5f/gKAWx2QVfh0N/0SyK 3BqQ8yDMhk7fnX/D0n95f/gDzAsazirSrT4g0JXl2WicNL7ur5vVFJhQXguVYzcVAwGb 7Gjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qz8qKS17; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a632311000000b0042c7a2d0196si17461812pgj.484.2022.09.07.15.21.18; Wed, 07 Sep 2022 15:21:30 -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=@google.com header.s=20210112 header.b=qz8qKS17; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230323AbiIGVrU (ORCPT + 99 others); Wed, 7 Sep 2022 17:47:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbiIGVrR (ORCPT ); Wed, 7 Sep 2022 17:47:17 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F7888D3CE for ; Wed, 7 Sep 2022 14:47:16 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id q3so15815531pjg.3 for ; Wed, 07 Sep 2022 14:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=a0onBmXPphYT3RuqfDE1tfHpBM48udC3uDDfIPbNeqQ=; b=qz8qKS17YDB74dB3eVq/ImHb/1panXWt9MKNv77sjzlXj8cL3XwLCX/xz8ZQn9FJSc pkuvn/eM3SPKQUCBDgtCZu6rnvnlsgeB696oCeiPN8LzQIFq4odPuYBB/o7hizZaRcRP tH7JasNxHZyEVsUyfz0V/dL1r9OPMoCaBwGTkGjH1jd/RD5/uG56v/Pc1g6Dr4EGnH6r hr+0E5wBEw/x3ik8lSEvklHAQ6eORvUgxri4N5u/Sr7xvTrdNUpSsXg71MROLD6JhtYd nyD3JCmVLfqxQWXd75Tk6Z+u4KPOxj45s6/oI+dRFkvHvvGKtM9qmtSw3qCoO59EWNNk GKXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=a0onBmXPphYT3RuqfDE1tfHpBM48udC3uDDfIPbNeqQ=; b=Q1H2MJqb7aHVdoTtW9vC1YPZQxxATJk/pNDwAlu+XVPKdYUnL+umeiMpuCXNelp7ap ra6wJDHVMoBc0jeydmZaljxWOc4Apz7NsRdR6SbSki8+1hCm0Q3hVJjahWLQjKAsmc7y n7+QY+TMEQOwd3W++bqLUxgshGW4B/QV2mChSyDHHX1+61Yu6U4ToAwewRoKRgh4I3vl IOoYhoGVaesqKW4d9MUr62TkCPj8bO3J93BsktbH1XVfA7u6GOB8ii7ZGyVl9cAbPNjj 1nCSnSHdSUgkL81/wx1Addjxmz+V0Zs+z1Y6Wl+BREM4fEZpdWpUTWbU5t7DdV497zTG 8Rtg== X-Gm-Message-State: ACgBeo3sFTZr3QQr7P3E0WAuSRINHFzR7902BDyjihVd52XjFUjUKHoK aEFxMZIpq2MH6ySQ5cpyibvP6dc7eGFn1Q== X-Received: by 2002:a17:902:6b4c:b0:171:38ab:e762 with SMTP id g12-20020a1709026b4c00b0017138abe762mr5635735plt.42.1662587235722; Wed, 07 Sep 2022 14:47:15 -0700 (PDT) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id n6-20020a170902e54600b00173cfaed233sm659052plf.62.2022.09.07.14.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 14:47:14 -0700 (PDT) Date: Wed, 7 Sep 2022 14:47:08 -0700 From: David Matlack To: Oliver Upton Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Quentin Perret , Ricardo Koller , Reiji Watanabe , Ben Gardon , Paolo Bonzini , Gavin Shan , Peter Xu , Sean Christopherson , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/14] KVM: arm64: Protect page table traversal with RCU Message-ID: References: <20220830194132.962932-1-oliver.upton@linux.dev> <20220830194132.962932-9-oliver.upton@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220830194132.962932-9-oliver.upton@linux.dev> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Tue, Aug 30, 2022 at 07:41:26PM +0000, Oliver Upton wrote: > 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___) > + Future readers will wonder why NVHE stubs out RCU support and how that is even correct. Some comments here would be useful explain it. > +static inline void kvm_pgtable_walk_begin(void) {} > +static inline void kvm_pgtable_walk_end(void) {} > + > +#define kvm_dereference_ptep rcu_dereference_raw How does NVHE have access 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)); What about all the other places where page table memory is accessed? If RCU is going to be used to protect page table memory, then all accesses have to go under an RCU critical section. This means that page table memory should only be accessed through __rcu annotated pointers and dereferenced with rcu_dereference(). > } > > #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 >