Skip to content

Commit 2d70de4

Browse files
committed
Merge tag 'block-5.15-2021-09-25' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: - NVMe pull request via Christoph: - keep ctrl->namespaces ordered (Christoph Hellwig) - fix incorrect h2cdata pdu offset accounting in nvme-tcp (Sagi Grimberg) - handled updated hw_queues in nvme-fc more carefully (Daniel Wagner, James Smart) - md lock order fix (Christoph) - fallocate locking fix (Ming) - blktrace UAF fix (Zhihao) - rq-qos bio tracking fix (Ming) * tag 'block-5.15-2021-09-25' of git://git.kernel.dk/linux-block: block: hold ->invalidate_lock in blkdev_fallocate blktrace: Fix uaf in blk_trace access after removing by sysfs block: don't call rq_qos_ops->done_bio if the bio isn't tracked md: fix a lock order reversal in md_alloc nvme: keep ctrl->namespaces ordered nvme-tcp: fix incorrect h2cdata pdu offset accounting nvme-fc: remove freeze/unfreeze around update_nr_hw_queues nvme-fc: avoid race between time out and tear down nvme-fc: update hardware queues before using them
2 parents 5739844 + f278eb3 commit 2d70de4

File tree

7 files changed

+55
-45
lines changed

7 files changed

+55
-45
lines changed

block/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ void bio_endio(struct bio *bio)
14661466
if (!bio_integrity_endio(bio))
14671467
return;
14681468

1469-
if (bio->bi_bdev)
1469+
if (bio->bi_bdev && bio_flagged(bio, BIO_TRACKED))
14701470
rq_qos_done_bio(bio->bi_bdev->bd_disk->queue, bio);
14711471

14721472
if (bio->bi_bdev && bio_flagged(bio, BIO_TRACE_COMPLETION)) {

block/fops.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/task_io_accounting_ops.h>
1515
#include <linux/falloc.h>
1616
#include <linux/suspend.h>
17+
#include <linux/fs.h>
1718
#include "blk.h"
1819

1920
static struct inode *bdev_file_inode(struct file *file)
@@ -553,7 +554,8 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
553554
static long blkdev_fallocate(struct file *file, int mode, loff_t start,
554555
loff_t len)
555556
{
556-
struct block_device *bdev = I_BDEV(bdev_file_inode(file));
557+
struct inode *inode = bdev_file_inode(file);
558+
struct block_device *bdev = I_BDEV(inode);
557559
loff_t end = start + len - 1;
558560
loff_t isize;
559561
int error;
@@ -580,10 +582,12 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
580582
if ((start | len) & (bdev_logical_block_size(bdev) - 1))
581583
return -EINVAL;
582584

585+
filemap_invalidate_lock(inode->i_mapping);
586+
583587
/* Invalidate the page cache, including dirty pages. */
584588
error = truncate_bdev_range(bdev, file->f_mode, start, end);
585589
if (error)
586-
return error;
590+
goto fail;
587591

588592
switch (mode) {
589593
case FALLOC_FL_ZERO_RANGE:
@@ -600,17 +604,12 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
600604
GFP_KERNEL, 0);
601605
break;
602606
default:
603-
return -EOPNOTSUPP;
607+
error = -EOPNOTSUPP;
604608
}
605-
if (error)
606-
return error;
607609

608-
/*
609-
* Invalidate the page cache again; if someone wandered in and dirtied
610-
* a page, we just discard it - userspace has no way of knowing whether
611-
* the write happened before or after discard completing...
612-
*/
613-
return truncate_bdev_range(bdev, file->f_mode, start, end);
610+
fail:
611+
filemap_invalidate_unlock(inode->i_mapping);
612+
return error;
614613
}
615614

616615
const struct file_operations def_blk_fops = {

drivers/md/md.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,10 +5700,6 @@ static int md_alloc(dev_t dev, char *name)
57005700
disk->flags |= GENHD_FL_EXT_DEVT;
57015701
disk->events |= DISK_EVENT_MEDIA_CHANGE;
57025702
mddev->gendisk = disk;
5703-
/* As soon as we call add_disk(), another thread could get
5704-
* through to md_open, so make sure it doesn't get too far
5705-
*/
5706-
mutex_lock(&mddev->open_mutex);
57075703
add_disk(disk);
57085704

57095705
error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md");
@@ -5718,7 +5714,6 @@ static int md_alloc(dev_t dev, char *name)
57185714
if (mddev->kobj.sd &&
57195715
sysfs_create_group(&mddev->kobj, &md_bitmap_group))
57205716
pr_debug("pointless warning\n");
5721-
mutex_unlock(&mddev->open_mutex);
57225717
abort:
57235718
mutex_unlock(&disks_mutex);
57245719
if (!error && mddev->kobj.sd) {

drivers/nvme/host/core.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/kernel.h>
1414
#include <linux/module.h>
1515
#include <linux/backing-dev.h>
16-
#include <linux/list_sort.h>
1716
#include <linux/slab.h>
1817
#include <linux/types.h>
1918
#include <linux/pr.h>
@@ -3716,15 +3715,6 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
37163715
return ret;
37173716
}
37183717

3719-
static int ns_cmp(void *priv, const struct list_head *a,
3720-
const struct list_head *b)
3721-
{
3722-
struct nvme_ns *nsa = container_of(a, struct nvme_ns, list);
3723-
struct nvme_ns *nsb = container_of(b, struct nvme_ns, list);
3724-
3725-
return nsa->head->ns_id - nsb->head->ns_id;
3726-
}
3727-
37283718
struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)
37293719
{
37303720
struct nvme_ns *ns, *ret = NULL;
@@ -3745,6 +3735,22 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)
37453735
}
37463736
EXPORT_SYMBOL_NS_GPL(nvme_find_get_ns, NVME_TARGET_PASSTHRU);
37473737

3738+
/*
3739+
* Add the namespace to the controller list while keeping the list ordered.
3740+
*/
3741+
static void nvme_ns_add_to_ctrl_list(struct nvme_ns *ns)
3742+
{
3743+
struct nvme_ns *tmp;
3744+
3745+
list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) {
3746+
if (tmp->head->ns_id < ns->head->ns_id) {
3747+
list_add(&ns->list, &tmp->list);
3748+
return;
3749+
}
3750+
}
3751+
list_add(&ns->list, &ns->ctrl->namespaces);
3752+
}
3753+
37483754
static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
37493755
struct nvme_ns_ids *ids)
37503756
{
@@ -3795,9 +3801,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
37953801
goto out_unlink_ns;
37963802

37973803
down_write(&ctrl->namespaces_rwsem);
3798-
list_add_tail(&ns->list, &ctrl->namespaces);
3804+
nvme_ns_add_to_ctrl_list(ns);
37993805
up_write(&ctrl->namespaces_rwsem);
3800-
38013806
nvme_get_ctrl(ctrl);
38023807

38033808
if (device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups))
@@ -4080,10 +4085,6 @@ static void nvme_scan_work(struct work_struct *work)
40804085
if (nvme_scan_ns_list(ctrl) != 0)
40814086
nvme_scan_ns_sequential(ctrl);
40824087
mutex_unlock(&ctrl->scan_lock);
4083-
4084-
down_write(&ctrl->namespaces_rwsem);
4085-
list_sort(NULL, &ctrl->namespaces, ns_cmp);
4086-
up_write(&ctrl->namespaces_rwsem);
40874088
}
40884089

40894090
/*

drivers/nvme/host/fc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@ __nvme_fc_abort_outstanding_ios(struct nvme_fc_ctrl *ctrl, bool start_queues)
24872487
*/
24882488
if (ctrl->ctrl.queue_count > 1) {
24892489
nvme_stop_queues(&ctrl->ctrl);
2490+
nvme_sync_io_queues(&ctrl->ctrl);
24902491
blk_mq_tagset_busy_iter(&ctrl->tag_set,
24912492
nvme_fc_terminate_exchange, &ctrl->ctrl);
24922493
blk_mq_tagset_wait_completed_request(&ctrl->tag_set);
@@ -2510,6 +2511,7 @@ __nvme_fc_abort_outstanding_ios(struct nvme_fc_ctrl *ctrl, bool start_queues)
25102511
* clean up the admin queue. Same thing as above.
25112512
*/
25122513
blk_mq_quiesce_queue(ctrl->ctrl.admin_q);
2514+
blk_sync_queue(ctrl->ctrl.admin_q);
25132515
blk_mq_tagset_busy_iter(&ctrl->admin_tag_set,
25142516
nvme_fc_terminate_exchange, &ctrl->ctrl);
25152517
blk_mq_tagset_wait_completed_request(&ctrl->admin_tag_set);
@@ -2951,6 +2953,13 @@ nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
29512953
if (ctrl->ctrl.queue_count == 1)
29522954
return 0;
29532955

2956+
if (prior_ioq_cnt != nr_io_queues) {
2957+
dev_info(ctrl->ctrl.device,
2958+
"reconnect: revising io queue count from %d to %d\n",
2959+
prior_ioq_cnt, nr_io_queues);
2960+
blk_mq_update_nr_hw_queues(&ctrl->tag_set, nr_io_queues);
2961+
}
2962+
29542963
ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.sqsize + 1);
29552964
if (ret)
29562965
goto out_free_io_queues;
@@ -2959,15 +2968,6 @@ nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
29592968
if (ret)
29602969
goto out_delete_hw_queues;
29612970

2962-
if (prior_ioq_cnt != nr_io_queues) {
2963-
dev_info(ctrl->ctrl.device,
2964-
"reconnect: revising io queue count from %d to %d\n",
2965-
prior_ioq_cnt, nr_io_queues);
2966-
nvme_wait_freeze(&ctrl->ctrl);
2967-
blk_mq_update_nr_hw_queues(&ctrl->tag_set, nr_io_queues);
2968-
nvme_unfreeze(&ctrl->ctrl);
2969-
}
2970-
29712971
return 0;
29722972

29732973
out_delete_hw_queues:

drivers/nvme/host/tcp.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static int nvme_tcp_setup_h2c_data_pdu(struct nvme_tcp_request *req,
620620
cpu_to_le32(data->hdr.hlen + hdgst + req->pdu_len + ddgst);
621621
data->ttag = pdu->ttag;
622622
data->command_id = nvme_cid(rq);
623-
data->data_offset = cpu_to_le32(req->data_sent);
623+
data->data_offset = pdu->r2t_offset;
624624
data->data_length = cpu_to_le32(req->pdu_len);
625625
return 0;
626626
}
@@ -953,7 +953,15 @@ static int nvme_tcp_try_send_data(struct nvme_tcp_request *req)
953953
nvme_tcp_ddgst_update(queue->snd_hash, page,
954954
offset, ret);
955955

956-
/* fully successful last write*/
956+
/*
957+
* update the request iterator except for the last payload send
958+
* in the request where we don't want to modify it as we may
959+
* compete with the RX path completing the request.
960+
*/
961+
if (req->data_sent + ret < req->data_len)
962+
nvme_tcp_advance_req(req, ret);
963+
964+
/* fully successful last send in current PDU */
957965
if (last && ret == len) {
958966
if (queue->data_digest) {
959967
nvme_tcp_ddgst_final(queue->snd_hash,
@@ -965,7 +973,6 @@ static int nvme_tcp_try_send_data(struct nvme_tcp_request *req)
965973
}
966974
return 1;
967975
}
968-
nvme_tcp_advance_req(req, ret);
969976
}
970977
return -EAGAIN;
971978
}

kernel/trace/blktrace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,14 @@ static int blk_trace_remove_queue(struct request_queue *q)
16051605
if (bt == NULL)
16061606
return -EINVAL;
16071607

1608+
if (bt->trace_state == Blktrace_running) {
1609+
bt->trace_state = Blktrace_stopped;
1610+
spin_lock_irq(&running_trace_lock);
1611+
list_del_init(&bt->running_list);
1612+
spin_unlock_irq(&running_trace_lock);
1613+
relay_flush(bt->rchan);
1614+
}
1615+
16081616
put_probe_ref();
16091617
synchronize_rcu();
16101618
blk_trace_free(bt);

0 commit comments

Comments
 (0)