Skip to content

Commit 5235c7e

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: alternatives: use cpucap naming
To more clearly align the various users of the cpucap enumeration, this patch changes the alternative code to use the term `cpucap` in favour of `feature`. The alternative_has_feature_{likely,unlikely}() functions are renamed to alternative_has_cap_<likely,unlikely}() to more clearly align with the cpus_have_{const_,}cap() helpers. At the same time remove the stale comment referring to the "ARM64_CB bit", which is evidently a typo for ARM64_CB_PATCH, which was removed in commit: 4c0bd99 ("arm64: alternatives: have callbacks take a cap") There should be no functional change as a result of this patch; this is purely a renaming exercise. Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Brown <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 7f24298 commit 5235c7e

File tree

6 files changed

+41
-42
lines changed

6 files changed

+41
-42
lines changed

arch/arm64/include/asm/alternative-macros.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323

2424
#include <linux/stringify.h>
2525

26-
#define ALTINSTR_ENTRY(feature) \
26+
#define ALTINSTR_ENTRY(cpucap) \
2727
" .word 661b - .\n" /* label */ \
2828
" .word 663f - .\n" /* new instruction */ \
29-
" .hword " __stringify(feature) "\n" /* feature bit */ \
29+
" .hword " __stringify(cpucap) "\n" /* cpucap */ \
3030
" .byte 662b-661b\n" /* source len */ \
3131
" .byte 664f-663f\n" /* replacement len */
3232

33-
#define ALTINSTR_ENTRY_CB(feature, cb) \
33+
#define ALTINSTR_ENTRY_CB(cpucap, cb) \
3434
" .word 661b - .\n" /* label */ \
35-
" .word " __stringify(cb) "- .\n" /* callback */ \
36-
" .hword " __stringify(feature) "\n" /* feature bit */ \
35+
" .word " __stringify(cb) "- .\n" /* callback */ \
36+
" .hword " __stringify(cpucap) "\n" /* cpucap */ \
3737
" .byte 662b-661b\n" /* source len */ \
3838
" .byte 664f-663f\n" /* replacement len */
3939

@@ -53,13 +53,13 @@
5353
*
5454
* Alternatives with callbacks do not generate replacement instructions.
5555
*/
56-
#define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \
56+
#define __ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, cfg_enabled) \
5757
".if "__stringify(cfg_enabled)" == 1\n" \
5858
"661:\n\t" \
5959
oldinstr "\n" \
6060
"662:\n" \
6161
".pushsection .altinstructions,\"a\"\n" \
62-
ALTINSTR_ENTRY(feature) \
62+
ALTINSTR_ENTRY(cpucap) \
6363
".popsection\n" \
6464
".subsection 1\n" \
6565
"663:\n\t" \
@@ -70,31 +70,31 @@
7070
".previous\n" \
7171
".endif\n"
7272

73-
#define __ALTERNATIVE_CFG_CB(oldinstr, feature, cfg_enabled, cb) \
73+
#define __ALTERNATIVE_CFG_CB(oldinstr, cpucap, cfg_enabled, cb) \
7474
".if "__stringify(cfg_enabled)" == 1\n" \
7575
"661:\n\t" \
7676
oldinstr "\n" \
7777
"662:\n" \
7878
".pushsection .altinstructions,\"a\"\n" \
79-
ALTINSTR_ENTRY_CB(feature, cb) \
79+
ALTINSTR_ENTRY_CB(cpucap, cb) \
8080
".popsection\n" \
8181
"663:\n\t" \
8282
"664:\n\t" \
8383
".endif\n"
8484

85-
#define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \
86-
__ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg))
85+
#define _ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, cfg, ...) \
86+
__ALTERNATIVE_CFG(oldinstr, newinstr, cpucap, IS_ENABLED(cfg))
8787

88-
#define ALTERNATIVE_CB(oldinstr, feature, cb) \
89-
__ALTERNATIVE_CFG_CB(oldinstr, (1 << ARM64_CB_SHIFT) | (feature), 1, cb)
88+
#define ALTERNATIVE_CB(oldinstr, cpucap, cb) \
89+
__ALTERNATIVE_CFG_CB(oldinstr, (1 << ARM64_CB_SHIFT) | (cpucap), 1, cb)
9090
#else
9191

9292
#include <asm/assembler.h>
9393

94-
.macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
94+
.macro altinstruction_entry orig_offset alt_offset cpucap orig_len alt_len
9595
.word \orig_offset - .
9696
.word \alt_offset - .
97-
.hword (\feature)
97+
.hword (\cpucap)
9898
.byte \orig_len
9999
.byte \alt_len
100100
.endm
@@ -210,9 +210,9 @@ alternative_endif
210210
#endif /* __ASSEMBLY__ */
211211

212212
/*
213-
* Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature));
213+
* Usage: asm(ALTERNATIVE(oldinstr, newinstr, cpucap));
214214
*
215-
* Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO));
215+
* Usage: asm(ALTERNATIVE(oldinstr, newinstr, cpucap, CONFIG_FOO));
216216
* N.B. If CONFIG_FOO is specified, but not selected, the whole block
217217
* will be omitted, including oldinstr.
218218
*/
@@ -224,15 +224,15 @@ alternative_endif
224224
#include <linux/types.h>
225225

226226
static __always_inline bool
227-
alternative_has_feature_likely(const unsigned long feature)
227+
alternative_has_cap_likely(const unsigned long cpucap)
228228
{
229-
compiletime_assert(feature < ARM64_NCAPS,
230-
"feature must be < ARM64_NCAPS");
229+
compiletime_assert(cpucap < ARM64_NCAPS,
230+
"cpucap must be < ARM64_NCAPS");
231231

232232
asm_volatile_goto(
233-
ALTERNATIVE_CB("b %l[l_no]", %[feature], alt_cb_patch_nops)
233+
ALTERNATIVE_CB("b %l[l_no]", %[cpucap], alt_cb_patch_nops)
234234
:
235-
: [feature] "i" (feature)
235+
: [cpucap] "i" (cpucap)
236236
:
237237
: l_no);
238238

@@ -242,15 +242,15 @@ alternative_has_feature_likely(const unsigned long feature)
242242
}
243243

244244
static __always_inline bool
245-
alternative_has_feature_unlikely(const unsigned long feature)
245+
alternative_has_cap_unlikely(const unsigned long cpucap)
246246
{
247-
compiletime_assert(feature < ARM64_NCAPS,
248-
"feature must be < ARM64_NCAPS");
247+
compiletime_assert(cpucap < ARM64_NCAPS,
248+
"cpucap must be < ARM64_NCAPS");
249249

250250
asm_volatile_goto(
251-
ALTERNATIVE("nop", "b %l[l_yes]", %[feature])
251+
ALTERNATIVE("nop", "b %l[l_yes]", %[cpucap])
252252
:
253-
: [feature] "i" (feature)
253+
: [cpucap] "i" (cpucap)
254254
:
255255
: l_yes);
256256

arch/arm64/include/asm/alternative.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
struct alt_instr {
1414
s32 orig_offset; /* offset to original instruction */
1515
s32 alt_offset; /* offset to replacement instruction */
16-
u16 cpufeature; /* cpufeature bit set for replacement */
16+
u16 cpucap; /* cpucap bit set for replacement */
1717
u8 orig_len; /* size of original instruction(s) */
1818
u8 alt_len; /* size of new instruction(s), <= orig_len */
1919
};
@@ -23,7 +23,7 @@ typedef void (*alternative_cb_t)(struct alt_instr *alt,
2323

2424
void __init apply_boot_alternatives(void);
2525
void __init apply_alternatives_all(void);
26-
bool alternative_is_applied(u16 cpufeature);
26+
bool alternative_is_applied(u16 cpucap);
2727

2828
#ifdef CONFIG_MODULES
2929
void apply_alternatives_module(void *start, size_t length);

arch/arm64/include/asm/cpufeature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ unsigned long cpu_get_elf_hwcap2(void);
437437

438438
static __always_inline bool system_capabilities_finalized(void)
439439
{
440-
return alternative_has_feature_likely(ARM64_ALWAYS_SYSTEM);
440+
return alternative_has_cap_likely(ARM64_ALWAYS_SYSTEM);
441441
}
442442

443443
/*
@@ -464,7 +464,7 @@ static __always_inline bool __cpus_have_const_cap(int num)
464464
{
465465
if (num >= ARM64_NCAPS)
466466
return false;
467-
return alternative_has_feature_unlikely(num);
467+
return alternative_has_cap_unlikely(num);
468468
}
469469

470470
/*

arch/arm64/include/asm/irqflags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
static __always_inline bool __irqflags_uses_pmr(void)
2525
{
2626
return IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) &&
27-
alternative_has_feature_unlikely(ARM64_HAS_GIC_PRIO_MASKING);
27+
alternative_has_cap_unlikely(ARM64_HAS_GIC_PRIO_MASKING);
2828
}
2929

3030
static __always_inline void __daif_local_irq_enable(void)

arch/arm64/include/asm/lse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
static __always_inline bool system_uses_lse_atomics(void)
2020
{
21-
return alternative_has_feature_likely(ARM64_HAS_LSE_ATOMICS);
21+
return alternative_has_cap_likely(ARM64_HAS_LSE_ATOMICS);
2222
}
2323

2424
#define __lse_ll_sc_body(op, ...) \

arch/arm64/kernel/alternative.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset)
2525
#define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset)
2626

27-
#define ALT_CAP(a) ((a)->cpufeature & ~ARM64_CB_BIT)
28-
#define ALT_HAS_CB(a) ((a)->cpufeature & ARM64_CB_BIT)
27+
#define ALT_CAP(a) ((a)->cpucap & ~ARM64_CB_BIT)
28+
#define ALT_HAS_CB(a) ((a)->cpucap & ARM64_CB_BIT)
2929

3030
/* Volatile, as we may be patching the guts of READ_ONCE() */
3131
static volatile int all_alternatives_applied;
@@ -37,12 +37,12 @@ struct alt_region {
3737
struct alt_instr *end;
3838
};
3939

40-
bool alternative_is_applied(u16 cpufeature)
40+
bool alternative_is_applied(u16 cpucap)
4141
{
42-
if (WARN_ON(cpufeature >= ARM64_NCAPS))
42+
if (WARN_ON(cpucap >= ARM64_NCAPS))
4343
return false;
4444

45-
return test_bit(cpufeature, applied_alternatives);
45+
return test_bit(cpucap, applied_alternatives);
4646
}
4747

4848
/*
@@ -141,7 +141,7 @@ static void clean_dcache_range_nopatch(u64 start, u64 end)
141141

142142
static void __apply_alternatives(const struct alt_region *region,
143143
bool is_module,
144-
unsigned long *feature_mask)
144+
unsigned long *cpucap_mask)
145145
{
146146
struct alt_instr *alt;
147147
__le32 *origptr, *updptr;
@@ -151,7 +151,7 @@ static void __apply_alternatives(const struct alt_region *region,
151151
int nr_inst;
152152
int cap = ALT_CAP(alt);
153153

154-
if (!test_bit(cap, feature_mask))
154+
if (!test_bit(cap, cpucap_mask))
155155
continue;
156156

157157
if (!cpus_have_cap(cap))
@@ -188,9 +188,8 @@ static void __apply_alternatives(const struct alt_region *region,
188188
icache_inval_all_pou();
189189
isb();
190190

191-
/* Ignore ARM64_CB bit from feature mask */
192191
bitmap_or(applied_alternatives, applied_alternatives,
193-
feature_mask, ARM64_NCAPS);
192+
cpucap_mask, ARM64_NCAPS);
194193
bitmap_and(applied_alternatives, applied_alternatives,
195194
system_cpucaps, ARM64_NCAPS);
196195
}

0 commit comments

Comments
 (0)