Skip to content

Commit 4fd84bc

Browse files
committed
Merge tag 'block-5.10-2020-11-20' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: - NVMe pull request from Christoph: - Doorbell Buffer freeing fix (Minwoo Im) - CSE log leak fix (Keith Busch) - blk-cgroup hd_struct leak fix (Christoph) - Flush request state fix (Ming) - dasd NULL deref fix (Stefan) * tag 'block-5.10-2020-11-20' of git://git.kernel.dk/linux-block: s390/dasd: fix null pointer dereference for ERP requests blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats nvme: fix memory leak freeing command effects nvme: directly cache command effects log nvme: free sq/cq dbbuf pointers when dbbuf set fails block: mark flush request as IDLE when it is really finished
2 parents fa5fca7 + 45f703a commit 4fd84bc

6 files changed

Lines changed: 46 additions & 14 deletions

File tree

block/blk-cgroup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ static void blkcg_fill_root_iostats(void)
849849
blkg_iostat_set(&blkg->iostat.cur, &tmp);
850850
u64_stats_update_end(&blkg->iostat.sync);
851851
}
852+
disk_put_part(part);
852853
}
853854
}
854855

block/blk-flush.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,18 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
225225
/* release the tag's ownership to the req cloned from */
226226
spin_lock_irqsave(&fq->mq_flush_lock, flags);
227227

228-
WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
229228
if (!refcount_dec_and_test(&flush_rq->ref)) {
230229
fq->rq_status = error;
231230
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
232231
return;
233232
}
234233

234+
/*
235+
* Flush request has to be marked as IDLE when it is really ended
236+
* because its .end_io() is called from timeout code path too for
237+
* avoiding use-after-free.
238+
*/
239+
WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
235240
if (fq->rq_status != BLK_STS_OK)
236241
error = fq->rq_status;
237242

drivers/nvme/host/core.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,7 +2929,7 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
29292929
static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
29302930
struct nvme_effects_log **log)
29312931
{
2932-
struct nvme_cel *cel = xa_load(&ctrl->cels, csi);
2932+
struct nvme_effects_log *cel = xa_load(&ctrl->cels, csi);
29332933
int ret;
29342934

29352935
if (cel)
@@ -2940,16 +2940,15 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
29402940
return -ENOMEM;
29412941

29422942
ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi,
2943-
&cel->log, sizeof(cel->log), 0);
2943+
cel, sizeof(*cel), 0);
29442944
if (ret) {
29452945
kfree(cel);
29462946
return ret;
29472947
}
29482948

2949-
cel->csi = csi;
2950-
xa_store(&ctrl->cels, cel->csi, cel, GFP_KERNEL);
2949+
xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
29512950
out:
2952-
*log = &cel->log;
2951+
*log = cel;
29532952
return 0;
29542953
}
29552954

@@ -4374,6 +4373,19 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
43744373
}
43754374
EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
43764375

4376+
static void nvme_free_cels(struct nvme_ctrl *ctrl)
4377+
{
4378+
struct nvme_effects_log *cel;
4379+
unsigned long i;
4380+
4381+
xa_for_each (&ctrl->cels, i, cel) {
4382+
xa_erase(&ctrl->cels, i);
4383+
kfree(cel);
4384+
}
4385+
4386+
xa_destroy(&ctrl->cels);
4387+
}
4388+
43774389
static void nvme_free_ctrl(struct device *dev)
43784390
{
43794391
struct nvme_ctrl *ctrl =
@@ -4383,8 +4395,7 @@ static void nvme_free_ctrl(struct device *dev)
43834395
if (!subsys || ctrl->instance != subsys->instance)
43844396
ida_simple_remove(&nvme_instance_ida, ctrl->instance);
43854397

4386-
xa_destroy(&ctrl->cels);
4387-
4398+
nvme_free_cels(ctrl);
43884399
nvme_mpath_uninit(ctrl);
43894400
__free_page(ctrl->discard_page);
43904401

drivers/nvme/host/nvme.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,6 @@ struct nvme_fault_inject {
226226
#endif
227227
};
228228

229-
struct nvme_cel {
230-
struct list_head entry;
231-
struct nvme_effects_log log;
232-
u8 csi;
233-
};
234-
235229
struct nvme_ctrl {
236230
bool comp_seen;
237231
enum nvme_ctrl_state state;

drivers/nvme/host/pci.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,21 @@ static void nvme_dbbuf_init(struct nvme_dev *dev,
292292
nvmeq->dbbuf_cq_ei = &dev->dbbuf_eis[cq_idx(qid, dev->db_stride)];
293293
}
294294

295+
static void nvme_dbbuf_free(struct nvme_queue *nvmeq)
296+
{
297+
if (!nvmeq->qid)
298+
return;
299+
300+
nvmeq->dbbuf_sq_db = NULL;
301+
nvmeq->dbbuf_cq_db = NULL;
302+
nvmeq->dbbuf_sq_ei = NULL;
303+
nvmeq->dbbuf_cq_ei = NULL;
304+
}
305+
295306
static void nvme_dbbuf_set(struct nvme_dev *dev)
296307
{
297308
struct nvme_command c;
309+
unsigned int i;
298310

299311
if (!dev->dbbuf_dbs)
300312
return;
@@ -308,6 +320,9 @@ static void nvme_dbbuf_set(struct nvme_dev *dev)
308320
dev_warn(dev->ctrl.device, "unable to set dbbuf\n");
309321
/* Free memory and continue on */
310322
nvme_dbbuf_dma_free(dev);
323+
324+
for (i = 1; i <= dev->online_queues; i++)
325+
nvme_dbbuf_free(&dev->queues[i]);
311326
}
312327
}
313328

drivers/s390/block/dasd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,12 @@ static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
29802980

29812981
if (!block)
29822982
return -EINVAL;
2983+
/*
2984+
* If the request is an ERP request there is nothing to requeue.
2985+
* This will be done with the remaining original request.
2986+
*/
2987+
if (cqr->refers)
2988+
return 0;
29832989
spin_lock_irq(&cqr->dq->lock);
29842990
req = (struct request *) cqr->callback_data;
29852991
blk_mq_requeue_request(req, false);

0 commit comments

Comments
 (0)