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 9022EC4332F for ; Thu, 10 Nov 2022 13:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbiKJNeV (ORCPT ); Thu, 10 Nov 2022 08:34:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbiKJNeV (ORCPT ); Thu, 10 Nov 2022 08:34:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 343D81FCE3 for ; Thu, 10 Nov 2022 05:34:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DBFCDB821AC for ; Thu, 10 Nov 2022 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B112C433D6; Thu, 10 Nov 2022 13:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668087257; bh=CxU5CLs5OzAY7rGv18GgAC+P9XrarCRDN5MlMlNYwc0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ig3W1MeBQMrSMV0bQOlZ63AAFX/0x05D4mvVeQpGUSLykXvxa4WbCPvHWf9WbSWGq 7mwKiCYgBH0guWQT0Yo2Z/ZvIo9tX+gqnQfcg/hOktDB5keIM66X2DFpRImUKuaBQB y27td9nyeWERrxZ37BcQoHZTEnlW9hk3sR4MI8NZ1AADpwt2CWZVZ9XJY+nEb4z/R0 3qD4ZtDye4MjatDM8IL8SIWKZD3UkhdrRCW9Sxhc0q9Amnk6q+uWgjcBkRwxMInt/O WIiERHFhc8sJeSbcpVr2PRLHAWGOrzV6h9xhIg0ok0I1A929w+P3gKpZizpHX1VMKq SPbynZR5N5kBA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ot7h9-005A9N-90; Thu, 10 Nov 2022 13:34:15 +0000 Date: Thu, 10 Nov 2022 13:34:14 +0000 Message-ID: <86mt8zorvt.wl-maz@kernel.org> From: Marc Zyngier To: Ben Gardon Cc: Oliver Upton , 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 , Gavin Shan , Peter Xu , Will Deacon , Sean Christopherson , kvmarm@lists.linux.dev Subject: Re: [PATCH v5 08/14] KVM: arm64: Protect stage-2 traversal with RCU In-Reply-To: References: <20221107215644.1895162-1-oliver.upton@linux.dev> <20221107215644.1895162-9-oliver.upton@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: bgardon@google.com, oliver.upton@linux.dev, james.morse@arm.com, alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, reijiw@google.com, ricarkol@google.com, dmatlack@google.com, qperret@google.com, gshan@redhat.com, peterx@redhat.com, will@kernel.org, seanjc@google.com, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, 09 Nov 2022 22:25:38 +0000, Ben Gardon wrote: > > On Mon, Nov 7, 2022 at 1:57 PM Oliver Upton wrote: > > > > Use RCU to safely walk the stage-2 page tables in parallel. Acquire and > > release the RCU read lock when traversing the page tables. Defer the > > freeing of table memory to an RCU callback. Indirect the calls into RCU > > and provide stubs for hypervisor code, as RCU is not available in such a > > context. > > > > The RCU protection doesn't amount to much at the moment, as readers are > > already protected by the read-write lock (all walkers that free table > > memory take the write lock). Nonetheless, a subsequent change will > > futher relax the locking requirements around the stage-2 MMU, thereby > > depending on RCU. > > > > Signed-off-by: Oliver Upton > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 49 ++++++++++++++++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 10 +++++- > > arch/arm64/kvm/mmu.c | 14 +++++++- > > 3 files changed, 71 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index e70cf57b719e..7634b6964779 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -37,6 +37,13 @@ static inline u64 kvm_get_parange(u64 mmfr0) > > > > typedef u64 kvm_pte_t; > > > > +/* > > + * RCU cannot be used in a non-kernel context such as the hyp. As such, page > > + * table walkers used in hyp do not call into RCU and instead use other > > + * synchronization mechanisms (such as a spinlock). > > + */ > > +#if defined(__KVM_NVHE_HYPERVISOR__) || defined(__KVM_VHE_HYPERVISOR__) > > + > > typedef kvm_pte_t *kvm_pteref_t; > > > > static inline kvm_pte_t *kvm_dereference_pteref(kvm_pteref_t pteref, bool shared) > > @@ -44,6 +51,40 @@ 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) {} > > + > > +static inline bool kvm_pgtable_walk_lock_held(void) > > +{ > > + return true; > > Forgive my ignorance, but does hyp not use a MMU lock at all? Seems > like this would be a good place to add a lockdep check. For normal KVM, we don't mess with the page tables in the HYP code *at all*. That's just not the place. It is for pKVM that this is a bit different, as EL2 is where the stuff happens. Lockdep at EL2 is wishful thinking. However, we have the next best thing, which is an assertion such as: hyp_assert_lock_held(&host_kvm.lock); though at the moment, this is a *global* lock that serialises everyone, as a guest stage-2 operation usually affects the host stage-2 as well (ownership change and such). Quentin should be able to provide more details on that. M. -- Without deviation from the norm, progress is not possible. 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 25AF8C43217 for ; Thu, 10 Nov 2022 13:34:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9026A4BA8B; Thu, 10 Nov 2022 08:34:22 -0500 (EST) 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=@kernel.org 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 UedGYuPIfuIC; Thu, 10 Nov 2022 08:34:21 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 506144BA9B; Thu, 10 Nov 2022 08:34:21 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E258D4BA79 for ; Thu, 10 Nov 2022 08:34:19 -0500 (EST) 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 2R3xIKRKHF46 for ; Thu, 10 Nov 2022 08:34:18 -0500 (EST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id B7D444BA76 for ; Thu, 10 Nov 2022 08:34:18 -0500 (EST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1CFA16163C; Thu, 10 Nov 2022 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B112C433D6; Thu, 10 Nov 2022 13:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668087257; bh=CxU5CLs5OzAY7rGv18GgAC+P9XrarCRDN5MlMlNYwc0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ig3W1MeBQMrSMV0bQOlZ63AAFX/0x05D4mvVeQpGUSLykXvxa4WbCPvHWf9WbSWGq 7mwKiCYgBH0guWQT0Yo2Z/ZvIo9tX+gqnQfcg/hOktDB5keIM66X2DFpRImUKuaBQB y27td9nyeWERrxZ37BcQoHZTEnlW9hk3sR4MI8NZ1AADpwt2CWZVZ9XJY+nEb4z/R0 3qD4ZtDye4MjatDM8IL8SIWKZD3UkhdrRCW9Sxhc0q9Amnk6q+uWgjcBkRwxMInt/O WIiERHFhc8sJeSbcpVr2PRLHAWGOrzV6h9xhIg0ok0I1A929w+P3gKpZizpHX1VMKq SPbynZR5N5kBA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ot7h9-005A9N-90; Thu, 10 Nov 2022 13:34:15 +0000 Date: Thu, 10 Nov 2022 13:34:14 +0000 Message-ID: <86mt8zorvt.wl-maz@kernel.org> From: Marc Zyngier To: Ben Gardon Subject: Re: [PATCH v5 08/14] KVM: arm64: Protect stage-2 traversal with RCU In-Reply-To: References: <20221107215644.1895162-1-oliver.upton@linux.dev> <20221107215644.1895162-9-oliver.upton@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: bgardon@google.com, oliver.upton@linux.dev, james.morse@arm.com, alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, reijiw@google.com, ricarkol@google.com, dmatlack@google.com, qperret@google.com, gshan@redhat.com, peterx@redhat.com, will@kernel.org, seanjc@google.com, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: kvm@vger.kernel.org, Will Deacon , kvmarm@lists.linux.dev, 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, 09 Nov 2022 22:25:38 +0000, Ben Gardon wrote: > > On Mon, Nov 7, 2022 at 1:57 PM Oliver Upton wrote: > > > > Use RCU to safely walk the stage-2 page tables in parallel. Acquire and > > release the RCU read lock when traversing the page tables. Defer the > > freeing of table memory to an RCU callback. Indirect the calls into RCU > > and provide stubs for hypervisor code, as RCU is not available in such a > > context. > > > > The RCU protection doesn't amount to much at the moment, as readers are > > already protected by the read-write lock (all walkers that free table > > memory take the write lock). Nonetheless, a subsequent change will > > futher relax the locking requirements around the stage-2 MMU, thereby > > depending on RCU. > > > > Signed-off-by: Oliver Upton > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 49 ++++++++++++++++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 10 +++++- > > arch/arm64/kvm/mmu.c | 14 +++++++- > > 3 files changed, 71 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index e70cf57b719e..7634b6964779 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -37,6 +37,13 @@ static inline u64 kvm_get_parange(u64 mmfr0) > > > > typedef u64 kvm_pte_t; > > > > +/* > > + * RCU cannot be used in a non-kernel context such as the hyp. As such, page > > + * table walkers used in hyp do not call into RCU and instead use other > > + * synchronization mechanisms (such as a spinlock). > > + */ > > +#if defined(__KVM_NVHE_HYPERVISOR__) || defined(__KVM_VHE_HYPERVISOR__) > > + > > typedef kvm_pte_t *kvm_pteref_t; > > > > static inline kvm_pte_t *kvm_dereference_pteref(kvm_pteref_t pteref, bool shared) > > @@ -44,6 +51,40 @@ 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) {} > > + > > +static inline bool kvm_pgtable_walk_lock_held(void) > > +{ > > + return true; > > Forgive my ignorance, but does hyp not use a MMU lock at all? Seems > like this would be a good place to add a lockdep check. For normal KVM, we don't mess with the page tables in the HYP code *at all*. That's just not the place. It is for pKVM that this is a bit different, as EL2 is where the stuff happens. Lockdep at EL2 is wishful thinking. However, we have the next best thing, which is an assertion such as: hyp_assert_lock_held(&host_kvm.lock); though at the moment, this is a *global* lock that serialises everyone, as a guest stage-2 operation usually affects the host stage-2 as well (ownership change and such). Quentin should be able to provide more details on that. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ 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 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 05A61C4332F for ; Thu, 10 Nov 2022 13:35:17 +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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/CF1o+w47MIYl/utdCLNdbSQ/lUXLhXuP9iwBxslzF8=; b=FYpSZ73pc3DAw6 lGzMQXolmWipE/CrZ+fbf2Tnt9IM4ks8s81pHx25XF76+Xmxv+Wzw74y1R//Z1KONF5DVJTbhyfno EUzTz5jk9ra5niIp4z22IEjQtLZDHZ/LCxwBIJUj8quG/4OpQtIoFN8WGpme89FlUR6pdmbfFeGpX xgl0B9ysgtnTxbjXIQUsEJagEExYHw3LdkDlELStToDxsdBBxyLzukDY1UyDSHLL9Y/oHGOB4FMB6 4AbIRWaOgwhIOYsopYMB81x90nxZ+VzZUcV6QlHnXAip4mSUp2Zj8ZwCrRDns1r+QNzcYQBr6Y/Y3 oRdLMlwGYoqvSsfEwkUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ot7hG-00639y-BT; Thu, 10 Nov 2022 13:34:22 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ot7hC-00637u-PI for linux-arm-kernel@lists.infradead.org; Thu, 10 Nov 2022 13:34:20 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1CFA16163C; Thu, 10 Nov 2022 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B112C433D6; Thu, 10 Nov 2022 13:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668087257; bh=CxU5CLs5OzAY7rGv18GgAC+P9XrarCRDN5MlMlNYwc0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ig3W1MeBQMrSMV0bQOlZ63AAFX/0x05D4mvVeQpGUSLykXvxa4WbCPvHWf9WbSWGq 7mwKiCYgBH0guWQT0Yo2Z/ZvIo9tX+gqnQfcg/hOktDB5keIM66X2DFpRImUKuaBQB y27td9nyeWERrxZ37BcQoHZTEnlW9hk3sR4MI8NZ1AADpwt2CWZVZ9XJY+nEb4z/R0 3qD4ZtDye4MjatDM8IL8SIWKZD3UkhdrRCW9Sxhc0q9Amnk6q+uWgjcBkRwxMInt/O WIiERHFhc8sJeSbcpVr2PRLHAWGOrzV6h9xhIg0ok0I1A929w+P3gKpZizpHX1VMKq SPbynZR5N5kBA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ot7h9-005A9N-90; Thu, 10 Nov 2022 13:34:15 +0000 Date: Thu, 10 Nov 2022 13:34:14 +0000 Message-ID: <86mt8zorvt.wl-maz@kernel.org> From: Marc Zyngier To: Ben Gardon Cc: Oliver Upton , 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 , Gavin Shan , Peter Xu , Will Deacon , Sean Christopherson , kvmarm@lists.linux.dev Subject: Re: [PATCH v5 08/14] KVM: arm64: Protect stage-2 traversal with RCU In-Reply-To: References: <20221107215644.1895162-1-oliver.upton@linux.dev> <20221107215644.1895162-9-oliver.upton@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: bgardon@google.com, oliver.upton@linux.dev, james.morse@arm.com, alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, reijiw@google.com, ricarkol@google.com, dmatlack@google.com, qperret@google.com, gshan@redhat.com, peterx@redhat.com, will@kernel.org, seanjc@google.com, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221110_053418_918650_D4E1930F X-CRM114-Status: GOOD ( 32.01 ) 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, 09 Nov 2022 22:25:38 +0000, Ben Gardon wrote: > > On Mon, Nov 7, 2022 at 1:57 PM Oliver Upton wrote: > > > > Use RCU to safely walk the stage-2 page tables in parallel. Acquire and > > release the RCU read lock when traversing the page tables. Defer the > > freeing of table memory to an RCU callback. Indirect the calls into RCU > > and provide stubs for hypervisor code, as RCU is not available in such a > > context. > > > > The RCU protection doesn't amount to much at the moment, as readers are > > already protected by the read-write lock (all walkers that free table > > memory take the write lock). Nonetheless, a subsequent change will > > futher relax the locking requirements around the stage-2 MMU, thereby > > depending on RCU. > > > > Signed-off-by: Oliver Upton > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 49 ++++++++++++++++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 10 +++++- > > arch/arm64/kvm/mmu.c | 14 +++++++- > > 3 files changed, 71 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index e70cf57b719e..7634b6964779 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -37,6 +37,13 @@ static inline u64 kvm_get_parange(u64 mmfr0) > > > > typedef u64 kvm_pte_t; > > > > +/* > > + * RCU cannot be used in a non-kernel context such as the hyp. As such, page > > + * table walkers used in hyp do not call into RCU and instead use other > > + * synchronization mechanisms (such as a spinlock). > > + */ > > +#if defined(__KVM_NVHE_HYPERVISOR__) || defined(__KVM_VHE_HYPERVISOR__) > > + > > typedef kvm_pte_t *kvm_pteref_t; > > > > static inline kvm_pte_t *kvm_dereference_pteref(kvm_pteref_t pteref, bool shared) > > @@ -44,6 +51,40 @@ 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) {} > > + > > +static inline bool kvm_pgtable_walk_lock_held(void) > > +{ > > + return true; > > Forgive my ignorance, but does hyp not use a MMU lock at all? Seems > like this would be a good place to add a lockdep check. For normal KVM, we don't mess with the page tables in the HYP code *at all*. That's just not the place. It is for pKVM that this is a bit different, as EL2 is where the stuff happens. Lockdep at EL2 is wishful thinking. However, we have the next best thing, which is an assertion such as: hyp_assert_lock_held(&host_kvm.lock); though at the moment, this is a *global* lock that serialises everyone, as a guest stage-2 operation usually affects the host stage-2 as well (ownership change and such). Quentin should be able to provide more details on that. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel