riscv: jump_label: mark arguments as const to satisfy asm constraints
Subsystems (2)
PATCH v2 1/1 riscv: jump_label: mark arguments as const to satisfy asm constraints
Samuel reported that the static branch usage in cpu_relax() breaks building with CONFIG_CC_OPTIMIZE_FOR_SIZE:
In file included from <command-line>:./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax':././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints
285 | #define asm_volatile_goto(x...) asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'
41 | asm_volatile_goto(
| ^~~~~~~~~~~~~~~~~././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm'
285 | #define asm_volatile_goto(x...) asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'
41 | asm_volatile_goto(
| ^~~~~~~~~~~~~~~~~make[1]: *** [scripts/Makefile.build:249:arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make: *** [arch/riscv/Makefile:128: vdso_prepare] Error 2
Maybe "-Os" prevents GCC from detecting that the key/branch arguments can be treated as constants and used as immediate operands. Inspired by x86's commit 864b435514b2("x86/jump_label: Mark arguments as const to satisfy asm constraints"), and as pointed out by Steven: "The "i" constraint needs to be a constant.", let's do similar modifications to riscv.
Tested by CC_OPTIMIZE_FOR_SIZE + gcc and CC_OPTIMIZE_FOR_SIZE + clang.
---
since v1:
- add Reported-by, Reviewed-by, Fixes and Link tag
arch/riscv/include/asm/jump_label.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/include/asm/jump_label.h +4 -4
@@ -14,8 +14,8 @@#define JUMP_LABEL_NOP_SIZE 4 -static __always_inline bool arch_static_branch(struct static_key *key, -bool branch) +static __always_inline bool arch_static_branch(struct static_key * const key, +const bool branch) {asm_volatile_goto ( " .option push \n\t"
@@ -35,8 +35,8 @@ static __always_inline bool arch_static_branch(struct static_key *key,return true; } -static __always_inline bool arch_static_branch_jump(struct static_key *key, -bool branch) +static __always_inline bool arch_static_branch_jump(struct static_key * const key, +const bool branch) {asm_volatile_goto ( " .option push \n\t"
Signature · 1 line
2.37.2
Am Samstag, 8. Oktober 2022, 16:54:37 CEST schrieb Jisheng Zhang:
Quoted 32 lines
Samuel reported that the static branch usage in
cpu_relax()breaks building withCONFIG_CC_OPTIMIZE_FOR_SIZE:In file included from <command-line>:
./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax':././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~
././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm'
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~make[1]: *** [
scripts/Makefile.build:249:arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make: *** [arch/riscv/Makefile:128:vdso_prepare] Error 2Maybe "-Os" prevents GCC from detecting that the key/branch arguments can be treated as constants and used as immediate operands. Inspired by x86's commit 864b435514b2("x86/jump_label: Mark arguments as const to satisfy asm constraints"), and as pointed out by Steven: "The "i" constraint needs to be a constant.", let's do similar modifications to riscv.
Quoted 8 lines
Tested by
CC_OPTIMIZE_FOR_SIZE+ gcc andCC_OPTIMIZE_FOR_SIZE+ clang.Fixes 8eb060e10185 ("arch/riscv: add Zihintpause support")Reported-by Samuel Holland <[email protected]>Signed-off-by Jisheng Zhang <[email protected]>Reviewed-by Andrew Jones <[email protected]>
I ran into the same build-issue when enabling CC_OPTIMIZE_FOR_SIZE and this patch fixes it, so
Hey Jisheng,
LKP reported an error that seems to only have gone to myself & Samuel, but the branch it's complaining about is your v1:
https://lore.kernel.org/lkml/[email protected]/
Any idea what the story is here?
Thanks,
Conor.
Quoted 77 lines · Jisheng Zhang
Samuel reported that the static branch usage in
cpu_relax()breaks building withCONFIG_CC_OPTIMIZE_FOR_SIZE:In file included from <command-line>:
./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax':././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~
././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm'
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~make[1]: *** [
scripts/Makefile.build:249:arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make: *** [arch/riscv/Makefile:128:vdso_prepare] Error 2Maybe "-Os" prevents GCC from detecting that the key/branch arguments can be treated as constants and used as immediate operands. Inspired by x86's commit 864b435514b2("x86/jump_label: Mark arguments as const to satisfy asm constraints"), and as pointed out by Steven: "The "i" constraint needs to be a constant.", let's do similar modifications to riscv.
Tested by
CC_OPTIMIZE_FOR_SIZE+ gcc andCC_OPTIMIZE_FOR_SIZE+ clang.Fixes 8eb060e10185 ("arch/riscv: add Zihintpause support")Reported-by Samuel Holland <[email protected]>Signed-off-by Jisheng Zhang <[email protected]>Reviewed-by Andrew Jones <[email protected]>---
since v1:
- add Reported-by, Reviewed-by, Fixes and Link tagarch/riscv/include/asm/jump_label.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/riscv/include/asm/jump_label.h +4
-4@@ -14,8 +14,8 @@#define JUMP_LABEL_NOP_SIZE 4 -static __always_inline bool arch_static_branch(struct static_key *key, -bool branch) +static __always_inline bool arch_static_branch(struct static_key * const key, +const bool branch) {asm_volatile_goto ( " .option push \n\t"@@ -35,8 +35,8 @@ static __always_inline bool arch_static_branch(struct static_key *key,return true; } -static __always_inline bool arch_static_branch_jump(struct static_key *key, -bool branch) +static __always_inline bool arch_static_branch_jump(struct static_key * const key, +const bool branch) {asm_volatile_goto ( " .option push \n\t"Signature · 1 line
2.37.2
Quoted 1 line · Conor Dooley
Hey Jisheng,
Hi Conor,
Quoted 5 lines
LKP reported an error that seems to only have gone to myself & Samuel, but the branch it's complaining about is your v1:
https://lore.kernel.org/lkml/[email protected]/Any idea what the story is here?
I tried the config in the link, I can reproduce the build error w/ and w/o the my patch. So I think the root cause of the build error is a different story. I have a fix in local repo, will send it out soon.
Thanks
Quoted 82 lines
Thanks,
Conor.Quoted 77 lines · Jisheng Zhang
Samuel reported that the static branch usage in
cpu_relax()breaks building withCONFIG_CC_OPTIMIZE_FOR_SIZE:In file included from <command-line>:
./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax':././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~
././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm'
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~make[1]: *** [
scripts/Makefile.build:249:arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make: *** [arch/riscv/Makefile:128:vdso_prepare] Error 2Maybe "-Os" prevents GCC from detecting that the key/branch arguments can be treated as constants and used as immediate operands. Inspired by x86's commit 864b435514b2("x86/jump_label: Mark arguments as const to satisfy asm constraints"), and as pointed out by Steven: "The "i" constraint needs to be a constant.", let's do similar modifications to riscv.
Tested by
CC_OPTIMIZE_FOR_SIZE+ gcc andCC_OPTIMIZE_FOR_SIZE+ clang.Fixes 8eb060e10185 ("arch/riscv: add Zihintpause support")Reported-by Samuel Holland <[email protected]>Signed-off-by Jisheng Zhang <[email protected]>Reviewed-by Andrew Jones <[email protected]>---
since v1:
- add Reported-by, Reviewed-by, Fixes and Link tagarch/riscv/include/asm/jump_label.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/riscv/include/asm/jump_label.h +4
-4@@ -14,8 +14,8 @@#define JUMP_LABEL_NOP_SIZE 4 -static __always_inline bool arch_static_branch(struct static_key *key, -bool branch) +static __always_inline bool arch_static_branch(struct static_key * const key, +const bool branch) {asm_volatile_goto ( " .option push \n\t"@@ -35,8 +35,8 @@ static __always_inline bool arch_static_branch(struct static_key *key,return true; } -static __always_inline bool arch_static_branch_jump(struct static_key *key, -bool branch) +static __always_inline bool arch_static_branch_jump(struct static_key * const key, +const bool branch) {asm_volatile_goto ( " .option push \n\t"Signature · 1 line
2.37.2
Palmer Dabbelt
AppliedQuoted 19 lines · Jisheng Zhang
Samuel reported that the static branch usage in
cpu_relax()breaks building withCONFIG_CC_OPTIMIZE_FOR_SIZE:In file included from <command-line>:
./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax':././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~
././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm'
285 | #defineasm_volatile_goto(x...)asm goto(x)
| ^~~./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto'
Quoted 7 lines
41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~make[1]: *** [
scripts/Makefile.build:249:arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make: *** [arch/riscv/Makefile:128:vdso_prepare] Error 2[...]
Applied, thanks!
[1/1] riscv: jump_label: mark arguments as const to satisfy asm constraints
commit: 89fd4a1df829187d4d35f6a520cc531de622e6f0
Best regards,
Signature · 1 line
Palmer Dabbelt <[email protected]>