From patchwork Wed Apr 10 17:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13624952 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5989BCD128A for ; Wed, 10 Apr 2024 17:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=6iWpBQGZxS8W6GShVGUJ3MnEj2sAJTdWbbXY2TUj2Ys=; b=s0J xZc6e6BFLI1lm602YtFe8nQ+T/s28oNKo3BvX66kla6lZuLlc9lVJWeCvOUYBG1nWIY3OARs1uJHZ g1Tbu8E+4gNCQ+HLakMLirGE8NMZQICckJUvPGG6u3dGCBI3GszbN0hi1MCAwX9vICwnPvI8SX+PW UAQoPJIpPpgpj+1WWkvnGmmRnHPGFQccQ+GiJmSIXHWK9duSiieR1RRyHIJQnUZUfs9LAGfEvv2jM 7qgc7wCjTOQtM4spyRYujHHajEgW5KZ9rBfpziZKTaX6HWGn1IZ0H13HLPNQiTM9eD8RTr1srvYyb ryEf8Wq9N3xPPK7PjiUx/ZpxjdlpYTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rucAO-00000008N7Y-0RLF; Wed, 10 Apr 2024 17:55:24 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rucAK-00000008N6G-1L0e for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 17:55:22 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-61561dbdf14so1076627b3.1 for ; Wed, 10 Apr 2024 10:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712771718; x=1713376518; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=oTRds48YQAuzki9smTU0zbOfJX16SMcTfKd42zPqGTw=; b=0fP7ya8+hIXU7A5mCZc3rAUB/ujuuOy85UHWd/7buND9gSGRrgvaUAREnwdw72Ap5B 34FtMPDLTcAKpmXkkiwXdk9FzdvyzeA25E2j6fwBiUcbAKVTo1nXt2vj/ml1cg3xgRUq 4C8EdGdiPbbnmC3atI4b2nzurXg5x7aFtEJr32Bqhve2FTCPymkOQG9QDSbdIINJU251 fvZfNLLnV0yuITU7QykrrN2qAAv6QyzuVhRT/JPaqUoRfXQq67+pl6r8h401xycpfQaG ULHC+dwR4rX5yWxDhLDc2e91zDGMvDvo53YX88T7YX/kx2R0B2MZjFoPv9HyM91Sm7C5 I5lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712771718; x=1713376518; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oTRds48YQAuzki9smTU0zbOfJX16SMcTfKd42zPqGTw=; b=r4cUZujLaEpgoNeRxW5hOF99fyJYTX3Hs5q/8l2rlvvLfrS75hHZhEq9BZbtWbDeSj YKUGyJaQ0Sgs2GSvf4Ie6lJ+xdNZ5LncJGH0OjGeMSRpxDm5iHZZA834+gj3NXtHvDRz P/c6IhnuKHoz+m5s3b/zB/mrD6Uu+jYVKBi2qG78eJFNLEw4snk3WQLlthGV+MUidoWF 2P6P5JPZwHR+IHB2EnDTCSZZT2PL7ey/o66T4vmIc8smGTlbBNF856sL7FRbumYIKxhA coDevRBG3CKvHZYN+rsdmbxwvjcxE9CSSNW+eMibTbo/O/7b4be4ZkrG9hyQNTNl3gu8 aCUQ== X-Forwarded-Encrypted: i=1; AJvYcCXtj4/N6FAsruWQ1V3WXdQQvB6OYOurmUqMqHfr8Vi2QoxEaJwKTh6lYVqODprppmkfIhIPk4bnPsRk4vZatfSgnSR+alHa36obAFEq+OeUhQoUPV0= X-Gm-Message-State: AOJu0Yyizz/rmOeHvI3ee6wrkqB5DuFTxb3P7t129WiXjAXBGwPvDDeJ ZN6qQntQMJSuXyJ/4XxbAfrHn7GuDg8CYJDoAKBmBSJgx3MW5+Te/4kvS/LbUOT6bKaJDSujp4y cOmF5Hk7LEpNtnx2IesHKrQ== X-Google-Smtp-Source: AGHT+IFGk/yictiXP/bmh1HJDKurTfI9OfoF/LDokYTgZALVerLy33LdKx5oD0s+3wIFHKHy3OTGRtA6WddrXew0Eg== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:14ce]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:1148:b0:dd9:20c1:85b6 with SMTP id p8-20020a056902114800b00dd920c185b6mr109753ybu.2.1712771718281; Wed, 10 Apr 2024 10:55:18 -0700 (PDT) Date: Wed, 10 Apr 2024 17:54:37 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240410175437.793508-1-coltonlewis@google.com> Subject: [PATCH v3] KVM: arm64: Add early_param to control WFx trapping From: Colton Lewis To: kvm@vger.kernel.org Cc: Marc Zyngier , 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, Colton Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_105520_588793_E40E5974 X-CRM114-Status: GOOD ( 16.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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(-) -- 2.44.0.478.gd926399ef9-goog 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, +}; + #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())) 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); + enum kvm_mode kvm_get_mode(void) { return kvm_mode;