From patchwork Thu Jun 27 16:22:21 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: 807814 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp889339wrn; Thu, 27 Jun 2024 09:24:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVwF0yIwBC6zXXAVR6mzM0zXpZ3YtvwsE8R41nMyhx5Y/cbJvJPFep1SD9F3nsR4DhfEuEKT+ONUJ3Xcrt81RNH X-Google-Smtp-Source: AGHT+IGKN0BoDdJyp6aBOOuaZhI5QEOip9wMloYzYIiAt1bbQDQxY5AGUczTW4IuFbWIxV77ofys X-Received: by 2002:a05:6830:44a1:b0:6fa:128a:557a with SMTP id 46e09a7af769-700b1213ca6mr20014317a34.20.1719505484633; Thu, 27 Jun 2024 09:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719505484; cv=none; d=google.com; s=arc-20160816; b=cL+XoZK8jCnJro79lPTnGvKrG2+TH6U9rXKMIvlHdmnJVxZ6ERd4XChlGejLm5Yeui f8+9IYvfLHKwhFgIfNxW3mWlKtq7lkji22cgR0Hh9mZffPN4BiUgy8pO59egqMHXcZXq hV7ATZiUZyrwfpY4iEUsWqhKakzAgza1VCJyRT+BWaxEDOMljXxYpAKJ6Er9fm1Vv9bB g7d1LK4OdMo7rB7qFixf2y7PoJgtzDhsiS8fHZP4hp5horCWEqt5pE05dmIl5t34NCEr aDZ5oX0yfP9HeA7VB3T/Ve6MgciB3UdUUAzjdWptaSr2H9cc4R2cb04/RC3UvNpdMqAm z7OA== 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=8X6AtOCpBUXAQ/1xHubY59Be7qdcbmyzPDPReyo42Nc=; fh=5XML3vQt+HMoI5gIGsJOFRukFSQ1eFP2dSC8cWdbehs=; b=SPB4jkQPGVKxX/yJF2Op/hYnyuRHEB0c8L7XJwh7H4PFQqSof8Gio3Cgl6U3hjUtRR cuetxpj0WCIyWis6vNjEh96LPbbU3xa1dmvTcUmjmuV4gAqfxDOmN2SNxGJ6aji7GLCm pQ4/8AOmxw2GOD8QZizWViXDhoJH19sLXqZxVrGsmCNH7nYsFKJEYE2hxuUMIsuV8Wix 0G5rVwvqc83ZwSiGMrCgQMXyS9FLwP0bsZJZGsjEe++z+kxloYWApeoAW73JikoMBhCM kBPeoUF21vs2W8S7DyCPUM4xymcCKwhZ8XbQlF8TgOL/6duXgYg0Qz7hazhtkzgbAbeP upOg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lDZhQmln; 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 af79cd13be357-79d5c8cf454si159864685a.681.2024.06.27.09.24.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:24:44 -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=lDZhQmln; 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 1sMruq-0005DD-NE; Thu, 27 Jun 2024 12:24:08 -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 1sMrun-0004oc-Tg for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:24:06 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMruk-0008PL-J5 for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:24:05 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42565cdf99cso8429235e9.3 for ; Thu, 27 Jun 2024 09:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719505441; x=1720110241; 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=8X6AtOCpBUXAQ/1xHubY59Be7qdcbmyzPDPReyo42Nc=; b=lDZhQmlnBgasyBcj7jL/oMVauEXD9X2Y2rsmp+UadHuV97/s1Eh3FHwyp3hgCMuCej SsAALmXkLtX4DC7I5wDGyE5b7PMMbH94WFnUoRFmVudWkw8Ka8FYQ3LiUToVlgLleG2j xgCZww43gkC3dK8tL1sOMOz8qBy7BE//cGvFgGFzOB7CJa03h7G2q8+dCHNy7mIOatHd jrKxlaXiejTZ2C3G+8EMFKQvTyPVkVFENEb1h+lfhnHaDPAre49mEd0nzxdGEFqqVAlu ZXe0N1ZQ7u6FSxW6TyFiFa6zft6vfHILVUA3C8aOSP4KoIkZbCz/RI27oUhOrKUda4Nc DaoQ== 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=bqPf4WsVYqdlA2e12Ft8xTjNABg6ZPfsaUgnHVgqskAVNuPRGBCUgKGqQ3gsVPLCUl RjlUHj7wSgpx4tb5g6Ud9oDIL8m03RhwWnwtAB75GqdZQ1aLvsb0ykXPMPKXgELsP7fc 71Ty6/dKj4osTDk78/iNJUxJNkSYxWj15ml4UEH4QZG0J0l/FKemLZdjj7ndkwgduXc/ PGVNKYLTmu6i2IY61RxRgEMcRTsi9ktbvDL4iHSLlG2WXBo+el8KnGeKZUtd/E0XhJ5V usWKbnXOR52a1QIXeO9VVmMKKyooKUO6ohwEHQtDFnHXPpsXuJWa4j3LgaptQI2I5Ftw /rag== X-Gm-Message-State: AOJu0YxW67/x7+1sBnVXtkUpcJmQOAVI8fCBBZ90gAG/B0LpjveOXpcI PGSVujIEF6FWnxq1fRbgMiqU3Xrn2FeL6kvREOdOyKWI+gnAO+Maqcmmd71Nh0PxeDzlQSE6eJl FgC8= 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Laurent Vivier , Tyrone Ting , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Hao Wu , Francisco Iglesias , Paolo Bonzini , Thomas Huth , =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-arm@nongnu.org, Joel Stanley , Sai Pavan Boddu , devel@lists.libvirt.org, Luc Michel , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= , Peter Xu , Fabiano Rosas 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 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.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 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 = 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; @@ -771,7 +774,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() }, @@ -2029,9 +2032,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; @@ -2165,12 +2167,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: