Blob Blame History Raw
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Fri, 6 Mar 2020 15:59:06 +0100
Subject: [PATCH] mm: Warn on memory allocation in non-preemptible context on
 RT
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git
Git-commit: 393527e40ef478626a56439714743e7b17fcd7f1
Patch-mainline: Queued in subsystem maintainer repository
References: SLE Realtime Extension

The memory allocation via kmalloc(, GFP_ATOMIC) in atomic context
(disabled preemption or interrupts) is not allowed on RT because the
buddy allocator is using sleeping locks which can't be acquired in this
context.
Such an an allocation may not trigger a warning in the buddy allocator
if it is always satisfied in the SLUB allocator.

Add a warning on RT if a memory allocation was attempted in not
preemptible region.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 mm/slub.c |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2687,6 +2687,9 @@ static __always_inline void *slab_alloc_
 	struct page *page;
 	unsigned long tid;
 
+	if (IS_ENABLED(CONFIG_PREEMPT_RT) && IS_ENABLED(CONFIG_DEBUG_ATOMIC_SLEEP))
+		WARN_ON_ONCE(!preemptible() && system_state >= SYSTEM_SCHEDULING);
+
 	s = slab_pre_alloc_hook(s, gfpflags);
 	if (!s)
 		return NULL;
@@ -3148,6 +3151,9 @@ int kmem_cache_alloc_bulk(struct kmem_ca
 	struct kmem_cache_cpu *c;
 	int i;
 
+	if (IS_ENABLED(CONFIG_PREEMPT_RT) && IS_ENABLED(CONFIG_DEBUG_ATOMIC_SLEEP))
+		WARN_ON_ONCE(!preemptible() && system_state >= SYSTEM_SCHEDULING);
+
 	/* memcg and kmem_cache debug support */
 	s = slab_pre_alloc_hook(s, flags);
 	if (unlikely(!s))