Skip to content

Commit 099bfaa

Browse files
davem330Alexei Starovoitov
authored andcommitted
bpf/stackmap: Dont trylock mmap_sem with PREEMPT_RT and interrupts disabled
In a RT kernel down_read_trylock() cannot be used from NMI context and up_read_non_owner() is another problematic issue. So in such a configuration, simply elide the annotated stackmap and just report the raw IPs. In the longer term, it might be possible to provide a atomic friendly versions of the page cache traversal which will at least provide the info if the pages are resident and don't need to be paged in. [ tglx: Use IS_ENABLED() to avoid the #ifdeffery, fixup the irq work callback and add a comment ] Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200224145644.708960317@linutronix.de
1 parent 66150d0 commit 099bfaa

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎kernel/bpf/stackmap.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static void do_up_read(struct irq_work *entry)
4040
{
4141
struct stack_map_irq_work *work;
4242

43+
if (WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT)))
44+
return;
45+
4346
work = container_of(entry, struct stack_map_irq_work, irq_work);
4447
up_read_non_owner(work->sem);
4548
work->sem = NULL;
@@ -288,10 +291,19 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
288291
struct stack_map_irq_work *work = NULL;
289292

290293
if (irqs_disabled()) {
291-
work = this_cpu_ptr(&up_read_work);
292-
if (atomic_read(&work->irq_work.flags) & IRQ_WORK_BUSY)
293-
/* cannot queue more up_read, fallback */
294+
if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
295+
work = this_cpu_ptr(&up_read_work);
296+
if (atomic_read(&work->irq_work.flags) & IRQ_WORK_BUSY) {
297+
/* cannot queue more up_read, fallback */
298+
irq_work_busy = true;
299+
}
300+
} else {
301+
/*
302+
* PREEMPT_RT does not allow to trylock mmap sem in
303+
* interrupt disabled context. Force the fallback code.
304+
*/
294305
irq_work_busy = true;
306+
}
295307
}
296308

297309
/*

0 commit comments

Comments
 (0)