Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8705297rwp; Wed, 19 Jul 2023 14:06:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlG1bISrCNLWozqb9g6OJBQw/qAxjknmyVLTdlrLxpNKieufbVzFM0Myqt509n1wbgFTpoMC X-Received: by 2002:a17:906:1ce:b0:993:d955:1280 with SMTP id 14-20020a17090601ce00b00993d9551280mr3064247ejj.12.1689800807173; Wed, 19 Jul 2023 14:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689800807; cv=none; d=google.com; s=arc-20160816; b=g68Qjm804c4vy+tf9YB/aYHwMLlLrGD2OU/tFq/oRJCQlesUJYEvTb6Pegky5DUgWV wIPjioP0vg3Z8DsgA8VsJ1HB6jQNWKuU1DXDa1JEMjHnTDyOd4443PpK4+Wx5UZ12V+z Qcrk/zie1QaBMhaqTWNXpxio4JY39t73+1iSTcTNC5v6yaI5kq+PgONJs4vrBwSLboo6 0UOzgJWvonJVBoMgR7QMSLJTwhzrRLeeWs33iUxVPHFJ/FnIMhO/caLiMMT8C+LUhG2g NucnOHWyl5TgA9h10DD/DGFxOBAXTKNBR8G7byUsZ/ROu493b3EmbQzydLDKQaMXmRTP sLCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=ABmm8ziz9w11JK63dBDo/JptwWWVO+Y+GrOZN7APQNo=; fh=TrZWSTw6yUdTzq8oRO5WEGmf8JqjMwoBubAR3izkH0M=; b=JDfTdrbRybUF8916ekbDSlBePGarWVDQj20td0KAHWhCJzjYgdgViT65DLL5aJ8zu3 ey7tzKo0wg4SOq6fcsFpa6AzwMMoodZRD7GNolS+MK1Wf4qBP1GqIzf+ec8GIQDKytOi UAUvVlE4c1zy2bC8BP7V4ipR9mIV2FAvXZRauWGOo9pWOVYTsuq+8YeIcuRCCRGIKbx1 EbknpmxoI2pTp8ZYop5JAyDQ1RgcgcJ5umMUfP8uYodrDfhtYIY0pgmyk7fPUDBzSvNo 5Ty48/Gpmm066+jXkcer/ynAndSiq3cfgsQibrf/khAOjsSTy6Vy6u381zqtD5jDWRYy qj6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QbYLN3Ks; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a170906d20700b00987ffac6129si3381855ejz.930.2023.07.19.14.06.17; Wed, 19 Jul 2023 14:06:47 -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=@linux.dev header.s=key1 header.b=QbYLN3Ks; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbjGSUsW (ORCPT + 99 others); Wed, 19 Jul 2023 16:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjGSUsV (ORCPT ); Wed, 19 Jul 2023 16:48:21 -0400 Received: from out-6.mta1.migadu.com (out-6.mta1.migadu.com [IPv6:2001:41d0:203:375::6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E2F91FC0 for ; Wed, 19 Jul 2023 13:48:19 -0700 (PDT) Date: Wed, 19 Jul 2023 20:48:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689799697; 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=ABmm8ziz9w11JK63dBDo/JptwWWVO+Y+GrOZN7APQNo=; b=QbYLN3KsKY0UMpUE5N0eq/DOFDyLXqbm3K+hyONSSXH3wZQHs8MT77tS5XJr3QJq+IP5pb Z8SO/+JsRWBto74/wxwKIzmZoubj4AVb3sXX621eRLSyhaY4s1H7YaOlFv8SE9oVCYuxed J7dOGvyYBSQgQoUZOa6NV5OgRwc0sF4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta 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 Subject: Re: [PATCH] KVM: arm64: Fix CPUHP logic for protected KVM Message-ID: References: <20230719175400.647154-1-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230719175400.647154-1-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 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(). 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. > 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 *discard) > > int kvm_arch_hardware_enable(void) > { > - int was_enabled = __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 *discard) > > 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