* [PATCH] nvme: Report MDTS values that are too large
@ 2021-03-31 3:42 Bart Van Assche
2021-03-31 5:10 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2021-03-31 3:42 UTC (permalink / raw)
To: Keith Busch, Sagi Grimberg; +Cc: Christoph Hellwig, linux-nvme, Bart Van Assche
Instead of triggering an integer overflow and undefined behavior if MDTS is
too large, set max_hw_sectors to UINT_MAX and log an error message.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/nvme/host/core.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 40215a0246e4..0edbc8c125a7 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3123,10 +3123,14 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
atomic_set(&ctrl->abort_limit, id->acl + 1);
ctrl->vwc = id->vwc;
- if (id->mdts)
- max_hw_sectors = 1 << (id->mdts + page_shift - 9);
- else
+ max_hw_sectors = UINT_MAX;
+ if (id->mdts && check_shl_overflow(1U, id->mdts + page_shift - 9,
+ &max_hw_sectors)) {
+ dev_err(ctrl->device,
+ "MDTS = %u is too large (page_shift = %u)\n",
+ id->mdts, page_shift);
max_hw_sectors = UINT_MAX;
+ }
ctrl->max_hw_sectors =
min_not_zero(ctrl->max_hw_sectors, max_hw_sectors);
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] nvme: Report MDTS values that are too large
2021-03-31 3:42 [PATCH] nvme: Report MDTS values that are too large Bart Van Assche
@ 2021-03-31 5:10 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2021-03-31 5:10 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Keith Busch, Sagi Grimberg, Christoph Hellwig, linux-nvme
On Tue, Mar 30, 2021 at 08:42:14PM -0700, Bart Van Assche wrote:
> Instead of triggering an integer overflow and undefined behavior if MDTS is
> too large, set max_hw_sectors to UINT_MAX and log an error message.
I really do not think reporting an error for something that is
perfetly valid but not useful to Linux makes much sense.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-31 5:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 3:42 [PATCH] nvme: Report MDTS values that are too large Bart Van Assche
2021-03-31 5:10 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.