Skip to content

Commit b6a68b9

Browse files
author
Marc Zyngier
committed
KVM: arm64: Allow KVM to be disabled from the command line
Although KVM can be compiled out of the kernel, it cannot be disabled at runtime. Allow this possibility by introducing a new mode that will prevent KVM from initialising. This is useful in the (limited) circumstances where you don't want KVM to be available (what is wrong with you?), or when you want to install another hypervisor instead (good luck with that). Reviewed-by: David Brazdil <[email protected]> Acked-by: Will Deacon <[email protected]> Acked-by: Suzuki K Poulose <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Andrew Scull <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9e1ff30 commit b6a68b9

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,6 +2365,8 @@
23652365
kvm-arm.mode=
23662366
[KVM,ARM] Select one of KVM/arm64's modes of operation.
23672367

2368+
none: Forcefully disable KVM.
2369+
23682370
nvhe: Standard nVHE-based mode, without support for
23692371
protected guests.
23702372

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
enum kvm_mode {
5959
KVM_MODE_DEFAULT,
6060
KVM_MODE_PROTECTED,
61+
KVM_MODE_NONE,
6162
};
6263
enum kvm_mode kvm_get_mode(void);
6364

arch/arm64/kvm/arm.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,11 @@ int kvm_arch_init(void *opaque)
20642064
return -ENODEV;
20652065
}
20662066

2067+
if (kvm_get_mode() == KVM_MODE_NONE) {
2068+
kvm_info("KVM disabled from command line\n");
2069+
return -ENODEV;
2070+
}
2071+
20672072
in_hyp_mode = is_kernel_in_hyp_mode();
20682073

20692074
if (cpus_have_final_cap(ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) ||
@@ -2137,8 +2142,15 @@ static int __init early_kvm_mode_cfg(char *arg)
21372142
return 0;
21382143
}
21392144

2140-
if (strcmp(arg, "nvhe") == 0 && !WARN_ON(is_kernel_in_hyp_mode()))
2145+
if (strcmp(arg, "nvhe") == 0 && !WARN_ON(is_kernel_in_hyp_mode())) {
2146+
kvm_mode = KVM_MODE_DEFAULT;
21412147
return 0;
2148+
}
2149+
2150+
if (strcmp(arg, "none") == 0) {
2151+
kvm_mode = KVM_MODE_NONE;
2152+
return 0;
2153+
}
21422154

21432155
return -EINVAL;
21442156
}

0 commit comments

Comments
 (0)