Skip to contentSkip to conversation

Fixes for -cpu host KVM/SVM feature initialization

PATCH In review Eduardo Habkost 3 participants 11 messages Dec 28, 2012 – Jan 2, 2013 KVM

lore
Share & tools
lore
#0 lore raw

cover Fixes for -cpu host KVM/SVM feature initialization

This series has two very similar fixes for feature initizliation for "-cpu host". This should allow us to make the check/enforce code check for host support of KVM and SVM features, later.

Eduardo Habkost (2):
target-i386: kvm: -cpu host: use GET_SUPPORTED_CPUID for SVM features
target-i386: kvm: enable all supported KVM features for -cpu host

 target-i386/cpu.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 target-i386: kvm: -cpu host: use GET_SUPPORTED_CPUID for SVM features

The existing -cpu host code simply set every bit inside svm_features (initializing it to -1), and that makes it impossible to make the enforce/check options work properly when the user asks for SVM features explicitly in the command-line.

So, instead of initializing svm_features to -1, use GET_SUPPORTED_CPUID to fill only the bits that are supported by the host (just like we do for all other CPUID feature words inside kvm_cpu_fill_host()).

This will keep the existing behavior (as filter_features_for_kvm() already uses GET_SUPPORTED_CPUID to filter svm_features), but will allow us to properly check for KVM features inside kvm_check_features_against_host() later.

For example, we will be able to make this:

  $ qemu-system-x86_64 -cpu ...,+pfthreshold,enforce

refuse to start if the SVM "pfthreshold" feature is not supported by the host (after we fix kvm_check_features_against_host() to check SVM flags as well).

---
 target-i386/cpu.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
target-i386/cpu.c +4 -7
index 3cd1cee..6e2d32d 100644
@@ -897,13 +897,10 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
         }
     }
 
-    /*
-     * Every SVM feature requires emulation support in KVM - so we can't just
-     * read the host features here. KVM might even support SVM features not
-     * available on the host hardware. Just set all bits and mask out the
-     * unsupported ones later.
-     */
-    x86_cpu_def->svm_features = -1;
+    /* Other KVM-specific feature fields: */
+    x86_cpu_def->svm_features =
+                kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+
 #endif /* CONFIG_KVM */
 }
 
Signature · 1 line
1.7.11.7
#5 lore raw

PATCH 2/2 target-i386: kvm: enable all supported KVM features for -cpu host

In reply to Eduardo Habkost

When using -cpu host, we don't need to use the kvm_default_features variable, as the user is explicitly asking QEMU to enable all feature supported by the host.

This changes the kvm_cpu_fill_host() code to use GET_SUPPORTED_CPUID to initialize the kvm_features field, so we get all host KVM features enabled.

This will also allow use to properly check/enforce KVM features inside kvm_check_features_against_host() later. For example, we will be able to make this:

  $ qemu-system-x86_64 -cpu ...,+kvm_pv_eoi,enforce

refuse to start if kvm_pv_eoi is not supported by the host (after we fix kvm_check_features_against_host() to check KVM flags as well).

---
 target-i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target-i386/cpu.c +2 -0
index 6e2d32d..76f19f0 100644
@@ -900,6 +900,8 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
     /* Other KVM-specific feature fields: */
     x86_cpu_def->svm_features =
                 kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+    x86_cpu_def->kvm_features =
+                kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX);
 
 #endif /* CONFIG_KVM */
 }
Signature · 1 line
1.7.11.7
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] target-i386: kvm: -cpu host: use GET_SUPPORTED_CPUID for SVM features

In reply to Eduardo Habkost
Quoted 16 lines · On Fri, 28 Dec 2012 16:37:33 -0200 Eduardo Habkost <[email protected]> wrote:

The existing -cpu host code simply set every bit inside svm_features (initializing it to -1), and that makes it impossible to make the enforce/check options work properly when the user asks for SVM features explicitly in the command-line.

So, instead of initializing svm_features to -1, use GET_SUPPORTED_CPUID to fill only the bits that are supported by the host (just like we do for all other CPUID feature words inside kvm_cpu_fill_host()).

This will keep the existing behavior (as filter_features_for_kvm() already uses GET_SUPPORTED_CPUID to filter svm_features), but will allow us to properly check for KVM features inside kvm_check_features_against_host() later.

For example, we will be able to make this:

Quoted 7 lines
  $ qemu-system-x86_64 -cpu ...,+pfthreshold,enforce

refuse to start if the SVM "pfthreshold" feature is not supported by the host (after we fix kvm_check_features_against_host() to check SVM flags as well).

Quoted 27 lines
---
 target-i386/cpu.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
target-i386/cpu.c +0 -2
index 3cd1cee..6e2d32d 100644
@@ -897,13 +897,10 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
         }
     }
 
-    /*
-     * Every SVM feature requires emulation support in KVM - so we can't

just

target-i386/cpu.c +4 -5
-     * read the host features here. KVM might even support SVM features not
-     * available on the host hardware. Just set all bits and mask out the
-     * unsupported ones later.
-     */
-    x86_cpu_def->svm_features = -1;
+    /* Other KVM-specific feature fields: */
+    x86_cpu_def->svm_features =
+                kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+
 #endif /* CONFIG_KVM */
 }
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] target-i386: kvm: -cpu host: use GET_SUPPORTED_CPUID for SVM features

In reply to Eduardo Habkost

Am 28.12.2012 19:37, schrieb Eduardo Habkost:

Quoted 35 lines

The existing -cpu host code simply set every bit inside svm_features (initializing it to -1), and that makes it impossible to make the enforce/check options work properly when the user asks for SVM features explicitly in the command-line.

So, instead of initializing svm_features to -1, use GET_SUPPORTED_CPUID to fill only the bits that are supported by the host (just like we do for all other CPUID feature words inside kvm_cpu_fill_host()).

This will keep the existing behavior (as filter_features_for_kvm() already uses GET_SUPPORTED_CPUID to filter svm_features), but will allow us to properly check for KVM features inside kvm_check_features_against_host() later.

For example, we will be able to make this:

  $ qemu-system-x86_64 -cpu ...,+pfthreshold,enforce

refuse to start if the SVM "pfthreshold" feature is not supported by the host (after we fix kvm_check_features_against_host() to check SVM flags as well).

---
 target-i386/cpu.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
target-i386/cpu.c +0 -0
index 3cd1cee..6e2d32d 100644
@@ -897,13 +897,10 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
         }
     }
 

target-i386/cpu.c static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def) · line 902

Quoted 10 lines
target-i386/cpu.c +3 -7
-    /*
-     * Every SVM feature requires emulation support in KVM - so we can't just
-     * read the host features here. KVM might even support SVM features not
-     * available on the host hardware. Just set all bits and mask out the
-     * unsupported ones later.
-     */
-    x86_cpu_def->svm_features = -1;
+    /* Other KVM-specific feature fields: */
+    x86_cpu_def->svm_features =
+                kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);

Is there no #define for this, similar to KVM_CPUID_FEATURES in 2/2? FWIW indentation looks odd.

Andreas

Quoted 5 lines
target-i386/cpu.c +1 -0
+
 #endif /* CONFIG_KVM */
 }
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#10 lore raw
In reply to Eduardo Habkost

Am 28.12.2012 19:37, schrieb Eduardo Habkost:

Quoted 3 lines

This series has two very similar fixes for feature initizliation for "-cpu host". This should allow us to make the check/enforce code check for host support of KVM and SVM features, later.

I am out of my field here to verify whether this is semantically correct and whether any fallback code may be needed. However, this will conflict with X86CPU subclasses, so I'd be interested in taking this through my qom-cpu queue if there are acks from the KVM folks.

Regards,
Andreas

Quoted 6 lines

Eduardo Habkost (2):
target-i386: kvm: -cpu host: use GET_SUPPORTED_CPUID for SVM features
target-i386: kvm: enable all supported KVM features for -cpu host

 target-i386/cpu.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw

Re: [PATCH 2/2] target-i386: kvm: enable all supported KVM features for -cpu host

In reply to Eduardo Habkost
Quoted 7 lines · On Fri, 28 Dec 2012 16:37:34 -0200 Eduardo Habkost <[email protected]> wrote:

When using -cpu host, we don't need to use the kvm_default_features variable, as the user is explicitly asking QEMU to enable all feature supported by the host.

This changes the kvm_cpu_fill_host() code to use GET_SUPPORTED_CPUID to initialize the kvm_features field, so we get all host KVM features enabled.

1_2 and 1_3 compat machines diff on pv_eoi flag, with this patch 1_2 might have it set.
Is it ok from compat machines pov?

Quoted 9 lines

This will also allow use to properly check/enforce KVM features inside kvm_check_features_against_host() later. For example, we will be able to make this:

  $ qemu-system-x86_64 -cpu ...,+kvm_pv_eoi,enforce

refuse to start if kvm_pv_eoi is not supported by the host (after we fix kvm_check_features_against_host() to check KVM flags as well).

It would be nice to have kvm_check_features_against_host() patch in this series to verify that this patch and previous patch works as expected.

Quoted 19 lines
---
 target-i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target-i386/cpu.c +2 -0
index 6e2d32d..76f19f0 100644
@@ -900,6 +900,8 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
     /* Other KVM-specific feature fields: */
     x86_cpu_def->svm_features =
                 kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+    x86_cpu_def->kvm_features =
+                kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0,
 R_EAX); 
 #endif /* CONFIG_KVM */
 }
#4 lore raw

Re: [PATCH 1/2] target-i386: kvm: -cpu host: use GET_SUPPORTED_CPUID for SVM features

In reply to Andreas Färber
Quoted 36 lines · Andreas Färber

Am 28.12.2012 19:37, schrieb Eduardo Habkost:

Quoted 35 lines

The existing -cpu host code simply set every bit inside svm_features (initializing it to -1), and that makes it impossible to make the enforce/check options work properly when the user asks for SVM features explicitly in the command-line.

So, instead of initializing svm_features to -1, use GET_SUPPORTED_CPUID to fill only the bits that are supported by the host (just like we do for all other CPUID feature words inside kvm_cpu_fill_host()).

This will keep the existing behavior (as filter_features_for_kvm() already uses GET_SUPPORTED_CPUID to filter svm_features), but will allow us to properly check for KVM features inside kvm_check_features_against_host() later.

For example, we will be able to make this:

  $ qemu-system-x86_64 -cpu ...,+pfthreshold,enforce

refuse to start if the SVM "pfthreshold" feature is not supported by the host (after we fix kvm_check_features_against_host() to check SVM flags as well).

---
 target-i386/cpu.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
target-i386/cpu.c +0 -0
index 3cd1cee..6e2d32d 100644
@@ -897,13 +897,10 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
         }
     }
 
Quoted 12 lines

target-i386/cpu.c static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def) · line 902

Quoted 10 lines
target-i386/cpu.c +3 -7
-    /*
-     * Every SVM feature requires emulation support in KVM - so we can't just
-     * read the host features here. KVM might even support SVM features not
-     * available on the host hardware. Just set all bits and mask out the
-     * unsupported ones later.
-     */
-    x86_cpu_def->svm_features = -1;
+    /* Other KVM-specific feature fields: */
+    x86_cpu_def->svm_features =
+                kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);

Is there no #define for this, similar to KVM_CPUID_FEATURES in 2/2?

I believve KVM_CPUID_FEATURES is the exception, all other leaves have their own numbers hardcoded in the code.

(The way I plan to fix this is to introduce the feature-array and a CPUID leaf/register table for the feature-array, so kvm_cpu_fill_host(), filter_features_for_kvm(), kvm_check_features_against_host() & similar functions would always handle exactly the same set of CPUID leaves, by simply looking at the table).

Quoted 1 line

FWIW indentation looks odd.

Oops, I intended to follow the existing style used for ext2_features and ext3_features and use 8 spaces instead of 12. I will resubmit.

Signature · 1 line
Eduardo
#7 lore raw

Re: [PATCH 2/2] target-i386: kvm: enable all supported KVM features for -cpu host

In reply to Igor Mammedov
Quoted 7 lines · Igor Mammedov
Quoted 4 lines · On Fri, 28 Dec 2012 16:37:34 -0200 Eduardo Habkost <[email protected]> wrote:

When using -cpu host, we don't need to use the kvm_default_features variable, as the user is explicitly asking QEMU to enable all feature supported by the host.

Quoted 7 lines
Quoted 3 lines

This changes the kvm_cpu_fill_host() code to use GET_SUPPORTED_CPUID to initialize the kvm_features field, so we get all host KVM features enabled.

1_2 and 1_3 compat machines diff on pv_eoi flag, with this patch 1_2 might have it set.
Is it ok from compat machines pov?

-cpu host is completely dependent on host hardware and kernel version, there are no compatibility expectations.

Quoted 6 lines
Quoted 6 lines

This will also allow use to properly check/enforce KVM features inside kvm_check_features_against_host() later. For example, we will be able to make this:

Quoted 6 lines
Quoted 4 lines
  $ qemu-system-x86_64 -cpu ...,+kvm_pv_eoi,enforce

refuse to start if kvm_pv_eoi is not supported by the host (after we fix kvm_check_features_against_host() to check KVM flags as well).

It would be nice to have kvm_check_features_against_host() patch in this series to verify that this patch and previous patch works as expected.

The kvm_check_features_against_host() change would be a user-visible behavior change, and I wanted to keep the changes minimal by now. (the main reason I submitted this earlier is to make it easier to clean up the init code for CPU subclasses)

I was planning to introduce those behavior changes only after introducing the feature-word array, so the kvm_check_features_against_host() code can become simpler and easier to review (instead of adding 4 additional items to the messy struct model_features_t array). But if you think we can introduce those changes now, I will be happy to send a series that changes that code as well.

Quoted 21 lines
Quoted 20 lines
---
 target-i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target-i386/cpu.c +2 -0
index 6e2d32d..76f19f0 100644
@@ -900,6 +900,8 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
     /* Other KVM-specific feature fields: */
     x86_cpu_def->svm_features =
                 kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+    x86_cpu_def->kvm_features =
+                kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0,
 R_EAX); 
 #endif /* CONFIG_KVM */
 }
Signature · 1 line
Eduardo
#8 lore raw

Re: [PATCH 2/2] target-i386: kvm: enable all supported KVM features for -cpu host

Quoted 12 lines · On Wed, 2 Jan 2013 13:29:10 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 11 lines · Igor Mammedov
Quoted 7 lines · On Fri, 28 Dec 2012 16:37:34 -0200 Eduardo Habkost <[email protected]> wrote:

When using -cpu host, we don't need to use the kvm_default_features variable, as the user is explicitly asking QEMU to enable all feature supported by the host.

This changes the kvm_cpu_fill_host() code to use GET_SUPPORTED_CPUID to initialize the kvm_features field, so we get all host KVM features enabled.

Quoted 6 lines
Quoted 3 lines

1_2 and 1_3 compat machines diff on pv_eoi flag, with this patch 1_2 might have it set.
Is it ok from compat machines pov?

-cpu host is completely dependent on host hardware and kernel version, there are no compatibility expectations.

It's still kind of unpleasant surprise if on the same host "qemu-1.3 -cpu host -machine pc-1.2" and "qemu-1.3+ -cpu host -machine pc-1.2" would give different pv_eoi feature default, where pv-eoi should be available after -machine pc-1.2 by default.

Quoted 19 lines
Quoted 7 lines
Quoted 7 lines

This will also allow use to properly check/enforce KVM features inside kvm_check_features_against_host() later. For example, we will be able to make this:

Quoted 6 lines
Quoted 4 lines
  $ qemu-system-x86_64 -cpu ...,+kvm_pv_eoi,enforce

refuse to start if kvm_pv_eoi is not supported by the host (after we fix kvm_check_features_against_host() to check KVM flags as well).

It would be nice to have kvm_check_features_against_host() patch in this series to verify that this patch and previous patch works as expected.

The kvm_check_features_against_host() change would be a user-visible behavior change, and I wanted to keep the changes minimal by now. (the main reason I submitted this earlier is to make it easier to clean up the init code for CPU subclasses)

Quoted 6 lines

I was planning to introduce those behavior changes only after introducing the feature-word array, so the kvm_check_features_against_host() code can become simpler and easier to review (instead of adding 4 additional items to the messy struct model_features_t array). But if you think we can introduce those changes now, I will be happy to send a series that changes that code as well.

It would be better if it and simplifying kvm_check_features_against_host() were in here together.

Quoted 26 lines
Quoted 22 lines
Quoted 21 lines
---
 target-i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target-i386/cpu.c +2 -0
index 6e2d32d..76f19f0 100644
@@ -900,6 +900,8 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
     /* Other KVM-specific feature fields: */
     x86_cpu_def->svm_features =
                 kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+    x86_cpu_def->kvm_features =
+                kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0,
 R_EAX); 
 #endif /* CONFIG_KVM */
 }
Signature · 1 line
Eduardo
Signature · 2 lines
Regards,
  Igor
#9 lore raw

Re: [PATCH 2/2] target-i386: kvm: enable all supported KVM features for -cpu host

Quoted 19 lines · Igor Mammedov
Quoted 16 lines · On Wed, 2 Jan 2013 13:29:10 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 14 lines · Igor Mammedov
Quoted 7 lines · On Fri, 28 Dec 2012 16:37:34 -0200 Eduardo Habkost <[email protected]> wrote:

When using -cpu host, we don't need to use the kvm_default_features variable, as the user is explicitly asking QEMU to enable all feature supported by the host.

This changes the kvm_cpu_fill_host() code to use GET_SUPPORTED_CPUID to initialize the kvm_features field, so we get all host KVM features enabled.

1_2 and 1_3 compat machines diff on pv_eoi flag, with this patch 1_2 might have it set.
Is it ok from compat machines pov?

Quoted 7 lines
Quoted 2 lines

-cpu host is completely dependent on host hardware and kernel version, there are no compatibility expectations.

It's still kind of unpleasant surprise if on the same host "qemu-1.3 -cpu host -machine pc-1.2" and "qemu-1.3+ -cpu host -machine pc-1.2" would give different pv_eoi feature default, where pv-eoi should be available after -machine pc-1.2 by default.

Just like you may end up getting new features enabled by -cpu host after upgrading the kernel, you may end up getting new features enabled by -cpu host after upgrading qemu. If you don't like surprises, don't use -cpu host. ;-)

I don't think machine-types exist to avoid user surprise, they exist to keep compatibility (which is not expected to happen when using -cpu host). Keeping compatibility is hard enough in the cases where we really need it, I don't think it is worth the extra work and complexity for an use case where compatibility is not expected.

Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
Quoted 8 lines

This will also allow use to properly check/enforce KVM features inside kvm_check_features_against_host() later. For example, we will be able to make this:

Quoted 6 lines
Quoted 4 lines
  $ qemu-system-x86_64 -cpu ...,+kvm_pv_eoi,enforce

refuse to start if kvm_pv_eoi is not supported by the host (after we fix kvm_check_features_against_host() to check KVM flags as well).

It would be nice to have kvm_check_features_against_host() patch in this series to verify that this patch and previous patch works as expected.

The kvm_check_features_against_host() change would be a user-visible behavior change, and I wanted to keep the changes minimal by now. (the main reason I submitted this earlier is to make it easier to clean up the init code for CPU subclasses)

Quoted 8 lines
Quoted 6 lines

I was planning to introduce those behavior changes only after introducing the feature-word array, so the kvm_check_features_against_host() code can become simpler and easier to review (instead of adding 4 additional items to the messy struct model_features_t array). But if you think we can introduce those changes now, I will be happy to send a series that changes that code as well.

It would be better if it and simplifying kvm_check_features_against_host() were in here together.

The best way I see to simplify kvm_check_features_against_host() requires the feature words array patch, that touches _lots_ of code. I wanted to avoid adding such an intrusive patch as a dependency.

Quoted 32 lines
Quoted 27 lines
Quoted 23 lines
Quoted 22 lines
---
 target-i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target-i386/cpu.c +2 -0
index 6e2d32d..76f19f0 100644
@@ -900,6 +900,8 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
     /* Other KVM-specific feature fields: */
     x86_cpu_def->svm_features =
                 kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
+    x86_cpu_def->kvm_features =
+                kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0,
 R_EAX); 
 #endif /* CONFIG_KVM */
 }
Signature · 1 line
Eduardo
Signature · 2 lines
Regards,
  Igor
Signature · 1 line
Eduardo