Skip to content

Commit 731dc9d

Browse files
tyhicksKAGA-KOKO
authored andcommitted
cpu/speculation: Uninline and export CPU mitigations helpers
A kernel module may need to check the value of the "mitigations=" kernel command line parameter as part of its setup when the module needs to perform software mitigations for a CPU flaw. Uninline and export the helper functions surrounding the cpu_mitigations enum to allow for their usage from a module. Lastly, privatize the enum and cpu_mitigations variable since the value of cpu_mitigations can be checked with the exported helper functions. Signed-off-by: Tyler Hicks <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent cad1488 commit 731dc9d

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

include/linux/cpu.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,28 +218,7 @@ static inline int cpuhp_smt_enable(void) { return 0; }
218218
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
219219
#endif
220220

221-
/*
222-
* These are used for a global "mitigations=" cmdline option for toggling
223-
* optional CPU mitigations.
224-
*/
225-
enum cpu_mitigations {
226-
CPU_MITIGATIONS_OFF,
227-
CPU_MITIGATIONS_AUTO,
228-
CPU_MITIGATIONS_AUTO_NOSMT,
229-
};
230-
231-
extern enum cpu_mitigations cpu_mitigations;
232-
233-
/* mitigations=off */
234-
static inline bool cpu_mitigations_off(void)
235-
{
236-
return cpu_mitigations == CPU_MITIGATIONS_OFF;
237-
}
238-
239-
/* mitigations=auto,nosmt */
240-
static inline bool cpu_mitigations_auto_nosmt(void)
241-
{
242-
return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT;
243-
}
221+
extern bool cpu_mitigations_off(void);
222+
extern bool cpu_mitigations_auto_nosmt(void);
244223

245224
#endif /* _LINUX_CPU_H_ */

kernel/cpu.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,18 @@ void __init boot_cpu_hotplug_init(void)
23732373
this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
23742374
}
23752375

2376-
enum cpu_mitigations cpu_mitigations __ro_after_init = CPU_MITIGATIONS_AUTO;
2376+
/*
2377+
* These are used for a global "mitigations=" cmdline option for toggling
2378+
* optional CPU mitigations.
2379+
*/
2380+
enum cpu_mitigations {
2381+
CPU_MITIGATIONS_OFF,
2382+
CPU_MITIGATIONS_AUTO,
2383+
CPU_MITIGATIONS_AUTO_NOSMT,
2384+
};
2385+
2386+
static enum cpu_mitigations cpu_mitigations __ro_after_init =
2387+
CPU_MITIGATIONS_AUTO;
23772388

23782389
static int __init mitigations_parse_cmdline(char *arg)
23792390
{
@@ -2390,3 +2401,17 @@ static int __init mitigations_parse_cmdline(char *arg)
23902401
return 0;
23912402
}
23922403
early_param("mitigations", mitigations_parse_cmdline);
2404+
2405+
/* mitigations=off */
2406+
bool cpu_mitigations_off(void)
2407+
{
2408+
return cpu_mitigations == CPU_MITIGATIONS_OFF;
2409+
}
2410+
EXPORT_SYMBOL_GPL(cpu_mitigations_off);
2411+
2412+
/* mitigations=auto,nosmt */
2413+
bool cpu_mitigations_auto_nosmt(void)
2414+
{
2415+
return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT;
2416+
}
2417+
EXPORT_SYMBOL_GPL(cpu_mitigations_auto_nosmt);

0 commit comments

Comments
 (0)