From nobody Mon Nov 25 00:17:23 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719294949; cv=none; d=zohomail.com; s=zohoarc; b=k6KQ0BGhLqJUwrI+JAlhmse7jHQCZnK/zt7mMHa8gAlVLAs2SOIiByMGqabnLzk6TwNgt0Fo7RjkTOKb2CjhoBEZYvnLSHmT8UBkyQmWC3RGNmEiMLCTLFNkkw17JBlgxXEOcrNJlT83qKVJTJt30gedLR3GgLCDSsjQkIzSeQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719294949; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Jx8nddqay2J5qb2F3WGg5BgvSRB/NLqHqQ/hS1TB/ro=; b=ifPgrAhgKdmVBRmJBpRr6xbiocar+41R+kPrcK8O1cQPcbjTO/y+zE9c8Oa1hyXn3NiB+EN+y2B7kNWemaAGnFN3VHwB+G9rEhYjyF1Y40hH4m/lgmitW5P4J9XDnDwhyoUJZr0UDRkfNlxFuU6ILMXqnjU5e6pd1XVCBoSBls4= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719294949410939.590767994452; Mon, 24 Jun 2024 22:55:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8P-0001fs-R4; Tue, 25 Jun 2024 01:54:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8O-0001fP-TI for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:28 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8N-0001bl-9P for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:28 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3636c572257so4373476f8f.0 for ; Mon, 24 Jun 2024 22:54:26 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208e13sm195345575e9.36.2024.06.24.22.54.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294865; x=1719899665; 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; bh=Jx8nddqay2J5qb2F3WGg5BgvSRB/NLqHqQ/hS1TB/ro=; b=BHgf19KFSS35ocGMl5MjIlgWSey0IrQlkmrvZVEQI7itULuEjgpaCyKzgvGIVqTyce fmk9a0ZOVbieokPHS9d5DNQ2cUjZA7pYuD4DDJieHkgFvXTSgIh/NTCBe4PmjRtdVpVx kNu1JW9X26TsvZozqD0XDZk7x8jYSCkLynsmA8PI8kF51g1VpGHF0C+cJ0YwbZCGEUnL 3Mu2o+tptn1xNJlH9Q7X04yz3dt6Y/0JUT936PdlpsTDl7Ny8V+TNYbd0DQ9MfYJvojI QTi5hS9xTVoDdE4+xnmay60kxpO3JIrdkv6uQERK8luydxHTKCTm7cTYibFFpUezRFBG EvIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294865; x=1719899665; 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=Jx8nddqay2J5qb2F3WGg5BgvSRB/NLqHqQ/hS1TB/ro=; b=l1sZtTdpMOiF/cW2bI5Wxo3f9ymEN9+cDszYRmnTpl+Y4D+yxhWRxUXpNaV+UggtBZ rIYfQxFEUp66K+mE/hzFu8MazfAPHX7pcRaL69yUnbxjpwbvBxW4Ok+ySUF++O1n+NYn 3TUpvNuLG1DvgMzby68ognRHcjG/YGBcRy4EBn0aEea4qKmkoik1JCnMvCIvCaOC5v7W CVfjltcfREoPIQzFQPoTwvEL72A/yYwzgaoG1lgkFzTigh/rxSydYt77CGgcYBvzRRtc 7Ptlvfwoib6Jdr/LaXwJPOAvVS4sG+yoYeboAiO9JQ55/4LTandHTYL250YVaQNavkBl 3USA== X-Gm-Message-State: AOJu0YxxPtUmUG3qfU8qQ2m68OPF1NGi74OzQFN33AzM/Wpocxkb+ptK LtRjvond+c7nP3aVkPKqpT4s6QskvN7G6eizzKc0maQGLUrJuk42ZwEqWYqN4C7iDSBZbJIiwqT j X-Google-Smtp-Source: AGHT+IHFXhdXxP7UQ/eJnv5ppGcrgkC88yZHp35w9j0TvL7sbB31jFVa1rEMIclc953ODSLvxbciKw== X-Received: by 2002:adf:f450:0:b0:360:9a40:3dd8 with SMTP id ffacd0b85a97d-366e96567cemr5210858f8f.65.1719294865378; Mon, 24 Jun 2024 22:54:25 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Bin Meng , Peter Xu , Fabiano Rosas Subject: [PATCH v2 05/12] hw/sd/sdcard: Do not store vendor data on block drive (CMD56) Date: Tue, 25 Jun 2024 07:53:46 +0200 Message-ID: <20240625055354.23273-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=philmd@linaro.org; helo=mail-wr1-x434.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, 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: 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 @linaro.org) X-ZM-MESSAGEID: 1719294950907100005 "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 e4587a0a37..0f8440efcc 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -143,6 +143,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; @@ -647,6 +649,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; @@ -762,7 +765,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() }, @@ -2020,9 +2023,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; @@ -2156,12 +2158,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