Commit f4956cf8 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Thomas Gleixner

x86/debug: Support negative polarity DR6 bits

DR6 has a whole bunch of bits that have negative polarity; they were
architecturally reserved and defined to be 1 and are now getting used.
Since they're 1 by default, 0 becomes the signal value.

Handle this by xor'ing the read DR6 value by the reserved mask, this
will flip them around such that 1 is the signal value (positive
polarity).

Current Linux doesn't yet support any of these bits, but there's two
defined:

 - DR6[11] Bus Lock Debug Exception		(ISEr39)
 - DR6[16] Restricted Transactional Memory	(SDM)

Update ptrace_{set,get}_debugreg() to provide/consume the value in
architectural polarity. Although afaict ptrace_set_debugreg(6) is
pointless, the value is not consumed anywhere.

Change hw_breakpoint_restore() to alway write the DR6_RESERVED value
to DR6, again, no consumer for that write.
Suggested-by: default avatarAndrew Cooper <Andrew.Cooper3@citrix.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Link: https://lore.kernel.org/r/20200902133201.354220797@infradead.org
parent 21d44be7
...@@ -464,7 +464,7 @@ void hw_breakpoint_restore(void) ...@@ -464,7 +464,7 @@ void hw_breakpoint_restore(void)
set_debugreg(__this_cpu_read(cpu_debugreg[1]), 1); set_debugreg(__this_cpu_read(cpu_debugreg[1]), 1);
set_debugreg(__this_cpu_read(cpu_debugreg[2]), 2); set_debugreg(__this_cpu_read(cpu_debugreg[2]), 2);
set_debugreg(__this_cpu_read(cpu_debugreg[3]), 3); set_debugreg(__this_cpu_read(cpu_debugreg[3]), 3);
set_debugreg(current->thread.debugreg6, 6); set_debugreg(DR6_RESERVED, 6);
set_debugreg(__this_cpu_read(cpu_dr7), 7); set_debugreg(__this_cpu_read(cpu_dr7), 7);
} }
EXPORT_SYMBOL_GPL(hw_breakpoint_restore); EXPORT_SYMBOL_GPL(hw_breakpoint_restore);
......
...@@ -601,7 +601,7 @@ static unsigned long ptrace_get_debugreg(struct task_struct *tsk, int n) ...@@ -601,7 +601,7 @@ static unsigned long ptrace_get_debugreg(struct task_struct *tsk, int n)
if (bp) if (bp)
val = bp->hw.info.address; val = bp->hw.info.address;
} else if (n == 6) { } else if (n == 6) {
val = thread->debugreg6; val = thread->debugreg6 ^ DR6_RESERVED; /* Flip back to arch polarity */
} else if (n == 7) { } else if (n == 7) {
val = thread->ptrace_dr7; val = thread->ptrace_dr7;
} }
...@@ -657,7 +657,7 @@ static int ptrace_set_debugreg(struct task_struct *tsk, int n, ...@@ -657,7 +657,7 @@ static int ptrace_set_debugreg(struct task_struct *tsk, int n,
if (n < HBP_NUM) { if (n < HBP_NUM) {
rc = ptrace_set_breakpoint_addr(tsk, n, val); rc = ptrace_set_breakpoint_addr(tsk, n, val);
} else if (n == 6) { } else if (n == 6) {
thread->debugreg6 = val; thread->debugreg6 = val ^ DR6_RESERVED; /* Flip to positive polarity */
rc = 0; rc = 0;
} else if (n == 7) { } else if (n == 7) {
rc = ptrace_write_dr7(tsk, val); rc = ptrace_write_dr7(tsk, val);
......
...@@ -745,9 +745,8 @@ static __always_inline unsigned long debug_read_clear_dr6(void) ...@@ -745,9 +745,8 @@ static __always_inline unsigned long debug_read_clear_dr6(void)
* Keep it simple: clear DR6 immediately. * Keep it simple: clear DR6 immediately.
*/ */
get_debugreg(dr6, 6); get_debugreg(dr6, 6);
set_debugreg(0, 6); set_debugreg(DR6_RESERVED, 6);
/* Filter out all the reserved bits which are preset to 1 */ dr6 ^= DR6_RESERVED; /* Flip to positive polarity */
dr6 &= ~DR6_RESERVED;
/* /*
* The SDM says "The processor clears the BTF flag when it * The SDM says "The processor clears the BTF flag when it
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment