Skip to contentSkip to conversation

KVM pull request: Various fixes and cleanups

PATCH In review Jan Kiszka 4 participants 20 messages Feb 3, 2010 – Feb 8, 2010 KVM

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

cover KVM pull request: Various fixes and cleanups

As discussed in http://www.spinics.net/lists/kvm/msg28517.html, this is the first part of the KVM upstream patches developed while cleaning up qemu-kvm.

Please pull from

git://git.kiszka.org/qemu.git queues/kvm

Jan Kiszka (4):
KVM: x86: Fix up misreported CPU features
KVM: Make vmport KVM-compatible
KVM: Move and rename regs_modified
KVM: Rework of guest debug state writing

 cpu-defs.h        |    3 ++-
 hw/vmport.c       |    3 +++
 kvm-all.c         |   21 ++++++++-------------
 target-i386/cpu.h |    9 ++++++++-
 target-i386/kvm.c |   19 ++++++++++++++++++-
 5 files changed, 39 insertions(+), 16 deletions(-)
author
#1 lore raw

PATCH 1/4 KVM: x86: Fix up misreported CPU features

Quoted 1 line

From qemu-kvm: Kernels before 2.6.30 misreported some essential CPU

features via KVM_GET_SUPPORTED_CPUID. Fix them up.

---
 target-i386/kvm.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
target-i386/kvm.c +7 -1
index 5b093ce..f690b2e 100644
@@ -99,12 +99,18 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg)
                 break;
             case R_EDX:
                 ret = cpuid->entries[i].edx;
-                if (function == 0x80000001) {
+                switch (function) {
+                case 1:
+                    /* KVM before 2.6.30 misreports the following features */
+                    ret |= CPUID_MTRR | CPUID_PAT | CPUID_MCE | CPUID_MCA;
+                    break;
+                case 0x80000001:
                     /* On Intel, kvm returns cpuid according to the Intel spec,
                      * so add missing bits according to the AMD spec:
                      */
                     cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, R_EDX);
                     ret |= cpuid_1_edx & 0xdfeff7ff;
+                    break;
                 }
                 break;
             }
Signature · 1 line
1.6.0.2
author
#2 lore raw

PATCH 2/4 KVM: Make vmport KVM-compatible

In reply to Jan Kiszka

The vmport "device" accesses the VCPU registers, so it requires proper cpu_synchronize_state. Add it to vmport_ioport_read, which also synchronizes vmport_ioport_write.

---
 hw/vmport.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/vmport.c +3 -0
index 884af3f..6c9d7c9 100644
@@ -25,6 +25,7 @@
 #include "isa.h"
 #include "pc.h"
 #include "sysemu.h"
+#include "kvm.h"
 
 //#define VMPORT_DEBUG
 
@@ -58,6 +59,8 @@ static uint32_t vmport_ioport_read(void *opaque, uint32_t addr)
     unsigned char command;
     uint32_t eax;
 
+    cpu_synchronize_state(env);
+
     eax = env->regs[R_EAX];
     if (eax != VMPORT_MAGIC)
         return eax;
Signature · 1 line
1.6.0.2
author
#3 lore raw

PATCH 3/4 KVM: Move and rename regs_modified

In reply to Jan Kiszka

Touching the user space representation of KVM's VCPU state is - naturally - a per-VCPU thing. So move the dirty flag into KVM_CPU_COMMON and rename it at this chance to reflect its true meaning.

---
 cpu-defs.h |    3 ++-
 kvm-all.c  |   13 ++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)
cpu-defs.h +2 -1
index 95068b5..7fdbe97 100644
@@ -197,6 +197,7 @@ typedef struct CPUWatchpoint {
     const char *cpu_model_str;                                          \
     struct KVMState *kvm_state;                                         \
     struct kvm_run *kvm_run;                                            \
-    int kvm_fd;
+    int kvm_fd;                                                         \
+    int kvm_vcpu_dirty;
 
 #endif
kvm-all.c +6 -7
index 15ec38e..67b44b5 100644
@@ -57,7 +57,6 @@ struct KVMState
     KVMSlot slots[32];
     int fd;
     int vmfd;
-    int regs_modified;
     int coalesced_mmio;
     int broken_set_mem_region;
     int migration_log;
@@ -567,9 +566,9 @@ static void kvm_run_coalesced_mmio(CPUState *env, struct kvm_run *run)
 
 void kvm_cpu_synchronize_state(CPUState *env)
 {
-    if (!env->kvm_state->regs_modified) {
+    if (!env->kvm_vcpu_dirty) {
         kvm_arch_get_registers(env);
-        env->kvm_state->regs_modified = 1;
+        env->kvm_vcpu_dirty = 1;
     }
 }
 
@@ -587,9 +586,9 @@ int kvm_cpu_exec(CPUState *env)
             break;
         }
 
-        if (env->kvm_state->regs_modified) {
+        if (env->kvm_vcpu_dirty) {
             kvm_arch_put_registers(env);
-            env->kvm_state->regs_modified = 0;
+            env->kvm_vcpu_dirty = 0;
         }
 
         kvm_arch_pre_run(env, run);
@@ -939,9 +938,9 @@ static void kvm_invoke_set_guest_debug(void *data)
     struct kvm_set_guest_debug_data *dbg_data = data;
     CPUState *env = dbg_data->env;
 
-    if (env->kvm_state->regs_modified) {
+    if (env->kvm_vcpu_dirty) {
         kvm_arch_put_registers(env);
-        env->kvm_state->regs_modified = 0;
+        env->kvm_vcpu_dirty = 0;
     }
     dbg_data->err = kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, &dbg_data->dbg);
 }
Signature · 1 line
1.6.0.2
author
#4 lore raw

PATCH 4/4 KVM: Rework of guest debug state writing

In reply to Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

---
 kvm-all.c         |   12 ++++--------
 target-i386/cpu.h |    9 ++++++++-
 target-i386/kvm.c |   11 +++++++++++
 3 files changed, 23 insertions(+), 9 deletions(-)
kvm-all.c +4 -8
index 67b44b5..f3e09c8 100644
@@ -938,10 +938,6 @@ static void kvm_invoke_set_guest_debug(void *data)
     struct kvm_set_guest_debug_data *dbg_data = data;
     CPUState *env = dbg_data->env;
 
-    if (env->kvm_vcpu_dirty) {
-        kvm_arch_put_registers(env);
-        env->kvm_vcpu_dirty = 0;
-    }
     dbg_data->err = kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, &dbg_data->dbg);
 }
 
@@ -949,12 +945,12 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap)
 {
     struct kvm_set_guest_debug_data data;
 
-    data.dbg.control = 0;
-    if (env->singlestep_enabled)
-        data.dbg.control = KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
+    data.dbg.control = reinject_trap;
 
+    if (env->singlestep_enabled) {
+        data.dbg.control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
+    }
     kvm_arch_update_guest_debug(env, &data.dbg);
-    data.dbg.control |= reinject_trap;
     data.env = env;
 
     on_vcpu(env, kvm_invoke_set_guest_debug, &data);
target-i386/cpu.h +8 -1
index 216b00e..dfc4a26 100644
@@ -21,6 +21,10 @@
 
 #include "config.h"
 
+#ifdef CONFIG_KVM
+#include <linux/kvm.h>  /* for kvm_guest_debug */
+#endif
+
 #ifdef TARGET_X86_64
 #define TARGET_LONG_BITS 64
 #else
@@ -702,7 +706,10 @@ typedef struct CPUX86State {
     uint8_t has_error_code;
     uint32_t sipi_vector;
     uint32_t cpuid_kvm_features;
-    
+#if defined(CONFIG_KVM) && defined(KVM_CAP_SET_GUEST_DEBUG)
+    struct kvm_guest_debug kvm_guest_debug;
+#endif
+
     /* in order to simplify APIC support, we leave this pointer to the
        user */
     struct APICState *apic_state;
target-i386/kvm.c +11 -0
index f690b2e..2b3d8f6 100644
@@ -851,6 +851,15 @@ int kvm_arch_put_registers(CPUState *env)
     if (ret < 0)
         return ret;
 
+    /*
+     * Kernels before 2.6.33 overwrote flags.TF injected via SET_GUEST_DEBUG
+     * while updating GP regs. Work around this by updating the debug state
+     * once again.
+     */
+    ret = kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, &env->kvm_guest_debug);
+    if (ret < 0)
+        return ret;
+
     ret = kvm_put_fpu(env);
     if (ret < 0)
         return ret;
@@ -1147,5 +1156,7 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg)
                 (len_code[hw_breakpoint[n].len] << (18 + n*4));
         }
     }
+    /* Keep a copy for the writeback workaround in kvm_arch_put_registers */
+    memcpy(&env->kvm_guest_debug, dbg, sizeof(env->kvm_guest_debug));
 }
 #endif /* KVM_CAP_SET_GUEST_DEBUG */
Signature · 1 line
1.6.0.2
#5 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Jan,

This patch breaks migration.

#6 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 10 lines · Marcelo Tosatti
Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Jan,

This patch breaks migration.

Can you elaborate what you did? I can't reproduce, and I do not see any conceptual issue (given that guest debugging conflicts with migration anyway).

Jan

#7 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Marcelo Tosatti
Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Quoted 7 lines
Quoted 3 lines

Jan,

This patch breaks migration.

Can you elaborate what you did? I can't reproduce, and I do not see any conceptual issue (given that guest debugging conflicts with migration anyway).

kvm-autotest fails (migration only, install is ok, both Linux and Win guests). Not sure why, perhaps the unconditional KVM_SET_GUEST_DEBUG corrupts state somehow?

Tested with io thread enabled.

author
#8 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 15 lines · Marcelo Tosatti
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Marcelo Tosatti
Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Quoted 6 lines
Quoted 3 lines

Jan,

This patch breaks migration.

Can you elaborate what you did? I can't reproduce, and I do not see any conceptual issue (given that guest debugging conflicts with migration anyway).

Quoted 5 lines

kvm-autotest fails (migration only, install is ok, both Linux and Win guests). Not sure why, perhaps the unconditional KVM_SET_GUEST_DEBUG corrupts state somehow?

Tested with io thread enabled.

That's this default-off thing, so... OK, confirmed, investigating.

Jan

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

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Marcelo Tosatti
Quoted 13 lines · Jan Kiszka
Quoted 9 lines · Marcelo Tosatti
Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Jan,

This patch breaks migration.

Can you elaborate what you did? I can't reproduce, and I do not see any conceptual issue (given that guest debugging conflicts with migration anyway).

Quoted 8 lines
Quoted 5 lines

kvm-autotest fails (migration only, install is ok, both Linux and Win guests). Not sure why, perhaps the unconditional KVM_SET_GUEST_DEBUG corrupts state somehow?

Tested with io thread enabled.

That's this default-off thing, so... OK, confirmed, investigating.

Heisenbug: It first also popped up (in form of a frozen migration target) after removing this patch, but now it's totally unreproducible, whatever patch I apply or revert from my series. Base is current master. I tend to think there is a hidden issue of iothread vs. migration, unrelated to this patch.

Jan

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

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 25 lines · Jan Kiszka
Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Marcelo Tosatti
Quoted 13 lines · Jan Kiszka
Quoted 9 lines · Marcelo Tosatti
Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Jan,

This patch breaks migration.

Can you elaborate what you did? I can't reproduce, and I do not see any conceptual issue (given that guest debugging conflicts with migration anyway).

Quoted 8 lines
Quoted 5 lines

kvm-autotest fails (migration only, install is ok, both Linux and Win guests). Not sure why, perhaps the unconditional KVM_SET_GUEST_DEBUG corrupts state somehow?

Tested with io thread enabled.

That's this default-off thing, so... OK, confirmed, investigating.

Quoted 6 lines

Heisenbug: It first also popped up (in form of a frozen migration target) after removing this patch, but now it's totally unreproducible, whatever patch I apply or revert from my series. Base is current master.

I tend to think there is a hidden issue of iothread vs. migration, unrelated to this patch.

Probably many :)

Do you have c5f32c99c6855d466737daf1cd262e7e92062f87 (from qemu-kvm.git uq/master) in?

With kvm-autotest the failure is not sporadic (and the above commit applied): with KVM_SET_GUEST_DEBUG in arch_put_regs all migration tests fail, without, all of them succeed.

So env->kvm_guest_debug has been zeroed by cpu_x86_init, which means the writeback via KVM_SET_GUEST_DEBUG does almost nothing. It does get_rflags and set_rflags in the kernel.

Test box is off, but the synchronous writeback via qemu_system_reset in main, after machine and vcpu thread initialization, might be problematic. But it would be nice to understand this.

Unrelated to this problem, won't put_vcpu_events, which is executed after KVM_SET_GUEST_DEBUG, overwrite any queued debug exceptions?

author
#11 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 28 lines · Marcelo Tosatti
Quoted 27 lines · Jan Kiszka
Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Marcelo Tosatti
Quoted 13 lines · Jan Kiszka
Quoted 9 lines · Marcelo Tosatti
Quoted 5 lines · Jan Kiszka

So far we synchronized any dirty VCPU state back into the kernel before updating the guest debug state. This was a tribute to a deficit in x86 kernels before 2.6.33. But as this is an arch-dependent issue, it is better handle in the x86 part of KVM and remove the writeback point for generic code.

Jan,

This patch breaks migration.

Can you elaborate what you did? I can't reproduce, and I do not see any conceptual issue (given that guest debugging conflicts with migration anyway).

Quoted 7 lines
Quoted 5 lines

kvm-autotest fails (migration only, install is ok, both Linux and Win guests). Not sure why, perhaps the unconditional KVM_SET_GUEST_DEBUG corrupts state somehow?

Tested with io thread enabled.

That's this default-off thing, so... OK, confirmed, investigating.

Heisenbug: It first also popped up (in form of a frozen migration target) after removing this patch, but now it's totally unreproducible, whatever patch I apply or revert from my series. Base is current master.

Quoted 7 lines
Quoted 2 lines

I tend to think there is a hidden issue of iothread vs. migration, unrelated to this patch.

Probably many :)

Do you have c5f32c99c6855d466737daf1cd262e7e92062f87 (from qemu-kvm.git uq/master) in?

Yes. And that might have been the reason why some early tests failed when it was no yet applied here.

Quoted 8 lines

With kvm-autotest the failure is not sporadic (and the above commit applied): with KVM_SET_GUEST_DEBUG in arch_put_regs all migration tests fail, without, all of them succeed.

So env->kvm_guest_debug has been zeroed by cpu_x86_init, which means the writeback via KVM_SET_GUEST_DEBUG does almost nothing. It does get_rflags and set_rflags in the kernel.

Hmm, it also copies debug regs around... BTW, where do we save/restore dr0..7 between kernel and user space?

But that should not be a problem, both shadow as well as effective regs should be properly initialized, specifically for a newly created VCPU.

Quoted 7 lines

Test box is off, but the synchronous writeback via qemu_system_reset in main, after machine and vcpu thread initialization, might be problematic. But it would be nice to understand this.

Unrelated to this problem, won't put_vcpu_events, which is executed after KVM_SET_GUEST_DEBUG, overwrite any queued debug exceptions?

Good point, SET_GUEST_DEBUG should be last in the writeback for that reason.

Jan

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

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 6 lines · Jan Kiszka
Quoted 3 lines · Marcelo Tosatti

Unrelated to this problem, won't put_vcpu_events, which is executed after KVM_SET_GUEST_DEBUG, overwrite any queued debug exceptions?

Good point, SET_GUEST_DEBUG should be last in the writeback for that reason.

Actually, we no longer need the exception injection via SET_GUEST_DEBUG now that we have full access via vcpu_events. So this needs a cleanup, and I'm afraid quite a few cases are broken ATM with vcpu_events writeback overwriting the reinjected exceptions.

Jan

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

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 6 lines · Jan Kiszka
Quoted 5 lines · Jan Kiszka
Quoted 3 lines · Marcelo Tosatti

Unrelated to this problem, won't put_vcpu_events, which is executed after KVM_SET_GUEST_DEBUG, overwrite any queued debug exceptions?

Quoted 7 lines
Quoted 1 line

Good point, SET_GUEST_DEBUG should be last in the writeback for that reason.

Actually, we no longer need the exception injection via SET_GUEST_DEBUG now that we have full access via vcpu_events.

So this needs a cleanup, and I'm afraid quite a few cases are broken ATM with vcpu_events writeback overwriting the reinjected exceptions.

Don't see what you mean here. Can you be more explicit? What breakage?

author
#14 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 5 lines · Marcelo Tosatti
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Jan Kiszka
Quoted 2 lines · Marcelo Tosatti

Unrelated to this problem, won't put_vcpu_events, which is executed after KVM_SET_GUEST_DEBUG, overwrite any queued debug exceptions?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Good point, SET_GUEST_DEBUG should be last in the writeback for that reason.

Actually, we no longer need the exception injection via SET_GUEST_DEBUG now that we have full access via vcpu_events.

So this needs a cleanup, and I'm afraid quite a few cases are broken ATM with vcpu_events writeback overwriting the reinjected exceptions.

Don't see what you mean here. Can you be more explicit? What breakage?

SET_GUEST_DEBUG and SET_VCPU_EVENTS are mutually exclusive. If we have the latter, don't use the former for exception injection anymore. And this is broken already without any of my patches applied, that was my point. Will work on this soon.

Jan

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

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka
Quoted 7 lines · Marcelo Tosatti

With kvm-autotest the failure is not sporadic (and the above commit applied): with KVM_SET_GUEST_DEBUG in arch_put_regs all migration tests fail, without, all of them succeed.

So env->kvm_guest_debug has been zeroed by cpu_x86_init, which means the writeback via KVM_SET_GUEST_DEBUG does almost nothing. It does get_rflags and set_rflags in the kernel.

Quoted 5 lines

Hmm, it also copies debug regs around... BTW, where do we save/restore dr0..7 between kernel and user space?

But that should not be a problem, both shadow as well as effective regs should be properly initialized, specifically for a newly created VCPU.

Could you retry after pushing SET_GUEST_DEBUG at the end of kvm_arch_put_registers? Maybe it is no good idea to run get/set_rflags without having the sregs properly initialized.

Jan

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

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

Quoted 6 lines · Jan Kiszka
Quoted 5 lines · Jan Kiszka
Quoted 4 lines · Marcelo Tosatti

With kvm-autotest the failure is not sporadic (and the above commit applied): with KVM_SET_GUEST_DEBUG in arch_put_regs all migration tests fail, without, all of them succeed.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

So env->kvm_guest_debug has been zeroed by cpu_x86_init, which means the writeback via KVM_SET_GUEST_DEBUG does almost nothing. It does get_rflags and set_rflags in the kernel.

Hmm, it also copies debug regs around... BTW, where do we save/restore dr0..7 between kernel and user space?

They're not.

Quoted 2 lines
Quoted 2 lines

But that should not be a problem, both shadow as well as effective regs should be properly initialized, specifically for a newly created VCPU.

Yep.

Quoted 3 lines

Could you retry after pushing SET_GUEST_DEBUG at the end of kvm_arch_put_registers? Maybe it is no good idea to run get/set_rflags without having the sregs properly initialized.

Will do next week.

Another tricky thing with this is that the definition of whats the kernel job and whats userspace job is somewhat blurry in points. For example set_regs clears pending exceptions, which made sense in the past, but breaks now if userspace does put_vcpu_events before set_regs (which is not the case with current userspace but just an example).

Makes sense to heavily document things as suggested.

#17 lore raw

Re: [PATCH 4/4] KVM: Rework of guest debug state writing

In reply to Jan Kiszka
Quoted 13 lines · Jan Kiszka
Quoted 12 lines · Jan Kiszka
Quoted 7 lines · Marcelo Tosatti

With kvm-autotest the failure is not sporadic (and the above commit applied): with KVM_SET_GUEST_DEBUG in arch_put_regs all migration tests fail, without, all of them succeed.

So env->kvm_guest_debug has been zeroed by cpu_x86_init, which means the writeback via KVM_SET_GUEST_DEBUG does almost nothing. It does get_rflags and set_rflags in the kernel.

Hmm, it also copies debug regs around... BTW, where do we save/restore dr0..7 between kernel and user space?

Quoted 8 lines
Quoted 2 lines

But that should not be a problem, both shadow as well as effective regs should be properly initialized, specifically for a newly created VCPU.

Could you retry after pushing SET_GUEST_DEBUG at the end of kvm_arch_put_registers? Maybe it is no good idea to run get/set_rflags without having the sregs properly initialized.

Jan

Can't reproduce (with the original patch, KVM_SET_GUEST_DEBUG at beginning of arch_put_regs). Different test box though. Go figure.

Anyway, as you mentioned, the workaround can be made cleaner through set_vcpu_events.

#18 lore raw
In reply to Jan Kiszka

Hi Jan,

Thanks for sending this out.

Quoted 4 lines · Jan Kiszka

As discussed in http://www.spinics.net/lists/kvm/msg28517.html, this is the first part of the KVM upstream patches developed while cleaning up qemu-kvm.

I'd prefer if Marcelo/Avi took this first into qemu-kvm.git and then did a pull request for me to pull it into upstream qemu.

I'm also happy to pull from multiple sources but I think the former work flow will do a better job at ensuring that qemu-kvm.git becomes the primary location of this work.

Regards,

Anthony Liguori

Quoted 20 lines

Please pull from

git://git.kiszka.org/qemu.git queues/kvm

Jan Kiszka (4):
KVM: x86: Fix up misreported CPU features
KVM: Make vmport KVM-compatible
KVM: Move and rename regs_modified
KVM: Rework of guest debug state writing

  cpu-defs.h        |    3 ++-
  hw/vmport.c       |    3 +++
  kvm-all.c         |   21 ++++++++-------------
  target-i386/cpu.h |    9 ++++++++-
  target-i386/kvm.c |   19 ++++++++++++++++++-
  5 files changed, 39 insertions(+), 16 deletions(-)
#19 lore raw
Quoted 10 lines · Anthony Liguori

Hi Jan,

Thanks for sending this out.

Quoted 4 lines · Jan Kiszka

As discussed in http://www.spinics.net/lists/kvm/msg28517.html, this is the first part of the KVM upstream patches developed while cleaning up qemu-kvm.

Quoted 7 lines

I'd prefer if Marcelo/Avi took this first into qemu-kvm.git and then did a pull request for me to pull it into upstream qemu.

I'm also happy to pull from multiple sources but I think the former work flow will do a better job at ensuring that qemu-kvm.git becomes the primary location of this work.

Whatever is preferred - but, you all, please decide at some point what you want here. :) This part of the series is easy to push around, but I'm not keen on juggling too much with the heavier parts later on.

Jan