Re: [PATCH 4/6] hw-breakpoints: Rewrite the hw-breakpoints layer on top of perf events

Frederic Weisbecker
2009-11-01T22:49:04Z

On Sun, Nov 01, 2009 at 11:09:03PM +0100, Jan Kiszka wrote:
> Frederic Weisbecker wrote:
> [...]
> > @@ -94,6 +87,12 @@ static inline void hw_breakpoint_disable(void)
> > set_debugreg(0UL, 3);
> > }
> >
> > +#ifdef CONFIG_KVM
> > +extern void hw_breakpoint_restore(void);
> > +#else
> > +static inline void hw_breakpoint_restore(void) { }
> > +#endif
> > +
>
> Hmm, if this shall become a KVM-only API, why the empty wrapper?

Right, this is an odd reflex.

> [...]
> > -void arch_flush_thread_hw_breakpoint(struct task_struct *tsk)
> > +#ifdef CONFIG_KVM
> > +void hw_breakpoint_restore(void)
> > {
> > - int i;
> > - struct thread_struct *thread = &(tsk->thread);
> > -
> > - thread->debugreg7 = 0;
> > - for (i = 0; i < HBP_NUM; i++)
> > - thread->debugreg[i] = 0;
> > + set_debugreg(__get_cpu_var(cpu_debugreg[0]), 0);
> > + set_debugreg(__get_cpu_var(cpu_debugreg[1]), 1);
> > + set_debugreg(__get_cpu_var(cpu_debugreg[2]), 2);
> > + set_debugreg(__get_cpu_var(cpu_debugreg[3]), 3);
> > + set_debugreg(current->thread.debugreg6, 6);
> > + set_debugreg(__get_cpu_var(dr7), 7);
> > }
> > +#endif
>
> EXPORT_SYMBOL_GPL(hw_breakpoint_restore);
>
> as KVM can be built as module.

Indeed.

> [...]
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index fc2974a..32d7bca 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -42,6 +42,7 @@
> > #define CREATE_TRACE_POINTS
> > #include "trace.h"
> >
> > +#include <asm/debugreg.h>
> > #include <asm/uaccess.h>
> > #include <asm/msr.h>
> > #include <asm/desc.h>
> > @@ -3643,14 +3644,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> > trace_kvm_entry(vcpu->vcpu_id);
> > kvm_x86_ops->run(vcpu, kvm_run);
> >
> > - if (unlikely(vcpu->arch.switch_db_regs || test_thread_flag(TIF_DEBUG))) {
> > - set_debugreg(current->thread.debugreg[0], 0);
> > - set_debugreg(current->thread.debugreg[1], 1);
> > - set_debugreg(current->thread.debugreg[2], 2);
> > - set_debugreg(current->thread.debugreg[3], 3);
> > - set_debugreg(current->thread.debugreg6, 6);
> > - set_debugreg(current->thread.debugreg7, 7);
> > - }
> > + if (unlikely(vcpu->arch.switch_db_regs || test_thread_flag(TIF_DEBUG)))
> > + hw_breakpoint_restore();
>
> TIF_DEBUG is only set on active ptrace hw-breakpoints, thus we miss
> other types here, right? (Note: arch.switch_db_regs is guest-related,
> thus does not help in this regard.)
>
> Jan
>

True :)
Thanks a lot for this review, I'm going to fix that quickly.