<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Aug 20, 2018 at 11:16 PM Kevin O'Connor <<a href="mailto:kevin@koconnor.net">kevin@koconnor.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Aug 12, 2018 at 03:42:40PM -0500, Matt DeVillier wrote:<br>
> Commit cd47172 changed the I/O queue length calculation to use the<br>
> Maximum Queue Entries Supported (MQES) value from the capabilities<br>
> register, plus one, with a maximum value of NVME_PAGE_SIZE.<br>
> <br>
> An unintended effect from this is that a MQES value of 0xFFFF yields<br>
> a length of zero, resulting in the queue allocation failing. Fix this<br>
> by checking for a zero length when checking that the length exceeds<br>
> NVME_PAGE_SIZE, and setting to NVME_PAGE_SIZE.<br>
> <br>
> TEST: build/boot on a Purism Librem13v2 with a MyDigitalSSD BPX NVMe<br>
> drive, which reports a MQES of 0xFFFF. Verify NVMe drive present in<br>
> boot menu and OS boots successfully.<br>
> <br>
> Signed-off-by: Matt DeVillier <<a href="mailto:matt.devillier@gmail.com" target="_blank">matt.devillier@gmail.com</a>><br>
> ---<br>
>  src/hw/nvme.c | 4 ++--<br>
>  1 file changed, 2 insertions(+), 2 deletions(-)<br>
> <br>
> diff --git a/src/hw/nvme.c b/src/hw/nvme.c<br>
> index e6d739d..c2d6863 100644<br>
> --- a/src/hw/nvme.c<br>
> +++ b/src/hw/nvme.c<br>
> @@ -319,7 +319,7 @@ nvme_create_io_cq(struct nvme_ctrl *ctrl, struct<br>
> nvme_cq *cq, u16 q_idx)<br>
>      int rc;<br>
>      struct nvme_sqe *cmd_create_cq;<br>
>      u16 length = 1 + (ctrl->reg->cap & 0xffff);<br>
> -    if (length > NVME_PAGE_SIZE / sizeof(struct nvme_cqe))<br>
> +    if (length == 0 || length > NVME_PAGE_SIZE / sizeof(struct nvme_cqe))<br>
>          length = NVME_PAGE_SIZE / sizeof(struct nvme_cqe);<br>
<br>
Thanks.  Instead of changing the if statement, could we just change<br>
length here to a u32 to avoid this issue?<br></blockquote><div><br></div><div>I can't think of why not, I'll test this method and submit an updated patchset if so - thanks!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> <br>
>      rc = nvme_init_cq(ctrl, cq, q_idx, length);<br>
> @@ -363,7 +363,7 @@ nvme_create_io_sq(struct nvme_ctrl *ctrl, struct<br>
> nvme_sq *sq, u16 q_idx, struct<br>
>      int rc;<br>
>      struct nvme_sqe *cmd_create_sq;<br>
>      u16 length = 1 + (ctrl->reg->cap & 0xffff);<br>
> -    if (length > NVME_PAGE_SIZE / sizeof(struct nvme_cqe))<br>
> +    if (length == 0 || length > NVME_PAGE_SIZE / sizeof(struct nvme_cqe))<br>
>          length = NVME_PAGE_SIZE / sizeof(struct nvme_cqe);<br>
> <br>
>      rc = nvme_init_sq(ctrl, sq, q_idx, length, cq);<br>
> -- <br>
> 2.17.1<br>
<br>
-Kevin<br>
</blockquote></div></div>