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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78644C433FE for ; Thu, 20 Oct 2022 08:34:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BECFE4B93E; Thu, 20 Oct 2022 04:34:36 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@linux.dev Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VzkxDBTVYP+C; Thu, 20 Oct 2022 04:34:35 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 88F324B945; Thu, 20 Oct 2022 04:34:35 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9FE3A4B93B for ; Thu, 20 Oct 2022 04:34:34 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IyzQyd6QKFYT for ; Thu, 20 Oct 2022 04:34:33 -0400 (EDT) Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 73B684B8F2 for ; Thu, 20 Oct 2022 04:34:33 -0400 (EDT) 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 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-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT Cc: kvm@vger.kernel.org, Marc Zyngier , Will Deacon , kvmarm@lists.linux.dev, Ben Gardon , David Matlack , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu 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 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72F9B7E for ; Thu, 20 Oct 2022 08:34:34 +0000 (UTC) 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> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT Message-ID: <20221020083424.dbnbcxxABi7KKU_nW7AJJwtL0xeHdTZOtWYBsrl0dAo@z> 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 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 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 02855C433FE for ; Thu, 20 Oct 2022 08:35:49 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pifJpwU+62trREVesjqotWbyrZ7jzshynmqzaaxkvE4=; b=BYxKtglTA9P0WH xH1Kv27Df7+We55P0NxF4yvKoz0GL1Ffn70qp+W6/vqGlUTWbeP1QK4q9O2pio2CxYRS3OCo758we TLGxASKQvQRvwvVWwn+D+xr8RqOAxbv3cCdLyCckWX7avogoeN8PADfNROqb95zqCQZj6TCrja63r dgt5zBpxS/qKrasgPOUTiVs0F1Sb9ABSkw7GP9UIooAlQm2rA8ZmfVI76Sr5pDZnFI9WZJNntakq0 5TE/vD8VXcp4OfjcREDrbFmhBWNCghwoMiF6QwSA0sjhvrCTb5SGy7wRaR0h8zBx0vUzPLB2lbrBI Y3ESbkL7MeY4zLzIdecg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olR0l-00CGqx-In; Thu, 20 Oct 2022 08:34:43 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olR0f-00CGkf-CN for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 08:34:38 +0000 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-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221020_013437_590832_D7A4C63A X-CRM114-Status: GOOD ( 17.62 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel