Skip to content

Commit a246daa

Browse files
mpegregkh
authored andcommitted
powerpc/pseries: Fix dtl_access_lock to be a rw_semaphore
[ Upstream commit cadae3a ] The dtl_access_lock needs to be a rw_sempahore, a sleeping lock, because the code calls kmalloc() while holding it, which can sleep: # echo 1 > /proc/powerpc/vcpudispatch_stats BUG: sleeping function called from invalid context at include/linux/sched/mm.h:337 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 199, name: sh preempt_count: 1, expected: 0 3 locks held by sh/199: #0: c00000000a0743f8 (sb_writers#3){.+.+}-{0:0}, at: vfs_write+0x324/0x438 #1: c0000000028c7058 (dtl_enable_mutex){+.+.}-{3:3}, at: vcpudispatch_stats_write+0xd4/0x5f4 #2: c0000000028c70b8 (dtl_access_lock){+.+.}-{2:2}, at: vcpudispatch_stats_write+0x220/0x5f4 CPU: 0 PID: 199 Comm: sh Not tainted 6.10.0-rc4 #152 Hardware name: IBM pSeries (emulated by qemu) POWER9 (raw) 0x4e1202 0xf000005 of:SLOF,HEAD hv:linux,kvm pSeries Call Trace: dump_stack_lvl+0x130/0x148 (unreliable) __might_resched+0x174/0x410 kmem_cache_alloc_noprof+0x340/0x3d0 alloc_dtl_buffers+0x124/0x1ac vcpudispatch_stats_write+0x2a8/0x5f4 proc_reg_write+0xf4/0x150 vfs_write+0xfc/0x438 ksys_write+0x88/0x148 system_call_exception+0x1c4/0x5a0 system_call_common+0xf4/0x258 Fixes: 06220d7 ("powerpc/pseries: Introduce rwlock to gatekeep DTLB usage") Tested-by: Kajol Jain <[email protected]> Reviewed-by: Nysal Jan K.A <[email protected]> Reviewed-by: Kajol Jain <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 8a06435 commit a246daa

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

arch/powerpc/include/asm/dtl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef _ASM_POWERPC_DTL_H
22
#define _ASM_POWERPC_DTL_H
33

4+
#include <linux/rwsem.h>
45
#include <asm/lppaca.h>
5-
#include <linux/spinlock_types.h>
66

77
/*
88
* Layout of entries in the hypervisor's dispatch trace log buffer.
@@ -35,7 +35,7 @@ struct dtl_entry {
3535
#define DTL_LOG_ALL (DTL_LOG_CEDE | DTL_LOG_PREEMPT | DTL_LOG_FAULT)
3636

3737
extern struct kmem_cache *dtl_cache;
38-
extern rwlock_t dtl_access_lock;
38+
extern struct rw_semaphore dtl_access_lock;
3939

4040
extern void register_dtl_buffer(int cpu);
4141
extern void alloc_dtl_buffers(unsigned long *time_limit);

arch/powerpc/platforms/pseries/dtl.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ static int dtl_enable(struct dtl *dtl)
191191
return -EBUSY;
192192

193193
/* ensure there are no other conflicting dtl users */
194-
if (!read_trylock(&dtl_access_lock))
194+
if (!down_read_trylock(&dtl_access_lock))
195195
return -EBUSY;
196196

197197
n_entries = dtl_buf_entries;
198198
buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL, cpu_to_node(dtl->cpu));
199199
if (!buf) {
200200
printk(KERN_WARNING "%s: buffer alloc failed for cpu %d\n",
201201
__func__, dtl->cpu);
202-
read_unlock(&dtl_access_lock);
202+
up_read(&dtl_access_lock);
203203
return -ENOMEM;
204204
}
205205

@@ -217,7 +217,7 @@ static int dtl_enable(struct dtl *dtl)
217217
spin_unlock(&dtl->lock);
218218

219219
if (rc) {
220-
read_unlock(&dtl_access_lock);
220+
up_read(&dtl_access_lock);
221221
kmem_cache_free(dtl_cache, buf);
222222
}
223223

@@ -232,7 +232,7 @@ static void dtl_disable(struct dtl *dtl)
232232
dtl->buf = NULL;
233233
dtl->buf_entries = 0;
234234
spin_unlock(&dtl->lock);
235-
read_unlock(&dtl_access_lock);
235+
up_read(&dtl_access_lock);
236236
}
237237

238238
/* file interface */

arch/powerpc/platforms/pseries/lpar.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct vcpu_dispatch_data {
169169
*/
170170
#define NR_CPUS_H NR_CPUS
171171

172-
DEFINE_RWLOCK(dtl_access_lock);
172+
DECLARE_RWSEM(dtl_access_lock);
173173
static DEFINE_PER_CPU(struct vcpu_dispatch_data, vcpu_disp_data);
174174
static DEFINE_PER_CPU(u64, dtl_entry_ridx);
175175
static DEFINE_PER_CPU(struct dtl_worker, dtl_workers);
@@ -463,7 +463,7 @@ static int dtl_worker_enable(unsigned long *time_limit)
463463
{
464464
int rc = 0, state;
465465

466-
if (!write_trylock(&dtl_access_lock)) {
466+
if (!down_write_trylock(&dtl_access_lock)) {
467467
rc = -EBUSY;
468468
goto out;
469469
}
@@ -479,7 +479,7 @@ static int dtl_worker_enable(unsigned long *time_limit)
479479
pr_err("vcpudispatch_stats: unable to setup workqueue for DTL processing\n");
480480
free_dtl_buffers(time_limit);
481481
reset_global_dtl_mask();
482-
write_unlock(&dtl_access_lock);
482+
up_write(&dtl_access_lock);
483483
rc = -EINVAL;
484484
goto out;
485485
}
@@ -494,7 +494,7 @@ static void dtl_worker_disable(unsigned long *time_limit)
494494
cpuhp_remove_state(dtl_worker_state);
495495
free_dtl_buffers(time_limit);
496496
reset_global_dtl_mask();
497-
write_unlock(&dtl_access_lock);
497+
up_write(&dtl_access_lock);
498498
}
499499

500500
static ssize_t vcpudispatch_stats_write(struct file *file, const char __user *p,

0 commit comments

Comments
 (0)