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 2CE94C4332F for ; Mon, 7 Nov 2022 09:47:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9AA9A4B8A5; Mon, 7 Nov 2022 04:47:26 -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 HOBdED5KVwdl; Mon, 7 Nov 2022 04:47:25 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 640D34B869; Mon, 7 Nov 2022 04:47:25 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id B47044B869 for ; Mon, 7 Nov 2022 04:47:23 -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 bLozBzxy-eWL for ; Mon, 7 Nov 2022 04:47:22 -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 503764B81C for ; Mon, 7 Nov 2022 04:47:22 -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 A63AC60FA1; Mon, 7 Nov 2022 09:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E95CC433D6; Mon, 7 Nov 2022 09:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667814441; bh=d0Gjfq9IxI3neZ7cJFWswdfvAF3YFvZpLGtaAX3HpYM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sydGUJFv2o6i8NK3xyRwL7nvQjqAX8UE6aB/aSQZkGhs/R2kPIMTwXbR8/TLUXedv 7RFJeljbFNvMFDOpCKL2oD7UhZXHjZJ6CdToSyQswD249eMMwRIPzWzt0IX6b7GWns WlbmNwBx2GVKJ5Sd0kB5pZzFmPfPYxx2lyh5c5TTfqGYD0NmR1UQKA159vNEtQwAa0 tVbnps8s8ym6LJr5OOeL/DLpFm5KwOr97g1FXJ9UPxKqacVD2/vNnE2i9Y18i7ehrk aJq+yyTsf0Ywln8+sUxnIN5vWn10/3NI9o0B0sQIlZAVAk9CxEK5xs9ZpFuUD+jLui WtEmBJi6gDcCA== 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 1oryis-004M3i-S1; Mon, 07 Nov 2022 09:47:19 +0000 Date: Mon, 07 Nov 2022 09:47:18 +0000 Message-ID: <8635avqeop.wl-maz@kernel.org> From: Marc Zyngier To: Gavin Shan Subject: Re: [PATCH v8 4/7] KVM: arm64: Enable ring-based dirty memory tracking In-Reply-To: References: <20221104234049.25103-1-gshan@redhat.com> <20221104234049.25103-5-gshan@redhat.com> <87mt94f5ev.wl-maz@kernel.org> 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: gshan@redhat.com, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, shuah@kernel.org, catalin.marinas@arm.com, andrew.jones@linux.dev, ajones@ventanamicro.com, bgardon@google.com, dmatlack@google.com, will@kernel.org, suzuki.poulose@arm.com, alexandru.elisei@arm.com, pbonzini@redhat.com, peterx@redhat.com, seanjc@google.com, oliver.upton@linux.dev, zhenyzha@redhat.com, shan.gavin@gmail.com 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, catalin.marinas@arm.com, andrew.jones@linux.dev, dmatlack@google.com, will@kernel.org, shan.gavin@gmail.com, bgardon@google.com, kvmarm@lists.linux.dev, pbonzini@redhat.com, zhenyzha@redhat.com, shuah@kernel.org, kvmarm@lists.cs.columbia.edu, ajones@ventanamicro.com 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 Sun, 06 Nov 2022 21:46:19 +0000, Gavin Shan wrote: > > Hi Marc, > > On 11/6/22 11:50 PM, Marc Zyngier wrote: > > On Fri, 04 Nov 2022 23:40:46 +0000, > > Gavin Shan wrote: > >> > >> Enable ring-based dirty memory tracking on arm64 by selecting > >> CONFIG_HAVE_KVM_DIRTY_{RING_ACQ_REL, RING_WITH_BITMAP} and providing > >> the ring buffer's physical page offset (KVM_DIRTY_LOG_PAGE_OFFSET). > >> > >> Besides, helper kvm_vgic_save_its_tables_in_progress() is added to > >> indicate if vgic/its tables are being saved or not. The helper is used > >> in ARM64's kvm_arch_allow_write_without_running_vcpu() to keep the > >> site of saving vgic/its tables out of no-running-vcpu radar. > >> > >> Signed-off-by: Gavin Shan > >> --- > >> Documentation/virt/kvm/api.rst | 2 +- > >> arch/arm64/include/uapi/asm/kvm.h | 1 + > >> arch/arm64/kvm/Kconfig | 2 ++ > >> arch/arm64/kvm/arm.c | 3 +++ > >> arch/arm64/kvm/mmu.c | 15 +++++++++++++++ > >> arch/arm64/kvm/vgic/vgic-its.c | 3 +++ > >> arch/arm64/kvm/vgic/vgic-mmio-v3.c | 7 +++++++ > >> include/kvm/arm_vgic.h | 2 ++ > >> 8 files changed, 34 insertions(+), 1 deletion(-) > >> > >> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > >> index 2ec32bd41792..2fc68f684ad8 100644 > >> --- a/Documentation/virt/kvm/api.rst > >> +++ b/Documentation/virt/kvm/api.rst > >> @@ -7921,7 +7921,7 @@ regardless of what has actually been exposed through the CPUID leaf. > >> 8.29 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL > >> ---------------------------------------------------------- > >> -:Architectures: x86 > >> +:Architectures: x86, arm64 > >> :Parameters: args[0] - size of the dirty log ring > >> KVM is capable of tracking dirty memory using ring buffers that > >> are > >> diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h > >> index 316917b98707..a7a857f1784d 100644 > >> --- a/arch/arm64/include/uapi/asm/kvm.h > >> +++ b/arch/arm64/include/uapi/asm/kvm.h > >> @@ -43,6 +43,7 @@ > >> #define __KVM_HAVE_VCPU_EVENTS > >> #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 > >> +#define KVM_DIRTY_LOG_PAGE_OFFSET 64 > >> #define KVM_REG_SIZE(id) > >> \ > >> (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) > >> diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig > >> index 815cc118c675..066b053e9eb9 100644 > >> --- a/arch/arm64/kvm/Kconfig > >> +++ b/arch/arm64/kvm/Kconfig > >> @@ -32,6 +32,8 @@ menuconfig KVM > >> select KVM_VFIO > >> select HAVE_KVM_EVENTFD > >> select HAVE_KVM_IRQFD > >> + select HAVE_KVM_DIRTY_RING_ACQ_REL > >> + select HAVE_KVM_DIRTY_RING_WITH_BITMAP > >> select HAVE_KVM_MSI > >> select HAVE_KVM_IRQCHIP > >> select HAVE_KVM_IRQ_ROUTING > >> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > >> index 94d33e296e10..6b097605e38c 100644 > >> --- a/arch/arm64/kvm/arm.c > >> +++ b/arch/arm64/kvm/arm.c > >> @@ -746,6 +746,9 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu) > >> if (kvm_check_request(KVM_REQ_SUSPEND, vcpu)) > >> return kvm_vcpu_suspend(vcpu); > >> + > >> + if (kvm_dirty_ring_check_request(vcpu)) > >> + return 0; > >> } > >> return 1; > >> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > >> index 60ee3d9f01f8..fbeb55e45f53 100644 > >> --- a/arch/arm64/kvm/mmu.c > >> +++ b/arch/arm64/kvm/mmu.c > >> @@ -932,6 +932,21 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, > >> kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); > >> } > >> +/* > >> + * kvm_arch_allow_write_without_running_vcpu - allow writing guest memory > >> + * without the running VCPU when dirty ring is enabled. > >> + * > >> + * The running VCPU is required to track dirty guest pages when dirty ring > >> + * is enabled. Otherwise, the backup bitmap should be used to track the > >> + * dirty guest pages. When vgic/its tables are being saved, the backup > >> + * bitmap is used to track the dirty guest pages due to the missed running > >> + * VCPU in the period. > >> + */ > >> +bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm) > >> +{ > >> + return kvm_vgic_save_its_tables_in_progress(kvm); > > > > I don't think we need the extra level of abstraction here. Just return > > kvm->arch.vgic.save_its_tables_in_progress and be done with it. > > > > You can also move the helper to the vgic-its code since they are > > closely related for now. > > > > Ok. After kvm_arch_allow_write_without_running_vcpu() is moved to vgic-its.c, > do we need to replace 'struct vgic_dist::save_its_tables_in_progress' with > a file-scoped variant ('bool vgic_its_saving_tables') ? No, this still needs to be per-VM. 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 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 67E977F for ; Mon, 7 Nov 2022 09:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E95CC433D6; Mon, 7 Nov 2022 09:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667814441; bh=d0Gjfq9IxI3neZ7cJFWswdfvAF3YFvZpLGtaAX3HpYM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sydGUJFv2o6i8NK3xyRwL7nvQjqAX8UE6aB/aSQZkGhs/R2kPIMTwXbR8/TLUXedv 7RFJeljbFNvMFDOpCKL2oD7UhZXHjZJ6CdToSyQswD249eMMwRIPzWzt0IX6b7GWns WlbmNwBx2GVKJ5Sd0kB5pZzFmPfPYxx2lyh5c5TTfqGYD0NmR1UQKA159vNEtQwAa0 tVbnps8s8ym6LJr5OOeL/DLpFm5KwOr97g1FXJ9UPxKqacVD2/vNnE2i9Y18i7ehrk aJq+yyTsf0Ywln8+sUxnIN5vWn10/3NI9o0B0sQIlZAVAk9CxEK5xs9ZpFuUD+jLui WtEmBJi6gDcCA== 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 1oryis-004M3i-S1; Mon, 07 Nov 2022 09:47:19 +0000 Date: Mon, 07 Nov 2022 09:47:18 +0000 Message-ID: <8635avqeop.wl-maz@kernel.org> From: Marc Zyngier To: Gavin Shan Cc: kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, shuah@kernel.org, catalin.marinas@arm.com, andrew.jones@linux.dev, ajones@ventanamicro.com, bgardon@google.com, dmatlack@google.com, will@kernel.org, suzuki.poulose@arm.com, alexandru.elisei@arm.com, pbonzini@redhat.com, peterx@redhat.com, seanjc@google.com, oliver.upton@linux.dev, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: Re: [PATCH v8 4/7] KVM: arm64: Enable ring-based dirty memory tracking In-Reply-To: References: <20221104234049.25103-1-gshan@redhat.com> <20221104234049.25103-5-gshan@redhat.com> <87mt94f5ev.wl-maz@kernel.org> 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) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: gshan@redhat.com, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, shuah@kernel.org, catalin.marinas@arm.com, andrew.jones@linux.dev, ajones@ventanamicro.com, bgardon@google.com, dmatlack@google.com, will@kernel.org, suzuki.poulose@arm.com, alexandru.elisei@arm.com, pbonzini@redhat.com, peterx@redhat.com, seanjc@google.com, oliver.upton@linux.dev, zhenyzha@redhat.com, shan.gavin@gmail.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Message-ID: <20221107094718.hL6y7TuOVMMPfUxwxig3HsKSm-IDuw4cPxcVmEBloRk@z> On Sun, 06 Nov 2022 21:46:19 +0000, Gavin Shan wrote: > > Hi Marc, > > On 11/6/22 11:50 PM, Marc Zyngier wrote: > > On Fri, 04 Nov 2022 23:40:46 +0000, > > Gavin Shan wrote: > >> > >> Enable ring-based dirty memory tracking on arm64 by selecting > >> CONFIG_HAVE_KVM_DIRTY_{RING_ACQ_REL, RING_WITH_BITMAP} and providing > >> the ring buffer's physical page offset (KVM_DIRTY_LOG_PAGE_OFFSET). > >> > >> Besides, helper kvm_vgic_save_its_tables_in_progress() is added to > >> indicate if vgic/its tables are being saved or not. The helper is used > >> in ARM64's kvm_arch_allow_write_without_running_vcpu() to keep the > >> site of saving vgic/its tables out of no-running-vcpu radar. > >> > >> Signed-off-by: Gavin Shan > >> --- > >> Documentation/virt/kvm/api.rst | 2 +- > >> arch/arm64/include/uapi/asm/kvm.h | 1 + > >> arch/arm64/kvm/Kconfig | 2 ++ > >> arch/arm64/kvm/arm.c | 3 +++ > >> arch/arm64/kvm/mmu.c | 15 +++++++++++++++ > >> arch/arm64/kvm/vgic/vgic-its.c | 3 +++ > >> arch/arm64/kvm/vgic/vgic-mmio-v3.c | 7 +++++++ > >> include/kvm/arm_vgic.h | 2 ++ > >> 8 files changed, 34 insertions(+), 1 deletion(-) > >> > >> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > >> index 2ec32bd41792..2fc68f684ad8 100644 > >> --- a/Documentation/virt/kvm/api.rst > >> +++ b/Documentation/virt/kvm/api.rst > >> @@ -7921,7 +7921,7 @@ regardless of what has actually been exposed through the CPUID leaf. > >> 8.29 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL > >> ---------------------------------------------------------- > >> -:Architectures: x86 > >> +:Architectures: x86, arm64 > >> :Parameters: args[0] - size of the dirty log ring > >> KVM is capable of tracking dirty memory using ring buffers that > >> are > >> diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h > >> index 316917b98707..a7a857f1784d 100644 > >> --- a/arch/arm64/include/uapi/asm/kvm.h > >> +++ b/arch/arm64/include/uapi/asm/kvm.h > >> @@ -43,6 +43,7 @@ > >> #define __KVM_HAVE_VCPU_EVENTS > >> #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 > >> +#define KVM_DIRTY_LOG_PAGE_OFFSET 64 > >> #define KVM_REG_SIZE(id) > >> \ > >> (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) > >> diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig > >> index 815cc118c675..066b053e9eb9 100644 > >> --- a/arch/arm64/kvm/Kconfig > >> +++ b/arch/arm64/kvm/Kconfig > >> @@ -32,6 +32,8 @@ menuconfig KVM > >> select KVM_VFIO > >> select HAVE_KVM_EVENTFD > >> select HAVE_KVM_IRQFD > >> + select HAVE_KVM_DIRTY_RING_ACQ_REL > >> + select HAVE_KVM_DIRTY_RING_WITH_BITMAP > >> select HAVE_KVM_MSI > >> select HAVE_KVM_IRQCHIP > >> select HAVE_KVM_IRQ_ROUTING > >> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > >> index 94d33e296e10..6b097605e38c 100644 > >> --- a/arch/arm64/kvm/arm.c > >> +++ b/arch/arm64/kvm/arm.c > >> @@ -746,6 +746,9 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu) > >> if (kvm_check_request(KVM_REQ_SUSPEND, vcpu)) > >> return kvm_vcpu_suspend(vcpu); > >> + > >> + if (kvm_dirty_ring_check_request(vcpu)) > >> + return 0; > >> } > >> return 1; > >> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > >> index 60ee3d9f01f8..fbeb55e45f53 100644 > >> --- a/arch/arm64/kvm/mmu.c > >> +++ b/arch/arm64/kvm/mmu.c > >> @@ -932,6 +932,21 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, > >> kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); > >> } > >> +/* > >> + * kvm_arch_allow_write_without_running_vcpu - allow writing guest memory > >> + * without the running VCPU when dirty ring is enabled. > >> + * > >> + * The running VCPU is required to track dirty guest pages when dirty ring > >> + * is enabled. Otherwise, the backup bitmap should be used to track the > >> + * dirty guest pages. When vgic/its tables are being saved, the backup > >> + * bitmap is used to track the dirty guest pages due to the missed running > >> + * VCPU in the period. > >> + */ > >> +bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm) > >> +{ > >> + return kvm_vgic_save_its_tables_in_progress(kvm); > > > > I don't think we need the extra level of abstraction here. Just return > > kvm->arch.vgic.save_its_tables_in_progress and be done with it. > > > > You can also move the helper to the vgic-its code since they are > > closely related for now. > > > > Ok. After kvm_arch_allow_write_without_running_vcpu() is moved to vgic-its.c, > do we need to replace 'struct vgic_dist::save_its_tables_in_progress' with > a file-scoped variant ('bool vgic_its_saving_tables') ? No, this still needs to be per-VM. M. -- Without deviation from the norm, progress is not possible.