>> It is not, since it also happens with -no-kvm-irqchip, that does not
>> exercise this path.
>> I looked into it today, will look further, but my current impression
>> is that hlt is working fine.
>>
>> It might be the case that the problem lies in any kind of interrupt
>> injection that were supposed to wake it up.
>>
>
> I'm also suspecting that, a patch for Xen sent a few weeks ago solved
> that issue for FreeDOS. Have a look at it here:
> http://xenbits.xensource.com/xen-3.2-testing.hg?rev/6d81a6f6cb21
>
> I have written some code to implement debug exception injection and
> single-step status checking, but it didn't seem to work. I'll post my
> attempt for review in a later post, maybe there was something I was
> missing.
>

OK, here is the code. Please inform me if there is something I am missing.
-----
>> It is not, since it also happens with -no-kvm-irqchip, that does not
>> exercise this path.
>> I looked into it today, will look further, but my current impression
>> is that hlt is working fine.
>>
>> It might be the case that the problem lies in any kind of interrupt
>> injection that were supposed to wake it up.
>>
>
> I'm also suspecting that, a patch for Xen sent a few weeks ago solved
> that issue for FreeDOS. Have a look at it here:
> http://xenbits.xensource.com/xen-3.2-testing.hg?rev/6d81a6f6cb21
>
> I have written some code to implement debug exception injection and
> single-step status checking, but it didn't seem to work. I'll post my
> attempt for review in a later post, maybe there was something I was
> missing.
>

OK, here is the code. Please inform me if I am missing something.

----
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index dd4efe1..8643ee5 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -294,6 +294,7 @@ static u16 group2_table[] = {
 /* EFLAGS bit definitions. */
 #define EFLG_OF (1<<11)
 #define EFLG_DF (1<<10)
+#define EFLG_TF (1<<8)
 #define EFLG_SF (1<<7)
 #define EFLG_ZF (1<<6)
 #define EFLG_AF (1<<4)
@@ -1767,6 +1768,9 @@ writeback:
        if (rc != 0)
                goto done;

+       if (ctxt->eflags & EFLG_TF)
+               kvm_inject_db(ctxt->vcpu,0);
+
        /* Commit shadow register state. */
        memcpy(ctxt->vcpu->arch.regs, c->regs, sizeof c->regs);
        kvm_rip_write(ctxt->vcpu, c->eip);
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 02b88ec..2af18f7 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -56,6 +56,7 @@
 #define KVM_PAGES_PER_HPAGE (KVM_HPAGE_SIZE / PAGE_SIZE)

 #define DE_VECTOR 0
+#define DB_VECTOR 1
 #define UD_VECTOR 6
 #define NM_VECTOR 7
 #define DF_VECTOR 8
@@ -663,6 +664,11 @@ static inline void kvm_inject_gp(struct kvm_vcpu
*vcpu, u32 error_code)
        kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
 }

+static inline void kvm_inject_db(struct kvm_vcpu *vcpu, u32 error_code)
+{
+       kvm_queue_exception_e(vcpu, DB_VECTOR, error_code);
+}
+
 #define ASM_VMX_VMCLEAR_RAX       ".byte 0x66, 0x0f, 0xc7, 0x30"
 #define ASM_VMX_VMLAUNCH          ".byte 0x0f, 0x01, 0xc2"
 #define ASM_VMX_VMRESUME          ".byte 0x0f, 0x01, 0xc3"
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index dd4efe1..8643ee5 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -294,6 +294,7 @@ static u16 group2_table[] = {
 /* EFLAGS bit definitions. */
 #define EFLG_OF (1<<11)
 #define EFLG_DF (1<<10)
+#define EFLG_TF (1<<8)
 #define EFLG_SF (1<<7)
 #define EFLG_ZF (1<<6)
 #define EFLG_AF (1<<4)
@@ -1767,6 +1768,9 @@ writeback:
 	if (rc != 0)
 		goto done;
 
+	if (ctxt->eflags & EFLG_TF)
+		kvm_inject_db(ctxt->vcpu,0);
+
 	/* Commit shadow register state. */
 	memcpy(ctxt->vcpu->arch.regs, c->regs, sizeof c->regs);
 	kvm_rip_write(ctxt->vcpu, c->eip);
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 02b88ec..2af18f7 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -56,6 +56,7 @@
 #define KVM_PAGES_PER_HPAGE (KVM_HPAGE_SIZE / PAGE_SIZE)
 
 #define DE_VECTOR 0
+#define DB_VECTOR 1
 #define UD_VECTOR 6
 #define NM_VECTOR 7
 #define DF_VECTOR 8
@@ -663,6 +664,11 @@ static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code)
 	kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
 }
 
+static inline void kvm_inject_db(struct kvm_vcpu *vcpu, u32 error_code)
+{
+	kvm_queue_exception_e(vcpu, DB_VECTOR, error_code);
+}
+
 #define ASM_VMX_VMCLEAR_RAX       ".byte 0x66, 0x0f, 0xc7, 0x30"
 #define ASM_VMX_VMLAUNCH          ".byte 0x0f, 0x01, 0xc2"
 #define ASM_VMX_VMRESUME          ".byte 0x0f, 0x01, 0xc3"

Reply via email to