Skip to contentSkip to conversation

x86 CPU feature +/- fiddling and +kvm-no-defaults

RFC PATCH In review David Edmondson 6 participants 21 messages Jan 19, 2021 – Jan 27, 2021

lore
Share & tools
lore
#0 lore raw

cover x86 CPU feature +/- fiddling and +kvm-no-defaults

Currently "-cpu -feature,+feature" will disable -feature, which seems contrary to the intention of the user. Fix this such that the later flag wins. There are no changes to the interaction of +/- and =on/=off.

Enabling KVM currently causes a default set of KVM features to be enabled. Allow this default set to be defeated, requiring all features to be explicitly enabled.

David Edmondson (1):
hw/i386: -cpu model,-feature,+feature should enable feature

Joao Martins (1):
target/i386: Add "-cpu +kvm-no-defaults"

 target/i386/cpu.c                   | 38 +++++++++++++++++++++++------
 target/i386/cpu.h                   |  3 +++
 tests/qtest/test-x86-cpuid-compat.c |  8 +++---
 3 files changed, 38 insertions(+), 11 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

RFC PATCH 1/2 hw/i386: -cpu model, -feature, +feature should enable feature

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

---
 target/i386/cpu.c                   | 33 +++++++++++++++++++++++------
 tests/qtest/test-x86-cpuid-compat.c |  8 +++----
 2 files changed, 30 insertions(+), 11 deletions(-)
target/i386/cpu.c +26 -7
index 35459a38bb..13f58ef183 100644
@@ -4750,13 +4750,32 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
         GlobalProperty *prop;
 
         /* Compatibility syntax: */
-        if (featurestr[0] == '+') {
-            plus_features = g_list_append(plus_features,
-                                          g_strdup(featurestr + 1));
-            continue;
-        } else if (featurestr[0] == '-') {
-            minus_features = g_list_append(minus_features,
-                                           g_strdup(featurestr + 1));
+        if (featurestr[0] == '+' || featurestr[0] == '-') {
+            const char *feat = featurestr + 1;
+            GList **remove, **add;
+            GList *val;
+
+            if (featurestr[0] == '+') {
+                remove = &minus_features;
+                add = &plus_features;
+            } else {
+                remove = &plus_features;
+                add = &minus_features;
+            }
+
+            val = g_list_find_custom(*remove, feat, compare_string);
+            if (val) {
+                char *data = val->data;
+
+                *remove = g_list_remove(*remove, data);
+                g_free(data);
+            }
+
+            val = g_list_find_custom(*add, feat, compare_string);
+            if (!val) {
+                *add = g_list_append(*add, g_strdup(feat));
+            }
+
             continue;
         }
 
tests/qtest/test-x86-cpuid-compat.c +4 -4
index 7ca1883a29..6824d2b13e 100644
@@ -171,18 +171,18 @@ static void test_plus_minus_subprocess(void)
     char *path;
 
     /* Rules:
-     * 1)"-foo" overrides "+foo"
+     * 1) The later of "+foo" or "-foo" wins
      * 2) "[+-]foo" overrides "foo=..."
      * 3) Old feature names with underscores (e.g. "sse4_2")
      *    should keep working
      *
-     * Note: rules 1 and 2 are planned to be removed soon, and
-     * should generate a warning.
+     * Note: rule 2 is planned to be removed soon, and should generate
+     * a warning.
      */
     qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
     path = get_cpu0_qom_path();
 
-    g_assert_false(qom_get_bool(path, "fpu"));
+    g_assert_true(qom_get_bool(path, "fpu"));
     g_assert_false(qom_get_bool(path, "mce"));
     g_assert_true(qom_get_bool(path, "cx8"));
 
Signature · 1 line
2.29.2
#2 lore raw

Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 5 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Quoted 37 lines
---
 target/i386/cpu.c                   | 33 +++++++++++++++++++++++------
 tests/qtest/test-x86-cpuid-compat.c |  8 +++----
 2 files changed, 30 insertions(+), 11 deletions(-)
target/i386/cpu.c +15 -7
index 35459a38bb..13f58ef183 100644
@@ -4750,13 +4750,32 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
         GlobalProperty *prop;
 
         /* Compatibility syntax: */
-        if (featurestr[0] == '+') {
-            plus_features = g_list_append(plus_features,
-                                          g_strdup(featurestr + 1));
-            continue;
-        } else if (featurestr[0] == '-') {
-            minus_features = g_list_append(minus_features,
-                                           g_strdup(featurestr + 1));
+        if (featurestr[0] == '+' || featurestr[0] == '-') {
+            const char *feat = featurestr + 1;
+            GList **remove, **add;
+            GList *val;
+
+            if (featurestr[0] == '+') {
+                remove = &minus_features;
+                add = &plus_features;
+            } else {
+                remove = &plus_features;
+                add = &minus_features;
+            }
+
+            val = g_list_find_custom(*remove, feat, compare_string);
+            if (val) {

target/i386/cpu.c static void x86_cpu_parse_featurestr(const char *typename, char *features, · line 4777

Quoted 10 lines
target/i386/cpu.c +10 -0
+                char *data = val->data;
+
+                *remove = g_list_remove(*remove, data);
+                g_free(data);
+            }
+
+            val = g_list_find_custom(*add, feat, compare_string);
+            if (!val) {
+                *add = g_list_append(*add, g_strdup(feat));
+            }

I believe we'll be able to get rid of plus_features/minus_features completely if we remove compatibility of "-feature,feature=on". But if we don't, wouldn't it be simpler to replace plus_features/minus_features with a single list, appending items in the order they appear?

Quoted 34 lines
target/i386/cpu.c +1 -0
+
             continue;
         }
 
tests/qtest/test-x86-cpuid-compat.c +4 -4
index 7ca1883a29..6824d2b13e 100644
@@ -171,18 +171,18 @@ static void test_plus_minus_subprocess(void)
     char *path;
 
     /* Rules:
-     * 1)"-foo" overrides "+foo"
+     * 1) The later of "+foo" or "-foo" wins
      * 2) "[+-]foo" overrides "foo=..."
      * 3) Old feature names with underscores (e.g. "sse4_2")
      *    should keep working
      *
-     * Note: rules 1 and 2 are planned to be removed soon, and
-     * should generate a warning.
+     * Note: rule 2 is planned to be removed soon, and should generate
+     * a warning.
      */
     qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
     path = get_cpu0_qom_path();
 
-    g_assert_false(qom_get_bool(path, "fpu"));
+    g_assert_true(qom_get_bool(path, "fpu"));
     g_assert_false(qom_get_bool(path, "mce"));
     g_assert_true(qom_get_bool(path, "cx8"));
 
Signature · 1 line
2.29.2
Signature · 1 line
Eduardo
#3 lore raw

Re: [External] : Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

Quoted 45 lines
Quoted 45 lines
---
 target/i386/cpu.c                   | 33 +++++++++++++++++++++++------
 tests/qtest/test-x86-cpuid-compat.c |  8 +++----
 2 files changed, 30 insertions(+), 11 deletions(-)
target/i386/cpu.c +23 -7
index 35459a38bb..13f58ef183 100644
@@ -4750,13 +4750,32 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
         GlobalProperty *prop;
 
         /* Compatibility syntax: */
-        if (featurestr[0] == '+') {
-            plus_features = g_list_append(plus_features,
-                                          g_strdup(featurestr + 1));
-            continue;
-        } else if (featurestr[0] == '-') {
-            minus_features = g_list_append(minus_features,
-                                           g_strdup(featurestr + 1));
+        if (featurestr[0] == '+' || featurestr[0] == '-') {
+            const char *feat = featurestr + 1;
+            GList **remove, **add;
+            GList *val;
+
+            if (featurestr[0] == '+') {
+                remove = &minus_features;
+                add = &plus_features;
+            } else {
+                remove = &plus_features;
+                add = &minus_features;
+            }
+
+            val = g_list_find_custom(*remove, feat, compare_string);
+            if (val) {
+                char *data = val->data;
+
+                *remove = g_list_remove(*remove, data);
+                g_free(data);
+            }
+
+            val = g_list_find_custom(*add, feat, compare_string);
+            if (!val) {
Quoted 8 lines

target/i386/cpu.c static void x86_cpu_parse_featurestr(const char *typename, char *features, · line 4777

Quoted 2 lines
target/i386/cpu.c +2 -0
+                *add = g_list_append(*add, g_strdup(feat));
+            }

I believe we'll be able to get rid of plus_features/minus_features completely if we remove compatibility of "-feature,feature=on". But if we don't, wouldn't it be simpler to replace plus_features/minus_features with a single list, appending items in the order they appear?

Will investigate.

Quoted 26 lines
Quoted 26 lines
target/i386/cpu.c +1 -0
+
             continue;
         }
 
tests/qtest/test-x86-cpuid-compat.c +3 -3
index 7ca1883a29..6824d2b13e 100644
@@ -171,18 +171,18 @@ static void test_plus_minus_subprocess(void)
     char *path;
 
     /* Rules:
-     * 1)"-foo" overrides "+foo"
+     * 1) The later of "+foo" or "-foo" wins
      * 2) "[+-]foo" overrides "foo=..."
      * 3) Old feature names with underscores (e.g. "sse4_2")
      *    should keep working
      *
-     * Note: rules 1 and 2 are planned to be removed soon, and
-     * should generate a warning.
+     * Note: rule 2 is planned to be removed soon, and should generate
+     * a warning.
      */
     qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
     path = get_cpu0_qom_path();
 
Quoted 11 lines
Quoted 8 lines
tests/qtest/test-x86-cpuid-compat.c +1 -1
-    g_assert_false(qom_get_bool(path, "fpu"));
+    g_assert_true(qom_get_bool(path, "fpu"));
     g_assert_false(qom_get_bool(path, "mce"));
     g_assert_true(qom_get_bool(path, "cx8"));
 
Signature · 1 line
2.29.2
Signature · 1 line
Eduardo

dme.

Signature · 1 line
They must have taken my marbles away.
#4 lore raw

Re: [External] : Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 21 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Quoted 7 lines

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

Signature · 1 line
Eduardo
#5 lore raw

Re: [External] : Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 26 lines · On Tue, 19 Jan 2021 11:30:52 -0500 Eduardo Habkost <[email protected]> wrote:
Quoted 25 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Quoted 8 lines
Quoted 3 lines

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

As part of preparation to define/create machines via QMP,
I plan to post patch(s) to deprecate +-features in 6.0 (including special casing for -feat behavior (affects x86/sparc only)) and drop support for +-feat in 2 releases.
So we should end up with canonical property behavior only like all other CPUs and devices.

#6 lore raw

Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 37 lines · Igor Mammedov
Quoted 26 lines · On Tue, 19 Jan 2021 11:30:52 -0500 Eduardo Habkost <[email protected]> wrote:
Quoted 25 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Quoted 8 lines
Quoted 3 lines

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

Quoted 6 lines

As part of preparation to define/create machines via QMP,
I plan to post patch(s) to deprecate +-features in 6.0 (including special casing for -feat behavior (affects x86/sparc only)) and drop support for +-feat in 2 releases.
So we should end up with canonical property behavior only like all other CPUs and devices.

In that case I will abandon this change and focus on getting my upstack consumer to switch away from using +-.

Thanks.

dme.

Signature · 1 line
Sometimes these eyes, forget the face they're peering from.
#7 lore raw

Re: [External] : Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

In reply to Eduardo Habkost
Quoted 26 lines · Eduardo Habkost
Quoted 25 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Quoted 8 lines
Quoted 3 lines

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

Where are you expecting warnings ? I don't see any when launching QEMU

$ qemu-system-x86_64 -display none  -cpu Westmere,-vmx 
$ qemu-system-x86_64 -display none  -cpu Westmere,-vmx,sse=on

neither produces warnings, even with current git master.

I don't think we can change the parsing behaviour here without impacting guest ABI, and that feels dangerous given that we've not been warning people the syntax is undesirable.

IMHO just leave the parsing unchanged, deprecate it, and then delete the code. We don't need to "improve" usability semantics of something that we want to delete anyway.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw

Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Eduardo Habkost
Quoted 28 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

Quoted 6 lines
Quoted 4 lines

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

Where are you expecting warnings ? I don't see any when launching QEMU

qemu-system-x86_64 -display none -cpu Westmere,-vmx,+vmx

Warnings because the result of this is "-vmx".

Quoted 3 lines

IMHO just leave the parsing unchanged, deprecate it, and then delete the code. We don't need to "improve" usability semantics of something that we want to delete anyway.

/me nods.

dme.

Signature · 1 line
I just bite it, it's for the look I don't light it.
#9 lore raw

Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 42 lines · David Edmondson
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Eduardo Habkost
Quoted 28 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

Quoted 6 lines
Quoted 4 lines

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

Where are you expecting warnings ? I don't see any when launching QEMU

qemu-system-x86_64 -display none -cpu Westmere,-vmx,+vmx

Quoted 7 lines

Warnings because the result of this is "-vmx".

Quoted 3 lines

IMHO just leave the parsing unchanged, deprecate it, and then delete the code. We don't need to "improve" usability semantics of something that we want to delete anyway.

/me nods.

I agree, but I guess we need to convince Paolo:
https://lore.kernel.org/qemu-devel/[email protected]/

Signature · 1 line
Eduardo
#10 lore raw

Re: [RFC PATCH 1/2] hw/i386: -cpu model,-feature,+feature should enable feature

Quoted 45 lines · On Wed, 20 Jan 2021 11:18:01 -0500 Eduardo Habkost <[email protected]> wrote:
Quoted 44 lines · David Edmondson
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Eduardo Habkost
Quoted 28 lines · David Edmondson
Quoted 9 lines · Eduardo Habkost

Hi,

Thanks for the patch. Getting rid of special -feature/+feature behavior was in our TODO list for a long time.

Quoted 3 lines · David Edmondson

"Minus" features are applied after "plus" features, so ensure that a later "plus" feature causes an earlier "minus" feature to be removed.

Quoted 7 lines
Quoted 2 lines

This has no effect on the existing "-feature,feature=on" backward compatibility code (which warns and turns the feature off).

If we are changing behavior, why not change behavior of "-feature,feature=on" at the same time? This would allow us to get rid of plus_features/minus_features completely and just make +feature/-feature synonyms to feature=on/feature=off.

Okay, I'll do that.

Given that there have been warnings associated with "-feature,feature=on" for a while, changing that behaviour seems acceptable.

Would the same be true for changing "-feature,+feature"? (i.e. what this patch does) Really: can this just be changed, or does there have to be some period where the behaviour stays the same with a warning?

Quoted 6 lines
Quoted 4 lines

I actually expected warnings to be triggered when using "-feature,+feature" as well. If we were not generating warnings for that case, it will need more careful evaluation, just to be sure it's safe. Igor, do you remember the details here?

Where are you expecting warnings ? I don't see any when launching QEMU

qemu-system-x86_64 -display none -cpu Westmere,-vmx,+vmx

Warnings because the result of this is "-vmx".

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

IMHO just leave the parsing unchanged, deprecate it, and then delete the code. We don't need to "improve" usability semantics of something that we want to delete anyway.

/me nods.

I agree, but I guess we need to convince Paolo:
https://lore.kernel.org/qemu-devel/[email protected]/

that's ancient :)

He recently started this revolution himself :)
https://www.mail-archive.com/[email protected]/msg757280.html

That's why I have -cpu +/-foo deprecation on my not too far away TODO list.

#11 lore raw

PATCH 1/1 docs/system: Deprecate `-cpu ...,+feature,-feature` syntax

The ordering semantics of +feature/-feature is tricky and not obvious, and it requires a custom option parser. Deprecate that syntax so we can eventually remove the custom -cpu option parser and plus_features/minus_features global variables in i386.

---
 docs/system/deprecated.rst | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
docs/system/deprecated.rst +14 -0
index e20bfcb17a4..2c4b8d4b78b 100644
@@ -127,6 +127,20 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+``-cpu`` ``+feature`` and ``-feature`` syntax (since 6.0.0)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The ``-cpu ...,+feature`` and ``-cpu ...,-feature`` syntax for
+enabling and disabling CPU features is deprecated.  The ``-cpu
+...,feature=on`` or ``-cpu ...,feature=off`` should be used
+instead.
+
+Note that the ordering semantics of ``-cpu ...,-feature,+feature``
+is different from ``-cpu ...,feature=off,feature=on``.  With the
+former, the feature got disabled because ``-feature`` had
+precedence, but with the latter the feature will be enabled
+because options are applied in the order they appear.
+
 
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
Signature · 1 line
2.28.0
author Reviewed-by on v1 1/1
#12 lore raw

Re: [PATCH] docs/system: Deprecate `-cpu ..., +feature, -feature` syntax

Quoted 6 lines · Eduardo Habkost

The ordering semantics of +feature/-feature is tricky and not obvious, and it requires a custom option parser. Deprecate that syntax so we can eventually remove the custom -cpu option parser and plus_features/minus_features global variables in i386.

With very minor wording comment...

Quoted 13 lines
---
 docs/system/deprecated.rst | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
docs/system/deprecated.rst +1 -0
index e20bfcb17a4..2c4b8d4b78b 100644
@@ -127,6 +127,20 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+``-cpu`` ``+feature`` and ``-feature`` syntax (since 6.0.0)

docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 140

Quoted 10 lines
docs/system/deprecated.rst +10 -0
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The ``-cpu ...,+feature`` and ``-cpu ...,-feature`` syntax for
+enabling and disabling CPU features is deprecated.  The ``-cpu
+...,feature=on`` or ``-cpu ...,feature=off`` should be used
+instead.
+
+Note that the ordering semantics of ``-cpu ...,-feature,+feature``
+is different from ``-cpu ...,feature=off,feature=on``.  With the
+former, the feature got disabled because ``-feature`` had

s/got/was/

Quoted 8 lines
docs/system/deprecated.rst +3 -0
+precedence, but with the latter the feature will be enabled
+because options are applied in the order they appear.
+
 
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
Signature · 1 line
2.28.0

dme.

Signature · 1 line
I got a girlfriend that's better than that.
#13 lore raw

Re: [PATCH] docs/system: Deprecate `-cpu ...,+feature,-feature` syntax

In reply to Eduardo Habkost
Quoted 9 lines · Eduardo Habkost

The ordering semantics of +feature/-feature is tricky and not obvious, and it requires a custom option parser. Deprecate that syntax so we can eventually remove the custom -cpu option parser and plus_features/minus_features global variables in i386.

---
 docs/system/deprecated.rst | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Ideally we would also print a warning on stderr when this deprecated style is used.

Quoted 13 lines
docs/system/deprecated.rst +4 -0
index e20bfcb17a4..2c4b8d4b78b 100644
@@ -127,6 +127,20 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+``-cpu`` ``+feature`` and ``-feature`` syntax (since 6.0.0)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The ``-cpu ...,+feature`` and ``-cpu ...,-feature`` syntax for

docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 143

Quoted 10 lines
docs/system/deprecated.rst +10 -0
+enabling and disabling CPU features is deprecated.  The ``-cpu
+...,feature=on`` or ``-cpu ...,feature=off`` should be used
+instead.
+
+Note that the ordering semantics of ``-cpu ...,-feature,+feature``
+is different from ``-cpu ...,feature=off,feature=on``.  With the
+former, the feature got disabled because ``-feature`` had
+precedence, but with the latter the feature will be enabled
+because options are applied in the order they appear.
+

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#14 lore raw

Re: [PATCH] docs/system: Deprecate `-cpu ...,+feature,-feature` syntax

Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · Eduardo Habkost

The ordering semantics of +feature/-feature is tricky and not obvious, and it requires a custom option parser. Deprecate that syntax so we can eventually remove the custom -cpu option parser and plus_features/minus_features global variables in i386.

Quoted 8 lines
Quoted 4 lines
---
  docs/system/deprecated.rst | 14 ++++++++++++++
  1 file changed, 14 insertions(+)

Ideally we would also print a warning on stderr when this deprecated style is used.

+1.

It might break some tests to do that, though, but if it's not too gruesome it's probably worth it.

Reviewed-by on v1 1/1
#15 lore raw

Re: [PATCH] docs/system: Deprecate `-cpu ...,+feature,-feature` syntax

In reply to Eduardo Habkost
Quoted 4 lines · On Wed, 20 Jan 2021 15:12:41 -0500 Eduardo Habkost <[email protected]> wrote:

The ordering semantics of +feature/-feature is tricky and not obvious, and it requires a custom option parser. Deprecate that syntax so we can eventually remove the custom -cpu option parser and plus_features/minus_features global variables in i386.

it affects spark as well

with that

Quoted 30 lines
---
 docs/system/deprecated.rst | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
docs/system/deprecated.rst +14 -0
index e20bfcb17a4..2c4b8d4b78b 100644
@@ -127,6 +127,20 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+``-cpu`` ``+feature`` and ``-feature`` syntax (since 6.0.0)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The ``-cpu ...,+feature`` and ``-cpu ...,-feature`` syntax for
+enabling and disabling CPU features is deprecated.  The ``-cpu
+...,feature=on`` or ``-cpu ...,feature=off`` should be used
+instead.
+
+Note that the ordering semantics of ``-cpu ...,-feature,+feature``
+is different from ``-cpu ...,feature=off,feature=on``.  With the
+former, the feature got disabled because ``-feature`` had
+precedence, but with the latter the feature will be enabled
+because options are applied in the order they appear.
+
 
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
#16 lore raw

RFC PATCH 2/2 target/i386: Add "-cpu +kvm-no-defaults"

In reply to David Edmondson

From: Joao Martins <[email protected]>

When enabling reporting to the guest that the hypervisor is KVM via "+kvm", we also enable all of the known KVM features that are supported by the host kernel. A new "kvm-no-defaults" option for -cpu defeats this, enabling KVM reporting but *not* enabling any specific KVM features. Those features can be enabled one-by-one using existing feature flags, such as kvmclock, kvm-pv-eoi, etc.

---
 target/i386/cpu.c | 5 +++++
 target/i386/cpu.h | 3 +++
 2 files changed, 8 insertions(+)
target/i386/cpu.c +5 -0
index 13f58ef183..4f1e807815 100644
@@ -6398,6 +6398,10 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
     int i;
     GList *l;
 
+    if (kvm_enabled() && cpu->kvm_no_defaults) {
+        env->features[FEAT_KVM] = 0;
+    }
+
     for (l = plus_features; l; l = l->next) {
         const char *prop = l->data;
         if (!object_property_set_bool(OBJECT(cpu), prop, true, errp)) {
@@ -7269,6 +7273,7 @@ static Property x86_cpu_properties[] = {
     DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true),
     DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false),
     DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true),
+    DEFINE_PROP_BOOL("kvm-no-defaults", X86CPU, kvm_no_defaults, false),
     DEFINE_PROP_BOOL("kvm-no-smi-migration", X86CPU, kvm_no_smi_migration,
                      false),
     DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true),
target/i386/cpu.h +3 -0
index d23a5b340a..f76af4a771 100644
@@ -1744,6 +1744,9 @@ struct X86CPU {
     /* if set, limit maximum value for phys_bits when host_phys_bits is true */
     uint8_t host_phys_bits_limit;
 
+    /* Don't automatically enable all of the discovered KVM features. */
+    bool kvm_no_defaults;
+
     /* Stop SMI delivery for migration compatibility with old machines */
     bool kvm_no_smi_migration;
 
Signature · 1 line
2.29.2
#17 lore raw
In reply to David Edmondson
Quoted 3 lines · David Edmondson

Currently "-cpu -feature,+feature" will disable -feature, which seems contrary to the intention of the user. Fix this such that the later flag wins. There are no changes to the interaction of +/- and =on/=off.

The -feature/+feature syntax is the legacy way of configuring features, with feature=on|off being the preferred, since that matches the general QEMU standard for boolean properties.

Your proposed change in ordering of + vs - makes conceptual sense, but it is none the less a semantic change in behaviour that may well cause breakage for existing deployed VMs. This impacts guest ABI so could particularly cause live migration problems.

IOW, we should have implemented it the way you propose in the first place, but I don't think it is safe to change it now, unless you can tie that new semantic to a machine type version.

Before we consider that though, Paolo has just deprecated many of the legacy approaches for boolean properties in this:

https://lists.nongnu.org/archive/html/qemu-devel/2021-01/msg04341.html

I'm inclined to say that we just follow on from that and finally deprecate the +feature/-feature CPU syntax which we're already considering legacy. This would remove the need to care about changing its behaviour

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#18 lore raw
Quoted 18 lines · Daniel P. Berrangé
Quoted 3 lines · David Edmondson

Currently "-cpu -feature,+feature" will disable -feature, which seems contrary to the intention of the user. Fix this such that the later flag wins. There are no changes to the interaction of +/- and =on/=off.

The -feature/+feature syntax is the legacy way of configuring features, with feature=on|off being the preferred, since that matches the general QEMU standard for boolean properties.

Your proposed change in ordering of + vs - makes conceptual sense, but it is none the less a semantic change in behaviour that may well cause breakage for existing deployed VMs. This impacts guest ABI so could particularly cause live migration problems.

IOW, we should have implemented it the way you propose in the first place, but I don't think it is safe to change it now, unless you can tie that new semantic to a machine type version.

Quoted 8 lines

Before we consider that though, Paolo has just deprecated many of the legacy approaches for boolean properties in this:

https://lists.nongnu.org/archive/html/qemu-devel/2021-01/msg04341.html

I'm inclined to say that we just follow on from that and finally deprecate the +feature/-feature CPU syntax which we're already considering legacy. This would remove the need to care about changing its behaviour

I believe we had multiple proposal in the past do deprecate +feature/-feature, but there were objections. I couldn't find the original threads, though.

In either case, I thought we had already deprecated the weird ordering rules of "-feature,+feature".

Signature · 1 line
Eduardo
#19 lore raw
Quoted 24 lines · Eduardo Habkost
Quoted 23 lines · Daniel P. Berrangé
Quoted 3 lines · David Edmondson

Currently "-cpu -feature,+feature" will disable -feature, which seems contrary to the intention of the user. Fix this such that the later flag wins. There are no changes to the interaction of +/- and =on/=off.

The -feature/+feature syntax is the legacy way of configuring features, with feature=on|off being the preferred, since that matches the general QEMU standard for boolean properties.

Your proposed change in ordering of + vs - makes conceptual sense, but it is none the less a semantic change in behaviour that may well cause breakage for existing deployed VMs. This impacts guest ABI so could particularly cause live migration problems.

IOW, we should have implemented it the way you propose in the first place, but I don't think it is safe to change it now, unless you can tie that new semantic to a machine type version.

Before we consider that though, Paolo has just deprecated many of the legacy approaches for boolean properties in this:

https://lists.nongnu.org/archive/html/qemu-devel/2021-01/msg04341.html

Quoted 7 lines
Quoted 3 lines

I'm inclined to say that we just follow on from that and finally deprecate the +feature/-feature CPU syntax which we're already considering legacy. This would remove the need to care about changing its behaviour

I believe we had multiple proposal in the past do deprecate +feature/-feature, but there were objections. I couldn't find the original threads, though.

Historically libvirt was using +/- syntax, but we finally removed the last usage of it in June 2019 / libvirt v5.4.0. So for modern QEMU libvirt will always use =on|off.

Quoted 2 lines

In either case, I thought we had already deprecated the weird ordering rules of "-feature,+feature".

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#20 lore raw
Quoted 29 lines · On Tue, 19 Jan 2021 16:41:42 +0000 Daniel P. Berrangé <[email protected]>…
Quoted 28 lines · Eduardo Habkost
Quoted 26 lines · Daniel P. Berrangé
Quoted 3 lines · David Edmondson

Currently "-cpu -feature,+feature" will disable -feature, which seems contrary to the intention of the user. Fix this such that the later flag wins. There are no changes to the interaction of +/- and =on/=off.

The -feature/+feature syntax is the legacy way of configuring features, with feature=on|off being the preferred, since that matches the general QEMU standard for boolean properties.

Your proposed change in ordering of + vs - makes conceptual sense, but it is none the less a semantic change in behaviour that may well cause breakage for existing deployed VMs. This impacts guest ABI so could particularly cause live migration problems.

IOW, we should have implemented it the way you propose in the first place, but I don't think it is safe to change it now, unless you can tie that new semantic to a machine type version.

Before we consider that though, Paolo has just deprecated many of the legacy approaches for boolean properties in this:

https://lists.nongnu.org/archive/html/qemu-devel/2021-01/msg04341.html

I'm inclined to say that we just follow on from that and finally deprecate the +feature/-feature CPU syntax which we're already considering legacy. This would remove the need to care about changing its behaviour

Quoted 7 lines
Quoted 3 lines

I believe we had multiple proposal in the past do deprecate +feature/-feature, but there were objections. I couldn't find the original threads, though.

Historically libvirt was using +/- syntax, but we finally removed the last usage of it in June 2019 / libvirt v5.4.0. So for modern QEMU libvirt will always use =on|off.

there are KVM unit tests that used /- syntax, I don't recall any attempt to switch to canonical syntax.

Quoted 6 lines
Quoted 3 lines

In either case, I thought we had already deprecated the weird ordering rules of "-feature,+feature".

Regards,
Daniel