From nobody Mon Nov 23 05:00:14 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=1791361982; cv=none; d=zohomail.com; s=zohoarc; b=UwbzWKzjikwfpInMmBXg1INBls/rPK3TWmF+ntOzJ7tCBWKEHbsmrdA/TZw5C4RFIIyCWQyCxQfigHczK4rqrc7HGRCILWJwaq81WnMai77IgHqDlqLycPDxOmmR/pRyKMFQWhNR58fagh/x8B8Xs4P94MzCaxfaWYlxk4mWbSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791361982; 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=GLxNFWV8pCAYWPytD3wTV65ZM3p+kzSwWoszDQAFfO8=; b=IixUkb78eqQFZYadKJJx+2PvPUnMa6q96mPvUumHoM3d3XJ2FqcOS70YZCVvgzxynS5ydUOKgXSoRVqwR2hdLhNFMOwewOYazFQA0mKNTKkQ4tl9LAOkAWXZ7Bp2iWzJ3M2Sp5OtksAKMTxNCaUkpQNdfgAItSpWhUMUwAe0k7M= 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 1791361982050234.63497466703677; Wed, 7 Oct 2026 01:33:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEMzf-0007hP-16; Wed, 07 Oct 2026 04:27:20 -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 1xEHmA-0006Xb-3v for qemu-devel@nongnu.org; Tue, 06 Oct 2026 22:53:09 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEHly-0004rp-VW for qemu-devel@nongnu.org; Tue, 06 Oct 2026 22:52:56 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-5bccc73eea4so1129731e87.1 for ; Tue, 06 Oct 2026 19:50:42 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791341440; x=1791946240; 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=GLxNFWV8pCAYWPytD3wTV65ZM3p+kzSwWoszDQAFfO8=; b=WngT7Oo9kpQDED41dqAvJLWjZmUFbd9/omILqrdVhmW5mkROYTCO966jX2IfkR+tlJ wfoj4v7CtTeNb9IdGrQd25ITyduevCg09+VTFvHHA7kK1mUSDKelizAskZn8mgBT6mJm LhgHFW+g9CCgVDakIYBagE+nhe2lb9Rm6A7JTMU9owP58zvziLwja2itc7pm277N04cz Jx5qTaFZqvzTcwPcMeTknD9Ar3xSXWJSBxq/NvBc3uD+pgoAXZOCCi2SSBrYo3WmABiM RGeawAPJhb3qY0319bzaRyiFkC4l94X5LOETIA+ekpaMZ+h6B+FcLoaq9KZzPPwTUBlh qcAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791341440; x=1791946240; 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=GLxNFWV8pCAYWPytD3wTV65ZM3p+kzSwWoszDQAFfO8=; b=i/TCT1M9ASRfHvghAXRQCPIXEgLWpcxWaEctNwgYzTM+jBXilGRLxQ1yyb/C0wXOML jedtYhRZTd01Zbz+2LmQB99QOJaCjrPmNM6anUB7YGCAEroFGm5iRIfd8gwYgGsQsAkr Ba/v4X67JmwDWdcFo7NW3VqhidR2t3D2iKoDIpo3YR1/XmrtASbxzQNn4ISkC02UxloZ 4OY07hsdTmyDe1SJPpoQgMztZaInzGI/9zz/jhCAy1mPiAJgFIh+Lwu6hzG+TH8ivEG5 eDQD11brLTtbSmB3za0nduAmZZg4S3d6Gx4w1nSiEjIX11Wg9/q5gRQm9xUeQ8ReLSy9 gCCw== X-Gm-Message-State: AFq9FYJSAprSBN4xbckAk6SVpMUqfTwugAUcoBZ0T9QsJoQDzIGumJi5 y+j6VBHreq8sUnNUkFmlBy+2s3ByoTQOqoxjojEpy8Cjh9woa01oNKprmDdZWg== X-Gm-Gg: AYBFou0wbv7uMbaC2xQeCQbNDUwb2S+wTL1fXKCDFuSD1kuLeIEqGyOffcDsrXDvEaQ 9kllk+tJ3YdSurV0CKML5FZIZRB+KvCQ7QzYUQnXljv/X91o7HYYi//kGua6kWf1z1FVQVQpuUR YEoMixVac9HSnluEDcgdLSA1FoXzCH0XEqC8ud0NDG/2xPLuw8zU3yUn36XTRL27gZUimhwXSSS oTkYMs1uCKMKVvoFIVv0KQQilX0mLbY4ydrQuDMaEJD7yesohui5IOV/3zQnyjlJYcVxcS0e27R 6n+GeonKDYW0/48VLxjmKwww5BWFL7VShZABGcFFIXA3/iza5OzW/DTUn2UNTWhU5nzx4nh5JRP 6jLu0127Bz2v1jffVgJZ4/3MbrCiCgu+1cse/d2B24aDuGX14nKK4RgWodelpqUiv7C09BMnju6 a3jtmOlHytzTdEl0a/QrfE3yH/QeIxkxAB4UUuK3eNldFmk4qc69SCBupUi2SqIIcPzTWVFun/x umjHzQU0LjqVmKR2keKUNCjXWJIJxofTD9W7oGLZO0dzdLf X-Received: by 2002:a5d:5f88:0:b0:48c:4a62:9b31 with SMTP id ffacd0b85a97d-48c6d164fa6mr2204289f8f.5.1791279905135; Tue, 06 Oct 2026 02:45:05 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH v5 1/8] hw/sd/sd: Transfer up to one block in case of multi-block commands Date: Tue, 6 Oct 2026 11:44:40 +0200 Message-ID: <20261006094447.43491-2-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> 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=2a00:1450:4864:20::136; envelope-from=shentey@gmail.com; helo=mail-lf1-x136.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1791361983574158500 Content-Type: text/plain; charset="utf-8" Commit eff58d3d9681 ("hw/sd/sd: Allow multi-byte read/write for generic paths") allowed for transferring multiple bytes at once at the choice of the SD host implementation. Take advantage of that in the multi-block commands CMD18 and CMD25 by transferring up to one block rather than one byte at a time. Note that the drive limits and write-protect groups were already checked at the block boundary only. In between, bytes were accumulated up to one block and the block was trustfully transferred once full. This patch optimizes the accumulation process to fill a whole block at once if possible, so no further checks are required. This patch is based on https://lore.kernel.org/qemu-devel/20260417-sdcard-p= erformance-b4-v4-3-119e66be10c2@avm.de/ Signed-off-by: Christian Speich Signed-off-by: Bernhard Beschow --- hw/sd/sd.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b1b3b1226a..759db66e3d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2663,7 +2663,6 @@ static size_t sd_write_data(SDState *sd, const void *= buf, size_t length) { unsigned int partition_access; int i; - const uint8_t *value =3D buf; =20 if (!sd->blk || !blk_is_inserted(sd->blk)) { return length; @@ -2695,12 +2694,6 @@ static size_t sd_write_data(SDState *sd, const void = *buf, size_t length) break; =20 case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ - /* - * Only read one byte at a time. We will be called again with the - * remaining. - */ - length =3D 1; - if (sd->data_offset =3D=3D 0) { /* Start of the block - let's check the address is valid */ if (!address_in_range(sd, "WRITE_MULTIPLE_BLOCK", @@ -2714,7 +2707,11 @@ static size_t sd_write_data(SDState *sd, const void = *buf, size_t length) } } } - sd->data[sd->data_offset++] =3D value[0]; + + length =3D MIN(sd->blk_len - sd->data_offset, length); + memcpy(sd->data + sd->data_offset, buf, length); + sd->data_offset +=3D length; + if (sd->data_offset >=3D sd->blk_len) { /* TODO: Check CRC before committing */ sd->state =3D sd_programming_state; @@ -2811,7 +2808,6 @@ static size_t sd_read_data(SDState *sd, void *buf, si= ze_t length) const uint8_t dummy_byte =3D 0x00; unsigned int partition_access; uint32_t io_len; - uint8_t *value =3D buf; =20 if (!sd->blk || !blk_is_inserted(sd->blk)) { memset(buf, dummy_byte, length); @@ -2851,16 +2847,10 @@ static size_t sd_read_data(SDState *sd, void *buf, = size_t length) break; =20 case 18: /* CMD18: READ_MULTIPLE_BLOCK */ - /* - * We will only read one byte at a time. We will be called again w= ith - * the remaining buffer. - */ - length =3D 1; - if (sd->data_offset =3D=3D 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK", sd->data_start, io_len)) { - *value =3D dummy_byte; + memset(buf, dummy_byte, length); return length; } partition_access =3D sd->ext_csd[EXT_CSD_PART_CONFIG] @@ -2871,7 +2861,10 @@ static size_t sd_read_data(SDState *sd, void *buf, s= ize_t length) sd_blk_read(sd, sd->data_start, io_len); } } - *value =3D sd->data[sd->data_offset++]; + + length =3D MIN(io_len - sd->data_offset, length); + memcpy(buf, sd->data + sd->data_offset, length); + sd->data_offset +=3D length; =20 if (sd->data_offset >=3D io_len) { sd->data_start +=3D io_len; --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791361786; cv=none; d=zohomail.com; s=zohoarc; b=f5qwXaosWRvyX2XX33nX9WbZgkGpk2TrKvFqHusRlr5MIeD2vY1+2czreP+LThwtpCbFFKtwTNACaaq9Hb0PSAsB3kMoxMD6rkkV1dAY+/Ll+xjHydw5eVDJKMtN3NTWaEyuJdx/yYmq5yeHCflf6FDnycZkTAv2aGUme8pXd70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791361786; 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=woCGK0xgaNA3qhNiS3PzZJahdF7mNwl1idZ90g/lgvU=; b=JMG8NNpnOjQvJnD2oJHS0gb7+mBd6yGBZviYNrEXij/ZVNwjU8XAqnS6QsM2h3gFE0aZtpt+vj/bOKh8yeu9BX1SPbDiFzgcWqLFRMZ+TFJt03DHls/uIbi/LIIMlQIZiG8IhHP8ooxYKF1FPggS8WiXsydTMm3b1JBRVn/CaZk= 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 1791361786487663.7940829402532; Wed, 7 Oct 2026 01:29:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEMwO-0005WA-At; Wed, 07 Oct 2026 04:23:56 -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 1xEHL0-0003Fk-F1 for qemu-devel@nongnu.org; Tue, 06 Oct 2026 22:25:18 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEHKr-0007pf-Js for qemu-devel@nongnu.org; Tue, 06 Oct 2026 22:24:55 -0400 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-c2e3846d1caso179046566b.0 for ; Tue, 06 Oct 2026 19:20:45 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791339644; x=1791944444; 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=woCGK0xgaNA3qhNiS3PzZJahdF7mNwl1idZ90g/lgvU=; b=cob0S/dzD+ueeUe7PfX/pkCp4/HaoqhiAnSjsmHA8rFNz6OvNqg+GNOfLK5ocnMtTB ymrSVfhUiz+m0udRy+0ITc3vO2/Ec1+v0G6lhQgHRyD8yE7vChgpYsCHeiTUyLyk4qKC lvnN+rdQXSACn8+XM3KmUJfEkJDNnHI4A1qpnBZui+fguv7iwAAY9fxM/KlnURkDQYHe OH+PRe0IgI5T8LgH2jDynBAhpQrUFczqO4+KH9Bak0xV2gaAOLattO7fX7tg0Hzpc5HQ ShwgfkoonhduO+LKVS6Ck/Rc7Dwx3Yq46N1X5/ug+V56MyFT55XM/QxMqtJ+z+kDfS7i uecQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791339644; x=1791944444; 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=woCGK0xgaNA3qhNiS3PzZJahdF7mNwl1idZ90g/lgvU=; b=GpBLggfJ2+VcdnLTjwnGeGAisxokS3KK2IClNwilA1P3ONJ8UstrzakglSMqU8XO/2 QwvQM4c+UmjCwmy0Wh+DLuvKz2tHEdVMzJsEzH/jfyYC9XBvzbTUzAIsmrm49po+yGbF QiaEPONrflGA0FEyuMPvMWt9w7RK75RtyDxnCT+aI5q7fOQZnQ4UBa7d+1tMf4xcQf45 vplhGr7fL/MLN97vfcAWAQWCaVPR8KkzpK7hSwXOiCnqDFbzG9e9U69b7X2ae4she/g5 iy5qun72Ju7U1xp9z1mNIiQ9uZhCzGkJr2KKYs1m1zdaNc6cTbQz2DVcWVl3zZti19u3 aJVQ== X-Gm-Message-State: AFuF++kJMSCq7skxuVbXECksJBAOk2Y4ya90kzHkgzh7GDsAa7bGXnUo wtQrPZabSSTYAgiF1fNHRIaF0cCbsQEkkxY4dDZkyCr9jSwnGPSk8Aoj/sCUcA== X-Gm-Gg: AYBFou3jQ5UkxyWcGeL8lzYogiSYSwdLtZKkb54MsfytMSP3/W7CIN+W+cE3NnesN60 JTp+uK0BdCPYK7Kyr0o83rt8hLrF8JHB/jXyZLcrD0M1KHq9IpYlBD7qUoZnKoLDIlFhYrKcGYK 7uMP5WVwRhk1T+0/9Miz2DLh1gjri9FWbjHBxeqSsctXVm2DeVHZXGLTjw4gWrzXabxs/LKeBu3 NksRhN4UARBQPAZZsdcl2NH4hsOiYjCFrJW28r772QCBdGynXLXxZpf44CKcvNX2bAviVXFBRLr lnEV1p5svgE548KVJcFPoCbs75mVqZevO9G6t3AYMgQSYkAlT8P2zN0ImuCCw0MmOU3iGH0rr4A 2kI10i9Me22N7fIgnayLqb1BDNUmd1K6MtoCEFbWmhtnCFSbuXW40DG3olI+qToMkno2oPoun++ Xmcnzc1fNIPVzI4WLruaOuhb8arSCkxyPOPTBSp3xgjmGauawzuTprPVwr0CxzHLbIxcyEGTfKn LJTLmnPAKT6nkNMOO8pEMqujTfmU8lYAB7RvA== X-Received: by 2002:a5d:5e07:0:b0:488:8850:50ec with SMTP id ffacd0b85a97d-48c6d1a5c67mr1541939f8f.46.1791279906636; Tue, 06 Oct 2026 02:45:06 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH v5 2/8] hw/sd/sd: Add buffer argument to sd_blk_{read,write} Date: Tue, 6 Oct 2026 11:44:41 +0200 Message-ID: <20261006094447.43491-3-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> 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=2a00:1450:4864:20::633; envelope-from=shentey@gmail.com; helo=mail-ej1-x633.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1791361788131158500 Content-Type: text/plain; charset="utf-8" The next patch offers to skip the s->data bounce buffer for CMD18 and CMD25. Prepare for that by adding a buffer parameter. Rather than introducing two new wrapper functions, as in the inspiring commit, the additional argument is added at all call sites. This reduces the number of helper functions and matches existing code where multiple sd->* arguments are passed to sd_blk_{read,write}. This patch is inspired by: https://lore.kernel.org/qemu-devel/20260417-sdca= rd-performance-b4-v4-3-119e66be10c2@avm.de/ Inspired-by: Christian Speich Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 759db66e3d..bccb839ce6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1113,20 +1113,22 @@ static const VMStateDescription sd_vmstate =3D { }, }; =20 -static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) +static void sd_blk_read(SDState *sd, void* buf, uint64_t addr, + uint32_t len) { trace_sdcard_read_block(addr, len); addr +=3D sd_part_offset(sd); - if (!sd->blk || blk_pread(sd->blk, addr, len, sd->data, 0) < 0) { + if (!sd->blk || blk_pread(sd->blk, addr, len, buf, 0) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); } } =20 -static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) +static void sd_blk_write(SDState *sd, const void *buf, uint64_t addr, + uint32_t len) { trace_sdcard_write_block(addr, len); addr +=3D sd_part_offset(sd); - if (!sd->blk || blk_pwrite(sd->blk, addr, len, sd->data, 0) < 0) { + if (!sd->blk || blk_pwrite(sd->blk, addr, len, buf, 0) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); } } @@ -1364,7 +1366,7 @@ static void sd_erase(SDState *sd) continue; } } - sd_blk_write(sd, erase_addr, erase_len); + sd_blk_write(sd, sd->data, erase_addr, erase_len); } } =20 @@ -1985,7 +1987,7 @@ static sd_rsp_type_t sd_cmd_READ_SINGLE_BLOCK(SDState= *sd, SDRequest req) return sd_r1; } =20 - sd_blk_read(sd, addr, sd->blk_len); + sd_blk_read(sd, sd->data, addr, sd->blk_len); return sd_cmd_to_sendingdata(sd, req, addr, NULL, sd->blk_len); } =20 @@ -2685,7 +2687,7 @@ static size_t sd_write_data(SDState *sd, const void *= buf, size_t length) if (sd_generic_write_data(sd, buf, &length)) { /* TODO: Check CRC before committing */ sd->state =3D sd_programming_state; - sd_blk_write(sd, sd->data_start, sd->data_offset); + sd_blk_write(sd, sd->data, sd->data_start, sd->data_offset); sd->blk_written ++; sd->csd[14] |=3D 0x40; /* Bzzzzzzztt .... Operation complete. */ @@ -2720,7 +2722,7 @@ static size_t sd_write_data(SDState *sd, const void *= buf, size_t length) if (partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { emmc_rpmb_blk_write(sd, sd->data_start, sd->data_offset); } else { - sd_blk_write(sd, sd->data_start, sd->data_offset); + sd_blk_write(sd, sd->data, sd->data_start, sd->data_offset= ); } sd->blk_written++; sd->data_start +=3D sd->blk_len; @@ -2858,7 +2860,7 @@ static size_t sd_read_data(SDState *sd, void *buf, si= ze_t length) if (partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { emmc_rpmb_blk_read(sd, sd->data_start, io_len); } else { - sd_blk_read(sd, sd->data_start, io_len); + sd_blk_read(sd, sd->data, sd->data_start, io_len); } } =20 --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791361562; cv=none; d=zohomail.com; s=zohoarc; b=cOG52Enwk/Q8yI0b2u2Wuq7X6F/tXShIP9t6bYOzmHDIkdQXwjfZWIPZzYP/YMN8S1IG1iBdPiGonV7dwRGrEDPoTNqipFdqNta6V3q1+NFp/tw5YsGVFA8fsNfLNIXYySRU8FmzbYJyVc/tmr0fP89s27p/v+UUdckkwKrRLfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791361562; 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=+qm9RFm9kpcLhP87Ut2zliIvFmj6+EMYEVrRI1a4jgs=; b=JFqfy4E8zxLDU+dlcwRmbaNwWHzDhNaoU2eBSgKwORYhIXqar2OaSvEM4aQdsHTqN73HYbwRmjCOmMQKZXIP5Ajre+jQeE8QYmYUI0tDzpWaIWFWIAsgBlOSrjGv/Lw2G3N+8cBaMOuFVIjlEoLCM6CSrpjCkXDKS05acABzLxQ= 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 1791361562258986.2025917084488; Wed, 7 Oct 2026 01:26:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEMxV-00068P-EV; Wed, 07 Oct 2026 04:25:07 -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 1xEHPU-0003oN-ND for qemu-devel@nongnu.org; Tue, 06 Oct 2026 22:29:52 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEHP6-0000Sh-NM for qemu-devel@nongnu.org; Tue, 06 Oct 2026 22:29:25 -0400 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-6a9a20a5e72so1670834a12.0 for ; Tue, 06 Oct 2026 19:25:52 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791339951; x=1791944751; 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=+qm9RFm9kpcLhP87Ut2zliIvFmj6+EMYEVrRI1a4jgs=; b=N+p8FdcyrdVuHtY/38hYtefONo2nYnSplI99zfak/PtlyGr7vW/genlFghQ/FiKXoI i6191ck7jGHrAyTvizGYkb1f73thxGlG7TKcZkkvAFSpwYWGW9ZZ+5rn4jIzUS6R9SCS O64IE8t0Jfzb7TEX3oao5djK8Yl3lPS39YQJHujvCM20idNdPtrcMEmhT1u9nxAYyIPt fEjoKkoul7AbZEZkSGHMyAQ3cGASIXrHdwvyAnXubEpxxaKUyWeIKPbCc1np0tStRhZu AunNGC1D3bB6lVG+e/DLhHb5XbZTus1RR9HfRL49QBDfaNvrUSU41cq50rwiqq7bi4O7 Kxxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791339951; x=1791944751; 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=+qm9RFm9kpcLhP87Ut2zliIvFmj6+EMYEVrRI1a4jgs=; b=M8Py2mNCUDqawd3H+plZIAxHik0xI96IBa87JINZB8/gz3GMETg0s+dAO0LZrU/RsC voLBO+K1B5X+hq4RoOC8bs2Hu8mPvXGoIjESH8CpBHzH6VGWSieq/EEY3hjGfTvW7d0D FQUwz3sN43ACK0GjFF1qxP6bnq46zNyiVx9g+PKHv8jrg4JQMPx1IRa+DFDlA+i9v84R uYYjP39tNUke89x4bhzAhI8zERM4OxoBvDofXe9JV9WByGix0GCoB7lUeZjHP8zOrkKG vvarLzPzAUUIhkOazRC5OXhRmcijhIINfNkt7SBoF8+C9+eDbJPywZVCU3pm/19WSx7I wH/Q== X-Gm-Message-State: AFq9FYLbsGCQJzdEQ0RiwFi4b+d0yBQc0lJu9eJ7nd3yRXS7WKrlmgW+ M/RQFOSZ3e+rMKheQ/cokvAHNpcw+nnf2qLY+A/Yv6VIr1PkHXz5n9SPJXoqSA== X-Gm-Gg: AYBFou0wEcjRq+pLi8i5Eaeg60kQXEbQLHYg6fuN6mPpsDGw7atGbXHDE/LrwoSddFX LFIHnt/YN1RJgE09TaYNdcsDX1UVXoNKi+NlDYg/liQkljFyyK2OmBHPK6Jp/qsEPqOZdVxlR7q /d59mzqDbLcm3LIrXAtR3O8TbTSZvAmrkHyiEKmJD+0UpvWbfXXd18bxsRWDeJ47mHCsqjgTGMt d8UpaUTniLYlLEdzwHg23AjqXWkzC8PHyOpHqzB3ycdbqCc0SlUpYb0i5WKpp2xmxNXyz9L3it8 Yy1MEUBI1Cx3ALVMb3DoBXyAAi0g+reiscznLp/BbNypJ0nEQebuH7lwL/gVQ6cPo/rG5WOCb+j OvXYE3eT+2G3LI5aEq9WcuQ3ZtAwSmYcLgHCZgRq/73VL89stVpWvngB3gLpWxAZUS3ypv0mUUF DowXwIlME2q3XXWU6bxJHAbnFNL2q6XXT9kWvEbZEqhbWkK25kc8MFj/8r5qNHed8cwtqAQnIR1 vvlP0vY4CTzDdGcwgzX7lhfd5FwlmCf41UPPA== X-Received: by 2002:a5d:5f85:0:b0:487:2805:6834 with SMTP id ffacd0b85a97d-48c6d1e6f2dmr1521384f8f.42.1791279907601; Tue, 06 Oct 2026 02:45:07 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH v5 3/8] hw/sd/sd: Use multi-byte/block writes for block path Date: Tue, 6 Oct 2026 11:44:42 +0200 Message-ID: <20261006094447.43491-4-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> 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=2a00:1450:4864:20::530; envelope-from=shentey@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1791361563311158500 Content-Type: text/plain; charset="utf-8" When writing/reading blocks via WRITE/READ_MULTIPLE_BLOCK we try to directly pass this request down to the block layer. This can only be done for properly sized and aligned accesses, other access still use a bounce buffer but still benefit from copying as much data in one memcpy as possible. RPMB is limited to the slow path using a bounce buffer. Signed-off-by: Christian Speich Original patch has been split into multiple ones to help review. Further changes: * Drive limits and write protect groups are preserved to be checked on block boundaries only since these checks are redundant in case the SD host transfers one byte at a time. * WP_VIOLATION is only raised once the first protected block shall be written, rather than immediately at the beginning of a multiple block write which starts with allowed blocks. * An off-by-one error has been fixed in the same case where one bye too less had been written if a write protected block had been detected. * There are only two rather than three code paths each handling the multiple block optimization. Signed-off-by: Bernhard Beschow --- hw/sd/sd.c | 147 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 114 insertions(+), 33 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index bccb839ce6..6e2bb8ff2d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2702,36 +2702,84 @@ static size_t sd_write_data(SDState *sd, const void= *buf, size_t length) sd->data_start, sd->blk_len)) { break; } + + /* Limit writing data to our device size */ + length =3D MIN(sd->size - sd->data_start, length); + if (sd->size <=3D SDSC_MAX_CAPACITY) { if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |=3D WP_VIOLATION; break; } + + /* + * Check if any covered address violates WP. If so, limit = our + * write up to the allowed address. + */ + for (uint64_t addr =3D ROUND_UP(sd->data_start + 1, WPGROU= P_SIZE); + addr < sd->data_start + length; + addr +=3D WPGROUP_SIZE) { + if (sd_wp_addr(sd, addr)) { + length =3D addr - sd->data_start; + break; + } + } } } =20 - length =3D MIN(sd->blk_len - sd->data_offset, length); - memcpy(sd->data + sd->data_offset, buf, length); - sd->data_offset +=3D length; + partition_access =3D sd->ext_csd[EXT_CSD_PART_CONFIG] + & EXT_CSD_PART_CONFIG_ACC_MASK; =20 - if (sd->data_offset >=3D sd->blk_len) { - /* TODO: Check CRC before committing */ - sd->state =3D sd_programming_state; - partition_access =3D sd->ext_csd[EXT_CSD_PART_CONFIG] - & EXT_CSD_PART_CONFIG_ACC_MASK; - if (partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { - emmc_rpmb_blk_write(sd, sd->data_start, sd->data_offset); - } else { - sd_blk_write(sd, sd->data, sd->data_start, sd->data_offset= ); + if (length < sd->blk_len || sd->data_offset > 0 + || partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { + /* Partial write or RPMB (single block only for now) */ + length =3D MIN(sd->blk_len - sd->data_offset, length); + + memcpy(sd->data + sd->data_offset, buf, length); + sd->data_offset +=3D length; + + if (sd->data_offset >=3D sd->blk_len) { + sd->state =3D sd_programming_state; + if (partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { + emmc_rpmb_blk_write(sd, sd->data_start, sd->data_offse= t); + } else { + sd_blk_write(sd, sd->data, sd->data_start, sd->data_of= fset); + } + sd->blk_written++; + sd->data_start +=3D sd->blk_len; + sd->data_offset =3D 0; + sd->csd[14] |=3D 0x40; + + /* Bzzzzzzztt .... Operation complete. */ + if (sd->multi_blk_cnt !=3D 0) { + if (--sd->multi_blk_cnt =3D=3D 0) { + /* Stop! */ + sd->state =3D sd_transfer_state; + break; + } + } + + sd->state =3D sd_receivingdata_state; } - sd->blk_written++; - sd->data_start +=3D sd->blk_len; - sd->data_offset =3D 0; + } else { + /* Write multiple of block sizes */ + length =3D QEMU_ALIGN_DOWN(length, sd->blk_len); + + /* For limited writes, only write the requested block count. */ + if (sd->multi_blk_cnt !=3D 0) { + length =3D MIN(length, sd->multi_blk_cnt * sd->blk_len); + } + + sd->state =3D sd_programming_state; + sd_blk_write(sd, buf, sd->data_start, length); + sd->blk_written +=3D length / sd->blk_len; + sd->data_start +=3D length; sd->csd[14] |=3D 0x40; =20 - /* Bzzzzzzztt .... Operation complete. */ if (sd->multi_blk_cnt !=3D 0) { - if (--sd->multi_blk_cnt =3D=3D 0) { + sd->multi_blk_cnt -=3D length / sd->blk_len; + + if (sd->multi_blk_cnt =3D=3D 0) { /* Stop! */ sd->state =3D sd_transfer_state; break; @@ -2740,6 +2788,7 @@ static size_t sd_write_data(SDState *sd, const void *= buf, size_t length) =20 sd->state =3D sd_receivingdata_state; } + break; =20 case 26: /* CMD26: PROGRAM_CID */ @@ -2855,28 +2904,60 @@ static size_t sd_read_data(SDState *sd, void *buf, = size_t length) memset(buf, dummy_byte, length); return length; } - partition_access =3D sd->ext_csd[EXT_CSD_PART_CONFIG] - & EXT_CSD_PART_CONFIG_ACC_MASK; - if (partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { - emmc_rpmb_blk_read(sd, sd->data_start, io_len); - } else { - sd_blk_read(sd, sd->data, sd->data_start, io_len); - } } =20 - length =3D MIN(io_len - sd->data_offset, length); - memcpy(buf, sd->data + sd->data_offset, length); - sd->data_offset +=3D length; + /* Limit reading data to our device size */ + length =3D MIN(sd->size - sd->data_start, length); + + partition_access =3D sd->ext_csd[EXT_CSD_PART_CONFIG] + & EXT_CSD_PART_CONFIG_ACC_MASK; + + if (length < io_len || sd->data_offset > 0 + || partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { + /* Partial read or RPMB (single block only for now) */ + if (sd->data_offset =3D=3D 0) { + /* Fill the buffer */ + if (partition_access =3D=3D EXT_CSD_PART_CONFIG_ACC_RPMB) { + emmc_rpmb_blk_read(sd, sd->data_start, io_len); + } else { + sd_blk_read(sd, sd->data, sd->data_start, io_len); + } + } + + length =3D MIN(io_len - sd->data_offset, length); + memcpy(buf, sd->data + sd->data_offset, length); + sd->data_offset +=3D length; =20 - if (sd->data_offset >=3D io_len) { - sd->data_start +=3D io_len; - sd->data_offset =3D 0; + if (sd->data_offset >=3D io_len) { + sd->data_start +=3D io_len; + sd->data_offset =3D 0; =20 + if (sd->multi_blk_cnt !=3D 0) { + if (--sd->multi_blk_cnt =3D=3D 0) { + /* Stop! */ + sd->state =3D sd_transfer_state; + break; + } + } + } + } else { + /* Read multiple of block sizes */ + length =3D QEMU_ALIGN_DOWN(length, io_len); + + /* For limited reads, only read the requested block count. */ if (sd->multi_blk_cnt !=3D 0) { - if (--sd->multi_blk_cnt =3D=3D 0) { - /* Stop! */ + length =3D MIN(length, sd->multi_blk_cnt * io_len); + } + + sd_blk_read(sd, buf, sd->data_start, length); + + sd->data_start +=3D length; + + if (sd->multi_blk_cnt !=3D 0) { + sd->multi_blk_cnt -=3D length / io_len; + + if (sd->multi_blk_cnt =3D=3D 0) { sd->state =3D sd_transfer_state; - break; } } } --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791362304; cv=none; d=zohomail.com; s=zohoarc; b=hRrvG0ZO2Ifrbl6/5BHrafh3wUDRearq3ecHgPeoosjcoeInPPh9NF0kuTFDQP0ZyHkTcUNIBFxFgzu+UmB07IUj+NBNRXOS254Hv2D2kKBSjZAzMh1HBn8puYCJryZK8xI0/DTbKSSUsdeui9VUfCCeKAH2XfcrRjP96wEfEOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791362304; h=Content-Type: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=PYKfHPldhWeFOjyIkeLoCzfvceJRidlCUcbU149i39Q=; b=Lrtqlv9VEGWYWjlv7a59LqpaAa/vhTAFsO27rf6sCvQueVYBJvXBWTWjyXPIPIaBC58kYgCucODz2uMZv7EebzY+8t9MnaiCC2HMnaTzggLGQEC+Bqy2BfY9cEbNLDbfGpzVB0C3ZNIQBhrhdr00STp1hyCYHsniK0IgKnAcoe0= 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 1791362304396997.8845495908085; Wed, 7 Oct 2026 01:38:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEN5k-00074b-Ln; Wed, 07 Oct 2026 04:33: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 1xEHww-0007vm-58 for qemu-devel@nongnu.org; Tue, 06 Oct 2026 23:04:12 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEHwk-0006Sc-Ak for qemu-devel@nongnu.org; Tue, 06 Oct 2026 23:04:06 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-c2acc1e170cso201299166b.1 for ; Tue, 06 Oct 2026 19:59:11 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791341950; x=1791946750; darn=nongnu.org; h=content-transfer-encoding:content-type: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=PYKfHPldhWeFOjyIkeLoCzfvceJRidlCUcbU149i39Q=; b=Q8hsb6m8HSn5k7bMtZLm/QRjbqODEpA4HbHozIG/p2TqZ8c8kNg7Wb109BWKGEB8BR JBUSsbIlONjpgjObVMAS35/9sNYxqdLfc/Ez3uMhCsu9nvbXz54A6nqNN7vqNhrCQKju D5C+7RUYXO4gOTOdF6JMzyv8P+8x/NOjYFcwVlKXX4Pk7RDhvxOYeTyN8qkjyF0k/BRv dzjhgq69mxQNQUOqI9o434duYvpmtBXbaBhGOPI78mCNu2wgNUOcv9ZmL8nZCWmBkPwr 9h5dd/m19qyOhg1Os6WTWGi1vkzXkfiH1yThP6xIWLX/eGFVZrxhcJM4EZTWycZbyHK4 X8Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791341950; x=1791946750; h=content-transfer-encoding:content-type: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=PYKfHPldhWeFOjyIkeLoCzfvceJRidlCUcbU149i39Q=; b=2sZEjJ9zEJfW465YwngRhlhWgyiXqquyf+wfJ09w3/cnI1WjZbgUkmcWiGqAcVsS7O r69H7k5g4K4buz6kzp5ebyFDV4HxVfu5OrcbvG/0t30zlOp98/GNzNaEX67MGiur8N+6 uO0kAZtouT6D07TMky2tBANX+2p6ozL0IHBp4IQBJIomBN2HuAIQuULL0C9Pix1WQYkA maGwNwkE6ckqHdQ9+CNt8rnF89mdlEEYTMI0ipTWvej3Ype9DVJooQQRld2Hg8qwzT+t mvRP1VjedUriTwefVkuVcKMYtGCmafmMcA4POtKxcoH5Oc17fEJ2buOIbnDI+KqWs+BG u0hg== X-Gm-Message-State: AFq9FYKuAPLhKGNRKc6JE7o7w8p8VNODBNo1MLNCZKPe3sYxeAp0+1Nx Avg6bxh16pEyHdLpqojB5H+kQOsRZED6ArOyDKrO80NUBTYOo60VYt+L9WObPg== X-Gm-Gg: AYBFou1qJP7/ud/lnqA4Fobh1p1YRwOlFT2HH22VzCXdZv3grzIpsFxZu2NsCwVz+qw z4q7EeN61hYxEBLaEt8St5jedcXPQITpOg4EE5AWgGzoGKXMu5Uo1rDkIBSzGAEtqmLr7oY2h4G lVfq6qfiGDVmxGNOEjwYpk28uAyJUjXduNNRder7Wj+MUR0PG2kw4kObuMNIqozmQaV0wShUJku /FjGarIkOrTkMa0/GOYY9QZq4cCFNid7AWEDj32vCmlTcsLjoLGqJl7rGrABwVBGQ1AApg/CUOC AOEiHDu41l64b4R6+zT1dXJvobkk8jcMULkFxLr2sprrABi/ovDmEo7yj4Clm0jtdOCHHOFLXV5 bLKGh4YPtBvhf4VwRgaehGbXruD37dfte44O+d7nA/yzWKKbJo5G7TPGpPv7Vrl8zfWenY1lqrP nB4MzPKyjtcHi4aMI97cetET0uaYkuV9YY3u9vLA6oFIBlFCpJd+OsloDi5/hq7WaiAFgX8mYPy 4u5Ml80S2Iq0F51rNg/rjmsQmTxzt9eymSnTrIM2k2gp4sj X-Received: by 2002:a05:6000:40ca:b0:48c:4f83:f42f with SMTP id ffacd0b85a97d-48c6d0f432dmr1564943f8f.8.1791279908514; Tue, 06 Oct 2026 02:45:08 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 4/8] hw/sd/sdhci: Don't use bounce buffer for ADMA Date: Tue, 6 Oct 2026 11:44:43 +0200 Message-ID: <20261006094447.43491-5-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::62f; envelope-from=shentey@gmail.com; helo=mail-ej1-x62f.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: 1791362305133158500 From: Christian Speich Currently, ADMA will temporarily store data into a local bounce buffer when transferring it. This will produce unneeded copies of the data and limit us to the bounce buffer size for each step. This patch now maps the requested DMA address and passes this buffer directly to sdbus_{read,write}_data. This allows to pass much larger buffers down to increase the performance. sdbus_{read,write}_data is already able to handle arbitrary length and alignments, so we do not need to ensure this. Signed-off-by: Christian Speich Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sdhci.c | 102 +++++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index bd74c60f72..2f52b252ce 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -852,7 +852,7 @@ static void get_adma_description(SDHCIState *s, ADMADes= cr *dscr) =20 static void sdhci_do_adma(SDHCIState *s) { - unsigned int begin, length; + unsigned int length; const uint16_t block_size =3D s->blksize & BLOCK_SIZE_MASK; const MemTxAttrs attrs =3D { .memory =3D true }; ADMADescr dscr =3D {}; @@ -894,66 +894,74 @@ static void sdhci_do_adma(SDHCIState *s) if (s->trnmod & SDHC_TRNS_READ) { s->prnsts |=3D SDHC_DOING_READ; while (length) { - if (s->data_count =3D=3D 0) { - sdbus_read_data(&s->sdbus, s->fifo_buffer, block_s= ize); - } - begin =3D s->data_count; - if ((length + begin) < block_size) { - s->data_count =3D length + begin; - length =3D 0; - } else { - s->data_count =3D block_size; - length -=3D block_size - begin; - } - res =3D dma_memory_write(s->dma_as, dscr.addr, - &s->fifo_buffer[begin], - s->data_count - begin, - attrs); - if (res !=3D MEMTX_OK) { + dma_addr_t dma_len =3D length; + + void *buf =3D dma_memory_map(s->dma_as, dscr.addr, &dm= a_len, + DMA_DIRECTION_FROM_DEVICE, + attrs); + + if (buf =3D=3D NULL) { + res =3D MEMTX_ERROR; break; + } else { + res =3D MEMTX_OK; } - dscr.addr +=3D s->data_count - begin; - if (s->data_count =3D=3D block_size) { - s->data_count =3D 0; - if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { - s->blkcnt--; - if (s->blkcnt =3D=3D 0) { - break; - } + + sdbus_read_data(&s->sdbus, buf, dma_len); + length -=3D dma_len; + dscr.addr +=3D dma_len; + + dma_memory_unmap(s->dma_as, buf, dma_len, + DMA_DIRECTION_FROM_DEVICE, dma_len); + + if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { + size_t transfered =3D s->data_count + dma_len; + + s->blkcnt -=3D transfered / block_size; + s->data_count =3D transfered % block_size; + + if (s->blkcnt =3D=3D 0) { + s->data_count =3D 0; + break; } } } } else { s->prnsts |=3D SDHC_DOING_WRITE; while (length) { - begin =3D s->data_count; - if ((length + begin) < block_size) { - s->data_count =3D length + begin; - length =3D 0; - } else { - s->data_count =3D block_size; - length -=3D block_size - begin; - } - res =3D dma_memory_read(s->dma_as, dscr.addr, - &s->fifo_buffer[begin], - s->data_count - begin, - attrs); - if (res !=3D MEMTX_OK) { + dma_addr_t dma_len =3D length; + + void *buf =3D dma_memory_map(s->dma_as, dscr.addr, &dm= a_len, + DMA_DIRECTION_TO_DEVICE, at= trs); + + if (buf =3D=3D NULL) { + res =3D MEMTX_ERROR; break; + } else { + res =3D MEMTX_OK; } - dscr.addr +=3D s->data_count - begin; - if (s->data_count =3D=3D block_size) { - sdbus_write_data(&s->sdbus, s->fifo_buffer, block_= size); - s->data_count =3D 0; - if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { - s->blkcnt--; - if (s->blkcnt =3D=3D 0) { - break; - } + + sdbus_write_data(&s->sdbus, buf, dma_len); + length -=3D dma_len; + dscr.addr +=3D dma_len; + + dma_memory_unmap(s->dma_as, buf, dma_len, + DMA_DIRECTION_TO_DEVICE, dma_len); + + if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { + size_t transfered =3D s->data_count + dma_len; + + s->blkcnt -=3D transfered / block_size; + s->data_count =3D transfered % block_size; + + if (s->blkcnt =3D=3D 0) { + s->data_count =3D 0; + break; } } } } + if (res !=3D MEMTX_OK) { s->data_count =3D 0; if (s->errintstsen & SDHC_EISEN_ADMAERR) { --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791363145; cv=none; d=zohomail.com; s=zohoarc; b=QhIi2Cib8xr18drLONfOh+jl6NKJeNbCNvAsYUgi0pV7ya6xVzEL8hzY9AruC5qoBzfu4S/qB9yQJPReFGhay4eYADYawyyfERwnXHl7CR2okmx5xZXo71kXOAq1/bjikSz0+reqvuHrmQE3ios2T1Y8gTgDd3CkaN4+OuWH52U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791363145; h=Content-Type: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=21yxfb4i7kxC3qcFd4IJSGMl/u7d4pLAk60w6us8vRM=; b=MBnRWTCLfy+P4o6yPdBc+VHxSYyutUkslu4lfAw2AveaFHwIhwWupNFWSuareMV81C3B+QhIXHmxEyLYI5u99yZ5zIS6NOM5W63v+fJIGPtJiMUZFCq2L8gQWdUIMsi9wRJdTDRbQwjDcUA6pEYAztSCLBL1Rv7Nd2i4/eyqRC0= 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 1791363145360650.9191493720194; Wed, 7 Oct 2026 01:52:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENGx-0004Ka-2R; Wed, 07 Oct 2026 04:45:12 -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 1xEJb5-0006rq-VP for qemu-devel@nongnu.org; Wed, 07 Oct 2026 00:49:53 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEJav-0003QI-2Z for qemu-devel@nongnu.org; Wed, 07 Oct 2026 00:49:41 -0400 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-3a9a2cfe1d4so2824271fa.2 for ; Tue, 06 Oct 2026 21:49:01 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791348540; x=1791953340; darn=nongnu.org; h=content-transfer-encoding:content-type: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=21yxfb4i7kxC3qcFd4IJSGMl/u7d4pLAk60w6us8vRM=; b=EprH6Pq7UqRgDIx+ts5V827FxpwJKJ9bFX9zYKpmSzAlJYOa/bGmYeCYMbclY95eaZ Q1PS9Hre/fHzJuDjwcLgKjtTIwkv/bt4IqgRDtuQD6uZ090W+HSMcE2mYqTnLSTDMVDm NkRmtIMgBt5RCLwAhwfqa+IRo89AiQMOqdsywGZHwg4EPF5SOwRXWTwRLcc1fyAfadPZ htyNJHKwp4cQWN+IMzKUBNBBmQbJt/XsTNGMtvSx0KS45+g4M54W2mtGNbSXGh9/TJzj nMjMvqaHXaREHitRCrRfXcPj5yy0yCpsf5TWramNRu7K7hHgUJAUxGUMhB2dxPsEiQTi G7pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791348540; x=1791953340; h=content-transfer-encoding:content-type: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=21yxfb4i7kxC3qcFd4IJSGMl/u7d4pLAk60w6us8vRM=; b=Ac62Vw+veywjCfX+Bj1GyzLGWIPDLWm3HvXBb5i7cKpfzp8ozrM/YiMAZOlDYgFMRq qQWuwp+WQtrzHWmZim7SY0Wpr/tHTorM/z3e9WfOHvV6exsJAs6fs9IlH6dVzIX2MfzP 4F1L2+O1yoNQrMqqQMpNHmvErRxLEjJLuunabwQzONbHnBDSzDioYxfRN0TwuMeZE9iY E4O9V7+oAV5bRKL8Q2ToyyeBvhdegOxGCSTbuyNbIr73Peaef3oYoE4m+uz/uQFlERYF COonto3OLZMXj8kSUW+UUHZS4MaYjRGpSomkD7XIkgB8gS/Votdo0KpMKfBWDmTuWvit R79w== X-Gm-Message-State: AFq9FYJhRW2DyqQdUc9EpRe1bctpnoDj6vRuTVk6b2pvqRmNfOEC1/91 G8l6iRwbAe3ssqoVwQPtdIGG/lHuz7of4XL5LoD87b9dy/6jWhzafcrRJY+gdA== X-Gm-Gg: AYBFou1/8AszOk1vstjbPu/hZf9HsiaahxClUTvhOTExPTbBTT20TM8TF3IGknrm6sI 7DNUWifdopOISfMhk7UdjTuFHw/VPj6dcmMDepgd/By/lPBb0MjKKI5gVv01v4uQHHCFVfdfC5Q hc2i6eDXA1WbJi03l+enppOnTKrllrWXfo+jqGs13/TyNf9DlSlhj1ClRQwGrTUKQRi3+EkXiYd M1k3im7yp9VzILvCFn6Kr9Hy6OgX+bhd+d1IWhH6JMoYziUxxUuRP77voZqIwy4rLccsNQ8/aVM hKJjwrFybgG7Gvwt7qljcm3UB19Zo0PkCj2UljGKht3dVie4qa7mI8l/iNUrbGl7WopVhTIqTvJ HylkMaZLumME1VNmWy+V4dKAEnh9U/WxjBQ221f9krm90L0iT1zPhU65KPINUHXd+XdvmjEXFLK 7T7X2lK+eke9uC3dKf4jW5tudw8gsnNQqfD5N17LOaFRar6DHJwhj00uyJ2KePOtU5BivtNT3YA dPFwCV8wx4QrLIPMhNtREmb5QNximjhzdM8UA== X-Received: by 2002:a05:6000:26c9:b0:487:218b:bbb0 with SMTP id ffacd0b85a97d-48c6d1d1c18mr1762387f8f.42.1791279909492; Tue, 06 Oct 2026 02:45:09 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bernhard Beschow Subject: [PATCH v5 5/8] hw/sd/sd: Add erase-blocks-as-zero option. Date: Tue, 6 Oct 2026 11:44:44 +0200 Message-ID: <20261006094447.43491-6-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::22a; envelope-from=shentey@gmail.com; helo=mail-lj1-x22a.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: 1791363145702158501 From: Christian Speich Currently, erased blocks are filled with 0xFF. However SCR Bit 55 (DATA_STAT_AFTER_ERASE) indicates that an erase produces zeros. One of them is wrong. This patch does two things. First it fixes the reporting of DATA_STAT_AFTER_ERASE in SCR to correctly reflect the content of erased blocks. We also increase the Product Revision (REV in CID) to indicate to the guest that DATA_STAT_AFTER_ERASE is now reliable. Secondly, we introduce a erase-blocks-as-zero option, which allows the user to choose if erased blocks should contain 0xFF or 0x00. The default is still 0xFF to remain compatible with current users. Signed-off-by: Christian Speich Reviewed-by: Philippe Mathieu-Daud=C3=A9 Move global compat property `{ "sdmmc-common", "erase-blocks-as-zero", "false" }` to 11.1 section. Signed-off-by: Bernhard Beschow --- hw/core/machine.c | 1 + hw/sd/sd.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index d9ac4b419a..7b0be16444 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -41,6 +41,7 @@ #include "hw/arm/smmuv3.h" =20 GlobalProperty hw_compat_11_1[] =3D { + { "sdmmc-common", "erase-blocks-as-zero", "false" }, { "sysbus-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, }; diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6e2bb8ff2d..c40097924c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -162,6 +162,7 @@ struct SDState { /* Static properties */ =20 uint8_t spec_version; + bool erase_blocks_as_zero; uint64_t boot_part_size; uint64_t rpmb_part_size; BlockBackend *blk; @@ -440,6 +441,9 @@ static void sd_set_scr(SDState *sd) sd->scr[0] |=3D 2; /* Spec Version 2.00 or Version 3.0X */ sd->scr[1] =3D (2 << 4) /* SDSC Card (Security Version 1.01) */ | 0b0101; /* 1-bit or 4-bit width bus modes */ + if (!sd->erase_blocks_as_zero) { + sd->scr[1] |=3D (1 << 7); /* DATA_STAT_AFTER_ERASE: Erase produces= 0xFF */ + } sd->scr[2] =3D 0x00; /* Extended Security is not supported. */ if (sd->spec_version >=3D SD_PHY_SPECv3_01_VERS) { sd->scr[2] |=3D 1 << 7; /* Spec Version 3.0X */ @@ -457,7 +461,7 @@ static void sd_set_scr(SDState *sd) #define MID 0xaa #define OID "XY" #define PNM "QEMU!" -#define PRV 0x01 +#define PRV 0x02 #define MDT_YR 2006 #define MDT_MON 2 =20 @@ -1354,7 +1358,12 @@ static void sd_erase(SDState *sd) sd->erase_end =3D INVALID_ADDRESS; sd->csd[14] |=3D 0x40; =20 - memset(sd->data, 0xff, erase_len); + if (sd->erase_blocks_as_zero) { + memset(sd->data, 0x0, erase_len); + } else { + memset(sd->data, 0xFF, erase_len); + } + for (erase_addr =3D erase_start; erase_addr <=3D erase_end; erase_addr +=3D erase_len) { if (sdsc) { @@ -3281,6 +3290,8 @@ static void emmc_realize(DeviceState *dev, Error **er= rp) =20 static const Property sdmmc_common_properties[] =3D { DEFINE_PROP_DRIVE("drive", SDState, blk), + DEFINE_PROP_BOOL("erase-blocks-as-zero", SDState, erase_blocks_as_zero, + true), }; =20 static const Property sd_properties[] =3D { --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791363453; cv=none; d=zohomail.com; s=zohoarc; b=kFLsihtSZML7TIfgQMnwsTlk7fwWps2nswm9TvfE9beIgOGaRBzXcazoTOzct+JiiKHHIOw/sLsJ2C3Wwgg4pzENl/eZBFTlVNOfiCW69LE23ivsl08cTztN5UqvqXd8MuKrSLpge3tM9smS5lZZHxGEA38xKJxph2+6n9zW7Fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791363453; 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=ijBHVO8i4WEMr8/QksZUlHjObyra+9udgmuoDDxE/As=; b=fkqzFCDeSIEMHhW3HmAaBuDXWIh4I5ThkdkD6hyqksXp5GQltsTelxWMCAO3QddFp2FYYDld7c/SRp7FIyP6zo5VRd7Znsn2uJiNeKh+krPa4WAyK+JEIoCSuSxT0JppwmWhdkFDwsu9Cms1bB9cDIkcYTywRpDOFe/B2U28ViU= 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 1791363453106868.4035903482907; Wed, 7 Oct 2026 01:57:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENDa-0002rV-Uv; Wed, 07 Oct 2026 04:41:43 -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 1xEInL-0007X3-U1 for qemu-devel@nongnu.org; Tue, 06 Oct 2026 23:58:23 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEInK-0003pN-5W for qemu-devel@nongnu.org; Tue, 06 Oct 2026 23:58:19 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5ba328513b9so1210084e87.1 for ; Tue, 06 Oct 2026 20:58:17 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791345496; x=1791950296; 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=ijBHVO8i4WEMr8/QksZUlHjObyra+9udgmuoDDxE/As=; b=Rxqxp6IujxDooASp3aKvRBBDeVqmpMUarOG/UG152UnU+LE2Rcd0PjRYyhNKB4Ih5b W5Jl4gmuOnfo633XSYpPAp1cZEUXLlC4Mhv2EZYh1+ln98sN2anc8Yve7zV0hHyE3RoE 7i5dh3g2QXFfStFvOv2jWVYJg4VbO3VbfjGL1qzve0gSX5GADaIzdGAiRnAWRdCzDifC HxCN4DLR/B5+XsKQnm6Qp6JdsPRNmJHZ/qiU+VimUVkjrUWQxOqsxgG/SHsYHSWhvQjA Y6rUe4tEV3j9EqXSk0J/CznLBP551i/g5lbuQSJjvx5B4iHJYYuHvDH4Nwfm/5iKsAAQ 9T4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791345496; x=1791950296; 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=ijBHVO8i4WEMr8/QksZUlHjObyra+9udgmuoDDxE/As=; b=AgF+eG2fNPqAhWtU2gW7K7gx5zV7V/KekL15D4JtBcC+GeL5LjDbHsNRJvXN15dK3m OCiCGIxsllKJS5wxP3PYN40CeYmQJv57ke5wtRkUYQUDhs92gSDgo4TGPVf05DmTGqcp bANuDJDLM0Q6C7cd1yKcwMUTu7V5+ke2R/eb4V8lNBvBrf0Ay9PGepg0RPfyy5Uze7T1 cVkXbWlES2hmZAWPxGxnfadddQgG/BaTnnY5ProIEHyLwh7wrq4+o5FKtu3Mi41Ga856 uKhmM5FdC2S6llysCbQNXeEkVlLLay0RQZJx+RhzDNiH8hlxFPWAr6EZf85IFVKUObSL /Waw== X-Gm-Message-State: AFq9FYKy25y1pL6PbubzeYW2t11S/8EQoziBUDJoSQ+/SbRAevTIKgsc JtY/we8+LCGoC7xoUT2Uqr+AtXTQU/RxcUc8OJ6LjAUI9jiApVRbAh2UUdZ88A== X-Gm-Gg: AYBFou05izDWv7MfBoAR4IZ0oj9OEDqAHMe/G67iJAii5iE3VwsikOdUY1+cQWdegXi mqR1k/rTmJd+mgjghj6qI5Rja18JNxkysXyqm2SO2bPUl+3X4Iw5feC1MdAKvqTgKqrxsSKz3ra Bn5egUujgcl4xi4e9NfRbhOr4hhv2U+4hjR6wORMfjZ35zcal6OvMwwIomeyDBHBc7nEElSDhOo HGu45KKcGN6ZzjPH3k9Y0qhw6ixpuBRe8tmWr/CwxtMxi5VR7xA4+aMW1hsMsKZSqUgrBlRF4oO qA1TSykn+tbl263/3uYrXd1XMkyXfSo/i7dlhiQjZuKzUwArBLoV1R/IHQDZaAqueWU9GRsWsuB VYc3wmk9su/XvhvLZOwaWRXKIPf0fni+cnskHuj+vgv5pgLaNV47ty/vMQ6B+IsBBdwg5Z/YngW X4SxuVy103YZyxoKRU9dbUmKO6+w9Du+KvmdTMSkXrdZYheBzKLoGuXurX8Dq97oUTHlLaZU9WW 6rMzcdAPJm72KCXSCpb3QXhS3J80xBLaR5a1Q== X-Received: by 2002:a05:600c:34d5:b0:49d:1fa8:b266 with SMTP id 5b1f17b1804b1-4a17b55b28bmr15234625e9.26.1791279910595; Tue, 06 Oct 2026 02:45:10 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH v5 6/8] hw/sd/sd: Optimize erase blocks as zero. Date: Tue, 6 Oct 2026 11:44:45 +0200 Message-ID: <20261006094447.43491-7-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> 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=2a00:1450:4864:20::12a; envelope-from=shentey@gmail.com; helo=mail-lf1-x12a.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: 1791363455142158500 Content-Type: text/plain; charset="utf-8" From: Christian Speich When erasing blocks as zero, we can use optimized block functions to achieve this. These allow us to request a large rage to be zeroed, possible optimizing this operation and freeing disk space for sparsesly stored images. This only is possible when erase-blocks-as-zero=3Dtrue is used and can provide a significant performance boost. The case where 0xFF is used during erase is as slow as before. Signed-off-by: Christian Speich Signed-off-by: Bernhard Beschow --- hw/sd/sd.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c40097924c..03c51b0291 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1322,6 +1322,26 @@ exit: trace_sdcard_rpmb_write_block(req, lduw_be_p(&sd->rpmb.result.result)); } =20 +/* Requires sd->data to be filled with 0xFF */ +static void sd_erase_ff(SDState *sd, uint64_t addr, size_t len) +{ + int erase_len =3D 1 << HWBLOCK_SHIFT; + uint64_t erase_addr; + + for (erase_addr =3D addr; erase_addr < addr + len; erase_addr +=3D era= se_len) { + sd_blk_write(sd, sd->data, erase_addr, erase_len); + } +} + +static void sd_blk_erase(SDState *sd, uint64_t addr, size_t len) +{ + if (sd->erase_blocks_as_zero) { + blk_pwrite_zeroes(sd->blk, addr + sd_part_offset(sd), len, 0); + } else { + sd_erase_ff(sd, addr, len); + } +} + static void sd_erase(SDState *sd) { uint64_t erase_start =3D sd->erase_start; @@ -1329,7 +1349,6 @@ static void sd_erase(SDState *sd) bool sdsc =3D true; uint64_t wpnum; uint64_t erase_addr; - int erase_len =3D 1 << HWBLOCK_SHIFT; =20 trace_sdcard_erase(sd->erase_start, sd->erase_end); if (sd->erase_start =3D=3D INVALID_ADDRESS @@ -1358,24 +1377,28 @@ static void sd_erase(SDState *sd) sd->erase_end =3D INVALID_ADDRESS; sd->csd[14] |=3D 0x40; =20 - if (sd->erase_blocks_as_zero) { - memset(sd->data, 0x0, erase_len); - } else { - memset(sd->data, 0xFF, erase_len); + if (!sd->erase_blocks_as_zero) { + memset(sd->data, 0xFF, 1 << HWBLOCK_SHIFT); } =20 - for (erase_addr =3D erase_start; erase_addr <=3D erase_end; - erase_addr +=3D erase_len) { - if (sdsc) { - /* Only SDSC cards support write protect groups */ + /* Only SDSC cards support write protect groups */ + if (sdsc) { + for (erase_addr =3D erase_start; erase_addr <=3D erase_end; + erase_addr =3D ROUND_UP(erase_addr + 1, WPGROUP_SIZE)) { + uint64_t wp_group_end =3D ROUND_UP(erase_addr + 1, WPGROUP_SIZ= E) - 1; + size_t erase_len =3D MIN(erase_end, wp_group_end) - erase_addr; + wpnum =3D sd_addr_to_wpnum(erase_addr); assert(wpnum < sd->wp_group_bits); if (test_bit(wpnum, sd->wp_group_bmap)) { sd->card_status |=3D WP_ERASE_SKIP; continue; } + + sd_blk_erase(sd, erase_addr, erase_len); } - sd_blk_write(sd, sd->data, erase_addr, erase_len); + } else { + sd_blk_erase(sd, erase_start, erase_end - erase_start); } } =20 --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791363957; cv=none; d=zohomail.com; s=zohoarc; b=F63plSLyJPpXMHGzYTyHXvZDeOPKMa4GaYnlKqoDjJVEuSVFe7EP8KH2j0JXAM3GF4GuIWMpDVrpTkdPuYUPvZ1Qi2ihFn9Bu9fs1+0wNxvEGIfOvj/DqKAhGzyo7yMwFMY33b7N7mDem6gTR+Mj/9mLO7SOTZ7FD1vo3gJLkE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791363957; 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=wKcbZxFVNlLilCNRix49XjJCUS9fhra/dn6x/AnwPTA=; b=VxogXa92xjYGNFyFJJquQT4yuhC+yKjt/p1hyRtPNRa/BBSykEj0k6YN6+XZPHljoxVTdUOHBgQ9l417aN6pnKoHzsQZxNkotlZNGWOtGgZj6+/iD4vIEYWkYCtOQzYl4KtnpWAPmYmtRQptpgyFDGKpvR9Stebz6RjHkNWZgjc= 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 1791363957735355.8834773072068; Wed, 7 Oct 2026 02:05:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENH5-0004S5-Qa; Wed, 07 Oct 2026 04:45:23 -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 1xEJNH-0004Ly-7s for qemu-devel@nongnu.org; Wed, 07 Oct 2026 00:35:38 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEJNC-0001yF-7R for qemu-devel@nongnu.org; Wed, 07 Oct 2026 00:35:23 -0400 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-6afe8d3980aso1303961a12.1 for ; Tue, 06 Oct 2026 21:35:21 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791347721; x=1791952521; 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=wKcbZxFVNlLilCNRix49XjJCUS9fhra/dn6x/AnwPTA=; b=LtMp9IyU2nguv4wgqsRxJgRVoMOHR2CpYQE77Gn4DfeA/GuEUAP/l8cQNmKuIFM4S9 oqf8f+sOfiXjml9HUKqP559DTKFsOiULREtFHPJREumha2VsOY9QGlbSfEzKckKuKCmC PTtVSSL2An5KVjIOvxvJqSUCeLJSTQ4Y3B3pp3ZNfZEW/AheVTbnh8FHWU4WmATFnTpy S3UyuiiofwmryM/y/hA/ncYnjFutRls0/6DHamQ4pX3XtafPpAQVIWW8kpoFGHCQS3Hc RUe58U5/Q7Hrp3bLGGpMahPcvNKYzWxYzpKxFNs4yMgDPkQz669r8NTmUDzOOt61vPqw TumA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791347721; x=1791952521; 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=wKcbZxFVNlLilCNRix49XjJCUS9fhra/dn6x/AnwPTA=; b=r+iZ8BqOph2uOgv5Cks1pUPql7uQkFKyhh2jC8//ZRbpzk250U0SKpdldAIUishUXo gkdfrhDQka3XIK8hll5vq6jiQg5oSKKVHOp21yT8p75Xlqwi1Mw/PliREI3Kxeo19bwj d+vaHhX43t2wMaUuXZFpXPwwGdpfcQlL9ulRaPduiMhGe491f06RIMVti0yneW7ufmup o9QG2C9N8idIyiDKUpKatZgo+YE+EetLAA0hFWI7/Zr/QWnYJsSdlbNhX/YoPqTVTQbG f+gNV+i1S97oKTfP39j9qpO38Jn9Kcz/yc5XrfrpK/x/jKuy3fKjHfBgo/Vei8J4h9XE ybHg== X-Gm-Message-State: AFq9FYIZF0nZqblDqJlanJ6bZ+117Cs1F7wPwyRqHgO1oNo6OZmW2UAJ KYGWCdSZ7wwxCaWhnqQ1zy9PG30wg+lI8v+E3WrsNRQ3MxAtqvNSWL5Bpx/gjA== X-Gm-Gg: AYBFou1JduQn6oaX//94HMrcngAbjCNSvS/MUvc35j1ela5WWDmT5Oq2F+jCE+pJ6Tk 3Kjggo48BY0Qoyj0cpAA8UvETlOXXfrNItD6R9ixHdutYHsV1VF3kkpkH9PyXz6Kwr2XuwL/lra 6oXV/CsENSjowofZVR6hLeCk+Wi5a0wfyieS64goNVzIUAKhwyqq/yWHijqHIqLEDfHNFj4tm+l OCvyEo11SLRInGeE3WW9Yi13kWh60XcxmmVJVryLjbBGsne7wnrmLAgYq5n8lE7V6QMdbGlluaQ zgv2OSAwC7b/AsyNsPsiGWiznnRKsPM3J0SUCCLvX1yjeAllM9ITpenXXT5WZpSHJ9VHf6ZOX9X 9y4kO4Vv8yZqDp1Q8KBxgGtWWqKwE1fpxlEqvi8Tgt214mYksmRKHwc0T+NdkrVKin1oUryFlAB /PCqvXr0kkAK5sJy9ONcIn71SGtYqZxk5uDdQJAHTYAgrS8lvyhUYAF+RGVR9LWQzh5FFna6NXb g67CBD5IM2cbG+vh+Jk9xyQuuRET6fKtncvNI/GzJsCP3yl X-Received: by 2002:a05:6000:4b0d:b0:487:27f9:82f with SMTP id ffacd0b85a97d-48c6d1a2624mr1369239f8f.36.1791279911635; Tue, 06 Oct 2026 02:45:11 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH v5 7/8] hw/sd/sd: Retype state attribute to SDCardStates Date: Tue, 6 Oct 2026 11:44:46 +0200 Message-ID: <20261006094447.43491-8-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> 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=2a00:1450:4864:20::535; envelope-from=shentey@gmail.com; helo=mail-ed1-x535.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: 1791363958326158500 Content-Type: text/plain; charset="utf-8" An enumeration is checked by the compiler, so is more robust. It also helps auto-completion, so is more ergonomic. Change the state attribute to be of type enum SDCardStates rather than int32_t to achieve both. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 03c51b0291..6295e7a942 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -172,7 +172,7 @@ struct SDState { =20 /* Runtime changeables */ =20 - int32_t state; /* current card state, one of SDCardStates */ + enum SDCardStates state; /* current card state */ uint32_t vhs; bool wp_switch; unsigned long *wp_group_bmap; --=20 2.56.0 From nobody Mon Nov 23 05:00:14 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=1791362928; cv=none; d=zohomail.com; s=zohoarc; b=Otv09YjtUi7NWg1MGrniKChVxdNqu1g2IgmHPleveIE7DPCUv6WITq8G3JkgmV8UqjS73vSKERVGAPk8j0qxidw5XDQXpO6f/lrSXc3mzzohX5dU9yfYtl6frSzHsf3FjGd2vGxmua3pkeDGsgsxnTws6Hv7+L8cIoR61FEgMbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791362928; 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=jKRx1YyyivMARcN7Ip7PPc1gr4r7pEfYbwdTqcTWbBM=; b=IdpkYaiGloEPUp0aaJPtJzoqrHI8Z8kcdGkTorInVjCxZmrp/oywhyhf795WKu1eKCHAkPkOp9ucssPNHgOgYSjtnLbujxq6sHVpFcUWwRNxCyRodtSBikVrOsGDfQKursBxqS7A9jdE77ORz6FngI22+NkiamGwOXVxAFz8yA8= 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 1791362928936628.211094129863; Wed, 7 Oct 2026 01:48:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENFr-0001GJ-Nj; Wed, 07 Oct 2026 04:44:03 -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 1xEIzb-0001ej-Fz for qemu-devel@nongnu.org; Wed, 07 Oct 2026 00:11:02 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xEIzY-0006fh-9P for qemu-devel@nongnu.org; Wed, 07 Oct 2026 00:10:57 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-6a082b3671fso2056439a12.3 for ; Tue, 06 Oct 2026 21:10:55 -0700 (PDT) Received: from archlinux (pd95eda80.dip0.t-ipconnect.de. [217.94.218.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c6faa93fbsm433426f8f.16.2026.10.06.02.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 02:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791346255; x=1791951055; 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=jKRx1YyyivMARcN7Ip7PPc1gr4r7pEfYbwdTqcTWbBM=; b=sWHY6eIwf3goh5GVgDhTzxYllEOwsKKe9WWHHBQiDBcZFjugCL0mHza0fqkA7EC2mP xLyRjJ98x5fSXaZwoZsnU49xOB5KkjVobPZ9LpgC7AJANgGNMKCC86ct4VXi83UvmUcV /q/i17NE/Usq5832wJXSDUncyopOXaF0RVGtCjsombGq3yo7+PRV2Z2BdWG1Y1qCu+uM J1bP+fsLT2i9lqWPCVduJh2oYktMk1LvaLGjslANQJhOeNLo6vwYLdWg+Ip735uw9EeX MncUWiRPglN05Mesrkti0Dqj5BLFJqqz7VdVOuRSJgiKxA3qpxib6/bZweqj2Fx1lxR1 tYrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791346255; x=1791951055; 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=jKRx1YyyivMARcN7Ip7PPc1gr4r7pEfYbwdTqcTWbBM=; b=eiFr+40QvlTRtAnKvqCs4SDpIsjomiYpiU/RSA2lLxywxvDdrA7rTpjRTiMJdoeWKB ghG7I4W1kPHCv5GT/nsUFN4DnRg7rPqpQ2RnqJ0UA6WSDX+IHOJoe/BQIjblci8BGzDk eZ2PQkPMVYvaIwDsQmo2OHYaHmoD/UpTmtPn2Mh8tMRLXlJB+sBuOZZ0fhFjtwcJem4y OndqPnI81+L2rBalsIIl3ig0bWnSYvkJt6VGuoq1IVJedmz1QHBlVno9YdbMhhueSCxQ K4tuyeA2L4lJhn7ZdrMyWX0VO2wk7joBHFwXCe5SWJAdj+S6ozzAUrf9GFh14ITZ5KcI /yow== X-Gm-Message-State: AFq9FYK6MXDKvjVuq5ExTtjrByV6l6d35uS9rrX4Kx2OwzcZtgt1ig1a aXsnvDn9cpwyFrdfwzKAn+2Nj56e8pRhfKtxCxr+oulJJhnVBK/NcxzYsxH2eg== X-Gm-Gg: AYBFou1jli7wC0SC9Vfqqa4l3VNcS0TTZo5eIhKhZqqAofy/vvjVkk1BUpeJn6o1R9z NppfUOee9CriQfyKLke6bF5m5O1CLrkw2yGW5tWe2Z8DjdeLiSIwmNpHJrcmW5/RkwWsPLRO61O z19tqBbzX2UYtyqhSs3RQ+zluvDtYTqc+xXF5bdWGig3NwvB17w9cGGiY14utzo03Q3wfv7RFlK kQ/eTQb0DozAMKRg8HC0oxCN8QHdlVVE+ZGgDAJNQaKW+ebM5Mt2xMbXEKbu1lhH3FSmzE+DzoY i6WhLbjfr6bIwfUtiobrrqvtbps40Th+uV4j/TsS1Qdn4B80zlmgQel6h6qphdP+il47h/+nJ/T dRyKVu41xrAFqrxcu+0UujvtyIJ613KeWzharHon0XBYthZNVekHagOhnLS2uy5q+tS4ugvDHch NKZzzv/Wz1+JpJY+bCm46P1t+iHV0FVfhSTgAIZZx52aFSiC4RU2+/PSRJjDyjPhiDG/jRSqbY1 8Tfs3T0q1+5I6IikVUAmyWn2dQsC9ZKiejujg== X-Received: by 2002:a05:600c:4fc2:b0:49f:e8bf:8f9b with SMTP id 5b1f17b1804b1-4a17b4f4d36mr14958855e9.4.1791279912496; Tue, 06 Oct 2026 02:45:12 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Speich , Bin Meng , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH v5 8/8] hw/sd/sd: Remove unneeded forward declaration Date: Tue, 6 Oct 2026 11:44:47 +0200 Message-ID: <20261006094447.43491-9-shentey@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006094447.43491-1-shentey@gmail.com> References: <20261006094447.43491-1-shentey@gmail.com> 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=2a00:1450:4864:20::533; envelope-from=shentey@gmail.com; helo=mail-ed1-x533.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: 1791362930053158500 Content-Type: text/plain; charset="utf-8" No need for a forward declaration of sd_realize() since it is only used after its definition. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6295e7a942..e6452226bc 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -209,8 +209,6 @@ struct SDState { char *preset_auth_key; }; =20 -static void sd_realize(DeviceState *dev, Error **errp); - static const SDProto sd_proto_spi; static const SDProto sd_proto_emmc; =20 --=20 2.56.0