From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D330C4332F for ; Thu, 20 Oct 2022 08:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230517AbiJTIfX (ORCPT ); Thu, 20 Oct 2022 04:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbiJTIet (ORCPT ); Thu, 20 Oct 2022 04:34:49 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ACD83E753 for ; Thu, 20 Oct 2022 01:34:35 -0700 (PDT) Date: Thu, 20 Oct 2022 11:34:24 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1666254872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qzX6SzV6RdnXytSM2ouehoSyV7++gCHengCJvmVIT7s=; b=ha7Agfr0EZ1HqBNwRgfdeT84BnPAGCdqCmWxiw8zIoxjGznrHHmeb8r2ZOT6kEIhjttnjI JvxjjwysVU/zudV3hs35G+nF2vyB/lOZmRkFRbJiEHOWfZ3PgsVHrBtc/g4SKQQcQZBtBN V/iHop8+q44+UHjRL4hZo422bZj8pPY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: Marc Zyngier , James Morse , Alexandru Elisei , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Reiji Watanabe , Ricardo Koller , David Matlack , Quentin Perret , Ben Gardon , Gavin Shan , Peter Xu , Will Deacon , kvmarm@lists.linux.dev Subject: Re: [PATCH v2 08/15] KVM: arm64: Protect stage-2 traversal with RCU Message-ID: References: <20221007232818.459650-1-oliver.upton@linux.dev> <20221007232818.459650-9-oliver.upton@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Oct 19, 2022 at 11:29:56PM +0000, Sean Christopherson wrote: > On Fri, Oct 07, 2022, Oliver Upton wrote: > > The use of RCU is necessary to safely change the stage-2 page tables in > > parallel. Acquire and release the RCU read lock when traversing the page > > tables. > > > > Use the _raw() flavor of rcu_dereference when changes to the page tables > > are otherwise protected from parallel software walkers (e.g. holding the > > write lock). > > > > Signed-off-by: Oliver Upton > > --- > > ... > > > @@ -32,6 +39,33 @@ static inline kvm_pte_t *kvm_dereference_pteref(kvm_pteref_t pteref, bool shared > > return pteref; > > } > > > > +static inline void kvm_pgtable_walk_begin(void) {} > > +static inline void kvm_pgtable_walk_end(void) {} > > + > > +#else > > + > > +typedef kvm_pte_t __rcu *kvm_pteref_t; > > + > > +static inline kvm_pte_t *kvm_dereference_pteref(kvm_pteref_t pteref, bool shared) > > +{ > > + if (shared) > > + return rcu_dereference(pteref); > > + > > + return rcu_dereference_raw(pteref); > > Rather than use raw, use rcu_dereference_check(). If you can plumb down @kvm or > @mmu_lock, the ideal check would be (apparently there's no lockdep_is_held_write() > wrapper?) > > return READ_ONCE(*rcu_dereference_check(ptep, lockdep_is_held_type(mmu_lock, 0))); > > If getting at mmu_lock is too difficult, this can still be > > return READ_ONCE(*rcu_dereference_check(ptep, !shared); > > Doubt it matters for code generation, but IMO it's cleaner overall. As the page table walkers can be used outside of the context of a VM (such as hyp stage-1), I think option #2 is probably a bit easier. -- Thanks, Oliver