Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: Jackie Liu <liu.yun@linux.dev>, josef@toxicpanda.com
Cc: cui.tao@linux.dev, axboe@kernel.dk, shuah@kernel.org,
	tom.leiming@gmail.com, yukuai@fygo.io,
	linux-block@vger.kernel.org, nbd@other.debian.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 0/4] nbd: revalidate startup state after queue updates
Date: Tue, 20 Oct 2026 21:03:30 +0800	[thread overview]
Message-ID: <23fa4413-83b0-45b2-b790-1bae653e3e95@linux.dev> (raw)
In-Reply-To: <cover.1792399225.git.liuyun01@kylinos.cn>

Hi Jackie,

在 2026/10/19 16:42, Jackie Liu 写道:
> Commit 8b428f42f3ed ("nbd: fix lockdep deadlock warning") drops
> config_lock around blk_mq_update_nr_hw_queues(). The initial checks for a
> running device and NBD_FLAG_CAN_MULTI_CONN can become stale while the
> lock is dropped.
> 
> Two NBD_DO_IT callers can both pass the PID check. After the first caller
> starts the device, the loser overwrites nbd->pid before failing to create
> the existing sysfs pid attribute. Concurrent NBD_SET_SOCK or NBD_SET_FLAGS
> can also leave multiple connections without NBD_FLAG_CAN_MULTI_CONN,
> which the queue-count retry does not validate.
> 
> Recheck both conditions after reacquiring config_lock. Reject an already
> started device with EBUSY, and reject unsupported multiple connections
> with EINVAL before retrying the queue update or starting receive workers.
> 
> Each fix is followed by its regression test. The tests prime the hardware
> queue count before each attempt and use socket pairs, so no external NBD
> server is needed. They require CAP_SYS_ADMIN, at least two online CPUs
> and unused NBD devices. 

Tested this series on top of next-20261019 (x86_64 KVM guest, 8 vCPUs),
building and running the new selftests in-guest with nbd loaded as a
module (nbds_max=4 max_part=0).

On the unpatched kernel both bugs reproduce at round 1: the losing
NBD_DO_IT caller exits with errno=17 (EEXIST) and /sys/block/nbdX/pid
reports the loser's pid, and nbd_multi_conn flags both the socket-added
and flags-changed variants ("invalid second receiver").

With the series applied, nbd_pid_race and nbd_multi_conn pass 100
rounds per case with seeds 123 and 456 - every round rejected with
EBUSY/EINVAL, no regressions, dmesg clean.

Tested-by: Tao Cui <cuitao@kylinos.cn>

Thanks,
Tao

  parent reply	other threads:[~2026-10-20 13:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  8:42 [PATCH 0/4] nbd: revalidate startup state after queue updates Jackie Liu
2026-10-19  8:42 ` [PATCH 1/4] nbd: reject concurrent device starts Jackie Liu
2026-10-19  8:42 ` [PATCH 2/4] selftests: nbd: test " Jackie Liu
2026-10-19  8:42 ` [PATCH 3/4] nbd: recheck multi-connection support on startup Jackie Liu
2026-10-19  8:42 ` [PATCH 4/4] selftests: nbd: test multi-connection startup races Jackie Liu
2026-10-20 13:03 ` Tao Cui [this message]
2026-10-23  3:12   ` [PATCH 0/4] nbd: revalidate startup state after queue updates Jackie Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23fa4413-83b0-45b2-b790-1bae653e3e95@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liu.yun@linux.dev \
    --cc=nbd@other.debian.org \
    --cc=shuah@kernel.org \
    --cc=tom.leiming@gmail.com \
    --cc=yukuai@fygo.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox