Skip to content

Commit 393e2ea

Browse files
Mark RutlandIngo Molnar
Mark Rutland
authored and
Ingo Molnar
committed
cpuidle: drivers: firmware: psci: Dont instrument suspend code
The PSCI suspend code is currently instrumentable, which is not safe as instrumentation (e.g. ftrace) may try to make use of RCU during idle periods when RCU is not watching. To fix this we need to ensure that psci_suspend_finisher() and anything it calls are not instrumented. We can do this fairly simply by marking psci_suspend_finisher() and the psci*_cpu_suspend() functions as noinstr, and the underlying helper functions as __always_inline. When CONFIG_DEBUG_VIRTUAL=y, __pa_symbol() can expand to an out-of-line instrumented function, so we must use __pa_symbol_nodebug() within psci_suspend_finisher(). The raw SMCCC invocation functions are written in assembly, and are not subject to compiler instrumentation. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20230126151323.349423061@infradead.org
1 parent 57a3021 commit 393e2ea

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

drivers/firmware/psci/psci.c

+19-12
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,29 @@ bool psci_power_state_is_valid(u32 state)
108108
return !(state & ~valid_mask);
109109
}
110110

111-
static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
112-
unsigned long arg0, unsigned long arg1,
113-
unsigned long arg2)
111+
static __always_inline unsigned long
112+
__invoke_psci_fn_hvc(unsigned long function_id,
113+
unsigned long arg0, unsigned long arg1,
114+
unsigned long arg2)
114115
{
115116
struct arm_smccc_res res;
116117

117118
arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
118119
return res.a0;
119120
}
120121

121-
static unsigned long __invoke_psci_fn_smc(unsigned long function_id,
122-
unsigned long arg0, unsigned long arg1,
123-
unsigned long arg2)
122+
static __always_inline unsigned long
123+
__invoke_psci_fn_smc(unsigned long function_id,
124+
unsigned long arg0, unsigned long arg1,
125+
unsigned long arg2)
124126
{
125127
struct arm_smccc_res res;
126128

127129
arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
128130
return res.a0;
129131
}
130132

131-
static int psci_to_linux_errno(int errno)
133+
static __always_inline int psci_to_linux_errno(int errno)
132134
{
133135
switch (errno) {
134136
case PSCI_RET_SUCCESS:
@@ -169,21 +171,24 @@ int psci_set_osi_mode(bool enable)
169171
return psci_to_linux_errno(err);
170172
}
171173

172-
static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point)
174+
static __always_inline int
175+
__psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point)
173176
{
174177
int err;
175178

176179
err = invoke_psci_fn(fn, state, entry_point, 0);
177180
return psci_to_linux_errno(err);
178181
}
179182

180-
static int psci_0_1_cpu_suspend(u32 state, unsigned long entry_point)
183+
static __always_inline int
184+
psci_0_1_cpu_suspend(u32 state, unsigned long entry_point)
181185
{
182186
return __psci_cpu_suspend(psci_0_1_function_ids.cpu_suspend,
183187
state, entry_point);
184188
}
185189

186-
static int psci_0_2_cpu_suspend(u32 state, unsigned long entry_point)
190+
static __always_inline int
191+
psci_0_2_cpu_suspend(u32 state, unsigned long entry_point)
187192
{
188193
return __psci_cpu_suspend(PSCI_FN_NATIVE(0_2, CPU_SUSPEND),
189194
state, entry_point);
@@ -450,10 +455,12 @@ late_initcall(psci_debugfs_init)
450455
#endif
451456

452457
#ifdef CONFIG_CPU_IDLE
453-
static int psci_suspend_finisher(unsigned long state)
458+
static noinstr int psci_suspend_finisher(unsigned long state)
454459
{
455460
u32 power_state = state;
456-
phys_addr_t pa_cpu_resume = __pa_symbol(cpu_resume);
461+
phys_addr_t pa_cpu_resume;
462+
463+
pa_cpu_resume = __pa_symbol_nodebug((unsigned long)cpu_resume);
457464

458465
return psci_ops.cpu_suspend(power_state, pa_cpu_resume);
459466
}

0 commit comments

Comments
 (0)