All of lore.kernel.org
 help / color / mirror / Atom feed
From: Colton Lewis <coltonlewis@google.com>
To: kvm@vger.kernel.org
Cc: Marc Zyngier <maz@kernel.org>,
	Oliver Upton <oliver.upton@linux.dev>,
	 James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	 Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	 Will Deacon <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org,  kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	 Colton Lewis <coltonlewis@google.com>
Subject: [PATCH v3] KVM: arm64: Add early_param to control WFx trapping
Date: Wed, 10 Apr 2024 17:54:37 +0000	[thread overview]
Message-ID: <20240410175437.793508-1-coltonlewis@google.com> (raw)

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 <coltonlewis@google.com>
---
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 <kvm/arm_psci.h>

 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

WARNING: multiple messages have this Message-ID (diff)
From: Colton Lewis <coltonlewis@google.com>
To: kvm@vger.kernel.org
Cc: Marc Zyngier <maz@kernel.org>,
	Oliver Upton <oliver.upton@linux.dev>,
	 James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	 Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	 Will Deacon <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org,  kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	 Colton Lewis <coltonlewis@google.com>
Subject: [PATCH v3] KVM: arm64: Add early_param to control WFx trapping
Date: Wed, 10 Apr 2024 17:54:37 +0000	[thread overview]
Message-ID: <20240410175437.793508-1-coltonlewis@google.com> (raw)

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 <coltonlewis@google.com>
---
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 <kvm/arm_psci.h>

 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2024-04-10 17:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 17:54 Colton Lewis [this message]
2024-04-10 17:54 ` [PATCH v3] KVM: arm64: Add early_param to control WFx trapping Colton Lewis
2024-04-11  7:53 ` Marc Zyngier
2024-04-11  7:53   ` Marc Zyngier
2024-04-15 19:40   ` Colton Lewis
2024-04-15 19:40     ` Colton Lewis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240410175437.793508-1-coltonlewis@google.com \
    --to=coltonlewis@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.