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.
Link: https://lore.kernel.org/linux-riscv/20220922060958.44203-1-samuel@sholland.org/
Link: https://lore.kernel.org/all/20210212094059.5f8d05e8@gandalf.local.home/
Fixes: 8eb060e101
("arch/riscv: add Zihintpause support")
Reported-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20221008145437.491-1-jszhang@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2020 Emil Renner Berthing
|
|
*
|
|
* Based on arch/arm64/include/asm/jump_label.h
|
|
*/
|
|
#ifndef __ASM_JUMP_LABEL_H
|
|
#define __ASM_JUMP_LABEL_H
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <linux/types.h>
|
|
#include <asm/asm.h>
|
|
|
|
#define JUMP_LABEL_NOP_SIZE 4
|
|
|
|
static __always_inline bool arch_static_branch(struct static_key * const key,
|
|
const bool branch)
|
|
{
|
|
asm_volatile_goto(
|
|
" .option push \n\t"
|
|
" .option norelax \n\t"
|
|
" .option norvc \n\t"
|
|
"1: nop \n\t"
|
|
" .option pop \n\t"
|
|
" .pushsection __jump_table, \"aw\" \n\t"
|
|
" .align " RISCV_LGPTR " \n\t"
|
|
" .long 1b - ., %l[label] - . \n\t"
|
|
" " RISCV_PTR " %0 - . \n\t"
|
|
" .popsection \n\t"
|
|
: : "i"(&((char *)key)[branch]) : : label);
|
|
|
|
return false;
|
|
label:
|
|
return true;
|
|
}
|
|
|
|
static __always_inline bool arch_static_branch_jump(struct static_key * const key,
|
|
const bool branch)
|
|
{
|
|
asm_volatile_goto(
|
|
" .option push \n\t"
|
|
" .option norelax \n\t"
|
|
" .option norvc \n\t"
|
|
"1: jal zero, %l[label] \n\t"
|
|
" .option pop \n\t"
|
|
" .pushsection __jump_table, \"aw\" \n\t"
|
|
" .align " RISCV_LGPTR " \n\t"
|
|
" .long 1b - ., %l[label] - . \n\t"
|
|
" " RISCV_PTR " %0 - . \n\t"
|
|
" .popsection \n\t"
|
|
: : "i"(&((char *)key)[branch]) : : label);
|
|
|
|
return false;
|
|
label:
|
|
return true;
|
|
}
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
#endif /* __ASM_JUMP_LABEL_H */
|