[PATCH v2 13/19] KVM: Do processor compatibility check on cpu online and resume

isaku.yamahata
2022-08-30T12:03:08Z

So far the processor compatibility check is not done for newly added CPU.
It should be done. For online cpu case, the function is called by kernel
thread bind to the cpu without irq disabled. So remove
WARN_ON(!irq_disabled()).

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
arch/x86/kvm/x86.c | 2 --
virt/kvm/kvm_arch.c | 15 +++++++++++++--
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0b112cd7de58..ac185e199f69 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12003,8 +12003,6 @@ int kvm_arch_check_processor_compat(void)
{
struct cpuinfo_x86 *c = &cpu_data(smp_processor_id());

- WARN_ON(!irqs_disabled());
-
if (__cr4_reserved_bits(cpu_has, c) !=
__cr4_reserved_bits(cpu_has, &boot_cpu_data))
return -EIO;
diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c
index 3990f85edab3..e440d4a99c8a 100644
--- a/virt/kvm/kvm_arch.c
+++ b/virt/kvm/kvm_arch.c
@@ -99,6 +99,12 @@ __weak int kvm_arch_del_vm(int usage_count)

__weak int kvm_arch_online_cpu(unsigned int cpu, int usage_count)
{
+ int r;
+
+ r = kvm_arch_check_processor_compat();
+ if (r)
+ return r;
+
if (usage_count) {
/*
* Abort the CPU online process if hardware virtualization cannot
@@ -132,6 +138,11 @@ __weak int kvm_arch_suspend(int usage_count)

__weak void kvm_arch_resume(int usage_count)
{
- if (usage_count)
- (void)__hardware_enable();
+ if (kvm_arch_check_processor_compat())
+ return; /* FIXME: disable KVM */
+
+ if (!usage_count)
+ return;
+
+ (void)__hardware_enable();
}
--
2.25.1