diff options
author | Minwoo Im <minwoo.im@samsung.com> | 2023-04-18 09:26:22 +0900 |
---|---|---|
committer | Klaus Jensen <k.jensen@samsung.com> | 2023-06-28 11:13:42 +0200 |
commit | 381ab99d858709eab34b65d123a6356b8b1e87bd (patch) | |
tree | 22f3ec1e41bfeef9b46e2a27f91a05608b3c1836 /hw/nvme | |
parent | cab1da59c2ff3bf08d0a7becf9b51e43a724a85c (diff) | |
download | qemu-381ab99d858709eab34b65d123a6356b8b1e87bd.zip qemu-381ab99d858709eab34b65d123a6356b8b1e87bd.tar.gz qemu-381ab99d858709eab34b65d123a6356b8b1e87bd.tar.bz2 |
hw/nvme: check maximum copy length (MCL) for COPY
MCL(Maximum Copy Length) in the Identify Namespace data structure limits
the number of LBAs to be copied inside of the controller. We've not
checked it at all, so added the check with returning the proper error
status.
Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Diffstat (limited to 'hw/nvme')
-rw-r--r-- | hw/nvme/ctrl.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index e031c22..355668b 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -2855,6 +2855,25 @@ static void nvme_copy_source_range_parse(void *ranges, int idx, uint8_t format, } } +static inline uint16_t nvme_check_copy_mcl(NvmeNamespace *ns, + NvmeCopyAIOCB *iocb, uint16_t nr) +{ + uint32_t copy_len = 0; + + for (int idx = 0; idx < nr; idx++) { + uint32_t nlb; + nvme_copy_source_range_parse(iocb->ranges, idx, iocb->format, NULL, + &nlb, NULL, NULL, NULL); + copy_len += nlb + 1; + } + + if (copy_len > ns->id_ns.mcl) { + return NVME_CMD_SIZE_LIMIT | NVME_DNR; + } + + return NVME_SUCCESS; +} + static void nvme_copy_out_completed_cb(void *opaque, int ret) { NvmeCopyAIOCB *iocb = opaque; @@ -3167,6 +3186,11 @@ static uint16_t nvme_copy(NvmeCtrl *n, NvmeRequest *req) } } + status = nvme_check_copy_mcl(ns, iocb, nr); + if (status) { + goto invalid; + } + iocb->req = req; iocb->ret = 0; iocb->nr = nr; |