Skip to content

Commit 75df529

Browse files
Andrew Jonesctmarinas
authored andcommitted
arm64: paravirt: Initialize steal time when cpu is online
Steal time initialization requires mapping a memory region which invokes a memory allocation. Doing this at CPU starting time results in the following trace when CONFIG_DEBUG_ATOMIC_SLEEP is enabled: BUG: sleeping function called from invalid context at mm/slab.h:498 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/1 CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.9.0-rc5+ #1 Call trace: dump_backtrace+0x0/0x208 show_stack+0x1c/0x28 dump_stack+0xc4/0x11c ___might_sleep+0xf8/0x130 __might_sleep+0x58/0x90 slab_pre_alloc_hook.constprop.101+0xd0/0x118 kmem_cache_alloc_node_trace+0x84/0x270 __get_vm_area_node+0x88/0x210 get_vm_area_caller+0x38/0x40 __ioremap_caller+0x70/0xf8 ioremap_cache+0x78/0xb0 memremap+0x9c/0x1a8 init_stolen_time_cpu+0x54/0xf0 cpuhp_invoke_callback+0xa8/0x720 notify_cpu_starting+0xc8/0xd8 secondary_start_kernel+0x114/0x180 CPU1: Booted secondary processor 0x0000000001 [0x431f0a11] However we don't need to initialize steal time at CPU starting time. We can simply wait until CPU online time, just sacrificing a bit of accuracy by returning zero for steal time until we know better. While at it, add __init to the functions that are only called by pv_time_init() which is __init. Signed-off-by: Andrew Jones <[email protected]> Fixes: e0685fa ("arm64: Retrieve stolen time as paravirtualized guest") Cc: [email protected] Reviewed-by: Steven Price <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 32f6865 commit 75df529

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

arch/arm64/kernel/paravirt.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ static u64 pv_steal_clock(int cpu)
5050
struct pv_time_stolen_time_region *reg;
5151

5252
reg = per_cpu_ptr(&stolen_time_region, cpu);
53-
if (!reg->kaddr) {
54-
pr_warn_once("stolen time enabled but not configured for cpu %d\n",
55-
cpu);
53+
54+
/*
55+
* paravirt_steal_clock() may be called before the CPU
56+
* online notification callback runs. Until the callback
57+
* has run we just return zero.
58+
*/
59+
if (!reg->kaddr)
5660
return 0;
57-
}
5861

5962
return le64_to_cpu(READ_ONCE(reg->kaddr->stolen_time));
6063
}
6164

62-
static int stolen_time_dying_cpu(unsigned int cpu)
65+
static int stolen_time_cpu_down_prepare(unsigned int cpu)
6366
{
6467
struct pv_time_stolen_time_region *reg;
6568

@@ -73,7 +76,7 @@ static int stolen_time_dying_cpu(unsigned int cpu)
7376
return 0;
7477
}
7578

76-
static int init_stolen_time_cpu(unsigned int cpu)
79+
static int stolen_time_cpu_online(unsigned int cpu)
7780
{
7881
struct pv_time_stolen_time_region *reg;
7982
struct arm_smccc_res res;
@@ -103,19 +106,20 @@ static int init_stolen_time_cpu(unsigned int cpu)
103106
return 0;
104107
}
105108

106-
static int pv_time_init_stolen_time(void)
109+
static int __init pv_time_init_stolen_time(void)
107110
{
108111
int ret;
109112

110-
ret = cpuhp_setup_state(CPUHP_AP_ARM_KVMPV_STARTING,
111-
"hypervisor/arm/pvtime:starting",
112-
init_stolen_time_cpu, stolen_time_dying_cpu);
113+
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
114+
"hypervisor/arm/pvtime:online",
115+
stolen_time_cpu_online,
116+
stolen_time_cpu_down_prepare);
113117
if (ret < 0)
114118
return ret;
115119
return 0;
116120
}
117121

118-
static bool has_pv_steal_clock(void)
122+
static bool __init has_pv_steal_clock(void)
119123
{
120124
struct arm_smccc_res res;
121125

include/linux/cpuhotplug.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ enum cpuhp_state {
142142
/* Must be the last timer callback */
143143
CPUHP_AP_DUMMY_TIMER_STARTING,
144144
CPUHP_AP_ARM_XEN_STARTING,
145-
CPUHP_AP_ARM_KVMPV_STARTING,
146145
CPUHP_AP_ARM_CORESIGHT_STARTING,
147146
CPUHP_AP_ARM_CORESIGHT_CTI_STARTING,
148147
CPUHP_AP_ARM64_ISNDEP_STARTING,

0 commit comments

Comments
 (0)