Skip to content

ublk: fix maple tree lockdep warning and unpin under spinlock#779

Open
blktests-ci[bot] wants to merge 3 commits intofor-next_basefrom
series/1084082=>for-next
Open

ublk: fix maple tree lockdep warning and unpin under spinlock#779
blktests-ci[bot] wants to merge 3 commits intofor-next_basefrom
series/1084082=>for-next

Conversation

@blktests-ci
Copy link
Copy Markdown

@blktests-ci blktests-ci Bot commented Apr 29, 2026

Pull request for series with
subject: ublk: fix maple tree lockdep warning and unpin under spinlock
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1084082

axboe and others added 3 commits April 28, 2026 16:09
* block-7.1: (35 commits)
  md: use ATTRIBUTE_GROUPS() for md default sysfs attributes
  md: use mddev_is_dm() instead of open-coding gendisk checks
  md/raid1: replace wait loop with wait_event_idle() in raid1_write_request()
  md/md-bitmap: add a none backend for bitmap grow
  md/md-bitmap: split bitmap sysfs groups
  md: factor bitmap creation away from sysfs handling
  md: use mddev_lock_nointr() in mddev_suspend_and_lock_nointr()
  md: replace wait loop with wait_event() in md_handle_request()
  md/raid10: fix divide-by-zero in setup_geo() with zero far_copies
  md/raid1,raid10: don't fail devices for invalid IO errors
  MAINTAINERS: Add Xiao Ni as md/raid reviewer
  md/raid5: Fix UAF on IO across the reshape position
  cdrom, scsi: sr: propagate read-only status to block layer via set_disk_ro()
  nvme-auth: Hash DH shared secret to create session key
  nvme-pci: fix missed admin queue sq doorbell write
  nvme-auth: Include SC_C in RVAL controller hash
  nvme-tcp: teardown circular locking fixes
  nvmet-tcp: Don't clear tls_key when freeing sq
  Revert "nvmet-tcp: Don't free SQ on authentication success"
  nvme: skip trace completion for host path errors
  ...
* io_uring-7.1:
  io_uring/napi: cap busy_poll_to 10 msec
  io_uring/kbuf: support min length left for incremental buffers
  io_uring/kbuf: kill dead struct io_buffer_list 'nr_entries' member
@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented Apr 29, 2026

Upstream branch: fb9d71c
series: https://patchwork.kernel.org/project/linux-block/list/?series=1084082
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-block/list/?series=1084082
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: ublk: fix maple tree lockdep warning and unpin under spinlock
Using index info to reconstruct a base tree...
M	drivers/block/ublk_drv.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/block/ublk_drv.c
CONFLICT (content): Merge conflict in drivers/block/ublk_drv.c
Patch failed at 0001 ublk: fix maple tree lockdep warning and unpin under spinlock'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"'

conflict:

diff --cc drivers/block/ublk_drv.c
index 8e5f3738c203,0a92569c0c7d..000000000000
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@@ -5441,68 -5424,36 +5441,93 @@@ static void ublk_unpin_range_pages(unsi
  }
  
  /*
++<<<<<<< HEAD
 + * Inner loop: erase up to UBLK_REMOVE_BATCH matching ranges under
 + * mas_lock, collecting them into an xarray. Then drop the lock and
 + * unpin pages + free ranges outside spinlock context.
 + *
 + * Returns true if the tree walk completed, false if more ranges remain.
 + * Xarray key is the base PFN, value encodes nr_pages via xa_mk_value().
 + */
 +#define UBLK_REMOVE_BATCH	64
 +
 +static bool __ublk_shmem_remove_ranges(struct ublk_device *ub,
 +					int buf_index, int *ret)
 +{
 +	MA_STATE(mas, &ub->buf_tree, 0, ULONG_MAX);
 +	struct ublk_buf_range *range;
 +	struct xarray to_unpin;
 +	unsigned long idx;
 +	unsigned int count = 0;
 +	bool done = false;
 +	void *entry;
 +
 +	xa_init(&to_unpin);
 +
 +	mas_lock(&mas);
 +	mas_for_each(&mas, range, ULONG_MAX) {
 +		unsigned long nr;
++=======
+  * Drop mas_lock during iteration to avoid unpinning pages under spinlock.
+  * Safe because callers hold ub->mutex (via ublk_lock_buf_tree), preventing
+  * concurrent tree modifications.
+  */
+ static int __ublk_ctrl_unreg_buf(struct ublk_device *ub, int buf_index)
+ {
+ 	MA_STATE(mas, &ub->buf_tree, 0, ULONG_MAX);
+ 	struct ublk_buf_range *range;
+ 	int ret = -ENOENT;
+ 
+ 	mas_lock(&mas);
+ 	mas_for_each(&mas, range, ULONG_MAX) {
+ 		unsigned long base, nr;
++>>>>>>> ublk: fix maple tree lockdep warning and unpin under spinlock
  
 -		if (range->buf_index != buf_index)
 +		if (buf_index >= 0 && range->buf_index != buf_index)
  			continue;
  
 -		ret = 0;
 -		base = mas.index;
 -		nr = mas.last - base + 1;
 +		*ret = 0;
 +		nr = mas.last - mas.index + 1;
 +		if (xa_err(xa_store(&to_unpin, mas.index,
 +				    xa_mk_value(nr), GFP_ATOMIC)))
 +			goto unlock;
  		mas_erase(&mas);
++<<<<<<< HEAD
 +		kfree(range);
 +		if (++count >= UBLK_REMOVE_BATCH)
 +			goto unlock;
++=======
+ 		mas_unlock(&mas);
+ 
+ 		ublk_unpin_range_pages(base, nr);
+ 		kfree(range);
+ 
+ 		mas_lock(&mas);
++>>>>>>> ublk: fix maple tree lockdep warning and unpin under spinlock
  	}
 +	done = true;
 +unlock:
  	mas_unlock(&mas);
  
 +	xa_for_each(&to_unpin, idx, entry)
 +		ublk_unpin_range_pages(idx, xa_to_value(entry));
 +	xa_destroy(&to_unpin);
 +
 +	return done;
 +}
 +
 +/*
 + * Remove ranges from the maple tree matching buf_index, unpin pages
 + * and free range structs. If buf_index < 0, remove all ranges.
 + * Processes ranges in batches to avoid holding the maple tree spinlock
 + * across potentially expensive page unpinning.
 + */
 +static int ublk_shmem_remove_ranges(struct ublk_device *ub, int buf_index)
 +{
 +	int ret = -ENOENT;
 +
 +	while (!__ublk_shmem_remove_ranges(ub, buf_index, &ret))
 +		cond_resched();
  	return ret;
  }
  
@@@ -5529,9 -5480,27 +5554,31 @@@ static int ublk_ctrl_unreg_buf(struct u
  	return ret;
  }
  
+ /*
+  * Drop mas_lock during iteration to avoid unpinning pages under spinlock.
+  * Safe because this is called from device release with exclusive access.
+  */
  static void ublk_buf_cleanup(struct ublk_device *ub)
  {
++<<<<<<< HEAD
 +	ublk_shmem_remove_ranges(ub, -1);
++=======
+ 	MA_STATE(mas, &ub->buf_tree, 0, ULONG_MAX);
+ 	struct ublk_buf_range *range;
+ 
+ 	mas_lock(&mas);
+ 	mas_for_each(&mas, range, ULONG_MAX) {
+ 		unsigned long base = mas.index;
+ 		unsigned long nr = mas.last - base + 1;
+ 
+ 		mas_erase(&mas);
+ 		mas_unlock(&mas);
+ 		ublk_unpin_range_pages(base, nr);
+ 		kfree(range);
+ 		mas_lock(&mas);
+ 	}
+ 	mas_unlock(&mas);
++>>>>>>> ublk: fix maple tree lockdep warning and unpin under spinlock
  	mtree_destroy(&ub->buf_tree);
  	ida_destroy(&ub->buf_ida);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants