Commit 3096280
ublk: fix maple tree lockdep warning and unpin under spinlock
Fix two issues in the shmem buffer maple tree usage:
1) ublk_buf_cleanup() iterates the tree with mas_for_each() without
holding rcu_read_lock or mas_lock, triggering a lockdep splat on
CONFIG_PROVE_RCU kernels. Add mas_lock/unlock around the iteration.
2) __ublk_ctrl_unreg_buf() calls unpin_user_pages() under mas_lock
(a spinlock). unpin_user_pages can be expensive for large buffers
and may take additional locks if folio refcount drops to zero.
Restructure to drop mas_lock before unpinning, re-acquiring it
to continue iteration.
Both functions now use the same pattern: erase under lock, drop lock,
unpin and free, re-lock to continue. Extract ublk_unpin_range_pages()
helper to share the page unpinning loop.
Reported-by: Jens Axboe <[email protected]>
Closes: https://lore.kernel.org/linux-block/[email protected]/
Cc: Liam R. Howlett <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
Tested-by: Shin'ichiro Kawasaki <[email protected]>1 parent 59ca59b commit 3096280
1 file changed
Lines changed: 39 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5413 | 5413 | | |
5414 | 5414 | | |
5415 | 5415 | | |
| 5416 | + | |
| 5417 | + | |
| 5418 | + | |
| 5419 | + | |
| 5420 | + | |
| 5421 | + | |
| 5422 | + | |
| 5423 | + | |
| 5424 | + | |
| 5425 | + | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
| 5430 | + | |
| 5431 | + | |
| 5432 | + | |
| 5433 | + | |
| 5434 | + | |
| 5435 | + | |
| 5436 | + | |
| 5437 | + | |
| 5438 | + | |
| 5439 | + | |
5416 | 5440 | | |
5417 | 5441 | | |
5418 | 5442 | | |
5419 | 5443 | | |
5420 | | - | |
5421 | 5444 | | |
5422 | 5445 | | |
5423 | 5446 | | |
5424 | 5447 | | |
5425 | | - | |
| 5448 | + | |
5426 | 5449 | | |
5427 | 5450 | | |
5428 | 5451 | | |
| |||
5431 | 5454 | | |
5432 | 5455 | | |
5433 | 5456 | | |
| 5457 | + | |
5434 | 5458 | | |
5435 | | - | |
5436 | | - | |
5437 | | - | |
5438 | | - | |
5439 | | - | |
5440 | | - | |
5441 | | - | |
5442 | | - | |
5443 | | - | |
5444 | | - | |
| 5459 | + | |
5445 | 5460 | | |
| 5461 | + | |
| 5462 | + | |
5446 | 5463 | | |
5447 | 5464 | | |
5448 | 5465 | | |
| |||
5472 | 5489 | | |
5473 | 5490 | | |
5474 | 5491 | | |
| 5492 | + | |
| 5493 | + | |
| 5494 | + | |
| 5495 | + | |
5475 | 5496 | | |
5476 | 5497 | | |
5477 | 5498 | | |
5478 | 5499 | | |
5479 | | - | |
5480 | 5500 | | |
| 5501 | + | |
5481 | 5502 | | |
5482 | 5503 | | |
5483 | 5504 | | |
5484 | | - | |
5485 | 5505 | | |
5486 | | - | |
5487 | | - | |
5488 | | - | |
5489 | | - | |
5490 | | - | |
5491 | | - | |
5492 | | - | |
5493 | | - | |
5494 | | - | |
5495 | | - | |
| 5506 | + | |
| 5507 | + | |
| 5508 | + | |
5496 | 5509 | | |
| 5510 | + | |
5497 | 5511 | | |
| 5512 | + | |
5498 | 5513 | | |
5499 | 5514 | | |
5500 | 5515 | | |
| |||
0 commit comments