Commit 393e2ea3 authored by Mark Rutland's avatar Mark Rutland Committed by Ingo Molnar

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: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230126151323.349423061@infradead.org
parent 57a30218
......@@ -108,7 +108,8 @@ bool psci_power_state_is_valid(u32 state)
return !(state & ~valid_mask);
}
static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
static __always_inline unsigned long
__invoke_psci_fn_hvc(unsigned long function_id,
unsigned long arg0, unsigned long arg1,
unsigned long arg2)
{
......@@ -118,7 +119,8 @@ static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
return res.a0;
}
static unsigned long __invoke_psci_fn_smc(unsigned long function_id,
static __always_inline unsigned long
__invoke_psci_fn_smc(unsigned long function_id,
unsigned long arg0, unsigned long arg1,
unsigned long arg2)
{
......@@ -128,7 +130,7 @@ static unsigned long __invoke_psci_fn_smc(unsigned long function_id,
return res.a0;
}
static int psci_to_linux_errno(int errno)
static __always_inline int psci_to_linux_errno(int errno)
{
switch (errno) {
case PSCI_RET_SUCCESS:
......@@ -169,7 +171,8 @@ int psci_set_osi_mode(bool enable)
return psci_to_linux_errno(err);
}
static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point)
static __always_inline int
__psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point)
{
int err;
......@@ -177,13 +180,15 @@ static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point)
return psci_to_linux_errno(err);
}
static int psci_0_1_cpu_suspend(u32 state, unsigned long entry_point)
static __always_inline int
psci_0_1_cpu_suspend(u32 state, unsigned long entry_point)
{
return __psci_cpu_suspend(psci_0_1_function_ids.cpu_suspend,
state, entry_point);
}
static int psci_0_2_cpu_suspend(u32 state, unsigned long entry_point)
static __always_inline int
psci_0_2_cpu_suspend(u32 state, unsigned long entry_point)
{
return __psci_cpu_suspend(PSCI_FN_NATIVE(0_2, CPU_SUSPEND),
state, entry_point);
......@@ -450,10 +455,12 @@ late_initcall(psci_debugfs_init)
#endif
#ifdef CONFIG_CPU_IDLE
static int psci_suspend_finisher(unsigned long state)
static noinstr int psci_suspend_finisher(unsigned long state)
{
u32 power_state = state;
phys_addr_t pa_cpu_resume = __pa_symbol(cpu_resume);
phys_addr_t pa_cpu_resume;
pa_cpu_resume = __pa_symbol_nodebug((unsigned long)cpu_resume);
return psci_ops.cpu_suspend(power_state, pa_cpu_resume);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment