Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kgdbts: fix hw_access_break_test

The test for access watchpoints (hw_access_break_test) was broken
(always failed) because the compiler optimized out the write to the
static helper variable (hw_break_val2), as it is never read anywhere.
This resulted in the target variable (hw_break_val) not being accessed
and thus the breakpoint not being triggered.

Remove the helper variable (hw_break_val2), and use READ_ONCE to force
reading the target variable (hw_break_val).

Signed-off-by: Florian Rommel <mail@florommel.de>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20240812085459.291741-1-mail@florommel.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Florian Rommel and committed by
Greg Kroah-Hartman
4a017c01 9ca12e50

+2 -2
+2 -2
drivers/misc/kgdbts.c
··· 95 95 #include <linux/kallsyms.h> 96 96 97 97 #include <asm/sections.h> 98 + #include <asm/rwonce.h> 98 99 99 100 #define v1printk(a...) do { \ 100 101 if (verbose) \ ··· 127 126 static int force_hwbrks; 128 127 static int hwbreaks_ok; 129 128 static int hw_break_val; 130 - static int hw_break_val2; 131 129 static int cont_instead_of_sstep; 132 130 static unsigned long cont_thread_id; 133 131 static unsigned long sstep_thread_id; ··· 284 284 285 285 static void hw_break_val_access(void) 286 286 { 287 - hw_break_val2 = hw_break_val; 287 + READ_ONCE(hw_break_val); 288 288 } 289 289 290 290 static void hw_break_val_write(void)