nvme fixes for Linux 6.7

- Invalid namespace identification error handling (Marizio Ewan, Keith)
  - Fabrics keep-alive tuning (Mark)
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE3Fbyvv+648XNRdHTPe3zGtjzRgkFAmVqAtwACgkQPe3zGtjz
 RglRnA/+M7S1MTBBeW9XfjJWZQcQQdcspXskc+ylFfKMYkcxOHPNZVYnA2tvcDCP
 g9Vg8NtHab8b4i4Q/axBPnYSWpYimvj6mse3G9DutA7Ag/G7vA+hNoh6YZ0PE7xO
 SNASA34lBN5dpfM1IZ8JyOn22XH+R6HMHLRpw7vBkdBNCQr9/m2OUs2ckQ7rVARj
 +FCibJBog8WZVCULvDW2nt9cOyHM5jc6Ti3r0+s60u0YKNpoJ4Am6JSHdeBeDj2t
 vh1Mto3C0z9E/nn7VNZCZNohQrsP/YnmC7henS1xnALlNTO8lVJK9w0ZBgoiNqhA
 2fIfl4k1txjqrhIshtsptP1uAh8j90evZ7QbQ3B1dPAuzHWVETxhZ2Bzn/gJrId4
 rB/wtrQimezvFqpw83s8yQPMmvO3jhW8DYsEvctHtzn3bbIRiMsagfe5P0TgQsCb
 dqXgVZzWTqyPaa1/M8X0VaWmh4XPKqqZULCuwKifRVnn0GIPavhMmtfqxmRvyayg
 WP9bhe2Sgr+FrItdRjDYMrmQiE4onzhSpMRWPWaKxsfYS9sf2DgUcEMKb1FrlHaQ
 ApTXrP9tM48K4aqybjRJfcQkuDesGgnZu2q5EsmU6ZHhD86kIthX/lJkdd2EmY8J
 iykLCeTMRo6nsut2Lr2yTt7H6Y4gUhsUrNLCO50Go7jMyxISkqA=
 =tdDy
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Jens Axboe 2023-12-01 09:09:16 -07:00
commit 8ad3ac92f0

View File

@ -1192,8 +1192,16 @@ static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl)
static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl)
{
queue_delayed_work(nvme_wq, &ctrl->ka_work,
nvme_keep_alive_work_period(ctrl));
unsigned long now = jiffies;
unsigned long delay = nvme_keep_alive_work_period(ctrl);
unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay;
if (time_after(now, ka_next_check_tm))
delay = 0;
else
delay = ka_next_check_tm - now;
queue_delayed_work(nvme_wq, &ctrl->ka_work, delay);
}
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,
if (id->ncap == 0) {
/* namespace not allocated or attached */
info->is_removed = true;
return -ENODEV;
ret = -ENODEV;
goto error;
}
info->anagrpid = id->anagrpid;
@ -1497,8 +1506,10 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
!memchr_inv(ids->nguid, 0, sizeof(ids->nguid)))
memcpy(ids->nguid, id->nguid, sizeof(ids->nguid));
}
error:
kfree(id);
return 0;
return ret;
}
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,
/*
* The block layer can't support LBA sizes larger than the page size
* yet, so catch this early and don't allow block I/O.
* or smaller than a sector size yet, so catch this early and don't
* allow block I/O.
*/
if (ns->lba_shift > PAGE_SHIFT) {
if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) {
capacity = 0;
bs = (1 << 9);
}
@ -2029,6 +2041,13 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
if (ret)
return ret;
if (id->ncap == 0) {
/* namespace not allocated or attached */
info->is_removed = true;
ret = -ENODEV;
goto error;
}
blk_mq_freeze_queue(ns->disk->queue);
lbaf = nvme_lbaf_index(id->flbas);
ns->lba_shift = id->lbaf[lbaf].ds;
@ -2090,6 +2109,8 @@ out:
set_bit(NVME_NS_READY, &ns->flags);
ret = 0;
}
error:
kfree(id);
return ret;
}
@ -4471,6 +4492,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work);
memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
ctrl->ka_last_check_time = jiffies;
BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
PAGE_SIZE);