From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348236; cv=none; d=zohomail.com; s=zohoarc; b=fN7DhE2VDPxBY1AWYccwCjcuwNc7kH34BKvSs5dIxsym1HYMlqjRRMhK2cUijiYEF5q3uC86UPdo8BOqIGt8z6cB9IYBdPe0QOSZivE5jEO/aGjNCUFM8QoNfcf0/1Da2SPkweRoss8An8CEjMCxQ6hhQovcwIU6q4uX3PjtXWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348236; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1G58KDvPaxDf1pbDbbJqX1WIkHSLAs8rb9t3XK2KfZY=; b=hJHCQ47wwSyQCNM87WjAs63vNqBm8tzfM6vnasPmbfJFgGKI2NRBqYtr1MA6PI7YBsS+Azu2twawmcwo6/fPuV7yxZAXP9FAIW3cwAPj1vLcoKvcsALJBiKE0srXUYq+dNzjo1YyeGwCH6avKtCmCtcrRKh4FLALit9F8s7B3rQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348236083155.74372969945682; Fri, 30 Oct 2026 01:17:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhlV-0006F6-Io; Fri, 30 Oct 2026 04:15:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlO-00069v-V7 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:05 -0400 Received: from mail-dl1-x1231.google.com ([2607:f8b0:4864:20::1231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlM-0001Mb-VD for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:02 -0400 Received: by mail-dl1-x1231.google.com with SMTP id a92af1059eb24-18cdcfc05ffso548837c88.1 for ; Fri, 30 Oct 2026 01:15:00 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348099; x=1793952899; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1G58KDvPaxDf1pbDbbJqX1WIkHSLAs8rb9t3XK2KfZY=; b=V1QdWjNq2DIszNRvb4uD+SkbCjIDTJBuU64KZyYO8hkabH6X8ZIV1wDdZvtFhkjW2u 8tMez2wIqVIfXFxMUTQKqRv+EmHKl5q2yLt7HKx5RCbpzUms8KCZjTO+GjVr+jEZFaV5 Oz51hrXqnAWWSx9JDLjn+pDBhhVVg0H3GX44zJxMrsBq3CD0KWAIhrmj5uG4Oo5b9zDI no773pzso6v0nsQfHP0x3xCKEoLYvMzy9L1pt9fWpq9xgUlVVBHmffrdE0QNXSH29Vas lCL8QhYbbCJbhyio5mSVsA3y/D8MpBQrlhYJVyJE9BApvL+iGxf+8BHF2UAQnIY++oNZ HxIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348099; x=1793952899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1G58KDvPaxDf1pbDbbJqX1WIkHSLAs8rb9t3XK2KfZY=; b=1RQRsbmD+4gUQb2nLu9MUpfX+klX+Ml/MLTlGBqOGOf7xb9CZJN4lokgKGuFCQnjfB Mr/zMxUNauBUlunsKbutgGTcHyPkwFuODSRN9Oc2V4M5qdr2V9Cx0iyZXIvOTZLFbTt1 dAufuLYwBocuGhIur/S6dwnJuDSQ2Ue0dnXju3MHipcVDhsHNkXNAVhJMbu3PCwfa6uv IoT9i2dxQOynZgmKbbSefKYz+Ne6PCZ8AKH+NLQWZjgABT9omWK2vi1ptwJb/C1fMQO5 JBAwVHBMHcAx7TlulK8kTa5ZNPRdvZXlUnEvM5sOjVup0YXK0AAwPwvLEl9vMvDzQtk9 /9WQ== X-Gm-Message-State: AFq9FYLkKUF/Lko1KlYbzrMaEkqyW0/WhifOKlmTFhxiUFHNNNjvWrUo LUOq7sAtPAfNlZhZsKViHsRyqL5tnZwtvhgAt8jgy4iXcodC7Y0CjDvO/lgW9w== X-Gm-Gg: AYBFou0Uyn4iNBNGBUBbUKTfIyfaKCK/1CkemX+TrH0bSf6QcM1xgQauLuBwk11tFrI ak7xTT3oiOiOfGjR03Cr4eoJiouUMZsu94Q5bbhd+ezv97FXuUwMtIbRMEkDrtj2La2UMIF63nE jkm1S2kAABNFAVZs/8nbHn8vQs4SDS2IB4GwLHXXgOvLlcINMEezcyx3vrGxpVop7aZfIZenK99 tjLsCornhyEgvntyGpAtLzIlNUVH9nhM0lalWD5Xp6AZDZRywrBTJiCgBBLDTWkIGGQwVNKUFLx l2fR5tNsOcF7khW/C0D6UtORbD/UNtL9KqRutd9skEEL5Dw+E5qHo4eftOoll4nwg+YtoWFowvM JaAOI4qBnuOlyhjHU3TL/D4XroNIPax4lEmVFbJPWBgvnOafkv6HltaPUITqiHERT3Q4GZEzgjn Vp5XihsbPLLDXyFHreTm8fcUz/qyzpD6ac31KTn/VhlRmNQ7t0o3HGpRT1ZA/I4k+jrio6nqbUN HxCenm9153fSM5NOyHvoP3cT03UF93v6NDPPHBF7ejzT+pMuSygomGn5HBFDfv8dIxEC4PfrpCS BgplENb/Wecrf2i3hcyJnbCXyzeB0DD6Wd15IFwxD1u6IYZ3oHXOKiSju5/Oo921Cg== X-Received: by 2002:a05:7022:5f0b:b0:168:3243:c91a with SMTP id a92af1059eb24-1ac5bbb966fmr2250904c88.13.1793348099282; Fri, 30 Oct 2026 01:14:59 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 01/12] hw/ufs: Add support for REPORT_LUNS SCSI command for Well Known LUNs Date: Fri, 30 Oct 2026 17:14:27 +0900 Message-ID: <397086dd554e75fca27ac7b9ff9b5c51818fdf62.1793347487.git.jeuk20.kim@samsung.com> X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1231; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1231.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348236590158500 Content-Type: text/plain; charset="utf-8" From: dridiha According to the UFS specification, the REPORT_LUNS SCSI command can query Well Known LUNs by setting CDB[2] to 0x01 (select Well Known LUNs) or 0x02 (select all LUNs). Currently, the UFS emulation layer lacks handling for these CDB[2] select report values, causing command failures when guests attempt to report Well Known LUNs. This patch adds support for handling CDB[2] values 0x01 and 0x02 in the REPORT_LUNS command, returning the appropriate Well Known LUN descriptors in the SCSI response payload. Signed-off-by: Hamza Dridi Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/lu.c | 44 ++++++++++++++++++++++++++++++++++---------- include/block/ufs.h | 3 +++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/hw/ufs/lu.c b/hw/ufs/lu.c index 5905c49fac9..ee4bb75361c 100644 --- a/hw/ufs/lu.c +++ b/hw/ufs/lu.c @@ -218,33 +218,57 @@ static const struct SCSIBusInfo ufs_scsi_info =3D { .cancel =3D ufs_scsi_command_cancelled, }; =20 +static bool ufs_append_lun(uint8_t *outbuf, uint32_t outbuf_len, int *len, + uint8_t lun, uint8_t lun_msb) +{ + if (*len + 8 > outbuf_len) { + return false; + } + + memset(outbuf + *len, 0, 8); + outbuf[*len] =3D lun_msb; + outbuf[*len + 1] =3D lun; + *len +=3D 8; + + return true; +} + static int ufs_emulate_report_luns(UfsRequest *req, uint8_t *outbuf, uint32_t outbuf_len) { UfsHc *u =3D req->hc; int len =3D 0; =20 - /* TODO: Support for cases where SELECT REPORT is 1 and 2 */ - if (req->req_upiu.sc.cdb[2] !=3D 0) { + uint8_t report_lun_cmd =3D req->req_upiu.sc.cdb[2]; + + if (report_lun_cmd > 2) { return SCSI_COMMAND_FAIL; } =20 if (outbuf_len < 8) { return SCSI_COMMAND_FAIL; } + memset(outbuf, 0, 8); len +=3D 8; =20 - for (uint8_t lun =3D 0; lun < UFS_MAX_LUS; ++lun) { - if (u->lus[lun]) { - if (len + 8 > outbuf_len) { + if (report_lun_cmd =3D=3D 2 || report_lun_cmd =3D=3D 1) { + ufs_append_lun(outbuf, outbuf_len, &len, u->report_wlu.lun & 0x7F, + UFS_WLUN_MSB); + ufs_append_lun(outbuf, outbuf_len, &len, u->dev_wlu.lun & 0x7F, + UFS_WLUN_MSB); + ufs_append_lun(outbuf, outbuf_len, &len, u->boot_wlu.lun & 0x7F, + UFS_WLUN_MSB); + ufs_append_lun(outbuf, outbuf_len, &len, u->rpmb_wlu.lun & 0x7F, + UFS_WLUN_MSB); + } + + if (report_lun_cmd =3D=3D 0 || report_lun_cmd =3D=3D 2) { + for (uint8_t lun =3D 0; lun < UFS_MAX_LUS; ++lun) { + if (u->lus[lun] && + !ufs_append_lun(outbuf, outbuf_len, &len, lun, 0)) { break; } - - memset(outbuf + len, 0, 8); - outbuf[len] =3D 0; - outbuf[len + 1] =3D lun; - len +=3D 8; } } =20 diff --git a/include/block/ufs.h b/include/block/ufs.h index 4a614fbe526..f4a3371bcea 100644 --- a/include/block/ufs.h +++ b/include/block/ufs.h @@ -835,6 +835,9 @@ typedef struct QEMU_PACKED UtpTaskReqDesc { */ #define UFS_EHS_OFFSET_IN_RESPONSE 32 =20 +/* Most significant byte in the Report Lun response for Well Known LU */ +#define UFS_WLUN_MSB 0xC1 + /* Well known logical unit id in LUN field of UPIU */ enum { UFS_UPIU_REPORT_LUNS_WLUN =3D 0x81, --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348144; cv=none; d=zohomail.com; s=zohoarc; b=I+gML3WNKFVg2xO5Q2tzGhVKbHHKgzoudbF2Bg67ZAKB+XWt23zhIa8R5h9g55rBSBuUD5lSdCGCjbY0api/Mg/ioz+lHlC5DUJRpTbx1TxgwkNqWOwgnP2fLTfGM530HhZDicTKJoLGMWkFjTExN2lCgsU9F4V9yFojXmoWOUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348144; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lrpLvY4y/DVxVCVbGZK+Hu379grYqQp9XaOoVPBLZtY=; b=JbN9MLvdixgBihJUSWm4JG7+CU848yJDtjoxXAA3DbjaITjOtKqRWFDaua/OlCJtaDVmm4EytCz2nMxmB10dFTMsyOG54hdzNHl8DrOEMOZ+B2fuKxgIU5YIOSryXfjHh+YdBWlpHTdqxzux1CbJdJeGhqS5syMJfLmckXruaks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348144527794.3615839390778; Fri, 30 Oct 2026 01:15:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhli-0006Mj-Qn; Fri, 30 Oct 2026 04:15:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlT-0006D0-0h for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:07 -0400 Received: from mail-dl1-x1233.google.com ([2607:f8b0:4864:20::1233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlQ-0001NO-8I for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:06 -0400 Received: by mail-dl1-x1233.google.com with SMTP id a92af1059eb24-14fc585291cso328345c88.1 for ; Fri, 30 Oct 2026 01:15:03 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348103; x=1793952903; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lrpLvY4y/DVxVCVbGZK+Hu379grYqQp9XaOoVPBLZtY=; b=pbIPBgokcwsgvtW4bIhrc73ODJ9lFCIeBe6W1B9a4Kynb/5dXR5NZy1y+gzwG4+jE0 j2Y/o4ggjzU7DBpK4klXMLUHNkV1LpTqIqm4hxmLWVX8hFdPG3vKDkeJXWBVlL7oBsBv FwXJYalryc3JH47YMmsyUBAZJMbANSt+pNtjPIU0pxI2KPtGke+uU9/oEsklr+XlUs+P mbTI3xJ0XLY2FUtzm5+MQTEw/dYJhGBWOxMsM8i1OX9SGenGyL2Dl+vmjW8/syWuIMLi 9nX9rXdBU9nww+ThnfpPALPNEttLUR/wFUACrBhivd9cYOwFFnV9kDnYbgYPM2urwur3 FAig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348103; x=1793952903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lrpLvY4y/DVxVCVbGZK+Hu379grYqQp9XaOoVPBLZtY=; b=HHI50DkCT0zAAi2AZ/F5dn8vdxoBAbSvsI+LdunzuklIqexKV2y/vIFuEsA3zM3TT3 nVwmfjQDrzn7cM0DbL8oCW3cwk4XjVl7Eqad48cXdQGbydUoh+nqGM5mbfHix+ZwwyXq Rd+VgWjJUVQcyrvma33Ugbq7fOPj0cTP5GxDAOKTVKejZzeIeY5kVfSv1ad59dRecYae GQWGsqNqLIpua7Y3fMEYpkfmgpBGZCN+3XphlVM0R5O+Wb3C9QmwFK9U2RHlt+gIgpF7 HacYGF61GR5+ngr6wcRf0MNMe/2hJvkRhjcxspyZiAL67J9Z1JYG+XP17eDDF/+pYQmk /qUQ== X-Gm-Message-State: AFq9FYK/woyh2u/J8Bq1pzPDc7Lp1qpsaPvryJZAAeQ8gEQNTfq1H0+u GrpD5LW3elEt6LBACANADPl5XjVZsL/oyYqCM2byaAQHE55Dn1otnNP7sx6coQ== X-Gm-Gg: AYBFou3WXCIPOhWgEKb7iDNUM5+oN2nYpYrWMDeZ7pOswiS+uezlS45KkuURRbrn9do wrl/EvmPgeoQzuN75Vx+XU1AbSGaoesBUO28iXozvEcNs8KodDEkqEMR56F/xhvd2IYkpUK7F7h 3RrUsUFBeMH6Ry5TKvh88clSFFSAhSxz2E4/Si9I7kXISPGiB1CawAgyfChsGuOXoIXGnP0PDuS b8F5D0e/e1dEPMEa2BlvFm1SzicsAzZpzghNyx/HfLy5IYNuLcHzZfrEfs1GPOGQhsQkx934/9f 23zkcvXLl86S+a+g8Aes2t8JOheXjmbz01y8IK7Kz02WShZ7manmBcodCNqTAGAhDqc/HiXTjWo BwpSQvWuT1pRqitEnzpgaLQ1hF5XWdhFuyNHW/IZxCvkYJNIbhnS6Irl7+o6Czo/61k3RrJx/JW nXa/W9OeuoWtAuODfDWFcMrB2vqp+8XYwW3nv6ow5Qzhna6Llkiwn2S98ev3pgN0PpWlYUODIaG Y+01Ya/Ju0DeRsUglAO0jGufdc+1xFzVlP82EtObqkJzIj2J9FdeiD05EftpCLExDjCgB+ublZh XasxQWIPc6uzhZ+YOuTwLoVIQAhzxe2gA3bf/O51Z6Guw+m2S3L77G5iYL77PKrTkw== X-Received: by 2002:a05:701b:2051:20b0:151:8280:2c1a with SMTP id a92af1059eb24-1ac5e8e1dfemr2146900c88.42.1793348102504; Fri, 30 Oct 2026 01:15:02 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com, qemu-stable@nongnu.org Subject: [PULL 02/12] hw/ufs: Fail SCSI commands that move data without a PRDT Date: Fri, 30 Oct 2026 17:14:28 +0900 Message-ID: <4992210c844592663e8f3265cd4ff47c0bf03d6f.1793347487.git.jeuk20.kim@samsung.com> X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1233; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1233.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348146280154100 Content-Type: text/plain; charset="utf-8" From: Daejun Park A command whose CDB transfers data, sent with a PRDT length of 0, reaches scsi-hd without an SG list. The SCSI layer then calls the transfer_data callback of the bus, which ufs_scsi_info does not set, and QEMU dies with SIGSEGV. A guest triggers this with, for example, an INQUIRY whose PRDT is empty; the new no-prdt qtest crashed QEMU before this change. Check the transfer direction that scsi_req_new() parsed, and fail such a command with OCS MISMATCH DATA BUFFER SIZE before it reaches scsi-hd: the PRDT describes less data than the command moves. virtio-scsi likewise fails a command that has no matching buffer (VIRTIO_SCSI_S_OVERRUN). A request that only reports a pending unit attention moves no data and goes through, so that the guest still sees the unit attention. Handing scsi-hd an empty SG list instead is not enough: READ and WRITE then complete synchronously in dma_blk_io() and trip the assertion in scsi_dma_complete(). Fixes: 2a8b36a4967d ("hw/ufs: Support for UFS logical unit") Cc: qemu-stable@nongnu.org Signed-off-by: Daejun Park Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/lu.c | 24 ++++++++++++++++++---- hw/ufs/ufs.c | 10 ++++++++-- hw/ufs/ufs.h | 2 ++ tests/qtest/ufs-test.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 6 deletions(-) diff --git a/hw/ufs/lu.c b/hw/ufs/lu.c index ee4bb75361c..1101e368734 100644 --- a/hw/ufs/lu.c +++ b/hw/ufs/lu.c @@ -406,6 +406,8 @@ static UfsReqResult ufs_emulate_scsi_cmd(UfsLu *lu, Ufs= Request *req) static UfsReqResult ufs_process_scsi_cmd(UfsLu *lu, UfsRequest *req) { uint8_t task_tag =3D req->req_upiu.header.task_tag; + SCSIRequest *scsi_req; + uint32_t len; =20 /* * Each ufs-lu has its own independent virtual SCSI bus. Therefore, we= can't @@ -417,12 +419,26 @@ static UfsReqResult ufs_process_scsi_cmd(UfsLu *lu, U= fsRequest *req) return ufs_emulate_scsi_cmd(lu, req); } =20 - SCSIRequest *scsi_req =3D - scsi_req_new(lu->scsi_dev, task_tag, lu->lun, req->req_upiu.sc.cdb, - UFS_CDB_SIZE, req); + scsi_req =3D scsi_req_new(lu->scsi_dev, task_tag, lu->lun, + req->req_upiu.sc.cdb, UFS_CDB_SIZE, req); + + /* + * A command that moves data needs a PRDT. Without one there is no SG + * list, and the SCSI layer would call the transfer_data callback, whi= ch + * ufs-lu does not set. Fail the request with OCS MISMATCH DATA BUFFER + * SIZE, as virtio-scsi fails a buffer that does not match the command. + * A request that reports a pending unit attention instead moves no da= ta; + * its sense is already set, so let it through and the guest sees the = UA. + */ + if (scsi_req->cmd.mode !=3D SCSI_XFER_NONE && !req->sg && + !scsi_req->sense_len) { + scsi_req_unref(scsi_req); + return UFS_REQUEST_MISMATCH_DATA_BUF; + } + req->sreq =3D scsi_req; =20 - uint32_t len =3D scsi_req_enqueue(scsi_req); + len =3D scsi_req_enqueue(scsi_req); if (len) { scsi_req_continue(scsi_req); } diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index f008af7467e..dda615da7ce 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -2451,10 +2451,16 @@ void ufs_complete_req(UfsRequest *req, UfsReqResult= req_result) UfsHc *u =3D req->hc; assert(req->state =3D=3D UFS_REQUEST_RUNNING); =20 - if (req_result =3D=3D UFS_REQUEST_SUCCESS) { + switch (req_result) { + case UFS_REQUEST_SUCCESS: req->utrd.header.dword_2 =3D cpu_to_le32(UFS_OCS_SUCCESS); - } else { + break; + case UFS_REQUEST_MISMATCH_DATA_BUF: + req->utrd.header.dword_2 =3D cpu_to_le32(UFS_OCS_MISMATCH_DATA_BUF= _SIZE); + break; + default: req->utrd.header.dword_2 =3D cpu_to_le32(UFS_OCS_INVALID_CMD_TABLE= _ATTR); + break; } =20 req->state =3D UFS_REQUEST_COMPLETE; diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h index 265a43faaa6..adf74b6833d 100644 --- a/hw/ufs/ufs.h +++ b/hw/ufs/ufs.h @@ -47,6 +47,8 @@ typedef enum UfsReqResult { UFS_REQUEST_SUCCESS =3D 0, UFS_REQUEST_FAIL =3D 1, UFS_REQUEST_NO_COMPLETE =3D 2, + /* The PRDT describes less data than the command moves */ + UFS_REQUEST_MISMATCH_DATA_BUF =3D 3, } UfsReqResult; =20 #define UFS_INVALID_SLOT (-1) diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index 9a9c5ca8346..ea7b9aa62a7 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -770,6 +770,50 @@ static void ufstest_read_write(void *obj, void *data, = QGuestAllocator *alloc) ufs_exit(ufs, alloc); } =20 +static void ufstest_no_prdt(void *obj, void *data, QGuestAllocator *alloc) +{ + QUfs *ufs =3D obj; + uint8_t buf[4096]; + const uint8_t inquiry_cdb[UFS_CDB_SIZE] =3D { + /* INQUIRY, allocation length 36 */ + INQUIRY, 0x00, 0x00, 0x00, 0x24 + }; + const uint8_t write_cdb[UFS_CDB_SIZE] =3D { + /* WRITE(10) to LBA 0, transfer length 1 */ + WRITE_10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 + }; + enum UtpOcsCodes ocs; + UtpUpiuRsp rsp_upiu; + const int test_lun =3D 1; + + ufs_init(ufs, alloc); + + /* A pending unit attention is reported even without a PRDT */ + ocs =3D ufs_send_scsi_command(ufs, test_lun, write_cdb, NULL, 0, NULL,= 0, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, CHECK_CONDITION); + g_assert_cmpuint(rsp_upiu.sr.sense_data[2] & 0xf, =3D=3D, UNIT_ATTENTI= ON); + + /* Commands that move data but come without a PRDT fail */ + ocs =3D ufs_send_scsi_command(ufs, test_lun, inquiry_cdb, NULL, 0, NUL= L, 0, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_MISMATCH_DATA_BUF_SIZE); + + ocs =3D ufs_send_scsi_command(ufs, test_lun, write_cdb, NULL, 0, NULL,= 0, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_MISMATCH_DATA_BUF_SIZE); + + /* The logical unit keeps working */ + ocs =3D ufs_send_scsi_command(ufs, test_lun, inquiry_cdb, NULL, 0, buf= , 0x24, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + g_assert_cmpuint(buf[0] & 0x1f, =3D=3D, TYPE_DISK); + + ufs_exit(ufs, alloc); +} + static void ufstest_mcq_cq_wraparound(void *obj, void *data, QGuestAllocator *alloc) { @@ -1721,6 +1765,7 @@ static void ufs_register_nodes(void) qos_add_test("init", "ufs", ufstest_init, NULL); qos_add_test("legacy-read-write", "ufs", ufstest_read_write, &io_test_= opts); qos_add_test("mcq-read-write", "ufs", ufstest_read_write, &mcq_test_op= ts); + qos_add_test("no-prdt", "ufs", ufstest_no_prdt, &io_test_opts); qos_add_test("mcq-cq-wraparound", "ufs", ufstest_mcq_cq_wraparound, &mcq_test_opts); qos_add_test("query-flag", "ufs", ufstest_query_flag_request, --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348175; cv=none; d=zohomail.com; s=zohoarc; b=leKpcO5BECqIzeaujpYArPoAMyHxltIISBGHPgkKtwf4lF08NB/Bvjg7nGu8oBddUEuBxnPteLCZpZscoKaV4Dw0Ik7AO+VxqK/49NOmCOEmutuPTuvpSE+V0ahxHVqBkLFf6PhJhctBB9M1uYv7Rxfj1Gc+e3QRMRlwwaaB+6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348175; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wb0nK65gnGUWWtL+z/a/RxvOUUh5TBKwqMiX4tDJvI8=; b=lgfgJ5+CoyigKC8HgtDuhm1+AQWPHkJgd6d1ql4PzmuRcLw3P7FGopqxpUhPJl1j4ZUFDuTnSoZ0LwTdAeapV2D53Q7B7zt8BXXkQwC+M+38q8C4yWt2VoCDyEQRFegDfGzG4B4I7m+rERZFfPq1yDr8gNNODpEr6dkTj39JBVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348175565949.4378354425144; Fri, 30 Oct 2026 01:16:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhly-0006UV-IM; Fri, 30 Oct 2026 04:15:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlV-0006Hj-EU for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:09 -0400 Received: from mail-dl1-x122b.google.com ([2607:f8b0:4864:20::122b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlT-0001OC-8C for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:08 -0400 Received: by mail-dl1-x122b.google.com with SMTP id a92af1059eb24-1a2af4c8d00so833437c88.0 for ; Fri, 30 Oct 2026 01:15:06 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348106; x=1793952906; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wb0nK65gnGUWWtL+z/a/RxvOUUh5TBKwqMiX4tDJvI8=; b=w3PE5XgN8ay08mIk2fCmaLbrkRq3xCvLwU8YDjtDaC6z5f6JBr8KVfWnmnhd/hmNBR LawKnYKN87J04KdDxWBrrdMJdPMiMavT1V/4M4Zabc6OGMO95voCBmapf5MqIpC+95Eu G8U/iHn/asyfFTst7NT3pNfwcTLoTIJxAXJqPEsAl7OT4mcYFX2AmLZitAoG4wRrvvyX e5dJ/+KDFbdrWFIktpa0PkHDsCy7AEO0uZ3GxCxXbP9gtYK5iC5DoDRb2M92RS2l44sD Z3WDFLlHTWcTlU57QdpHPRrtTxMs0HMdkCh/G1+aYzsQzSR0lF3/Tn52JmWQh/MGEfLa 0X7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348106; x=1793952906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=wb0nK65gnGUWWtL+z/a/RxvOUUh5TBKwqMiX4tDJvI8=; b=fwkkvM2FefP/ALTutUDvdJZol9Bzo+tAfTGRox9z0u+M/WINY+GzgcDKr+qq9p64hy RpTTJEO2f14zYZA1qr0n23hZjTMJWsOu5v6WBxB6LxuvmgstWK0RDuaHd6eSv/acgSOu TUhQx9EsoViRfO+aQmqMlA1Qv+cWAssMD+SamPoxBGCu2Js1KhhAKGHmTHvV4Nf/u1TZ oziNV1iLEsNg22QUSeS8tOtUJTGDtLHoT/qxScH92vutmHXGqy3zd6ZpOzhWAINHwREH MAmksRIFwkHmGZ2kGfVju3AOUc8QEra1+KSOv/a0BjPDz8gSDjq+d8T5kv6ikA6LxrEN 31WQ== X-Gm-Message-State: AFq9FYIMZyEdL/13RH/rPBxb4RPuoJ2cfLyBt84S4OewA4Y9Ge1oCqeW PiMbuIqwU2+r/en85J8d1lif6fF0lrqPbZTGedeQcSkmkgb1nuAlA3lmBXXhqQ== X-Gm-Gg: AYBFou2HsHITDiVjR2m6BSMFL4W1GfEplNw+vX207I/4ecdUaI+deFg5BDP+Honp5tP I24tdeweNDVWRRfxpIGN0CPOzcHo6o4trq0q7GP4oDIAMBi9oFmTvM6w4R53+VdHXk1R1csLhgG MiPzitt0OLCAGu0EpuqJ4TFrRHs1DJRHGA9vuXoAVdth4/TI39jUWbswBhOSGJyaB4YPVSQh+y2 LeM0hgb9+cxeyyq47Z4GMt9+MpT6+qPdV4Nw8PqUPokJzRaPEWW4r2vh/IvhhdKD6R2nnAImu/J seatpos6Rh6GdFvPt+FtdFWofKP/rYkSPmkO1ceCr+8JrYvG3hh06DnxHZmKZXcFJ/LYllGbVOq sFuY1lVosPFb4Urug0EBSn4MZYZdeG5pwxyBUvlzPHXU2Yhc2jxLwAhn3/oaoJa4TkUKtGB6Ovs UeauVFeBRaQ0n25synNxofG9c12Osd3aIkwP4jnmURisVBybpuidVXmbFE1ym3RJ3fJTdkAV0ZR VvFwOOji0RLgfwL9ZGiyZuD0aOm77qaxxFX+s7uYl47CmWTmRIxmzlrkuyAzxb4NNFZNkp+Fgas 3yJhJ8BknhFjggum9659pcB1glSuToI3QiMoRWKxmxe0xz/D1JZ9aY4ldEhWFKZHag== X-Received: by 2002:a05:701b:428a:20b0:17b:fed6:7449 with SMTP id a92af1059eb24-1ac5da7725fmr2385733c88.47.1793348105465; Fri, 30 Oct 2026 01:15:05 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 03/12] hw/ufs: Pass SYNCHRONIZE CACHE(16) to scsi-hd as SYNCHRONIZE CACHE(10) Date: Fri, 30 Oct 2026 17:14:29 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::122b; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x122b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348176649154100 Content-Type: text/plain; charset="utf-8" From: Daejun Park scsi-hd implements SYNCHRONIZE CACHE(10) only and fails the 16-byte variant with INVALID COMMAND OPERATION CODE. Linux sends SYNCHRONIZE CACHE(16) to zoned disks (sd_zbc sets use_16_for_sync), so once a logical unit can be zoned, every flush from such a guest fails. With the zoned logical units and without this change, a Linux 7.3-rc7 guest logged sd 2:0:0:1: [sdb] tag#9 Add. Sense: Invalid command operation code critical target error, dev sdb, sector 0 op 0x1:(WRITE) flags 0x800 and fsync() on the disk failed with EREMOTEIO. scsi-hd flushes the whole medium for SYNCHRONIZE CACHE(10) and does not look at its LBA range. Hand the 16-byte command to scsi-hd as the 10-byte one and keep the IMMED bit. This keeps the UFS change inside hw/ufs; if scsi-disk learns SYNCHRONIZE CACHE(16), the translation can go. Signed-off-by: Daejun Park Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/lu.c | 17 ++++++++++++++-- tests/qtest/ufs-test.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/hw/ufs/lu.c b/hw/ufs/lu.c index 1101e368734..a7b6d778f9b 100644 --- a/hw/ufs/lu.c +++ b/hw/ufs/lu.c @@ -406,6 +406,8 @@ static UfsReqResult ufs_emulate_scsi_cmd(UfsLu *lu, Ufs= Request *req) static UfsReqResult ufs_process_scsi_cmd(UfsLu *lu, UfsRequest *req) { uint8_t task_tag =3D req->req_upiu.header.task_tag; + uint8_t *cdb =3D req->req_upiu.sc.cdb; + uint8_t sync_cache_10[UFS_CDB_SIZE] =3D { SYNCHRONIZE_CACHE }; SCSIRequest *scsi_req; uint32_t len; =20 @@ -419,8 +421,19 @@ static UfsReqResult ufs_process_scsi_cmd(UfsLu *lu, Uf= sRequest *req) return ufs_emulate_scsi_cmd(lu, req); } =20 - scsi_req =3D scsi_req_new(lu->scsi_dev, task_tag, lu->lun, - req->req_upiu.sc.cdb, UFS_CDB_SIZE, req); + /* + * scsi-hd implements SYNCHRONIZE CACHE(10) only, while Linux sends the + * 16-byte variant to zoned disks. scsi-hd flushes the whole medium for + * SYNCHRONIZE CACHE(10) whatever its LBA range, so pass the 16-byte + * command on as the 10-byte one, keeping IMMED. + */ + if (cdb[0] =3D=3D SYNCHRONIZE_CACHE_16) { + sync_cache_10[1] =3D cdb[1] & 0x02; + cdb =3D sync_cache_10; + } + + scsi_req =3D scsi_req_new(lu->scsi_dev, task_tag, lu->lun, cdb, UFS_CD= B_SIZE, + req); =20 /* * A command that moves data needs a PRDT. Without one there is no SG diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index ea7b9aa62a7..3c9e9e4032c 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -814,6 +814,51 @@ static void ufstest_no_prdt(void *obj, void *data, QGu= estAllocator *alloc) ufs_exit(ufs, alloc); } =20 +static void ufstest_sync_cache(void *obj, void *data, QGuestAllocator *all= oc) +{ + QUfs *ufs =3D obj; + uint8_t buf[4096]; + const uint8_t request_sense_cdb[UFS_CDB_SIZE] =3D { + REQUEST_SENSE, + }; + const uint8_t sync_cache_10_cdb[UFS_CDB_SIZE] =3D { + SYNCHRONIZE_CACHE, + }; + const uint8_t sync_cache_16_cdb[UFS_CDB_SIZE] =3D { + SYNCHRONIZE_CACHE_16, + }; + const uint8_t sync_cache_16_immed_cdb[UFS_CDB_SIZE] =3D { + SYNCHRONIZE_CACHE_16, 0x02 /* IMMED */ + }; + enum UtpOcsCodes ocs; + UtpUpiuRsp rsp_upiu; + const int test_lun =3D 1; + + ufs_init(ufs, alloc); + + /* Clear Unit Attention */ + ocs =3D ufs_send_scsi_command(ufs, test_lun, request_sense_cdb, NULL, = 0, + buf, sizeof(buf), &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + + ocs =3D ufs_send_scsi_command(ufs, test_lun, sync_cache_10_cdb, NULL, = 0, + NULL, 0, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + + ocs =3D ufs_send_scsi_command(ufs, test_lun, sync_cache_16_cdb, NULL, = 0, + NULL, 0, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + + ocs =3D ufs_send_scsi_command(ufs, test_lun, sync_cache_16_immed_cdb, = NULL, + 0, NULL, 0, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + + ufs_exit(ufs, alloc); +} + static void ufstest_mcq_cq_wraparound(void *obj, void *data, QGuestAllocator *alloc) { @@ -1766,6 +1811,7 @@ static void ufs_register_nodes(void) qos_add_test("legacy-read-write", "ufs", ufstest_read_write, &io_test_= opts); qos_add_test("mcq-read-write", "ufs", ufstest_read_write, &mcq_test_op= ts); qos_add_test("no-prdt", "ufs", ufstest_no_prdt, &io_test_opts); + qos_add_test("sync-cache", "ufs", ufstest_sync_cache, &io_test_opts); qos_add_test("mcq-cq-wraparound", "ufs", ufstest_mcq_cq_wraparound, &mcq_test_opts); qos_add_test("query-flag", "ufs", ufstest_query_flag_request, --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348192; cv=none; d=zohomail.com; s=zohoarc; b=d67KaMbOZNvUZUyWRQBk07k89HTqPnT9UQLeo/EKw5JSWzrgAyKYrWhuzDx5kFT+PX4/Skwp7B31oidzxyWUDRmYgIyq8p/58zfbAiyutWhjzIaB/yd5LOglboCnS843cDM7ikHM47KauZWgeVR7WzNBKBtkCuquGWbH6Sqbpec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348192; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nAdljkISQ75QNeWlz6TQpkKdNNAEruYPkaLPZ1Gh7PA=; b=Opmeh/tLIn9VaL5J8ef0s2Wece2ztVDzR8xiSD/9pk8G/QHDBJrNtQPpPqLZo2wD8wIEvscJXpMnzFezRO3q3zc9OAUMqz1zgI1CEe4L/sbtPwOGrP9Q0V1o5xeL8ccKrDqXcp4uNQTYIWMwK3q3eKDge6XLNvNurDt5b8vtQ98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179334819226030.502239498380845; Fri, 30 Oct 2026 01:16:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhly-0006UK-GC; Fri, 30 Oct 2026 04:15:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhld-0006MH-6l for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:20 -0400 Received: from mail-dl1-x1234.google.com ([2607:f8b0:4864:20::1234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlX-0001P0-0y for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:15 -0400 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-1931ff67a29so1264327c88.1 for ; Fri, 30 Oct 2026 01:15:10 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348109; x=1793952909; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nAdljkISQ75QNeWlz6TQpkKdNNAEruYPkaLPZ1Gh7PA=; b=AMXHVFKE4p1Ww40FQjy3kblnTEUggWDxf3ao3RBm7c3GqEtCBm0fQhyzRApjHP2Xgg IirqrlR+Za3yVVf8vqsDwEb3IgZCgJgKlcfckGnX9n3c8JpQfzU/g2sDL/Ga80w1OP/E e/fRcJfOEzMmaalI8RfgMBw/anPM7Sd4tmIqOBDcV0dND7gzthgTpwDL74SXzOv/+ST2 YMpnqYh+hEZjqTgHrsW8NA161hv8J3wZZkiI9vRzO/OVxcA8CKanvv0vqdX0V5BcUIor DJoPeDeQBFEetNOd9Lao0gYlN/SYaeCnSLkaWVCFP+22Zt1KcUlH4xV/4NNQ7+/GsZS/ kXNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348109; x=1793952909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nAdljkISQ75QNeWlz6TQpkKdNNAEruYPkaLPZ1Gh7PA=; b=ESTN2Bx/e1qv+3ZnceerhQImA38oqnh5fTZtJmv70mO8Nl9xGp97OF67oHt4HvP57P QEBJZ8E/anCx0pe+gW6MjEnxXHX75Im5rxVyzupJekNUvoCMA5JSpUFx+5wIrj/7CNnM PPp/wljIqT45duebTmtt0IoObFboNynZcd/9HkwT+tVlgjC2PTTCH79LnxwX1ElghMHO ysjj2X63kehYSp2Yfm063T9GzZtjJYH2THoH5lZWqJ5GRZ/SKmQcdRXYW00V6DnS3jj4 7Qa2mbejWJgQKCtlT5nmFWr6hOHt+MVurMmSoR5hqVHCjvNc3L+zmmoSSwN0I2XeEkiv XdqQ== X-Gm-Message-State: AFq9FYKoFtwtR/puMZgZw5yszuOf1+hfFFht8vZkA5jj3CrcVBQvoMZj +2mlkid12YjKIErRzStL64Wma5OvXsP701E+M2wcfXgyF9WuIPM2tbVhjWlYJA== X-Gm-Gg: AYBFou2YyrkOVM8PpDSJq17WjLIroKw07nCD/Oyrmev3n2IB1boTfGA0PFP6Bj07JSi uWX5/2UxrjAOlW9VFAGdqsBnov3oi0XAF7x1ULDrSAyo0kLw07GEXZKXipV9tuay1Ff50HXp6tt 9xvMoNl2/DOOiiPwx0dkCU3L/9Jasce0rvx0TGWnltBzTFagUTTeXyLIrc+cocTAmTBCpO5bEaT zEDPpcvTELzJgeibGQWmPdpq5UTztqlhWgJBeSJZtySHdqdUKlypskG+D66Iu0JuL0TXp1w+orc rdLxb+diKansw3iOrdBM9856Kz8dxp5VI2YE33VWKIJ7rjnYBc3Wbja46TFT17mra6rRILnSXSN IJspydrzNqhEBYhv+xT/xW/klgLKD5GNs6HLk7iAZC0iv5S+KfKHWIOinzld35krsJmjuRwcxg9 dikA2cYptadQVYRr/3Enw/H0TLpWaFfl7qh2KFZNlphCisPxSomL3ebUkSEBvP+iNZ6pcDh7m6+ TSRsgBBeaMKt838en+F67Nkqn45dYl/hOVgT57ZM8Wy9DqJxcf6JSNaJ6vNDdC91VROHvSp5S0Q ZUYO3QMRcekCl0TCHK12mem/dH0waN6p2iNV0pcl1QYneq8pn5estGQm28uBW4wAbjGv1vR2oVU yTPMqPcSMJKI= X-Received: by 2002:a05:701b:424e:10b0:1a1:47b2:5512 with SMTP id a92af1059eb24-1ac5b7dfd1cmr2385869c88.26.1793348108546; Fri, 30 Oct 2026 01:15:08 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com, qemu-stable@nongnu.org Subject: [PULL 04/12] hw/ufs: Check the PRDT size against the transfer length of the CDB Date: Fri, 30 Oct 2026 17:14:30 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1234; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348193873158500 Content-Type: text/plain; charset="utf-8" From: Daejun Park scsi-hd moves as many bytes as the SG list of a request holds, and ufs-lu builds that list from the whole PRDT. When the PRDT is larger than the transfer length in the CDB, a WRITE writes more blocks than the CDB names and a READ reads more. A one-block WRITE(10) at LBA 0 with an 8 KiB PRDT also wrote LBA 1, and its response reported no residual. A UFS device transfers what the CDB asks for and reports the rest of the Expected Data Transfer Length as a residual. The commands that scsi-hd emulates had their residual computed against the PRDT too: an INQUIRY with an allocation length of 36, a 4 KiB PRDT and an Expected Data Transfer Length of 4096 reported an overflow of 4294959176 bytes. It now reports an underflow of 4060. When the PRDT is smaller than the transfer length, scsi-hd moved what it holds and the request completed without an error, for example a two-block WRITE(10) with a 4 KiB PRDT. Such a request now fails with OCS MISMATCH DATA BUFFER SIZE, as one without a PRDT does. As in virtio-scsi, the PRDT is compared with the transfer length of the CDB, which for commands that return data is the allocation length, and before scsi-hd checks the CDB. The new ufs_fit_data_buffer() in ufs.c, where the SG list is built from the PRDT, cuts a longer list and reports a shorter one; ufs-lu passes it the transfer length that scsi_req_new() parsed. The HID qtest wrote eight blocks from a one-block buffer, so give it eight blocks. The new long-prdt and short-prdt qtests failed before this change. Fixes: 2a8b36a4967d ("hw/ufs: Support for UFS logical unit") Cc: qemu-stable@nongnu.org Signed-off-by: Daejun Park Reviewed-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/lu.c | 20 +++--- hw/ufs/trace-events | 1 + hw/ufs/ufs.c | 35 ++++++++++ hw/ufs/ufs.h | 1 + tests/qtest/ufs-test.c | 141 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 189 insertions(+), 9 deletions(-) diff --git a/hw/ufs/lu.c b/hw/ufs/lu.c index a7b6d778f9b..bbb0554fb0d 100644 --- a/hw/ufs/lu.c +++ b/hw/ufs/lu.c @@ -436,15 +436,19 @@ static UfsReqResult ufs_process_scsi_cmd(UfsLu *lu, U= fsRequest *req) req); =20 /* - * A command that moves data needs a PRDT. Without one there is no SG - * list, and the SCSI layer would call the transfer_data callback, whi= ch - * ufs-lu does not set. Fail the request with OCS MISMATCH DATA BUFFER - * SIZE, as virtio-scsi fails a buffer that does not match the command. - * A request that reports a pending unit attention instead moves no da= ta; - * its sense is already set, so let it through and the guest sees the = UA. + * scsi-hd moves as many bytes as the SG list holds, and without an SG + * list it would call the transfer_data callback, which ufs-lu does not + * set. A UFS device moves what the CDB asks for, so fit the PRDT to t= he + * transfer length, and fail a request whose PRDT describes less, a + * missing PRDT included, with OCS MISMATCH DATA BUFFER SIZE, as + * virtio-scsi fails a buffer that does not match the command. The + * response reports the rest of the Expected Data Transfer Length as a + * residual. A request that reports a pending unit attention moves no + * data; its sense is already set, so let it through and the guest sees + * the UA. */ - if (scsi_req->cmd.mode !=3D SCSI_XFER_NONE && !req->sg && - !scsi_req->sense_len) { + if (!scsi_req->sense_len && + !ufs_fit_data_buffer(req, scsi_req->cmd.xfer)) { scsi_req_unref(scsi_req); return UFS_REQUEST_MISMATCH_DATA_BUF; } diff --git a/hw/ufs/trace-events b/hw/ufs/trace-events index 5e5a54a3fb3..db9d1727135 100644 --- a/hw/ufs/trace-events +++ b/hw/ufs/trace-events @@ -22,6 +22,7 @@ ufs_hce_reset(void) "HCE 1 -> 0 reset: cancelling BHs, re= setting MCQ and request ufs_err_dma_read_utrd(uint32_t slot, uint64_t addr) "failed to read utrd. = UTRLDBR slot %"PRIu32", UTRD dma addr %"PRIu64"" ufs_err_dma_read_req_upiu(uint32_t slot, uint64_t addr) "failed to read re= q upiu. UTRLDBR slot %"PRIu32", request upiu addr %"PRIu64"" ufs_err_dma_read_prdt(uint32_t slot, uint64_t addr) "failed to read prdt. = UTRLDBR slot %"PRIu32", prdt addr %"PRIu64"" +ufs_err_mismatch_data_buf(uint32_t slot, uint8_t task_tag, uint64_t xfer, = uint64_t prdt_size) "slot %"PRIu32", task tag %"PRIu8", transfer length %"P= RIu64", PRDT %"PRIu64"" ufs_err_dma_read_sq(uint8_t sqid, uint64_t addr) "failed to read sq entry.= sqid %"PRIu8", hwaddr %"PRIu64"" ufs_err_dma_write_utrd(uint32_t slot, uint64_t addr) "failed to write utrd= . UTRLDBR slot %"PRIu32", UTRD dma addr %"PRIu64"" ufs_err_dma_write_rsp_upiu(uint32_t slot, uint64_t addr) "failed to write = rsp upiu. UTRLDBR slot %"PRIu32", response upiu addr %"PRIu64"" diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index dda615da7ce..cd28f97a123 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -227,6 +227,41 @@ static MemTxResult ufs_dma_read_prdt(UfsRequest *req) return MEMTX_OK; } =20 +/* + * Fit the SG list built from the PRDT to the len bytes that the command of + * req moves: keep only the first len bytes of a longer list. Return false= if + * the PRDT describes fewer than len bytes. + */ +bool ufs_fit_data_buffer(UfsRequest *req, uint64_t len) +{ + QEMUSGList *prdt_sg =3D req->sg; + uint64_t prdt_size =3D prdt_sg ? prdt_sg->size : 0; + QEMUSGList *sg; + int i; + + if (prdt_size < len) { + trace_ufs_err_mismatch_data_buf(req->slot, + req->req_upiu.header.task_tag, len, + prdt_size); + return false; + } + if (prdt_size =3D=3D len) { + return true; + } + + sg =3D g_new0(QEMUSGList, 1); + qemu_sglist_init(sg, prdt_sg->dev, prdt_sg->nsg, prdt_sg->as); + for (i =3D 0; i < prdt_sg->nsg && sg->size < len; i++) { + qemu_sglist_add(sg, prdt_sg->sg[i].base, + MIN(prdt_sg->sg[i].len, len - sg->size)); + } + qemu_sglist_destroy(prdt_sg); + g_free(prdt_sg); + req->sg =3D sg; + req->data_len =3D sg->size; + return true; +} + static MemTxResult ufs_dma_read_upiu(UfsRequest *req) { MemTxResult ret; diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h index adf74b6833d..15b3a352f3b 100644 --- a/hw/ufs/ufs.h +++ b/hw/ufs/ufs.h @@ -306,6 +306,7 @@ void ufs_build_upiu_header(UfsRequest *req, uint8_t tra= ns_type, uint8_t flags, uint16_t data_segment_length); void ufs_build_query_response(UfsRequest *req); void ufs_complete_req(UfsRequest *req, UfsReqResult req_result); +bool ufs_fit_data_buffer(UfsRequest *req, uint64_t len); void ufs_wb_update_avail_buffer(UfsHc *u); void ufs_init_wlu(UfsLu *wlu, uint8_t wlun); bool ufs_realize(UfsHc *u, DeviceState *dev, AddressSpace *dma_as, diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index 3c9e9e4032c..e8993e8c246 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -859,6 +859,142 @@ static void ufstest_sync_cache(void *obj, void *data,= QGuestAllocator *alloc) ufs_exit(ufs, alloc); } =20 +static void ufstest_long_prdt(void *obj, void *data, QGuestAllocator *allo= c) +{ + QUfs *ufs =3D obj; + const uint8_t request_sense_cdb[UFS_CDB_SIZE] =3D { + REQUEST_SENSE, + }; + /* One block at LBA 0 and at LBA 1 */ + const uint8_t write_lba0_cdb[UFS_CDB_SIZE] =3D { + WRITE_10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + }; + const uint8_t read_lba0_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + }; + const uint8_t read_lba1_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, + }; + /* Allocation length 36 */ + const uint8_t inquiry_cdb[UFS_CDB_SIZE] =3D { + INQUIRY, 0x00, 0x00, 0x00, 0x24, 0x00, + }; + uint8_t buf[2 * 4096]; + uint8_t zero_buf[4096] =3D { 0 }; + uint8_t write_buf[2 * 4096]; + UtpUpiuRsp rsp_upiu, write_rsp_upiu; + enum UtpOcsCodes ocs; + + ufs_init(ufs, alloc); + ocs =3D ufs_send_scsi_command(ufs, 1, request_sense_cdb, NULL, 0, buf,= 4096, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + + /* A one-block WRITE with a two-block PRDT writes one block */ + memset(write_buf, 0xa5, sizeof(write_buf)); + ocs =3D ufs_send_scsi_command(ufs, 1, write_lba0_cdb, write_buf, + sizeof(write_buf), NULL, 0, &write_rsp_upi= u); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(write_rsp_upiu.header.scsi_status, =3D=3D, GOOD); + + ocs =3D ufs_send_scsi_command(ufs, 1, read_lba1_cdb, NULL, 0, buf, 409= 6, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + g_assert_cmpmem(buf, 4096, zero_buf, sizeof(zero_buf)); + + g_assert_cmpuint(write_rsp_upiu.header.flags, =3D=3D, UFS_UPIU_FLAG_UN= DERFLOW); + g_assert_cmpuint(be32_to_cpu(write_rsp_upiu.sr.residual_transfer_count= ), + =3D=3D, 4096); + + /* A one-block READ with a two-block PRDT reads one block */ + ocs =3D ufs_send_scsi_command(ufs, 1, read_lba0_cdb, NULL, 0, buf, + sizeof(buf), &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + g_assert_cmpuint(rsp_upiu.header.flags, =3D=3D, UFS_UPIU_FLAG_UNDERFLO= W); + g_assert_cmpuint(be32_to_cpu(rsp_upiu.sr.residual_transfer_count), =3D= =3D, + 4096); + g_assert_cmpmem(buf, 4096, write_buf, 4096); + + /* A 36-byte INQUIRY with a 4 KiB PRDT reports the rest as a residual = */ + ocs =3D ufs_send_scsi_command(ufs, 1, inquiry_cdb, NULL, 0, buf, 4096, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + g_assert_cmpuint(rsp_upiu.header.flags, =3D=3D, UFS_UPIU_FLAG_UNDERFLO= W); + g_assert_cmpuint(be32_to_cpu(rsp_upiu.sr.residual_transfer_count), =3D= =3D, + 4096 - 36); + + ufs_exit(ufs, alloc); +} + +static void ufstest_short_prdt(void *obj, void *data, QGuestAllocator *all= oc) +{ + QUfs *ufs =3D obj; + const uint8_t request_sense_cdb[UFS_CDB_SIZE] =3D { + REQUEST_SENSE, + }; + /* Two blocks at LBA 2, and one */ + const uint8_t write_2_cdb[UFS_CDB_SIZE] =3D { + WRITE_10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, + }; + const uint8_t read_2_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, + }; + const uint8_t write_1_cdb[UFS_CDB_SIZE] =3D { + WRITE_10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, + }; + const uint8_t read_1_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, + }; + /* Allocation length 36 */ + const uint8_t inquiry_cdb[UFS_CDB_SIZE] =3D { + INQUIRY, 0x00, 0x00, 0x00, 0x24, 0x00, + }; + uint8_t buf[4096]; + uint8_t zero_buf[4096] =3D { 0 }; + uint8_t write_buf[4096]; + UtpUpiuRsp rsp_upiu; + enum UtpOcsCodes ocs; + + ufs_init(ufs, alloc); + ocs =3D ufs_send_scsi_command(ufs, 1, request_sense_cdb, NULL, 0, buf,= 4096, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + memset(write_buf, 0x5a, sizeof(write_buf)); + + /* A PRDT that describes less than the command moves fails */ + ocs =3D ufs_send_scsi_command(ufs, 1, write_2_cdb, write_buf, + sizeof(write_buf), NULL, 0, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_MISMATCH_DATA_BUF_SIZE); + ocs =3D ufs_send_scsi_command(ufs, 1, read_2_cdb, NULL, 0, buf, sizeof= (buf), + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_MISMATCH_DATA_BUF_SIZE); + ocs =3D ufs_send_scsi_command(ufs, 1, inquiry_cdb, NULL, 0, buf, 16, + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_MISMATCH_DATA_BUF_SIZE); + + /* The failed WRITE wrote nothing */ + ocs =3D ufs_send_scsi_command(ufs, 1, read_1_cdb, NULL, 0, buf, sizeof= (buf), + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + g_assert_cmpmem(buf, sizeof(buf), zero_buf, sizeof(zero_buf)); + + /* A matching PRDT still works */ + ocs =3D ufs_send_scsi_command(ufs, 1, write_1_cdb, write_buf, + sizeof(write_buf), NULL, 0, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(rsp_upiu.header.scsi_status, =3D=3D, GOOD); + ocs =3D ufs_send_scsi_command(ufs, 1, read_1_cdb, NULL, 0, buf, sizeof= (buf), + &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpmem(buf, sizeof(buf), write_buf, sizeof(write_buf)); + + ufs_exit(ufs, alloc); +} + static void ufstest_mcq_cq_wraparound(void *obj, void *data, QGuestAllocator *alloc) { @@ -1577,7 +1713,8 @@ static void ufstest_hid(void *obj, void *data, QGuest= Allocator *alloc) /* WRITE(10) to LBA 0, transfer length 8 sectors =3D 1 fragment */ WRITE_10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 }; - uint8_t write_buf[4096]; + /* The PRDT must hold the eight blocks that the WRITE(10) moves */ + uint8_t write_buf[8 * 4096]; uint8_t read_buf[4096]; int i; =20 @@ -1812,6 +1949,8 @@ static void ufs_register_nodes(void) qos_add_test("mcq-read-write", "ufs", ufstest_read_write, &mcq_test_op= ts); qos_add_test("no-prdt", "ufs", ufstest_no_prdt, &io_test_opts); qos_add_test("sync-cache", "ufs", ufstest_sync_cache, &io_test_opts); + qos_add_test("long-prdt", "ufs", ufstest_long_prdt, &io_test_opts); + qos_add_test("short-prdt", "ufs", ufstest_short_prdt, &io_test_opts); qos_add_test("mcq-cq-wraparound", "ufs", ufstest_mcq_cq_wraparound, &mcq_test_opts); qos_add_test("query-flag", "ufs", ufstest_query_flag_request, --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348151; cv=none; d=zohomail.com; s=zohoarc; b=jYog+/9yMYeEeoYcKUZ0eI+bf7ACCKRcdvge9DwQeSgyfG7y3Xi3IaMP91LW0uInl90ESxnSZ6JuGclPUxRIRsj2hU5B7XmrgHr87UHrcwCQbajwfU6Mc/3aF2mkVtMgOj1AwId3wgpDxmDEqbFUmegw1/6w64YZ/nHSRE3Xo8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348151; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Fp9LZTokCb77yom7hPnnnrO7TqI9laTG0ZXcPuVz3to=; b=StleAlWx0IqegApTBMto46aBULkqSWoHML/0d0372+wSTiWpqoe9aR2QwgQ1wumgBC6p5YBNx74LJn8pJeT1idPieypfwHI04Ma8wCcxnmDhAQ90aVSxw0t6P/0p4KttRcTO153k4GHW+b5XkciW3M/I/o2tEgTurk5KyLpF4yQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348151265189.36761650221536; Fri, 30 Oct 2026 01:15:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhlw-0006T4-TR; Fri, 30 Oct 2026 04:15:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlf-0006MT-43 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:20 -0400 Received: from mail-dl1-x1232.google.com ([2607:f8b0:4864:20::1232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlZ-0001PF-Em for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:17 -0400 Received: by mail-dl1-x1232.google.com with SMTP id a92af1059eb24-14fc585291cso328472c88.1 for ; Fri, 30 Oct 2026 01:15:13 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348112; x=1793952912; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Fp9LZTokCb77yom7hPnnnrO7TqI9laTG0ZXcPuVz3to=; b=L/GYzGiIFVRRBi00ZSGIw3sAcr3F6Y2/M51IcssoSzY+JUVyX8F2/g8o1xtuBBZ/w1 bjDvWO7oP187sK56hgjTgKXBWSbZNg8zj+fP2eObHAo88NiA+fkgbGhIXPKIMEuZH+37 Ir3WMO/0/uaseHAX1oNX2S6Yk3tqi9Y7yLoNmHBCLjc+7FsDsWXCGZU9mFWLE2V+lwtG 24WujA4VXN0eYb0EKR/ideg8ELo8t8ToHL8Ay/y0TqzDPzIZgfreZAvvO3h+rNCFfkA/ Rmgy70BEl2uaflEn3RddzZzENOB3MiGZKx3S+vCzMBRPJGGE1H2vU9jA/K8drnjCeUNS wXrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348112; x=1793952912; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Fp9LZTokCb77yom7hPnnnrO7TqI9laTG0ZXcPuVz3to=; b=FZFUidyPAdvj4jbUZ4ojZ3r1ghhO5BgXDQgZbZIeouCm2QOni84hwMGff+/YS7KIzI 3mr47WlHbZEwjDWhYnrEw86qKmTlb7Wzkn3ntHWxpYEV98wXTt7Vas4+FFDb3uB2YsLj M9mDK66F45Azu0lwzwk2JaaPbwvRPZh0yxomxg6NSnePqba1CDsGtpqGcVSX8PvF7Bwo 06SRzBb9FZu/XeqybJe8qOVJywwpqftP2xvZ3Fh7UB6ihsjIOjq6Fgl/arF/q2ltG4g2 07XSGeesTqleZ1ikOrjhW3PjDEP4ZslPG41ctpzu755lQ3a6JvXrY/iFjhPA9ForworR cuAw== X-Gm-Message-State: AFq9FYIUXduxU0MG4YajMrTSqigyAqqjoHANIwDkb7mqPlapAeH4QezN 2y6nttesWiSgneNeiKs2oBHAdQ+zgGsazklf/RKDZp61IjupioH+8BAF8IWqBA== X-Gm-Gg: AYBFou1OqmNP7rxeiz4xhmT3gNBUMp0HI4X7iTSvoryCUEUxGNh4U+jvWsz+4lR1w7v MJYxI6EzHLFyEZP17tr5W6Iv11P77BhisBKMugzsAH1Omtveb2aWOhJn34VcxyYc08XiQ/8aRlD TcrG3qCxOlCwks0B1htNukOKKjxC0+wwmhu1LbCRZxITfC4ZTJ47EHqaV+S4GhCu9FvZBqk1CU0 yUyPj3wzRqd+wtq+xGmv1or/BefG01IpLW/iQvzOQUk6gE2cty7vi5/L39ivIaRR0GuileEL5gN tMwZUny7GISCezBlFKi3g/qWUpoXha5UBH/BEFb607nbEzkelLJceqZ1qxtQ/56YXcMK++3oaM0 iZEh8HKrT1wFpMlGWH/0CRFAgf2WZHZwR6jrMXTM+60NG7Vc1KPV+i4aBhjV+ytqC+UsKesmnC4 TrWH1qOjmeDlMdCVZXhwwwuEE/zR6Hvr1bG7QCbmFNR8G9HkupD16EgVN5lVbBjxzUB0Geoijpn vhCSJobmU9lnXoLISs1pyZSxOWKB8lP/4RyWI788VhipJhOpbnbf8eKNdqaQmLUwh7VL8gm2E0b e35wqrUaP3fpGA/okOlPZBllyKD0CXQ8C5z/RSnBSjtF6+NC7Jnf20TydgnqOzs0dQQs/TZIXk8 xUW6PTTiJOjg= X-Received: by 2002:a05:7022:29c:10b0:143:8860:afa1 with SMTP id a92af1059eb24-1ac5f36d693mr2070019c88.46.1793348111926; Fri, 30 Oct 2026 01:15:11 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 05/12] hw/ufs: Add experimental fault injection properties for holding requests Date: Fri, 30 Oct 2026 17:14:31 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1232; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1232.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348153164158500 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Add experimental properties x-fault-inject-tag and x-fault-inject-mode to ufs-pci and ufs-sysbus devices for testing host driver error handling and recovery routines. When x-fault-inject-tag is set to a specific tag (0..255), the controller holds the matching SCSI command request in u->held_req without completing it. When x-fault-inject-tag is set to 0xfffffffe (UFS_FAULT_INJECT_TAG_ANY), the controller intercepts the first READ_10, WRITE_10, READ_16, or WRITE_16 command with LBA >=3D 512, skipping boot-time metadata reads. The default value is 0xffffffff (UFS_FAULT_INJECT_TAG_NONE), which disables fault injection. Both properties can be changed at runtime through QOM (for example QMP qom-set). A held request is released on HCE reset. Task management handling for held requests follows in the next patch. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/trace-events | 2 + hw/ufs/ufs-pci.c | 7 ++ hw/ufs/ufs-sysbus.c | 7 ++ hw/ufs/ufs.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ hw/ufs/ufs.h | 61 ++++++++++++++++ 5 files changed, 241 insertions(+) diff --git a/hw/ufs/trace-events b/hw/ufs/trace-events index db9d1727135..17acbebd301 100644 --- a/hw/ufs/trace-events +++ b/hw/ufs/trace-events @@ -16,6 +16,8 @@ ufs_mcq_create_sq(uint8_t sqid, uint8_t cqid, uint64_t ad= dr, uint16_t size) "mcq ufs_mcq_create_cq(uint8_t cqid, uint64_t addr, uint16_t size) "mcq create = cq cqid %"PRIu8", addr 0x%"PRIx64", size %"PRIu16"" ufs_write_mcq_op_reg(uint8_t qid, uint32_t offset, uint32_t data) "qid %"P= RIu8", offset 0x%"PRIx32", data 0x%"PRIx32"" ufs_process_tmr(uint8_t func, uint32_t tag, uint8_t resp) "query_func 0x%"= PRIx8", task_tag %"PRIu32", tm_resp 0x%"PRIx8"" +ufs_fault_inject_hold_req(uint8_t tag, uint64_t lba) "held command tag %"P= RIu8", lba %"PRIu64"" +ufs_fault_inject_set_tag(uint32_t tag) "fault-inject-tag set to 0x%"PRIx32= "" ufs_hce_reset(void) "HCE 1 -> 0 reset: cancelling BHs, resetting MCQ and r= equest lists" =20 # error condition diff --git a/hw/ufs/ufs-pci.c b/hw/ufs/ufs-pci.c index 8abd7d98e3d..8a2268f11ff 100644 --- a/hw/ufs/ufs-pci.c +++ b/hw/ufs/ufs-pci.c @@ -72,6 +72,13 @@ static const Property ufs_pci_props[] =3D { 0x400), DEFINE_PROP_UINT32("wb-min-size", UfsPciState, ufs.params.wb_min_size, 0x100), + DEFINE_PROP_UNSIGNED("x-fault-inject-tag", UfsPciState, + ufs.params.fault_inject_tag, UFS_FAULT_INJECT_TAG= _NONE, + ufs_prop_fault_inject_tag, uint32_t), + DEFINE_PROP_SIGNED("x-fault-inject-mode", UfsPciState, + ufs.params.fault_inject_mode, + UFS_FAULT_INJECT_ABORT_SUCCESS, + ufs_prop_fault_inject_mode, UfsFaultInjectMode), }; =20 static const VMStateDescription ufs_pci_vmstate =3D { diff --git a/hw/ufs/ufs-sysbus.c b/hw/ufs/ufs-sysbus.c index 84de2e95ac4..7e85d8fc4c9 100644 --- a/hw/ufs/ufs-sysbus.c +++ b/hw/ufs/ufs-sysbus.c @@ -45,6 +45,13 @@ static const Property ufs_sysbus_props[] =3D { 0x400), DEFINE_PROP_UINT32("wb-min-size", SysbusUfsState, ufs.params.wb_min_si= ze, 0x100), + DEFINE_PROP_UNSIGNED("x-fault-inject-tag", SysbusUfsState, + ufs.params.fault_inject_tag, UFS_FAULT_INJECT_TAG= _NONE, + ufs_prop_fault_inject_tag, uint32_t), + DEFINE_PROP_SIGNED("x-fault-inject-mode", SysbusUfsState, + ufs.params.fault_inject_mode, + UFS_FAULT_INJECT_ABORT_SUCCESS, + ufs_prop_fault_inject_mode, UfsFaultInjectMode), }; =20 static const VMStateDescription ufs_sysbus_vmstate =3D { diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index cd28f97a123..1a5bc54eac4 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -15,8 +15,10 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "scsi/constants.h" #include "hw/core/irq.h" +#include "hw/core/qdev-prop-internal.h" #include "trace.h" #include "ufs.h" =20 @@ -778,6 +780,77 @@ static bool ufs_mcq_delete_cq(UfsHc *u, uint8_t qid) return true; } =20 +static void ufs_fault_inject_init(UfsHc *u) +{ + u->active_fault_inject_tag =3D u->params.fault_inject_tag; + u->held_req =3D NULL; +} + +static void ufs_fault_inject_hce_reset(UfsHc *u) +{ + if (u->held_req) { + u->held_req =3D NULL; + u->active_fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + u->params.fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + } else { + u->active_fault_inject_tag =3D u->params.fault_inject_tag; + } +} + +static bool ufs_fault_inject_exec_req(UfsRequest *req) +{ + UfsHc *u =3D req->hc; + + if (likely(u->active_fault_inject_tag =3D=3D UFS_FAULT_INJECT_TAG_NONE= ) || + u->held_req !=3D NULL || + req->req_upiu.header.trans_type !=3D UFS_UPIU_TRANSACTION_COMMAND)= { + return false; + } + + if (u->active_fault_inject_tag =3D=3D UFS_FAULT_INJECT_TAG_ANY) { + uint8_t op =3D req->req_upiu.sc.cdb[0]; + uint64_t lba =3D 0; + bool is_match =3D false; + + if (op =3D=3D READ_10 || op =3D=3D WRITE_10) { + /* + * In 10-byte SCSI read/write commands (SBC-4), bytes 2..5 + * encode the 32-bit Logical Block Address (LBA) in + * big-endian. + */ + lba =3D ldl_be_p(&req->req_upiu.sc.cdb[2]); + is_match =3D (lba >=3D UFS_FAULT_INJECT_MIN_LBA); + } else if (op =3D=3D READ_16 || op =3D=3D WRITE_16) { + /* + * In 16-byte SCSI read/write commands (SBC-4), bytes 2..9 + * encode the 64-bit Logical Block Address (LBA) in + * big-endian. + */ + lba =3D ldq_be_p(&req->req_upiu.sc.cdb[2]); + is_match =3D (lba >=3D UFS_FAULT_INJECT_MIN_LBA); + } + + /* + * Only intercept target I/O targeting LBA >=3D + * UFS_FAULT_INJECT_MIN_LBA. Skips guest boot-time partition + * table and superblock scanning. + */ + if (is_match) { + u->active_fault_inject_tag =3D req->req_upiu.header.task_tag; + u->held_req =3D req; + trace_ufs_fault_inject_hold_req( + req->req_upiu.header.task_tag, lba); + return true; + } + } else if (req->req_upiu.header.task_tag =3D=3D u->active_fault_inject= _tag) { + u->held_req =3D req; + trace_ufs_fault_inject_hold_req(req->req_upiu.header.task_tag, 0); + return true; + } + + return false; +} + static void ufs_hce_reset(UfsHc *u) { int i; @@ -854,6 +927,8 @@ static void ufs_hce_reset(UfsHc *u) memset(u->mcq_op_reg, 0, sizeof(u->mcq_op_reg)); } =20 + ufs_fault_inject_hce_reset(u); + u->resetting =3D false; =20 /* 5. De-assert IRQ */ @@ -2432,6 +2507,10 @@ static void ufs_exec_req(UfsRequest *req) return; } =20 + if (ufs_fault_inject_exec_req(req)) { + return; + } + switch (req->req_upiu.header.trans_type) { case UFS_UPIU_TRANSACTION_NOP_OUT: req_result =3D ufs_exec_nop_cmd(req); @@ -3058,8 +3137,93 @@ static void ufs_init_hc(UfsHc *u) =20 timer_init_ms(&u->idle_timer, QEMU_CLOCK_VIRTUAL_RT, ufs_idle_timer_cb= , u); timer_mod(&u->idle_timer, now + UFS_IDLE_TIMER_TICK); + + ufs_fault_inject_init(u); } =20 +const QEnumLookup UfsFaultInjectMode_lookup =3D { + .array =3D (const char *const[]) { + [UFS_FAULT_INJECT_ABORT_SUCCESS] =3D "abort-success", + [UFS_FAULT_INJECT_ABORT_FAILED] =3D "abort-failed", + [UFS_FAULT_INJECT_IN_TRANSITION] =3D "in-transition", + [UFS_FAULT_INJECT_TIMEOUT] =3D "timeout", + }, + .size =3D UFS_FAULT_INJECT_MODE_MAX, +}; + +static void ufs_prop_get_fault_inject_tag(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + uint32_t *ptr =3D object_field_prop_ptr(obj, prop); + UfsParams *params =3D container_of(ptr, UfsParams, fault_inject_tag); + UfsHc *u =3D container_of(params, UfsHc, params); + + visit_type_uint32(v, name, &u->active_fault_inject_tag, errp); +} + +static void ufs_prop_set_fault_inject_tag(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + uint32_t *ptr =3D object_field_prop_ptr(obj, prop); + UfsParams *params =3D container_of(ptr, UfsParams, fault_inject_tag); + UfsHc *u =3D container_of(params, UfsHc, params); + uint32_t val; + + if (!visit_type_uint32(v, name, &val, errp)) { + return; + } + + if (val > 255 && val !=3D UFS_FAULT_INJECT_TAG_NONE && + val !=3D UFS_FAULT_INJECT_TAG_ANY) { + error_setg(errp, + "invalid %s %u: must be 0..255, 0x%x (none), or 0x%x (a= ny)", + name, val, UFS_FAULT_INJECT_TAG_NONE, + UFS_FAULT_INJECT_TAG_ANY); + return; + } + + if (u->held_req !=3D NULL) { + error_setg(errp, + "cannot change %s while a request (tag %u) is held", + name, u->held_req->req_upiu.header.task_tag); + return; + } + + *ptr =3D val; + u->active_fault_inject_tag =3D val; + trace_ufs_fault_inject_set_tag(val); +} + +static void ufs_prop_set_default_fault_inject_tag(ObjectProperty *op, + const Property *prop) +{ + object_property_set_default_uint(op, prop->defval.u); +} + +const PropertyInfo ufs_prop_fault_inject_tag =3D { + .type =3D "uint32", + .description =3D "Task tag to hold for fault injection", + .get =3D ufs_prop_get_fault_inject_tag, + .set =3D ufs_prop_set_fault_inject_tag, + .set_default_value =3D ufs_prop_set_default_fault_inject_tag, + .realized_set_allowed =3D true, +}; + +const PropertyInfo ufs_prop_fault_inject_mode =3D { + .type =3D "UfsFaultInjectMode", + .description =3D "Fault injection mode: abort-success, abort-failed, " + "in-transition, timeout", + .enum_table =3D &UfsFaultInjectMode_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, + .realized_set_allowed =3D true, +}; + bool ufs_realize(UfsHc *u, DeviceState *dev, AddressSpace *dma_as, Error *= *errp) { u->dev =3D dev; diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h index 15b3a352f3b..80bdaa1a2aa 100644 --- a/hw/ufs/ufs.h +++ b/hw/ufs/ufs.h @@ -90,6 +90,56 @@ typedef struct UfsLu { UfsScsiOp scsi_op; } UfsLu; =20 +/* + * Fault injection modes for x-fault-inject-mode property. + * Controls how the held transfer request and subsequent Task Management + * Request (TMR) are resolved by the controller: + * + * UFS_FAULT_INJECT_ABORT_SUCCESS: TMR ABORT_TASK aborts the held request, + * clears its state, and returns SUCCESS + * (COMPL). + * UFS_FAULT_INJECT_ABORT_FAILED: TMR ABORT_TASK returns + * TASK_MANAGEMENT_FUNC_FAILED, forcing ho= st + * driver to escalate to Host Reset. + * UFS_FAULT_INJECT_IN_TRANSITION: TMR QUERY_TASK releases the held reques= t to + * execute normally through the SCSI layer= and + * returns the real task status (SUCCEEDED= while + * the command is still in flight); + * ABORT_TASK cancels the held request and + * returns FUNCTION_COMPLETE. + * UFS_FAULT_INJECT_TIMEOUT: TMR ABORT_TASK does not complete or cle= ar + * doorbell, triggering hardware-level TMR + * timeout. + */ +typedef enum UfsFaultInjectMode { + UFS_FAULT_INJECT_ABORT_SUCCESS =3D 0, + UFS_FAULT_INJECT_ABORT_FAILED, + UFS_FAULT_INJECT_IN_TRANSITION, + UFS_FAULT_INJECT_TIMEOUT, + UFS_FAULT_INJECT_MODE_MAX, +} UfsFaultInjectMode; + +/* + * Sentinel values for x-fault-inject-tag property. + * Task Tags in UFS are 8-bit (0..255). Values >=3D 256 are reserved as + * sentinel flags to preserve full testability of Tag 0. + * + * UFS_FAULT_INJECT_TAG_NONE: Disable fault injection (default). + * UFS_FAULT_INJECT_TAG_ANY: Automatically intercept the first user-space + * READ_10, WRITE_10, READ_16, or WRITE_16 comm= and + * targeting LBA >=3D UFS_FAULT_INJECT_MIN_LBA. + */ +#define UFS_FAULT_INJECT_TAG_NONE 0xffffffff +#define UFS_FAULT_INJECT_TAG_ANY 0xfffffffe + +/* + * Minimum Logical Block Address (LBA) for automatic fault injection. + * Skip early disk blocks (LBA 0..511, e.g. MBR, GPT partition tables, EFI, + * and filesystem superblocks) to ensure guest OS boot-time disk discovery + * and partition scanning complete cleanly without being held. + */ +#define UFS_FAULT_INJECT_MIN_LBA 512 + typedef struct UfsParams { char *serial; uint8_t nutrs; /* Number of UTP Transfer Request Slots */ @@ -99,6 +149,8 @@ typedef struct UfsParams { uint8_t mcq_maxq; /* MCQ Maximum number of Queues */ uint32_t wb_max_size; /* WB Maximum allocation units */ uint32_t wb_min_size; /* WB Minimum allocation units */ + uint32_t fault_inject_tag; + UfsFaultInjectMode fault_inject_mode; } UfsParams; =20 /* @@ -188,6 +240,10 @@ typedef struct UfsHc { uint32_t hid_fragment_count; /* Remaining fragmented 4KB units */ uint32_t hid_defrag_total; /* Requested units at defrag start */ uint32_t hid_defrag_remaining; /* Requested units left to move */ + + /* Test and fault injection properties */ + uint32_t active_fault_inject_tag; + UfsRequest *held_req; } UfsHc; =20 static inline uint32_t ufs_mcq_sq_tail(UfsHc *u, uint32_t qid) @@ -312,4 +368,9 @@ void ufs_init_wlu(UfsLu *wlu, uint8_t wlun); bool ufs_realize(UfsHc *u, DeviceState *dev, AddressSpace *dma_as, Error **errp); void ufs_unrealize(UfsHc *u); + +extern const PropertyInfo ufs_prop_fault_inject_tag; +extern const PropertyInfo ufs_prop_fault_inject_mode; +extern const QEnumLookup UfsFaultInjectMode_lookup; + #endif /* HW_UFS_UFS_H */ --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348248; cv=none; d=zohomail.com; s=zohoarc; b=Q111M4z11i3R09j0P9MRmp1RD2i/1btJlurPbMWuR4fP0VyL5kC6z1y5Xcwh3ZBsT8OTcR38HHMhvdjPLjuH7GsFm0YbpgU3zd4V3zPPb6csppUIBWbquT/LastPAHj3PC+KpgC8xBWwW3v0kaCCY2pJQSsejcYLntL8lnYqeWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348248; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ayIuClwUin4beqwJzWu7BwW7Km9Z24gdUDZznk+CoGU=; b=EDNON/sbNgVzA7FOl/4h1TdOjZ9l9mC98+Dhbngfk5+j14d9t0uNyJ4Kig7om3C1ZfY5JgzE7YmfX8QF6Igc6TpN3UnC55hPP0YzbBkI4hWiyAM188J41x9Z9OSbQTBoznG7+emaMc0ycQs6f8biOKeJU4wMsTRTCfwcTjUiRzQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179334824860249.76258259469023; Fri, 30 Oct 2026 01:17:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhlx-0006Tj-9L; Fri, 30 Oct 2026 04:15:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlf-0006MU-3Z for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:20 -0400 Received: from mail-dy1-x1335.google.com ([2607:f8b0:4864:20::1335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlc-0001aR-U8 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:18 -0400 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-36a17a332ecso835248eec.1 for ; Fri, 30 Oct 2026 01:15:16 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348115; x=1793952915; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ayIuClwUin4beqwJzWu7BwW7Km9Z24gdUDZznk+CoGU=; b=vpDNoB24j9PlktZ2KIS809gFfx7WZS+nx4iAyqbR6m2G8y4qA8E9OqLrkLZFya9Vey 63wCE6Gk4+WFxx94AUsNr+CuyPRXZuoIuHejTJ6ACUYeP6XXJgwlgr480+rz5wko7zj+ gKpl0UsNPAIXHUdosOZ3dNzdoMknSlIsuWNc6zcI7QmcBSgGhFEW8mGUHptZrXfGL+z3 B+w7VmfHMjAgFgrANY1ALCmlNspmAZKtLROncriZ3I3ggKSTsPccoDThjKNDkY+YRN9x K51xzuxTCMURrbrzBvQ/7U7t46JTsV/7s84Ajta015I4TGtsALxpbX3kM6tkMv2Awqkg w3Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348115; x=1793952915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ayIuClwUin4beqwJzWu7BwW7Km9Z24gdUDZznk+CoGU=; b=GbxvlSKxGGmQchIEdgT2vTm8Nj58U89YLbsBMXaAjMf1jI6fuu3bsWR/UIDb7yqjZj GSuA+2uIrdMN757GoierVFCKp+r/l+3xCZZYWrZQF6I6Ehp1AxoyUWLmM/101TyOW8vt 2coO3SSp2mUIZljzvutwDnEwgyNy4jGWf7ce2qu8WrnAXYaJxdHSQ9dLl9pCeWFVZBcW srG9rPbrJo79cC2/haogkElYAA1BOcixY8yP45lyR+QxbytqFEVKSyFE9VFh/9lgLUq+ esylnMbs2mZXxBerTh7bcsOutj9aFIrZM7cCEZCJ6M8RlssBP4o0DsbfNJq6BCNmWdf3 Yr5A== X-Gm-Message-State: AFq9FYJ8Fu6ETNhd4B2Qd5lFpleMZwakmNMv+Jo1JVN+zLasgquhvXHA 8RBUHAg6ZWmEXuGuxa3d3TohGTk8BbxgvuurCd9FzCoysqcaJOPgQyOHED0B5g== X-Gm-Gg: AYBFou0GNIr+OBooeb17/9RHSPx1nmRGbz9F1nOwqstG7gkOBb7QJsfY7Z3PNmBcscw Tpmmy3h5ef9m1dG4GZIg39cR/RZ1xdiMeNSkDGIgdCtS5sZDloqOG9Wj/lrLoHBZeiFkLQAbCxm /lu1J6NwTrwwErVQQEinvxw6a7rm9iuQ0dBYsQVDuHa78NLaVMJAqVFn/Fv6cS/ivEjJhzQ94ie 3S1Hsp/74LO7cTGOoMaKV2F17ojveB2jzvYaLefJ+QtB1mucJ5xobbanP7ewBSIhw/Npwn0wNqS DrsIdjf2h4wu0H/F6kfcgO/f+5SHAQOjlUGNjnQ7slncHnJ2N1Oq0BCe6HyiQo6uW7d/lLlgo2R g5IOKAQTELjXClcKGmX+TNkjdjkyXEatGrEJxaIkSKBH4cCKhZc639tT3oU5X9LmFfYGiycMpON i1NbqWNK5oTGq4eTmr49CecE/IK4OT9Y8IhAXt7V1N2z8KtF8CVeOqmFeJH5BqyQS5DrUMoHU0N yqRc71MV2mQvM/52AK/BWS/IJkZeoCQ/OUxvEwsUCLkfkLQLn2hkVPPiCpUmL55mAlJXikvmPtS p+nlnQRKjHuZHdZCBYPX3CVxlrpyEPWSg6kHXeZaaSKNViiWOK55t4goUqokHEvLtaM1hzeOf54 TZ0dl+hb9I/U= X-Received: by 2002:a05:701b:42c5:10b0:193:3274:aac with SMTP id a92af1059eb24-1ac5fd05d6bmr2160351c88.37.1793348115081; Fri, 30 Oct 2026 01:15:15 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 06/12] hw/ufs: Handle task management requests for fault-injected held requests Date: Fri, 30 Oct 2026 17:14:32 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1335; envelope-from=jeuk20.kim@gmail.com; helo=mail-dy1-x1335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 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: 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348248886158500 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Wire up Task Management Request (TMR) and MCQ submission queue cleanup handling for transfer requests held by x-fault-inject-tag according to x-fault-inject-mode: - "abort-success": UFS_QUERY_TASK returns UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED. UFS_ABORT_TASK cancels the underlying SCSI request and marks the MCQ request in error state for SQRTC.ICU cleanup (or clears the legacy UTRL slot), then returns UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL. - "abort-failed": UFS_ABORT_TASK returns UFS_UPIU_TASK_MANAGEMENT_FUNC_FAILED while keeping the request held. - "in-transition": UFS_QUERY_TASK releases the held transfer request and executes it through the normal SCSI command path, completing with genuine device I/O and CQE generation, while returning UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED per SAM-5 task set rules. UFS_ABORT_TASK releases the held request to generic abort processing. - "timeout": UFS_ABORT_TASK skips completion so the host driver hits its TMR timeout path. Also clear u->held_req and disarm active_fault_inject_tag when an MCQ submission queue containing the held request is cleaned up via ufs_mcq_sq_cleanup(). Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/ufs.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index 1a5bc54eac4..83d5fc24414 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -37,6 +37,7 @@ #define UFS_HID_PROGRESS_COMPLETE 100 =20 static void ufs_exec_req(UfsRequest *req); +static void ufs_fault_inject_execute_held_req(UfsRequest *hreq); static void ufs_clear_req(UfsRequest *req); static void ufs_mcq_process_cq(void *opaque); =20 @@ -797,6 +798,67 @@ static void ufs_fault_inject_hce_reset(UfsHc *u) } } =20 +static bool ufs_fault_inject_tmr(UfsHc *u, uint8_t tm_func, uint8_t lun, + uint32_t task_tag, uint8_t *tm_resp, + bool *skip_completion) +{ + UfsRequest *hreq =3D u->held_req; + + *skip_completion =3D false; + if (!hreq || task_tag !=3D u->active_fault_inject_tag || + hreq->req_upiu.header.lun !=3D lun) { + return false; + } + + if (tm_func =3D=3D UFS_QUERY_TASK) { + if (u->params.fault_inject_mode =3D=3D UFS_FAULT_INJECT_IN_TRANSIT= ION) { + u->held_req =3D NULL; + u->active_fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + u->params.fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + ufs_fault_inject_execute_held_req(hreq); + return false; + } + /* + * Generic QUERY TASK in ufs_process_tmr() will check + * ufs_find_req_by_tag() and return SUCCEEDED for the held request. + */ + return false; + } + + if (tm_func =3D=3D UFS_ABORT_TASK) { + if (u->params.fault_inject_mode =3D=3D UFS_FAULT_INJECT_ABORT_FAIL= ED) { + *tm_resp =3D UFS_UPIU_TASK_MANAGEMENT_FUNC_FAILED; + return true; + } + if (u->params.fault_inject_mode =3D=3D UFS_FAULT_INJECT_TIMEOUT) { + *skip_completion =3D true; + return true; + } + + /* + * UFS_FAULT_INJECT_ABORT_SUCCESS, UFS_FAULT_INJECT_IN_TRANSITION, + * or default: + * Release the fault-injection hold, then let generic ABORT TASK + * in ufs_process_tmr() handle cancellation. + */ + u->held_req =3D NULL; + u->active_fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + u->params.fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + return false; + } + + return false; +} + +static void ufs_fault_inject_sq_cleanup(UfsHc *u, UfsRequest *req) +{ + if (u->held_req =3D=3D req) { + u->held_req =3D NULL; + u->active_fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + u->params.fault_inject_tag =3D UFS_FAULT_INJECT_TAG_NONE; + } +} + static bool ufs_fault_inject_exec_req(UfsRequest *req) { UfsHc *u =3D req->hc; @@ -980,6 +1042,7 @@ static void ufs_process_tmr(UfsHc *u, uint32_t val) UtpTaskReqDesc desc; uint8_t tm_func, tm_resp, lun; uint32_t task_tag; + bool skip_completion =3D false; =20 if (ufs_addr_read(u, desc_addr, &desc, sizeof(desc))) { continue; @@ -989,7 +1052,12 @@ static void ufs_process_tmr(UfsHc *u, uint32_t val) lun =3D desc.upiu_req.req_header.lun; task_tag =3D be32_to_cpu(desc.upiu_req.input_param2); =20 - if (tm_func =3D=3D UFS_QUERY_TASK) { + if (ufs_fault_inject_tmr(u, tm_func, lun, task_tag, &tm_resp, + &skip_completion)) { + if (skip_completion) { + continue; + } + } else if (tm_func =3D=3D UFS_QUERY_TASK) { UfsRequest *req =3D ufs_find_req_by_tag(u, lun, task_tag); =20 if (req) { @@ -1257,6 +1325,7 @@ static void ufs_mcq_sq_cleanup(UfsHc *u, uint8_t qid) } =20 if (req) { + ufs_fault_inject_sq_cleanup(u, req); if (req->sreq !=3D NULL) { SCSIRequest *sreq =3D req->sreq; req->sreq =3D NULL; @@ -2537,6 +2606,16 @@ static void ufs_exec_req(UfsRequest *req) } } =20 +static void ufs_fault_inject_execute_held_req(UfsRequest *hreq) +{ + UfsReqResult req_result; + + req_result =3D ufs_exec_scsi_cmd(hreq); + if (req_result !=3D UFS_REQUEST_NO_COMPLETE) { + ufs_complete_req(hreq, req_result); + } +} + static void ufs_process_req(void *opaque) { UfsHc *u =3D opaque; --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348210; cv=none; d=zohomail.com; s=zohoarc; b=jk810jyDiS1r8TWDB/ptzalnBfMV6cHctglu+66my6rqzhmP/4jf9WHfH0lqJf3/LOBSkfflrX0K2KPYcXZRz8Fzjt/QWF3/3M8MRfIiMjrefTXjSmCo4tmgKeD3r9F6ikvdOa2tTKdAKOn//Dh1hfa1cqWRFi5/Gt5OXS+1qro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348210; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+XCn0sBHOYbsfWPGiKYrhq0BRf7HOq+gvrjL/gS0UZo=; b=nWv8aQ8X6LkvCcCAAaGLbtBCaS9cUdD2FYRng2wMZBM2qLFk2M2kcSmU7VT+l87wHwbJ8PMGBvWcgQMqtNTCb1lqIFklrEPeZOyzjvwGlRfSMDRQvgYlqikJ6KWKLpzuo8nhrH8edigWX1UI4aLmXt2Pj6QXbDsvgnnhoAWKbh8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17933482100841006.7008934748424; Fri, 30 Oct 2026 01:16:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhlz-0006Wc-Or; Fri, 30 Oct 2026 04:15:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhli-0006NS-8Q for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:22 -0400 Received: from mail-dl1-x1235.google.com ([2607:f8b0:4864:20::1235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlg-0001b0-G9 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:21 -0400 Received: by mail-dl1-x1235.google.com with SMTP id a92af1059eb24-19305bcb72cso300325c88.1 for ; Fri, 30 Oct 2026 01:15:19 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348118; x=1793952918; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+XCn0sBHOYbsfWPGiKYrhq0BRf7HOq+gvrjL/gS0UZo=; b=oOiEQjDYL7DJuVfy+K5kHTd4umxDsK0QUrqzAc/6hCG4vbxy0cX++iXbQAQ68wgs4I RkT1/SWlPjhVQliMJd90wLFR7eZIgTY50vdsX7ErSU72ytukVnAE9sMT9kqpH6Wvwyzw 5bBzZa4sSW2X9mcey3HGRDsyKP8HcypHdOeHLXGPcjO+lwaPIgCUY/XGqwZqH7/PRA7n hoV45n+puRnvgIKAhVlf+O3vl3eSeirNhCPS5KhOxZWVc5QGECeL04nCHC+3TgT7Am8N cBjiQZAeROftS+6ELF/uDzWCYFGc1CQaE3mKw33gbfNNpC6gNDdkvkpLxHvKjQb+Tf7e rXUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348118; x=1793952918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+XCn0sBHOYbsfWPGiKYrhq0BRf7HOq+gvrjL/gS0UZo=; b=SRTz0CjLCtk47TRUt2LM8PlOxajLDxy80BK2mepMh3FR5ZLOPSr4KGN7Np3Tu2unWT btVVhbBRi8H1Km9UDDwgzXAcoPCzJzONYzpFXFDo1W1M5xtOnmgsv9EFAYY0V4xJgfJi XMSCGigOJR38rJt8oTV7imeoCblQgtePRfzsOhRw3xcDCj0yWJTKEx0juKohipagtILb 2tP8emBI0Q9rAr89ZcF8i8Suekkxm7z9NMIxyR8p/P5eRJTbxy1PCebzaq9V5W16veuj vSomLH7wrl1Aa2RAqhQNLhqHOwcv9hzHfczykq6x8H2j7IR8PRaAota2tyDOvWxt5Eil NOdA== X-Gm-Message-State: AFq9FYJhrkIDXexyj/uYzrBY8TDsTdt3gBFi5HFz/OrdlAMonB54zG3S 0pV+REW9KjVvuLJmw5wnpR6eQ7RyzawVLLOqvIUvTC9/1Vg06yKNwz6HSbL9sA== X-Gm-Gg: AYBFou2kRbRTuq9jDPuZhRf0Tuy1829CJPgK092Ns7/48UW5QZDGlc7Q1j2WTfQ3KAo wRU7cS4r62d0jm+DDTDoyp5lX/5KKnDGfdddrE8aCHTk3BUqxSu/KEFkjNI7sjj8+DcBwIHoB+Z DnrQ7K8Kumh8l0Odiv4i8ZyLDJsYTE0iIcxtdD3KITXrxOvP3qoPHjFuA2yH8Xpu6DCf4ExZLk2 2ks8pOqUdyWfM3eMLmVP3tKVHc+JEgDZifLMqBq4zl4jAh0gUTv9wikBVcZ5xpDRJmJS4U0a+XB tpGDRmGqy8NP8xLw8XNgR4nmvQfDLdyT3DQ7HL7H1VfDo3wC3IRutRtJtD04trOMIhzv3X1YtY/ Uy6VHDJWYG4SH9j5tlXOzis1NFFFO7P2/xHepLlGPwOXi1MfMeelToZLEt04z7g1HBDjPByLB/V cpogAEnDGcN+eZ0YDXKPz/3bbycoK86FXjbQcK4t0C8RTGYwKhKvoZvu3DB6OHLTY+jVdJ3dfOe 9UMtq79IQHAZWAMeOM7zTccYFEbroQS2sxJaNEg6BkE/uH7XHrVHI07xHj+c8VYrtS7ZPsU16sh 2Kp2azPw3kl5Gf5jg5u4o/7BM1VY2YOvRegSHx/1k5iIRb0hUcVGeh4CN+GTSHAqYg== X-Received: by 2002:a05:7022:1507:b0:149:49c:233 with SMTP id a92af1059eb24-1ac5bbb5048mr2621707c88.27.1793348118159; Fri, 30 Oct 2026 01:15:18 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 07/12] hw/ufs: Add ssu-timeout mode for power management recovery testing Date: Fri, 30 Oct 2026 17:14:33 +0900 Message-ID: <0c6b9e77fbd1ecd3888c6a694349a3cec7ad6256.1793347487.git.jeuk20.kim@samsung.com> X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1235; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348213252154100 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Extend the experimental fault injection property x-fault-inject-mode with a new "ssu-timeout" mode to facilitate automated testing of host driver power management and Start Stop Unit (SSU) recovery handling. When x-fault-inject-mode=3D"ssu-timeout" is set and x-fault-inject-tag is armed (e.g., 0xfffffffe for any tag, or a matching tag), the controller only intercepts SCSI START_STOP (0x1B) commands sent to the UFS Device Well-Known LUN (WLUN) and holds them without queuing them to the SCSI layer, while letting non-SSU commands complete normally. This triggers the host driver's 10-second SSU command timeout and subsequent power management recovery routines (e.g., during suspend-to-idle or freeze transitions), verifying host error recovery and link restoration paths. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- hw/ufs/ufs.c | 19 +++++++++++++++++-- hw/ufs/ufs.h | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c index 83d5fc24414..f8da7c9554c 100644 --- a/hw/ufs/ufs.c +++ b/hw/ufs/ufs.c @@ -862,6 +862,7 @@ static void ufs_fault_inject_sq_cleanup(UfsHc *u, UfsRe= quest *req) static bool ufs_fault_inject_exec_req(UfsRequest *req) { UfsHc *u =3D req->hc; + uint8_t op; =20 if (likely(u->active_fault_inject_tag =3D=3D UFS_FAULT_INJECT_TAG_NONE= ) || u->held_req !=3D NULL || @@ -869,8 +870,21 @@ static bool ufs_fault_inject_exec_req(UfsRequest *req) return false; } =20 + op =3D req->req_upiu.sc.cdb[0]; + if (u->params.fault_inject_mode =3D=3D UFS_FAULT_INJECT_SSU_TIMEOUT) { + if (op =3D=3D START_STOP && + req->req_upiu.header.lun =3D=3D UFS_UPIU_UFS_DEVICE_WLUN && + (u->active_fault_inject_tag =3D=3D UFS_FAULT_INJECT_TAG_ANY || + req->req_upiu.header.task_tag =3D=3D u->active_fault_inject_t= ag)) { + u->active_fault_inject_tag =3D req->req_upiu.header.task_tag; + u->held_req =3D req; + trace_ufs_fault_inject_hold_req(req->req_upiu.header.task_tag,= 0); + return true; + } + return false; + } + if (u->active_fault_inject_tag =3D=3D UFS_FAULT_INJECT_TAG_ANY) { - uint8_t op =3D req->req_upiu.sc.cdb[0]; uint64_t lba =3D 0; bool is_match =3D false; =20 @@ -3226,6 +3240,7 @@ const QEnumLookup UfsFaultInjectMode_lookup =3D { [UFS_FAULT_INJECT_ABORT_FAILED] =3D "abort-failed", [UFS_FAULT_INJECT_IN_TRANSITION] =3D "in-transition", [UFS_FAULT_INJECT_TIMEOUT] =3D "timeout", + [UFS_FAULT_INJECT_SSU_TIMEOUT] =3D "ssu-timeout", }, .size =3D UFS_FAULT_INJECT_MODE_MAX, }; @@ -3295,7 +3310,7 @@ const PropertyInfo ufs_prop_fault_inject_tag =3D { const PropertyInfo ufs_prop_fault_inject_mode =3D { .type =3D "UfsFaultInjectMode", .description =3D "Fault injection mode: abort-success, abort-failed, " - "in-transition, timeout", + "in-transition, timeout, ssu-timeout", .enum_table =3D &UfsFaultInjectMode_lookup, .get =3D qdev_propinfo_get_enum, .set =3D qdev_propinfo_set_enum, diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h index 80bdaa1a2aa..7ddc5405465 100644 --- a/hw/ufs/ufs.h +++ b/hw/ufs/ufs.h @@ -110,12 +110,16 @@ typedef struct UfsLu { * UFS_FAULT_INJECT_TIMEOUT: TMR ABORT_TASK does not complete or cle= ar * doorbell, triggering hardware-level TMR * timeout. + * UFS_FAULT_INJECT_SSU_TIMEOUT: Intercepts SCSI START_STOP (0x1B) comma= nds + * targeting the UFS Device WLUN when + * x-fault-inject-tag is armed. */ typedef enum UfsFaultInjectMode { UFS_FAULT_INJECT_ABORT_SUCCESS =3D 0, UFS_FAULT_INJECT_ABORT_FAILED, UFS_FAULT_INJECT_IN_TRANSITION, UFS_FAULT_INJECT_TIMEOUT, + UFS_FAULT_INJECT_SSU_TIMEOUT, UFS_FAULT_INJECT_MODE_MAX, } UfsFaultInjectMode; =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348215; cv=none; d=zohomail.com; s=zohoarc; b=DsfS1CHEJoEHSYiSu5jCc5yrC+HndCyLbQ157CrmTHSwVj9/8rMu0qfgfPCb8HCbkKmvucPqX4YhIiJ9PLNSn9dkVwAnTGszPC+Z2g9tYBtK0NPxZGq0OFusrT20etPnfVxIl8Ks286t5RTxX05d7JXZAxR77LcYLZVU4nX1bBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348215; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VZTk+bWZv9HgKLG3yBi98N6JwFOQooDFPJWrumdsr+A=; b=CCGDvzfa4GAGpWzegqIVsJ8lteTK01dDZYDZSyZQKFW1MRQUQJeRs+/2i5LVQI5A9LSASDhFyib/VGuNcTmkskjtTQsNIlFmh/ucMBA7k5af+ICCXGY+Nky8EhLkNa7YFXwXwORY6J5higYZZOy2+eZDWiBz4YZsWIiJybu8enk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348215978863.4408006244058; Fri, 30 Oct 2026 01:16:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhlz-0006Vg-6s; Fri, 30 Oct 2026 04:15:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlm-0006Pu-EM for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:30 -0400 Received: from mail-dl1-x1231.google.com ([2607:f8b0:4864:20::1231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhli-0001bU-H3 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:25 -0400 Received: by mail-dl1-x1231.google.com with SMTP id a92af1059eb24-15dd124bbe7so749531c88.1 for ; Fri, 30 Oct 2026 01:15:22 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348121; x=1793952921; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VZTk+bWZv9HgKLG3yBi98N6JwFOQooDFPJWrumdsr+A=; b=Xjjit7SCWObbJtbSAfxPAbc6J8DVvpFE4MyRUlbo+j48s3C7pKBSEe29cnOi+2mR7w QlnzryDsmQWQShRcAcnDnpAffnLQqLZwp3qmv3mO0ew17lVH+i7/SVmiUzamUHLOCqAc SopPUZB+ST68ofTjTMmvEOe0b2hPEx848AfFnRluo+98kNGvnSnH5W0MqbW27qJAyo7+ OZr7P1JwdoLiEy03eDLuDNaL53X97vTwgQTOhAw6phlJKPRs3jiviH60ccRTkat/Gdfg q7kO+dK5YltcND4vQCYu/itLPr5DoJYUCcThAEM1tRhTsLYajzINl2SvyE5JPvbR5V9n t17w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348121; x=1793952921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VZTk+bWZv9HgKLG3yBi98N6JwFOQooDFPJWrumdsr+A=; b=FI1P3FOs0gW0G4JR3p+ILTlJgJuLqk+vWMJgyCD7/W6/ILNPsNLtsnBZ9K4nylivZ3 2IxMRoY2TMXdHRd6izntmcMc6LlO1HljLX9SWJ7VblfA4JOVm0o5F29D/KLSduCt+3AR f+ffLuwQUCAxcwjvXDKUeGr0/sA1MhoMQ/iWLU+mnfQGMi6FRB2sHboDSdA3dvuAISE9 g3wbEcyZVlNo2qqg+3aJBHbEr1vtF0w9tStshMAcn1UN5CVQe26tvJu92ujwjDLNca/e a0GUvCxox7PvN0eyDGUbKXgcTBXxi0JuNqJOB+nRvWb8RSy1269lJUdfEE2H0G7cNEWj G4JA== X-Gm-Message-State: AFq9FYIjdSPPfZM/R5QudVZquQW0myMfV5QHGsdZdXYJHtty0HmlP2A4 JSb9s/irMzCK388b6+BRB4aFNnVoUzHOHZRXNn8scrMfPrlVCaJ66g5m/7B9AQ== X-Gm-Gg: AYBFou0WqnneNSVTInE09fw+S+TJSnkHPQXWiZUX35VOgw7PtnqrKgWIXVASObIjD+4 4iQSUlALImbJ6gTtxwUlgBjU9v19SRI2YZKgfQ88BS5L7W8qcuMLMdcNJPGjkJp6zP4HzTxVbzJ vuWMQl3OQXENBR/E3Bibpasm1B5zrlZoq6nMc0q2aK+MZRXgUGPcRsqPFDyZB1C+duWKk4Njr1Q +CBQd0TPH9i0/9MKsRB1m3QIjBJ5ncHSG0XZbMllV4AyoqJo3A2yPbg871AzwkkZiW7ebZZ0o1E qHeuyx+r6pPj8z9qB4bVDQJOhqC3OiEaZPbb+5BuO5PkaaYQTEY+5ZrjcDm6uDdBtp3klJEGd9V drLo8KubWtg1yIO2WmVEj0997xoPgADXGF3Xym3PwGPZ0wyrvKKCiWM7fKosKH//Ci4MdPKOago JK3A22SrA4Be8V5tmuwwMH1GY+Dy7KoypbA+Dnuo5q7n4Mlae6L4scIlj9LfQvzpQLjrTh7lEwZ H+REmcSAD4NPQNF45xiUotP+ilCUpqF2JgQZ/gTi0ogiJZ9AmZQ3W9TM1Y7Xj4rDy9N7yqHeovW PxNOpo5q66isoteAptgrkK6lqjyBWfaa2d/Og43L742nOh5zrIgeqmSmutwjSWsjnQ== X-Received: by 2002:a05:701b:4213:20b0:1ab:aaf3:389d with SMTP id a92af1059eb24-1ac55968e30mr2413189c88.1.1793348121118; Fri, 30 Oct 2026 01:15:21 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 08/12] docs/system/ufs: Update task management request support status Date: Fri, 30 Oct 2026 17:14:34 +0900 Message-ID: <86d74cbea5667e2062d924d57ed52a7072570d70.1793347487.git.jeuk20.kim@samsung.com> X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1231; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1231.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348217308154100 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu The task management request (TMR) handling implemented for UFS supports QUERY TASK and ABORT TASK, while other task management functions return TASK MANAGEMENT FUNCTION NOT SUPPORTED. Update the documentation in ufs.rst to reflect the current implementation by removing the outdated note under nutmrs and updating the Limitations section accordingly. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- docs/system/devices/ufs.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/system/devices/ufs.rst b/docs/system/devices/ufs.rst index d3482e92992..7e1fa671ab4 100644 --- a/docs/system/devices/ufs.rst +++ b/docs/system/devices/ufs.rst @@ -51,7 +51,6 @@ Host Controller Properties =20 ``nutmrs`` (default 8, maximum 8) Number of UTP task management request slots advertised to the guest. - Task management requests are not processed yet (see Limitations). =20 ``mcq`` (default off) Advertise Multi-Circular Queue (MCQ) support. When off, the guest @@ -81,8 +80,10 @@ Limitations link startup, DME attribute access and hibernation are handled; DME reads return fixed values, and DME writes, power mode changes and hibernation do not change any link state. -* UTP task management requests are not processed, so a guest that - tries to abort a command or reset a logical unit gets no completion. +* Only the ``QUERY TASK`` and ``ABORT TASK`` UTP task management + requests are supported; other task management functions such as + ``LOGICAL UNIT RESET`` return ``TASK MANAGEMENT FUNCTION NOT + SUPPORTED``. * The Boot and RPMB well-known logical units only answer basic SCSI commands such as INQUIRY; boot and RPMB data access are not emulated. * The device cannot be migrated. --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348177; cv=none; d=zohomail.com; s=zohoarc; b=dn7nF7g5rZHsP0yEC1Zc/DmMkvweQUTtqfQWl6Uo2Xxu5goo5Jw6gW1MqmrtIfcG4Zo/pyAgqJP2gyg7DeUHQVWEX39vDMX7XCscOLaPeD+d1yV+zkZDpYPzRKsx17gOBMowgf2wBbr+wG3FKjWZC1xetShGCnXCLv4+FxbvTwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348177; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UpU5RDRKzNoJvyj8f8RzWBQ1TwN1Z6+4TWa8z4piMBk=; b=nmwU0ocs2hijOagSkIjzfKZAvfzZCsgsxVU4PLJ6+WgU3jSF8G9bNJbB7zIRL3dRtncSR8XNbV/MFNn9V9uKjiYh1JlZ9cmW0qryMeHvQbMaFer8XlkKXYokmzqEuBTI5ROnvB1/svNNrLozAfU764/QSwfm1yKdfahVjnQHuCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348177871775.4148321569729; Fri, 30 Oct 2026 01:16:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhm0-0006XS-Hz; Fri, 30 Oct 2026 04:15:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhls-0006R0-0O for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:36 -0400 Received: from mail-dl1-x1231.google.com ([2607:f8b0:4864:20::1231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlm-0001br-6a for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:31 -0400 Received: by mail-dl1-x1231.google.com with SMTP id a92af1059eb24-1438d9363fbso345169c88.0 for ; Fri, 30 Oct 2026 01:15:25 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348124; x=1793952924; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UpU5RDRKzNoJvyj8f8RzWBQ1TwN1Z6+4TWa8z4piMBk=; b=i+VtY5+f6ShVF/Qax5qWzQRg4qYVpdpA8WNGBO8BTg1o7DFc8sKMperVOdhQuXH5IP qVXpyR0pGNvHh4FYvyJV4AigazJWDI+o57PmaW5Iio3V2PkE2T3N8F8eYjb67iws1D+s Xvb7HYF0hlS8rtGR493VUbTJYNzMVuEnvob60M6Q2vq1k4zxfaqKTsBVqNX5CCa8vCZk yiqTxMexaDN9CfKqrxSlFcIndtK3UsUuJBQ4j5G+nZYtJD2DdFXRJdzO7ljUe5L4MKhP jUegnWz6Upmy5sNYrTI1f6vFxHKVpRiCQi/r4F6x3+2BpUCem7OICBNqHLWYGd1XYg6u Dfug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348124; x=1793952924; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=UpU5RDRKzNoJvyj8f8RzWBQ1TwN1Z6+4TWa8z4piMBk=; b=J090Xh6dc1GysbG8U8OHcot/QEUBPWQmkFspPPj70TaYWGc3u/hCRXJ7wUl9UA+6uG ePu7t7nCqx1M1m/dsjonsDvNdBEA1NG8VjaP+76r4w18JIXVsXh/YRV0XnPV7WCr8NqG d0eYohDrrtGD7ymJFnhoWh2hXOW7X0S/4vlCP3Q1mxV3IRw5ET8QmRj7FK1SHzD7VvOj 7bdIxD7bhwdaI+d1rYk5K1f/knR0lfAfHPfyXRWxyRHpZiQvNILw6KVoYj8p9YhHbn+A hqFAC3wAZjEvWBmRMISeTreGGjOotY0lrw+cB+ZofbiSL2URX3ntaIqbbA+3w5Ujfp3H rIBw== X-Gm-Message-State: AFq9FYKUN2p9Tzi6UQwycNMziMYdkCKocpnuTyVUzCskqgLvbtxxpYOq wIX2n9V2xCWRPClJi5J7juM2hjjMIN9V2kbCLe/8o9cuPmZlqQnvqViNeIh1Wg== X-Gm-Gg: AYBFou0Yx7RR4ttTK3ukOhm+1kO7Gl8uTVOHnc8DFhxDerIBw1oTHk/of/gekd04U4a bSDREf08nr/z3AF8S9HmZtdYlkr/be3DWmRSphr3tHm8RbxzrjyJDcqGKlaVmM3Uefbzv/IUlRP HnWye4tVdPTVSWYoTpk65+bFGpKe2xlLva04LBq1z5MMtbELcupI/s5Pt3MGmOWBUHAavdMm6YQ Jt5T/u6ahs3+nmhNPxTcWCaYY07aX2CSl47Zq+/imUzdK1KkVILK0ywuxZsvDjBQ4iCGMDEHAgo 8ORhAo9ogQRRKPyxqrjZR2YIYZIdgPfdystM/wn4n/JLsqOZb+KvHvfBTbew3X9T502xwKSmmyC h+AcGL1iKtZJUer+5nBBpHLVq8F3pA9a5jIjLiq8qUw2DspVk3hbFow4QPxoOutnYdcVnH+1zTD 99/ViKQ/rowBBnV861bGHgbTCdwECskRZApecIsZ0NHMxvKTYC3JwAnwcBJXA+DwD16iHVlhiN7 NNuHn/C6BzLqBSJNOfkYA6oCeBlnJ/Rs03u32ciV4ZbseBvYtURrgdMH4a1tSCCJhwtxPjllbEp Bf4ly04TQn+pICfghBs+Cip/SO4bl7smFRn/d6z0ZXbyrFgpuWJjA/rDSVL3HIJOIg== X-Received: by 2002:a05:701b:2710:b0:196:7590:8bed with SMTP id a92af1059eb24-1ac55960a88mr2309924c88.2.1793348124495; Fri, 30 Oct 2026 01:15:24 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 09/12] tests/qtest/ufs-test: Add TMR and async MCQ SCSI submission helpers Date: Fri, 30 Oct 2026 17:14:35 +0900 Message-ID: <4da9629dd63c9d92056608b9bbea446004f55431.1793347487.git.jeuk20.kim@samsung.com> X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1231; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x1231.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348180742154100 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Add ufs_send_tmr() and ufs_mcq_send_scsi_cmd_async() helper functions in preparation for UTMRL task management and QOM fault injection unit tests. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- tests/qtest/ufs-test.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index e8993e8c246..2914723430c 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -1899,6 +1899,59 @@ static void ufstest_hid(void *obj, void *data, QGues= tAllocator *alloc) ufs_exit(ufs, alloc); } =20 +static G_GNUC_UNUSED void ufs_send_tmr(QUfs *ufs, uint64_t utmrlba, int sl= ot, + uint8_t tm_func, uint8_t lun, + uint32_t task_tag, + UtpTaskReqDesc *utrd_out) +{ + uint64_t desc_addr =3D utmrlba + slot * sizeof(UtpTaskReqDesc); + UtpTaskReqDesc desc =3D { 0 }; + + desc.header.dword_0 =3D cpu_to_le32(UFS_UTP_REQ_DESC_INT_CMD); + desc.header.dword_2 =3D cpu_to_le32(UFS_OCS_INVALID_COMMAND_STATUS); + + desc.upiu_req.req_header.trans_type =3D UFS_UPIU_TRANSACTION_TASK_REQ; + desc.upiu_req.req_header.query_func =3D tm_func; + desc.upiu_req.req_header.lun =3D lun; + desc.upiu_req.req_header.task_tag =3D 0x10 + slot; + desc.upiu_req.input_param1 =3D cpu_to_be32(lun); + desc.upiu_req.input_param2 =3D cpu_to_be32(task_tag); + + qtest_memwrite(ufs->dev.bus->qts, desc_addr, &desc, sizeof(desc)); + + ufs_wreg(ufs, A_UTMRLDBR, 1 << slot); + ufs_wait_for_irq(ufs); + g_assert_true(FIELD_EX32(ufs_rreg(ufs, A_IS), IS, UTMRCS)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, UTMRCS, 1)); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLDBR) & (1 << slot), =3D=3D, 0); + + qtest_memread(ufs->dev.bus->qts, desc_addr, utrd_out, sizeof(*utrd_out= )); +} + +static G_GNUC_UNUSED int ufs_mcq_send_scsi_cmd_async(QUfs *ufs, uint8_t lu= n, + const uint8_t *cdb) +{ + int cmd_desc_slot =3D alloc_cmd_desc_slot(ufs); + uint64_t req_upiu_addr =3D + ufs->cmd_desc_addr + cmd_desc_slot * UTP_COMMAND_DESCRIPTOR_SIZE; + UtpUpiuReq req_upiu =3D { 0 }; + UtpTransferReqDesc utrd; + + req_upiu.header.trans_type =3D UFS_UPIU_TRANSACTION_COMMAND; + req_upiu.header.flags =3D UFS_UPIU_CMD_FLAGS_NONE; + req_upiu.header.lun =3D lun; + req_upiu.header.task_tag =3D cmd_desc_slot; + memcpy(req_upiu.sc.cdb, cdb, UFS_CDB_SIZE); + qtest_memwrite(ufs->dev.bus->qts, req_upiu_addr, &req_upiu, + sizeof(req_upiu)); + + utrd =3D ufs_build_req_utrd(req_upiu_addr, UFS_UTP_NO_DATA_TRANSFER, 0= ); + __ufs_send_transfer_request_mcq_async(ufs, lun, &utrd); + + return cmd_desc_slot; +} + + static void ufs_register_nodes(void) { const char *arch; --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348208; cv=none; d=zohomail.com; s=zohoarc; b=PX0nMRacgYnA7VCsGjPKonQ1a0GBi5MANmKR20z0hmwFF28GY60vFaQ1aoDL6nTEPICS7WhrjwBOkFSEHQg/S5JEpXUDcVf0XdubwGX2XCiXmZuqMuon3LTWF7uWEMJAi3w1w+3NlAJkvcOpaUbkKu/hY13M/EjH/6uYS17wbK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348208; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=USQSlCDXbe2Po2yshNTH5Baw8p7W0+sQ6ZyjyEsakFc=; b=P2cxpfyXjl728pvlCrx8vzlbZ0Geww1fioxQX1orXG6ZXDpv/f0d/80DxBboiSCO2Wc1zF6Z8W6jbDqfma1lJvsR4sukSZDBepxm99Ri3qdG28EZ/hslWlfDc8u4pWSSCc+dzbZDr10Y2tgxRap+/NFwFJ2NsVTDOKiZDbPk2/o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348208780544.3935822972858; Fri, 30 Oct 2026 01:16:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhm7-0006ik-OF; Fri, 30 Oct 2026 04:15:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhls-0006RC-PA for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:36 -0400 Received: from mail-dl1-x122b.google.com ([2607:f8b0:4864:20::122b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlq-0001cK-E7 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:32 -0400 Received: by mail-dl1-x122b.google.com with SMTP id a92af1059eb24-1931ff67a29so1264801c88.1 for ; Fri, 30 Oct 2026 01:15:28 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348128; x=1793952928; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=USQSlCDXbe2Po2yshNTH5Baw8p7W0+sQ6ZyjyEsakFc=; b=W0XN0OsH6QXknGiPjJHxBHYCg0+LL/Q8emEMe0ZlZSKKi9zDvgZFXlQHUHVMRpzGIU WpXF9eA1dLTFBOOT3DThORg30i+Zc/X6Hea0ETWhEf90mPAf3ad2r5c8hvX8lToAWlZa miLvkNbAWds4kslkQJkdEkCes+79ivkK5Ze+B/G9Ld8KetnLg/XiSDm9IRlJmV5+YeZg W7zdUhRewTe1kXZs3B6RmgV3fvToe1Ojk8q4xugie/+tttr+Ax72nKaK46lD9FwkiUcp yJhw6RlqKGm363+5crfxmKvUqge5t01Bv/AclmlxNaS8MrQMVNfplhYAwttKeGhpsomn Xjkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348128; x=1793952928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=USQSlCDXbe2Po2yshNTH5Baw8p7W0+sQ6ZyjyEsakFc=; b=z8dBGAE8fhixc9pHfskTa5nImo0OWpueABlVBhQVih1pXIViFhDa4xf9hcFFu9FZ7G tjFoC8sM9gUq9D6pJr21cYrfHfeGy1sNASGIeGUYoL2lL9Idp59q5ZwqH0Ha1r1w5kXj 7T5ty8Qq7sCU/KuN9Jvc7s45WtJ02grJvbebdHdDGnHm80C0LhYbK628vAFE4w897gLd Vuag45Zd5eTX+nFm8Ln43GnnYERefErp1/nST/AQIFqPMhVUIJ7PlvPzoeFts4YbjGy4 iWCzgsaNtx1qg1SqB0DdCEYPM5BxIP3ynODaUKGPVqsjC1FyjFDxQrAutD+f4B/AGai/ NRYw== X-Gm-Message-State: AFq9FYLH12KcmJta/EZ7REFfLHvzAKye9yZ6J2pPSX0J/++kKyHDNVEI 55l0YigZ/VKL5PClC6mzOoMRTRJordUVGKVQpcCLyWoQgdVdZAcxPXStLWx6pA== X-Gm-Gg: AYBFou2neihgSYvryw3MW0mZsfKpZNcGz7elI9U7HrAmT0BC+2JAfK70x6xjrLizcd8 CWHFPgOg/MY18FPI95pqYibyNh15iWwHxYjfaG+8OVdGYQIOMJj4NSzh1bNYS/J1aF6soZYYq04 jfa9002g3CUjbb1PuR5lXwygRr8/tiG5dm9T08kWOSo5oqdRqQfbI4V7v9SBnTnerb+LTkwiU3k f2FEbbW7FZcnSDdik7wn+vj39q4YqCoalhfiv/yTUSel7m8l+VKESTdWKgpUwTRLywnDEjh/dZw tnsz8//wFLHv5nPmLkhvBYV/MEHf1k2Rma+PYi/2LbiLdWeOxj/DR7IxbiU5y5rrC01+Hh8Jo68 GLieLgTLpXfCaED1CHZ/8udeM7SHgrBrv/UCegslrv++yfhwVauJ6nD8SlHJcTQyG4pu3Q8kBWy 5wypLXbLnzMPXYTG+WB/1JoGrysU6t8NAZbKb+3skTp/Q+nybf0shR3HbS2f5CXHErVRa2lUeny /ptaPY91gH415bbYOluc/OyebJ3PXOnlQ9/kfelUEkPCPO5NbtaFdyLgxyb33S6HzuD8f8Prh1M s5W4qVEX5gRRGZyltzo/+Y29dWtqd1y1TfD4LM/SHzugT/J1hNu/1IgmsOdoHA6xAQ== X-Received: by 2002:a05:7022:258a:b0:18c:e014:6f1d with SMTP id a92af1059eb24-1ac55f2d3cemr2748373c88.1.1793348127532; Fri, 30 Oct 2026 01:15:27 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 10/12] tests/qtest/ufs-test: Add HCE reset unit test Date: Fri, 30 Oct 2026 17:14:36 +0900 Message-ID: <415c4cf108707a0ba580ba9fa6e2aec17ffd5fc1.1793347487.git.jeuk20.kim@samsung.com> X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::122b; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x122b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348211164154100 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Add ufs_test_hce_reset() to verify HCE 1->0->1 controller reset behavior, checking that UTMRLRSR and dynamic MCQ queue configuration and operational registers reset to 0 while host-configured registers (IE, UTMRLBA/UTMRLBAU, MCQCONFIG) and static capability offsets (SQDAO/CQDAO) are preserved and subsequent I/O succeeds. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- tests/qtest/ufs-test.c | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index 2914723430c..9270e3b137a 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -1952,6 +1952,84 @@ static G_GNUC_UNUSED int ufs_mcq_send_scsi_cmd_async= (QUfs *ufs, uint8_t lun, } =20 =20 +static void ufs_test_hce_reset(void *obj, void *data, QGuestAllocator *all= oc) +{ + QUfs *ufs =3D obj; + uint32_t mcqcap, qcfgptr, mcq_reg_offset; + uint32_t orig_sqdao, orig_cqdao, orig_ie; + enum UtpOcsCodes ocs; + UtpUpiuRsp rsp_upiu; + + ufs_init(ufs, alloc); + g_assert_true(ufs->support_mcq); + + mcqcap =3D ufs_rreg(ufs, A_MCQCAP); + qcfgptr =3D FIELD_EX32(mcqcap, MCQCAP, QCFGPTR); + mcq_reg_offset =3D qcfgptr * 0x200 + TEST_QID * 0x40; + + orig_sqdao =3D ufs_rreg(ufs, mcq_reg_offset + A_SQDAO); + orig_cqdao =3D ufs_rreg(ufs, mcq_reg_offset + A_CQDAO); + orig_ie =3D ufs_rreg(ufs, A_IE); + g_assert_cmpuint(orig_sqdao, !=3D, 0); + g_assert_cmpuint(orig_cqdao, !=3D, 0); + g_assert_cmpuint(orig_ie, !=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_SQATTR), !=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_CQATTR), !=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_sqdao + 0x4), !=3D, 0); + + ufs_wreg(ufs, A_UTMRLBA, 0x1000); + ufs_wreg(ufs, A_UTMRLBAU, 0x1); + ufs_wreg(ufs, A_UTMRLRSR, 1); + ufs_wreg(ufs, A_MCQCONFIG, 0x100); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLRSR), =3D=3D, 1); + + /* Write HCE=3D0 to trigger controller reset */ + ufs_wreg(ufs, A_HCE, 0); + g_assert_cmpuint(FIELD_EX32(ufs_rreg(ufs, A_HCE), HCE, HCE), =3D=3D, 0= ); + g_assert_cmpuint(ufs_rreg(ufs, A_HCS), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLRSR), =3D=3D, 0); + + /* Verify host-configured registers remain preserved across HCE=3D0 */ + g_assert_cmpuint(ufs_rreg(ufs, A_IE), =3D=3D, orig_ie); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLBA), =3D=3D, 0x1000); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLBAU), =3D=3D, 0x1); + g_assert_cmpuint(ufs_rreg(ufs, A_MCQCONFIG), =3D=3D, 0x100); + + /* Verify dynamic queue configuration registers reset to 0 */ + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_SQATTR), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_SQLBA), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_CQATTR), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_CQLBA), =3D=3D, 0); + + /* Verify dynamic MCQ operational registers reset to 0 on HCE=3D0 */ + g_assert_cmpuint(ufs_rreg(ufs, orig_sqdao), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_sqdao + 0x4), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_cqdao), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_cqdao + 0x4), =3D=3D, 0); + + /* Verify read-only capability offsets (SQDAO/CQDAO) remain intact */ + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_SQDAO), =3D=3D, orig= _sqdao); + g_assert_cmpuint(ufs_rreg(ufs, mcq_reg_offset + A_CQDAO), =3D=3D, orig= _cqdao); + + /* Re-enable HCE=3D1 and verify dynamic queue status/pointers remain 0= */ + ufs_wreg(ufs, A_HCE, FIELD_DP32(0, HCE, HCE, 1)); + g_assert_cmpuint(FIELD_EX32(ufs_rreg(ufs, A_HCE), HCE, HCE), =3D=3D, 1= ); + g_assert_cmpuint(ufs_rreg(ufs, orig_sqdao), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_sqdao + 0x4), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_cqdao), =3D=3D, 0); + g_assert_cmpuint(ufs_rreg(ufs, orig_cqdao + 0x4), =3D=3D, 0); + + /* Free previous guest allocations before re-initializing */ + ufs_exit(ufs, alloc); + + /* Re-enable HCE=3D1, re-init controller, and verify normal I/O succee= ds */ + ufs_init(ufs, alloc); + ocs =3D ufs_send_nop_out(ufs, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + + ufs_exit(ufs, alloc); +} + static void ufs_register_nodes(void) { const char *arch; @@ -2012,6 +2090,7 @@ static void ufs_register_nodes(void) &io_test_opts); qos_add_test("query-desciptor", "ufs", ufstest_query_desc_request, &io_test_opts); + qos_add_test("hce-reset", "ufs", ufs_test_hce_reset, &mcq_test_opts); qos_add_test("wb-init", "ufs", ufstest_wb_init, &wb_test_opts); qos_add_test("wb-read-write", "ufs", ufstest_wb_read_write, &wb_test_o= pts); qos_add_test("hid", "ufs", ufstest_hid, &io_test_opts); --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348221; cv=none; d=zohomail.com; s=zohoarc; b=i2RLG0WMe/UYPJdghBSDFbmqhcMfSBZbxG9zTbq83E5Ad5/YGRPnmDVY53LfF/O9ncJZheLuWDoZZinQICdOEqOhM0649a6qdT8nOvBQOgHCf4agb39Ued2nTxacTsqmL0437ThD+ewJnrKGOJJTCh+zeVOcbfcolGh2VHe5M5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348221; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GKP9t/oHs7wOb99z6biNCqhPIdqzJTK+WwxnKi7cqhs=; b=e54v4OhIo2ZwvWxzGxWq0/DL2UrWv7pihr1lK0voBgcjnldHBkRCwPIOD+MfSIe8QYoo1pGKXNsOgMfcCBypfU1QydctSwzKfETD5Xf5vqy20/Dh2hNeTQHPfni+ntMVh3i2K/Qn/90IW6VlrpE5BC0yZ+Up3DLJ9gsleJKVojw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348221143882.6945939178266; Fri, 30 Oct 2026 01:17:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhm1-0006YK-AE; Fri, 30 Oct 2026 04:15:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlu-0006Rb-H2 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:36 -0400 Received: from mail-dl1-x122a.google.com ([2607:f8b0:4864:20::122a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhls-0001ce-6J for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:34 -0400 Received: by mail-dl1-x122a.google.com with SMTP id a92af1059eb24-18cdcfc05ffso549268c88.1 for ; Fri, 30 Oct 2026 01:15:31 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348131; x=1793952931; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GKP9t/oHs7wOb99z6biNCqhPIdqzJTK+WwxnKi7cqhs=; b=NCghRlIn4RBqrdKCXmg5aLJubq/H64dgYzIVhLaa2XEm+ZDNdaDln8lfuwXSCdl7gw PuSDFobRvPyZdnLu/u93hwR98KndnXt8NmRGCdkKvYBDtQQNi7qYg5fyVsoicwEEwAw1 jTehTFqSKlaIPWspydzfvF0bXJZ/GT45t/nHcdcUW+dBCcu2soVWMSgA2NJlwK62pg5Z BjbyxS0myXf0CoeNx6YD9LrUUSi7srtWaogW46B4o+3ZEWvzZXfzeff2525hiiPg3ThM 8M/V5rfxkov3UiHiHeqmlDsrJdKGnexScBHPgmHxBzieqpL6aWAU7X4QLosOJlpgC6VL f9/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348131; x=1793952931; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GKP9t/oHs7wOb99z6biNCqhPIdqzJTK+WwxnKi7cqhs=; b=aFWIo8ki6wjjo9CyRH8zwa4i0nYKiTZuce0J4n8jWbstt4wn/JM0lP5MaXctSI/6lD 4O3eeyhZ07wh4RwOdE/jNprTSQdXRB8IXuxFsv93iOL9VcF7mXhrXA/xN85CXVbz0HfO m0gQrmayaKkADj/8RYV7jbRQMr1wvZr4H6gL36a7+A5eRVJJ2NaxEgjq9eOI4X2Gh4Qr vDrIHvTvg3Xk6nCF6buLlMuwH1RZ75KYjAlWE0Vyb3A14VyDR1V5tRDCp9MkKc6PW5SM +4recahtcSThQY0fmQSaZff97NdJPQGB4pCiCmp1JLrA4IlZuu6RLmoohb7wePDQmkp5 Friw== X-Gm-Message-State: AFq9FYIiMXDXYIPwc11W4fOCNNqPaCVGhZhcVE3ybl5LZn3jG4Sp/lHx +jQwYxI/CjU49pMHR3ckOTAE8cuS0rv/R0bCB40fzmEDUdDPQ6FJ1cL1KodIPw== X-Gm-Gg: AYBFou36Wth2RPxpVvhzLA4Yx4qZ8KW7C/H5E+uafjEl8gBCjJfqhd+zTLp8fPT2I86 OSSorGGdmB0J2L895kIdrmr72liIUWYxOsggjhnGosi0WW8Vm0d79ys6OIWyhBU4ySwM/uOfFMR BHtEtqatRZU9yw23/pJnsjjGs+UdawdCmJejNCOKfHEr0v03Z6YvFrJyuT7VjiLX166OPOLSbnb lq4VbDhuzsYxDuGwUgDs/nkmyPUyiI7rNxI+DTCNjqLkmRcpd2mL18ZfX303++6NYdAGQd5LIUL iQGuIL+x/YJjJykHGzm4rNlI3SN4RQnlMB8vYVIpueC6Xb11GWgzVNGx1cjBaZCKcntv+zWN4uN mUqECmZYo3e+/nikPbOzecL/d4FAOV4AfYN6GIMr3p6H07Vd/gA3o8QK1WbTmvfZf5b4Xw8pF1j ElPRhi1QFAbE2OLwygS89q1THEjWqsfdgfNEXyhz30RzYPs8PaFwJ/Yws3WTc2ivoJtgaI4Ym+Q 9CanJU6/22FDWDpRxkZznrCbEzgbysEHVdGh0pKEdEs15nj2Df3pJ5zatgd4rGkkvIZdpcCaXTc zpsc8ADJhOpKiFk3+42/1/4GAM1y8ZhdBoGnuhfnaDf9YQuPiG64xh25gUFJNpUKPg== X-Received: by 2002:a05:7022:68f:b0:169:3706:d61b with SMTP id a92af1059eb24-1ac5bbba040mr3138230c88.16.1793348130545; Fri, 30 Oct 2026 01:15:30 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 11/12] tests/qtest/ufs-test: Add MCQ runtime register and TMR handling test Date: Fri, 30 Oct 2026 17:14:37 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::122a; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x122a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348222308158500 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Add ufs_test_tmr_handling() to verify UTMRL UFS_QUERY_TASK execution (both interrupt-driven I=3D1 and polling I=3D0 UTMRDs), SQCTI/CQIACR register access, SQRTC/SQRTS queue stop/start and self-clearing ICU transitions across running, stopped, and disabled SQ states, nullified SQE (CT =3D 0xF) completion with UFS_OCS_ABORTED, and CQIS.TEPS write-1-to-clear synchronization with IS.CQES. Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- tests/qtest/ufs-test.c | 161 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 1 deletion(-) diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index 9270e3b137a..78feeed8599 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -1899,7 +1899,7 @@ static void ufstest_hid(void *obj, void *data, QGuest= Allocator *alloc) ufs_exit(ufs, alloc); } =20 -static G_GNUC_UNUSED void ufs_send_tmr(QUfs *ufs, uint64_t utmrlba, int sl= ot, +static void ufs_send_tmr(QUfs *ufs, uint64_t utmrlba, int slot, uint8_t tm_func, uint8_t lun, uint32_t task_tag, UtpTaskReqDesc *utrd_out) @@ -2030,6 +2030,164 @@ static void ufs_test_hce_reset(void *obj, void *dat= a, QGuestAllocator *alloc) ufs_exit(ufs, alloc); } =20 +static void ufs_test_tmr_handling(void *obj, void *data, QGuestAllocator *= alloc) +{ + QUfs *ufs =3D obj; + uint64_t utmrlba, desc_addr, req_upiu_addr, rsp_upiu_addr; + UtpTaskReqDesc desc =3D { 0 }, utrd_result; + UtpTransferReqDesc null_utrd; + UtpUpiuReq req_upiu =3D { 0 }; + UfsCqEntry cqe; + uint32_t mcq_reg_offset, sqdao, cqisao, sqrts, sqrtc, orig_sqattr; + int null_slot; + enum UtpOcsCodes ocs; + UtpUpiuRsp rsp_upiu; + + ufs_init(ufs, alloc); + g_assert_true(ufs->support_mcq); + + /* Set up UTMRL */ + utmrlba =3D guest_alloc(alloc, 8 * sizeof(UtpTaskReqDesc)); + ufs_wreg(ufs, A_UTMRLBA, utmrlba & 0xffffffff); + ufs_wreg(ufs, A_UTMRLBAU, utmrlba >> 32); + ufs_wreg(ufs, A_UTMRLRSR, 1); + + /* Issue UFS_QUERY_TASK for inactive tag 15 (Interrupt bit I=3D1) */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_QUERY_TASK, 0, 15, &utrd_result); + g_assert_cmpuint(le32_to_cpu(utrd_result.header.dword_2) & UFS_MASK_OC= S, + =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL); + + /* Issue polling UTMRD with I=3D0 (slot 1): clears doorbell without UT= MRCS */ + desc_addr =3D utmrlba + 1 * sizeof(UtpTaskReqDesc); + desc.header.dword_0 =3D 0; + desc.header.dword_2 =3D cpu_to_le32(UFS_OCS_INVALID_COMMAND_STATUS); + desc.upiu_req.req_header.trans_type =3D UFS_UPIU_TRANSACTION_TASK_REQ; + desc.upiu_req.req_header.query_func =3D UFS_QUERY_TASK; + desc.upiu_req.req_header.lun =3D 0; + desc.upiu_req.req_header.task_tag =3D 0x11; + desc.upiu_req.input_param1 =3D cpu_to_be32(0); + desc.upiu_req.input_param2 =3D cpu_to_be32(15); + qtest_memwrite(ufs->dev.bus->qts, desc_addr, &desc, sizeof(desc)); + + ufs_wreg(ufs, A_UTMRLDBR, 1 << 1); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLDBR) & (1 << 1), =3D=3D, 0); + g_assert_cmpuint(FIELD_EX32(ufs_rreg(ufs, A_IS), IS, UTMRCS), =3D=3D, = 0); + qtest_memread(ufs->dev.bus->qts, desc_addr, &utrd_result, + sizeof(utrd_result)); + g_assert_cmpuint(le32_to_cpu(utrd_result.header.dword_2) & UFS_MASK_OC= S, + =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL); + + /* Verify SQCTI, CQIACR, SQRTS/SQRTC, and CQIS/IS.CQES W1C sync */ + sqdao =3D ufs->sqdao[TEST_QID]; + mcq_reg_offset =3D + FIELD_EX32(ufs_rreg(ufs, A_MCQCAP), MCQCAP, QCFGPTR) * 0x200 + + TEST_QID * 0x40; + cqisao =3D ufs_rreg(ufs, mcq_reg_offset + A_CQISAO); + + /* SQCTI and CQIACR read/write */ + ufs_wreg(ufs, sqdao + A_SQCTI, (1 << 8) | 0x2b); + g_assert_cmpuint(ufs_rreg(ufs, sqdao + A_SQCTI), =3D=3D, (1 << 8) | 0x= 2b); + ufs_wreg(ufs, cqisao + offsetof(UfsMcqCqIntReg, iacr), 0x101); + g_assert_cmpuint(ufs_rreg(ufs, cqisao + offsetof(UfsMcqCqIntReg, iacr)= ), + =3D=3D, 0x101); + + /* SQ_ICU while running (STS=3D0) -> sets SQRTS.CUS=3D1, RTC=3D2 */ + ufs_wreg(ufs, sqdao + A_SQRTC, FIELD_DP32(0, SQRTC, ICU, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + sqrtc =3D ufs_rreg(ufs, sqdao + A_SQRTC); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, STS), =3D=3D, 0); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, RTC), =3D=3D, 2); + g_assert_cmpuint(FIELD_EX32(sqrtc, SQRTC, ICU), =3D=3D, 0); + + /* SQ_STOP -> sets SQRTS.STS =3D 1 */ + ufs_wreg(ufs, sqdao + A_SQRTC, FIELD_DP32(0, SQRTC, STOP, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, STS), =3D=3D, 1); + + /* + * SQ_ICU while stopped (no matching req) -> sets SQRTS.CUS=3D1, RTC= =3D1 and + * self-clears ICU. + */ + ufs_wreg(ufs, sqdao + A_SQRTC, + FIELD_DP32(0, SQRTC, STOP, 1) | FIELD_DP32(0, SQRTC, ICU, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + sqrtc =3D ufs_rreg(ufs, sqdao + A_SQRTC); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, STS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, RTC), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrtc, SQRTC, ICU), =3D=3D, 0); + + /* + * Queue a nullified SQE (CT =3D 0xF) while SQ is stopped, then resume= SQ + * (STOP 1->0): SQRTS.STS clears to 0 while SQRTS.CUS remains 1, and t= he + * nullified SQE posts CQE with UFS_OCS_ABORTED without writing rsp_up= iu. + */ + null_slot =3D alloc_cmd_desc_slot(ufs); + req_upiu_addr =3D + ufs->cmd_desc_addr + null_slot * UTP_COMMAND_DESCRIPTOR_SIZE; + rsp_upiu_addr =3D req_upiu_addr + UTP_RESPONSE_UPIU_OFFSET; + req_upiu.header.trans_type =3D UFS_UPIU_TRANSACTION_NOP_OUT; + req_upiu.header.task_tag =3D null_slot; + qtest_memwrite(ufs->dev.bus->qts, req_upiu_addr, &req_upiu, + sizeof(req_upiu)); + memset(&rsp_upiu, 0xa5, sizeof(rsp_upiu)); + qtest_memwrite(ufs->dev.bus->qts, rsp_upiu_addr, &rsp_upiu, + sizeof(rsp_upiu)); + + null_utrd =3D ufs_build_req_utrd(req_upiu_addr, UFS_UTP_NO_DATA_TRANSF= ER, 0); + null_utrd.header.dword_0 =3D cpu_to_le32((UFS_UTP_CMD_TYPE_NULL << 28)= | + UFS_UTP_NO_DATA_TRANSFER | + UFS_UTP_REQ_DESC_INT_CMD); + __ufs_send_transfer_request_mcq_async(ufs, 0, &null_utrd); + + /* SQ_START (STOP 1->0) -> clears SQRTS.STS =3D 0 while preserving CUS= =3D 1 */ + ufs_wreg(ufs, sqdao + A_SQRTC, 0); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, STS), =3D=3D, 0); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + + ufs_wait_for_irq(ufs); + g_assert_cmpuint(ufs_mcq_poll_cq(ufs, &cqe, 1), =3D=3D, 1); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_ABORTED); + g_assert_cmpuint(cqe.task_tag, =3D=3D, null_slot); + qtest_memread(ufs->dev.bus->qts, rsp_upiu_addr, &rsp_upiu, + sizeof(rsp_upiu)); + g_assert_cmpuint(rsp_upiu.header.trans_type, =3D=3D, 0xa5); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + release_cmd_desc_slot(ufs, null_slot); + + /* Verify MCQ command sets CQIS.TEPS=3D1 and W1C clears CQIS.TEPS & IS= .CQES */ + ocs =3D ufs_send_nop_out(ufs, &rsp_upiu); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpuint(FIELD_EX32(ufs_rreg(ufs, cqisao + A_CQIS), CQIS, TEPS= ), + =3D=3D, 1); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + g_assert_cmpuint(FIELD_EX32(ufs_rreg(ufs, cqisao + A_CQIS), CQIS, TEPS= ), + =3D=3D, 0); + g_assert_cmpuint(FIELD_EX32(ufs_rreg(ufs, A_IS), IS, CQES), =3D=3D, 0); + + /* SQ_ICU on disabled SQ (SQEN=3D0) -> sets SQRTS.CUS=3D1, RTC=3D3 */ + orig_sqattr =3D ufs_rreg(ufs, mcq_reg_offset + A_SQATTR); + ufs_wreg(ufs, mcq_reg_offset + A_SQATTR, 0); + ufs_wreg(ufs, sqdao + A_SQRTC, FIELD_DP32(0, SQRTC, ICU, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, RTC), =3D=3D, 3); + ufs_wreg(ufs, mcq_reg_offset + A_SQATTR, orig_sqattr); + + guest_free(alloc, utmrlba); + ufs_exit(ufs, alloc); +} + static void ufs_register_nodes(void) { const char *arch; @@ -2091,6 +2249,7 @@ static void ufs_register_nodes(void) qos_add_test("query-desciptor", "ufs", ufstest_query_desc_request, &io_test_opts); qos_add_test("hce-reset", "ufs", ufs_test_hce_reset, &mcq_test_opts); + qos_add_test("tmr-handling", "ufs", ufs_test_tmr_handling, &mcq_test_o= pts); qos_add_test("wb-init", "ufs", ufstest_wb_init, &wb_test_opts); qos_add_test("wb-read-write", "ufs", ufstest_wb_read_write, &wb_test_o= pts); qos_add_test("hid", "ufs", ufstest_hid, &io_test_opts); --=20 2.43.0 From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793348233; cv=none; d=zohomail.com; s=zohoarc; b=MF9Wd52NxfUAV8cy+3C+TSF07ymZYMvF2aKi6Zh2RL5+seAqwC0A6mVlgYrvJmKks1J9/V00EBpEUovL074eOinmKjoqf1b0E5/drTG60OPzom01vvng+oLT9hDla/J63QtgR32bsl1+WVh2eB17KnxinolSstER+mhTKQbSQf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793348233; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4xslbgwZSHudUvrxVZ/QacRpqMBAc+XwtjLFYIEDgqY=; b=OwxEZug335TJYa1Zved5eOlDUQwteN5x+tj5EZGThlSQicr3ojj5rIN/bC8rdExamqXuOUx6ZSshyNZ020PUhG1eYta2atFFYyqkgTcawV+cfm5VA6xEYd1goMD26MGXH/CL50jYoJ7LqB7csKNFyYvuOg4eEVnWgnUsO2vwwHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793348233966239.07922729025768; Fri, 30 Oct 2026 01:17:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMhm7-0006gX-EG; Fri, 30 Oct 2026 04:15:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMhlz-0006WW-HK for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:39 -0400 Received: from mail-dl1-x122d.google.com ([2607:f8b0:4864:20::122d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMhlv-0001dX-Mn for qemu-devel@nongnu.org; Fri, 30 Oct 2026 04:15:39 -0400 Received: by mail-dl1-x122d.google.com with SMTP id a92af1059eb24-156cbe59524so379533c88.1 for ; Fri, 30 Oct 2026 01:15:35 -0700 (PDT) Received: from jeuk-MS-7D42.. ([211.226.54.223]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1ac193b8179sm5905766c88.11.2026.10.30.01.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 01:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793348134; x=1793952934; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=4xslbgwZSHudUvrxVZ/QacRpqMBAc+XwtjLFYIEDgqY=; b=RC1VVP4/6aZrLOcfQW3gS1CP0jxAH7IEI+hxBB+dkFluvZ6EVWoV/QA/clpQcjCGRj tv1eZQ2xsZe+st3cMUu8ylhy4eH8Z4QDflxhUwi5sU5J92b5RhjsIe5Lk7C4OY/iBmGe fP5HTpFN13vgUw0GFfoThtzx1U92z1+Xa6y2Uo51Sscc7U3XfyXZGZhyiwmd6XlviVuS RQzVdskl+UJrNWsp/FMFYMPANI4/8yF+cayYoTubGd+mMTtulQ7N9+miT9g944k7vC32 gn9EqcE4O08QCVbfKr2Eh4xBCyvoqwqu+A8uC0/6mYf+HKVprYPoIAMB7W4W/OqHX1Bc UyLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793348134; x=1793952934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=4xslbgwZSHudUvrxVZ/QacRpqMBAc+XwtjLFYIEDgqY=; b=LmRmk5Ixg0Q5fcYIezEWm8GIVOq2gu8qsIFjXx/wNFr7cLobhEtnF0qNNPDNMVIVYy DM05kUAF5v1uEetB+qIRCtCLjvAespgINRSdPHeNQlccSJdSX1NFGw8bWFy/VjpWlorI KvFr3P4C+Db0vK1MFvvhu8l1P+m/TelzbB1IBNtHYrKyqgjCZUTNVgchBYqE5C9iEH+L l4KWEdx6NWMpDWdhW9JGO6mqzXH4wdlFc0X4PtuyAU41W1E8OqsyEAOf9a6PJqnI2TI5 b7QX3gai0/sbk6QVFlHOl2Iy/zgnv41umDBqL+lDJxhILKDECO/p2z+gWitCyc/Cd+pR JG9w== X-Gm-Message-State: AFq9FYKerU7E2jqBPbhz/uHn0znJVSaZLKJX5Ed2t9wXUb8WzMrtlilL wPSq89gBMOhn3ej2egpDmZf63USTZVb8ufb9YmqzKpQBwcY0oKiF2wcf7pRHBQ== X-Gm-Gg: AYBFou1oKDN/c4FvnTes5NMTnrvCeOpgpJXDYUmSmUfKMK7CMoIlhB/AdBo0G3GKJH1 Qajmx7sSmmjApS0wGu7IsK5JN3tXupEM4VRlGbG0oLg2nvbsV2sJQ7w3V6Js5PC0nxvjXm54OqI EGAuw1AVoQKdzzRhRzYPQmbD9vUeFTmDDKHCxhV04wJHFtHX7ZOBTkiGe64Qja7/ljBBs8WkLlO kvyEBQugsDp0Wf4/PXNJvbnyL1iDfDfR5x8cY3RcYZI986xlokO2DBjgWi19mtqfuz+6asLpvhU QGoyxdIAILMNqRDhKWYv3MrRdAIiwskAhuI5/l1fcyNkikCDd9OhZX5plSDXzFYIUjxe/RpzC+s GYWnTVhrfDIaPllfdVHLMaRcWa0WGKWwrYyPCBvUwEgTcSE6MbkIZn9cPj6GNBXems2s1mARGyJ GsyxsiHKJj1CQhj1vxLBEz1XZ4qvbMZNdSw5OJ9LU1Rf2ojbEyGmcqIsQ5QZGkdF3xxM2qA3nIL XOKGBjptRxIEn+LycOlOd6D6OHhxc2yNHLTwQNd7vumyFmPPs7R0QobPUNNF8/b8E57vj0YtwUz w1LBAUKzFRVx3KtgHRFs+uMzxY6SqslqE5FPV7qZlMgGA3gzQSmk/Xp+HHQLsyIRIQ== X-Received: by 2002:a05:7022:fc05:b0:184:992:c9ec with SMTP id a92af1059eb24-1ac5fd06166mr1575313c88.38.1793348133917; Fri, 30 Oct 2026 01:15:33 -0700 (PDT) From: Jeuk Kim To: qemu-devel@nongnu.org, richard.henderson@linaro.org Cc: stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, daejun7.park@samsung.com, stanleyjhu@google.com, dridiha98@gmail.com, jeuk20.kim@samsung.com, j-young.choi@samsung.com Subject: [PULL 12/12] tests/qtest/ufs-test: Add QOM fault injection task abort test Date: Fri, 30 Oct 2026 17:14:38 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::122d; envelope-from=jeuk20.kim@gmail.com; helo=mail-dl1-x122d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 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: 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793348235555154100 Content-Type: text/plain; charset="utf-8" From: Stanley Jhu Add ufs_test_fault_injection_abort() to validate runtime QOM fault injection modes via x-fault-inject-tag and x-fault-inject-mode (abort-success with held-request tag overwrite rejection, two-stage UFS_ABORT_TASK + SQRTC.ICU and LUN matching, in-transition completion, timeout with UTMRLCLR clear-on-zero verification, abort-failed rejection, and ssu-timeout WLUN START_STOP filtering). Signed-off-by: Stanley Jhu Reviewed-by: Jeuk Kim Signed-off-by: Jeuk Kim --- tests/qtest/ufs-test.c | 681 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 680 insertions(+), 1 deletion(-) diff --git a/tests/qtest/ufs-test.c b/tests/qtest/ufs-test.c index 78feeed8599..1f86d834ac9 100644 --- a/tests/qtest/ufs-test.c +++ b/tests/qtest/ufs-test.c @@ -1928,7 +1928,7 @@ static void ufs_send_tmr(QUfs *ufs, uint64_t utmrlba,= int slot, qtest_memread(ufs->dev.bus->qts, desc_addr, utrd_out, sizeof(*utrd_out= )); } =20 -static G_GNUC_UNUSED int ufs_mcq_send_scsi_cmd_async(QUfs *ufs, uint8_t lu= n, +static int ufs_mcq_send_scsi_cmd_async(QUfs *ufs, uint8_t lun, const uint8_t *cdb) { int cmd_desc_slot =3D alloc_cmd_desc_slot(ufs); @@ -1951,6 +1951,66 @@ static G_GNUC_UNUSED int ufs_mcq_send_scsi_cmd_async= (QUfs *ufs, uint8_t lun, return cmd_desc_slot; } =20 +static int ufs_mcq_send_write_async(QUfs *ufs, uint8_t lun, + const uint8_t *cdb, + const uint8_t *data_in, + size_t data_in_len) +{ + QTestState *qts =3D ufs->dev.bus->qts; + int cmd_desc_slot =3D alloc_cmd_desc_slot(ufs); + uint64_t req_upiu_addr =3D + ufs->cmd_desc_addr + cmd_desc_slot * UTP_COMMAND_DESCRIPTOR_SIZE; + UfshcdSgEntry entry =3D { 0 }; + UtpUpiuReq req_upiu =3D { 0 }; + UtpTransferReqDesc utrd; + + g_assert_true(ufs->support_mcq); + g_assert_cmpuint(data_in_len, <=3D, PRD_ENTRY_DATA_SIZE); + qtest_memwrite(qts, ufs->data_buffer_addr, data_in, data_in_len); + entry.addr =3D cpu_to_le64(ufs->data_buffer_addr); + entry.size =3D cpu_to_le32(data_in_len - 1); + qtest_memwrite(qts, req_upiu_addr + UTP_PRDT_UPIU_OFFSET, &entry, + sizeof(entry)); + + req_upiu.header.trans_type =3D UFS_UPIU_TRANSACTION_COMMAND; + req_upiu.header.flags =3D UFS_UPIU_CMD_FLAGS_WRITE; + req_upiu.header.lun =3D lun; + req_upiu.header.task_tag =3D cmd_desc_slot; + req_upiu.sc.exp_data_transfer_len =3D cpu_to_be32(data_in_len); + memcpy(req_upiu.sc.cdb, cdb, UFS_CDB_SIZE); + qtest_memwrite(qts, req_upiu_addr, &req_upiu, sizeof(req_upiu)); + + utrd =3D ufs_build_req_utrd(req_upiu_addr, UFS_UTP_HOST_TO_DEVICE, 1); + __ufs_send_transfer_request_mcq_async(ufs, lun, &utrd); + return cmd_desc_slot; +} + +static int ufs_send_scsi_cmd_doorbell_async(QUfs *ufs, uint8_t lun, + const uint8_t *cdb) +{ + int cmd_desc_slot =3D alloc_cmd_desc_slot(ufs); + uint64_t req_upiu_addr =3D + ufs->cmd_desc_addr + cmd_desc_slot * UTP_COMMAND_DESCRIPTOR_SIZE; + uint64_t utrd_addr =3D + ufs->utrlba + cmd_desc_slot * sizeof(UtpTransferReqDesc); + UtpUpiuReq req_upiu =3D { 0 }; + UtpTransferReqDesc utrd; + + req_upiu.header.trans_type =3D UFS_UPIU_TRANSACTION_COMMAND; + req_upiu.header.flags =3D UFS_UPIU_CMD_FLAGS_NONE; + req_upiu.header.lun =3D lun; + req_upiu.header.task_tag =3D cmd_desc_slot; + memcpy(req_upiu.sc.cdb, cdb, UFS_CDB_SIZE); + qtest_memwrite(ufs->dev.bus->qts, req_upiu_addr, &req_upiu, + sizeof(req_upiu)); + + utrd =3D ufs_build_req_utrd(req_upiu_addr, UFS_UTP_NO_DATA_TRANSFER, 0= ); + qtest_memwrite(ufs->dev.bus->qts, utrd_addr, &utrd, sizeof(utrd)); + + ufs_wreg(ufs, A_UTRLDBR, 1 << cmd_desc_slot); + return cmd_desc_slot; +} + =20 static void ufs_test_hce_reset(void *obj, void *data, QGuestAllocator *all= oc) { @@ -2188,6 +2248,621 @@ static void ufs_test_tmr_handling(void *obj, void *= data, QGuestAllocator *alloc) ufs_exit(ufs, alloc); } =20 +#define UFS_FAULT_INJECT_TAG_NONE 0xffffffffU +#define UFS_FAULT_INJECT_TAG_ANY 0xfffffffeU + +static void ufs_test_fault_injection_abort(void *obj, void *data, + QGuestAllocator *alloc) +{ + QUfs *ufs =3D obj; + QTestState *qts =3D ufs->dev.bus->qts; + uint64_t utmrlba, desc_addr; + UtpTaskReqDesc utrd, utrd_result; + const uint8_t test_unit_ready_cdb[UFS_CDB_SIZE] =3D { TEST_UNIT_READY = }; + const uint8_t read10_lba512_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + const uint8_t start_stop_cdb[UFS_CDB_SIZE] =3D { START_STOP }; + const uint8_t request_sense_cdb[UFS_CDB_SIZE] =3D { REQUEST_SENSE }; + const uint8_t write10_cdb[UFS_CDB_SIZE] =3D { + WRITE_10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 + }; + const uint8_t read10_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 + }; + const uint8_t read10_lba0_cdb[UFS_CDB_SIZE] =3D { + READ_10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + const uint8_t read16_lba0_cdb[UFS_CDB_SIZE] =3D { + READ_16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + const uint8_t read16_lba512_cdb[UFS_CDB_SIZE] =3D { + READ_16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + uint8_t write_buf[4096]; + uint8_t read_buf[4096]; + UtpUpiuRsp read_rsp; + enum UtpOcsCodes ocs; + uint32_t sqdao, cqdao, mcq_reg_offset, cqisao, sqrts, cqhp, cqtp; + UfsCqEntry cqe; + int slot; + QDict *rsp; + + ufs_init(ufs, alloc); + g_assert_true(ufs->support_mcq); + + utmrlba =3D guest_alloc(alloc, 8 * sizeof(UtpTaskReqDesc)); + ufs_wreg(ufs, A_UTMRLBA, utmrlba & 0xffffffff); + ufs_wreg(ufs, A_UTMRLBAU, utmrlba >> 32); + ufs_wreg(ufs, A_UTMRLRSR, 1); + + sqdao =3D ufs->sqdao[TEST_QID]; + cqdao =3D ufs->cqdao[TEST_QID]; + mcq_reg_offset =3D + FIELD_EX32(ufs_rreg(ufs, A_MCQCAP), MCQCAP, QCFGPTR) * 0x200 + + TEST_QID * 0x40; + cqisao =3D ufs_rreg(ufs, mcq_reg_offset + A_CQISAO); + + /* + * Case 1: x-fault-inject-mode =3D abort-success (two-stage MCQ abort + + * SQRTC.ICU). + */ + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'abort-success' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, test_unit_ready_cdb); + qtest_clock_step(qts, 100); + + /* Issue UFS_QUERY_TASK -> assert Target Success & SUCCEEDED (0x08) */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_QUERY_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED); + + /* Verify x-fault-inject-tag cannot be overwritten while a req is held= */ + rsp =3D qtest_qmp(qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': 7 } }"); + g_assert_true(qdict_haskey(rsp, "error")); + qobject_unref(rsp); + + /* Issue UFS_ABORT_TASK -> assert COMPL (0x00) and tag cleared */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_ABORT_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL); + + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, + UFS_FAULT_INJECT_TAG_NONE); + qobject_unref(rsp); + + /* + * UFS_ABORT_TASK alone must NOT post a CQE + * before SQRTC.ICU is issued. + */ + cqhp =3D ufs_rreg(ufs, cqdao); + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, =3D=3D, cqhp); + + /* Stop SQ and test SQRTC.ICU with a mismatched LUN (lun=3D1 vs lun=3D= 0) */ + ufs_wreg(ufs, sqdao + A_SQRTC, FIELD_DP32(0, SQRTC, STOP, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, STS), =3D=3D, 1); + + ufs_wreg(ufs, sqdao + A_SQCTI, (1 << 8) | slot); + ufs_wreg(ufs, sqdao + A_SQRTC, + FIELD_DP32(0, SQRTC, STOP, 1) | FIELD_DP32(0, SQRTC, ICU, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, RTC), =3D=3D, 1); + g_assert_cmpuint(ufs_rreg(ufs, cqdao + 0x4), =3D=3D, cqhp); + + /* Issue SQRTC.ICU with matching SQCTI (lun=3D0) -> posts ABORTED CQE = */ + ufs_wreg(ufs, sqdao + A_SQCTI, (0 << 8) | slot); + ufs_wreg(ufs, sqdao + A_SQRTC, + FIELD_DP32(0, SQRTC, STOP, 1) | FIELD_DP32(0, SQRTC, ICU, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, RTC), =3D=3D, 0); + + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, !=3D, cqhp); + qtest_memread(qts, ufs->cqlba[TEST_QID] + cqhp, &cqe, sizeof(cqe)); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_ABORTED); + g_assert_cmpuint(cqe.task_tag, =3D=3D, slot); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + ufs_wreg(ufs, sqdao + A_SQRTC, 0); + release_cmd_desc_slot(ufs, slot); + + /* + * Direct SQRTC.ICU without prior UFS_ABORT_TASK: + * ufs_fault_inject_sq_cleanup() must clear held_req and active tag. + */ + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'abort-success' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, test_unit_ready_cdb); + qtest_clock_step(qts, 100); + + /* Abort directly via SQRTC.ICU */ + ufs_wreg(ufs, sqdao + A_SQRTC, FIELD_DP32(0, SQRTC, STOP, 1)); + ufs_wreg(ufs, sqdao + A_SQCTI, (0 << 8) | slot); + ufs_wreg(ufs, sqdao + A_SQRTC, + FIELD_DP32(0, SQRTC, STOP, 1) | FIELD_DP32(0, SQRTC, ICU, 1)); + sqrts =3D ufs_rreg(ufs, sqdao + A_SQRTS); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, CUS), =3D=3D, 1); + g_assert_cmpuint(FIELD_EX32(sqrts, SQRTS, RTC), =3D=3D, 0); + + /* Verify ufs_fault_inject_sq_cleanup cleared the held request */ + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, + UFS_FAULT_INJECT_TAG_NONE); + qobject_unref(rsp); + + /* Verify setting tag now succeeds (not blocked by held_req) */ + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': 7 } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %u } }", + UFS_FAULT_INJECT_TAG_NONE); + + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + ufs_wreg(ufs, sqdao + A_SQRTC, 0); + release_cmd_desc_slot(ufs, slot); + + /* + * Case 2: x-fault-inject-mode =3D in-transition. + * WRITE a pattern while held -> QUERY TASK (in-transition) releases + * and really executes the request -> READ back shows the pattern. + */ + memset(write_buf, 0x5a, sizeof(write_buf)); + memset(read_buf, 0, sizeof(read_buf)); + + /* Clear Unit Attention on LUN 1 before I/O */ + ufs_send_scsi_command(ufs, 1, request_sense_cdb, NULL, 0, read_buf, + sizeof(read_buf), &read_rsp); + + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'in-transition' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_write_async(ufs, 1, write10_cdb, write_buf, + sizeof(write_buf)); + qtest_clock_step(qts, 100); + + /* Command is held; no CQE posted yet */ + g_assert_cmpuint(ufs_rreg(ufs, cqdao + 0x4), =3D=3D, cqhp); + + /* QUERY TASK releases the held request and lets it actually execute */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_QUERY_TASK, 1, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED); + + /* Wait for the released request to finish and post its CQE */ + ufs_wait_for_irq(ufs); + g_assert_true(FIELD_EX32(ufs_rreg(ufs, A_IS), IS, CQES)); + + /* Verify completion CQE was posted with real status (SUCCESS) */ + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, !=3D, cqhp); + qtest_memread(qts, ufs->cqlba[TEST_QID] + cqhp, &cqe, sizeof(cqe)); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_SUCCESS); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + release_cmd_desc_slot(ufs, slot); + + /* READ back LBA 512 and verify the pattern actually reached the LU */ + ocs =3D ufs_send_scsi_command(ufs, 1, read10_cdb, NULL, 0, read_buf, + sizeof(read_buf), &read_rsp); + g_assert_cmpuint(ocs, =3D=3D, UFS_OCS_SUCCESS); + g_assert_cmpmem(read_buf, sizeof(read_buf), write_buf, sizeof(write_bu= f)); + + /* + * Case 3: x-fault-inject-mode =3D timeout + A_UTMRLCLR clear-on-zero. + * UFS_ABORT_TASK times out, leaving UTMRLDBR bit 2 set. + * + * UFSHCI defines UTMRLCLR as write-0-to-clear: writing 0 to a bit cle= ars + * that slot in UTMRLDBR, writing 1 leaves it unchanged. + */ + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'timeout' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, test_unit_ready_cdb); + qtest_clock_step(qts, 100); + + memset(&utrd, 0, sizeof(utrd)); + utrd.header.dword_0 =3D cpu_to_le32(UFS_UTP_REQ_DESC_INT_CMD); + utrd.header.dword_2 =3D cpu_to_le32(UFS_OCS_INVALID_COMMAND_STATUS); + utrd.upiu_req.req_header.trans_type =3D UFS_UPIU_TRANSACTION_TASK_REQ; + utrd.upiu_req.req_header.query_func =3D UFS_ABORT_TASK; + utrd.upiu_req.req_header.lun =3D 0; + utrd.upiu_req.req_header.task_tag =3D 2; + utrd.upiu_req.input_param1 =3D cpu_to_be32(0); + utrd.upiu_req.input_param2 =3D cpu_to_be32(slot); + desc_addr =3D utmrlba + 2 * sizeof(UtpTaskReqDesc); + qtest_memwrite(qts, desc_addr, &utrd, sizeof(utrd)); + + ufs_wreg(ufs, A_UTMRLDBR, 1 << 2); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLDBR) & (1 << 2), =3D=3D, 1 << 2); + + /* + * Writing 1s to A_UTMRLCLR indicates no change per UFSHCI spec, + * so it must NOT clear UTMRLDBR bit 2. + */ + ufs_wreg(ufs, A_UTMRLCLR, 0xffffffffU); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLDBR) & (1 << 2), =3D=3D, 1 << 2); + + /* + * Writing 0 at bit 2 (~(1 << 2)) to A_UTMRLCLR indicates slot cleared, + * so it MUST clear bit 2. + */ + ufs_wreg(ufs, A_UTMRLCLR, ~(1U << 2)); + g_assert_cmpuint(ufs_rreg(ufs, A_UTMRLDBR) & (1 << 2), =3D=3D, 0); + + ufs_wreg(ufs, A_HCE, 0); + release_cmd_desc_slot(ufs, slot); + ufs_exit(ufs, alloc); + ufs_init(ufs, alloc); + ufs_wreg(ufs, A_UTMRLBA, utmrlba & 0xffffffff); + ufs_wreg(ufs, A_UTMRLBAU, utmrlba >> 32); + ufs_wreg(ufs, A_UTMRLRSR, 1); + + /* + * Case 4: x-fault-inject-mode =3D abort-failed. + */ + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'abort-failed' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, test_unit_ready_cdb); + qtest_clock_step(qts, 100); + + /* Issue UFS_QUERY_TASK -> assert Target Success & SUCCEEDED (0x08) */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_QUERY_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED); + + /* Issue UFS_ABORT_TASK -> assert Target Failure & FAILED (0x05) */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_ABORT_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_FAIL); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_FAILED); + + /* Reset controller to clear held request cleanly */ + ufs_wreg(ufs, A_HCE, 0); + release_cmd_desc_slot(ufs, slot); + ufs_exit(ufs, alloc); + ufs_init(ufs, alloc); + ufs_wreg(ufs, A_UTMRLBA, utmrlba & 0xffffffff); + ufs_wreg(ufs, A_UTMRLBAU, utmrlba >> 32); + ufs_wreg(ufs, A_UTMRLRSR, 1); + + /* + * Case 5: x-fault-inject-mode =3D ssu-timeout. + * Non-SSU commands on LU 0 complete normally even with a matching + * specific tag or UFS_FAULT_INJECT_TAG_ANY, whereas START_STOP to + * UFS_UPIU_UFS_DEVICE_WLUN is held. + */ + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'ssu-timeout' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, test_unit_ready_cdb); + qtest_clock_step(qts, 100); + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, !=3D, cqhp); + qtest_memread(qts, ufs->cqlba[TEST_QID] + cqhp, &cqe, sizeof(cqe)); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_SUCCESS); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + release_cmd_desc_slot(ufs, slot); + + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %u } }", + UFS_FAULT_INJECT_TAG_ANY); + + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, read10_lba512_cdb); + qtest_clock_step(qts, 100); + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, !=3D, cqhp); + qtest_memread(qts, ufs->cqlba[TEST_QID] + cqhp, &cqe, sizeof(cqe)); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_SUCCESS); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + release_cmd_desc_slot(ufs, slot); + + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, UFS_UPIU_UFS_DEVICE_WLUN, + start_stop_cdb); + qtest_clock_step(qts, 100); + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, =3D=3D, cqhp); + + ufs_send_tmr(ufs, utmrlba, 0, UFS_QUERY_TASK, UFS_UPIU_UFS_DEVICE_WLUN, + slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED); + + ufs_wreg(ufs, A_HCE, 0); + release_cmd_desc_slot(ufs, slot); + ufs_exit(ufs, alloc); + ufs_init(ufs, alloc); + ufs_wreg(ufs, A_UTMRLBA, utmrlba & 0xffffffff); + ufs_wreg(ufs, A_UTMRLBAU, utmrlba >> 32); + ufs_wreg(ufs, A_UTMRLRSR, 1); + + /* + * Case 6: x-fault-inject-tag =3D ANY with READ_10 and READ_16. + * Commands with LBA < 512 must complete normally (not held). + * Commands with LBA >=3D 512 must be held. + */ + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'abort-success' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %u } }", + UFS_FAULT_INJECT_TAG_ANY); + + /* (a) READ_10 LBA 0 (< 512) -> completes normally, NOT held */ + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, read10_lba0_cdb); + qtest_clock_step(qts, 100); + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, !=3D, cqhp); + qtest_memread(qts, ufs->cqlba[TEST_QID] + cqhp, &cqe, sizeof(cqe)); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_SUCCESS); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + release_cmd_desc_slot(ufs, slot); + + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, + UFS_FAULT_INJECT_TAG_ANY); + qobject_unref(rsp); + + /* (b) READ_10 LBA 512 (>=3D 512) -> HELD */ + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, read10_lba512_cdb); + qtest_clock_step(qts, 100); + g_assert_cmpuint(ufs_rreg(ufs, cqdao + 0x4), =3D=3D, cqhp); + + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, slot); + qobject_unref(rsp); + + /* Abort the held READ_10 */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_ABORT_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL); + release_cmd_desc_slot(ufs, slot); + + /* Re-arm ANY for 16-byte testing */ + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %u } }", + UFS_FAULT_INJECT_TAG_ANY); + + /* (c) READ_16 LBA 0 (< 512) -> completes normally, NOT held */ + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, read16_lba0_cdb); + qtest_clock_step(qts, 100); + cqtp =3D ufs_rreg(ufs, cqdao + 0x4); + g_assert_cmpuint(cqtp, !=3D, cqhp); + qtest_memread(qts, ufs->cqlba[TEST_QID] + cqhp, &cqe, sizeof(cqe)); + g_assert_cmpuint(cqe.status, =3D=3D, UFS_OCS_SUCCESS); + ufs_wreg(ufs, cqdao, cqtp); + ufs_wreg(ufs, cqisao + A_CQIS, FIELD_DP32(0, CQIS, TEPS, 1)); + ufs_wreg(ufs, A_IS, FIELD_DP32(0, IS, CQES, 1)); + release_cmd_desc_slot(ufs, slot); + + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, + UFS_FAULT_INJECT_TAG_ANY); + qobject_unref(rsp); + + /* (d) READ_16 LBA 512 (>=3D 512) -> HELD */ + cqhp =3D ufs_rreg(ufs, cqdao); + slot =3D ufs_mcq_send_scsi_cmd_async(ufs, 0, read16_lba512_cdb); + qtest_clock_step(qts, 100); + g_assert_cmpuint(ufs_rreg(ufs, cqdao + 0x4), =3D=3D, cqhp); + + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, slot); + qobject_unref(rsp); + + /* Abort the held READ_16 */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_ABORT_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL); + release_cmd_desc_slot(ufs, slot); + + ufs_wreg(ufs, A_HCE, 0); + guest_free(alloc, utmrlba); + ufs_exit(ufs, alloc); +} + +static void ufs_test_fault_injection_legacy(void *obj, void *data, + QGuestAllocator *alloc) +{ + QUfs *ufs =3D obj; + QTestState *qts =3D ufs->dev.bus->qts; + uint64_t utmrlba; + UtpTaskReqDesc utrd_result; + const uint8_t test_unit_ready_cdb[UFS_CDB_SIZE] =3D { TEST_UNIT_READY = }; + int slot; + QDict *rsp; + + ufs_init(ufs, alloc); + g_assert_false(ufs->support_mcq); + + utmrlba =3D guest_alloc(alloc, 8 * sizeof(UtpTaskReqDesc)); + ufs_wreg(ufs, A_UTMRLBA, utmrlba & 0xffffffff); + ufs_wreg(ufs, A_UTMRLBAU, utmrlba >> 32); + ufs_wreg(ufs, A_UTMRLRSR, 1); + + slot =3D find_first_zero_bit(ufs->cmd_desc_bitmap, UFS_MAX_CMD_DESC); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-mode', 'value': 'abort-success' } }"); + qtest_qmp_assert_success( + qts, + "{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag', 'value': %d } }", slot); + + slot =3D ufs_send_scsi_cmd_doorbell_async(ufs, 0, test_unit_ready_cdb); + qtest_clock_step(qts, 100); + + /* Assert UTRLDBR bit is set while command is held */ + g_assert_cmpuint(ufs_rreg(ufs, A_UTRLDBR) & (1 << slot), =3D=3D, 1 << = slot); + + /* Issue UFS_ABORT_TASK -> clears UTRLDBR bit and returns COMPL */ + ufs_send_tmr(ufs, utmrlba, 0, UFS_ABORT_TASK, 0, slot, &utrd_result); + g_assert_cmpuint(utrd_result.upiu_rsp.rsp_header.response, + =3D=3D, UFS_COMMAND_RESULT_SUCCESS); + g_assert_cmpuint(be32_to_cpu(utrd_result.upiu_rsp.output_param1), + =3D=3D, UFS_UPIU_TASK_MANAGEMENT_FUNC_COMPL); + + /* Verify UTRLDBR bit was cleared by the abort */ + g_assert_cmpuint(ufs_rreg(ufs, A_UTRLDBR) & (1 << slot), =3D=3D, 0); + + rsp =3D qtest_qmp( + qts, + "{ 'execute': 'qom-get', 'arguments': { " + "'path': '/machine/peripheral/ufs0', " + "'property': 'x-fault-inject-tag' } }"); + g_assert_cmpuint(qdict_get_int(rsp, "return"), =3D=3D, + UFS_FAULT_INJECT_TAG_NONE); + qobject_unref(rsp); + + release_cmd_desc_slot(ufs, slot); + guest_free(alloc, utmrlba); + ufs_exit(ufs, alloc); +} + static void ufs_register_nodes(void) { const char *arch; @@ -2250,6 +2925,10 @@ static void ufs_register_nodes(void) &io_test_opts); qos_add_test("hce-reset", "ufs", ufs_test_hce_reset, &mcq_test_opts); qos_add_test("tmr-handling", "ufs", ufs_test_tmr_handling, &mcq_test_o= pts); + qos_add_test("fault-injection-abort", "ufs", + ufs_test_fault_injection_abort, &mcq_test_opts); + qos_add_test("fault-injection-legacy", "ufs", + ufs_test_fault_injection_legacy, &io_test_opts); qos_add_test("wb-init", "ufs", ufstest_wb_init, &wb_test_opts); qos_add_test("wb-read-write", "ufs", ufstest_wb_read_write, &wb_test_o= pts); qos_add_test("hid", "ufs", ufstest_hid, &io_test_opts); --=20 2.43.0