Skip to contentSkip to conversation

SVM: set/unset TF flag for single_step

PATCH Boris Ostrovsky 3 participants 5 messages Jul 2, 2014 – Jul 3, 2014

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines · ----- [email protected] wrote:

Also strangely, when SVM VMEXIT_EXCEPTION_DB occurs, the TF flag is not cleared. This patch addresses that too.

..

Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +0 -0
index 76616ac..8addb94 100644

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs · line 2357

Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +2 -0
@@ -2350,6 +2350,8 @@ void svm_vmexit_handler(struct cpu_user_regs
 *regs)
     case VMEXIT_EXCEPTION_DB:
         if ( !v->domain->debugger_attached )
             goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
         domain_pause_for_debugger();
         break;

I poked around debugger code and it looks to me that tools/debugger/gdbsx/xg:_change_TF() manages this flag.

-boris

#1 lore raw
Quoted 16 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs · line 2357

Quoted 12 lines
Quoted 1 line · On 02.07.14 at 05:36, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +2 -0
@@ -2350,6 +2350,8 @@ void svm_vmexit_handler(struct cpu_user_regs
 *regs)
     case VMEXIT_EXCEPTION_DB:
         if ( !v->domain->debugger_attached )
             goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
         domain_pause_for_debugger();
         break;

I poked around debugger code and it looks to me that tools/debugger/gdbsx/xg:_change_TF() manages this flag.

Indeed it shouldn't be the hypervisor to deal with that (unless it had a built-in one), but the debugger attached.

That said, Mukesh, just as a side note: There's no point for an "else" after an "if" leading to a "goto".

Jan

#2 lore raw
Quoted 16 lines · On Wed, 02 Jul 2014 09:38:40 +0100 "Jan Beulich" <[email protected]> wrote:
Quoted 16 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs · line 2357

Quoted 12 lines
Quoted 1 line · On 02.07.14 at 05:36, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +2 -0
@@ -2350,6 +2350,8 @@ void svm_vmexit_handler(struct cpu_user_regs
 *regs)
     case VMEXIT_EXCEPTION_DB:
         if ( !v->domain->debugger_attached )
             goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
         domain_pause_for_debugger();
         break;

I poked around debugger code and it looks to me that tools/debugger/gdbsx/xg:_change_TF() manages this flag.

_change_TF() only manages TF if XEN_DOMCTL_debug_op fails. Moreover, TF handling is intended for PV. For HVM, xen provides XEN_DOMCTL_debug_op which sets v->arch.hvm_vcpu.single_step.

Quoted 2 lines

Indeed it shouldn't be the hypervisor to deal with that (unless it had a built-in one), but the debugger attached.

Correct. But, the hyp provides abi hvm_debug_op (XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON) that it needs to honor for svm like it does for vmx.

Quoted 2 lines

That said, Mukesh, just as a side note: There's no point for an "else" after an "if" leading to a "goto".

Right. My "doh!".

Thanks
Mukesh

#3 lore raw
Quoted 24 lines · On Wed, 2 Jul 2014 14:52:38 -0700 Mukesh Rathor <[email protected]>…
Quoted 16 lines · On Wed, 02 Jul 2014 09:38:40 +0100 "Jan Beulich" <[email protected]> wrote:
Quoted 16 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct · line 2357

Quoted 12 lines
Quoted 1 line · On 02.07.14 at 05:36, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +2 -0
@@ -2350,6 +2350,8 @@ void svm_vmexit_handler(struct
 cpu_user_regs *regs)
     case VMEXIT_EXCEPTION_DB:
         if ( !v->domain->debugger_attached )
             goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
         domain_pause_for_debugger();
         break;

I poked around debugger code and it looks to me that tools/debugger/gdbsx/xg:_change_TF() manages this flag.

_change_TF() only manages TF if XEN_DOMCTL_debug_op fails. Moreover, TF handling is intended for PV. For HVM, xen provides XEN_DOMCTL_debug_op which sets v->arch.hvm_vcpu.single_step.

Quoted 6 lines
Quoted 2 lines

Indeed it shouldn't be the hypervisor to deal with that (unless it had a built-in one), but the debugger attached.

Correct. But, the hyp provides abi hvm_debug_op (XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON) that it needs to honor for svm like it does for vmx.

I should rephrase that from "it needs" to "it would be nice to" as all debuggers then can just use hvm_vcpu.single_step internally or via hvm_debug_op().

Boris rightly points out that the cpu_has_monitor_trap_flag check in hvm_debug_op() would still be an issue, and I missed that check. It could be removed or an intel check could be added in that if statement.

hvm_debug_op():

            rc = -ENOSYS;
            if ( !cpu_has_monitor_trap_flag ) <---
                break;

hope that makes sense. if in agreement, i can send v1.

thanks
Mukesh

#4 lore raw
In reply to Mukesh Rathor
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 02.07.14 at 23:52, <[email protected]> wrote:
Quoted 16 lines · On Wed, 02 Jul 2014 09:38:40 +0100 "Jan Beulich" <[email protected]> wrote:
Quoted 16 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs · line 2357

Quoted 12 lines
Quoted 1 line · On 02.07.14 at 05:36, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +2 -0
@@ -2350,6 +2350,8 @@ void svm_vmexit_handler(struct cpu_user_regs
 *regs)
     case VMEXIT_EXCEPTION_DB:
         if ( !v->domain->debugger_attached )
             goto exit_and_crash;
+        else
+            regs->eflags &= ~X86_EFLAGS_TF;
         domain_pause_for_debugger();
         break;

I poked around debugger code and it looks to me that tools/debugger/gdbsx/xg:_change_TF() manages this flag.

Quoted 3 lines

_change_TF() only manages TF if XEN_DOMCTL_debug_op fails. Moreover, TF handling is intended for PV. For HVM, xen provides XEN_DOMCTL_debug_op which sets v->arch.hvm_vcpu.single_step.

Maybe this is how things are expected to work right now (I admit to know very little about the specific debugger interface in Xen), but conceptually this is wrong (and I say this having written a number of kernel debuggers outside of Xen): Since the next thing done in the code path above is pausing the domain for debugging, and since the debugger ought to have control over the entire register state, it clearly has the power of setting TF to its liking, and hence no action on it should be needed here.

Jan