2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00

ublk: check for unprivileged daemon on each I/O fetch

Commit ab03a61c66 ("ublk: have a per-io daemon instead of a per-queue
daemon") allowed each ublk I/O to have an independent daemon task.
However, nr_privileged_daemon is only computed based on whether the last
I/O fetched in each ublk queue has an unprivileged daemon task.
Fix this by checking whether every fetched I/O's daemon is privileged.
Change nr_privileged_daemon from a count of queues to a boolean
indicating whether any I/Os have an unprivileged daemon.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Fixes: ab03a61c66 ("ublk: have a per-io daemon instead of a per-queue daemon")
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250808155216.296170-1-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Caleb Sander Mateos 2025-08-08 09:52:15 -06:00 committed by Jens Axboe
parent 212c928d01
commit 5058a62875

View File

@ -235,7 +235,7 @@ struct ublk_device {
struct completion completion; struct completion completion;
unsigned int nr_queues_ready; unsigned int nr_queues_ready;
unsigned int nr_privileged_daemon; bool unprivileged_daemons;
struct mutex cancel_mutex; struct mutex cancel_mutex;
bool canceling; bool canceling;
pid_t ublksrv_tgid; pid_t ublksrv_tgid;
@ -1551,7 +1551,7 @@ static void ublk_reset_ch_dev(struct ublk_device *ub)
/* set to NULL, otherwise new tasks cannot mmap io_cmd_buf */ /* set to NULL, otherwise new tasks cannot mmap io_cmd_buf */
ub->mm = NULL; ub->mm = NULL;
ub->nr_queues_ready = 0; ub->nr_queues_ready = 0;
ub->nr_privileged_daemon = 0; ub->unprivileged_daemons = false;
ub->ublksrv_tgid = -1; ub->ublksrv_tgid = -1;
} }
@ -1978,12 +1978,10 @@ static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq)
__must_hold(&ub->mutex) __must_hold(&ub->mutex)
{ {
ubq->nr_io_ready++; ubq->nr_io_ready++;
if (ublk_queue_ready(ubq)) { if (ublk_queue_ready(ubq))
ub->nr_queues_ready++; ub->nr_queues_ready++;
if (!ub->unprivileged_daemons && !capable(CAP_SYS_ADMIN))
if (capable(CAP_SYS_ADMIN)) ub->unprivileged_daemons = true;
ub->nr_privileged_daemon++;
}
if (ub->nr_queues_ready == ub->dev_info.nr_hw_queues) { if (ub->nr_queues_ready == ub->dev_info.nr_hw_queues) {
/* now we are ready for handling ublk io request */ /* now we are ready for handling ublk io request */
@ -2878,8 +2876,8 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
ublk_apply_params(ub); ublk_apply_params(ub);
/* don't probe partitions if any one ubq daemon is un-trusted */ /* don't probe partitions if any daemon task is un-trusted */
if (ub->nr_privileged_daemon != ub->nr_queues_ready) if (ub->unprivileged_daemons)
set_bit(GD_SUPPRESS_PART_SCAN, &disk->state); set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
ublk_get_device(ub); ublk_get_device(ub);