From nobody Tue Feb 10 03:56:10 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770070577045270.02246034951145; Mon, 2 Feb 2026 14:16:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vn2Ab-0000qb-FH; Mon, 02 Feb 2026 17:13:21 -0500 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 1vn2AO-00087J-QI; Mon, 02 Feb 2026 17:13:08 -0500 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vn2AM-0003Uo-5P; Mon, 02 Feb 2026 17:13:08 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id DDBBA1852E2; Tue, 03 Feb 2026 01:07:37 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id BDFCC35B3F5; Tue, 03 Feb 2026 01:08:19 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Jeuk Kim , Michael Tokarev Subject: [Stable-10.2.1 53/56] hw/ufs: fix CQE endianness and UPIU length Date: Tue, 3 Feb 2026 01:07:58 +0300 Message-ID: <20260202220805.945271-53-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: 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=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1770070577494158500 Content-Type: text/plain; charset="utf-8" From: Jeuk Kim Round-trip UTRD fields through cpu_to_le/ le_to_cpu when building MCQ CQEs = to keep BE hosts correct. Also avoid double BE conversion of response data_segment_length and document the LE round-trip. Signed-off-by: Jeuk Kim (cherry picked from commit ed621cc8e2a6dab2663ffb02e875f896f521bee2) Signed-off-by: Michael Tokarev diff --git a/hw/ufs/lu.c b/hw/ufs/lu.c index 2d8ffd72c5..3f3c9589ce 100644 --- a/hw/ufs/lu.c +++ b/hw/ufs/lu.c @@ -53,8 +53,7 @@ static void ufs_build_scsi_response_upiu(UfsRequest *req,= uint8_t *sense, response =3D UFS_COMMAND_RESULT_FAIL; } =20 - data_segment_length =3D - cpu_to_be16(sense_len + sizeof(req->rsp_upiu.sr.sense_data_len)); + data_segment_length =3D sense_len + sizeof(req->rsp_upiu.sr.sense_data= _len); ufs_build_upiu_header(req, UFS_UPIU_TRANSACTION_RESPONSE, flags, respo= nse, status, data_segment_length); } diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index 58099a554e..128e2b1ea8 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -449,15 +449,24 @@ static void ufs_mcq_process_cq(void *opaque) { ufs_dma_write_rsp_upiu(req); =20 - req->cqe.utp_addr =3D - ((uint64_t)req->utrd.command_desc_base_addr_hi << 32ULL) | - req->utrd.command_desc_base_addr_lo; - req->cqe.utp_addr |=3D req->sq->sqid; - req->cqe.resp_len =3D req->utrd.response_upiu_length; - req->cqe.resp_off =3D req->utrd.response_upiu_offset; - req->cqe.prdt_len =3D req->utrd.prd_table_length; - req->cqe.prdt_off =3D req->utrd.prd_table_offset; - req->cqe.status =3D req->utrd.header.dword_2 & 0xf; + /* UTRD/CQE are LE; round-trip through host to keep BE correct. */ + uint64_t ucdba =3D + ((uint64_t)le32_to_cpu(req->utrd.command_desc_base_addr_hi) + << 32ULL) | + le32_to_cpu(req->utrd.command_desc_base_addr_lo); + uint16_t resp_len =3D le16_to_cpu(req->utrd.response_upiu_length); + uint16_t resp_off =3D le16_to_cpu(req->utrd.response_upiu_offset); + uint16_t prdt_len =3D le16_to_cpu(req->utrd.prd_table_length); + uint16_t prdt_off =3D le16_to_cpu(req->utrd.prd_table_offset); + uint8_t status =3D le32_to_cpu(req->utrd.header.dword_2) & UFS_MAS= K_OCS; + + ucdba |=3D req->sq->sqid; + req->cqe.utp_addr =3D cpu_to_le64(ucdba); + req->cqe.resp_len =3D cpu_to_le16(resp_len); + req->cqe.resp_off =3D cpu_to_le16(resp_off); + req->cqe.prdt_len =3D cpu_to_le16(prdt_len); + req->cqe.prdt_off =3D cpu_to_le16(prdt_off); + req->cqe.status =3D status; req->cqe.error =3D 0; =20 ret =3D ufs_addr_write(u, cq->addr + tail, &req->cqe, sizeof(req->= cqe)); diff --git a/include/block/ufs.h b/include/block/ufs.h index a3ee62b027..22dc379eaa 100644 --- a/include/block/ufs.h +++ b/include/block/ufs.h @@ -645,7 +645,7 @@ enum UtpOcsCodes { }; =20 enum { - UFS_MASK_OCS =3D 0x0F, + UFS_MASK_OCS =3D 0xFF, }; =20 /* --=20 2.47.3