Skip to content

Commit 22036ab

Browse files
Sebastian Andrzej Siewiortorvalds
authored andcommitted
kcov: avoid enable+disable interrupts if !in_task()
kcov_remote_start() may need to allocate memory in the in_task() case (otherwise per-CPU memory has been pre-allocated) and therefore requires enabled interrupts. The interrupts are enabled before checking if the allocation is required so if no allocation is required then the interrupts are needlessly enabled and disabled again. Enable interrupts only if memory allocation is performed. Link: https://lkml.kernel.org/r/20210923164741.1859522-5-bigeasy@linutronix.de Link: https://lore.kernel.org/r/20210830172627.267989-5-bigeasy@linutronix.de Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Marco Elver <elver@google.com> Tested-by: Marco Elver <elver@google.com> Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Cc: Clark Williams <williams@redhat.com> Cc: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 741ddd4 commit 22036ab

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/kcov.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,19 @@ void kcov_remote_start(u64 handle)
869869
size = CONFIG_KCOV_IRQ_AREA_SIZE;
870870
area = this_cpu_ptr(&kcov_percpu_data)->irq_area;
871871
}
872-
spin_unlock_irqrestore(&kcov_remote_lock, flags);
872+
spin_unlock(&kcov_remote_lock);
873873

874874
/* Can only happen when in_task(). */
875875
if (!area) {
876+
local_irqrestore(flags);
876877
area = vmalloc(size * sizeof(unsigned long));
877878
if (!area) {
878879
kcov_put(kcov);
879880
return;
880881
}
882+
local_irq_save(flags);
881883
}
882884

883-
local_irq_save(flags);
884-
885885
/* Reset coverage size. */
886886
*(u64 *)area = 0;
887887

0 commit comments

Comments
 (0)