From nobody Tue Feb 10 01:35:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1614608580; cv=none; d=zohomail.com; s=zohoarc; b=RUkk0NzHsyYRVkUHej2yNUqmkrPzRTJ9OiQoSwy+wwIxib8DKPcXLa6igH6u8iLDZw0J4M8Zf/rd7S4Rf0vAULLSxUiQlfL+2f8uLY0ykeWOWzoElfOybqddMSsrBpk262V5vAxgJyJJmvAR4CjHPyCxOXn38Q1nGZ06u4gl0d0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614608580; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mRjXjRrlLaBvs/y3e9khv99zS4LcfbmbHcKA/41XJFk=; b=LkxhQb5xuYnZzPY3HIMM6JINRWxpw5KlfhojtYnA4sH3EjfJAR+DuE3/EHG1gr+IUtJaARdDBnQqrR93KRUqzm31BZkhfRuJohwCqG4vNB19//Wwtn3dRMrlEh+TVVxH7VyP4JrCylyUls7wiBOqGPvkgAQen1JKwuiwdkRdVUs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614608580105151.26392695769766; Mon, 1 Mar 2021 06:23:00 -0800 (PST) Received: from localhost ([::1]:43852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGjRq-0001D1-N4 for importer@patchew.org; Mon, 01 Mar 2021 09:22:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGj6h-0002Da-Fi; Mon, 01 Mar 2021 09:01:07 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:51777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGj6a-000409-Fc; Mon, 01 Mar 2021 09:01:07 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4D37A5C0153; Mon, 1 Mar 2021 09:00:58 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 01 Mar 2021 09:00:58 -0500 Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id E6E701080069; Mon, 1 Mar 2021 09:00:56 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=mRjXjRrlLaBvs /y3e9khv99zS4LcfbmbHcKA/41XJFk=; b=FgEu+6Rq9LmZ7HpV5CM8mWf+RcEgD OQIl/lqS1DEoANtqPHy+v6taVQZiH/h8QNqrFXrSjNcHgZ2kZh0Nr3QMQ4fkHQeJ LVD5KadeOpMbseTLsqYkgOztvDSmiYC0mZ8Ljr1HsAwz/cSgOxOX1bf9aD73nQRY ZpZ+o3c+tNJ0cOKFmuWBb2D9O1tQ7213XV+l/uT6v1+avQfGuTFBoYDYQzoq+oXl CTtCHie1bAuHChsSuBAXpjQR47RrYGrFVz1oXNbrMNvHdt7l3kAWQYQuVhNdoNlO AYhXBsnINy3qq2zWJ4ENPiEmwaYGe+vN0qzWZRjT/eDXRcjRhKrzJNcUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=mRjXjRrlLaBvs/y3e9khv99zS4LcfbmbHcKA/41XJFk=; b=A6Fe3mit wenRMndWm3pf2TXO16abMKUnBzUitUtKnU1Wb8hhRZtPdSnNQTR48EJ5HT7cgULV EWKh41mZb7LDtVZyMlHWw0LiOc0ISy7GXmTtfAClj/Ssd5FTqTzFQZYJmYuz5j6Z B3+r2SzuhxuK4heiNC33x1N+0RBcDVywGvtxMg9n8MCyH+po4+BkOMwMpRVkL1YC vyBDmE0thjGkAr1X87P8BDJEBoJNPTZqgM57YA0EgUsgkF5SibXLRohU6T2Z/0uU ehemkPFoEwjHhFvsAjjrRG26jmVlKs2yxm3xpsrT1DnyPAaAWc82e+537pcKH/WA qLUm1P2rGZ2l6w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrleekgdehjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghushcu lfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrthhtvg hrnhepueelteegieeuhffgkeefgfevjeeigfetkeeitdfgtdeifefhtdfhfeeuffevgfek necukfhppeektddrudeijedrleekrdduledtnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH v4 05/12] hw/block/nvme: remove the req dependency in map functions Date: Mon, 1 Mar 2021 15:00:40 +0100 Message-Id: <20210301140047.106261-6-its@irrelevant.dk> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301140047.106261-1-its@irrelevant.dk> References: <20210301140047.106261-1-its@irrelevant.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.25; envelope-from=its@irrelevant.dk; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Gollu Appalanaidu , Max Reitz , Klaus Jensen , Stefan Hajnoczi , Keith Busch Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Klaus Jensen The PRP and SGL mapping functions does not have any particular need for the entire NvmeRequest as a parameter. Clean it up. Signed-off-by: Klaus Jensen Reviewed-by: Keith Busch --- hw/block/nvme.c | 61 ++++++++++++++++++++++--------------------- hw/block/trace-events | 4 +-- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index ae411f04752b..fda2d480cb66 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -535,8 +535,8 @@ static inline bool nvme_addr_is_dma(NvmeCtrl *n, hwaddr= addr) return !(nvme_addr_is_cmb(n, addr) || nvme_addr_is_pmr(n, addr)); } =20 -static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1, uint64_t prp2, - uint32_t len, NvmeRequest *req) +static uint16_t nvme_map_prp(NvmeCtrl *n, NvmeSg *sg, uint64_t prp1, + uint64_t prp2, uint32_t len) { hwaddr trans_len =3D n->page_size - (prp1 % n->page_size); trans_len =3D MIN(len, trans_len); @@ -546,9 +546,9 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1= , uint64_t prp2, =20 trace_pci_nvme_map_prp(trans_len, len, prp1, prp2, num_prps); =20 - nvme_sg_init(n, &req->sg, nvme_addr_is_dma(n, prp1)); + nvme_sg_init(n, sg, nvme_addr_is_dma(n, prp1)); =20 - status =3D nvme_map_addr(n, &req->sg, prp1, trans_len); + status =3D nvme_map_addr(n, sg, prp1, trans_len); if (status) { goto unmap; } @@ -598,7 +598,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1= , uint64_t prp2, } =20 trans_len =3D MIN(len, n->page_size); - status =3D nvme_map_addr(n, &req->sg, prp_ent, trans_len); + status =3D nvme_map_addr(n, sg, prp_ent, trans_len); if (status) { goto unmap; } @@ -612,7 +612,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1= , uint64_t prp2, status =3D NVME_INVALID_PRP_OFFSET | NVME_DNR; goto unmap; } - status =3D nvme_map_addr(n, &req->sg, prp2, len); + status =3D nvme_map_addr(n, sg, prp2, len); if (status) { goto unmap; } @@ -622,7 +622,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1= , uint64_t prp2, return NVME_SUCCESS; =20 unmap: - nvme_sg_unmap(&req->sg); + nvme_sg_unmap(sg); return status; } =20 @@ -632,7 +632,7 @@ unmap: */ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor *segment, uint64_t nsg= ld, - size_t *len, NvmeRequest *req) + size_t *len, NvmeCmd *cmd) { dma_addr_t addr, trans_len; uint32_t dlen; @@ -643,7 +643,7 @@ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, NvmeSg *= sg, =20 switch (type) { case NVME_SGL_DESCR_TYPE_BIT_BUCKET: - if (req->cmd.opcode =3D=3D NVME_CMD_WRITE) { + if (cmd->opcode =3D=3D NVME_CMD_WRITE) { continue; } case NVME_SGL_DESCR_TYPE_DATA_BLOCK: @@ -672,7 +672,7 @@ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, NvmeSg *= sg, break; } =20 - trace_pci_nvme_err_invalid_sgl_excess_length(nvme_cid(req)); + trace_pci_nvme_err_invalid_sgl_excess_length(dlen); return NVME_DATA_SGL_LEN_INVALID | NVME_DNR; } =20 @@ -701,7 +701,7 @@ next: } =20 static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sg= l, - size_t len, NvmeRequest *req) + size_t len, NvmeCmd *cmd) { /* * Read the segment in chunks of 256 descriptors (one 4k page) to avoid @@ -722,7 +722,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, N= vmeSglDescriptor sgl, sgld =3D &sgl; addr =3D le64_to_cpu(sgl.addr); =20 - trace_pci_nvme_map_sgl(nvme_cid(req), NVME_SGL_TYPE(sgl.type), len); + trace_pci_nvme_map_sgl(NVME_SGL_TYPE(sgl.type), len); =20 nvme_sg_init(n, sg, nvme_addr_is_dma(n, addr)); =20 @@ -731,7 +731,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, N= vmeSglDescriptor sgl, * be mapped directly. */ if (NVME_SGL_TYPE(sgl.type) =3D=3D NVME_SGL_DESCR_TYPE_DATA_BLOCK) { - status =3D nvme_map_sgl_data(n, sg, sgld, 1, &len, req); + status =3D nvme_map_sgl_data(n, sg, sgld, 1, &len, cmd); if (status) { goto unmap; } @@ -770,7 +770,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, N= vmeSglDescriptor sgl, } =20 status =3D nvme_map_sgl_data(n, sg, segment, SEG_CHUNK_SIZE, - &len, req); + &len, cmd); if (status) { goto unmap; } @@ -796,7 +796,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, N= vmeSglDescriptor sgl, switch (NVME_SGL_TYPE(last_sgld->type)) { case NVME_SGL_DESCR_TYPE_DATA_BLOCK: case NVME_SGL_DESCR_TYPE_BIT_BUCKET: - status =3D nvme_map_sgl_data(n, sg, segment, nsgld, &len, req); + status =3D nvme_map_sgl_data(n, sg, segment, nsgld, &len, cmd); if (status) { goto unmap; } @@ -823,7 +823,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, N= vmeSglDescriptor sgl, * Do not map the last descriptor; it will be a Segment or Last Se= gment * descriptor and is handled by the next iteration. */ - status =3D nvme_map_sgl_data(n, sg, segment, nsgld - 1, &len, req); + status =3D nvme_map_sgl_data(n, sg, segment, nsgld - 1, &len, cmd); if (status) { goto unmap; } @@ -843,24 +843,20 @@ unmap: return status; } =20 -static uint16_t nvme_map_dptr(NvmeCtrl *n, size_t len, NvmeRequest *req) +static uint16_t nvme_map_dptr(NvmeCtrl *n, NvmeSg *sg, size_t len, + NvmeCmd *cmd) { uint64_t prp1, prp2; =20 - switch (NVME_CMD_FLAGS_PSDT(req->cmd.flags)) { + switch (NVME_CMD_FLAGS_PSDT(cmd->flags)) { case NVME_PSDT_PRP: - prp1 =3D le64_to_cpu(req->cmd.dptr.prp1); - prp2 =3D le64_to_cpu(req->cmd.dptr.prp2); + prp1 =3D le64_to_cpu(cmd->dptr.prp1); + prp2 =3D le64_to_cpu(cmd->dptr.prp2); =20 - return nvme_map_prp(n, prp1, prp2, len, req); + return nvme_map_prp(n, sg, prp1, prp2, len); case NVME_PSDT_SGL_MPTR_CONTIGUOUS: case NVME_PSDT_SGL_MPTR_SGL: - /* SGLs shall not be used for Admin commands in NVMe over PCIe */ - if (!req->sq->sqid) { - return NVME_INVALID_FIELD | NVME_DNR; - } - - return nvme_map_sgl(n, &req->sg, req->cmd.dptr.sgl, len, req); + return nvme_map_sgl(n, sg, cmd->dptr.sgl, len, cmd); default: return NVME_INVALID_FIELD; } @@ -871,7 +867,7 @@ static uint16_t nvme_dma(NvmeCtrl *n, uint8_t *ptr, uin= t32_t len, { uint16_t status =3D NVME_SUCCESS; =20 - status =3D nvme_map_dptr(n, len, req); + status =3D nvme_map_dptr(n, &req->sg, len, &req->cmd); if (status) { return status; } @@ -2086,7 +2082,7 @@ static uint16_t nvme_read(NvmeCtrl *n, NvmeRequest *r= eq) } } =20 - status =3D nvme_map_dptr(n, data_size, req); + status =3D nvme_map_dptr(n, &req->sg, data_size, &req->cmd); if (status) { goto invalid; } @@ -2175,7 +2171,7 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeReques= t *req, bool append, data_offset =3D nvme_l2b(ns, slba); =20 if (!wrz) { - status =3D nvme_map_dptr(n, data_size, req); + status =3D nvme_map_dptr(n, &req->sg, data_size, &req->cmd); if (status) { goto invalid; } @@ -3850,6 +3846,11 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequ= est *req) return NVME_INVALID_OPCODE | NVME_DNR; } =20 + /* SGLs shall not be used for Admin commands in NVMe over PCIe */ + if (NVME_CMD_FLAGS_PSDT(req->cmd.flags) !=3D NVME_PSDT_PRP) { + return NVME_INVALID_FIELD | NVME_DNR; + } + switch (req->cmd.opcode) { case NVME_ADM_CMD_DELETE_SQ: return nvme_del_sq(n, req); diff --git a/hw/block/trace-events b/hw/block/trace-events index 25ba51ea5405..51d94b9ddfe8 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -37,7 +37,7 @@ pci_nvme_dma_read(uint64_t prp1, uint64_t prp2) "DMA read= , prp1=3D0x%"PRIx64" prp2 pci_nvme_map_addr(uint64_t addr, uint64_t len) "addr 0x%"PRIx64" len %"PRI= u64"" pci_nvme_map_addr_cmb(uint64_t addr, uint64_t len) "addr 0x%"PRIx64" len %= "PRIu64"" pci_nvme_map_prp(uint64_t trans_len, uint32_t len, uint64_t prp1, uint64_t= prp2, int num_prps) "trans_len %"PRIu64" len %"PRIu32" prp1 0x%"PRIx64" pr= p2 0x%"PRIx64" num_prps %d" -pci_nvme_map_sgl(uint16_t cid, uint8_t typ, uint64_t len) "cid %"PRIu16" t= ype 0x%"PRIx8" len %"PRIu64"" +pci_nvme_map_sgl(uint8_t typ, uint64_t len) "type 0x%"PRIx8" len %"PRIu64"" pci_nvme_io_cmd(uint16_t cid, uint32_t nsid, uint16_t sqid, uint8_t opcode= , const char *opname) "cid %"PRIu16" nsid %"PRIu32" sqid %"PRIu16" opc 0x%"= PRIx8" opname '%s'" pci_nvme_admin_cmd(uint16_t cid, uint16_t sqid, uint8_t opcode, const char= *opname) "cid %"PRIu16" sqid %"PRIu16" opc 0x%"PRIx8" opname '%s'" pci_nvme_flush(uint16_t cid, uint32_t nsid) "cid %"PRIu16" nsid %"PRIu32"" @@ -124,7 +124,7 @@ pci_nvme_err_aio(uint16_t cid, const char *errname, uin= t16_t status) "cid %"PRIu pci_nvme_err_copy_invalid_format(uint8_t format) "format 0x%"PRIx8"" pci_nvme_err_invalid_sgld(uint16_t cid, uint8_t typ) "cid %"PRIu16" type 0= x%"PRIx8"" pci_nvme_err_invalid_num_sgld(uint16_t cid, uint8_t typ) "cid %"PRIu16" ty= pe 0x%"PRIx8"" -pci_nvme_err_invalid_sgl_excess_length(uint16_t cid) "cid %"PRIu16"" +pci_nvme_err_invalid_sgl_excess_length(uint32_t residual) "residual %"PRIu= 32"" pci_nvme_err_invalid_dma(void) "PRP/SGL is too small for transfer size" pci_nvme_err_invalid_prplist_ent(uint64_t prplist) "PRP list entry is not = page aligned: 0x%"PRIx64"" pci_nvme_err_invalid_prp2_align(uint64_t prp2) "PRP2 is not page aligned: = 0x%"PRIx64"" --=20 2.30.1