nbd: skip queue limits update for size-only reconfigure
Subsystems (2)
syzbot
syzbotCommit 242a49e5c878 ("nbd: fix queue freeze vs limits lock order") correctly added queue freezing for live updates of real queue limits. However, nbd_set_size() is also used for capacity-only generic netlink updates, so the freeze is unnecessarily broad for the reported request.
When an NBD server becomes unresponsive, it leaves I/O in flight. An unnecessary queue freeze during a size-only reconfigure will wait forever for these in-flight I/Os to complete while the global genl_mutex is held, leading to a system-wide deadlock.
A size-only reconfigure can update config->bytesize and disk capacity directly because the effective block size and all other queue limits stay unchanged.
This patch introduces nbd_size_set() to handle size-only updates directly without freezing the queue or committing queue limits. Startup and actual block-size changes continue to use the existing frozen limits update via nbd_set_size().
INFO: task nbd-client:6285 blocked for more than 143 seconds. Call Trace: <TASK> blk_mq_freeze_queue_wait+0x101/0x180 block/blk-mq.c:191 queue_limits_commit_update_frozen+0x55/0xd0 block/blk-settings.c:590 nbd_set_size+0x454/0x680 drivers/block/nbd.c:374 nbd_genl_reconfigure+0x7e9/0x1e80 drivers/block/nbd.c:2373 genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209 </TASK> INFO: task generic-netlink:6030 blocked for more than 143 seconds. Call Trace: <TASK> __mutex_lock+0x7c5/0x1590 kernel/locking/mutex.c:820 genl_rcv_msg+0x10b/0x7a0 net/netlink/genetlink.c:1208 </TASK>
To: "Jens Axboe" <[email protected]>
To: "Josef Bacik" <[email protected]>
To: <[email protected]>
To: <[email protected]>
To: "Christoph Hellwig" <[email protected]>
Cc: <[email protected]>
---
v2:
- Replaced the approach of using parallel netlink ops and custom timeouts with skipping queue limits updates for size-only reconfigurations.
- Introduced nbd_size_set() and nbd_size_update() to update device capacity directly without freezing the queue when the block size does not change.
- Retained queue freezing only for actual block-size changes.
- Added decrement of nbd_total_devices in nbd_dev_remove().
v1:
https://lore.kernel.org/all/[email protected]/T/
---
drivers/block/nbd.c +34 -7
@@ -277,6 +277,7 @@ static void nbd_dev_remove(struct nbd_device *nbd)mutex_unlock (&nbd_index_mutex);destroy_workqueue (nbd->recv_workq);put_disk (disk); + nbd_total_devices--; }static void nbd_dev_remove_work (struct work_struct *work)
@@ -331,6 +332,27 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock, nsock->sent =0 ; } +static void nbd_size_update (struct nbd_device *nbd) +{ +struct nbd_config *config = nbd->config; + +if (max_part) +set_bit (GD_NEED_PART_SCAN , &nbd->disk->state); +if (!set_capacity_and_notify (nbd->disk, config->bytesize >>9 )) +kobject_uevent (&nbd_to_dev (nbd)->kobj,KOBJ_CHANGE ); +} + +static int nbd_size_set (struct nbd_device *nbd,loff_t bytesize) +{ +if (bytesize <0 ) +return -EINVAL ; + + nbd->config->bytesize = bytesize; +if (nbd->pid) +nbd_size_update (nbd); +return 0 ; +} +static int nbd_set_size (struct nbd_device *nbd,loff_t bytesize,loff_t blksize) {struct queue_limits lim;
@@ -375,10 +397,7 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize)if (error)return error; -if (max_part) -set_bit (GD_NEED_PART_SCAN , &nbd->disk->state); -if (!set_capacity_and_notify (nbd->disk, bytesize >>9 )) -kobject_uevent (&nbd_to_dev (nbd)->kobj,KOBJ_CHANGE ); +nbd_size_update (nbd);return 0 ; }
@@ -2062,11 +2081,19 @@ static int nbd_genl_size_set(struct genl_info *info, struct nbd_device *nbd)if (info->attrs[NBD_ATTR_SIZE_BYTES ]) bytes =nla_get_u64 (info->attrs[NBD_ATTR_SIZE_BYTES ]); -if (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES ]) +if (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES ]) { bsize =nla_get_u64 (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES ]); +if (!bsize) + bsize =1u <<NBD_DEF_BLKSIZE_BITS ; +if (blk_validate_block_size (bsize)) +return -EINVAL ; + } -if (bytes != config->bytesize || bsize !=nbd_blksize (config)) -return nbd_set_size (nbd, bytes, bsize); +if (bytes != config->bytesize || bsize !=nbd_blksize (config)) { +if (bsize !=nbd_blksize (config)) +return nbd_set_size (nbd, bytes, bsize); +return nbd_size_set (nbd, bytes); + }return 0 ; }
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
Signature · 9 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at [email protected].syzbot ci has tested the following series
syzbot ci has tested the following series
[v2] nbd: skip queue limits update for size-only reconfigure
https://lore.kernel.org/all/[email protected]
* [PATCH RFC v2] nbd: skip queue limits update for size-only reconfigure
and found no issues.
Full report is available here:
https://ci.syzbot.org/series/409945b0-159c-4d52-ae37-bc7c04383918
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
Please generate a v3 patch for syzbot issue f272bbfbf8498ddadea5, INFO: task hung in queue_limits_commit_update_frozen. The reviewed v2 job is e5538deb-f4ac-4b3b-a22a-b47c828fc99e. Start from the original base commit 8cd9520d35a6c38db6567e97dd93b1f11f185dc6.
The main v2 fix is correct and should remain unchanged. The supplied reproducer leaves NBD I/O in flight against an unresponsive server, then sends a size-only NBD_CMD_RECONFIGURE. Calling queue_limits_commit_update_frozen() for that request waits indefinitely for the queue to drain while generic netlink serialization is held. Since the effective block size and all other queue limits are unchanged, updating config->bytesize and disk capacity directly is the right fix.
Keep these parts of v2:
1. Keep the small helper which publishes the existing NBD capacity update, including GD_NEED_PART_SCAN, set_capacity_and_notify(), and the fallback KOBJ_CHANGE event.
2. Keep the generic netlink capacity-only path which validates the byte size, stores config->bytesize, and avoids queue-limit update and queue freezing when the effective block size is unchanged.
3. Keep initial connect behavior. When nbd->pid is zero, store the requested size without notifying a live disk, then let nbd_start_device() perform the full queue-limits update.
4. Keep zero block-size normalization before comparison and keep validation of invalid nonzero block sizes.
5. Keep real generic netlink block-size changes on nbd_set_size().
6. Keep NBD_SET_BLKSIZE, NBD_SET_SIZE, and NBD_SET_SIZE_BLOCKS on their existing full nbd_set_size() path. Legacy NBD_SET_FLAGS followed by a size ioctl must still republish flag-derived queue limits.
Required corrections:
1. Remove nbd_total_devices-- from nbd_dev_remove(). The corrected code diff should otherwise be identical to the v2 code diff.
2. Remove the Added decrement of nbd_total_devices in nbd_dev_remove() bullet from the v2 changelog. Do not change nbd_total_devices, add a device limit, or attempt another accounting fix in this patch.
3. Correct the opening commit reference. Commit 242a49e5c878 is titled nbd: freeze the queue for queue limits updates, not nbd: fix queue freeze vs limits lock order.
The counter change must be removed because nbd_dev_remove() may run from asynchronous destroy-on-disconnect work. V2 decrements the plain counter after releasing nbd_index_mutex, while nbd_dev_add() increments it outside that mutex and nbd_genl_status() uses it to size an skb. Concurrent removal and creation can lose an update, and a later removal can make the counter negative. This can make status enumeration fail or turn the skb estimate into a very large unsigned allocation size. The decrement also cannot fix MAX_LOCKDEP_KEYS: device creation does not consult this counter, and changing the count does not release lockdep classes. The final test result therefore does not justify the line.
Use this subject:
nbd: skip queue limits update for size-only reconfigure
Keep the commit message narrowly scoped. Explain that capacity-only generic netlink reconfiguration no longer freezes the queue, while startup and real block-size changes retain the frozen limits update. Do not claim that all NBD reconfiguration hangs are fixed, since a real block-size change still requires queue serialization.
Keep this exact tag:
Preserve the syzbot report and issue tags for f272bbfbf8498ddadea5.
Quoted 20 lines · syzbot ci
syzbot ci has tested the following series
[v2] nbd: skip queue limits update for size-only reconfigure
https://lore.kernel.org/all/[email protected]
* [PATCH RFC v2] nbd: skip queue limits update for size-only reconfigureand found no issues.
Full report is available here:
https://ci.syzbot.org/series/409945b0-159c-4d52-ae37-bc7c04383918***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
Tested-by [email protected]---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].