Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp240165lqg; Thu, 11 Apr 2024 00:54:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXIwwIsUdwIVZ1jiqfEjbdjhXIzxU/MOOs2Es+WO6PykN0LL5cDwpjeRYufnCMbwIjVrxU+xVjqK4B8gx1XFztremTjtdxIeehK1DKBQ== X-Google-Smtp-Source: AGHT+IE8MRT6Xh21+ZXvwSj/p44fPZZTGtULxHQTv+NyXurOZ2ljifSaDg4Q3X1l/6jemRW814v5 X-Received: by 2002:a50:951c:0:b0:56e:3f0:a163 with SMTP id u28-20020a50951c000000b0056e03f0a163mr4777312eda.14.1712822098308; Thu, 11 Apr 2024 00:54:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712822098; cv=pass; d=google.com; s=arc-20160816; b=bazrTY2OEC3ljxW10CaI/mo1TY0vq02FnkGHSiyMW2zBBJ82ZS1oHAn371mkNpmpIs hN0ieVxUkhmpRSFQD8RVB0PVbVd1/r1ihWxRbRaU3G1PMQ2tRQ1A4UUVqnq8/8OF2+qM K0WSlN2vswpAmBVw2nvSPoUHNVPsW8vkdkXy2G/94tYJZBi6JxkuQfpOiQS51J2B1L85 6mMwLksWDrxhl+/6EEffRuwPGpJ9kvjXQjIyxFOFvaP8qWi0y+L0a5I8rWTE+z37lpEu EVwKyB15oECPc6QtxVd3K2opMj5XyTD+Ou6sGAIMDeOHYqy8W++7koOn5dBFpUWb+5BP ZxFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=gYN9P/gsUxV4iSPYuxkxpCWGKEUAf0dn25ixauDgJqM=; fh=eCoSc9DxLIwU5qBKI7ZhaEZOBib+jxva/ZnkQvnIWEk=; b=oyEir/Tz27NZ/ZNgT2INqIdby0BCMpR5jRxWafIIk7hbhWW7T0zfIFjo+HAj126WVe 0lMa6z+gPhzZrk+24ObEF3kWQv6rgKXxucQE9Wsm52U/YR3IkinCSnLa1bdw+aH9TfoS 0qhF/5UmNrPAG0GQaZrE2qVE/lBDbwRM8QJccU+tFCth17PoakuhQuVOSfUU7z42yIEH ea8dlKTzN9EznpIxHAsEaOBaMwdziwshZ0YaardSuFjmZFiyB0yVX6mCRSFzqLl2Tymc vpMC4Jx4T1KPS5p4Cfz4CicSGmBJPF7uy4KhV2PLbDTpqWEygPlnMosx623ki9ur1qB2 XZxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="aeZ/v6pH"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-140033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v18-20020a50a452000000b0056e520f0fe6si483168edb.508.2024.04.11.00.54.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 00:54:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="aeZ/v6pH"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-140033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2AAD71F2588B for ; Thu, 11 Apr 2024 07:53:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5098513E884; Thu, 11 Apr 2024 07:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aeZ/v6pH" 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 5A3E913F01E; Thu, 11 Apr 2024 07:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712821996; cv=none; b=l1IpQOs6i+s1M7CT/ov5oRzziBVB1gqmjG0y5izkjjjFU4lLCtazPyDS3z/mo5D6l3dZHLJC/TEu+aQ2rRIoW3/nfdeTHfysSt28HpMH9tLgC5qu1hoLf3sXHBruahtyhgRtlHDtbtAHgurANHLNPtLD5tEVNYjqVQgn2StdfIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712821996; c=relaxed/simple; bh=6EKuB8e7IExalHGky8lWzM8XAP+mtM0/jtPeWY6Ff7w=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=KNed5ByOjGtd5YBvbp4dJfY/RgKkcDTWntQqrOKO6bkjvmvzBtEmEXRLfW+eUUXauII8mzHCt7SHlD0CETL/e6YPk7sv+aqY7blo6o+7r5SqpOk9DOHYLfwZJqJvR7nh/HaWaPB7Pbb7qXOVe9KsKR1ttq64ZBTaMD7qHj4JWxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aeZ/v6pH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6F9EC433F1; Thu, 11 Apr 2024 07:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712821995; bh=6EKuB8e7IExalHGky8lWzM8XAP+mtM0/jtPeWY6Ff7w=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aeZ/v6pH60KlfPIfvA+9/9CqjGnpSE1J5BHeGOcjxO4CPdb58eNlu7fuLSnW9YIMy suGPjs4pcEF5wYoqtEZ3ApXLLxG0UOfQpCe8nU5dGxYJUX7yc6Uq0mFH8EEc6dPgeU CgwQ0KKFuOWJD26kuD9vMJCRupdbnBPmSiOZ3m9W5clqwIVQVvjdkjiZiA/nJfOP+I rvMWv+aX8g4wrkA/9IGKZ7gesau/gW4WNY3SAN/p4Eud2JhCbd9iHX8suE+BPqvIeU xCMxLPAN99qIdbrztrsiNXpjRPXDjxQ1fwUF2otGBysSPrMHKM/0WCdBzc8xM4ePrE sE2JrrU/v6TIQ== 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 1rupFB-003OqW-CZ; Thu, 11 Apr 2024 08:53:13 +0100 Date: Thu, 11 Apr 2024 08:53:13 +0100 Message-ID: <86sezss5cm.wl-maz@kernel.org> From: Marc Zyngier To: Colton Lewis Cc: kvm@vger.kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] KVM: arm64: Add early_param to control WFx trapping In-Reply-To: <20240410175437.793508-1-coltonlewis@google.com> References: <20240410175437.793508-1-coltonlewis@google.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/29.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org 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: coltonlewis@google.com, kvm@vger.kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, 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 On Wed, 10 Apr 2024 18:54:37 +0100, Colton Lewis wrote: > > Add an early_param to control WFx (WFI or WFE) trapping. This is so > interrupts can be passed through if the CPU has support for direct > interrupt injection, a feature of GICv4. This is described as an > enumeration with three possible behaviors, always passthrough (never > trap), never passthrough (always trap), or default (trap if more than > one task is running. Default matches the current behavior. > > Signed-off-by: Colton Lewis > --- > v3: > * Changed control mechanism to an early_param on Marc's advice this should be > a system level decision and not exposed via uapi > * Reduced behavior to an enum from an integer as there are only a few options > that make logical sense > * Limit option for always passthrough to systems with GICv4 since the primary > case for always passthrough is systems with direct interrupt injection > > v2: > https://lore.kernel.org/kvmarm/20240319164341.1674863-1-coltonlewis@google.com/ > > v1: > https://lore.kernel.org/kvmarm/20240129213918.3124494-1-coltonlewis@google.com/ > > arch/arm64/include/asm/kvm_host.h | 7 +++++++ > arch/arm64/kvm/arm.c | 30 +++++++++++++++++++++++++++++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 21c57b812569..e9225b1d0e9b 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -67,6 +67,13 @@ enum kvm_mode { > KVM_MODE_NV, > KVM_MODE_NONE, > }; > + > +enum kvm_interrupt_passthrough { > + KVM_INTERRUPT_PASSTHROUGH_DEFAULT, > + KVM_INTERRUPT_PASSTHROUGH_ALWAYS, > + KVM_INTERRUPT_PASSTHROUGH_NEVER, What does this mean? This is not dealing with interrupts, this is supposed to deal with the behaviour of specific instructions (WFI/WFE). The notion of "passthrough" is really odd as well. Finally, both ALWAYS and NEVER are wrong -- the architecture makes no such guarantee. > +}; > + > #ifdef CONFIG_KVM > enum kvm_mode kvm_get_mode(void); > #else > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index a25265aca432..5d0ea6b2c652 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -46,6 +46,7 @@ > #include > > static enum kvm_mode kvm_mode = KVM_MODE_DEFAULT; > +static enum kvm_interrupt_passthrough kvm_interrupt_passthrough = KVM_INTERRUPT_PASSTHROUGH_DEFAULT; > > DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector); > > @@ -456,7 +457,10 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > if (kvm_arm_is_pvtime_enabled(&vcpu->arch)) > kvm_make_request(KVM_REQ_RECORD_STEAL, vcpu); > > - if (single_task_running()) > + if ((kvm_interrupt_passthrough == KVM_INTERRUPT_PASSTHROUGH_ALWAYS > + && kvm_vgic_global_state.has_gicv4) || > + (kvm_interrupt_passthrough == KVM_INTERRUPT_PASSTHROUGH_DEFAULT > + && single_task_running())) Why is this affecting both WFI and WFE? They are very different and lumping them together makes little sense. > vcpu_clear_wfx_traps(vcpu); > else > vcpu_set_wfx_traps(vcpu); > @@ -2654,6 +2658,30 @@ static int __init early_kvm_mode_cfg(char *arg) > } > early_param("kvm-arm.mode", early_kvm_mode_cfg); > > +static int __init early_kvm_interrupt_passthrough_cfg(char *arg) > +{ > + if (!arg) > + return -EINVAL; > + > + if (strcmp(arg, "always") == 0) { > + kvm_interrupt_passthrough = KVM_INTERRUPT_PASSTHROUGH_ALWAYS; > + return 0; > + } > + > + if (strcmp(arg, "never") == 0) { > + kvm_interrupt_passthrough = KVM_INTERRUPT_PASSTHROUGH_NEVER; > + return 0; > + } > + > + if (strcmp(arg, "default") == 0) { > + kvm_interrupt_passthrough = KVM_INTERRUPT_PASSTHROUGH_DEFAULT; > + return 0; > + } > + > + return -EINVAL; > +} > +early_param("kvm-arm.interrupt-passthrough", early_kvm_interrupt_passthrough_cfg); > + Again, this is not dealing with interrupts. This is dealing with the *potential* trapping of instructions in certain circumstances. > enum kvm_mode kvm_get_mode(void) > { > return kvm_mode; Finally, this needs to be documented. Thanks, M. -- Without deviation from the norm, progress is not possible.