All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Linux-MM <linux-mm@kvack.org>, Andrew Morton <akpm@linux-foundation.org>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Subject: [PATCH] mm: vmalloc: annotate find_vmap_area_exceed_addr_lock() for lockdep
Date: Tue, 26 Mar 2024 15:25:34 -0600	[thread overview]
Message-ID: <eaad5cd8-5d70-4890-a290-c04b07558c33@kernel.dk> (raw)

lockdep gets confused with the nested locking:

============================================
WARNING: possible recursive locking detected
6.9.0-rc1-00060-ged3ccc57b108-dirty #6140 Not tainted
--------------------------------------------
drgn/455 is trying to acquire lock:
ffff0000c00131d0 (&vn->busy.lock/1){+.+.}-{2:2}, at: find_vmap_area_exceed_addr_lock+0x64/0x124

but task is already holding lock:
ffff0000c0011878 (&vn->busy.lock/1){+.+.}-{2:2}, at: find_vmap_area_exceed_addr_lock+0x64/0x124

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&vn->busy.lock/1);
  lock(&vn->busy.lock/1);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

3 locks held by drgn/455:
 #0: ffff800081ecbba8 (kclist_lock){++++}-{3:3}, at: read_kcore_iter+0x5c/0xa24
 #1: ffff800081ea7688 (page_offline_rwsem){.+.+}-{3:3}, at: page_offline_freeze+0x14/0x1c
 #2: ffff0000c0011878 (&vn->busy.lock/1){+.+.}-{2:2}, at: find_vmap_area_exceed_addr_lock+0x64/0x124

stack backtrace:
CPU: 5 PID: 455 Comm: drgn Not tainted 6.9.0-rc1-00060-ged3ccc57b108-dirty #6140
Hardware name: linux,dummy-virt (DT)
Call trace:
 dump_backtrace+0x90/0xe4
 show_stack+0x14/0x1c
 dump_stack_lvl+0x84/0xc0
 dump_stack+0x14/0x1c
 print_deadlock_bug+0x24c/0x334
 __lock_acquire+0xdf4/0x20e0
 lock_acquire+0x204/0x330
 _raw_spin_lock_nested+0x40/0x54
 find_vmap_area_exceed_addr_lock+0x64/0x124
 vread_iter+0x44/0x428
 read_kcore_iter+0x170/0xa24
 proc_reg_read_iter+0x7c/0xcc
 vfs_read+0x220/0x2c4
 ksys_pread64+0x74/0xb4
 __arm64_sys_pread64+0x1c/0x24
 invoke_syscall+0x44/0x104
 el0_svc_common.constprop.0+0xb4/0xd4
 do_el0_svc+0x18/0x20
 el0_svc+0x44/0x108
 el0t_64_sync_handler+0x118/0x124
 el0t_64_sync+0x168/0x16c

which seems to be because it's missing the proper nested annotation.
Add the level annotation to make lockdep happy about this use case.

Fixes: 53becf32aec1 ("mm: vmalloc: support multiple nodes in vread_iter")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 22aa63f4ef63..26a69fa6809c 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1032,7 +1032,7 @@ find_vmap_area_exceed_addr_lock(unsigned long addr, struct vmap_area **va)
 	for (i = 0; i < nr_vmap_nodes; i++) {
 		vn = &vmap_nodes[i];
 
-		spin_lock(&vn->busy.lock);
+		spin_lock_nested(&vn->busy.lock, i);
 		va_lowest = __find_vmap_area_exceed_addr(addr, &vn->busy.root);
 		if (va_lowest) {
 			if (!va_node || va_lowest->va_start < (*va)->va_start) {
-- 
Jens Axboe



             reply	other threads:[~2024-03-26 21:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 21:25 Jens Axboe [this message]
2024-03-26 22:24 ` [PATCH] mm: vmalloc: annotate find_vmap_area_exceed_addr_lock() for lockdep Jens Axboe
2024-03-27  9:57   ` Uladzislau Rezki
2024-03-27 17:04     ` Uladzislau Rezki
2024-03-27 17:21       ` Jens Axboe
2024-03-27 17:40         ` Uladzislau Rezki
2024-03-27 17:22       ` Omar Sandoval
2024-03-27 17:41         ` Uladzislau Rezki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eaad5cd8-5d70-4890-a290-c04b07558c33@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=urezki@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.