Skip to contentSkip to conversation

AMD support of hvm_vcpu.single_step

PATCH Mukesh Rathor 2 participants 7 messages Jun 10, 2014 – Jun 12, 2014

lore
Share & tools
lore
#0 lore raw

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

    /* Block event injection when single step with MTF. */
    if ( unlikely(v->arch.hvm_vcpu.single_step) )
    {           
        v->arch.hvm_vmx.exec_control |= CPU_BASED_MONITOR_TRAP_FLAG;
        vmx_update_cpu_exec_control(v);
        return;
    }       

I don't see equivalent on amd?

Furthermore, as a second issue, in __update_guest_eip(), imo the exception is injected into the guest prematurely :

    if ( regs->eflags & X86_EFLAGS_TF )
            hvm_inject_hw_exception(TRAP_debug,
    HVM_DELIVER_NO_ERROR_CODE);

Reason being, in the BP path, __update_guest_eip is called before domain_pause_for_debugger(). As such, if the BP is handled, there is no need to inject into the guest. right?

I've the following patch in my tree for the single step issue. LMK what you think.

thanks
Mukesh

xen/arch/x86/hvm/svm/intr.c +6 -0
index 023151a..28d2c6d 100644
@@ -139,6 +139,12 @@ void svm_intr_assist(void)
     struct hvm_intack intack;
     enum hvm_intblk intblk;
 
+    if ( unlikely(v->arch.hvm_vcpu.single_step) )
+    {
+        guest_cpu_user_regs()->eflags |= X86_EFLAGS_TF;
+        return;
+    }
+
     /* Crank the handle on interrupt state. */
     pt_update_irq(v);
 
xen/arch/x86/hvm/svm/svm.c +4 -2
index d307dfb..b55825b 100644
@@ -2340,12 +2368,14 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
         break;
 
     case VMEXIT_EXCEPTION_DB:
+        if ( !v->domain->debugger_attached )
+            goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
-        if ( !v->domain->debugger_attached )
-            goto exit_and_crash;
         domain_pause_for_debugger();
         break;
#1 lore raw
Quoted 13 lines · Mukesh Rathor

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

     /* Block event injection when single step with MTF. */
     if ( unlikely(v->arch.hvm_vcpu.single_step) )
     {
         v->arch.hvm_vmx.exec_control |= CPU_BASED_MONITOR_TRAP_FLAG;
         vmx_update_cpu_exec_control(v);
         return;
     }
Quoted 1 line

I don't see equivalent on amd?

I think HW performs TF bit manipulations that your patch is suggesting (per 13.1.4 of APMv2)

Quoted 11 lines

Furthermore, as a second issue, in __update_guest_eip(), imo the exception is injected into the guest prematurely :

     if ( regs->eflags & X86_EFLAGS_TF )
             hvm_inject_hw_exception(TRAP_debug,
     HVM_DELIVER_NO_ERROR_CODE);

Reason being, in the BP path, __update_guest_eip is called before domain_pause_for_debugger(). As such, if the BP is handled, there is no need to inject into the guest. right?

TF should be cleared when INT3 is executed according to the same section.

(Besides, it looks like VMX code does the same.)

-boris

Quoted 42 lines

I've the following patch in my tree for the single step issue. LMK what you think.

thanks
Mukesh

xen/arch/x86/hvm/svm/intr.c +6 -0
index 023151a..28d2c6d 100644
@@ -139,6 +139,12 @@ void svm_intr_assist(void)
      struct hvm_intack intack;
      enum hvm_intblk intblk;
 
+    if ( unlikely(v->arch.hvm_vcpu.single_step) )
+    {
+        guest_cpu_user_regs()->eflags |= X86_EFLAGS_TF;
+        return;
+    }
+
      /* Crank the handle on interrupt state. */
      pt_update_irq(v);
 
xen/arch/x86/hvm/svm/svm.c +4 -2
index d307dfb..b55825b 100644
@@ -2340,12 +2368,14 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
          break;
 
      case VMEXIT_EXCEPTION_DB:
+        if ( !v->domain->debugger_attached )
+            goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
-        if ( !v->domain->debugger_attached )
-            goto exit_and_crash;
          domain_pause_for_debugger();
          break;
 
#2 lore raw
Quoted 14 lines · On Wed, 11 Jun 2014 11:56:15 -0400 Boris Ostrovsky…
Quoted 13 lines · Mukesh Rathor

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

     /* Block event injection when single step with MTF. */
     if ( unlikely(v->arch.hvm_vcpu.single_step) )
     {
         v->arch.hvm_vmx.exec_control |=
CPU_BASED_MONITOR_TRAP_FLAG; vmx_update_cpu_exec_control(v);
         return;
     }
Quoted 4 lines
Quoted 1 line

I don't see equivalent on amd?

I think HW performs TF bit manipulations that your patch is suggesting (per 13.1.4 of APMv2)

It only clears it, not set it. Patch on the way.

thanks
mukesh

#3 lore raw
Quoted 17 lines · Mukesh Rathor
Quoted 14 lines · On Wed, 11 Jun 2014 11:56:15 -0400 Boris Ostrovsky…
Quoted 13 lines · Mukesh Rathor

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

      /* Block event injection when single step with MTF. */
      if ( unlikely(v->arch.hvm_vcpu.single_step) )
      {
          v->arch.hvm_vmx.exec_control |=
CPU_BASED_MONITOR_TRAP_FLAG; vmx_update_cpu_exec_control(v);
          return;
      }
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

I don't see equivalent on amd?

I think HW performs TF bit manipulations that your patch is suggesting (per 13.1.4 of APMv2)

It only clears it, not set it. Patch on the way.

Does it need to be set? My understanding is that it is supposed to be clear in the handler (in the guest) but set on the exception's stack so when the guest does the IRET it loads TF=1.

-boris

#4 lore raw
Quoted 20 lines · On Wed, 11 Jun 2014 18:55:53 -0400 Boris Ostrovsky…
Quoted 19 lines · Mukesh Rathor
Quoted 16 lines · On Wed, 11 Jun 2014 11:56:15 -0400 Boris Ostrovsky…
Quoted 15 lines · Mukesh Rathor

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

      /* Block event injection when single step with MTF. */
      if ( unlikely(v->arch.hvm_vcpu.single_step) )
      {
          v->arch.hvm_vmx.exec_control |=
CPU_BASED_MONITOR_TRAP_FLAG; vmx_update_cpu_exec_control(v);
          return;
      }

I don't see equivalent on amd?

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

I think HW performs TF bit manipulations that your patch is suggesting (per 13.1.4 of APMv2)

It only clears it, not set it. Patch on the way.

Does it need to be set? My understanding is that it is supposed to be clear in the handler (in the guest) but set on the exception's stack so when the guest does the IRET it loads TF=1.

If a debugger wants to single step, it needs to set the TF. So this is for the debugger path. The hardware clears it upon execution of next instruction, and generates #DB.

-Mukesh

#5 lore raw
Quoted 25 lines · Mukesh Rathor
Quoted 22 lines · On Wed, 11 Jun 2014 18:55:53 -0400 Boris Ostrovsky…
Quoted 21 lines · Mukesh Rathor
Quoted 18 lines · On Wed, 11 Jun 2014 11:56:15 -0400 Boris Ostrovsky…
Quoted 14 lines · Mukesh Rathor

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

       /* Block event injection when single step with MTF. */
       if ( unlikely(v->arch.hvm_vcpu.single_step) )
       {
           v->arch.hvm_vmx.exec_control |=
CPU_BASED_MONITOR_TRAP_FLAG; vmx_update_cpu_exec_control(v);
           return;
       }
Quoted 1 line

I don't see equivalent on amd?

I think HW performs TF bit manipulations that your patch is suggesting (per 13.1.4 of APMv2)

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

It only clears it, not set it. Patch on the way.

Does it need to be set? My understanding is that it is supposed to be clear in the handler (in the guest) but set on the exception's stack so when the guest does the IRET it loads TF=1.

If a debugger wants to single step, it needs to set the TF. So this is for the debugger path. The hardware clears it upon execution of next instruction, and generates #DB.

The patch seems to be setting TF when returning from #DB intercept, right? Won't this result in another #DB on the first instruction of guest's #DB handler?

-boris

#6 lore raw
Quoted 31 lines · On Wed, 11 Jun 2014 19:46:12 -0400 Boris Ostrovsky…
Quoted 30 lines · Mukesh Rathor
Quoted 27 lines · On Wed, 11 Jun 2014 18:55:53 -0400 Boris Ostrovsky…
Quoted 18 lines · Mukesh Rathor
Quoted 15 lines · On Wed, 11 Jun 2014 11:56:15 -0400 Boris Ostrovsky…
Quoted 14 lines · Mukesh Rathor

Hi AMD folks,

I am unable to see support of single step on amd platform. On intel, hvm_vcpu.single_step will cause MTF to be set in vmx_intr_assist:

       /* Block event injection when single step with MTF. */
       if ( unlikely(v->arch.hvm_vcpu.single_step) )
       {
           v->arch.hvm_vmx.exec_control |=
CPU_BASED_MONITOR_TRAP_FLAG; vmx_update_cpu_exec_control(v);
           return;
       }
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

I don't see equivalent on amd?

I think HW performs TF bit manipulations that your patch is suggesting (per 13.1.4 of APMv2)

It only clears it, not set it. Patch on the way.

Does it need to be set? My understanding is that it is supposed to be clear in the handler (in the guest) but set on the exception's stack so when the guest does the IRET it loads TF=1.

Quoted 7 lines
Quoted 3 lines

If a debugger wants to single step, it needs to set the TF. So this is for the debugger path. The hardware clears it upon execution of next instruction, and generates #DB.

The patch seems to be setting TF when returning from #DB intercept, right? Won't this result in another #DB on the first instruction of guest's #DB handler?

Nop, we are setting the TF in the resume path, returning from whatever intercept it was. It could have been anything. If an external debugger set the single_step flag during this time, then just like vmx, svm must honor that and do what it takes, in this case setting the TF (vmx sets MTF) when it's resuming the guest.

thanks,
Mukesh