All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] nbd: replace socks pointer array with xarray to eliminate queue freeze
@ 2026-03-27  9:12 leo.lilong
  2026-03-27  9:12 ` [PATCH 1/4] nbd: simplify find_fallback() by removing redundant logic leo.lilong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: leo.lilong @ 2026-03-27  9:12 UTC (permalink / raw)
  To: josef, axboe
  Cc: leo.lilong, linux-block, linux-kernel, yi.zhang, yangerkun,
	lonuxli.64

From: Long Li <leo.lilong@huawei.com>

Hi,

Commit b98e762e3d ("nbd: freeze the queue while we're adding
connections") introduced blk_mq_freeze_queue() in the add-socket path
to prevent use-after-free when krealloc() relocates the config->socks
array while I/O is in flight. However, freezing the queue on every
connection setup introduces significant latency when establishing a
large number of connections.

This series eliminates the queue freeze by replacing the
krealloc-based struct nbd_sock **socks array with a struct xarray.
The xarray provides RCU-safe pointer publishing: each nbd_sock is
fully initialized before being stored via xa_store(), and concurrent
readers access individual entries through xa_load() without ever
holding a reference to the array itself. This removes the possibility
of UAF on array reallocation, making the queue freeze unnecessary.

The following test was performed with 256 connections on a local
nbd-server:

  nbd-server -M 256 -C /etc/nbd-server/config
  time nbd-client 127.0.0.1 10809 /dev/nbd0 -N myexport -C 256

  Before:  real 4.510s  user 0.004s  sys 0.038s
  After:   real 0.263s  user 0.009s  sys 0.032s

Connection setup time is reduced by ~94%.

Long Li (4):
  nbd: simplify find_fallback() by removing redundant logic
  nbd: replace socks pointer array with xarray
  nbd: remove redundant num_connections boundary checks
  nbd: remove queue freeze in nbd_add_socket

 drivers/block/nbd.c | 201 +++++++++++++++++++++++---------------------
 1 file changed, 106 insertions(+), 95 deletions(-)

-- 
2.39.2


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

end of thread, other threads:[~2026-04-20  2:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27  9:12 [PATCH 0/4] nbd: replace socks pointer array with xarray to eliminate queue freeze leo.lilong
2026-03-27  9:12 ` [PATCH 1/4] nbd: simplify find_fallback() by removing redundant logic leo.lilong
2026-03-27  9:12 ` [PATCH 2/4] nbd: replace socks pointer array with xarray leo.lilong
2026-03-27  9:12 ` [PATCH 3/4] nbd: remove redundant num_connections boundary checks leo.lilong
2026-03-27  9:12 ` [PATCH 4/4] nbd: remove queue freeze in nbd_add_socket leo.lilong
2026-04-20  2:46 ` [PATCH 0/4] nbd: replace socks pointer array with xarray to eliminate queue freeze Long Li

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.