Skip to contentSkip to conversation

QEMU kvm: Adding paravirtual spinlock support for x86.

PATCH In review Raghavendra K T 2 participants 6 messages Mar 23, 2012 KVM

lore
Share & tools
lore
#0 lore raw

cover QEMU kvm: Adding paravirtual spinlock support for x86.

The patch, extends KVM-hypervisor and Linux guest running on KVM-hypervisor to support pv-ticket spinlocks.

PV ticket spinlock helps to solve Lock Holder Preemption problem discussed in
http://www.amd64.org/fileadmin/user_upload/pub/LHP-commented_slides.pdf.

When spinlock is contended,a guest vcpu relinqueshes cpu by halt(). Correspondingly, One hypercall is introduced in KVM hypervisor,that allows a vcpu to kick the halted vcpu to continue with execution.

Note:
Below patch should be applied only after corresponding
linux-header changes taken into qemu via scripts/update-linux-headers.sh script.
---
Changes in V3:

 rename PVLOCK_KICK --> PV_UNHALT

add MSR related changes to aid migration

Changes in V2:
Drop the syncing kernel header changes. (Alex)

 rename KICK_VCPU --> PVLOCK_KICK.

Raghavendra K T(2):
add PV_UNHALT feature support.
add support to get/set vcpu unhalt msr to aid migration

 target-i386/cpu.h |    1 +
 target-i386/kvm.c |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

V5 Kernel changes:
https://lkml.org/lkml/2012/3/23/50

V4 kernel changes:
https://lkml.org/lkml/2012/1/14/66
Qemu changes for V4:
http://www.mail-archive.com/[email protected]/msg66450.html

V3 kernel Changes:
https://lkml.org/lkml/2011/11/30/62
V2 kernel changes :
https://lkml.org/lkml/2011/10/23/207

Previous discussions : (posted by Srivatsa V).
https://lkml.org/lkml/2010/7/26/24
https://lkml.org/lkml/2011/1/19/212

Qemu patch for V3:
http://lists.gnu.org/archive/html/qemu-devel/2011-12/msg00397.html

#1 lore raw

PATCH 1/2 QEMU kvm: Add PV_UNHALT feature support

From: Raghavendra K T <[email protected]>

Extend the KVM Hypervisor to enable PVLOCK_KICK feature that allows a vcpu to kick the halted vcpu to continue with execution in PV ticket spinlock.

---

target-i386/kvm.c +1 -0
index e74a9e4..dbebd3a 100644
@@ -98,6 +98,7 @@ struct kvm_para_features {
     { KVM_CAP_NOP_IO_DELAY, KVM_FEATURE_NOP_IO_DELAY },
     { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
     { KVM_CAP_ASYNC_PF, KVM_FEATURE_ASYNC_PF },
+    { KVM_CAP_PV_UNHALT, KVM_FEATURE_PV_UNHALT },
     { -1, -1 }
 };
 
#2 lore raw

PATCH 2/2 QEMU kvm: Add support to get/set vcpu unhalt msr to aid migration

In reply to Raghavendra K T

From: Raghavendra K T <[email protected]>

MSR_KVM_PV_UNHALT tells whether vcpu is unhalted, which needs to be used during migration.

---

target-i386/cpu.h +1 -0
index a1ed3e7..10286a5 100644
@@ -697,6 +697,7 @@ typedef struct CPUX86State {
     uint64_t system_time_msr;
     uint64_t wall_clock_msr;
     uint64_t async_pf_en_msr;
+    uint64_t pv_unhalt_msr;
 
     uint64_t tsc;
     uint64_t tsc_deadline;
target-i386/kvm.c +12 -1
index dbebd3a..98b9088 100644
@@ -62,6 +62,7 @@ static bool has_msr_star;
 static bool has_msr_hsave_pa;
 static bool has_msr_tsc_deadline;
 static bool has_msr_async_pf_en;
+static bool has_msr_pv_unhalt;
 static bool has_msr_misc_enable;
 static int lm_capable_kernel;
 
@@ -444,7 +445,7 @@ int kvm_arch_init_vcpu(CPUX86State *env)
     }
 
     has_msr_async_pf_en = c->eax & (1 << KVM_FEATURE_ASYNC_PF);
-
+    has_msr_pv_unhalt = c->eax & (1 << KVM_FEATURE_PV_UNHALT);
     cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused);
 
     for (i = 0; i <= limit; i++) {
@@ -1012,6 +1013,10 @@ static int kvm_put_msrs(CPUX86State *env, int level)
         if (hyperv_vapic_recommended()) {
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
         }
+        if (has_msr_pv_unhalt) {
+            kvm_msr_entry_set(&msrs[n++], MSR_KVM_PV_UNHALT,
+                              env->pv_unhalt_msr);
+        }
     }
     if (env->mcg_cap) {
         int i;
@@ -1247,6 +1252,9 @@ static int kvm_get_msrs(CPUX86State *env)
     if (has_msr_async_pf_en) {
         msrs[n++].index = MSR_KVM_ASYNC_PF_EN;
     }
+    if (has_msr_pv_unhalt) {
+        msrs[n++].index = MSR_KVM_PV_UNHALT;
+    }
 
     if (env->mcg_cap) {
         msrs[n++].index = MSR_MCG_STATUS;
@@ -1326,6 +1334,9 @@ static int kvm_get_msrs(CPUX86State *env)
         case MSR_KVM_ASYNC_PF_EN:
             env->async_pf_en_msr = msrs[i].data;
             break;
+        case MSR_KVM_PV_UNHALT:
+            env->pv_unhalt_msr = msrs[i].data;
+            break;
         }
     }
 
#3 lore raw

Re: [PATCH 2/2] QEMU kvm: Add support to get/set vcpu unhalt msr to aid migration

Quoted 4 lines · Raghavendra K T

From: Raghavendra K T <[email protected]>

MSR_KVM_PV_UNHALT tells whether vcpu is unhalted, which needs to be used during migration.

Err, and where is it actually saved to/restored from the vmstate? You are lacking an extension of the CPU vmstate, preferably via a substate. See e.g. cpu/async_pf_msr.

Quoted 59 lines

---

target-i386/cpu.h +1 -0
index a1ed3e7..10286a5 100644
@@ -697,6 +697,7 @@ typedef struct CPUX86State {
     uint64_t system_time_msr;
     uint64_t wall_clock_msr;
     uint64_t async_pf_en_msr;
+    uint64_t pv_unhalt_msr;
 
     uint64_t tsc;
     uint64_t tsc_deadline;
target-i386/kvm.c +9 -1
index dbebd3a..98b9088 100644
@@ -62,6 +62,7 @@ static bool has_msr_star;
 static bool has_msr_hsave_pa;
 static bool has_msr_tsc_deadline;
 static bool has_msr_async_pf_en;
+static bool has_msr_pv_unhalt;
 static bool has_msr_misc_enable;
 static int lm_capable_kernel;
 
@@ -444,7 +445,7 @@ int kvm_arch_init_vcpu(CPUX86State *env)
     }
 
     has_msr_async_pf_en = c->eax & (1 << KVM_FEATURE_ASYNC_PF);
-
+    has_msr_pv_unhalt = c->eax & (1 << KVM_FEATURE_PV_UNHALT);
     cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused);
 
     for (i = 0; i <= limit; i++) {
@@ -1012,6 +1013,10 @@ static int kvm_put_msrs(CPUX86State *env, int level)
         if (hyperv_vapic_recommended()) {
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
         }
+        if (has_msr_pv_unhalt) {
+            kvm_msr_entry_set(&msrs[n++], MSR_KVM_PV_UNHALT,
+                              env->pv_unhalt_msr);
+        }
     }
     if (env->mcg_cap) {
         int i;
@@ -1247,6 +1252,9 @@ static int kvm_get_msrs(CPUX86State *env)
     if (has_msr_async_pf_en) {
         msrs[n++].index = MSR_KVM_ASYNC_PF_EN;
     }
+    if (has_msr_pv_unhalt) {
+        msrs[n++].index = MSR_KVM_PV_UNHALT;
+    }
 
     if (env->mcg_cap) {
         msrs[n++].index = MSR_MCG_STATUS;

target-i386/kvm.c static int kvm_get_msrs(CPUX86State *env) · line 1342

Quoted 9 lines
target-i386/kvm.c +3 -0
@@ -1326,6 +1334,9 @@ static int kvm_get_msrs(CPUX86State *env)
         case MSR_KVM_ASYNC_PF_EN:
             env->async_pf_en_msr = msrs[i].data;
             break;
+        case MSR_KVM_PV_UNHALT:
+            env->pv_unhalt_msr = msrs[i].data;
+            break;
         }
     }
 

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#4 lore raw

Re: [PATCH 2/2] QEMU kvm: Add support to get/set vcpu unhalt msr to aid migration

Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Raghavendra K T

From: Raghavendra K T<[email protected]>

MSR_KVM_PV_UNHALT tells whether vcpu is unhalted, which needs to be used during migration.

Err, and where is it actually saved to/restored from the vmstate? You are lacking an extension of the CPU vmstate, preferably via a substate. See e.g. cpu/async_pf_msr.

Thanks Jan for review, I 'll check that.

#5 lore raw

Re: [PATCH 2/2] QEMU kvm: Add support to get/set vcpu unhalt msr to aid migration

In reply to Jan Kiszka
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Raghavendra K T

From: Raghavendra K T<[email protected]>

MSR_KVM_PV_UNHALT tells whether vcpu is unhalted, which needs to be used during migration.

Err, and where is it actually saved to/restored from the vmstate? You are lacking an extension of the CPU vmstate, preferably via a substate. See e.g. cpu/async_pf_msr.

Please let me know whether adding below patch make it complete. Or did I miss something else ?

---

target-i386/machine.c +21 -0
index a8be058..c51d8d1 100644
@@ -279,6 +279,13 @@ static bool async_pf_msr_needed(void *opaque)
     return cpu->async_pf_en_msr != 0;
 }
 
+static bool pv_unhalt_msr_needed(void *opaque)
+{
+    CPUX86State *cpu = opaque;
+
+    return cpu->pv_unhalt_msr != 0;
+}
+
 static const VMStateDescription vmstate_async_pf_msr = {
     .name = "cpu/async_pf_msr",
     .version_id = 1,
@@ -290,6 +297,17 @@ static const VMStateDescription vmstate_async_pf_msr = {
     }
 };
 
+static const VMStateDescription vmstate_pv_unhalt_msr = {
+    .name = "cpu/pv_unhalt_msr",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT64(pv_unhalt_msr, CPUX86State),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static bool fpop_ip_dp_needed(void *opaque)
 {
     CPUX86State *env = opaque;
@@ -462,6 +480,9 @@ static const VMStateDescription vmstate_cpu = {
         }, {
             .vmsd = &vmstate_msr_ia32_misc_enable,
             .needed = misc_enable_needed,
+        }, {
+            .vmsd = &vmstate_pv_unhalt_msr,
+            .needed = pv_unhalt_msr_needed,
         } , {
             /* empty */
         }