Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8733601rwp; Wed, 19 Jul 2023 14:37:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlHCGA8H4pgu2UCQg+142p+Ao0FskhqJg4XcjyFdC3qe1i8qdRSe4J8a1l0JEmcab165Gp1E X-Received: by 2002:a17:902:d4c2:b0:1b8:9b1b:ae8e with SMTP id o2-20020a170902d4c200b001b89b1bae8emr285126plg.59.1689802651484; Wed, 19 Jul 2023 14:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689802651; cv=none; d=google.com; s=arc-20160816; b=ilUmAHaTeNYMVOfeq88h1RKklbz5ReSF6jU4MHpejcgk5zPVo/rmTtYYBvmOWYI/l+ nWIpoBVJ0B4WWmoDaQL1bH45AJcvTVcOy9ddg0sTvgdgO648xNv27yJt98u+jkwGw7vJ 2raj6UeU9beKXmteOblim3JFmSx0g4QAJEgNuoWDaH7uE6l9cKTKH5bL/K+BRMba865h MjuI/vlbfjG362F7sirn6/oCQIjN3Zj3JRgql4l7QgRuEG9piAvKUra4Y+EsjglzQdZ2 1n06BaGTNg1uWPjQ5Xbh9/S4zNDTa/akWIMVuwUXfUEYMnowdy8bCIh2AME7k2laCrUy rQcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=eBJj2LL0pM4tkw5oGrSPDiIzepbTgsFXALya9co7OzU=; fh=scvjTd8pHjUZeq6u9rXMhNdpwoKnxAk/CCXSgvUUogo=; b=rNcZ5sQfHenqbV5Yx+iH8rLLhk16aP5RA3dYtyot5V8si7jpL2+gzXcOke9SzXsqba mDmiRaXUL1ZsXIsyxLFmAfj+W7hv9cbhr02ni8LiL3GwfUN578nusQvwL/fzN0h/jeSU udeWqWc+qKx6ZDelZOw482C+wdo4/K3VBWLkjN/V2oT9FhQM9L1LpZOGI+5hVC9FISoa DfinWCr8HfK2GbibcTu3ZkJQhWwNOUygwOWSrP9c1cfSEa2YuSiSppy3n+4RbuuJZRCn vbUN/HOCsihL2CnaYC9FXzBVREFkA2tnMhimiuCAEVb0cOhiCVruBUGxPhXlxOHB7g4b WFiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=W6OMSkAA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ks5-20020a170903084500b001bb2c70affbsi4038759plb.296.2023.07.19.14.37.18; Wed, 19 Jul 2023 14:37:31 -0700 (PDT) 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=@google.com header.s=20221208 header.b=W6OMSkAA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229867AbjGSVQ4 (ORCPT + 99 others); Wed, 19 Jul 2023 17:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbjGSVQy (ORCPT ); Wed, 19 Jul 2023 17:16:54 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21EED210C for ; Wed, 19 Jul 2023 14:16:50 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b52875b8d9so58415ad.0 for ; Wed, 19 Jul 2023 14:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689801409; x=1690406209; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eBJj2LL0pM4tkw5oGrSPDiIzepbTgsFXALya9co7OzU=; b=W6OMSkAAUHEcMC412H0lAQ3j8Wn4AhrIEwRhYSYVuxLpiOCbfR46pbNCWs36E7yHLb 5UVJGnc9+6mX2OpE3q8S7+xNH/IYoxOT3PaeBp2xWoDyDyHIWrgVLSHjNxHaYkQ8jDkf WYEqlXjA2c78z7kIxII3WCpUyAVyV2/xBxEaRCRfsPXZspG8XQxzK/5o7xgrYLIioUtf uyEhVJ/lHOfIF8jZhsA0KmLH8s/73qzjxi9GhT/D50ZC7gj2d0NhTQ03OxaNEAktJFV8 iiFOOvx1G48+CpG1qT2hcgz3UpXZkAg0ijbJYKqPmM7ULVc0VY4YyhKq2sxJ/29vjUOR wUvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689801409; x=1690406209; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eBJj2LL0pM4tkw5oGrSPDiIzepbTgsFXALya9co7OzU=; b=lZ/cu/qwDRUrhYoR7kd5tkl8o2QjmOkKORgcs7k4za6zAnrQb3+vLgYXwFNtCElBAZ KHUptPR6QHHr+UXX5Bm+uQxIavFA2ouzC/lCV1El5w4twDAdFWulkxqQ4BeTC6U0HmJM u0s/Q7jeqHbqwbu/bL0XZskCmYSgAymA+XMZpkOqHiucj4d4wKDzmvNU2k5YqxKSUxfC rvtT6MUzUQj1D5to4YCbVzFlI1VtXP3oBbDh6W40exZteWBwoWGqGzHK2v9YZLhZJeCG 5CzgbFgrqMOFjrhOpEvCv9yyPAsXpgwcPGrmNHegbezOdXk6RfbYp6mvlDjJAOQUFEkE rg3Q== X-Gm-Message-State: ABy/qLZ00fgil2yk9gze4luEaH4DWjUpVKNC5KhOOnXj0BIVLqUnoDtq wNDG4qbZdROkvOwqbNM2225YnzPbKqDHIFUaQqg4WA== X-Received: by 2002:a17:902:f9cf:b0:1b8:89fd:61ea with SMTP id kz15-20020a170902f9cf00b001b889fd61eamr21553plb.1.1689801408973; Wed, 19 Jul 2023 14:16:48 -0700 (PDT) MIME-Version: 1.0 References: <20230719175400.647154-1-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Wed, 19 Jul 2023 14:16:36 -0700 Message-ID: Subject: Re: [PATCH] KVM: arm64: Fix CPUHP logic for protected KVM To: Oliver Upton Cc: Marc Zyngier , James Morse , Suzuki K Poulose , Will Deacon , Fuad Tabba , Jing Zhang , Colton Lewis , Reiji Watanabe , kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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, Jul 19, 2023 at 1:48=E2=80=AFPM Oliver Upton wrote: > > On Wed, Jul 19, 2023 at 05:54:00PM +0000, Raghavendra Rao Ananta wrote: > > For protected kvm, the CPU hotplug 'down' logic currently brings > > down the timer and vGIC, essentially disabling interrupts. However, > > because of how the 'kvm_arm_hardware_enabled' flag is designed, it > > never re-enables them back on the CPU hotplug 'up' path. Hence, > > clean up the logic to maintain the CPU hotplug up/down symmetry. > > Correct me if I am wrong, but this issue exists outside of cpu hotplug, > right? init_subsystems() calls _kvm_arch_hardware_enable() on all cores, > which only sets up the hyp cpu context and not the percpu interrupts. > Similar issue exists for the cpu that calls do_pkvm_init(). > Ah, perhaps I looked at the from a different perspective, but this makes sense too. > I'll also note kvm_arm_hardware_enabled is deceptively vague, as it only > keeps track of whether or not the hyp cpu context has been initialized. > May send a cleanup here in a bit. > > Perhaps this for the changelog: > > KVM: arm64: Fix hardware enable/disable flows for pKVM > > When running in protected mode, the hyp stub is disabled after pKVM is > initialized, meaning the host cannot enable/disable the hyp at > runtime. As such, kvm_arm_hardware_enabled is always 1 after > initialization, and kvm_arch_hardware_enable() never enables the vgic > maintenance irq or timer irqs. > > Unconditionally enable/disable the vgic + timer irqs in the respective > calls, instead relying on the percpu bookkeeping in the generic code > to keep track of which cpus have the interrupts unmasked. > Sure, we can use this for v2. Thanks, Raghavendra > > Fixes: 466d27e48d7c ("KVM: arm64: Simplify the CPUHP logic") > > Reported-by: Oliver Upton > > Suggested-by: Oliver Upton > > Signed-off-by: Raghavendra Rao Ananta > > --- > > arch/arm64/kvm/arm.c | 14 ++++---------- > > 1 file changed, 4 insertions(+), 10 deletions(-) > > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > index c2c14059f6a8..010ebfa69650 100644 > > --- a/arch/arm64/kvm/arm.c > > +++ b/arch/arm64/kvm/arm.c > > @@ -1867,14 +1867,10 @@ static void _kvm_arch_hardware_enable(void *dis= card) > > > > int kvm_arch_hardware_enable(void) > > { > > - int was_enabled =3D __this_cpu_read(kvm_arm_hardware_enabled); > > - > > _kvm_arch_hardware_enable(NULL); > > > > - if (!was_enabled) { > > - kvm_vgic_cpu_up(); > > - kvm_timer_cpu_up(); > > - } > > + kvm_vgic_cpu_up(); > > + kvm_timer_cpu_up(); > > > > return 0; > > } > > @@ -1889,10 +1885,8 @@ static void _kvm_arch_hardware_disable(void *dis= card) > > > > void kvm_arch_hardware_disable(void) > > { > > - if (__this_cpu_read(kvm_arm_hardware_enabled)) { > > - kvm_timer_cpu_down(); > > - kvm_vgic_cpu_down(); > > - } > > + kvm_timer_cpu_down(); > > + kvm_vgic_cpu_down(); > > > > if (!is_protected_kvm_enabled()) > > _kvm_arch_hardware_disable(NULL); > > -- > > 2.41.0.487.g6d72f3e995-goog > > > > -- > Thanks, > Oliver