Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp305489lqj; Wed, 10 Apr 2024 10:55:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTVYrfwOyC1V6jfvRZDFgPXiTzFdo6uBFa9cNHRgESqQgxbtphwaV2Hq9wA3pF4a6/UqWGaAe8sVldD7mo2ONUEmtU63PuQuVM9Ie2+w== X-Google-Smtp-Source: AGHT+IG5mNzGzq5/DU/DwEmm6y2a8Cl+2arKc0CxxLyNuneIYire/lqPNbMj+dfwX1oMnLNFSicr X-Received: by 2002:a05:620a:4151:b0:78d:77f6:8e7c with SMTP id k17-20020a05620a415100b0078d77f68e7cmr3685186qko.7.1712771729741; Wed, 10 Apr 2024 10:55:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712771729; cv=pass; d=google.com; s=arc-20160816; b=kqD/M09yD5vtyq1nG+aKYZ5K++E9+ab2Acng/T0ZJHTbdGKri3NXCaymxcqhTNb86S qYuh71AYresv1T/231pC2uSfIE125GH4I/du3fjzQWyR3IfDSbiOvN6U6EiDcMzjjYZR WsXN0ikvOgI7MnrJ8bWcjMwkrsS6Iahqd5Krg+JGn271y2bW3ufzkhrhb2yz1pnp1lS9 iOOV23+zKKuSW0RnXlmZFjgK2x1XRSEtkzaF/HGmVvaYiMIXjKoiJYenlFxubaPlAfwD ju60Q//2z7EWpIKOIk7tgt0i12k7RnZfCNlUiaFJ3OgC4MGILVXUUgx9nBrThwQAx1Lw 0uLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=oTRds48YQAuzki9smTU0zbOfJX16SMcTfKd42zPqGTw=; fh=ZggDVxEMc2MLi5ZmQN4Av5DHk0fa6j10rfKVa7dt1ME=; b=cLM9TevTJ7HEV1SLaMNag5xrHy0XJYixGorsdYonCpVtc4AQi6N5TS5SW3xx+jJ/mR ldfe8G9nhJkR7cx5c2xTOuJcxgOsWNWRiR3BrEmPqUFrVfLYA1IoEJLSQpvm1zd5yVOA O38WxdrK7Cw2AHbXoIzn9pVDxliMMCZbz7zZLV4tB4o6r23OhGnJT7qlOkmORZLdyaJo hPrWZkxj+F16S9n+qZB75cjgyol9gK3fg8LLFUJkCAVJ9LIANgigF6dG0fzOKrwbaw4p hbAp6n5KkJibR8nalRgArcpBDkbguCbYavHgRRfFQf9Zus+duuSzL5ExhGM8cMtLe7Hu 124Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="NjN/qLo+"; arc=pass (i=1 spf=pass spfdomain=flex--coltonlewis.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-139155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139155-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id xz9-20020a05620a5e0900b0078d6b4b06e7si5032869qkn.64.2024.04.10.10.55.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 10:55:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="NjN/qLo+"; arc=pass (i=1 spf=pass spfdomain=flex--coltonlewis.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-139155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139155-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 68D521C22A86 for ; Wed, 10 Apr 2024 17:55:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD9CE17F39C; Wed, 10 Apr 2024 17:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NjN/qLo+" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A5F817F37B for ; Wed, 10 Apr 2024 17:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712771720; cv=none; b=s7spg0S+UW9Crt/IOG4HZ2EBhegMOi5CZBjGqS4KyRRj1/q8T/I7a8L5HI4hx/V+/R7XJIQrWoZftzS79+ZpCop4muYFZAZtqkbjKJs0ESOUFRSt3SgNZpWhk0ZARFkXHHvMuTVgNXGcnOOnJBugIs+1w6RbAPUB5J1UxRhJYAQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712771720; c=relaxed/simple; bh=c5vOu3wln/bzFkI50zK54TLDDdF576q5OSt+R4RYCW0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=hZP3OR8efw1YV1tVuV+el/9YIqo9OV+vbXcDY7xvSK7HlUzG9qgyTzb9py/wtHpAHjsrPLmUsMclRP0Gd18wsg7ieyzXTwYS5dx+4vgwYFrq+Gyu+g8uXU2xorDa9vUFD38joAI/x3j54zZjoIrgg/6EiZ4ibnkYpEguAS8Rjbs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NjN/qLo+; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60ab69a9e6fso1224377b3.0 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=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=oTRds48YQAuzki9smTU0zbOfJX16SMcTfKd42zPqGTw=; b=NjN/qLo+8P4Ap71VpMAba/PrNVkDASi5njcnBqX0uUTk3wi1eVRMkoCmBsqzwaUb0M hlD+OdgY5qbavZHavTXev59BojFGj0Oz1Myv7wEOGykrx6Qu8YekKG11yNiLsPiOJFOX SjQ0wJhfb5vblmXhXN159ObhMthOTHRPkQJqFd00G6Z0RgLxOfmjyj+5yguRJ3su1cYf fFZeMx8ZcLrZ9O35KLZKnUJUZM0PFWQrafA7OAp3u+IepSTcg6/oI/4H4kYeNlqEmZPG jq5WVf1CQvYXGeRN8bWmSIXr4Iu08Q9bZUmmE2PCKSF9TBJ0p+btW6Nmlts02+uqqRKV EJAw== 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=gXg240ZI7n9EvfUWQIn6pOdPTSxP0HKYT1qaIDEWt3ini8/msyYEJIL0C5HUnjPsst OAeFTRlEkqw5rhzZoq4kYsBvxUjB/QN1bsUKPWtESWe0pcUNxwjJpAJepXHMfjByWabR sUmFrebvgt2MxlkXZZhvGwaIhQG6YLxcCU8Lu6n3Y7qv9NuAHyuJGwyv79AYVLzu5aIJ Z0N7e0K3ck7Wa5trgXk/iO7tlprky56ZyqR3eaZiPKeurH/a3UXHPxJQtonqAZAUeoE/ ZwE4MqZbGMx3l161SB/SrcB/7qnyV43/XmpBbCq3/Q7kw8AJKqSkIFLVE87/X6uewta+ YTBg== X-Forwarded-Encrypted: i=1; AJvYcCUdozR84LR5Og2947eRcdyniPLOr0KsE2i2Gdbr0aKPOA1k/O/lZtlRryB3kZfDdnsD8BSO55khRGU6ufldlkp7anWMm+Ed4rRelBFX X-Gm-Message-State: AOJu0YwQrlRCwWoMjD+u1rS9B9sNue//77zEy65lMqcJ6wmD0pQQWMfM H8Uza2+P2MkMDQXn46Vgg8+dJBwhum7MBWkGX8//h6DxdrlpMP3cT39gs6g/TTy15ekBI1YPwTW VYN2T8cuyehHQuMfxdQqBEA== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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, +}; + #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; -- 2.44.0.478.gd926399ef9-goog