libnvme: Add better asserts in SGL-to-PRP request conversion.

Taken from upstream (SPDK).
This commit is contained in:
Augustin Cavalier 2020-04-23 01:01:47 -04:00
parent b0460580c5
commit 9a3a70f437

View File

@ -687,6 +687,12 @@ static int _nvme_qpair_build_prps_sgl_request(struct nvme_qpair *qpair,
return -1;
}
nvme_assert((phys_addr & 0x3) == 0, "address must be dword aligned\n");
nvme_assert((length >= remaining_transfer_len) || ((phys_addr + length) % PAGE_SIZE) == 0,
"All SGEs except last must end on a page boundary\n");
nvme_assert((sge_count == 0) || (phys_addr % PAGE_SIZE) == 0,
"All SGEs except first must start on a page boundary\n");
data_transferred = nvme_min(remaining_transfer_len, length);
nseg = data_transferred >> PAGE_SHIFT;
@ -732,18 +738,6 @@ static int _nvme_qpair_build_prps_sgl_request(struct nvme_qpair *qpair,
}
last_nseg++;
cur_nseg++;
/* physical address and length check */
if (remaining_transfer_len ||
(!remaining_transfer_len &&
(cur_nseg < nseg))) {
if ((length & (PAGE_SIZE - 1)) ||
unaligned) {
_nvme_qpair_req_bad_phys(qpair,
tr);
return -1;
}
}
}
}
}