From patchwork Fri Jun 26 16:40:12 2020 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: 279294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C424AC433E0 for ; Fri, 26 Jun 2020 16:42:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 92337207FC for ; Fri, 26 Jun 2020 16:42:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ng6BJikd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92337207FC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorQZ-00022O-Qs for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:42:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorOz-000095-Cs; Fri, 26 Jun 2020 12:40:34 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorOx-00060C-UR; Fri, 26 Jun 2020 12:40:33 -0400 Received: by mail-wm1-x341.google.com with SMTP id f139so9955636wmf.5; Fri, 26 Jun 2020 09:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VaBeUAKeU/Fm4s8wzR3hU4H0t6OdWhihwFpjUJ3q1zc=; b=Ng6BJikdvB8LzBCPa9mn2RSe91/E/ECsqj6YtFgVSJwrzTDvBExtg/Et/ltGexKDPw CFjE4ZUQsmwI72nawN/h5CBvLQLvF7lJagP9uj7X1ekv/D81LDZPL23Ug3xpxOhQ+By2 aIF9yTjoP5cREs8OAsunsKES79Hihen1yg+x48jtQ3BM5X+dieliKDcNMMY9kPcRv1Uu rVkGTFIu0NwJk39Tip6fSFuKpt3csMxEwTjuWAD08ebXEolMoDT62ffEFZAdxD9UAtbr 7fYW4pL7a9JQShVba6V3/p9YPSSwNOj08X0JRueT1ZHdL52qP8pA+87gCVAVUK/2cImU 9FUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=VaBeUAKeU/Fm4s8wzR3hU4H0t6OdWhihwFpjUJ3q1zc=; b=r4/+GXduHQJqrfwg/Q2b+Ka+pfxR9gjFt5zD8LcUtyrhpcjEIDGJg0Fwg4Qum8GnPN xOaVF+wwJs9h1baHPTLlbLsHj0beeT1ddvehby63ALoz2jtNarE/LjJVJjDr2muRAD4a HmW7yPBmPmZYyrX/agfqQczRuGnpy/pgEfqT1NxY9LmWqOJ/13IIowglR54PW1Ky9Mrx YIUsqjD2/cnp24pCu09i7lAxi6T6AcJrLm9H2vkWolRSdAPYSL1RYETKxXj0LdPFFg6K GozuHecMM9+KKKbKmNvn8EAOns/RA91s7eRFFd7tc3EJK227MqPE00ApgpRQw0Vgg1Uu IcYA== X-Gm-Message-State: AOAM531Jr0ARMjQrxsfB8wS8frAZI/LwJ5wnP/GhoHTep3hzmdhA87H2 ogudXBqR7EojfBNoO9O1dStam4sB X-Google-Smtp-Source: ABdhPJxO/UWo/gr1Bm+nEy+GofiC17JewdT32AAcMdA4ann0CEoqV9SmYQRD9Q34u2fOiJP9Q957Uw== X-Received: by 2002:a1c:4d05:: with SMTP id o5mr4323087wmh.130.1593189629946; Fri, 26 Jun 2020 09:40:29 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 01/15] MAINTAINERS: Cc qemu-block mailing list Date: Fri, 26 Jun 2020 18:40:12 +0200 Message-Id: <20200626164026.766-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , qemu-block@nongnu.org, Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé We forgot to include the qemu-block mailing list while adding this section in commit 076a0fc32a7. Fix this. Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daudé --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 1b40446c73..d9695a2cb3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1622,6 +1622,7 @@ F: hw/ssi/xilinx_* SD (Secure Card) M: Philippe Mathieu-Daudé +L: qemu-block@nongnu.org S: Odd Fixes F: include/hw/sd/sd* F: hw/sd/core.c From patchwork Fri Jun 26 16:40:15 2020 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: 279292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 182CBC433E0 for ; Fri, 26 Jun 2020 16:44:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6217207FC for ; Fri, 26 Jun 2020 16:44:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W3K2Q4y2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6217207FC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorSo-0007Bn-VJ for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:44:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorP2-0000Bl-Uz; Fri, 26 Jun 2020 12:40:36 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:32824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorP1-00063e-EE; Fri, 26 Jun 2020 12:40:36 -0400 Received: by mail-wr1-x444.google.com with SMTP id f18so2051099wrs.0; Fri, 26 Jun 2020 09:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i3AX6k9zJcs7ntcPjDjs5EOqKiW+/SX/Gp5bwn7hkCA=; b=W3K2Q4y2qDU44ulfxHCRH0KyRak+lLK3bC38voxVslIUvmvNupChJmUHrLFVbjjCXY CyCP4ENRXOR7Lj+R0yzizDXSpreQpoeJsaO1IeNgRVa9R0tZA9Rxzxs0P6QyF0a4aIli Uq05UUswjyCRWXDWW7knMqHo+OjmtIqhIE6Jh4RCDiDPCW1emis16uwT3ArX3iEiU+d9 OzalJGIZZoW109vYdJf5Z5biOxaj8w5Zr6+V1mcEINg2raAAgORHGynzjeinsbSWNVLG AvgzACT6xsvJ+xSvBa6pPJFdBY+jJMsaGIk9kCcCK/nLDRfjAEzXXHcksQUGPkwsDB2R FvWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=i3AX6k9zJcs7ntcPjDjs5EOqKiW+/SX/Gp5bwn7hkCA=; b=kPlL9hTUe8L1A/x2dvZ8k4h4INCYKm6E8PGFDNTYV3nTJ4rhRRMaHAP7KMtfWcuVrL rM4PGDjQ0a5Fzn6B5OHnk0dgsEahrl1+kfRcObHCk/vjnZ5jRcuAxIRK7diIAwGFi1MM JenW3zUeQe6lzTa3jfzsdDSU11r+xj9xfXsuVbD4yvnv5UmzZAtpwSO9d3oRUgF567lH g52mUS3Edqf2p7Uq4y0GTa6e4XkEhOEVGdp5AB99K5i6bwIfTaIMN+Ya7TXrMWPOnGH6 SIWybwmsywpmIOGuiMv6SF/4oIy8Lebif4cKZQJWvyOqlHgzTG1sKkHyoafUwe8PoTo5 cToQ== X-Gm-Message-State: AOAM530f9niVmyY5q9dR+7WbEmxa89E/tyEw9PRPiqAYwa6bGJ/bRrTT wGEIDcbCnXUFkSZ51DGn+k6byIzI X-Google-Smtp-Source: ABdhPJzQetAz7tlH5J19bKZzCLEcB5GO2eV0SpayrGEeY4037Ye0Vx4fR+n/9WVMQWeekJBkenKfpA== X-Received: by 2002:adf:e60e:: with SMTP id p14mr4546743wrm.31.1593189633565; Fri, 26 Jun 2020 09:40:33 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:33 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 04/15] hw/sd/sdcard: Use the HWBLOCK_SIZE definition Date: Fri, 26 Jun 2020 18:40:15 +0200 Message-Id: <20200626164026.766-5-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replace the following different uses of the same value by the same HWBLOCK_SIZE definition: - 512 (magic value) - 0x200 (magic value) - 1 << HWBLOCK_SHIFT Signed-off-by: Philippe Mathieu-Daudé --- 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 4816b4a462..04451fdad2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -81,6 +81,7 @@ enum SDCardStates { }; #define HWBLOCK_SHIFT 9 /* 512 bytes */ +#define HWBLOCK_SIZE (1 << HWBLOCK_SHIFT) #define SECTOR_SHIFT 5 /* 16 kilobytes */ #define WPGROUP_SHIFT 7 /* 2 megs */ #define CMULT_SHIFT 9 /* 512 times HWBLOCK_SIZE */ @@ -129,7 +130,7 @@ struct SDState { uint32_t blk_written; uint64_t data_start; uint32_t data_offset; - uint8_t data[512]; + uint8_t data[HWBLOCK_SIZE]; qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; @@ -410,7 +411,7 @@ static void sd_set_csd(SDState *sd, uint64_t size) ((HWBLOCK_SHIFT << 6) & 0xc0); sd->csd[14] = 0x00; /* File format group */ } else { /* SDHC */ - size /= 512 * KiB; + size /= HWBLOCK_SIZE * KiB; size -= 1; sd->csd[0] = 0x40; sd->csd[1] = 0x0e; @@ -574,7 +575,7 @@ static void sd_reset(DeviceState *dev) sd->erase_start = 0; sd->erase_end = 0; sd->size = size; - sd->blk_len = 0x200; + sd->blk_len = HWBLOCK_SIZE; sd->pwd_len = 0; sd->expecting_acmd = false; sd->dat_lines = 0xf; @@ -685,7 +686,7 @@ static const VMStateDescription sd_vmstate = { VMSTATE_UINT32(blk_written, SDState), VMSTATE_UINT64(data_start, SDState), VMSTATE_UINT32(data_offset, SDState), - VMSTATE_UINT8_ARRAY(data, SDState, 512), + VMSTATE_UINT8_ARRAY(data, SDState, HWBLOCK_SIZE), VMSTATE_UNUSED_V(1, 512), VMSTATE_BOOL(enable, SDState), VMSTATE_END_OF_LIST() @@ -754,8 +755,8 @@ static void sd_erase(SDState *sd) if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { /* High capacity memory card: erase units are 512 byte blocks */ - erase_start *= 512; - erase_end *= 512; + erase_start *= HWBLOCK_SIZE; + erase_end *= HWBLOCK_SIZE; } erase_start = sd_addr_to_wpnum(erase_start); @@ -1149,7 +1150,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 16: /* CMD16: SET_BLOCKLEN */ switch (sd->state) { case sd_transfer_state: - if (req.arg > (1 << HWBLOCK_SHIFT)) { + if (req.arg > HWBLOCK_SIZE) { sd->card_status |= BLOCK_LEN_ERROR; } else { trace_sdcard_set_blocklen(req.arg); @@ -1961,7 +1962,7 @@ uint8_t sd_read_data(SDState *sd) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return 0x00; - io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; + io_len = (sd->ocr & (1 << 30)) ? HWBLOCK_SIZE : sd->blk_len; trace_sdcard_read_data(sd->proto_name, sd_acmd_name(sd->current_cmd), From patchwork Fri Jun 26 16:40:16 2020 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: 279290 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C87B7C433E0 for ; Fri, 26 Jun 2020 16:46:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9529020781 for ; Fri, 26 Jun 2020 16:46:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sFpqFS17" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9529020781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorUX-0002jm-Nt for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:46:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorP5-0000EJ-5Z; Fri, 26 Jun 2020 12:40:39 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:32822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorP2-00064P-Sv; Fri, 26 Jun 2020 12:40:38 -0400 Received: by mail-wr1-x441.google.com with SMTP id f18so2051158wrs.0; Fri, 26 Jun 2020 09:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0q3fvINBMewfm4ouk0ChZ+kON+bgL7uzrdyA1Uly1X8=; b=sFpqFS17yQY79QZJMC3kh2U9izuekgcjP82dQoSZ/wCDhEqUPF0ztyG4JEgyv/pKDy WLKTt/AUhN2GzIQuXJNtY1XWDpbblALFqJu7rN32OXinwFZE9gD6VxpCbuTszk9tFE/f NdZlNS/pwQBAD7ss+VTdu6dT38xXiBW1ysO4VPEqw46WNgl3dE4VqkJYQZWw7LWHAnjG D11CriLzCs05Xh0+gXIhZn3EnV0PiEi14wrTJLEnCYY5Ki8XmtPS3dnSI3y0Rq4sWUba +Oa52s3Jsv2OyARs66W8XCIRXLz3MNJkDYNpHhlkMzWMcG1MPvl3Ge7NUJ6c2B35c1VU j51g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0q3fvINBMewfm4ouk0ChZ+kON+bgL7uzrdyA1Uly1X8=; b=VZ/hrtGN01/+cp4N1goitstJR3GiaTCtPwh4ZBRKWjigbHmlg8fxKhi4dguT5T34dk l11sBEjtZH9tcG1/G63AngawF/AvvQMYynml8miBicMUtUdzRZi+abimLvJADAnbg8rN yb0VgCn17re6pQw5BTk/+cPuLNzF5EC/BCDgrLCKH+veFBMWha1v0Aco+lVxOjrfWvVj c+yBRIB7TbpQuVo5ZeuXPiNv27TYRb3D1Czn8m/HrdhFbxgrTyelWaFFIBsItTd+/7O4 k6K4/R1c6r2ShOz5qXEWHl4va5URhVo6uGCmLV1fx0V073T8J8gG+6+m+fDCfZ+GvwUV u80g== X-Gm-Message-State: AOAM531GGBmnZr3b++IZ/zZKBBBlJOs6RJpI/9afQWXIlGrskyTVPqkT p1mcY6n5JaalW3rtdlwUm/v4VG38 X-Google-Smtp-Source: ABdhPJx0C6QgEFKTkcI8cBFl7F6ZZ9L4w1OVnliVkgzuQ97DLvG/cn1Xn592mb0DKG/1fzf7y36dhQ== X-Received: by 2002:a5d:6b08:: with SMTP id v8mr4885683wrw.2.1593189634749; Fri, 26 Jun 2020 09:40:34 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 05/15] hw/sd/sdcard: Do not switch to ReceivingData if address is invalid Date: Fri, 26 Jun 2020 18:40:16 +0200 Message-Id: <20200626164026.766-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Only move the state machine to ReceivingData if there is no pending error. This avoids later OOB access while processing commands queued. "SD Specifications Part 1 Physical Layer Simplified Spec. v3.01" 4.3.3 Data Read Read command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. 4.3.4 Data Write Write command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. WP_VIOLATION errors are not modified: the error bit is set, we stay in receive-data state, wait for a stop command. All further data transfer is ignored. See the check on sd->card_status at the beginning of sd_read_data() and sd_write_data(). Fixes: CVE-2020-13253 Cc: Prasad J Pandit Reported-by: Alexander Bulekov Buglink: https://bugs.launchpad.net/qemu/+bug/1880822 Signed-off-by: Philippe Mathieu-Daudé --- v4: Only modify ADDRESS_ERROR, not WP_VIOLATION (pm215) --- hw/sd/sd.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 04451fdad2..7e0d684aca 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1167,13 +1167,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 17: /* CMD17: READ_SINGLE_BLOCK */ switch (sd->state) { case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset = 0; if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; + return sd_r1; } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset = 0; return sd_r1; default: @@ -1184,13 +1186,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 18: /* CMD18: READ_MULTIPLE_BLOCK */ switch (sd->state) { case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset = 0; if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; + return sd_r1; } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset = 0; return sd_r1; default: @@ -1230,14 +1234,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Writing in SPI mode not implemented. */ if (sd->spi) break; + + if (sd->data_start + sd->blk_len > sd->size) { + sd->card_status |= ADDRESS_ERROR; + return sd_r1; + } + sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset = 0; sd->blk_written = 0; - if (sd->data_start + sd->blk_len > sd->size) { - sd->card_status |= ADDRESS_ERROR; - } if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; } @@ -1257,14 +1264,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Writing in SPI mode not implemented. */ if (sd->spi) break; + + if (sd->data_start + sd->blk_len > sd->size) { + sd->card_status |= ADDRESS_ERROR; + return sd_r1; + } + sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset = 0; sd->blk_written = 0; - if (sd->data_start + sd->blk_len > sd->size) { - sd->card_status |= ADDRESS_ERROR; - } if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; } From patchwork Fri Jun 26 16:40:17 2020 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: 279293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 151D8C433DF for ; Fri, 26 Jun 2020 16:43:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA472207FC for ; Fri, 26 Jun 2020 16:43:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="txwXMu4X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA472207FC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorRv-0005ND-3t for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:43:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorP6-0000Ez-BH; Fri, 26 Jun 2020 12:40:41 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:41804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorP4-00064t-1M; Fri, 26 Jun 2020 12:40:39 -0400 Received: by mail-wr1-x443.google.com with SMTP id h15so10103321wrq.8; Fri, 26 Jun 2020 09:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2FehWZv489g7gLp1IpuJgAw0ELgG4HGTfqwfreEPxtg=; b=txwXMu4XvTfD1f8pUQtQk9yXebkKYepKvggw1Vy3cu4GclrXThTd6ud0foK3bRYntS 6wtabgp+67wFTD0dMNy6CD6qkcRi8rCb+FC/ZBl4t207YvdHOCC5oiFpTQPVGh6+qnCm LlHOOw7WMqZaTBUpO9MBu5ykhC3jcIVt6SGzocvRnmbvRx4t7o/mGb/fsHyKG6XGMTnk YfG6SWbnMyRY6TO/I7uiXH9gK/mQbHFw51WeF2gxAzNrXz9cwFtSjiRpUjIhdAgnFzzs CNI8bTqvkvZ4WIcY2dx5HUALUdNBiBLq3V6OcYfMJwjt1wRNDc7dXi2fSl/pv89FIszO AxFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2FehWZv489g7gLp1IpuJgAw0ELgG4HGTfqwfreEPxtg=; b=OBZE9fTWxbdYDNO0wQf6VLvLzDz5T3VbiT4qSLCiJ6x9W9hdy+MVqJUAkURu9t06Re lJpiUvaCoh2T0V6ifMrk4npOYqfhFdPIfl6RIXjpelYJHtbsiAn9TLHj6JMrlVN1+A93 DhJE0bPMDffaiCikUmGrknEVUWNWtOGzfnmwtKUTF1CHxoIeFWz5pTSq3aBj6EyszQW2 vrXYz13ai7g8WFBP3Lnp6Uz9qLbXS2uKlFfc6vdIz1vfN0sci+15K5x2twnRRUCysW0t bp4JCa9DGn7NwtYfNfAmgrJoid6814diF7xxnhaeDvLK+xvjqdNd09cKFmA6/1zbDoJ4 BF4g== X-Gm-Message-State: AOAM532wc0MCT2ORI/3tWjgIIZQwCzCUAwYwMxc2oHLFJvXj2Jzmbvke 9GifoiVlROinnpU7+R645ydE4cjH X-Google-Smtp-Source: ABdhPJxhoIM0XKrZpYY5JRU12pZfUtcDMDVd8w90AzShwY73VCFzDA9QhdQW9mNLc343257Rvb8IOw== X-Received: by 2002:adf:de01:: with SMTP id b1mr4507277wrm.305.1593189636111; Fri, 26 Jun 2020 09:40:36 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 06/15] hw/sd/sdcard: Restrict Class 6 commands to SCSD cards Date: Fri, 26 Jun 2020 18:40:17 +0200 Message-Id: <20200626164026.766-7-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Only SCSD cards support Class 6 (Block Oriented Write Protection) commands. "SD Specifications Part 1 Physical Layer Simplified Spec. v3.01" 4.3.14 Command Functional Difference in Card Capacity Types * Write Protected Group SDHC and SDXC do not support write-protected groups. Issuing CMD28, CMD29 and CMD30 generates the ILLEGAL_COMMAND error. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 7e0d684aca..871c30a67f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -922,6 +922,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->multi_blk_cnt = 0; } + if (sd_cmd_class[req.cmd] == 6 && FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { + /* Only Standard Capacity cards support class 6 commands */ + return sd_illegal; + } + switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ case 0: /* CMD0: GO_IDLE_STATE */ From patchwork Fri Jun 26 16:40:19 2020 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: 279289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 087EDC433E0 for ; Fri, 26 Jun 2020 16:47:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC79220836 for ; Fri, 26 Jun 2020 16:47:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KJza6d7/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC79220836 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorVs-0005EL-V2 for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:47:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorP8-0000GW-W7; Fri, 26 Jun 2020 12:40:43 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:50744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorP6-00066w-EC; Fri, 26 Jun 2020 12:40:41 -0400 Received: by mail-wm1-x343.google.com with SMTP id l17so9431634wmj.0; Fri, 26 Jun 2020 09:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R2DX/QQvHKfKb103HIE/F7gpPXUpgK50o5/9QbI2yBE=; b=KJza6d7/0XHGk9QScJHiogDEx4Kr/QcZg6XDP5GgSEv46bAujP6d5YNaRKpMycyeKD FVNJ9bVhdv/sSuEhabHCUJyzj+G+bfjBbBcNa4TrhobyzZEmNNuYgaKaEAoqy6sl3tz4 YD7snXvqW07HGDcbDYJwpzK8+LzzcpVjcuL8pPKxLp0OaMtyMzivdpp63mwsNTJBDqxa n+ZNbpycmtLeh6AP79jp2/g1tZyDTkE0BkzeIr+NMpZ1tmb8Go9Cn0bbDJkxazUvH1Nu ma/5Fv0rDhlcQV7yai/82gPMseNHjyzT4HR4eSvcAA+vHr64oPo2fZKY8AN/R620ejZs cbhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=R2DX/QQvHKfKb103HIE/F7gpPXUpgK50o5/9QbI2yBE=; b=VsEKk/9GjRY1hOilXO1yvUO7UTMp+0fgg6FAXqNOOfbnFkxFf+8iOz7On4GGBoDSvZ AWeclD41v+zP9v43ZV6NtWrqPfll1GxvEvuVg7svNA9D5njij7jHHF+aNTX4OHXp3KAy utqomVNyI00jLQxRxTiqtYPbCJSyzzwoDeSkQfW65ZuQOxGaprf2Bn0gP0Ygo/oM/7He 0FHKjSMqJTGP8Qo/M/Tf5oPDVwd6XVljqPo5t/mErNyS5YHxx2opSfYQtHIhbFeIcbAe smwleSYV5XkOcmChMoFcX3v6GX9QFFPkAwVGacOJYEKIDtFOMm27VVTnSu5KVfYG9HfH 1ghA== X-Gm-Message-State: AOAM531PBBuU7iOUliQ31UXub3G5ohZOQb06jOJPgpI+qDUAWYr1ZkKj QHMh8png1iivztqQ4fHaUpxLn/SV X-Google-Smtp-Source: ABdhPJxQ+ftUwDr3GnixSzlUlHFNC7KeT3dhTezAnQ2x5WTO94b5OefT29xSTFBQtDC90ojVI/sWcw== X-Received: by 2002:a7b:c4d6:: with SMTP id g22mr4469593wmk.170.1593189638354; Fri, 26 Jun 2020 09:40:38 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:37 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 08/15] hw/sd/sdcard: Check address is in range Date: Fri, 26 Jun 2020 18:40:19 +0200 Message-Id: <20200626164026.766-9-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As a defense, assert if the requested address is out of the card area. Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 22392e5084..2689a27b49 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -537,8 +537,10 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response) stl_be_p(response, sd->vhs); } -static inline uint64_t sd_addr_to_wpnum(uint64_t addr) +static uint64_t sd_addr_to_wpnum(SDState *sd, uint64_t addr) { + assert(addr < sd->size); + return addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT); } @@ -575,7 +577,7 @@ static void sd_reset(DeviceState *dev) sd_set_cardstatus(sd); sd_set_sdstatus(sd); - sect = sd_addr_to_wpnum(size) + 1; + sect = sd_addr_to_wpnum(sd, size) + 1; g_free(sd->wp_groups); sd->wp_switch = sd->blk ? blk_is_read_only(sd->blk) : false; sd->wpgrps_size = sect; @@ -759,8 +761,8 @@ static void sd_erase(SDState *sd) erase_end *= HWBLOCK_SIZE; } - erase_start = sd_addr_to_wpnum(erase_start); - erase_end = sd_addr_to_wpnum(erase_end); + erase_start = sd_addr_to_wpnum(sd, erase_start); + erase_end = sd_addr_to_wpnum(sd, erase_end); sd->erase_start = 0; sd->erase_end = 0; sd->csd[14] |= 0x40; @@ -777,7 +779,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) uint32_t i, wpnum; uint32_t ret = 0; - wpnum = sd_addr_to_wpnum(addr); + wpnum = sd_addr_to_wpnum(sd, addr); for (i = 0; i < 32; i++, wpnum++, addr += WPGROUP_SIZE) { if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) { @@ -819,7 +821,7 @@ static void sd_function_switch(SDState *sd, uint32_t arg) static inline bool sd_wp_addr(SDState *sd, uint64_t addr) { - return test_bit(sd_addr_to_wpnum(addr), sd->wp_groups); + return test_bit(sd_addr_to_wpnum(sd, addr), sd->wp_groups); } static void sd_lock_command(SDState *sd) @@ -1331,7 +1333,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd->state = sd_programming_state; - set_bit(sd_addr_to_wpnum(addr), sd->wp_groups); + set_bit(sd_addr_to_wpnum(sd, addr), sd->wp_groups); /* Bzzzzzzztt .... Operation complete. */ sd->state = sd_transfer_state; return sd_r1b; @@ -1350,7 +1352,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd->state = sd_programming_state; - clear_bit(sd_addr_to_wpnum(addr), sd->wp_groups); + clear_bit(sd_addr_to_wpnum(sd, addr), sd->wp_groups); /* Bzzzzzzztt .... Operation complete. */ sd->state = sd_transfer_state; return sd_r1b; From patchwork Fri Jun 26 16:40:22 2020 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: 279288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACAD7C433DF for ; Fri, 26 Jun 2020 16:48:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B16720781 for ; Fri, 26 Jun 2020 16:48:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MQvo7wu4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B16720781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorWz-0006r0-3g for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:48:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorPB-0000KG-Km; Fri, 26 Jun 2020 12:40:46 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorP9-0006AA-W7; Fri, 26 Jun 2020 12:40:45 -0400 Received: by mail-wr1-x442.google.com with SMTP id q5so10105174wru.6; Fri, 26 Jun 2020 09:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MLHuRhPJGMB88pWHM3hcWsOQI5A3QGzGpgPvgJRjRm0=; b=MQvo7wu4n32HNHV3DP4Y/rL9zFXpwifhHqwAgOfx+wSfl6rMR4ZCkVg5q1VqixBLcc xGmcT6oJ4IgYlsI+2sTz7rfkfl7SGSCZs4djTVTEP9Lm1Al2FU9qo2Y1HGlskmuqaqFh gp9/qzwsK1L6k5z5GHAH0uuuUIH0jZSHURvg856eDOA0WMGbMf3WoYb/edWXWdEg1KW8 vr2ol1S9ka+etHoHyYRYhGRRitE7xmZX63CTeNgoUfy76TcKpamU5fo0HjGbSEGQMGPh ZfcIbaTQusSogly6XCRwAPj1VhNPytaBoSAG1c+UTCWJ3AQYRHckj09nZyiS80adM5FZ rzPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MLHuRhPJGMB88pWHM3hcWsOQI5A3QGzGpgPvgJRjRm0=; b=KUI52PanrQ6unP836hVfYss+zRMEwjBeXcoIi4CHE0CEdY4amT40Gu+anPnnMwied3 nA5L1nr9YhIx03AZKH6Nm6y4K1kENhGq/te7ZJlL1B7qdN71YGUZUTY3JqN9zomLNZuu kfQ1iq55HXiflkY23OLaklrkRkoKJUuWKlY/qp3oZjmWDqr7uJ303na8shp9LBI6gbL4 nGD/UYrMDhJGH8/FKcR83KqAT1PqobPByWiz5tgotsaPm/+5jBFUUsLROd/Y0qSakcF0 EuLR41Vr0r1Meu0OBMsZaJNjlkOcxNgCOtol5HvWLPP1NqYqFfcOdGrjBXKgMc+8t12/ 1ayg== X-Gm-Message-State: AOAM5304CwQrFc3p5HGg1giw6BhMwUEme7SYP6gv1g7k9faFyEF05OgO JUq/0wM9FghUDCCgZ7mC1QY2+jNj X-Google-Smtp-Source: ABdhPJytNXVy5y53v9+oK2/cfOLZTds8ZjhFV5tp6TosUl027ZxAS3y4gSJZRl1qF2NZlxtiU+tIzQ== X-Received: by 2002:a5d:6342:: with SMTP id b2mr4622722wrw.262.1593189641866; Fri, 26 Jun 2020 09:40:41 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 11/15] hw/sd/sdcard: Constify sd_crc*()'s message argument Date: Fri, 26 Jun 2020 18:40:22 +0200 Message-Id: <20200626164026.766-12-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" CRC functions don't modify the buffer argument, make it const. Reviewed-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 115a5aa4c3..486538afc2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -255,11 +255,11 @@ static const int sd_cmd_class[SDMMC_CMD_MAX] = { 7, 7, 10, 7, 9, 9, 9, 8, 8, 10, 8, 8, 8, 8, 8, 8, }; -static uint8_t sd_crc7(void *message, size_t width) +static uint8_t sd_crc7(const void *message, size_t width) { int i, bit; uint8_t shift_reg = 0x00; - uint8_t *msg = (uint8_t *) message; + const uint8_t *msg = (const uint8_t *)message; for (i = 0; i < width; i ++, msg ++) for (bit = 7; bit >= 0; bit --) { @@ -271,11 +271,11 @@ static uint8_t sd_crc7(void *message, size_t width) return shift_reg; } -static uint16_t sd_crc16(void *message, size_t width) +static uint16_t sd_crc16(const void *message, size_t width) { int i, bit; uint16_t shift_reg = 0x0000; - uint16_t *msg = (uint16_t *) message; + const uint16_t *msg = (const uint16_t *)message; width <<= 1; for (i = 0; i < width; i ++, msg ++) From patchwork Fri Jun 26 16:40:23 2020 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: 279286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AB1CC433DF for ; Fri, 26 Jun 2020 16:50:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 674B6206A1 for ; Fri, 26 Jun 2020 16:50:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qUcy4cqt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 674B6206A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorYl-00020B-KZ for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:50:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorPC-0000KS-EF; Fri, 26 Jun 2020 12:40:46 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:56252) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorPA-0006B6-SJ; Fri, 26 Jun 2020 12:40:46 -0400 Received: by mail-wm1-x344.google.com with SMTP id g75so9395491wme.5; Fri, 26 Jun 2020 09:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SzJVtg/giHuTkd+J8k/OisBdWsb/IiYZi9QRfQu2hmE=; b=qUcy4cqtqne5kCrHujtYaDS0JqPF7akUIfY5NMEGhplfmgRPYn1EgH+t9eWyG36bUV +DYCjheTjcWXI2WqHifYE4oEwfcKcUc4PdUaXn/vFjgk/60D/GLMLVtgZlfBfnqdkd91 mkPGnJsJnvBMCBljdWZPWPX3lJobtxxEvosC3O+fefJWzadFr8TSy7BxotV9D4doQwLl IxlFFR7+7VN05o+9sN1WDrzJr8vHeruRWFFX0fAAnmLWqv/UzT56p3IQ1YiZQeK5QdaN buHqt+hMqw1zYCYv5WO94rfnmxQelv/OGMg5ifqUdV5haAbEg76pnCv6M6FPd+lqn0vM ECYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SzJVtg/giHuTkd+J8k/OisBdWsb/IiYZi9QRfQu2hmE=; b=SAHPv4Kos4jd0gXeJL9DVM+ovsS9ySvQA13K6Q+9CX56iPOL+YsN6TTRmsTz/cywLU eIHQt6N2cIm3XEDT+3TQkI4q5AR1PerN0OtLUchjna7jZoJoIE4TZNrCA/qFCjiudVzt Ob5u+GntR4gcc9KnrEoQ1vouEpl/4sS1UVYnPbpN9YvKsTJv+j2VzkU0GeLGAPQYIET1 5mpacoTki/vjzqHfW03TiNVlsgm01Ebz79e87PzTEfdyR2PqZJ9bayOOmiHe8WBdSJjT ey0USBHiYMPA+j96cbqN7pjBO0Ox6scP8BNdz7F6IB08kWp5uKSnoHvCSr2dtn8Rp8sv IBuw== X-Gm-Message-State: AOAM532UQgoPhrG/VwiVkjglI4Qy8PLFQhbXI7wfRGmejLrKBd3Ocqzd BAg0hphDGllpeWn0EvSV92XFKyOA X-Google-Smtp-Source: ABdhPJxNg58hLNwddX/dLsUrGVg5NJS0FI+TBoJZjE+u+tHe1wZN19TTn1cHt0ecEMSN2XiEuqAm+g== X-Received: by 2002:a1c:b182:: with SMTP id a124mr4120204wmf.114.1593189642944; Fri, 26 Jun 2020 09:40:42 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 12/15] hw/sd/sdcard: Make iolen unsigned Date: Fri, 26 Jun 2020 18:40:23 +0200 Message-Id: <20200626164026.766-13-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé I/O request length can not be negative. Signed-off-by: Philippe Mathieu-Daudé --- v4: Use uint32_t (pm215) --- hw/sd/sd.c | 2 +- hw/sd/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 486538afc2..dc005e4d91 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1967,7 +1967,7 @@ uint8_t sd_read_data(SDState *sd) { /* TODO: Append CRCs */ uint8_t ret; - int io_len; + uint32_t io_len; if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) return 0x00; diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 5f09d32eb2..d0cd7c6ec4 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -52,7 +52,7 @@ sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint8_t value) "%s %20s/ CMD%02d value 0x%02x" -sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, int length) "%s %20s/ CMD%02d len %d" +sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t length) "%s %20s/ CMD%02d len %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" # milkymist-memcard.c From patchwork Fri Jun 26 16:40:24 2020 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: 279287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68FF8C433E0 for ; Fri, 26 Jun 2020 16:50:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3546420781 for ; Fri, 26 Jun 2020 16:50:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iA4z3L90" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3546420781 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorY8-0000uN-C7 for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:50:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorPE-0000Mh-3a; Fri, 26 Jun 2020 12:40:48 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39706) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorPC-0006Be-6o; Fri, 26 Jun 2020 12:40:47 -0400 Received: by mail-wr1-x444.google.com with SMTP id q5so10105285wru.6; Fri, 26 Jun 2020 09:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BVIXWAPWTBjsXpXZqdnb/q35sBOEWB0rSw+ANL4hq18=; b=iA4z3L90/iOr+CPoSL8eBA6c2GSoTysz8MQT/z2gDIz5jSi4ZWDJ78EAk/rn5nAbhr VwxNG7u9tLoUY+HT1PnHOoMEYE3Z3jkJbU1RBlEz3bLLWvsPyQ/tryTt3W0rz0ewvC0n gKV7hAQ7blxha/xNCudS84t5BSj2R5sNjMKhC0YW99wdLJawE3Q1tg1jV4D+PsdIugP/ YU1j7PvR5omlnpp/7mRKY6VbIo2ZkJuU0tzQlkfCmpaAX6rVy7241zJCpv8kyPfFXc4w WzLKVq7nztIsTzpJG8j8bHkFepumyJ0qGbP4qj3zRbBzvxpAw7A7tIclGpTKITyU19CK DBUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BVIXWAPWTBjsXpXZqdnb/q35sBOEWB0rSw+ANL4hq18=; b=LBB9c2mATPO4osx+IeHjTp7Y+kTOgBaounrPPCm6YwQZqCCyKocbub5BG9McajMZLt 9OHlHAPI71ySFFxWCAcSkQdq2ja9jtLAXR4SF3j35xDTJmlEPqzyHpcBGWGg6M2Bzv9w Dmf1f2xlZfeAzgZXOXg4qVghm/N+xjdPoeT2Tncw7rzdl80J7Y0qmtmwkpRDtsSqbvah ec/MpdeKjOssNsmmDhLXaJ3P/dkEuxI/W2lKmjdXUy5JuKnk4cYBGWaDFiat3wLbASk3 nupCzmcWKJiVR9w/rZg6tsFomWYZn7tDWMd0htxskQXbyU4dmZLYC1zJf7oKNV/QzCzm 9i/w== X-Gm-Message-State: AOAM532ZbsMPAnYfoG4aRAEzQ4VcniX3B20h9JJmDGx8xzaivKk2kbtW y7kX091pZGRk4kg9iuYoIMKURqjg X-Google-Smtp-Source: ABdhPJxdBtOD+6VO1WfwHB+La1JXvzGI2PMAT47Sk8oAApTcdbEtJCDx46K+LRNyi4h/8uA+6XZvqA== X-Received: by 2002:adf:a49c:: with SMTP id g28mr4990965wrb.118.1593189644211; Fri, 26 Jun 2020 09:40:44 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:43 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 13/15] hw/sd/sdcard: Correctly display the command name in trace events Date: Fri, 26 Jun 2020 18:40:24 +0200 Message-Id: <20200626164026.766-14-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Some ACMD were incorrectly displayed. Fix by remembering if we are processing a ACMD (with current_cmd_is_acmd) and add the sd_current_cmd_name() helper, which display to correct name regardless it is a CMD or ACMD. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index dc005e4d91..e05af50cdb 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -125,6 +125,7 @@ struct SDState { uint8_t pwd[16]; uint32_t pwd_len; uint8_t function_group[6]; + bool current_cmd_is_acmd; uint8_t current_cmd; /* True if we will handle the next command as an ACMD. Note that this does * *not* track the APP_CMD status bit! @@ -1704,6 +1705,8 @@ int sd_do_command(SDState *sd, SDRequest *req, req->cmd); req->cmd &= 0x3f; } + sd->current_cmd = req->cmd; + sd->current_cmd_is_acmd = sd->expecting_acmd; if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req->cmd)) { @@ -1731,7 +1734,6 @@ int sd_do_command(SDState *sd, SDRequest *req, /* Valid command, we can update the 'state before command' bits. * (Do this now so they appear in r1 responses.) */ - sd->current_cmd = req->cmd; sd->card_status &= ~CURRENT_STATE; sd->card_status |= (last_state << 9); } @@ -1792,6 +1794,15 @@ send_response: return rsplen; } +static const char *sd_current_cmd_name(SDState *sd) +{ + if (sd->current_cmd_is_acmd) { + return sd_acmd_name(sd->current_cmd); + } else { + return sd_cmd_name(sd->current_cmd); + } +} + static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_read_block(addr, len); @@ -1830,7 +1841,7 @@ void sd_write_data(SDState *sd, uint8_t value) return; trace_sdcard_write_data(sd->proto_name, - sd_acmd_name(sd->current_cmd), + sd_current_cmd_name(sd), sd->current_cmd, value); switch (sd->current_cmd) { case 24: /* CMD24: WRITE_SINGLE_BLOCK */ @@ -1984,7 +1995,7 @@ uint8_t sd_read_data(SDState *sd) io_len = (sd->ocr & (1 << 30)) ? HWBLOCK_SIZE : sd->blk_len; trace_sdcard_read_data(sd->proto_name, - sd_acmd_name(sd->current_cmd), + sd_current_cmd_name(sd), sd->current_cmd, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ From patchwork Fri Jun 26 16:40:26 2020 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: 279285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A4A5C433E0 for ; Fri, 26 Jun 2020 16:52:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB220206BE for ; Fri, 26 Jun 2020 16:52:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LXvW9gSY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB220206BE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joraH-0004zt-UK for qemu-devel@archiver.kernel.org; Fri, 26 Jun 2020 12:52:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorPF-0000Nu-IQ; Fri, 26 Jun 2020 12:40:49 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorPE-0006Ch-5L; Fri, 26 Jun 2020 12:40:49 -0400 Received: by mail-wr1-x442.google.com with SMTP id z13so10125102wrw.5; Fri, 26 Jun 2020 09:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=074iMePnrQX+lQLKspStcL4/Sdxmmp5D48oE2Br3C4s=; b=LXvW9gSYa0SXpnKOq+5gPIPRM27/qard9nfNtEgjqVFqXXxOjt0BujRrp48k/qxncI hoUvufxqu0iVZCDVc9PGaA20csjXXFOEQctIamsfK95Melp3+gVbhnX/yJNocCJl18h+ 2ePe7fPhfxnlIsyDymkF1qzzRWj0VHkiWP8g8ZwJCUW8YGBsCV2LBU083CUQkSQZO6c9 +kiP3eu4ChiyZQT5tcfNsqspZpBGC7U9zOubPP9G/6iTKHJRMmKULHuaJQ713KFWL4cS doXKJ2U5/GjhReLqn6gsMppwVaJ8dAuPk5Jziot3OIPyxdFnRHYSLvDzRFQULpOBtLwW EBww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=074iMePnrQX+lQLKspStcL4/Sdxmmp5D48oE2Br3C4s=; b=mL21zghCb/cSoznny5anyVDmuJsk8A90/0xoA2hstPp/lfSEQVh+mU/jsKJ8/7PyMh jbR3LaDtsuR0D0R6rUI2HqB4oCkCkhAZ2zHsdVAJPfeBN2tFdczrezU+/rzn+wJ+294w TukXyJN9QPKxi5MTEFVorfV3h/behBx+v6lITfjGDGN0m0K6em0uPqPK3dC9zLaHKbJu DQ3ESfiXDmZaxV4iMmAP6aYzYOOh6BJaZf6qw3QIRN0zCVhqzW+pUr3Qu+wzfKgAOhww xLvdRv1V5yaZ9xDu5GHVQk8g+69wNUWeP4ROCP4Q1ngwDCwkPSzLeS1YvcXsYQ7GLMNx LThA== X-Gm-Message-State: AOAM531jdfPXD18zCGSS0dZgWCtyJ4UlFCX8t4Tx7l1B/y5w9Dxa75GD inEtFJIcfpOX+hrcxXFLoTU2hrLf X-Google-Smtp-Source: ABdhPJx3WyHMW1H3lktkBrGgzXb7DO9o79d+l3PLYrGf+y6TiFXz2tsXmyKS0Cp6+snHZjEkxqRmmQ== X-Received: by 2002:a5d:6786:: with SMTP id v6mr4614577wru.258.1593189646269; Fri, 26 Jun 2020 09:40:46 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f12sm24623646wrw.53.2020.06.26.09.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:40:45 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 15/15] hw/sd/sdcard: Simplify realize() a bit Date: Fri, 26 Jun 2020 18:40:26 +0200 Message-Id: <20200626164026.766-16-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200626164026.766-1-f4bug@amsat.org> References: <20200626164026.766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We don't need to check if sd->blk is set twice. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index f0b5527eaf..27a7862c98 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2140,12 +2140,12 @@ static void sd_realize(DeviceState *dev, Error **errp) return; } - if (sd->blk && blk_is_read_only(sd->blk)) { - error_setg(errp, "Cannot use read-only drive as SD card"); - return; - } - if (sd->blk) { + if (blk_is_read_only(sd->blk)) { + error_setg(errp, "Cannot use read-only drive as SD card"); + return; + } + ret = blk_set_perm(sd->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, BLK_PERM_ALL, errp); if (ret < 0) {