From patchwork Fri Mar 24 08:35:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1760816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=Mi5Ujfjr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pjnlz44YWz1yYB for ; Sat, 25 Mar 2023 03:31:43 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfczc-0000xQ-6l; Fri, 24 Mar 2023 04:41:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfczY-0000xA-NV for qemu-devel@nongnu.org; Fri, 24 Mar 2023 04:41:44 -0400 Received: from mailout1.samsung.com ([203.254.224.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfczJ-0000Nv-SH for qemu-devel@nongnu.org; Fri, 24 Mar 2023 04:41:43 -0400 Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230324083509epoutp0186d40e89e023efe08d43d24c0e416d7e~PTfcMrLNx2951029510epoutp01W for ; Fri, 24 Mar 2023 08:35:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230324083509epoutp0186d40e89e023efe08d43d24c0e416d7e~PTfcMrLNx2951029510epoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679646909; bh=+aRIg26OlnH+KFCxWh8KFBYzogllA7U/nt4SKZ6wxIo=; h=Subject:Reply-To:From:To:CC:Date:References:From; b=Mi5UjfjrPNEzrTiN3Al/bMFWHikgDm5c6q/hKrnicYZSYOEPftVYdhUxH/a0/m0z8 uqVCDHlUHj2KulJThbJBKfgiWocXWc8DhPh+jbBPq47qp/7Kz+NG0jwYEbglaijolb Wj33Ym5zas9iMeJ1q28O9TJjAYuH5NxqqtSbU/VA= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20230324083509epcas2p162360ede3cbfc4dbc939e38f925704cc~PTfbvvcaQ0582305823epcas2p15; Fri, 24 Mar 2023 08:35:09 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.102]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4PjbB42qY5z4x9Q6; Fri, 24 Mar 2023 08:35:08 +0000 (GMT) X-AuditID: b6c32a46-4e1ff70000007a4b-ac-641d60bcb914 Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id C1.BB.31307.CB06D146; Fri, 24 Mar 2023 17:35:08 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH 1/2] hw/nvme: consider COPY command in nvme_aio_err From: Minwoo Im To: "qemu-devel@nongnu.org" , "qemu-block@nongnu.org" CC: Klaus Birkelund Jensen , Minwoo Im X-Priority: 3 X-Content-Kind-Code: NORMAL X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20230324083507epcms2p3fcf6bed459a8080dc7f179a3506b44ec@epcms2p3> Date: Fri, 24 Mar 2023 17:35:07 +0900 X-CMS-MailID: 20230324083507epcms2p3fcf6bed459a8080dc7f179a3506b44ec X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKKsWRmVeSWpSXmKPExsWy7bCmue6eBNkUg6v7BC1ONu5htXh2+gCz xax37WwWx3t3sDiweDy5tpnJo2/LKsYApqhsm4zUxJTUIoXUvOT8lMy8dFsl7+B453hTMwND XUNLC3MlhbzE3FRbJRefAF23zBygTUoKZYk5pUChgMTiYiV9O5ui/NKSVIWM/OISW6XUgpSc AvMCveLE3OLSvHS9vNQSK0MDAyNToMKE7IzbvxpYCq6yV9z+N52xgXEyWxcjJ4eEgInExgcv WEFsIYEdjBIz7+t2MXJw8AoISvzdIQwSFhZwluh49oQZJCwkIC/x45UBRFhT4t3uM2CdbALq Eg1TX7GA2CICaRIt+96BxZkFwiQ2nznDDrGJV2JG+1MWCFtaYvvyrYwQtobEj2W9zBC2qMTN 1W/ZYez3x+ZD1YhItN47C1UjKPHg526ouJTE/vlzoexqiYbjz5gg7AqJX+8fQNWbS/y+vxvs Hl4BX4nn104wgbzCIqAq8fJMNkSJi8SlA3sYIU6Wl9j+dg7Yt8xAL67fpQ9iSggoSxy5xQJR wSfRcfgv3FM75j2BWqos8fHQIailkhLLL72GBrGHxKemXhZIEAdKtO3tZ5vAqDALEcqzkOyd hbB3ASPzKkax1ILi3PTUYqMCI3i8JufnbmIEpzcttx2MU95+0DvEyMTBeIhRgoNZSYT3XYhs ihBvSmJlVWpRfnxRaU5q8SFGU6CHJzJLiSbnAxNsXkm8oYmlgYmZmaG5kamBuZI4r7TtyWQh gfTEktTs1NSC1CKYPiYOTqkGppxrsWsTpI+zvrw805Dp4E7tc1+YNqU7NDCl7tzUc8f9UVue UOrMnXtdM/gbnv55ajhzn7zYH6FrxfdbE5cXzHBhDvX7N39PtstfobAQWYaPfVa+TKlm1hc0 vRxMuF43pt7luRo+iTfj9sZ9u7crztmr3+ftfNqTj63kmn7dnu2/9kjlBV2T/PX9ur3mFRcd kRd3Tmw989ZY6yaLem/6uRXqa3641DBzvwvfWfXu3r9UVQalne9yi6+5qP2aZStUHC7WO6Wg 8IrGa/XnT//Wtles/Cj4NGLtPhv7B1NWJy7KMX90sN95ZfWLGeerVyZNiHR6V5ZhbMXe0Gyo c597llSB5Kvbyw+XcDXnHBE6qsRSnJFoqMVcVJwIAPVSebL4AwAA DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230324083507epcms2p3fcf6bed459a8080dc7f179a3506b44ec References: Received-SPF: pass client-ip=203.254.224.24; envelope-from=minwoo.im@samsung.com; helo=mailout1.samsung.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: minwoo.im@samsung.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Minwoo Im Reviewed-by: Klaus Jensen --- hw/nvme/ctrl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 49c1210fce..fef5079a71 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -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: From patchwork Fri Mar 24 08:35:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1760804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=YEcOw3a7; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PjnkR3N0nz1yYM for ; Sat, 25 Mar 2023 03:30:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfkAL-0006mX-Aq; Fri, 24 Mar 2023 12:21:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfkAG-0006P8-LJ for qemu-devel@nongnu.org; Fri, 24 Mar 2023 12:21:17 -0400 Received: from mailout2.samsung.com ([203.254.224.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfkAE-0002Bq-Bz for qemu-devel@nongnu.org; Fri, 24 Mar 2023 12:21:16 -0400 Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230324083537epoutp02ee5845301486cf974b5a721ab06176c9~PTf2ttiZX1160111601epoutp02H for ; Fri, 24 Mar 2023 08:35:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230324083537epoutp02ee5845301486cf974b5a721ab06176c9~PTf2ttiZX1160111601epoutp02H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679646938; bh=Sq2JZy2YRQJkEfHMq/XSXWbUZoAaF09es+la+JKcsjI=; h=Subject:Reply-To:From:To:CC:Date:References:From; b=YEcOw3a730OTMEgAb2I8g3HATlBHSLsRghyX8ywUGSKXB1NkVe4f8VvSWhk88GNRP NWP0t+6i0nk9XTvl1pS9wxtDSISXq6Wrum82ZtBWo5ZwzPQ0DVb3ygy1xCVHJLlzbU V2XBca2S+JH+tUFjrIl/WBbXKV0yYfJYjoxTUwHk= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20230324083537epcas2p1fe64c45d05231127ffe6514832db52df~PTf2cHS7E2536225362epcas2p1f; Fri, 24 Mar 2023 08:35:37 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.36.68]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4PjbBd29ccz4x9Q5; Fri, 24 Mar 2023 08:35:37 +0000 (GMT) X-AuditID: b6c32a48-1f7ff70000021624-21-641d60d9140d Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 1C.84.05668.9D06D146; Fri, 24 Mar 2023 17:35:37 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH 2/2] hw/nvme: check maximum copy length (MCL) for COPY From: Minwoo Im To: "qemu-devel@nongnu.org" , "qemu-block@nongnu.org" CC: Klaus Birkelund Jensen , Minwoo Im X-Priority: 3 X-Content-Kind-Code: NORMAL X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20230324083536epcms2p2caa983827f96306c1ede1cabc900bfec@epcms2p2> Date: Fri, 24 Mar 2023 17:35:36 +0900 X-CMS-MailID: 20230324083536epcms2p2caa983827f96306c1ede1cabc900bfec X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKKsWRmVeSWpSXmKPExsWy7bCmqe7NBNkUg7ddAhYnG/ewWjw7fYDZ Yta7djaL4707WBxYPJ5c28zk0bdlFWMAU1S2TUZqYkpqkUJqXnJ+SmZeuq2Sd3C8c7ypmYGh rqGlhbmSQl5ibqqtkotPgK5bZg7QJiWFssScUqBQQGJxsZK+nU1RfmlJqkJGfnGJrVJqQUpO gXmBXnFibnFpXrpeXmqJlaGBgZEpUGFCdsbPNftYC87xVDy8vIStgXECZxcjJ4eEgInE+0Ud TF2MXBxCAjsYJVZ3X2fvYuTg4BUQlPi7QxikRljATWL5hpVgYSEBeYkfrwwgwpoS73afYQWx 2QTUJRqmvmIBsUUE0iRa9r0DizMLhElsPnOGHWIVr8SM9qcsELa0xPblWxkhbA2JH8t6mSFs UYmbq9+yw9jvj82HqhGRaL13FqpGUOLBz91QcSmJ/fPnQtnVEg3HnzFB2BUSv94/gKo3l/h9 fzfYPbwCvhL3F05iBnmFRUBV4nJfGESJi8S+018YIU6Wl9j+dg5YCTPQi+t36YOYEgLKEkdu sUBU8El0HP4L99SOeU+glipLfDx0CGqppMTyS6/ZIFo9JO4+iAEJCwkESsz7+45pAqPCLEQg z0KydhbC2gWMzKsYxVILinPTU4uNCkzg8Zqcn7uJEZzetDx2MM5++0HvECMTB+MhRgkOZiUR 3nchsilCvCmJlVWpRfnxRaU5qcWHGE2B/p3ILCWanA9MsHkl8YYmlgYmZmaG5kamBuZK4rzS tieThQTSE0tSs1NTC1KLYPqYODilGpgUl3KE5L6pKL34LZZpmTtzdc9fF7cTjW9P/gx6Jf/J wGwff5vzYe9pjE/SQ9ab1/E3bTVS+rLjiP0PrwV88/+KCm+8yhIsc+TxpgmHMlrqXX9ONJ64 XuHjm7l7ZffUZl9ZduicSurxZVdnWNnG3Xl2zCSxUSptk+a+c9Yhh1sWTJvxKBqo7EPWZin5 1yGbzC/f3+zsmv7wmHVhv+v294wd6ilL3uYGNQZu5JjU1DNTxVBN6anACZN64Ya+zX+7+vOT lrsnN73x2Hmcm8nCgtv77Y7EvyvSTzueF+nbeu223YYZH2z/rNSyzk5hPfxIqk//wuTm+Q/F 73UeEd9WcEfLfPIGlinr/+m9Xfx8f64SS3FGoqEWc1FxIgBkEve6+AMAAA== DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230324083536epcms2p2caa983827f96306c1ede1cabc900bfec References: Received-SPF: pass client-ip=203.254.224.25; envelope-from=minwoo.im@samsung.com; helo=mailout2.samsung.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: minwoo.im@samsung.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Klaus Jensen --- hw/nvme/ctrl.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index fef5079a71..b490bf4d3e 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -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;