From patchwork Tue Jun 25 05:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 807245 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2195736wrt; Mon, 24 Jun 2024 22:55:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVEYEFyeaY4AWIYtvFSM+osEHNH4+E4uzY01rgQ2G7nsq62CR4vBOrwACdIGtBTwUtoXVCROreNiDcD+V2HHtOg X-Google-Smtp-Source: AGHT+IE0AnOxF03cpRvM2qi+0AiUXRBpCzqojtEGML2lWbLQ2BzOnHY3Q5NKLm6Ug+8klbXDYVfT X-Received: by 2002:a67:ee41:0:b0:48f:3f55:c550 with SMTP id ada2fe7eead31-48f52a356dfmr6754371137.16.1719294949177; Mon, 24 Jun 2024 22:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719294949; cv=none; d=google.com; s=arc-20160816; b=CEmILRZlOPvitB+ZIkkZFeJ7e33ZPU/lNDbfV8Cn5zf4bXHMXIHOgFTyQcwptBF418 LbbeWmZWXxHq3x7Tcbcu2Kl+nQcy1aYwZzKDJILLrh50ZaaYeixem/B/g4NLvBSmMd9/ l1GAwvCcAeatSHjPdw0QXXxxtoTK+G5qIObrMyffvBSawzh/be/Q4Vipb6VbPOicy8Ou Q+9GIw3BecPp56zuDmLPLsL9+q6+KfNoxaB3S21mUbtTCtvv0jSZXu1aWCnub48eJ0O+ fNLoKFGm39r7oLV2MhwghfoN7/pyFSKbJWwi5Npcr5SEpEq5Auw2ltvOTvx+ORJfuM0i ax4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Jx8nddqay2J5qb2F3WGg5BgvSRB/NLqHqQ/hS1TB/ro=; fh=kCRCpXTlg6+oYN72O8LggFIMjcK4P6HtgE+/z1k9kdE=; b=UpPqDY9ZQaVZDdRWxNfbHBNxgwNxUSwtweo32PUtSfXXzZa5QjFcidVFvxFSuwSJ/H qyqivOz4Jxp1M5Q/HYrfTfsAj6T/CdyvDnKMb9J2CQ1YOtOy1Nccfq91HZbRJk6CHPKS bCTc4IPuRB/C4Cwt686g7o5e6/BTXVKvfS75RD9H9AjZzgto6N6yEyuvxpQ45FGgpsMp lgRzNbRz48qsDRty6tUJ0dO1O96g46b/byVeGOIImPYrk9B4fYZLhHP7BqWAuFkbYdKi bG44QCmdteobaUHxfaDfDHAXc3KuDtPRZPMUEIqOcK3x9MrrThOri9AW8UNR97QXcSYZ yaXQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BHgf19KF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-444c2c0bd57si97812201cf.230.2024.06.24.22.55.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jun 2024 22:55:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BHgf19KF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org "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é Tested-by: Cédric 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 = sd->blk ? !blk_is_writable(sd->blk) : false; sd->wp_group_bits = sect; sd->wp_group_bmap = 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 = INVALID_ADDRESS; sd->erase_end = INVALID_ADDRESS; @@ -762,7 +765,7 @@ static const VMStateDescription sd_vmstate = { 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; case 56: /* CMD56: GEN_CMD */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { - APP_WRITE_BLOCK(sd->data_start, sd->data_offset); + sd->vendor_data[sd->data_offset ++] = value; + if (sd->data_offset >= sizeof(sd->vendor_data)) { sd->state = sd_transfer_state; } break; @@ -2156,12 +2158,11 @@ uint8_t sd_read_byte(SDState *sd) break; case 56: /* CMD56: GEN_CMD */ - if (sd->data_offset == 0) - APP_READ_BLOCK(sd->data_start, sd->blk_len); - ret = sd->data[sd->data_offset ++]; + ret = sd->vendor_data[sd->data_offset ++]; - if (sd->data_offset >= sd->blk_len) + if (sd->data_offset >= sizeof(sd->vendor_data)) { sd->state = sd_transfer_state; + } break; default: