Skip to content

Commit 4482ebb

Browse files
committed
Merge tag 'block-6.19-20251208' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull block updates from Jens Axboe: "Followup set of fixes and updates for block for the 6.19 merge window. NVMe had some late minute debates which lead to dropping some patches from that tree, which is why the initial PR didn't have NVMe included. It's here now. This pull request contains: - NVMe pull request via Keith: - Subsystem usage cleanups (Max) - Endpoint device fixes (Shin'ichiro) - Debug statements (Gerd) - FC fabrics cleanups and fixes (Daniel) - Consistent alloc API usages (Israel) - Code comment updates (Chu) - Authentication retry fix (Justin) - Fix a memory leak in the discard ioctl code, if the task is being interrupted by a signal at just the wrong time - Zoned write plugging fixes - Add ioctls for for persistent reservations - Enable per-cpu bio caching by default - Various little fixes and tweaks" * tag 'block-6.19-20251208' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: (27 commits) nvme-fabrics: add ENOKEY to no retry criteria for authentication failures nvme-auth: use kvfree() for memory allocated with kvcalloc() nvmet-tcp: use kvcalloc for commands array nvmet-rdma: use kvcalloc for commands and responses arrays nvme: fix typo error in nvme target nvmet-fc: use pr_* print macros instead of dev_* nvmet-fcloop: remove unused lsdir member. nvmet-fcloop: check all request and response have been processed nvme-fc: check all request and response have been processed block: fix memory leak in __blkdev_issue_zero_pages block: fix comment for op_is_zone_mgmt() to include RESET_ALL block: Clear BLK_ZONE_WPLUG_PLUGGED when aborting plugged BIOs blk-mq: Abort suspend when wakeup events are pending blk-mq: add blk_rq_nr_bvec() helper block: add IOC_PR_READ_RESERVATION ioctl block: add IOC_PR_READ_KEYS ioctl nvme: reject invalid pr_read_keys() num_keys values scsi: sd: reject invalid pr_read_keys() num_keys values block: enable per-cpu bio cache by default block: use bio_alloc_bioset for passthru IO by default ...
2 parents 70e3083 + 0f45353 commit 4482ebb

File tree

30 files changed

+278
-153
lines changed

30 files changed

+278
-153
lines changed

block/bio.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -517,20 +517,18 @@ struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
517517
if (WARN_ON_ONCE(!mempool_initialized(&bs->bvec_pool) && nr_vecs > 0))
518518
return NULL;
519519

520-
if (opf & REQ_ALLOC_CACHE) {
521-
if (bs->cache && nr_vecs <= BIO_INLINE_VECS) {
522-
bio = bio_alloc_percpu_cache(bdev, nr_vecs, opf,
523-
gfp_mask, bs);
524-
if (bio)
525-
return bio;
526-
/*
527-
* No cached bio available, bio returned below marked with
528-
* REQ_ALLOC_CACHE to particpate in per-cpu alloc cache.
529-
*/
530-
} else {
531-
opf &= ~REQ_ALLOC_CACHE;
532-
}
533-
}
520+
if (bs->cache && nr_vecs <= BIO_INLINE_VECS) {
521+
opf |= REQ_ALLOC_CACHE;
522+
bio = bio_alloc_percpu_cache(bdev, nr_vecs, opf,
523+
gfp_mask, bs);
524+
if (bio)
525+
return bio;
526+
/*
527+
* No cached bio available, bio returned below marked with
528+
* REQ_ALLOC_CACHE to participate in per-cpu alloc cache.
529+
*/
530+
} else
531+
opf &= ~REQ_ALLOC_CACHE;
534532

535533
/*
536534
* submit_bio_noacct() converts recursion to iteration; this means if

block/blk-lib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev,
202202
unsigned int nr_vecs = __blkdev_sectors_to_bio_pages(nr_sects);
203203
struct bio *bio;
204204

205-
bio = bio_alloc(bdev, nr_vecs, REQ_OP_WRITE, gfp_mask);
206-
bio->bi_iter.bi_sector = sector;
207-
208205
if ((flags & BLKDEV_ZERO_KILLABLE) &&
209206
fatal_signal_pending(current))
210207
break;
211208

209+
bio = bio_alloc(bdev, nr_vecs, REQ_OP_WRITE, gfp_mask);
210+
bio->bi_iter.bi_sector = sector;
211+
212212
do {
213213
unsigned int len;
214214

block/blk-map.c

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ static struct bio_map_data *bio_alloc_map_data(struct iov_iter *data,
3737
return bmd;
3838
}
3939

40+
static inline void blk_mq_map_bio_put(struct bio *bio)
41+
{
42+
bio_put(bio);
43+
}
44+
45+
static struct bio *blk_rq_map_bio_alloc(struct request *rq,
46+
unsigned int nr_vecs, gfp_t gfp_mask)
47+
{
48+
struct block_device *bdev = rq->q->disk ? rq->q->disk->part0 : NULL;
49+
struct bio *bio;
50+
51+
bio = bio_alloc_bioset(bdev, nr_vecs, rq->cmd_flags, gfp_mask,
52+
&fs_bio_set);
53+
if (!bio)
54+
return NULL;
55+
56+
return bio;
57+
}
58+
4059
/**
4160
* bio_copy_from_iter - copy all pages from iov_iter to bio
4261
* @bio: The &struct bio which describes the I/O as destination
@@ -154,10 +173,9 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,
154173
nr_pages = bio_max_segs(DIV_ROUND_UP(offset + len, PAGE_SIZE));
155174

156175
ret = -ENOMEM;
157-
bio = bio_kmalloc(nr_pages, gfp_mask);
176+
bio = blk_rq_map_bio_alloc(rq, nr_pages, gfp_mask);
158177
if (!bio)
159178
goto out_bmd;
160-
bio_init_inline(bio, NULL, nr_pages, req_op(rq));
161179

162180
if (map_data) {
163181
nr_pages = 1U << map_data->page_order;
@@ -233,43 +251,12 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,
233251
cleanup:
234252
if (!map_data)
235253
bio_free_pages(bio);
236-
bio_uninit(bio);
237-
kfree(bio);
254+
blk_mq_map_bio_put(bio);
238255
out_bmd:
239256
kfree(bmd);
240257
return ret;
241258
}
242259

243-
static void blk_mq_map_bio_put(struct bio *bio)
244-
{
245-
if (bio->bi_opf & REQ_ALLOC_CACHE) {
246-
bio_put(bio);
247-
} else {
248-
bio_uninit(bio);
249-
kfree(bio);
250-
}
251-
}
252-
253-
static struct bio *blk_rq_map_bio_alloc(struct request *rq,
254-
unsigned int nr_vecs, gfp_t gfp_mask)
255-
{
256-
struct block_device *bdev = rq->q->disk ? rq->q->disk->part0 : NULL;
257-
struct bio *bio;
258-
259-
if (rq->cmd_flags & REQ_ALLOC_CACHE && (nr_vecs <= BIO_INLINE_VECS)) {
260-
bio = bio_alloc_bioset(bdev, nr_vecs, rq->cmd_flags, gfp_mask,
261-
&fs_bio_set);
262-
if (!bio)
263-
return NULL;
264-
} else {
265-
bio = bio_kmalloc(nr_vecs, gfp_mask);
266-
if (!bio)
267-
return NULL;
268-
bio_init_inline(bio, bdev, nr_vecs, req_op(rq));
269-
}
270-
return bio;
271-
}
272-
273260
static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
274261
gfp_t gfp_mask)
275262
{
@@ -318,25 +305,23 @@ static void bio_invalidate_vmalloc_pages(struct bio *bio)
318305
static void bio_map_kern_endio(struct bio *bio)
319306
{
320307
bio_invalidate_vmalloc_pages(bio);
321-
bio_uninit(bio);
322-
kfree(bio);
308+
blk_mq_map_bio_put(bio);
323309
}
324310

325-
static struct bio *bio_map_kern(void *data, unsigned int len, enum req_op op,
311+
static struct bio *bio_map_kern(struct request *rq, void *data, unsigned int len,
326312
gfp_t gfp_mask)
327313
{
328314
unsigned int nr_vecs = bio_add_max_vecs(data, len);
329315
struct bio *bio;
330316

331-
bio = bio_kmalloc(nr_vecs, gfp_mask);
317+
bio = blk_rq_map_bio_alloc(rq, nr_vecs, gfp_mask);
332318
if (!bio)
333319
return ERR_PTR(-ENOMEM);
334-
bio_init_inline(bio, NULL, nr_vecs, op);
320+
335321
if (is_vmalloc_addr(data)) {
336322
bio->bi_private = data;
337323
if (!bio_add_vmalloc(bio, data, len)) {
338-
bio_uninit(bio);
339-
kfree(bio);
324+
blk_mq_map_bio_put(bio);
340325
return ERR_PTR(-EINVAL);
341326
}
342327
} else {
@@ -349,8 +334,7 @@ static struct bio *bio_map_kern(void *data, unsigned int len, enum req_op op,
349334
static void bio_copy_kern_endio(struct bio *bio)
350335
{
351336
bio_free_pages(bio);
352-
bio_uninit(bio);
353-
kfree(bio);
337+
blk_mq_map_bio_put(bio);
354338
}
355339

356340
static void bio_copy_kern_endio_read(struct bio *bio)
@@ -369,6 +353,7 @@ static void bio_copy_kern_endio_read(struct bio *bio)
369353

370354
/**
371355
* bio_copy_kern - copy kernel address into bio
356+
* @rq: request to fill
372357
* @data: pointer to buffer to copy
373358
* @len: length in bytes
374359
* @op: bio/request operation
@@ -377,9 +362,10 @@ static void bio_copy_kern_endio_read(struct bio *bio)
377362
* copy the kernel address into a bio suitable for io to a block
378363
* device. Returns an error pointer in case of error.
379364
*/
380-
static struct bio *bio_copy_kern(void *data, unsigned int len, enum req_op op,
365+
static struct bio *bio_copy_kern(struct request *rq, void *data, unsigned int len,
381366
gfp_t gfp_mask)
382367
{
368+
enum req_op op = req_op(rq);
383369
unsigned long kaddr = (unsigned long)data;
384370
unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
385371
unsigned long start = kaddr >> PAGE_SHIFT;
@@ -394,10 +380,9 @@ static struct bio *bio_copy_kern(void *data, unsigned int len, enum req_op op,
394380
return ERR_PTR(-EINVAL);
395381

396382
nr_pages = end - start;
397-
bio = bio_kmalloc(nr_pages, gfp_mask);
383+
bio = blk_rq_map_bio_alloc(rq, nr_pages, gfp_mask);
398384
if (!bio)
399385
return ERR_PTR(-ENOMEM);
400-
bio_init_inline(bio, NULL, nr_pages, op);
401386

402387
while (len) {
403388
struct page *page;
@@ -431,8 +416,7 @@ static struct bio *bio_copy_kern(void *data, unsigned int len, enum req_op op,
431416

432417
cleanup:
433418
bio_free_pages(bio);
434-
bio_uninit(bio);
435-
kfree(bio);
419+
blk_mq_map_bio_put(bio);
436420
return ERR_PTR(-ENOMEM);
437421
}
438422

@@ -679,18 +663,16 @@ int blk_rq_map_kern(struct request *rq, void *kbuf, unsigned int len,
679663
return -EINVAL;
680664

681665
if (!blk_rq_aligned(rq->q, addr, len) || object_is_on_stack(kbuf))
682-
bio = bio_copy_kern(kbuf, len, req_op(rq), gfp_mask);
666+
bio = bio_copy_kern(rq, kbuf, len, gfp_mask);
683667
else
684-
bio = bio_map_kern(kbuf, len, req_op(rq), gfp_mask);
668+
bio = bio_map_kern(rq, kbuf, len, gfp_mask);
685669

686670
if (IS_ERR(bio))
687671
return PTR_ERR(bio);
688672

689673
ret = blk_rq_append_bio(rq, bio);
690-
if (unlikely(ret)) {
691-
bio_uninit(bio);
692-
kfree(bio);
693-
}
674+
if (unlikely(ret))
675+
blk_mq_map_bio_put(bio);
694676
return ret;
695677
}
696678
EXPORT_SYMBOL(blk_rq_map_kern);

block/blk-mq.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/cache.h>
2424
#include <linux/sched/topology.h>
2525
#include <linux/sched/signal.h>
26+
#include <linux/suspend.h>
2627
#include <linux/delay.h>
2728
#include <linux/crash_dump.h>
2829
#include <linux/prefetch.h>
@@ -3718,6 +3719,7 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
37183719
{
37193720
struct blk_mq_hw_ctx *hctx = hlist_entry_safe(node,
37203721
struct blk_mq_hw_ctx, cpuhp_online);
3722+
int ret = 0;
37213723

37223724
if (blk_mq_hctx_has_online_cpu(hctx, cpu))
37233725
return 0;
@@ -3738,12 +3740,24 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
37383740
* frozen and there are no requests.
37393741
*/
37403742
if (percpu_ref_tryget(&hctx->queue->q_usage_counter)) {
3741-
while (blk_mq_hctx_has_requests(hctx))
3743+
while (blk_mq_hctx_has_requests(hctx)) {
3744+
/*
3745+
* The wakeup capable IRQ handler of block device is
3746+
* not called during suspend. Skip the loop by checking
3747+
* pm_wakeup_pending to prevent the deadlock and improve
3748+
* suspend latency.
3749+
*/
3750+
if (pm_wakeup_pending()) {
3751+
clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
3752+
ret = -EBUSY;
3753+
break;
3754+
}
37423755
msleep(5);
3756+
}
37433757
percpu_ref_put(&hctx->queue->q_usage_counter);
37443758
}
37453759

3746-
return 0;
3760+
return ret;
37473761
}
37483762

37493763
/*

block/blk-zoned.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,17 @@ static void disk_zone_wplug_abort(struct blk_zone_wplug *zwplug)
741741
{
742742
struct bio *bio;
743743

744+
lockdep_assert_held(&zwplug->lock);
745+
744746
if (bio_list_empty(&zwplug->bio_list))
745747
return;
746748

747749
pr_warn_ratelimited("%s: zone %u: Aborting plugged BIOs\n",
748750
zwplug->disk->disk_name, zwplug->zone_no);
749751
while ((bio = bio_list_pop(&zwplug->bio_list)))
750752
blk_zone_wplug_bio_io_error(zwplug, bio);
753+
754+
zwplug->flags &= ~BLK_ZONE_WPLUG_PLUGGED;
751755
}
752756

753757
/*

block/fops.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
184184
loff_t pos = iocb->ki_pos;
185185
int ret = 0;
186186

187-
if (iocb->ki_flags & IOCB_ALLOC_CACHE)
188-
opf |= REQ_ALLOC_CACHE;
189187
bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL,
190188
&blkdev_dio_pool);
191189
dio = container_of(bio, struct blkdev_dio, bio);
@@ -333,8 +331,6 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
333331
loff_t pos = iocb->ki_pos;
334332
int ret = 0;
335333

336-
if (iocb->ki_flags & IOCB_ALLOC_CACHE)
337-
opf |= REQ_ALLOC_CACHE;
338334
bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL,
339335
&blkdev_dio_pool);
340336
dio = container_of(bio, struct blkdev_dio, bio);

0 commit comments

Comments
 (0)