Skip to content

Commit cadae3a

Browse files
committed
powerpc/pseries: Fix dtl_access_lock to be a rw_semaphore
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 <kjain@linux.ibm.com> Reviewed-by: Nysal Jan K.A <nysal@linux.ibm.com> Reviewed-by: Kajol Jain <kjain@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://patch.msgid.link/20240819122401.513203-1-mpe@ellerman.id.au
1 parent b23b9ed commit cadae3a

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
@@ -170,7 +170,7 @@ struct vcpu_dispatch_data {
170170
*/
171171
#define NR_CPUS_H NR_CPUS
172172

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

467-
if (!write_trylock(&dtl_access_lock)) {
467+
if (!down_write_trylock(&dtl_access_lock)) {
468468
rc = -EBUSY;
469469
goto out;
470470
}
@@ -480,7 +480,7 @@ static int dtl_worker_enable(unsigned long *time_limit)
480480
pr_err("vcpudispatch_stats: unable to setup workqueue for DTL processing\n");
481481
free_dtl_buffers(time_limit);
482482
reset_global_dtl_mask();
483-
write_unlock(&dtl_access_lock);
483+
up_write(&dtl_access_lock);
484484
rc = -EINVAL;
485485
goto out;
486486
}
@@ -495,7 +495,7 @@ static void dtl_worker_disable(unsigned long *time_limit)
495495
cpuhp_remove_state(dtl_worker_state);
496496
free_dtl_buffers(time_limit);
497497
reset_global_dtl_mask();
498-
write_unlock(&dtl_access_lock);
498+
up_write(&dtl_access_lock);
499499
}
500500

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

0 commit comments

Comments
 (0)