diff mbox series

[v5] KVM: arm64: Ignore kvm-arm.mode if !is_hyp_mode_available()

Message ID 20220920190658.2880184-1-quic_eberman@quicinc.com (mailing list archive)
State New, archived
Headers show
Series [v5] KVM: arm64: Ignore kvm-arm.mode if !is_hyp_mode_available() | expand

Commit Message

Elliot Berman Sept. 20, 2022, 7:06 p.m. UTC
Ignore kvm-arm.mode if !is_hyp_mode_available(). Specifically, we want
to avoid switching kvm_mode to KVM_MODE_PROTECTED if hypervisor mode is
not available. This prevents "Protected KVM" cpu capability being
reported when Linux is booting in EL1 and would not have KVM enabled.
Reasonably though, we should warn if the command line is requesting a
KVM mode at all if KVM isn't actually available. Allow
"kvm-arm.mode=none" to skip the warning since this would disable KVM
anyway.

Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
---
 arch/arm64/kvm/arm.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)


base-commit: 0982c8d859f8f7022b9fd44d421c7ec721bb41f9

Comments

Marc Zyngier Sept. 26, 2022, 9:59 a.m. UTC | #1
On Tue, 20 Sep 2022 12:06:58 -0700, Elliot Berman wrote:
> Ignore kvm-arm.mode if !is_hyp_mode_available(). Specifically, we want
> to avoid switching kvm_mode to KVM_MODE_PROTECTED if hypervisor mode is
> not available. This prevents "Protected KVM" cpu capability being
> reported when Linux is booting in EL1 and would not have KVM enabled.
> Reasonably though, we should warn if the command line is requesting a
> KVM mode at all if KVM isn't actually available. Allow
> "kvm-arm.mode=none" to skip the warning since this would disable KVM
> anyway.

Applied to next, thanks!

[1/1] KVM: arm64: Ignore kvm-arm.mode if !is_hyp_mode_available()
      commit: b2a4d007c347b4cb4c60f7512733c3f8300a129c

Cheers,

	M.
diff mbox series

Patch

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 8fe73ee5fa84..34cd0570e433 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -2271,6 +2271,16 @@  static int __init early_kvm_mode_cfg(char *arg)
 	if (!arg)
 		return -EINVAL;
 
+	if (strcmp(arg, "none") == 0) {
+		kvm_mode = KVM_MODE_NONE;
+		return 0;
+	}
+
+	if (!is_hyp_mode_available()) {
+		pr_warn_once("KVM is not available. Ignoring kvm-arm.mode\n");
+		return 0;
+	}
+
 	if (strcmp(arg, "protected") == 0) {
 		if (!is_kernel_in_hyp_mode())
 			kvm_mode = KVM_MODE_PROTECTED;
@@ -2285,11 +2295,6 @@  static int __init early_kvm_mode_cfg(char *arg)
 		return 0;
 	}
 
-	if (strcmp(arg, "none") == 0) {
-		kvm_mode = KVM_MODE_NONE;
-		return 0;
-	}
-
 	return -EINVAL;
 }
 early_param("kvm-arm.mode", early_kvm_mode_cfg);