Skip to content

Commit 9d0281b

Browse files
committed
Merge tag 'block-6.3-2023-03-03' of git://git.kernel.dk/linux
Pull block fixes from Jens Axboe: - NVMe pull request via Christoph: - Don't access released socket during error recovery (Akinobu Mita) - Bring back auto-removal of deleted namespaces during sequential scan (Christoph Hellwig) - Fix an error code in nvme_auth_process_dhchap_challenge (Dan Carpenter) - Show well known discovery name (Daniel Wagner) - Add a missing endianess conversion in effects masking (Keith Busch) - Fix for a regression introduced in blk-rq-qos during init in this merge window (Breno) - Reorder a few fields in struct blk_mq_tag_set, eliminating a few holes and shrinking it (Christophe) - Remove redundant bdev_get_queue() NULL checks (Juhyung) - Add sed-opal single user mode support flag (Luca) - Remove SQE128 check in ublk as it isn't needed, saving some memory (Ming) - Op specific segment checking for cloned requests (Uday) - Exclusive open partition scan fixes (Yu) - Loop offset/size checking before assigning them in the device (Zhong) - Bio polling fixes (me) * tag 'block-6.3-2023-03-03' of git://git.kernel.dk/linux: blk-mq: enforce op-specific segment limits in blk_insert_cloned_request nvme-fabrics: show well known discovery name nvme-tcp: don't access released socket during error recovery nvme-auth: fix an error code in nvme_auth_process_dhchap_challenge() nvme: bring back auto-removal of deleted namespaces during sequential scan blk-iocost: Pass gendisk to ioc_refresh_params nvme: fix sparse warning on effects masking block: be a bit more careful in checking for NULL bdev while polling block: clear bio->bi_bdev when putting a bio back in the cache loop: loop_set_status_from_info() check before assignment ublk: remove check IO_URING_F_SQE128 in ublk_ch_uring_cmd block: remove more NULL checks after bdev_get_queue() blk-mq: Reorder fields in 'struct blk_mq_tag_set' block: fix scan partition for exclusively open device again block: Revert "block: Do not reread partition table on exclusively open device" sed-opal: add support flag for SUM in status ioctl
2 parents 1bd1aee + 49d2439 commit 9d0281b

File tree

20 files changed

+114
-85
lines changed

20 files changed

+114
-85
lines changed

block/bio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ static inline void bio_put_percpu_cache(struct bio *bio)
772772

773773
if ((bio->bi_opf & REQ_POLLED) && !WARN_ON_ONCE(in_interrupt())) {
774774
bio->bi_next = cache->free_list;
775+
bio->bi_bdev = NULL;
775776
cache->free_list = bio;
776777
cache->nr++;
777778
} else {

block/blk-core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,16 @@ EXPORT_SYMBOL(submit_bio);
858858
*/
859859
int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
860860
{
861-
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
862861
blk_qc_t cookie = READ_ONCE(bio->bi_cookie);
862+
struct block_device *bdev;
863+
struct request_queue *q;
863864
int ret = 0;
864865

866+
bdev = READ_ONCE(bio->bi_bdev);
867+
if (!bdev)
868+
return 0;
869+
870+
q = bdev_get_queue(bdev);
865871
if (cookie == BLK_QC_T_NONE ||
866872
!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
867873
return 0;
@@ -930,7 +936,7 @@ int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob,
930936
*/
931937
rcu_read_lock();
932938
bio = READ_ONCE(kiocb->private);
933-
if (bio && bio->bi_bdev)
939+
if (bio)
934940
ret = bio_poll(bio, iob, flags);
935941
rcu_read_unlock();
936942

block/blk-iocost.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -800,19 +800,23 @@ static void ioc_refresh_period_us(struct ioc *ioc)
800800
ioc_refresh_margins(ioc);
801801
}
802802

803-
static int ioc_autop_idx(struct ioc *ioc)
803+
/*
804+
* ioc->rqos.disk isn't initialized when this function is called from
805+
* the init path.
806+
*/
807+
static int ioc_autop_idx(struct ioc *ioc, struct gendisk *disk)
804808
{
805809
int idx = ioc->autop_idx;
806810
const struct ioc_params *p = &autop[idx];
807811
u32 vrate_pct;
808812
u64 now_ns;
809813

810814
/* rotational? */
811-
if (!blk_queue_nonrot(ioc->rqos.disk->queue))
815+
if (!blk_queue_nonrot(disk->queue))
812816
return AUTOP_HDD;
813817

814818
/* handle SATA SSDs w/ broken NCQ */
815-
if (blk_queue_depth(ioc->rqos.disk->queue) == 1)
819+
if (blk_queue_depth(disk->queue) == 1)
816820
return AUTOP_SSD_QD1;
817821

818822
/* use one of the normal ssd sets */
@@ -901,14 +905,19 @@ static void ioc_refresh_lcoefs(struct ioc *ioc)
901905
&c[LCOEF_WPAGE], &c[LCOEF_WSEQIO], &c[LCOEF_WRANDIO]);
902906
}
903907

904-
static bool ioc_refresh_params(struct ioc *ioc, bool force)
908+
/*
909+
* struct gendisk is required as an argument because ioc->rqos.disk
910+
* is not properly initialized when called from the init path.
911+
*/
912+
static bool ioc_refresh_params_disk(struct ioc *ioc, bool force,
913+
struct gendisk *disk)
905914
{
906915
const struct ioc_params *p;
907916
int idx;
908917

909918
lockdep_assert_held(&ioc->lock);
910919

911-
idx = ioc_autop_idx(ioc);
920+
idx = ioc_autop_idx(ioc, disk);
912921
p = &autop[idx];
913922

914923
if (idx == ioc->autop_idx && !force)
@@ -939,6 +948,11 @@ static bool ioc_refresh_params(struct ioc *ioc, bool force)
939948
return true;
940949
}
941950

951+
static bool ioc_refresh_params(struct ioc *ioc, bool force)
952+
{
953+
return ioc_refresh_params_disk(ioc, force, ioc->rqos.disk);
954+
}
955+
942956
/*
943957
* When an iocg accumulates too much vtime or gets deactivated, we throw away
944958
* some vtime, which lowers the overall device utilization. As the exact amount
@@ -2880,7 +2894,7 @@ static int blk_iocost_init(struct gendisk *disk)
28802894

28812895
spin_lock_irq(&ioc->lock);
28822896
ioc->autop_idx = AUTOP_INVALID;
2883-
ioc_refresh_params(ioc, true);
2897+
ioc_refresh_params_disk(ioc, true, disk);
28842898
spin_unlock_irq(&ioc->lock);
28852899

28862900
/*

block/blk-merge.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,13 +587,6 @@ int __blk_rq_map_sg(struct request_queue *q, struct request *rq,
587587
}
588588
EXPORT_SYMBOL(__blk_rq_map_sg);
589589

590-
static inline unsigned int blk_rq_get_max_segments(struct request *rq)
591-
{
592-
if (req_op(rq) == REQ_OP_DISCARD)
593-
return queue_max_discard_segments(rq->q);
594-
return queue_max_segments(rq->q);
595-
}
596-
597590
static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
598591
sector_t offset)
599592
{

block/blk-mq.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,7 @@ blk_status_t blk_insert_cloned_request(struct request *rq)
30003000
{
30013001
struct request_queue *q = rq->q;
30023002
unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
3003+
unsigned int max_segments = blk_rq_get_max_segments(rq);
30033004
blk_status_t ret;
30043005

30053006
if (blk_rq_sectors(rq) > max_sectors) {
@@ -3026,9 +3027,9 @@ blk_status_t blk_insert_cloned_request(struct request *rq)
30263027
* original queue.
30273028
*/
30283029
rq->nr_phys_segments = blk_recalc_rq_segments(rq);
3029-
if (rq->nr_phys_segments > queue_max_segments(q)) {
3030-
printk(KERN_ERR "%s: over max segments limit. (%hu > %hu)\n",
3031-
__func__, rq->nr_phys_segments, queue_max_segments(q));
3030+
if (rq->nr_phys_segments > max_segments) {
3031+
printk(KERN_ERR "%s: over max segments limit. (%u > %u)\n",
3032+
__func__, rq->nr_phys_segments, max_segments);
30323033
return BLK_STS_IOERR;
30333034
}
30343035

block/blk-zoned.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,12 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
334334
{
335335
void __user *argp = (void __user *)arg;
336336
struct zone_report_args args;
337-
struct request_queue *q;
338337
struct blk_zone_report rep;
339338
int ret;
340339

341340
if (!argp)
342341
return -EINVAL;
343342

344-
q = bdev_get_queue(bdev);
345-
if (!q)
346-
return -ENXIO;
347-
348343
if (!bdev_is_zoned(bdev))
349344
return -ENOTTY;
350345

@@ -391,18 +386,13 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
391386
unsigned int cmd, unsigned long arg)
392387
{
393388
void __user *argp = (void __user *)arg;
394-
struct request_queue *q;
395389
struct blk_zone_range zrange;
396390
enum req_op op;
397391
int ret;
398392

399393
if (!argp)
400394
return -EINVAL;
401395

402-
q = bdev_get_queue(bdev);
403-
if (!q)
404-
return -ENXIO;
405-
406396
if (!bdev_is_zoned(bdev))
407397
return -ENOTTY;
408398

block/blk.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ static inline bool blk_discard_mergable(struct request *req)
156156
return false;
157157
}
158158

159+
static inline unsigned int blk_rq_get_max_segments(struct request *rq)
160+
{
161+
if (req_op(rq) == REQ_OP_DISCARD)
162+
return queue_max_discard_segments(rq->q);
163+
return queue_max_segments(rq->q);
164+
}
165+
159166
static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
160167
enum req_op op)
161168
{
@@ -427,7 +434,7 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio,
427434

428435
struct request_queue *blk_alloc_queue(int node_id);
429436

430-
int disk_scan_partitions(struct gendisk *disk, fmode_t mode, void *owner);
437+
int disk_scan_partitions(struct gendisk *disk, fmode_t mode);
431438

432439
int disk_alloc_events(struct gendisk *disk);
433440
void disk_add_events(struct gendisk *disk);

block/genhd.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,26 +356,40 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action)
356356
}
357357
EXPORT_SYMBOL_GPL(disk_uevent);
358358

359-
int disk_scan_partitions(struct gendisk *disk, fmode_t mode, void *owner)
359+
int disk_scan_partitions(struct gendisk *disk, fmode_t mode)
360360
{
361361
struct block_device *bdev;
362+
int ret = 0;
362363

363364
if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
364365
return -EINVAL;
365366
if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
366367
return -EINVAL;
367368
if (disk->open_partitions)
368369
return -EBUSY;
369-
/* Someone else has bdev exclusively open? */
370-
if (disk->part0->bd_holder && disk->part0->bd_holder != owner)
371-
return -EBUSY;
372370

373371
set_bit(GD_NEED_PART_SCAN, &disk->state);
374-
bdev = blkdev_get_by_dev(disk_devt(disk), mode, NULL);
372+
/*
373+
* If the device is opened exclusively by current thread already, it's
374+
* safe to scan partitons, otherwise, use bd_prepare_to_claim() to
375+
* synchronize with other exclusive openers and other partition
376+
* scanners.
377+
*/
378+
if (!(mode & FMODE_EXCL)) {
379+
ret = bd_prepare_to_claim(disk->part0, disk_scan_partitions);
380+
if (ret)
381+
return ret;
382+
}
383+
384+
bdev = blkdev_get_by_dev(disk_devt(disk), mode & ~FMODE_EXCL, NULL);
375385
if (IS_ERR(bdev))
376-
return PTR_ERR(bdev);
377-
blkdev_put(bdev, mode);
378-
return 0;
386+
ret = PTR_ERR(bdev);
387+
else
388+
blkdev_put(bdev, mode);
389+
390+
if (!(mode & FMODE_EXCL))
391+
bd_abort_claiming(disk->part0, disk_scan_partitions);
392+
return ret;
379393
}
380394

381395
/**
@@ -497,9 +511,14 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
497511
if (ret)
498512
goto out_unregister_bdi;
499513

514+
/* Make sure the first partition scan will be proceed */
515+
if (get_capacity(disk) && !(disk->flags & GENHD_FL_NO_PART) &&
516+
!test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
517+
set_bit(GD_NEED_PART_SCAN, &disk->state);
518+
500519
bdev_add(disk->part0, ddev->devt);
501520
if (get_capacity(disk))
502-
disk_scan_partitions(disk, FMODE_READ, NULL);
521+
disk_scan_partitions(disk, FMODE_READ);
503522

504523
/*
505524
* Announce the disk and partitions after all partitions are

block/ioctl.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,10 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode,
467467
* user space. Note the separate arg/argp parameters that are needed
468468
* to deal with the compat_ptr() conversion.
469469
*/
470-
static int blkdev_common_ioctl(struct file *file, fmode_t mode, unsigned cmd,
471-
unsigned long arg, void __user *argp)
470+
static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
471+
unsigned int cmd, unsigned long arg,
472+
void __user *argp)
472473
{
473-
struct block_device *bdev = I_BDEV(file->f_mapping->host);
474474
unsigned int max_sectors;
475475

476476
switch (cmd) {
@@ -528,8 +528,7 @@ static int blkdev_common_ioctl(struct file *file, fmode_t mode, unsigned cmd,
528528
return -EACCES;
529529
if (bdev_is_partition(bdev))
530530
return -EINVAL;
531-
return disk_scan_partitions(bdev->bd_disk, mode & ~FMODE_EXCL,
532-
file);
531+
return disk_scan_partitions(bdev->bd_disk, mode);
533532
case BLKTRACESTART:
534533
case BLKTRACESTOP:
535534
case BLKTRACETEARDOWN:
@@ -607,7 +606,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
607606
break;
608607
}
609608

610-
ret = blkdev_common_ioctl(file, mode, cmd, arg, argp);
609+
ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp);
611610
if (ret != -ENOIOCTLCMD)
612611
return ret;
613612

@@ -676,7 +675,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
676675
break;
677676
}
678677

679-
ret = blkdev_common_ioctl(file, mode, cmd, arg, argp);
678+
ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp);
680679
if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
681680
ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg);
682681

block/sed-opal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ static int opal_discovery0_end(struct opal_dev *dev)
487487
break;
488488
case FC_SINGLEUSER:
489489
single_user = check_sum(body->features);
490+
if (single_user)
491+
dev->flags |= OPAL_FL_SUM_SUPPORTED;
490492
break;
491493
case FC_GEOMETRY:
492494
check_geometry(dev, body);

drivers/block/loop.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,13 @@ loop_set_status_from_info(struct loop_device *lo,
977977
return -EINVAL;
978978
}
979979

980+
/* Avoid assigning overflow values */
981+
if (info->lo_offset > LLONG_MAX || info->lo_sizelimit > LLONG_MAX)
982+
return -EOVERFLOW;
983+
980984
lo->lo_offset = info->lo_offset;
981985
lo->lo_sizelimit = info->lo_sizelimit;
982986

983-
/* loff_t vars have been assigned __u64 */
984-
if (lo->lo_offset < 0 || lo->lo_sizelimit < 0)
985-
return -EOVERFLOW;
986-
987987
memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
988988
lo->lo_file_name[LO_NAME_SIZE-1] = 0;
989989
lo->lo_flags = info->lo_flags;

drivers/block/ublk_drv.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,6 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
12711271
__func__, cmd->cmd_op, ub_cmd->q_id, tag,
12721272
ub_cmd->result);
12731273

1274-
if (!(issue_flags & IO_URING_F_SQE128))
1275-
goto out;
1276-
12771274
if (ub_cmd->q_id >= ub->dev_info.nr_hw_queues)
12781275
goto out;
12791276

drivers/nvme/host/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
256256
chap->qid, ret, gid_name);
257257
chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
258258
chap->dh_tfm = NULL;
259-
return -ret;
259+
return ret;
260260
}
261261
dev_dbg(ctrl->device, "qid %d: selected DH group %s\n",
262262
chap->qid, gid_name);

0 commit comments

Comments
 (0)