Skip to content

Commit 8ad3ac9

Browse files
committed
Merge tag 'nvme-6.7-2023-12-01' of git://git.infradead.org/nvme into block-6.7
Pull NVMe fixes from Keith: "nvme fixes for Linux 6.7 - Invalid namespace identification error handling (Marizio Ewan, Keith) - Fabrics keep-alive tuning (Mark)" * tag 'nvme-6.7-2023-12-01' of git://git.infradead.org/nvme: nvme-core: check for too small lba shift nvme: check for valid nvme_identify_ns() before using it nvme-core: fix a memory leak in nvme_ns_info_from_identify() nvme: fine-tune sending of first keep-alive
2 parents 0e4237a + 74fbc88 commit 8ad3ac9

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

drivers/nvme/host/core.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,16 @@ static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl)
11921192

11931193
static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl)
11941194
{
1195-
queue_delayed_work(nvme_wq, &ctrl->ka_work,
1196-
nvme_keep_alive_work_period(ctrl));
1195+
unsigned long now = jiffies;
1196+
unsigned long delay = nvme_keep_alive_work_period(ctrl);
1197+
unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay;
1198+
1199+
if (time_after(now, ka_next_check_tm))
1200+
delay = 0;
1201+
else
1202+
delay = ka_next_check_tm - now;
1203+
1204+
queue_delayed_work(nvme_wq, &ctrl->ka_work, delay);
11971205
}
11981206

11991207
static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq,
@@ -1479,7 +1487,8 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
14791487
if (id->ncap == 0) {
14801488
/* namespace not allocated or attached */
14811489
info->is_removed = true;
1482-
return -ENODEV;
1490+
ret = -ENODEV;
1491+
goto error;
14831492
}
14841493

14851494
info->anagrpid = id->anagrpid;
@@ -1497,8 +1506,10 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
14971506
!memchr_inv(ids->nguid, 0, sizeof(ids->nguid)))
14981507
memcpy(ids->nguid, id->nguid, sizeof(ids->nguid));
14991508
}
1509+
1510+
error:
15001511
kfree(id);
1501-
return 0;
1512+
return ret;
15021513
}
15031514

15041515
static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
@@ -1890,9 +1901,10 @@ static void nvme_update_disk_info(struct gendisk *disk,
18901901

18911902
/*
18921903
* The block layer can't support LBA sizes larger than the page size
1893-
* yet, so catch this early and don't allow block I/O.
1904+
* or smaller than a sector size yet, so catch this early and don't
1905+
* allow block I/O.
18941906
*/
1895-
if (ns->lba_shift > PAGE_SHIFT) {
1907+
if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) {
18961908
capacity = 0;
18971909
bs = (1 << 9);
18981910
}
@@ -2029,6 +2041,13 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20292041
if (ret)
20302042
return ret;
20312043

2044+
if (id->ncap == 0) {
2045+
/* namespace not allocated or attached */
2046+
info->is_removed = true;
2047+
ret = -ENODEV;
2048+
goto error;
2049+
}
2050+
20322051
blk_mq_freeze_queue(ns->disk->queue);
20332052
lbaf = nvme_lbaf_index(id->flbas);
20342053
ns->lba_shift = id->lbaf[lbaf].ds;
@@ -2090,6 +2109,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
20902109
set_bit(NVME_NS_READY, &ns->flags);
20912110
ret = 0;
20922111
}
2112+
2113+
error:
20932114
kfree(id);
20942115
return ret;
20952116
}
@@ -4471,6 +4492,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
44714492
INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work);
44724493
memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
44734494
ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
4495+
ctrl->ka_last_check_time = jiffies;
44744496

44754497
BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
44764498
PAGE_SIZE);

0 commit comments

Comments
 (0)