Skip to content

Commit 4d6b1c9

Browse files
RevanthRajashekarChristoph Hellwig
authored andcommitted
nvme: check the PRINFO bit before deciding the host buffer length
According to NVMe spec v1.4, section 8.3.1, the PRINFO bit and the metadata size play a vital role in deteriming the host buffer size. If PRIFNO bit is set and MS==8, the host doesn't add the metadata buffer, instead the controller adds it. Signed-off-by: Revanth Rajashekar <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent b4f6642 commit 4d6b1c9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,21 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
15431543
}
15441544

15451545
length = (io.nblocks + 1) << ns->lba_shift;
1546-
meta_len = (io.nblocks + 1) * ns->ms;
1547-
metadata = nvme_to_user_ptr(io.metadata);
1546+
1547+
if ((io.control & NVME_RW_PRINFO_PRACT) &&
1548+
ns->ms == sizeof(struct t10_pi_tuple)) {
1549+
/*
1550+
* Protection information is stripped/inserted by the
1551+
* controller.
1552+
*/
1553+
if (nvme_to_user_ptr(io.metadata))
1554+
return -EINVAL;
1555+
meta_len = 0;
1556+
metadata = NULL;
1557+
} else {
1558+
meta_len = (io.nblocks + 1) * ns->ms;
1559+
metadata = nvme_to_user_ptr(io.metadata);
1560+
}
15481561

15491562
if (ns->features & NVME_NS_EXT_LBAS) {
15501563
length += meta_len;

0 commit comments

Comments
 (0)