Skip to content

nbd: revalidate startup state after queue updates - #1463

Open
ghost wants to merge 4 commits into
linus-master_basefrom
series/1188698=>linus-master
Open

ghost wants to merge 4 commits into
linus-master_basefrom
series/1188698=>linus-master

Conversation

@ghost

@ghost ghost commented Oct 19, 2026

Copy link
Copy Markdown

Pull request for series with
subject: nbd: revalidate startup state after queue updates
version: 1
url: https://patchwork.kernel.org/series/1188698/

@ghost

ghost commented Oct 19, 2026

Copy link
Copy Markdown
Author

Upstream branch: c03c1a1
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost

ghost commented Oct 22, 2026

Copy link
Copy Markdown
Author

Upstream branch: 7be4bc5
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 75699bf to b8955e3 Compare October 22, 2026 07:35
@ghost
ghost force-pushed the linus-master_base branch from 435b194 to fd67522 Compare October 24, 2026 03:36
@ghost

ghost commented Oct 24, 2026

Copy link
Copy Markdown
Author

Upstream branch: 17bb0e2
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from b8955e3 to 168042c Compare October 24, 2026 03:51
@ghost
ghost force-pushed the linus-master_base branch from fd67522 to 3b53a63 Compare October 26, 2026 01:52
@ghost

ghost commented Oct 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: 21a7f44
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 168042c to 3138fa3 Compare October 26, 2026 02:14
@ghost
ghost force-pushed the linus-master_base branch from 3b53a63 to 5d84576 Compare October 26, 2026 07:01
@ghost

ghost commented Oct 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: 6b4b543
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 3138fa3 to 9fc62b7 Compare October 26, 2026 07:20
@ghost
ghost force-pushed the linus-master_base branch from 5d84576 to 6582ed2 Compare October 26, 2026 18:11
@ghost

ghost commented Oct 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: fb2c3f4
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 9fc62b7 to 7917201 Compare October 26, 2026 18:24
@ghost
ghost force-pushed the linus-master_base branch from 6582ed2 to b3a1abc Compare October 26, 2026 23:55
@ghost

ghost commented Oct 27, 2026

Copy link
Copy Markdown
Author

Upstream branch: d135ab4
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 7917201 to 417e6e3 Compare October 27, 2026 00:09
@ghost
ghost force-pushed the linus-master_base branch from b3a1abc to 712496f Compare October 28, 2026 23:34
@ghost

ghost commented Oct 28, 2026

Copy link
Copy Markdown
Author

Upstream branch: c339f40
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 417e6e3 to 0d1ac43 Compare October 28, 2026 23:54
@ghost
ghost force-pushed the linus-master_base branch from 712496f to a186880 Compare October 30, 2026 13:52
@ghost

ghost commented Oct 30, 2026

Copy link
Copy Markdown
Author

Upstream branch: d89e1d1
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 0d1ac43 to 38e8c32 Compare October 30, 2026 14:17
@ghost
ghost force-pushed the linus-master_base branch from a186880 to 46206a3 Compare November 2, 2026 17:14
@ghost

ghost commented Nov 2, 2026

Copy link
Copy Markdown
Author

Upstream branch: 6628e7d
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 38e8c32 to 4cad4b2 Compare November 2, 2026 17:56
@ghost
ghost force-pushed the linus-master_base branch from 46206a3 to 220bd96 Compare November 3, 2026 23:41
@ghost

ghost commented Nov 4, 2026

Copy link
Copy Markdown
Author

Upstream branch: 05441d6
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 4cad4b2 to b68982b Compare November 4, 2026 00:09
@ghost
ghost force-pushed the linus-master_base branch from 220bd96 to 6c4625e Compare November 6, 2026 08:02
@ghost

ghost commented Nov 6, 2026

Copy link
Copy Markdown
Author

Upstream branch: f66469d
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from b68982b to 2c377e3 Compare November 6, 2026 08:49
@ghost
ghost force-pushed the linus-master_base branch from 6c4625e to c7f678d Compare November 7, 2026 03:08
@ghost

ghost commented Nov 7, 2026

Copy link
Copy Markdown
Author

Upstream branch: d487237
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from 2c377e3 to a56e7d3 Compare November 7, 2026 03:45
@ghost
ghost force-pushed the linus-master_base branch from c7f678d to 6aa6cd1 Compare November 10, 2026 07:53
nbd_start_device() drops config_lock while updating the hardware queue
count. Two NBD_DO_IT callers can pass the initial nbd->pid check before
either caller publishes its PID.

After the first caller starts the device, the second caller overwrites
nbd->pid and fails to create the existing sysfs pid attribute with
-EEXIST. The running device then reports the losing caller's PID.

Recheck nbd->pid after reacquiring config_lock and return -EBUSY if
another caller has already started the device. Do this before retrying
the queue update or changing any startup state.

Fixes: 8b428f4 ("nbd: fix lockdep deadlock warning")
Cc: stable@vger.kernel.org # v6.17+
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
Add an NBD selftest that races two NBD_DO_IT callers and checks that the
loser returns EBUSY while the sysfs pid attribute retains the successful
caller's PID. Prime the device with a different connection count before
each attempt so that the hardware queue update cannot take its no-op
path.

Use socket pairs and an exclusively opened unused device, with bounded
waits and cleanup of the test's own configuration. Skip the test when
CAP_SYS_ADMIN, at least two CPUs, or an unused NBD device is unavailable.
Register the new nbd target with kselftest.

The test uses scheduling stress rather than kernel instrumentation, so a
passing run only means that no regression was observed during that run.
The number of attempts, delays and random seed can be set on the command
line. Load nbd with nbds_max=4 max_part=0 before running the test.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
nbd_start_device() checks NBD_FLAG_CAN_MULTI_CONN before dropping
config_lock to update the hardware queue count. A concurrent
NBD_SET_SOCK can add a connection during that window, and NBD_SET_FLAGS
can clear the flag without changing the connection count.

The queue-count retry only notices changes to num_connections and does
not repeat the flag check. Startup can therefore create multiple receive
workers even though the server no longer advertises multi-connection
support.

Recheck the current connection count and flags after reacquiring
config_lock, before retrying the queue update or starting the device.
Return -EINVAL if multiple connections are no longer supported.

Fixes: 8b428f4 ("nbd: fix lockdep deadlock warning")
Cc: stable@vger.kernel.org # v6.17+
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
Extend the NBD startup selftests to race NBD_DO_IT against adding a
second socket without NBD_FLAG_CAN_MULTI_CONN, and against clearing the
flag on a device that already has two sockets. Prime the queue count
before each attempt to exercise the unlocked hardware queue update.

Check for EINVAL or a valid single-connection start. Detect an invalid
multi-connection start by checking whether a receive worker consumes a
byte from the second socket. Keep the reply incomplete so that the check
does not inject a malformed reply into request completion.

Exclude flag changes observed after PID publication, since changing
flags on an already running device is outside the startup race being
tested. As with the concurrent-start test, this is scheduling stress and
a passing run does not prove that every race window was exercised.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
@ghost

ghost commented Nov 10, 2026

Copy link
Copy Markdown
Author

Upstream branch: b3dfbde
series: https://patchwork.kernel.org/series/1188698/
version: 1

@ghost
ghost force-pushed the series/1188698=>linus-master branch from a56e7d3 to fb12d75 Compare November 10, 2026 08:18
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.

1 participant