diff mbox series

hw/i386: -cpu model,-feature,+feature should enable feature

Message ID 20201027102826.68489-1-david.edmondson@oracle.com
State New
Headers show
Series hw/i386: -cpu model,-feature,+feature should enable feature | expand

Commit Message

David Edmondson Oct. 27, 2020, 10:28 a.m. UTC
"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).

Signed-off-by: David Edmondson <david.edmondson@oracle.com>
---
 target/i386/cpu.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0d8606958e..c3dcfb868c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4720,13 +4720,30 @@  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 *val;
+            char *data;
+
+            /* Remove any existing +/- setting. */
+            val = g_list_find_custom(minus_features, feat, compare_string);
+            if (val) {
+                data = val->data;
+                minus_features = g_list_remove(minus_features, data);
+                g_free(data);
+            }
+            val = g_list_find_custom(plus_features, feat, compare_string);
+            if (val) {
+                data = val->data;
+                plus_features = g_list_remove(plus_features, data);
+                g_free(data);
+            }
+
+            if (featurestr[0] == '+') {
+                plus_features = g_list_append(plus_features, g_strdup(feat));
+            } else {
+                minus_features = g_list_append(minus_features, g_strdup(feat));
+            }
             continue;
         }