Skip to contentSkip to conversation

kgdbts: fix hw_access_break_test

PATCH In review Florian Rommel 4 participants 4 messages Aug 12, 2024 – Aug 14, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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).

---
 drivers/misc/kgdbts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/kgdbts.c +2 -2
index 88b91ad8e541..0cf31164b470 100644
@@ -95,6 +95,7 @@
 #include <linux/kallsyms.h>
 
 #include <asm/sections.h>
+#include <asm/rwonce.h>
 
 #define v1printk(a...) do {		\
 	if (verbose)			\
@@ -126,7 +127,6 @@ static int final_ack;
 static int force_hwbrks;
 static int hwbreaks_ok;
 static int hw_break_val;
-static int hw_break_val2;
 static int cont_instead_of_sstep;
 static unsigned long cont_thread_id;
 static unsigned long sstep_thread_id;
@@ -284,7 +284,7 @@ static void hw_rem_access_break(char *arg)
 
 static void hw_break_val_access(void)
 {
-	hw_break_val2 = hw_break_val;
+	READ_ONCE(hw_break_val);
 }
 
 static void hw_break_val_write(void)
Signature · 1 line
2.46.0
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 7 lines · Florian Rommel

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.

Quoted 7 lines

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

---
 drivers/misc/kgdbts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Acked-by Tested-by
#2 lore raw
Quoted 13 lines · Doug Anderson

Hi,

Quoted 10 lines · Florian Rommel

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).

Quoted 6 lines
Quoted 4 lines
---
 drivers/misc/kgdbts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Looks good. I pushed this through kgdbtest and it likes it too. I can turn one of the XFAILs off (yay).

Arnd/Greg: Are you happy to pick this up or should I take it through the kgdb tree? FWIW right now there are zero other patches for kgdb this cycle, although that could change!

Daniel.

#3 lore raw
Quoted 24 lines · Daniel Thompson
Quoted 13 lines · Doug Anderson

Hi,

Quoted 10 lines · Florian Rommel

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).

Quoted 6 lines
Quoted 4 lines
---
 drivers/misc/kgdbts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Looks good. I pushed this through kgdbtest and it likes it too. I can turn one of the XFAILs off (yay).

Quoted 6 lines

Arnd/Greg: Are you happy to pick this up or should I take it through the kgdb tree? FWIW right now there are zero other patches for kgdb this cycle, although that could change!

I've already picked it up, thanks!

greg k-h