powerpc/xmon: Avoid unsequenced accesses to tsk in show_task()
Subsystems (2)
PATCH 1/1 powerpc/xmon: Avoid unsequenced accesses to tsk in show_task()
After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in show_task(), which can break the build with CONFIG_PPC_WERROR=y / CONFIG_WERROR=y / W=e:
arch/powerpc/xmon/xmon.c:3262:3: error: unsequenced accesses to volatile qualified 'tsk' [-Werror,-Wunsequenced]
3261 | printf("%16px %16lx %16px %6d %6d %c %2d %s\n", tsk,
| ~~~
3262 | tsk->thread.ksp, tsk->thread.regs,
| ^Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced.
tsk was made volatile in commit a2305e3de819 ("powerpc: mark local variables around longjmp as volatile") to ensure its value in show_tasks() was properly restored after returning from a potential longjmp(). Aside from that, the value is not being modified through other means, so rename the volatile parameter and add a local variable named tsk to hold its value throughout show_task(), clearing up the warning.
--- arch/powerpc/xmon/xmon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/xmon/xmon.c +2 -1
@@ -3240,8 +3240,9 @@ memzcan(void)printf ("%.8lx\n" , a - mskip); } -static void show_task (struct task_struct *volatile tsk) +static void show_task (struct task_struct *volatile vol_tsk) { +struct task_struct *tsk = vol_tsk;unsigned int p_state =READ_ONCE (tsk->__state);char state;
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
change-id: 20261115-xmon-wunsequenced-120aeacf7636
Best regards,
Signature · 2 lines
Cheers, Nathan
Quoted 16 lines · Nathan Chancellor
After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in
show_task(), which can break the build withCONFIG_PPC_WERROR=y/CONFIG_WERROR=y/ W=e:
arch/powerpc/xmon/xmon.c:3262:3: error: unsequenced accesses to volatile qualified 'tsk' [-Werror,-Wunsequenced]3261 | printf("%16px %16lx %16px %6d %6d %c %2d %s\n", tsk, | ~~~ 3262 | tsk->thread.ksp, tsk->thread.regs, | ^Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced.
Quoted 7 lines
tsk was made volatile in commit
a2305e3de819("powerpc: mark local variables around longjmp as volatile") to ensure its value inshow_tasks()was properly restored after returning from a potentiallongjmp(). Aside from that, the value is not being modified through other means, so rename the volatile parameter and add a local variable named tsk to hold its value throughoutshow_task(), clearing up the warning.
Yes. Reading vol_tsk into tsk (local variable) in show_task() function, doesn't cause any functional change and also fixes the unsequenced volatile accesses as you described.
Quoted 10 lines
Fixes a2305e3de819 ("powerpc: mark local variables around longjmp as volatile")Signed-off-by Nathan Chancellor <[email protected]>--- arch/powerpc/xmon/xmon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
So, LGTM. Feel free to add:
Quoted 11 lines · Nathan Chancellor
After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in
show_task(), which can break the build withCONFIG_PPC_WERROR=y/CONFIG_WERROR=y/ W=e:
arch/powerpc/xmon/xmon.c:3262:3: error: unsequenced accesses to volatile qualified 'tsk' [-Werror,-Wunsequenced]3261 | printf("%16px %16lx %16px %6d %6d %c %2d %s\n", tsk, | ~~~ 3262 | tsk->thread.ksp, tsk->thread.regs, | ^[...]
Applied to powerpc/fixes.
[1/1] powerpc/xmon: Avoid unsequenced accesses to tsk in show_task()
https://git.kernel.org/powerpc/c/9ea01307e6c824eb0b8934d95d52bbacae17887d
cheers