Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2841285pxb; Thu, 10 Feb 2022 06:47:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdfspBe3SY8XtSWunVFo3FKjNEmJCgK77cMi88xNaE74FJvX9Pa3tYt12ds2uuFX8FJQwM X-Received: by 2002:a63:8641:: with SMTP id x62mr6408900pgd.293.1644504464015; Thu, 10 Feb 2022 06:47:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644504464; cv=none; d=google.com; s=arc-20160816; b=XoV+vpJtnudyhF1ngKcvLGDZiVhDRNKUzaXamyiMrPM3GywRi5y2gkw13mp1oOZz/b t9wq9MGrmRbRlIKEhJRJ4Svm/2g3DdAbT/kWCeLbxR3tQD4Ty0Ssy9eKhcO2m7OakRLO j+ziOT5H9w72MErO4RzI2T3KXfOa582iiwGK1+bq5a0bmZNRdJFfGjMJ52dr46lKp/U1 6vi8TSO2C5rKDjqWiqev3OlJ906AnA+HIn3D486M3Dja6RYPdWaDOQhk441YBejQFN5G U8xs88HsdjyTgo1l38FaZ6OwAACFDaE/ylQjJrsh/ItbQkfjsu72+SPyWIg6/RefJfj1 hblw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=ownnwDmvRyf1tTLRxOXI5zyGbZcAhZHI2cqxp4o1rWY=; b=aPvTUmyD2nSujYsbgfAE2wWs6TJRt3dcS8ZcTl3Uf4fBwsDdAsiiRnJoR4DcYnKvaH jFrDTKFFLUFwD2SpaiKA8FfiLUUARuBlelLYilLG7rr863C47uZujgN5kZv9tlpsNrcM tF/e0OighJ0d8SRw09+pcSCu8mcVMqGnE9ch9N6ERErMi8BjN2d9g2SvLnO6Gwc5A5Z9 q5nEzp7qRDkxuSYcVSWyuSNy3qVGAeKedrM9OJjxLdPZsFJbqTxw8hyGo0ux2BjYRMGa nZg9DK/1L0cx/yhzQLqQSonfUVNU0BHWWlFNqb/zaIjE83aVeE+hLbACkCFpQ7qHEpQ4 ktEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S9B2sKkL; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be3si2016925plb.194.2022.02.10.06.47.25; Thu, 10 Feb 2022 06:47:43 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=S9B2sKkL; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242637AbiBJOHd (ORCPT + 99 others); Thu, 10 Feb 2022 09:07:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233943AbiBJOHc (ORCPT ); Thu, 10 Feb 2022 09:07:32 -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 74FFF1B3; Thu, 10 Feb 2022 06:07:32 -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 1E1FEB82366; Thu, 10 Feb 2022 14:07:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EDBAC004E1; Thu, 10 Feb 2022 14:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644502049; bh=BJ/i3ajwOc9GZf1TyHa/AtivYqVLgEzzhCyPgZ8Bhrg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=S9B2sKkLnTG5D1mJOEo2dP0z8Bes+M8CS518E2wgmB0lS1uCokWFhyX0BxdBn6lJg Fx9zSTZHHfm297ZK0BrrzE2HjGlSwN87MNLAoTez19TmhPu0kVJsA8KFMjjb0y4x7r rxYfwCmyBG94loxBZSFiiWycB6WQSqceIKDVDboLxaqi+4P8hRPaVO6VQbUYYi0oWQ dCt67ItJvyDg9SCKXp1fcHzsE/hv+lF7lKPbZLqjKAjrLJszWZl+cKZNC9oICmpGO0 z3Vron5Yz9AbXF2Qs4l5o14ZQKqKIwHs5LI54zj7ERs4pnu70wlGCQfRmnHe0eDcvv J/KGkVHEZApmQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nIA6Z-006v5o-J4; Thu, 10 Feb 2022 14:07:27 +0000 Date: Thu, 10 Feb 2022 14:07:27 +0000 Message-ID: <87sfsq4xy8.wl-maz@kernel.org> From: Marc Zyngier To: Sean Christopherson , Chao Gao Cc: kvm@vger.kernel.org, pbonzini@redhat.com, kevin.tian@intel.com, tglx@linutronix.de, John Garry , Will Deacon , Qi Liu , Thomas Richter , Shaokun Zhang , Hector Martin , Huang Ying , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 4/5] KVM: Rename and move CPUHP_AP_KVM_STARTING to ONLINE section In-Reply-To: References: <20220209074109.453116-1-chao.gao@intel.com> <20220209074109.453116-5-chao.gao@intel.com> 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 (x86_64-pc-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 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: seanjc@google.com, chao.gao@intel.com, kvm@vger.kernel.org, pbonzini@redhat.com, kevin.tian@intel.com, tglx@linutronix.de, john.garry@huawei.com, will@kernel.org, liuqi115@huawei.com, tmricht@linux.ibm.com, zhangshaokun@hisilicon.com, marcan@marcan.st, ying.huang@intel.com, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, 09 Feb 2022 19:59:45 +0000, Sean Christopherson wrote: >=20 > +Marc Thanks for the heads up. >=20 > On Wed, Feb 09, 2022, Chao Gao wrote: > > The CPU STARTING section doesn't allow callbacks to fail. Move KVM's > > hotplug callback to ONLINE section so that it can abort onlining a CPU = in > > certain cases to avoid potentially breaking VMs running on existing CPU= s. > > For example, when kvm fails to enable hardware virtualization on the > > hotplugged CPU. > >=20 > > Place KVM's hotplug state before CPUHP_AP_SCHED_WAIT_EMPTY as it ensures > > when offlining a CPU, all user tasks and non-pinned kernel tasks have l= eft > > the CPU, i.e. there cannot be a vCPU task around. So, it is safe for KV= M's > > CPU offline callback to disable hardware virtualization at that point. > > Likewise, KVM's online callback can enable hardware virtualization befo= re > > any vCPU task gets a chance to run on hotplugged CPUs. > >=20 > > KVM's CPU hotplug callbacks are renamed as well. > >=20 > > Suggested-by: Thomas Gleixner > > Signed-off-by: Chao Gao > > --- > > include/linux/cpuhotplug.h | 2 +- > > virt/kvm/kvm_main.c | 30 ++++++++++++++++++++++-------- > > 2 files changed, 23 insertions(+), 9 deletions(-) > >=20 > > diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h > > index 773c83730906..14d354c8ce35 100644 > > --- a/include/linux/cpuhotplug.h > > +++ b/include/linux/cpuhotplug.h > > @@ -182,7 +182,6 @@ enum cpuhp_state { > > CPUHP_AP_CSKY_TIMER_STARTING, > > CPUHP_AP_TI_GP_TIMER_STARTING, > > CPUHP_AP_HYPERV_TIMER_STARTING, > > - CPUHP_AP_KVM_STARTING, > > CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, > > CPUHP_AP_KVM_ARM_VGIC_STARTING, > > CPUHP_AP_KVM_ARM_TIMER_STARTING, >=20 > This probably needs an ack from Marc. IIUC, it changes the ordering > between generic KVM enabling hardware and KVM ARM doing its vGIC and > timer stuff. Indeed, that's not great. Specially the part that enable interrupts before things are up and running on the CPU. But TBH, this area really deserves a good scrubbing, and I don't see why we need to keep these individual CPUHP notifiers. I wrote the patch below, thrown it at a test box, and nothing caught fire as I was fiddling with CPUs going up and down. It is thus obviously perfect. Feel free to take it as part of your series. Thanks, M. =46rom 57d80dbe5a10bc3b5bce748f637dea420ef960a1 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Thu, 10 Feb 2022 13:50:52 +0000 Subject: [PATCH] KVM: arm64: Simplify the CPUHP logic For a number of historical reasons, the KVM/arm64 hotplug setup is pretty complicated, and we have two extra CPUHP notifiers for vGIC and timers. It looks pretty pointless, and gets in the way of further changes. So let's just expose some helpers that can be called from the core CPUHP callback, and get rid of everything else. This gives us the opportunity to drop a useless notifier entry, as well as tidy-up the timer enable/disable, which was a bit odd. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/arch_timer.c | 27 ++++++++++----------------- arch/arm64/kvm/arm.c | 4 ++++ arch/arm64/kvm/vgic/vgic-init.c | 19 ++----------------- include/kvm/arm_arch_timer.h | 4 ++++ include/kvm/arm_vgic.h | 4 ++++ include/linux/cpuhotplug.h | 3 --- 6 files changed, 24 insertions(+), 37 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 6e542e2eae32..f9d14c6dc0b4 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -796,10 +796,18 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) ptimer->host_timer_irq_flags =3D host_ptimer_irq_flags; } =20 -static void kvm_timer_init_interrupt(void *info) +void kvm_timer_cpu_up(void) { enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags); - enable_percpu_irq(host_ptimer_irq, host_ptimer_irq_flags); + if (host_ptimer_irq) + enable_percpu_irq(host_ptimer_irq, host_ptimer_irq_flags); +} + +void kvm_timer_cpu_down(void) +{ + disable_percpu_irq(host_vtimer_irq); + if (host_ptimer_irq) + disable_percpu_irq(host_ptimer_irq); } =20 int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) @@ -961,18 +969,6 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu, preempt_enable(); } =20 -static int kvm_timer_starting_cpu(unsigned int cpu) -{ - kvm_timer_init_interrupt(NULL); - return 0; -} - -static int kvm_timer_dying_cpu(unsigned int cpu) -{ - disable_percpu_irq(host_vtimer_irq); - return 0; -} - static int timer_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu) { if (vcpu) @@ -1170,9 +1166,6 @@ int kvm_timer_hyp_init(bool has_gic) goto out_free_irq; } =20 - cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING, - "kvm/arm/timer:starting", kvm_timer_starting_cpu, - kvm_timer_dying_cpu); return 0; out_free_irq: free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus()); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index fefd5774ab55..6c9cb3fdd3af 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1600,6 +1600,8 @@ static void _kvm_arch_hardware_enable(void *discard) { if (!__this_cpu_read(kvm_arm_hardware_enabled)) { cpu_hyp_reinit(); + kvm_vgic_cpu_up(); + kvm_timer_cpu_up(); __this_cpu_write(kvm_arm_hardware_enabled, 1); } } @@ -1613,6 +1615,8 @@ int kvm_arch_hardware_enable(void) static void _kvm_arch_hardware_disable(void *discard) { if (__this_cpu_read(kvm_arm_hardware_enabled)) { + kvm_timer_cpu_down(); + kvm_vgic_cpu_down(); cpu_hyp_reset(); __this_cpu_write(kvm_arm_hardware_enabled, 0); } diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-ini= t.c index fc00304fe7d8..60038a8516de 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -460,17 +460,15 @@ int kvm_vgic_map_resources(struct kvm *kvm) =20 /* GENERIC PROBE */ =20 -static int vgic_init_cpu_starting(unsigned int cpu) +void kvm_vgic_cpu_up(void) { enable_percpu_irq(kvm_vgic_global_state.maint_irq, 0); - return 0; } =20 =20 -static int vgic_init_cpu_dying(unsigned int cpu) +void kvm_vgic_cpu_down(void) { disable_percpu_irq(kvm_vgic_global_state.maint_irq); - return 0; } =20 static irqreturn_t vgic_maintenance_handler(int irq, void *data) @@ -579,19 +577,6 @@ int kvm_vgic_hyp_init(void) return ret; } =20 - ret =3D cpuhp_setup_state(CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, - "kvm/arm/vgic:starting", - vgic_init_cpu_starting, vgic_init_cpu_dying); - if (ret) { - kvm_err("Cannot register vgic CPU notifier\n"); - goto out_free_irq; - } - kvm_info("vgic interrupt IRQ%d\n", kvm_vgic_global_state.maint_irq); return 0; - -out_free_irq: - free_percpu_irq(kvm_vgic_global_state.maint_irq, - kvm_get_running_vcpus()); - return ret; } diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 51c19381108c..16a2f65fcfb4 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -106,4 +106,8 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu, u32 timer_get_ctl(struct arch_timer_context *ctxt); u64 timer_get_cval(struct arch_timer_context *ctxt); =20 +/* CPU HP callbacks */ +void kvm_timer_cpu_up(void); +void kvm_timer_cpu_down(void); + #endif diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index bb30a6803d9f..a2a0cca05a73 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -427,4 +427,8 @@ int vgic_v4_load(struct kvm_vcpu *vcpu); void vgic_v4_commit(struct kvm_vcpu *vcpu); int vgic_v4_put(struct kvm_vcpu *vcpu, bool need_db); =20 +/* CPU HP callbacks */ +void kvm_vgic_cpu_up(void); +void kvm_vgic_cpu_down(void); + #endif /* __KVM_ARM_VGIC_H */ diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 411a428ace4d..4345b8eafc03 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -183,9 +183,6 @@ enum cpuhp_state { CPUHP_AP_TI_GP_TIMER_STARTING, CPUHP_AP_HYPERV_TIMER_STARTING, CPUHP_AP_KVM_STARTING, - CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, - CPUHP_AP_KVM_ARM_VGIC_STARTING, - CPUHP_AP_KVM_ARM_TIMER_STARTING, /* Must be the last timer callback */ CPUHP_AP_DUMMY_TIMER_STARTING, CPUHP_AP_ARM_XEN_STARTING, --=20 2.34.1 --=20 Without deviation from the norm, progress is not possible.