* [PATCH v3] nvme: Fix handling of large MDTS values
@ 2021-04-02 1:39 Bart Van Assche
2021-04-02 1:49 ` Keith Busch
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Bart Van Assche @ 2021-04-02 1:39 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
large, set max_hw_sectors to UINT_MAX.
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Keith Busch <kbusch@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
Changes compared to v2: reduced the two max_hw_sectors = UINT_MAX statements into a single assignment.
Changes compared to v1: removed a dev_err() call.
drivers/nvme/host/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 40215a0246e4..87d43309742b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3123,10 +3123,10 @@ 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
+ if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9,
+ &max_hw_sectors)) {
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] 5+ messages in thread
* Re: [PATCH v3] nvme: Fix handling of large MDTS values
2021-04-02 1:39 [PATCH v3] nvme: Fix handling of large MDTS values Bart Van Assche
@ 2021-04-02 1:49 ` Keith Busch
2021-04-02 5:00 ` Damien Le Moal
2021-04-02 16:50 ` Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2021-04-02 1:49 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Sagi Grimberg, Christoph Hellwig, linux-nvme
On Thu, Apr 01, 2021 at 06:39:07PM -0700, Bart Van Assche wrote:
> Instead of triggering an integer overflow and undefined behavior if MDTS is
> large, set max_hw_sectors to UINT_MAX.
Looks good,
Reviewed-by: Keith Busch <kbusch@kernel.org>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] nvme: Fix handling of large MDTS values
2021-04-02 1:39 [PATCH v3] nvme: Fix handling of large MDTS values Bart Van Assche
2021-04-02 1:49 ` Keith Busch
@ 2021-04-02 5:00 ` Damien Le Moal
2021-04-02 6:35 ` Christoph Hellwig
2021-04-02 16:50 ` Christoph Hellwig
2 siblings, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2021-04-02 5:00 UTC (permalink / raw)
To: Bart Van Assche, Keith Busch, Sagi Grimberg; +Cc: Christoph Hellwig, linux-nvme
On 2021/04/02 10:47, Bart Van Assche wrote:
> Instead of triggering an integer overflow and undefined behavior if MDTS is
> large, set max_hw_sectors to UINT_MAX.
>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Sagi Grimberg <sagi@grimberg.me>
> Cc: Keith Busch <kbusch@kernel.org>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>
> Changes compared to v2: reduced the two max_hw_sectors = UINT_MAX statements into a single assignment.
> Changes compared to v1: removed a dev_err() call.
>
> drivers/nvme/host/core.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 40215a0246e4..87d43309742b 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3123,10 +3123,10 @@ 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
> + if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9,
> + &max_hw_sectors)) {
> max_hw_sectors = UINT_MAX;
> + }
Nit: this could be rewritten as:
if (!id->mdts ||
check_shl_overflow(1U, id->mdts + page_shift - 9, &max_hw_sectors))
max_hw_sectors = UINT_MAX;
More readable and no unneeded brackets. No ?
> 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
>
--
Damien Le Moal
Western Digital Research
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] nvme: Fix handling of large MDTS values
2021-04-02 5:00 ` Damien Le Moal
@ 2021-04-02 6:35 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-04-02 6:35 UTC (permalink / raw)
To: Damien Le Moal
Cc: Bart Van Assche, Keith Busch, Sagi Grimberg, Christoph Hellwig,
linux-nvme
On Fri, Apr 02, 2021 at 05:00:58AM +0000, Damien Le Moal wrote:
> On 2021/04/02 10:47, Bart Van Assche wrote:
> > Instead of triggering an integer overflow and undefined behavior if MDTS is
> > large, set max_hw_sectors to UINT_MAX.
> >
> > Cc: Christoph Hellwig <hch@lst.de>
> > Cc: Sagi Grimberg <sagi@grimberg.me>
> > Cc: Keith Busch <kbusch@kernel.org>
> > Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> > ---
> >
> > Changes compared to v2: reduced the two max_hw_sectors = UINT_MAX statements into a single assignment.
> > Changes compared to v1: removed a dev_err() call.
> >
> > drivers/nvme/host/core.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 40215a0246e4..87d43309742b 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -3123,10 +3123,10 @@ 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
> > + if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9,
> > + &max_hw_sectors)) {
> > max_hw_sectors = UINT_MAX;
> > + }
>
> Nit: this could be rewritten as:
>
> if (!id->mdts ||
> check_shl_overflow(1U, id->mdts + page_shift - 9, &max_hw_sectors))
> max_hw_sectors = UINT_MAX;
>
> More readable and no unneeded brackets. No ?
I'll just fix this up when applying the patch.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] nvme: Fix handling of large MDTS values
2021-04-02 1:39 [PATCH v3] nvme: Fix handling of large MDTS values Bart Van Assche
2021-04-02 1:49 ` Keith Busch
2021-04-02 5:00 ` Damien Le Moal
@ 2021-04-02 16:50 ` Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-04-02 16:50 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Keith Busch, Sagi Grimberg, Christoph Hellwig, linux-nvme
Thanks,
applied to nvme-5.13.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-04-02 16:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02 1:39 [PATCH v3] nvme: Fix handling of large MDTS values Bart Van Assche
2021-04-02 1:49 ` Keith Busch
2021-04-02 5:00 ` Damien Le Moal
2021-04-02 6:35 ` Christoph Hellwig
2021-04-02 16:50 ` 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.