Skip to contentSkip to conversation

kvm: x86: Add support for -machine split-lock-ac

PATCH In review Jingqi Liu 5 participants 7 messages Jul 4, 2018 – Jul 5, 2018

lore
Share & tools
lore

Jingqi Liu

author
#0 lore raw

PATCH 1/1 kvm: x86: Add support for -machine split-lock-ac

Add the option split-lock-ac to control whether the #AC exception is generated for split locked accesses, which is introduced for the machine, there is an example to enable it:
-machine split-lock-ac=on
It is disabled on default.

When bit 29 of the MSR (33H) is set, the processor causes an #AC exception to be issued instead of suppressing LOCK on bus(during split lock access).

---
 accel/kvm/kvm-all.c       | 10 ++++++++++
 hw/core/machine.c         | 19 +++++++++++++++++++
 include/hw/boards.h       |  1 +
 linux-headers/linux/kvm.h |  1 +
 qemu-options.hx           |  3 +++
 5 files changed, 34 insertions(+)
accel/kvm/kvm-all.c +10 -0
index eb7db92..e960a4d 100644
@@ -1699,6 +1699,16 @@ static int kvm_init(MachineState *ms)
 
     s->sync_mmu = !!kvm_vm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);
 
+    if (ms->split_lock_ac &&
+        kvm_check_extension(s, KVM_CAP_X86_SPLIT_LOCK_AC)) {
+        ret = kvm_vm_enable_cap(s, KVM_CAP_X86_SPLIT_LOCK_AC, 0);
+        if (ret) {
+            fprintf(stderr, "Could not enable the feature that #AC exception"
+                    "will be generated for split lock accesses!\n");
+            goto err;
+        }
+    }
+
     return 0;
 
 err:
hw/core/machine.c +19 -0
index 617e5f8..e054119 100644
@@ -350,6 +350,22 @@ static void machine_set_memory_encryption(Object *obj, const char *value,
     ms->memory_encryption = g_strdup(value);
 }
 
+static void machine_set_split_lock_ac(Object *obj, bool value,
+                                      Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    ms->split_lock_ac = value;
+}
+
+static bool machine_get_split_lock_ac(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return ms->split_lock_ac;
+}
+
+
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
 {
     strList *item = g_new0(strList, 1);
@@ -634,6 +650,9 @@ static void machine_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "memory-encryption",
         "Set memory encyption object to use", &error_abort);
+    object_class_property_add_bool(oc, "split-lock-ac",
+        machine_get_split_lock_ac, machine_set_split_lock_ac,
+        &error_abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data)
include/hw/boards.h +1 -0
index 79069dd..9c1e2c0 100644
@@ -256,6 +256,7 @@ struct MachineState {
     bool suppress_vmdesc;
     bool enforce_config_section;
     bool enable_graphics;
+    bool split_lock_ac;
     char *memory_encryption;
     DeviceMemoryState *device_memory;
 
linux-headers/linux/kvm.h +1 -0
index 98f389a..4bfa879 100644
@@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_GET_MSR_FEATURES 153
 #define KVM_CAP_HYPERV_EVENTFD 154
 #define KVM_CAP_HYPERV_TLBFLUSH 155
+#define KVM_CAP_X86_SPLIT_LOCK_AC 156
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
qemu-options.hx +3 -0
index 81b1e99..935cefe 100644
@@ -44,6 +44,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
     "                enforce-config-section=on|off enforce configuration section migration (default=off)\n"
     "                s390-squash-mcss=on|off (deprecated) controls support for squashing into default css (default=off)\n"
+    "                split-lock-ac=on|off controls support #AC exception for split locked accesses (default=off)\n"
     "                memory-encryption=@var{} memory encryption object to use (default=none)\n",
     QEMU_ARCH_ALL)
 STEXI
@@ -113,6 +114,8 @@ NOTE: this parameter is deprecated. Please use @option{-global}
 @option{migration.send-configuration}=@var{on|off} instead.
 @item memory-encryption=@var{}
 Memory encryption object to use. The default is none.
+@item split-lock-ac=on|off
+Enables or disables #AC exception for split locked accesses.
 @end table
 ETEXI
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · Jingqi Liu

Add the option split-lock-ac to control whether the #AC exception is generated for split locked accesses, which is introduced for the machine, there is an example to enable it:
-machine split-lock-ac=on
It is disabled on default.

When bit 29 of the MSR (33H) is set, the processor causes an #AC exception to be issued instead of suppressing LOCK on bus(during split lock access).

This should be a CPU feature, not a machine feature. As mentioned in the review of the kernel patch, please work with Robert to use the same infrastructure for both MSR_TEST_CTL and MSR_IA32_ARCH_CAPABILITIES.

(Robert, does IceLake have this feature? If so, we cannot create the CPU model until everything is in place).

BTW, why is the availability of the feature not exposed with a CPUID bit? It doesn't make much sense.

Paolo

Quoted 113 lines
---
 accel/kvm/kvm-all.c       | 10 ++++++++++
 hw/core/machine.c         | 19 +++++++++++++++++++
 include/hw/boards.h       |  1 +
 linux-headers/linux/kvm.h |  1 +
 qemu-options.hx           |  3 +++
 5 files changed, 34 insertions(+)
accel/kvm/kvm-all.c +10 -0
index eb7db92..e960a4d 100644
@@ -1699,6 +1699,16 @@ static int kvm_init(MachineState *ms)
 
     s->sync_mmu = !!kvm_vm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);
 
+    if (ms->split_lock_ac &&
+        kvm_check_extension(s, KVM_CAP_X86_SPLIT_LOCK_AC)) {
+        ret = kvm_vm_enable_cap(s, KVM_CAP_X86_SPLIT_LOCK_AC, 0);
+        if (ret) {
+            fprintf(stderr, "Could not enable the feature that #AC exception"
+                    "will be generated for split lock accesses!\n");
+            goto err;
+        }
+    }
+
     return 0;
 
 err:
hw/core/machine.c +19 -0
index 617e5f8..e054119 100644
@@ -350,6 +350,22 @@ static void machine_set_memory_encryption(Object *obj, const char *value,
     ms->memory_encryption = g_strdup(value);
 }
 
+static void machine_set_split_lock_ac(Object *obj, bool value,
+                                      Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    ms->split_lock_ac = value;
+}
+
+static bool machine_get_split_lock_ac(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return ms->split_lock_ac;
+}
+
+
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
 {
     strList *item = g_new0(strList, 1);
@@ -634,6 +650,9 @@ static void machine_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "memory-encryption",
         "Set memory encyption object to use", &error_abort);
+    object_class_property_add_bool(oc, "split-lock-ac",
+        machine_get_split_lock_ac, machine_set_split_lock_ac,
+        &error_abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data)
include/hw/boards.h +1 -0
index 79069dd..9c1e2c0 100644
@@ -256,6 +256,7 @@ struct MachineState {
     bool suppress_vmdesc;
     bool enforce_config_section;
     bool enable_graphics;
+    bool split_lock_ac;
     char *memory_encryption;
     DeviceMemoryState *device_memory;
 
linux-headers/linux/kvm.h +1 -0
index 98f389a..4bfa879 100644
@@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_GET_MSR_FEATURES 153
 #define KVM_CAP_HYPERV_EVENTFD 154
 #define KVM_CAP_HYPERV_TLBFLUSH 155
+#define KVM_CAP_X86_SPLIT_LOCK_AC 156
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
qemu-options.hx +3 -0
index 81b1e99..935cefe 100644
@@ -44,6 +44,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
     "                enforce-config-section=on|off enforce configuration section migration (default=off)\n"
     "                s390-squash-mcss=on|off (deprecated) controls support for squashing into default css (default=off)\n"
+    "                split-lock-ac=on|off controls support #AC exception for split locked accesses (default=off)\n"
     "                memory-encryption=@var{} memory encryption object to use (default=none)\n",
     QEMU_ARCH_ALL)
 STEXI
@@ -113,6 +114,8 @@ NOTE: this parameter is deprecated. Please use @option{-global}
 @option{migration.send-configuration}=@var{on|off} instead.
 @item memory-encryption=@var{}
 Memory encryption object to use. The default is none.
+@item split-lock-ac=on|off
+Enables or disables #AC exception for split locked accesses.
 @end table
 ETEXI
 
#2 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Jingqi Liu

Add the option split-lock-ac to control whether the #AC exception is generated for split locked accesses, which is introduced for the machine, there is an example to enable it:
-machine split-lock-ac=on
It is disabled on default.

When bit 29 of the MSR (33H) is set, the processor causes an #AC exception to be issued instead of suppressing LOCK on bus(during split lock access).

Quoted 6 lines

This should be a CPU feature, not a machine feature. As mentioned in the review of the kernel patch, please work with Robert to use the same infrastructure for both MSR_TEST_CTL and MSR_IA32_ARCH_CAPABILITIES.

(Robert, does IceLake have this feature? If so, we cannot create the CPU model until everything is in place).

I don't think we need to block the CPU model because QEMU+KVM doesn't support some features yet, as long as kernel versions capable of running the 3.0 version of IceLake-Server will be also capable of running the 3.1 version of IceLake-Server.

Now, if that condition won't be true and we have some IceLake features that will added only to more recent kernels, it might be a good idea to hold the inclusion of the CPU model until everything is in place.

Quoted 3 lines

BTW, why is the availability of the feature not exposed with a CPUID bit? It doesn't make much sense.

I have the same question. Without a CPUID bit, guests may block the VM from being migrated to older hosts because the additional section for the MSR will appear.

Signature · 1 line
Eduardo
#3 lore raw
Quoted 7 lines · Eduardo Habkost
Quoted 2 lines

(Robert, does IceLake have this feature? If so, we cannot create the CPU model until everything is in place).

I don't think we need to block the CPU model because QEMU+KVM doesn't support some features yet, as long as kernel versions capable of running the 3.0 version of IceLake-Server will be also capable of running the 3.1 version of IceLake-Server.

Quoted 6 lines

Now, if that condition won't be true and we have some IceLake features that will added only to more recent kernels, it might be a good idea to hold the inclusion of the CPU model until everything is in place.

Yeah, the reason for that is to wait for the kernel side of the implementation.

Paolo

#4 lore raw
In reply to Paolo Bonzini

Best Regards,
Robert Hoo

Quoted 20 lines

-----Original Message-----
From: Paolo Bonzini <[email protected]>
Sent: Wednesday, July 4, 2018 21:39
To: Liu, Jingqi <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; qemu- [email protected]; Wang, Wei W <[email protected]>; Hu, Robert <[email protected]>
Subject: Re: [PATCH] kvm: x86: Add support for -machine split-lock-ac

Quoted 9 lines · Jingqi Liu

Add the option split-lock-ac to control whether the #AC exception is generated for split locked accesses, which is introduced for the machine, there is an example to enable it:
-machine split-lock-ac=on
It is disabled on default.

When bit 29 of the MSR (33H) is set, the processor causes an #AC exception to be issued instead of suppressing LOCK on bus(during split lock access).

Quoted 6 lines

This should be a CPU feature, not a machine feature. As mentioned in the review of the kernel patch, please work with Robert to use the same infrastructure for both MSR_TEST_CTL and MSR_IA32_ARCH_CAPABILITIES.

(Robert, does IceLake have this feature? If so, we cannot create the CPU model until everything is in place).

[Robert Hoo]
Hi Paolo,
This is not an Icelake feature.

Quoted 123 lines

BTW, why is the availability of the feature not exposed with a CPUID bit? It doesn't make much sense.

Paolo

hw/core/machine.c static void machine_set_memory_encryption(Object

Quoted 36 lines
---
 accel/kvm/kvm-all.c       | 10 ++++++++++
 hw/core/machine.c         | 19 +++++++++++++++++++
 include/hw/boards.h       |  1 +
 linux-headers/linux/kvm.h |  1 +
 qemu-options.hx           |  3 +++
 5 files changed, 34 insertions(+)
accel/kvm/kvm-all.c index renamed from accel/kvm/kvm-all.c +0 -0

eb7db92..e960a4d 100644

accel/kvm/kvm-all.c +10 -0
@@ -1699,6 +1699,16 @@ static int kvm_init(MachineState *ms)
 
     s->sync_mmu = !!kvm_vm_check_extension(kvm_state,
 KVM_CAP_SYNC_MMU);
 
+    if (ms->split_lock_ac &&
+        kvm_check_extension(s, KVM_CAP_X86_SPLIT_LOCK_AC)) {
+        ret = kvm_vm_enable_cap(s, KVM_CAP_X86_SPLIT_LOCK_AC, 0);
+        if (ret) {
+            fprintf(stderr, "Could not enable the feature that #AC exception"
+                    "will be generated for split lock accesses!\n");
+            goto err;
+        }
+    }
+
     return 0;
 

err:

hw/core/machine.c index renamed from hw/core/machine.c +0 -0

617e5f8..e054119 100644

hw/core/machine.c +0 -0
@@ -350,6 +350,22 @@ static void machine_set_memory_encryption(Object

*obj, const char *value,

Quoted 46 lines
hw/core/machine.c +17 -1
     ms->memory_encryption = g_strdup(value);  }
 
+static void machine_set_split_lock_ac(Object *obj, bool value,
+                                      Error **errp) {
+    MachineState *ms = MACHINE(obj);
+
+    ms->split_lock_ac = value;
+}
+
+static bool machine_get_split_lock_ac(Object *obj, Error **errp) {
+    MachineState *ms = MACHINE(obj);
+
+    return ms->split_lock_ac;
+}
+
+
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const
 char *type)  {
     strList *item = g_new0(strList, 1); @@ -634,6 +650,9 @@ static
 void machine_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "memory-encryption",
         "Set memory encyption object to use", &error_abort);
+    object_class_property_add_bool(oc, "split-lock-ac",
+        machine_get_split_lock_ac, machine_set_split_lock_ac,
+        &error_abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data) diff
--git a/include/hw/boards.h b/include/hw/boards.h index

79069dd..9c1e2c0 100644

include/hw/boards.h +1 -0
@@ -256,6 +256,7 @@ struct MachineState {
     bool suppress_vmdesc;
     bool enforce_config_section;
     bool enable_graphics;
+    bool split_lock_ac;
     char *memory_encryption;
     DeviceMemoryState *device_memory;
 
linux-headers/linux/kvm.h +0 -0
index 98f389a..4bfa879 100644
@@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {  #define
Quoted 1 line

KVM_CAP_GET_MSR_FEATURES 153 #define KVM_CAP_HYPERV_EVENTFD

154

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 45

Quoted 12 lines

#define KVM_CAP_HYPERV_TLBFLUSH 155

linux-headers/linux/kvm.h +1 -0
+#define KVM_CAP_X86_SPLIT_LOCK_AC 156
 
 #ifdef KVM_CAP_IRQ_ROUTING
qemu-options.hx index 81b1e99..935cefe renamed from qemu-options.hx +0 -0

100644

qemu-options.hx +0 -0
@@ -44,6 +44,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
     "                enforce-config-section=on|off enforce configuration section

migration (default=off)\n"

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 46

Quoted 1 line
qemu-options.hx +0 -0
     "                s390-squash-mcss=on|off (deprecated) controls support for

squashing into default css (default=off)\n"

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 47

Quoted 1 line
qemu-options.hx +1 -0
+    "                split-lock-ac=on|off controls support #AC exception for split

locked accesses (default=off)\n"

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 48

Quoted 1 line
qemu-options.hx +0 -0
     "                memory-encryption=@var{} memory encryption object to use

(default=none)\n",

qemu-options.hx NOTE: this parameter is deprecated. Please use · line 114

Quoted 4 lines
qemu-options.hx +0 -0
     QEMU_ARCH_ALL)
 STEXI
@@ -113,6 +114,8 @@ NOTE: this parameter is deprecated. Please use
 @option{-global}  @option{migration.send-configuration}=@var{on|off}

instead.

Quoted 8 lines
qemu-options.hx +2 -0
 @item memory-encryption=@var{}
 Memory encryption object to use. The default is none.
+@item split-lock-ac=on|off
+Enables or disables #AC exception for split locked accesses.
 @end table
 ETEXI
 
#5 lore raw
Quoted 10 lines · Robert
Quoted 6 lines

This should be a CPU feature, not a machine feature. As mentioned in the review of the kernel patch, please work with Robert to use the same infrastructure for both MSR_TEST_CTL and MSR_IA32_ARCH_CAPABILITIES.

(Robert, does IceLake have this feature? If so, we cannot create the CPU model until everything is in place).

[Robert Hoo]
Hi Paolo,
This is not an Icelake feature.

So why is Intel pushing operating system code for half-baked features? This "MSRs are the new CPUID" attitude must stop.

Paolo

Quoted 123 lines
Quoted 122 lines

BTW, why is the availability of the feature not exposed with a CPUID bit? It doesn't make much sense.

Paolo

hw/core/machine.c static void machine_set_memory_encryption(Object

Quoted 36 lines
---
 accel/kvm/kvm-all.c       | 10 ++++++++++
 hw/core/machine.c         | 19 +++++++++++++++++++
 include/hw/boards.h       |  1 +
 linux-headers/linux/kvm.h |  1 +
 qemu-options.hx           |  3 +++
 5 files changed, 34 insertions(+)
accel/kvm/kvm-all.c index renamed from accel/kvm/kvm-all.c +0 -0

eb7db92..e960a4d 100644

accel/kvm/kvm-all.c +10 -0
@@ -1699,6 +1699,16 @@ static int kvm_init(MachineState *ms)
 
     s->sync_mmu = !!kvm_vm_check_extension(kvm_state,
 KVM_CAP_SYNC_MMU);
 
+    if (ms->split_lock_ac &&
+        kvm_check_extension(s, KVM_CAP_X86_SPLIT_LOCK_AC)) {
+        ret = kvm_vm_enable_cap(s, KVM_CAP_X86_SPLIT_LOCK_AC, 0);
+        if (ret) {
+            fprintf(stderr, "Could not enable the feature that #AC exception"
+                    "will be generated for split lock accesses!\n");
+            goto err;
+        }
+    }
+
     return 0;
 

err:

hw/core/machine.c index renamed from hw/core/machine.c +0 -0

617e5f8..e054119 100644

hw/core/machine.c +0 -0
@@ -350,6 +350,22 @@ static void machine_set_memory_encryption(Object

*obj, const char *value,

Quoted 46 lines
hw/core/machine.c +17 -1
     ms->memory_encryption = g_strdup(value);  }
 
+static void machine_set_split_lock_ac(Object *obj, bool value,
+                                      Error **errp) {
+    MachineState *ms = MACHINE(obj);
+
+    ms->split_lock_ac = value;
+}
+
+static bool machine_get_split_lock_ac(Object *obj, Error **errp) {
+    MachineState *ms = MACHINE(obj);
+
+    return ms->split_lock_ac;
+}
+
+
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const
 char *type)  {
     strList *item = g_new0(strList, 1); @@ -634,6 +650,9 @@ static
 void machine_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "memory-encryption",
         "Set memory encyption object to use", &error_abort);
+    object_class_property_add_bool(oc, "split-lock-ac",
+        machine_get_split_lock_ac, machine_set_split_lock_ac,
+        &error_abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data) diff
--git a/include/hw/boards.h b/include/hw/boards.h index

79069dd..9c1e2c0 100644

include/hw/boards.h +1 -0
@@ -256,6 +256,7 @@ struct MachineState {
     bool suppress_vmdesc;
     bool enforce_config_section;
     bool enable_graphics;
+    bool split_lock_ac;
     char *memory_encryption;
     DeviceMemoryState *device_memory;
 
linux-headers/linux/kvm.h +0 -0
index 98f389a..4bfa879 100644
@@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {  #define
Quoted 1 line

KVM_CAP_GET_MSR_FEATURES 153 #define KVM_CAP_HYPERV_EVENTFD

154

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 45

Quoted 12 lines

#define KVM_CAP_HYPERV_TLBFLUSH 155

linux-headers/linux/kvm.h +1 -0
+#define KVM_CAP_X86_SPLIT_LOCK_AC 156
 
 #ifdef KVM_CAP_IRQ_ROUTING
qemu-options.hx index 81b1e99..935cefe renamed from qemu-options.hx +0 -0

100644

qemu-options.hx +0 -0
@@ -44,6 +44,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
     "                enforce-config-section=on|off enforce configuration section

migration (default=off)\n"

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 46

Quoted 1 line
qemu-options.hx +0 -0
     "                s390-squash-mcss=on|off (deprecated) controls support for

squashing into default css (default=off)\n"

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 47

Quoted 1 line
qemu-options.hx +1 -0
+    "                split-lock-ac=on|off controls support #AC exception for split

locked accesses (default=off)\n"

qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 48

Quoted 1 line
qemu-options.hx +0 -0
     "                memory-encryption=@var{} memory encryption object to use

(default=none)\n",

qemu-options.hx NOTE: this parameter is deprecated. Please use · line 114

Quoted 4 lines
qemu-options.hx +0 -0
     QEMU_ARCH_ALL)
 STEXI
@@ -113,6 +114,8 @@ NOTE: this parameter is deprecated. Please use
 @option{-global}  @option{migration.send-configuration}=@var{on|off}

instead.

Quoted 8 lines
qemu-options.hx +2 -0
 @item memory-encryption=@var{}
 Memory encryption object to use. The default is none.
+@item split-lock-ac=on|off
+Enables or disables #AC exception for split locked accesses.
 @end table
 ETEXI