From nobody Mon Nov 25 01:43:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1719505529935895.2111829686766; Thu, 27 Jun 2024 09:25:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C1E7ECF0; Thu, 27 Jun 2024 12:25:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id ECB4CE01; Thu, 27 Jun 2024 12:24:21 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7B0D413B2; Thu, 27 Jun 2024 12:24:17 -0400 (EDT) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CDCB313C6 for ; Thu, 27 Jun 2024 12:24:01 -0400 (EDT) Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-424acfff613so25428405e9.0 for ; Thu, 27 Jun 2024 09:24:01 -0700 (PDT) Received: from localhost.localdomain (33.red-95-127-46.staticip.rima-tde.net. [95.127.46.33]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424c8246b1dsm76798185e9.6.2024.06.27.09.23.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:24:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719505441; x=1720110241; darn=lists.libvirt.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; bh=8X6AtOCpBUXAQ/1xHubY59Be7qdcbmyzPDPReyo42Nc=; b=U0KvED0iPdGr7Za2xZOsj8RHelwRPjJ5mN/tyvaH5Wjp4rhvSl2X7KG6OVjJJ9FR1s VPMKOMaXSc3I3LwEiMUfMyrJi12dktRZUvuawMAnQ+uo+jw7Z+PGo4rea3aMo7QcB6EE zYlr6aN4VLUrQneVZhgeeqOO5R3PlBnF9m11+pnzFiAzVZe+8wyg6btGY02MtcPYbpGv AoTeQzeUImGU+2XIZzcopnz3qYzzYtZLsR4SWv11e7WtGvAB6YerKJX0+WvL57/TjkNr /ECp2rDot74S0c+9BUw1jF4oeeCKbG7yfPqDfx4qVJY5aCWEu4iXeXIt7dWERH1hpPyd EzPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719505441; x=1720110241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8X6AtOCpBUXAQ/1xHubY59Be7qdcbmyzPDPReyo42Nc=; b=K67Hwbc2+c0wharI3l1nFlQ3B2NCxYgDE4qqR+/PswCqq2Q6oZ2/x/4CutgJg4b/J3 fUPVQpDWxbRsNMOkOnfpSaRqz3WkpLlf29LVtnaTJJDksgMixAm1uCkk1sIkufDr2kKP AzPtEOtOYPNhHmbp45xgX9exNAX3maIurHoy7nGrgmQbuXLFIrcvi+33uiSzQz2dpWze CZELWASz9nAgD6gZpDLJvuXl86h4GHu3lkhmeJEJTogepUsqGsQbcupvI8HqUfdtxJp0 EOHIbOSYO+y7T+IjRayaIRClZfy7iOkB6S4eoiz6883VGsPl5/yzUkyQOdtOPOQ+rDHQ /Lgw== X-Forwarded-Encrypted: i=1; AJvYcCWsxBpUX3LkXZStBMHc3Ndooq1h1fnkb6+O5FrznMo3vntJcETN2sPc2JSY/3rUNxdn+g18WPSwFFclN6RY4PKSYepCui5HXQ== X-Gm-Message-State: AOJu0YztDtqESZqkirtWcZHHfec9oKUwiKJhmn9P/PNCPAFtTBdlgNYk M7hPVVzHMoEuB25NshRyZrNC/sMTcp8yFc9wpIp6EF4D+3KfVtGJKeibmRLr2SY= X-Google-Smtp-Source: AGHT+IHFhVoufCdvBfDNvagVn5p34PLe86CiYRsxIjjhPSD1BvJLJJNbCSXssHH758sWjmfqowailQ== X-Received: by 2002:a05:600c:4f07:b0:421:dd8c:35a3 with SMTP id 5b1f17b1804b1-4248cc586d0mr116166515e9.26.1719505440758; Thu, 27 Jun 2024 09:24:00 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 06/17] hw/sd/sdcard: Do not store vendor data on block drive (CMD56) Date: Thu, 27 Jun 2024 18:22:21 +0200 Message-ID: <20240627162232.80428-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627162232.80428-1-philmd@linaro.org> References: <20240627162232.80428-1-philmd@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6VJNQHD23SWKBQDXIFSZK2LX4UPIK2PC X-Message-ID-Hash: 6VJNQHD23SWKBQDXIFSZK2LX4UPIK2PC X-MailFrom: philmd@linaro.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: qemu-block@nongnu.org, Laurent Vivier , Tyrone Ting , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng , Hao Wu , Francisco Iglesias , Paolo Bonzini , Thomas Huth , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-arm@nongnu.org, Joel Stanley , Sai Pavan Boddu , devel@lists.libvirt.org, Luc Michel , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Xu , Fabiano Rosas X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1719505530759100001 Content-Type: text/plain; charset="utf-8" "General command" (GEN_CMD, CMD56) is described as: GEN_CMD is the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning. Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Tested-by: C=C3=A9dric Le Goater --- RFC: Is it safe to reuse VMSTATE_UNUSED_V() (which happens to be the same size)? Cc: Peter Xu Cc: Fabiano Rosas --- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 464576751a..1f3eea6e84 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -142,6 +142,8 @@ struct SDState { uint64_t data_start; uint32_t data_offset; uint8_t data[512]; + uint8_t vendor_data[512]; + qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; @@ -656,6 +658,7 @@ static void sd_reset(DeviceState *dev) sd->wp_switch =3D sd->blk ? !blk_is_writable(sd->blk) : false; sd->wp_group_bits =3D sect; sd->wp_group_bmap =3D bitmap_new(sd->wp_group_bits); + memset(sd->vendor_data, 0xec, sizeof(sd->vendor_data)); memset(sd->function_group, 0, sizeof(sd->function_group)); sd->erase_start =3D INVALID_ADDRESS; sd->erase_end =3D INVALID_ADDRESS; @@ -771,7 +774,7 @@ static const VMStateDescription sd_vmstate =3D { VMSTATE_UINT64(data_start, SDState), VMSTATE_UINT32(data_offset, SDState), VMSTATE_UINT8_ARRAY(data, SDState, 512), - VMSTATE_UNUSED_V(1, 512), + VMSTATE_UINT8_ARRAY(vendor_data, SDState, 512), VMSTATE_BOOL(enable, SDState), VMSTATE_END_OF_LIST() }, @@ -2029,9 +2032,8 @@ void sd_write_byte(SDState *sd, uint8_t value) break; =20 case 56: /* CMD56: GEN_CMD */ - sd->data[sd->data_offset ++] =3D value; - if (sd->data_offset >=3D sd->blk_len) { - APP_WRITE_BLOCK(sd->data_start, sd->data_offset); + sd->vendor_data[sd->data_offset ++] =3D value; + if (sd->data_offset >=3D sizeof(sd->vendor_data)) { sd->state =3D sd_transfer_state; } break; @@ -2165,12 +2167,11 @@ uint8_t sd_read_byte(SDState *sd) break; =20 case 56: /* CMD56: GEN_CMD */ - if (sd->data_offset =3D=3D 0) - APP_READ_BLOCK(sd->data_start, sd->blk_len); - ret =3D sd->data[sd->data_offset ++]; + ret =3D sd->vendor_data[sd->data_offset ++]; =20 - if (sd->data_offset >=3D sd->blk_len) + if (sd->data_offset >=3D sizeof(sd->vendor_data)) { sd->state =3D sd_transfer_state; + } break; =20 default: --=20 2.41.0