linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/util.c: Make kvfree() safe for calling while holding spinlocks
@ 2021-12-22 19:48 Manfred Spraul
  2021-12-23  3:40 ` Davidlohr Bueso
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Manfred Spraul @ 2021-12-22 19:48 UTC (permalink / raw)
  To: LKML, Andrew Morton
  Cc: Vasily Averin, cgel.zte, shakeelb, rdunlap, dbueso, unixbhaskar,
	chi.minghao, arnd, Zeal Robot, linux-mm, 1vier1, Manfred Spraul,
	stable

One codepath in find_alloc_undo() calls kvfree() while holding a spinlock.
Since vfree() can sleep this is a bug.

Previously, the code path used kfree(), and kfree() is safe to be called
while holding a spinlock.

Minghao proposed to fix this by updating find_alloc_undo().

Alternate proposal to fix this: Instead of changing find_alloc_undo(),
change kvfree() so that the same rules as for kfree() apply:
Having different rules for kfree() and kvfree() just asks for bugs.

Disadvantage: Releasing vmalloc'ed memory will be delayed a bit.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Reported-by: Minghao Chi <chi.minghao@zte.com.cn>
Link: https://lore.kernel.org/all/20211222081026.484058-1-chi.minghao@zte.com.cn/
Fixes: fc37a3b8b438 ("[PATCH] ipc sem: use kvmalloc for sem_undo allocation")
Cc: stable@vger.kernel.org
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
---
 mm/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index 741ba32a43ac..7f9181998835 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -610,12 +610,12 @@ EXPORT_SYMBOL(kvmalloc_node);
  * It is slightly more efficient to use kfree() or vfree() if you are certain
  * that you know which one to use.
  *
- * Context: Either preemptible task context or not-NMI interrupt.
+ * Context: Any context except NMI interrupt.
  */
 void kvfree(const void *addr)
 {
 	if (is_vmalloc_addr(addr))
-		vfree(addr);
+		vfree_atomic(addr);
 	else
 		kfree(addr);
 }
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-01-27 15:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 19:48 [PATCH] mm/util.c: Make kvfree() safe for calling while holding spinlocks Manfred Spraul
2021-12-23  3:40 ` Davidlohr Bueso
2021-12-23  7:21 ` Vasily Averin
2021-12-23 11:52   ` Manfred Spraul
2021-12-23 12:34     ` Vasily Averin
2021-12-25 18:54 ` Uladzislau Rezki
2021-12-25 22:58   ` Matthew Wilcox
2021-12-26 17:57     ` Uladzislau Rezki
2021-12-28 19:45       ` Uladzislau Rezki
2021-12-28 20:04         ` Manfred Spraul
2021-12-28 20:26           ` Uladzislau Rezki
2022-01-27  2:53 ` Andrew Morton
2022-01-27  5:59   ` Manfred Spraul
2022-01-27  8:25     ` Michal Hocko
2022-01-27 15:54       ` Uladzislau Rezki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).