Skip to content

Commit 19bef63

Browse files
quic-pheraguwilldeacon
authored andcommitted
arm64: paravirt: Use RCU read locks to guard stolen_time
During hotplug, the stolen time data structure is unmapped and memset. There is a possibility of the timer IRQ being triggered before memset and stolen time is getting updated as part of this timer IRQ handler. This causes the below crash in timer handler - [ 3457.473139][ C5] Unable to handle kernel paging request at virtual address ffffffc03df05148 ... [ 3458.154398][ C5] Call trace: [ 3458.157648][ C5] para_steal_clock+0x30/0x50 [ 3458.162319][ C5] irqtime_account_process_tick+0x30/0x194 [ 3458.168148][ C5] account_process_tick+0x3c/0x280 [ 3458.173274][ C5] update_process_times+0x5c/0xf4 [ 3458.178311][ C5] tick_sched_timer+0x180/0x384 [ 3458.183164][ C5] __run_hrtimer+0x160/0x57c [ 3458.187744][ C5] hrtimer_interrupt+0x258/0x684 [ 3458.192698][ C5] arch_timer_handler_virt+0x5c/0xa0 [ 3458.198002][ C5] handle_percpu_devid_irq+0xdc/0x414 [ 3458.203385][ C5] handle_domain_irq+0xa8/0x168 [ 3458.208241][ C5] gic_handle_irq.34493+0x54/0x244 [ 3458.213359][ C5] call_on_irq_stack+0x40/0x70 [ 3458.218125][ C5] do_interrupt_handler+0x60/0x9c [ 3458.223156][ C5] el1_interrupt+0x34/0x64 [ 3458.227560][ C5] el1h_64_irq_handler+0x1c/0x2c [ 3458.232503][ C5] el1h_64_irq+0x7c/0x80 [ 3458.236736][ C5] free_vmap_area_noflush+0x108/0x39c [ 3458.242126][ C5] remove_vm_area+0xbc/0x118 [ 3458.246714][ C5] vm_remove_mappings+0x48/0x2a4 [ 3458.251656][ C5] __vunmap+0x154/0x278 [ 3458.255796][ C5] stolen_time_cpu_down_prepare+0xc0/0xd8 [ 3458.261542][ C5] cpuhp_invoke_callback+0x248/0xc34 [ 3458.266842][ C5] cpuhp_thread_fun+0x1c4/0x248 [ 3458.271696][ C5] smpboot_thread_fn+0x1b0/0x400 [ 3458.276638][ C5] kthread+0x17c/0x1e0 [ 3458.280691][ C5] ret_from_fork+0x10/0x20 As a fix, introduce rcu lock to update stolen time structure. Fixes: 75df529 ("arm64: paravirt: Initialize steal time when cpu is online") Cc: [email protected] Suggested-by: Will Deacon <[email protected]> Signed-off-by: Prakruthi Deepak Heragu <[email protected]> Signed-off-by: Elliot Berman <[email protected]> Reviewed-by: Srivatsa S. Bhat (VMware) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 51f559d commit 19bef63

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

arch/arm64/kernel/paravirt.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static u64 native_steal_clock(int cpu)
3535
DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock);
3636

3737
struct pv_time_stolen_time_region {
38-
struct pvclock_vcpu_stolen_time *kaddr;
38+
struct pvclock_vcpu_stolen_time __rcu *kaddr;
3939
};
4040

4141
static DEFINE_PER_CPU(struct pv_time_stolen_time_region, stolen_time_region);
@@ -52,7 +52,9 @@ early_param("no-steal-acc", parse_no_stealacc);
5252
/* return stolen time in ns by asking the hypervisor */
5353
static u64 para_steal_clock(int cpu)
5454
{
55+
struct pvclock_vcpu_stolen_time *kaddr = NULL;
5556
struct pv_time_stolen_time_region *reg;
57+
u64 ret = 0;
5658

5759
reg = per_cpu_ptr(&stolen_time_region, cpu);
5860

@@ -61,28 +63,37 @@ static u64 para_steal_clock(int cpu)
6163
* online notification callback runs. Until the callback
6264
* has run we just return zero.
6365
*/
64-
if (!reg->kaddr)
66+
rcu_read_lock();
67+
kaddr = rcu_dereference(reg->kaddr);
68+
if (!kaddr) {
69+
rcu_read_unlock();
6570
return 0;
71+
}
6672

67-
return le64_to_cpu(READ_ONCE(reg->kaddr->stolen_time));
73+
ret = le64_to_cpu(READ_ONCE(kaddr->stolen_time));
74+
rcu_read_unlock();
75+
return ret;
6876
}
6977

7078
static int stolen_time_cpu_down_prepare(unsigned int cpu)
7179
{
80+
struct pvclock_vcpu_stolen_time *kaddr = NULL;
7281
struct pv_time_stolen_time_region *reg;
7382

7483
reg = this_cpu_ptr(&stolen_time_region);
7584
if (!reg->kaddr)
7685
return 0;
7786

78-
memunmap(reg->kaddr);
79-
memset(reg, 0, sizeof(*reg));
87+
kaddr = rcu_replace_pointer(reg->kaddr, NULL, true);
88+
synchronize_rcu();
89+
memunmap(kaddr);
8090

8191
return 0;
8292
}
8393

8494
static int stolen_time_cpu_online(unsigned int cpu)
8595
{
96+
struct pvclock_vcpu_stolen_time *kaddr = NULL;
8697
struct pv_time_stolen_time_region *reg;
8798
struct arm_smccc_res res;
8899

@@ -93,17 +104,19 @@ static int stolen_time_cpu_online(unsigned int cpu)
93104
if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
94105
return -EINVAL;
95106

96-
reg->kaddr = memremap(res.a0,
107+
kaddr = memremap(res.a0,
97108
sizeof(struct pvclock_vcpu_stolen_time),
98109
MEMREMAP_WB);
99110

111+
rcu_assign_pointer(reg->kaddr, kaddr);
112+
100113
if (!reg->kaddr) {
101114
pr_warn("Failed to map stolen time data structure\n");
102115
return -ENOMEM;
103116
}
104117

105-
if (le32_to_cpu(reg->kaddr->revision) != 0 ||
106-
le32_to_cpu(reg->kaddr->attributes) != 0) {
118+
if (le32_to_cpu(kaddr->revision) != 0 ||
119+
le32_to_cpu(kaddr->attributes) != 0) {
107120
pr_warn_once("Unexpected revision or attributes in stolen time data\n");
108121
return -ENXIO;
109122
}

0 commit comments

Comments
 (0)