From: sashiko-bot@kernel.org
To: "Yang Xiuwei" <yangxiuwei@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 1/2] block: bsg: add a per-device pool of uring_cmd completion buffers
Date: Thu, 19 Nov 2026 03:28:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-222393@kernel.org> (raw)
In-Reply-To: <20261119031751.3471968-2-yangxiuwei@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] block: bsg: IRQ-unsafe pool->lock acquisition in completion
buffer helpers
--
commit 581e3d94856bdf0c9a6edc480ced1d507eb97743
Author: Yang Xiuwei <yangxiuwei@kylinos.cn>
block: bsg: add a per-device pool of uring_cmd completion buffers
This commit adds a per-device pool of fixed-size completion buffers for
bsg devices registered with an io_uring command handler, along with
helpers to check out and return buffers.
> diff --git a/block/bsg.c b/block/bsg.c
> index b296fa3732924..96f46715ade9f 100644
> --- a/block/bsg.c
> +++ b/block/bsg.c
[ ... ]
> @@ -40,6 +43,116 @@ static inline struct bsg_device *to_bsg_device(struct inode *inode)
> #define BSG_DEFAULT_CMDS 64
> #define BSG_MAX_DEVS (1 << MINORBITS)
>
> +/*
> + * Per-device pool of fixed-size completion buffers for uring_cmd drivers that
> + * need data to outlive the block request until task work. Allocated when the
> + * queue is registered with a uring_cmd handler; freed when the bsg device is
> + * released. Callers check a buffer out at issue time and return it from task
> + * work. When the pool is exhausted the caller can reject the command with
> + * -EAGAIN instead of allocating or sleeping in the I/O path.
[ ... ]
> +void *bsg_uring_cmd_get_completion_buf(struct io_uring_cmd *ioucmd, size_t len)
> +{
> + struct bsg_device *bd = to_bsg_device(file_inode(ioucmd->file));
> + struct bsg_completion_pool *pool = bd->completion_pool;
> + unsigned int index;
> + void *buf;
> +
> + if (!pool || WARN_ON_ONCE(len > pool->buf_size))
> + return NULL;
> +
> + spin_lock(&pool->lock);
> + index = find_first_zero_bit(pool->checked_out, BSG_DEFAULT_CMDS);
> + if (index >= BSG_DEFAULT_CMDS) {
> + spin_unlock(&pool->lock);
> + return NULL;
> + }
> + __set_bit(index, pool->checked_out);
> + buf = pool->bufs + (size_t)index * pool->buf_size;
> + spin_unlock(&pool->lock);
> + return buf;
> +}
> +EXPORT_SYMBOL_GPL(bsg_uring_cmd_get_completion_buf);
> +
> +/**
> + * bsg_uring_cmd_put_completion_buf - return a per-device completion buffer
> + * @ioucmd: the uring command being completed
> + * @buf: buffer previously returned by bsg_uring_cmd_get_completion_buf()
> + *
> + * Return the buffer to the pool of the bsg device. Each buffer must be
> + * returned exactly once. The pool warns if a buffer is returned while it
> + * is already free.
> + */
> +void bsg_uring_cmd_put_completion_buf(struct io_uring_cmd *ioucmd, void *buf)
> +{
> + struct bsg_device *bd = to_bsg_device(file_inode(ioucmd->file));
> + struct bsg_completion_pool *pool = bd->completion_pool;
> + unsigned int index;
> +
> + if (WARN_ON_ONCE(!buf))
> + return;
> + index = ((u8 *)buf - pool->bufs) / pool->buf_size;
> + if (WARN_ON_ONCE(index >= BSG_DEFAULT_CMDS))
> + return;
> + spin_lock(&pool->lock);
> + WARN_ON_ONCE(!__test_and_clear_bit(index, pool->checked_out));
> + spin_unlock(&pool->lock);
> +}
[Severity: High]
Can acquiring pool->lock with plain spin_lock() deadlock when a command
completes in interrupt context?
In the next patch in this series, commit "scsi: bsg: release io_uring
requests from end-I/O", scsi_bsg_uring_cmd_done() runs as the req->end_io
callback from hardirq or softirq context and calls
bsg_uring_cmd_put_completion_buf() directly when a command completes
without sense data:
bsg_uring_cmd_get_completion_buf()
spin_lock(&pool->lock)
<hardirq / softirq>
scsi_complete()
...
scsi_bsg_uring_cmd_done()
bsg_uring_cmd_put_completion_buf()
spin_lock(&pool->lock) <-- spins forever
Both helpers should use spin_lock_irqsave() and spin_unlock_irqrestore(),
and the comment above struct bsg_completion_pool should note that buffers
may also be returned from end-I/O context.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119031751.3471968-2-yangxiuwei@kylinos.cn?part=1
next prev parent reply other threads:[~2026-11-19 3:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 15:37 [PATCH v4 0/2] scsi: bsg: release io_uring requests from end-I/O Yingjie Wang
2026-11-18 15:37 ` [PATCH v4 1/2] block: bsg: add a per-file pool of uring_cmd completion buffers Yingjie Wang
2026-11-18 15:37 ` [PATCH v4 2/2] scsi: bsg: release io_uring requests from end-I/O Yingjie Wang
2026-11-19 3:17 ` [PATCH v4 0/2] " Yang Xiuwei
2026-11-19 3:17 ` [PATCH 1/2] block: bsg: add a per-device pool of uring_cmd completion buffers Yang Xiuwei
2026-11-19 3:28 ` sashiko-bot [this message]
2026-11-19 4:02 ` Yang Xiuwei
2026-11-19 3:17 ` [PATCH 2/2] scsi: bsg: release io_uring requests from end-I/O Yang Xiuwei
2026-11-19 3:44 ` sashiko-bot
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=sashiko-outbox-222393@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangxiuwei@kylinos.cn \
/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