hw/nvme: COPY fixes
cover hw/nvme: COPY fixes
Fix status code overwritten issue in the COPY command and a trivial patch to check the Maximum Copy Length (MCL) for COPY command.
Minwoo Im (2):
hw/nvme: consider COPY command in nvme_aio_err hw/nvme: check maximum copy length (MCL) for COPY
hw/nvme/ctrl.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Signature · 1 line
2.34.1
PATCH RESEND 1/2 hw/nvme: consider COPY command in nvme_aio_err
From: Minwoo Im <[email protected]>
If we don't have NVME_CMD_COPY consideration in the switch statement in nvme_aio_err(), it will go to have NVME_INTERNAL_DEV_ERROR and req->status will be ovewritten to it. During the aio context, it might set the NVMe status field like NVME_CMD_SIZE_LIMIT, but it's overwritten in the nvme_aio_err().
Add consideration for the NVME_CMD_COPY not to overwrite the status at the end of the function.
--- hw/nvme/ctrl.c | 1 + 1 file changed, 1 insertion(+)
hw/nvme/ctrl.c +1 -0
@@ -1748,6 +1748,7 @@ static void nvme_aio_err(NvmeRequest *req, int ret)case NVME_CMD_WRITE :case NVME_CMD_WRITE_ZEROES :case NVME_CMD_ZONE_APPEND : +case NVME_CMD_COPY : status =NVME_WRITE_FAULT ;break ;default :
Signature · 1 line
2.34.1
PATCH RESEND 2/2 hw/nvme: check maximum copy length (MCL) for COPY
In reply to Minwoo ImFrom: Minwoo Im <[email protected]>
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.
--- hw/nvme/ctrl.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
hw/nvme/ctrl.c +24 -0
@@ -2845,6 +2845,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;
@@ -3157,6 +3176,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;
Signature · 1 line
2.34.1
Klaus Jensen
AppliedQuoted 13 lines · Minwoo Im
Fix status code overwritten issue in the COPY command and a trivial patch to check the Maximum Copy Length (MCL) for COPY command.
Minwoo Im (2):
hw/nvme: consider COPY command innvme_aio_errhw/nvme: check maximum copy length (MCL) for COPYhw/nvme/ctrl.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)Signature · 1 line
2.34.1
Thanks,
Applied to nvme-next!