2009-12-26 18:27:35

by K.Prasad

[permalink] [raw]
Subject: [RFC Patch 1/2][Bugfix][x86][hw-breakpoint] Clear reserved bits of DR6 in do_debug()

Clear the reserved bits from the stored copy of debug status register (DR6).
This will help easy bitwise operations.

Signed-off-by: K.Prasad <[email protected]>
---
arch/x86/include/asm/debugreg.h | 3 +++
arch/x86/kernel/traps.c | 3 +++
2 files changed, 6 insertions(+)

Index: linux-2.6-tip/arch/x86/include/asm/debugreg.h
===================================================================
--- linux-2.6-tip.orig/arch/x86/include/asm/debugreg.h
+++ linux-2.6-tip/arch/x86/include/asm/debugreg.h
@@ -14,6 +14,9 @@
which debugging register was responsible for the trap. The other bits
are either reserved or not of interest to us. */

+/* Define reserved bits in DR6 which are always set to 1 */
+#define DR6_RESERVED (0xFFFF0FF0)
+
#define DR_TRAP0 (0x1) /* db0 */
#define DR_TRAP1 (0x2) /* db1 */
#define DR_TRAP2 (0x4) /* db2 */
Index: linux-2.6-tip/arch/x86/kernel/traps.c
===================================================================
--- linux-2.6-tip.orig/arch/x86/kernel/traps.c
+++ linux-2.6-tip/arch/x86/kernel/traps.c
@@ -534,6 +534,9 @@ dotraplinkage void __kprobes do_debug(st

get_debugreg(dr6, 6);

+ /* Filter out all the reserved bits which are preset to 1 */
+ dr6 &= ~DR6_RESERVED;
+
/* Catch kmemcheck conditions first of all! */
if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
return;


2009-12-30 23:45:06

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [RFC Patch 1/2][Bugfix][x86][hw-breakpoint] Clear reserved bits of DR6 in do_debug()

On Sat, Dec 26, 2009 at 11:57:25PM +0530, K.Prasad wrote:
> Clear the reserved bits from the stored copy of debug status register (DR6).
> This will help easy bitwise operations.
>
> Signed-off-by: K.Prasad <[email protected]>
> ---
> arch/x86/include/asm/debugreg.h | 3 +++
> arch/x86/kernel/traps.c | 3 +++
> 2 files changed, 6 insertions(+)
>
> Index: linux-2.6-tip/arch/x86/include/asm/debugreg.h
> ===================================================================
> --- linux-2.6-tip.orig/arch/x86/include/asm/debugreg.h
> +++ linux-2.6-tip/arch/x86/include/asm/debugreg.h
> @@ -14,6 +14,9 @@
> which debugging register was responsible for the trap. The other bits
> are either reserved or not of interest to us. */
>
> +/* Define reserved bits in DR6 which are always set to 1 */
> +#define DR6_RESERVED (0xFFFF0FF0)
> +


The 12th bit seems to be also reserved.
Shouldn't it be 0xffff1ff0 ?

What kind of bitwise operations do you think it could help?

All of the operations I can find on dr6 are simple masks
test/set/clear.



> #define DR_TRAP0 (0x1) /* db0 */
> #define DR_TRAP1 (0x2) /* db1 */
> #define DR_TRAP2 (0x4) /* db2 */
> Index: linux-2.6-tip/arch/x86/kernel/traps.c
> ===================================================================
> --- linux-2.6-tip.orig/arch/x86/kernel/traps.c
> +++ linux-2.6-tip/arch/x86/kernel/traps.c
> @@ -534,6 +534,9 @@ dotraplinkage void __kprobes do_debug(st
>
> get_debugreg(dr6, 6);
>
> + /* Filter out all the reserved bits which are preset to 1 */
> + dr6 &= ~DR6_RESERVED;
> +
> /* Catch kmemcheck conditions first of all! */
> if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
> return;
>

2009-12-31 18:49:59

by K.Prasad

[permalink] [raw]
Subject: Re: [RFC Patch 1/2][Bugfix][x86][hw-breakpoint] Clear reserved bits of DR6 in do_debug()

On Thu, Dec 31, 2009 at 12:45:00AM +0100, Frederic Weisbecker wrote:
> On Sat, Dec 26, 2009 at 11:57:25PM +0530, K.Prasad wrote:
> > Clear the reserved bits from the stored copy of debug status register (DR6).
> > This will help easy bitwise operations.
> >
> > Signed-off-by: K.Prasad <[email protected]>
> > ---
> > arch/x86/include/asm/debugreg.h | 3 +++
> > arch/x86/kernel/traps.c | 3 +++
> > 2 files changed, 6 insertions(+)
> >
> > Index: linux-2.6-tip/arch/x86/include/asm/debugreg.h
> > ===================================================================
> > --- linux-2.6-tip.orig/arch/x86/include/asm/debugreg.h
> > +++ linux-2.6-tip/arch/x86/include/asm/debugreg.h
> > @@ -14,6 +14,9 @@
> > which debugging register was responsible for the trap. The other bits
> > are either reserved or not of interest to us. */
> >
> > +/* Define reserved bits in DR6 which are always set to 1 */
> > +#define DR6_RESERVED (0xFFFF0FF0)
> > +
>
>
> The 12th bit seems to be also reserved.
> Shouldn't it be 0xffff1ff0 ?
>

The 12th bit is reserved to be 0 always.

> What kind of bitwise operations do you think it could help?
>
> All of the operations I can find on dr6 are simple masks
> test/set/clear.
>

As you found out later, this bitmask helps us in
hw_breakpoint_handler().

Thanks,
K.Prasad

2010-01-10 03:22:31

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [RFC Patch 1/2][Bugfix][x86][hw-breakpoint] Clear reserved bits of DR6 in do_debug()

On Fri, Jan 01, 2010 at 12:19:49AM +0530, K.Prasad wrote:
> On Thu, Dec 31, 2009 at 12:45:00AM +0100, Frederic Weisbecker wrote:
> > On Sat, Dec 26, 2009 at 11:57:25PM +0530, K.Prasad wrote:
> > > Clear the reserved bits from the stored copy of debug status register (DR6).
> > > This will help easy bitwise operations.
> > >
> > > Signed-off-by: K.Prasad <[email protected]>
> > > ---
> > > arch/x86/include/asm/debugreg.h | 3 +++
> > > arch/x86/kernel/traps.c | 3 +++
> > > 2 files changed, 6 insertions(+)
> > >
> > > Index: linux-2.6-tip/arch/x86/include/asm/debugreg.h
> > > ===================================================================
> > > --- linux-2.6-tip.orig/arch/x86/include/asm/debugreg.h
> > > +++ linux-2.6-tip/arch/x86/include/asm/debugreg.h
> > > @@ -14,6 +14,9 @@
> > > which debugging register was responsible for the trap. The other bits
> > > are either reserved or not of interest to us. */
> > >
> > > +/* Define reserved bits in DR6 which are always set to 1 */
> > > +#define DR6_RESERVED (0xFFFF0FF0)
> > > +
> >
> >
> > The 12th bit seems to be also reserved.
> > Shouldn't it be 0xffff1ff0 ?
> >
>
> The 12th bit is reserved to be 0 always.


Ah, ok.


> > What kind of bitwise operations do you think it could help?
> >
> > All of the operations I can find on dr6 are simple masks
> > test/set/clear.
> >
>
> As you found out later, this bitmask helps us in
> hw_breakpoint_handler().


Yeah, ok. Just waiting for Jan's answer to be sure it has
not side effects :)

Thanks.