Skip to content

Commit 00d20db

Browse files
committed
Merge tag 'block-6.19-20260122' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull block fixes from Jens Axboe: - A set of selftest fixes for ublk - Fix for a pid mismatch in ublk, comparing PIDs in different namespaces if run inside a namespace - Fix for a regression added in this release with polling, where the nvme tcp connect code would spin forever - Zoned device error path fix - Tweak the blkzoned uapi additions from this kernel release, making them more easily discoverable - Fix for a regression in bcache with bio endio handling added in this release * tag 'block-6.19-20260122' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: bcache: use bio cloning for detached device requests blk-mq: use BLK_POLL_ONESHOT for synchronous poll completion selftests/ublk: fix garbage output in foreground mode selftests/ublk: fix error handling for starting device selftests/ublk: fix IO thread idle check block: make the new blkzoned UAPI constants discoverable ublk: fix ublksrv pid handling for pid namespaces block: Fix an error path in disk_update_zone_resources()
2 parents 7907f67 + 3ef825d commit 00d20db

8 files changed

Lines changed: 101 additions & 58 deletions

File tree

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ EXPORT_SYMBOL_GPL(blk_rq_is_poll);
14801480
static void blk_rq_poll_completion(struct request *rq, struct completion *wait)
14811481
{
14821482
do {
1483-
blk_hctx_poll(rq->q, rq->mq_hctx, NULL, 0);
1483+
blk_hctx_poll(rq->q, rq->mq_hctx, NULL, BLK_POLL_ONESHOT);
14841484
cond_resched();
14851485
} while (!completion_done(wait));
14861486
}

block/blk-zoned.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,7 @@ static int disk_update_zone_resources(struct gendisk *disk,
19571957

19581958
disk->nr_zones = args->nr_zones;
19591959
if (args->nr_conv_zones >= disk->nr_zones) {
1960+
queue_limits_cancel_update(q);
19601961
pr_warn("%s: Invalid number of conventional zones %u / %u\n",
19611962
disk->disk_name, args->nr_conv_zones, disk->nr_zones);
19621963
ret = -ENODEV;

drivers/block/ublk_drv.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,15 @@ static struct ublk_device *ublk_get_device_from_id(int idx)
28852885
return ub;
28862886
}
28872887

2888+
static bool ublk_validate_user_pid(struct ublk_device *ub, pid_t ublksrv_pid)
2889+
{
2890+
rcu_read_lock();
2891+
ublksrv_pid = pid_nr(find_vpid(ublksrv_pid));
2892+
rcu_read_unlock();
2893+
2894+
return ub->ublksrv_tgid == ublksrv_pid;
2895+
}
2896+
28882897
static int ublk_ctrl_start_dev(struct ublk_device *ub,
28892898
const struct ublksrv_ctrl_cmd *header)
28902899
{
@@ -2953,7 +2962,7 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
29532962
if (wait_for_completion_interruptible(&ub->completion) != 0)
29542963
return -EINTR;
29552964

2956-
if (ub->ublksrv_tgid != ublksrv_pid)
2965+
if (!ublk_validate_user_pid(ub, ublksrv_pid))
29572966
return -EINVAL;
29582967

29592968
mutex_lock(&ub->mutex);
@@ -2972,7 +2981,7 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
29722981
disk->fops = &ub_fops;
29732982
disk->private_data = ub;
29742983

2975-
ub->dev_info.ublksrv_pid = ublksrv_pid;
2984+
ub->dev_info.ublksrv_pid = ub->ublksrv_tgid;
29762985
ub->ub_disk = disk;
29772986

29782987
ublk_apply_params(ub);
@@ -3320,12 +3329,32 @@ static int ublk_ctrl_stop_dev(struct ublk_device *ub)
33203329
static int ublk_ctrl_get_dev_info(struct ublk_device *ub,
33213330
const struct ublksrv_ctrl_cmd *header)
33223331
{
3332+
struct task_struct *p;
3333+
struct pid *pid;
3334+
struct ublksrv_ctrl_dev_info dev_info;
3335+
pid_t init_ublksrv_tgid = ub->dev_info.ublksrv_pid;
33233336
void __user *argp = (void __user *)(unsigned long)header->addr;
33243337

33253338
if (header->len < sizeof(struct ublksrv_ctrl_dev_info) || !header->addr)
33263339
return -EINVAL;
33273340

3328-
if (copy_to_user(argp, &ub->dev_info, sizeof(ub->dev_info)))
3341+
memcpy(&dev_info, &ub->dev_info, sizeof(dev_info));
3342+
dev_info.ublksrv_pid = -1;
3343+
3344+
if (init_ublksrv_tgid > 0) {
3345+
rcu_read_lock();
3346+
pid = find_pid_ns(init_ublksrv_tgid, &init_pid_ns);
3347+
p = pid_task(pid, PIDTYPE_TGID);
3348+
if (p) {
3349+
int vnr = task_tgid_vnr(p);
3350+
3351+
if (vnr)
3352+
dev_info.ublksrv_pid = vnr;
3353+
}
3354+
rcu_read_unlock();
3355+
}
3356+
3357+
if (copy_to_user(argp, &dev_info, sizeof(dev_info)))
33293358
return -EFAULT;
33303359

33313360
return 0;
@@ -3470,7 +3499,7 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,
34703499
pr_devel("%s: All FETCH_REQs received, dev id %d\n", __func__,
34713500
header->dev_id);
34723501

3473-
if (ub->ublksrv_tgid != ublksrv_pid)
3502+
if (!ublk_validate_user_pid(ub, ublksrv_pid))
34743503
return -EINVAL;
34753504

34763505
mutex_lock(&ub->mutex);
@@ -3481,7 +3510,7 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,
34813510
ret = -EBUSY;
34823511
goto out_unlock;
34833512
}
3484-
ub->dev_info.ublksrv_pid = ublksrv_pid;
3513+
ub->dev_info.ublksrv_pid = ub->ublksrv_tgid;
34853514
ub->dev_info.state = UBLK_S_DEV_LIVE;
34863515
pr_devel("%s: new ublksrv_pid %d, dev id %d\n",
34873516
__func__, ublksrv_pid, header->dev_id);

drivers/md/bcache/bcache.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ struct bcache_device {
273273

274274
struct bio_set bio_split;
275275

276+
struct bio_set bio_detached;
277+
276278
unsigned int data_csum:1;
277279

278280
int (*cache_miss)(struct btree *b, struct search *s,
@@ -753,6 +755,13 @@ struct bbio {
753755
struct bio bio;
754756
};
755757

758+
struct detached_dev_io_private {
759+
struct bcache_device *d;
760+
unsigned long start_time;
761+
struct bio *orig_bio;
762+
struct bio bio;
763+
};
764+
756765
#define BTREE_PRIO USHRT_MAX
757766
#define INITIAL_PRIO 32768U
758767

drivers/md/bcache/request.c

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,68 +1077,58 @@ static CLOSURE_CALLBACK(cached_dev_nodata)
10771077
continue_at(cl, cached_dev_bio_complete, NULL);
10781078
}
10791079

1080-
struct detached_dev_io_private {
1081-
struct bcache_device *d;
1082-
unsigned long start_time;
1083-
bio_end_io_t *bi_end_io;
1084-
void *bi_private;
1085-
struct block_device *orig_bdev;
1086-
};
1087-
10881080
static void detached_dev_end_io(struct bio *bio)
10891081
{
1090-
struct detached_dev_io_private *ddip;
1091-
1092-
ddip = bio->bi_private;
1093-
bio->bi_end_io = ddip->bi_end_io;
1094-
bio->bi_private = ddip->bi_private;
1082+
struct detached_dev_io_private *ddip =
1083+
container_of(bio, struct detached_dev_io_private, bio);
1084+
struct bio *orig_bio = ddip->orig_bio;
10951085

10961086
/* Count on the bcache device */
1097-
bio_end_io_acct_remapped(bio, ddip->start_time, ddip->orig_bdev);
1087+
bio_end_io_acct(orig_bio, ddip->start_time);
10981088

10991089
if (bio->bi_status) {
1100-
struct cached_dev *dc = container_of(ddip->d,
1101-
struct cached_dev, disk);
1090+
struct cached_dev *dc = bio->bi_private;
1091+
11021092
/* should count I/O error for backing device here */
11031093
bch_count_backing_io_errors(dc, bio);
1094+
orig_bio->bi_status = bio->bi_status;
11041095
}
11051096

1106-
kfree(ddip);
1107-
bio_endio(bio);
1097+
bio_put(bio);
1098+
bio_endio(orig_bio);
11081099
}
11091100

1110-
static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
1111-
struct block_device *orig_bdev, unsigned long start_time)
1101+
static void detached_dev_do_request(struct bcache_device *d,
1102+
struct bio *orig_bio, unsigned long start_time)
11121103
{
11131104
struct detached_dev_io_private *ddip;
11141105
struct cached_dev *dc = container_of(d, struct cached_dev, disk);
1106+
struct bio *clone_bio;
11151107

1116-
/*
1117-
* no need to call closure_get(&dc->disk.cl),
1118-
* because upper layer had already opened bcache device,
1119-
* which would call closure_get(&dc->disk.cl)
1120-
*/
1121-
ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
1122-
if (!ddip) {
1123-
bio->bi_status = BLK_STS_RESOURCE;
1124-
bio_endio(bio);
1108+
if (bio_op(orig_bio) == REQ_OP_DISCARD &&
1109+
!bdev_max_discard_sectors(dc->bdev)) {
1110+
bio_endio(orig_bio);
11251111
return;
11261112
}
11271113

1128-
ddip->d = d;
1114+
clone_bio = bio_alloc_clone(dc->bdev, orig_bio, GFP_NOIO,
1115+
&d->bio_detached);
1116+
if (!clone_bio) {
1117+
orig_bio->bi_status = BLK_STS_RESOURCE;
1118+
bio_endio(orig_bio);
1119+
return;
1120+
}
1121+
1122+
ddip = container_of(clone_bio, struct detached_dev_io_private, bio);
11291123
/* Count on the bcache device */
1130-
ddip->orig_bdev = orig_bdev;
1124+
ddip->d = d;
11311125
ddip->start_time = start_time;
1132-
ddip->bi_end_io = bio->bi_end_io;
1133-
ddip->bi_private = bio->bi_private;
1134-
bio->bi_end_io = detached_dev_end_io;
1135-
bio->bi_private = ddip;
1136-
1137-
if ((bio_op(bio) == REQ_OP_DISCARD) &&
1138-
!bdev_max_discard_sectors(dc->bdev))
1139-
detached_dev_end_io(bio);
1140-
else
1141-
submit_bio_noacct(bio);
1126+
ddip->orig_bio = orig_bio;
1127+
1128+
clone_bio->bi_end_io = detached_dev_end_io;
1129+
clone_bio->bi_private = dc;
1130+
1131+
submit_bio_noacct(clone_bio);
11421132
}
11431133

11441134
static void quit_max_writeback_rate(struct cache_set *c,
@@ -1214,10 +1204,10 @@ void cached_dev_submit_bio(struct bio *bio)
12141204

12151205
start_time = bio_start_io_acct(bio);
12161206

1217-
bio_set_dev(bio, dc->bdev);
12181207
bio->bi_iter.bi_sector += dc->sb.data_offset;
12191208

12201209
if (cached_dev_get(dc)) {
1210+
bio_set_dev(bio, dc->bdev);
12211211
s = search_alloc(bio, d, orig_bdev, start_time);
12221212
trace_bcache_request_start(s->d, bio);
12231213

@@ -1237,9 +1227,10 @@ void cached_dev_submit_bio(struct bio *bio)
12371227
else
12381228
cached_dev_read(dc, s);
12391229
}
1240-
} else
1230+
} else {
12411231
/* I/O request sent to backing device */
1242-
detached_dev_do_request(d, bio, orig_bdev, start_time);
1232+
detached_dev_do_request(d, bio, start_time);
1233+
}
12431234
}
12441235

12451236
static int cached_dev_ioctl(struct bcache_device *d, blk_mode_t mode,

drivers/md/bcache/super.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ static void bcache_device_free(struct bcache_device *d)
887887
}
888888

889889
bioset_exit(&d->bio_split);
890+
bioset_exit(&d->bio_detached);
890891
kvfree(d->full_dirty_stripes);
891892
kvfree(d->stripe_sectors_dirty);
892893

@@ -949,6 +950,11 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
949950
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
950951
goto out_ida_remove;
951952

953+
if (bioset_init(&d->bio_detached, 4,
954+
offsetof(struct detached_dev_io_private, bio),
955+
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
956+
goto out_bioset_split_exit;
957+
952958
if (lim.logical_block_size > PAGE_SIZE && cached_bdev) {
953959
/*
954960
* This should only happen with BCACHE_SB_VERSION_BDEV.
@@ -964,7 +970,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
964970

965971
d->disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
966972
if (IS_ERR(d->disk))
967-
goto out_bioset_exit;
973+
goto out_bioset_detach_exit;
968974

969975
set_capacity(d->disk, sectors);
970976
snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", idx);
@@ -976,7 +982,9 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
976982
d->disk->private_data = d;
977983
return 0;
978984

979-
out_bioset_exit:
985+
out_bioset_detach_exit:
986+
bioset_exit(&d->bio_detached);
987+
out_bioset_split_exit:
980988
bioset_exit(&d->bio_split);
981989
out_ida_remove:
982990
ida_free(&bcache_device_idx, idx);

include/uapi/linux/blkzoned.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ enum blk_zone_cond {
8181
BLK_ZONE_COND_FULL = 0xE,
8282
BLK_ZONE_COND_OFFLINE = 0xF,
8383

84-
BLK_ZONE_COND_ACTIVE = 0xFF,
84+
BLK_ZONE_COND_ACTIVE = 0xFF, /* added in Linux 6.19 */
85+
#define BLK_ZONE_COND_ACTIVE BLK_ZONE_COND_ACTIVE
8586
};
8687

8788
/**
@@ -100,7 +101,8 @@ enum blk_zone_report_flags {
100101
BLK_ZONE_REP_CAPACITY = (1U << 0),
101102

102103
/* Input flags */
103-
BLK_ZONE_REP_CACHED = (1U << 31),
104+
BLK_ZONE_REP_CACHED = (1U << 31), /* added in Linux 6.19 */
105+
#define BLK_ZONE_REP_CACHED BLK_ZONE_REP_CACHED
104106
};
105107

106108
/**

tools/testing/selftests/ublk/kublk.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ static int ublk_thread_is_idle(struct ublk_thread *t)
753753

754754
static int ublk_thread_is_done(struct ublk_thread *t)
755755
{
756-
return (t->state & UBLKS_T_STOPPING) && ublk_thread_is_idle(t);
756+
return (t->state & UBLKS_T_STOPPING) && ublk_thread_is_idle(t) && !t->cmd_inflight;
757757
}
758758

759759
static inline void ublksrv_handle_tgt_cqe(struct ublk_thread *t,
@@ -1054,15 +1054,17 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev)
10541054
}
10551055
if (ret < 0) {
10561056
ublk_err("%s: ublk_ctrl_start_dev failed: %d\n", __func__, ret);
1057-
goto fail;
1057+
/* stop device so that inflight uring_cmd can be cancelled */
1058+
ublk_ctrl_stop_dev(dev);
1059+
goto fail_start;
10581060
}
10591061

10601062
ublk_ctrl_get_info(dev);
10611063
if (ctx->fg)
10621064
ublk_ctrl_dump(dev);
10631065
else
10641066
ublk_send_dev_event(ctx, dev, dev->dev_info.dev_id);
1065-
1067+
fail_start:
10661068
/* wait until we are terminated */
10671069
for (i = 0; i < dev->nthreads; i++)
10681070
pthread_join(tinfo[i].thread, &thread_ret);
@@ -1272,7 +1274,7 @@ static int __cmd_dev_add(const struct dev_ctx *ctx)
12721274
}
12731275

12741276
ret = ublk_start_daemon(ctx, dev);
1275-
ublk_dbg(UBLK_DBG_DEV, "%s: daemon exit %d\b", ret);
1277+
ublk_dbg(UBLK_DBG_DEV, "%s: daemon exit %d\n", __func__, ret);
12761278
if (ret < 0)
12771279
ublk_ctrl_del_dev(dev);
12781280

@@ -1618,6 +1620,7 @@ int main(int argc, char *argv[])
16181620
int option_idx, opt;
16191621
const char *cmd = argv[1];
16201622
struct dev_ctx ctx = {
1623+
._evtfd = -1,
16211624
.queue_depth = 128,
16221625
.nr_hw_queues = 2,
16231626
.dev_id = -1,

0 commit comments

Comments
 (0)