[RFC PATCH 12/18] KVM: Do processor compatibility check on cpu online and resume

isaku.yamahata@intel.com posted 18 patches 3 years, 7 months ago
There is a newer version of this series
[RFC PATCH 12/18] KVM: Do processor compatibility check on cpu online and resume
Posted by isaku.yamahata@intel.com 3 years, 7 months ago
From: Isaku Yamahata <isaku.yamahata@intel.com>

So far the processor compatibility check is not done for newly added CPU.
It should be done.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
 virt/kvm/kvm_arch.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c
index 2ed8de0591c9..20971f43df95 100644
--- a/virt/kvm/kvm_arch.c
+++ b/virt/kvm/kvm_arch.c
@@ -99,9 +99,15 @@ __weak int kvm_arch_del_vm(int usage_count)
 
 __weak int kvm_arch_online_cpu(unsigned int cpu, int usage_count)
 {
-	if (usage_count)
-		return __hardware_enable();
-	return 0;
+	int r;
+
+	if (!usage_count)
+		return 0;
+
+	r = kvm_arch_check_processor_compat();
+	if (r)
+		return r;
+	return __hardware_enable();
 }
 
 __weak int kvm_arch_offline_cpu(unsigned int cpu, int usage_count)
@@ -126,6 +132,10 @@ __weak int kvm_arch_suspend(int usage_count)
 
 __weak void kvm_arch_resume(int usage_count)
 {
-	if (usage_count)
-		(void)__hardware_enable();
+	if (!usage_count)
+		return;
+
+	if (kvm_arch_check_processor_compat())
+		return; /* FIXME: disable KVM */
+	(void)__hardware_enable();
 }
-- 
2.25.1
Re: [RFC PATCH 12/18] KVM: Do processor compatibility check on cpu online and resume
Posted by Chao Gao 3 years, 7 months ago
On Fri, Aug 19, 2022 at 11:00:18PM -0700, isaku.yamahata@intel.com wrote:
>From: Isaku Yamahata <isaku.yamahata@intel.com>
>
>So far the processor compatibility check is not done for newly added CPU.
>It should be done.
>
>Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
>---
> virt/kvm/kvm_arch.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
>diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c
>index 2ed8de0591c9..20971f43df95 100644
>--- a/virt/kvm/kvm_arch.c
>+++ b/virt/kvm/kvm_arch.c
>@@ -99,9 +99,15 @@ __weak int kvm_arch_del_vm(int usage_count)
> 
> __weak int kvm_arch_online_cpu(unsigned int cpu, int usage_count)
> {
>-	if (usage_count)
>-		return __hardware_enable();
>-	return 0;
>+	int r;
>+
>+	if (!usage_count)
>+		return 0;
>+
>+	r = kvm_arch_check_processor_compat();
>+	if (r)
>+		return r;

I think kvm_arch_check_processor_compat() should be called even when
usage_count is 0. Otherwise, compatibility checks may be missing on some
CPUs if no VM is running when those CPUs becomes online.

>+	return __hardware_enable();
> }
> 
> __weak int kvm_arch_offline_cpu(unsigned int cpu, int usage_count)
>@@ -126,6 +132,10 @@ __weak int kvm_arch_suspend(int usage_count)
> 
> __weak void kvm_arch_resume(int usage_count)
> {
>-	if (usage_count)
>-		(void)__hardware_enable();
>+	if (!usage_count)
>+		return;
>+
>+	if (kvm_arch_check_processor_compat())
>+		return; /* FIXME: disable KVM */

Ditto.

>+	(void)__hardware_enable();
> }
>-- 
>2.25.1
>
Re: [RFC PATCH 12/18] KVM: Do processor compatibility check on cpu online and resume
Posted by Isaku Yamahata 3 years, 7 months ago
On Tue, Aug 23, 2022 at 03:50:09PM +0800,
Chao Gao <chao.gao@intel.com> wrote:

> >diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c
> >index 2ed8de0591c9..20971f43df95 100644
> >--- a/virt/kvm/kvm_arch.c
> >+++ b/virt/kvm/kvm_arch.c
> >@@ -99,9 +99,15 @@ __weak int kvm_arch_del_vm(int usage_count)
> > 
> > __weak int kvm_arch_online_cpu(unsigned int cpu, int usage_count)
> > {
> >-	if (usage_count)
> >-		return __hardware_enable();
> >-	return 0;
> >+	int r;
> >+
> >+	if (!usage_count)
> >+		return 0;
> >+
> >+	r = kvm_arch_check_processor_compat();
> >+	if (r)
> >+		return r;
> 
> I think kvm_arch_check_processor_compat() should be called even when
> usage_count is 0. Otherwise, compatibility checks may be missing on some
> CPUs if no VM is running when those CPUs becomes online.

Oh, right. Compatibility check should be done unconditionally.
-- 
Isaku Yamahata <isaku.yamahata@gmail.com>