Skip to content

Commit 8075fc3

Browse files
committed
Merge tag 'block-5.9-2020-09-04' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "A bit larger than usual this week, mostly due to the NVMe fixes arriving late for -rc3 and hence didn't make last weeks pull request. - NVMe: - instance leak and io boundary fixes from Keith - fc locking fix from Christophe - various tcp/rdma reset during traffic fixes from Sagi - pci use-after-free fix from Tong - tcp target null deref fix from Ziye - Locking fix for partition removal (Christoph) - Ensure bdi->io_pages is always set (me) - Fixup for hd struct reference (Ming) - Fix for zero length bvecs (Ming) - Two small blk-iocost fixes (Tejun)" * tag 'block-5.9-2020-09-04' of git://git.kernel.dk/linux-block: block: allow for_each_bvec to support zero len bvec blk-stat: make q->stats->lock irqsafe blk-iocost: ioc_pd_free() shouldn't assume irq disabled block: fix locking in bdev_del_partition block: release disk reference in hd_struct_free_work block: ensure bdi->io_pages is always initialized nvme-pci: cancel nvme device request before disabling nvme: only use power of two io boundaries nvme: fix controller instance leak nvmet-fc: Fix a missed _irqsave version of spin_lock in 'nvmet_fc_fod_op_done()' nvme: Fix NULL dereference for pci nvme controllers nvme-rdma: fix reset hang if controller died in the middle of a reset nvme-rdma: fix timeout handler nvme-rdma: serialize controller teardown sequences nvme-tcp: fix reset hang if controller died in the middle of a reset nvme-tcp: fix timeout handler nvme-tcp: serialize controller teardown sequences nvme: have nvme_wait_freeze_timeout return if it timed out nvme-fabrics: don't check state NVME_CTRL_NEW for request acceptance nvmet-tcp: Fix NULL dereference when a connect data comes in h2cdata pdu
2 parents d849ca4 + 7e24969 commit 8075fc3

13 files changed

Lines changed: 212 additions & 82 deletions

File tree

‎block/blk-core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ struct request_queue *blk_alloc_queue(int node_id)
539539
goto fail_stats;
540540

541541
q->backing_dev_info->ra_pages = VM_READAHEAD_PAGES;
542+
q->backing_dev_info->io_pages = VM_READAHEAD_PAGES;
542543
q->backing_dev_info->capabilities = BDI_CAP_CGROUP_WRITEBACK;
543544
q->node = node_id;
544545

‎block/blk-iocost.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,14 +2092,15 @@ static void ioc_pd_free(struct blkg_policy_data *pd)
20922092
{
20932093
struct ioc_gq *iocg = pd_to_iocg(pd);
20942094
struct ioc *ioc = iocg->ioc;
2095+
unsigned long flags;
20952096

20962097
if (ioc) {
2097-
spin_lock(&ioc->lock);
2098+
spin_lock_irqsave(&ioc->lock, flags);
20982099
if (!list_empty(&iocg->active_list)) {
20992100
propagate_active_weight(iocg, 0, 0);
21002101
list_del_init(&iocg->active_list);
21012102
}
2102-
spin_unlock(&ioc->lock);
2103+
spin_unlock_irqrestore(&ioc->lock, flags);
21032104

21042105
hrtimer_cancel(&iocg->waitq_timer);
21052106
hrtimer_cancel(&iocg->delay_timer);

‎block/blk-stat.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void blk_stat_add_callback(struct request_queue *q,
137137
struct blk_stat_callback *cb)
138138
{
139139
unsigned int bucket;
140+
unsigned long flags;
140141
int cpu;
141142

142143
for_each_possible_cpu(cpu) {
@@ -147,20 +148,22 @@ void blk_stat_add_callback(struct request_queue *q,
147148
blk_rq_stat_init(&cpu_stat[bucket]);
148149
}
149150

150-
spin_lock(&q->stats->lock);
151+
spin_lock_irqsave(&q->stats->lock, flags);
151152
list_add_tail_rcu(&cb->list, &q->stats->callbacks);
152153
blk_queue_flag_set(QUEUE_FLAG_STATS, q);
153-
spin_unlock(&q->stats->lock);
154+
spin_unlock_irqrestore(&q->stats->lock, flags);
154155
}
155156

156157
void blk_stat_remove_callback(struct request_queue *q,
157158
struct blk_stat_callback *cb)
158159
{
159-
spin_lock(&q->stats->lock);
160+
unsigned long flags;
161+
162+
spin_lock_irqsave(&q->stats->lock, flags);
160163
list_del_rcu(&cb->list);
161164
if (list_empty(&q->stats->callbacks) && !q->stats->enable_accounting)
162165
blk_queue_flag_clear(QUEUE_FLAG_STATS, q);
163-
spin_unlock(&q->stats->lock);
166+
spin_unlock_irqrestore(&q->stats->lock, flags);
164167

165168
del_timer_sync(&cb->timer);
166169
}
@@ -183,10 +186,12 @@ void blk_stat_free_callback(struct blk_stat_callback *cb)
183186

184187
void blk_stat_enable_accounting(struct request_queue *q)
185188
{
186-
spin_lock(&q->stats->lock);
189+
unsigned long flags;
190+
191+
spin_lock_irqsave(&q->stats->lock, flags);
187192
q->stats->enable_accounting = true;
188193
blk_queue_flag_set(QUEUE_FLAG_STATS, q);
189-
spin_unlock(&q->stats->lock);
194+
spin_unlock_irqrestore(&q->stats->lock, flags);
190195
}
191196
EXPORT_SYMBOL_GPL(blk_stat_enable_accounting);
192197

‎block/partitions/core.c‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,15 @@ static void hd_struct_free_work(struct work_struct *work)
278278
{
279279
struct hd_struct *part =
280280
container_of(to_rcu_work(work), struct hd_struct, rcu_work);
281+
struct gendisk *disk = part_to_disk(part);
282+
283+
/*
284+
* Release the disk reference acquired in delete_partition here.
285+
* We can't release it in hd_struct_free because the final put_device
286+
* needs process context and thus can't be run directly from a
287+
* percpu_ref ->release handler.
288+
*/
289+
put_device(disk_to_dev(disk));
281290

282291
part->start_sect = 0;
283292
part->nr_sects = 0;
@@ -293,7 +302,6 @@ static void hd_struct_free(struct percpu_ref *ref)
293302
rcu_dereference_protected(disk->part_tbl, 1);
294303

295304
rcu_assign_pointer(ptbl->last_lookup, NULL);
296-
put_device(disk_to_dev(disk));
297305

298306
INIT_RCU_WORK(&part->rcu_work, hd_struct_free_work);
299307
queue_rcu_work(system_wq, &part->rcu_work);
@@ -524,19 +532,20 @@ int bdev_add_partition(struct block_device *bdev, int partno,
524532
int bdev_del_partition(struct block_device *bdev, int partno)
525533
{
526534
struct block_device *bdevp;
527-
struct hd_struct *part;
528-
int ret = 0;
535+
struct hd_struct *part = NULL;
536+
int ret;
529537

530-
part = disk_get_part(bdev->bd_disk, partno);
531-
if (!part)
532-
return -ENXIO;
533-
534-
ret = -ENOMEM;
535-
bdevp = bdget(part_devt(part));
538+
bdevp = bdget_disk(bdev->bd_disk, partno);
536539
if (!bdevp)
537-
goto out_put_part;
540+
return -ENOMEM;
538541

539542
mutex_lock(&bdevp->bd_mutex);
543+
mutex_lock_nested(&bdev->bd_mutex, 1);
544+
545+
ret = -ENXIO;
546+
part = disk_get_part(bdev->bd_disk, partno);
547+
if (!part)
548+
goto out_unlock;
540549

541550
ret = -EBUSY;
542551
if (bdevp->bd_openers)
@@ -545,16 +554,14 @@ int bdev_del_partition(struct block_device *bdev, int partno)
545554
sync_blockdev(bdevp);
546555
invalidate_bdev(bdevp);
547556

548-
mutex_lock_nested(&bdev->bd_mutex, 1);
549557
delete_partition(bdev->bd_disk, part);
550-
mutex_unlock(&bdev->bd_mutex);
551-
552558
ret = 0;
553559
out_unlock:
560+
mutex_unlock(&bdev->bd_mutex);
554561
mutex_unlock(&bdevp->bd_mutex);
555562
bdput(bdevp);
556-
out_put_part:
557-
disk_put_part(part);
563+
if (part)
564+
disk_put_part(part);
558565
return ret;
559566
}
560567

‎drivers/nvme/host/core.c‎

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,13 +2026,49 @@ static void nvme_update_disk_info(struct gendisk *disk,
20262026
blk_mq_unfreeze_queue(disk->queue);
20272027
}
20282028

2029+
static inline bool nvme_first_scan(struct gendisk *disk)
2030+
{
2031+
/* nvme_alloc_ns() scans the disk prior to adding it */
2032+
return !(disk->flags & GENHD_FL_UP);
2033+
}
2034+
2035+
static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)
2036+
{
2037+
struct nvme_ctrl *ctrl = ns->ctrl;
2038+
u32 iob;
2039+
2040+
if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) &&
2041+
is_power_of_2(ctrl->max_hw_sectors))
2042+
iob = ctrl->max_hw_sectors;
2043+
else
2044+
iob = nvme_lba_to_sect(ns, le16_to_cpu(id->noiob));
2045+
2046+
if (!iob)
2047+
return;
2048+
2049+
if (!is_power_of_2(iob)) {
2050+
if (nvme_first_scan(ns->disk))
2051+
pr_warn("%s: ignoring unaligned IO boundary:%u\n",
2052+
ns->disk->disk_name, iob);
2053+
return;
2054+
}
2055+
2056+
if (blk_queue_is_zoned(ns->disk->queue)) {
2057+
if (nvme_first_scan(ns->disk))
2058+
pr_warn("%s: ignoring zoned namespace IO boundary\n",
2059+
ns->disk->disk_name);
2060+
return;
2061+
}
2062+
2063+
blk_queue_chunk_sectors(ns->queue, iob);
2064+
}
2065+
20292066
static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
20302067
{
20312068
unsigned lbaf = id->flbas & NVME_NS_FLBAS_LBA_MASK;
20322069
struct nvme_ns *ns = disk->private_data;
20332070
struct nvme_ctrl *ctrl = ns->ctrl;
20342071
int ret;
2035-
u32 iob;
20362072

20372073
/*
20382074
* If identify namespace failed, use default 512 byte block size so
@@ -2060,12 +2096,6 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
20602096
return -ENODEV;
20612097
}
20622098

2063-
if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) &&
2064-
is_power_of_2(ctrl->max_hw_sectors))
2065-
iob = ctrl->max_hw_sectors;
2066-
else
2067-
iob = nvme_lba_to_sect(ns, le16_to_cpu(id->noiob));
2068-
20692099
ns->features = 0;
20702100
ns->ms = le16_to_cpu(id->lbaf[lbaf].ms);
20712101
/* the PI implementation requires metadata equal t10 pi tuple size */
@@ -2097,8 +2127,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
20972127
}
20982128
}
20992129

2100-
if (iob && !blk_queue_is_zoned(ns->queue))
2101-
blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(iob));
2130+
nvme_set_chunk_sectors(ns, id);
21022131
nvme_update_disk_info(disk, ns, id);
21032132
#ifdef CONFIG_NVME_MULTIPATH
21042133
if (ns->head->disk) {
@@ -3676,6 +3705,10 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
36763705
return 0;
36773706
if (a == &dev_attr_hostid.attr && !ctrl->opts)
36783707
return 0;
3708+
if (a == &dev_attr_ctrl_loss_tmo.attr && !ctrl->opts)
3709+
return 0;
3710+
if (a == &dev_attr_reconnect_delay.attr && !ctrl->opts)
3711+
return 0;
36793712

36803713
return a->mode;
36813714
}
@@ -4390,7 +4423,7 @@ static void nvme_free_ctrl(struct device *dev)
43904423
struct nvme_subsystem *subsys = ctrl->subsys;
43914424
struct nvme_cel *cel, *next;
43924425

4393-
if (subsys && ctrl->instance != subsys->instance)
4426+
if (!subsys || ctrl->instance != subsys->instance)
43944427
ida_simple_remove(&nvme_instance_ida, ctrl->instance);
43954428

43964429
list_for_each_entry_safe(cel, next, &ctrl->cels, entry) {
@@ -4534,7 +4567,7 @@ void nvme_unfreeze(struct nvme_ctrl *ctrl)
45344567
}
45354568
EXPORT_SYMBOL_GPL(nvme_unfreeze);
45364569

4537-
void nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout)
4570+
int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout)
45384571
{
45394572
struct nvme_ns *ns;
45404573

@@ -4545,6 +4578,7 @@ void nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout)
45454578
break;
45464579
}
45474580
up_read(&ctrl->namespaces_rwsem);
4581+
return timeout;
45484582
}
45494583
EXPORT_SYMBOL_GPL(nvme_wait_freeze_timeout);
45504584

‎drivers/nvme/host/fabrics.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
576576
* which is require to set the queue live in the appropinquate states.
577577
*/
578578
switch (ctrl->state) {
579-
case NVME_CTRL_NEW:
580579
case NVME_CTRL_CONNECTING:
581580
if (nvme_is_fabrics(req->cmd) &&
582581
req->cmd->fabrics.fctype == nvme_fabrics_type_connect)

‎drivers/nvme/host/nvme.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl);
605605
void nvme_sync_queues(struct nvme_ctrl *ctrl);
606606
void nvme_unfreeze(struct nvme_ctrl *ctrl);
607607
void nvme_wait_freeze(struct nvme_ctrl *ctrl);
608-
void nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
608+
int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
609609
void nvme_start_freeze(struct nvme_ctrl *ctrl);
610610

611611
#define NVME_QID_ANY -1

‎drivers/nvme/host/pci.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,8 +1249,8 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
12491249
dev_warn_ratelimited(dev->ctrl.device,
12501250
"I/O %d QID %d timeout, disable controller\n",
12511251
req->tag, nvmeq->qid);
1252-
nvme_dev_disable(dev, true);
12531252
nvme_req(req)->flags |= NVME_REQ_CANCELLED;
1253+
nvme_dev_disable(dev, true);
12541254
return BLK_EH_DONE;
12551255
case NVME_CTRL_RESETTING:
12561256
return BLK_EH_RESET_TIMER;
@@ -1267,10 +1267,10 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
12671267
dev_warn(dev->ctrl.device,
12681268
"I/O %d QID %d timeout, reset controller\n",
12691269
req->tag, nvmeq->qid);
1270+
nvme_req(req)->flags |= NVME_REQ_CANCELLED;
12701271
nvme_dev_disable(dev, false);
12711272
nvme_reset_ctrl(&dev->ctrl);
12721273

1273-
nvme_req(req)->flags |= NVME_REQ_CANCELLED;
12741274
return BLK_EH_DONE;
12751275
}
12761276

0 commit comments

Comments
 (0)