From patchwork Tue Apr 16 18:57:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raul Rangel X-Patchwork-Id: 10903853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACFEE17E0 for ; Tue, 16 Apr 2019 18:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9349D289E5 for ; Tue, 16 Apr 2019 18:57:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86E1828A0B; Tue, 16 Apr 2019 18:57:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAEF6289E5 for ; Tue, 16 Apr 2019 18:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728966AbfDPS5P (ORCPT ); Tue, 16 Apr 2019 14:57:15 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:35381 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730295AbfDPS5K (ORCPT ); Tue, 16 Apr 2019 14:57:10 -0400 Received: by mail-io1-f68.google.com with SMTP id p16so18566536iod.2 for ; Tue, 16 Apr 2019 11:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l1KWYHAuYUVf8bjjh0jDa0cfeK+F4GWiyYfdHN7gxb4=; b=JunfYtDIw9UNsyNXQAnGtBLYVcaP/YEfWP6ay7qK3JApcUo4Bdg0EhRdybpiDnvrID k+DhGwd2OKDGOy/9ImfL8t+Ij4Ynq+c6LRp/CGwneyqjqZNKig6+vGqXgW59sQNhuY7e SzYnykZSuPytzLIjQyZf51XUcEZ4N7g8C9e9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l1KWYHAuYUVf8bjjh0jDa0cfeK+F4GWiyYfdHN7gxb4=; b=QwqJwb2iYW7dOz4KpZ6cNc4mo5rGYSb1RM13rztRLae9ItIJtuXqseNUPsaTGpIWKR DMn0FfEK8EZZLVgXIWR05u5D4/vIP0ynoiPimWzmDesTs2TC1haTWIfUU/1hOjsQ9vDy 5DjI3m5i20khRYECLi8ACj1BSkmI/bygCB2boST207YxtYTVq9KClFH5vkFUv7+6TqGU +nYQMLzkuHP5ODAgzcoCQyFaIH2gGfTkzbzex4P9qSblgMgUAB6kL5v4Kf1KL2lC9O4m psaUDgdmAbbfrur7K35bvb7kixmZip1Q4SK3efzxXs+9l0ZPHWmi1rxf8/Xw/fV0ff7W 3Cog== X-Gm-Message-State: APjAAAWc2+ifKo37kq4WPPYd3xC6OKsdeYR0lpcjiOZQY83hdSwhYUKZ 2DbLE+2hH+uLs0FI1uaPC3IbIp4s42DAGQ== X-Google-Smtp-Source: APXvYqzEotswXO+6o5G9+5O8hsntC99kx4Z7vLQCrKm1XxDUXThLqY7j/8sed487xniHAti8P0kpJA== X-Received: by 2002:a6b:fe07:: with SMTP id x7mr18403013ioh.3.1555441029456; Tue, 16 Apr 2019 11:57:09 -0700 (PDT) Received: from localhost ([2620:15c:183:0:20b8:dee7:5447:d05]) by smtp.gmail.com with ESMTPSA id 19sm140814itm.6.2019.04.16.11.57.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Apr 2019 11:57:08 -0700 (PDT) From: Raul E Rangel To: linux-mmc@vger.kernel.org Cc: djkurtz@chromium.org, zwisler@chromium.org, Raul E Rangel , Avri Altman , hongjiefang , linux-kernel@vger.kernel.org, Shawn Lin , Kyle Roeschley , Ulf Hansson Subject: [PATCH v2] mmc: core: Verify SD bus width Date: Tue, 16 Apr 2019 12:57:05 -0600 Message-Id: <20190416185705.256369-1-rrangel@chromium.org> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SD Physical Layer Spec says the following: Since the SD Memory Card shall support at least the two bus modes 1-bit or 4-bit width, then any SD Card shall set at least bits 0 and 2 (SD_BUS_WIDTH="0101"). This change verifies the card has specified a bus width. AMD SDHC Device 7806 can get into a bad state after a card disconnect where anything transferred via the DATA lines will always result in a zero filled buffer. Currently the driver will continue without error if the HC is in this condition. A block device will be created, but reading from it will result in a zero buffer. This makes it seem like the SD device has been erased, when in actuality the data is never getting copied from the DATA lines to the data buffer. SCR is the first command in the SD initialization sequence that uses the DATA lines. By checking that the response was invalid, we can abort mounting the card. Acked-by: Avri Altman Signed-off-by: Raul E Rangel Reviewed-by: Avri Altman --- This patch currently requires the SD trace events patch to be applied first for it to apply cleanly. See: https://patchwork.kernel.org/cover/10903761 This is because I want the check to happen after the trace call. This way the invalid valid response is traced. I can also change the base so it applies cleanly to master if that is desired. Here is the testing I did: Good Trace: https://paste.fedoraproject.org/paste/oVEI5b0IzHD23Yo7CDZgEg [ 30.103686] mmc0: new high speed SDHC card at address 0001 [ 30.105262] mmcblk0: mmc0:0001 00000 7.41 GiB [ 30.108258] mmcblk0: p1 [ 31.947250] mmc0: card 0001 removed Bad Trace (before patch): https://paste.fedoraproject.org/paste/jBWfpFBM8gdEmGOzxij~hw Bad Trace (after patch): https://paste.fedoraproject.org/paste/8gB8MLYOKEUZEgHXmQ0W1Q [ 33.810760] mmc0: invalid bus width [ 33.810782] mmc0: error -22 whilst initialising SD card [ 34.068818] mmc0: invalid bus width [ 34.068839] mmc0: error -22 whilst initialising SD card [ 34.329521] mmc0: invalid bus width [ 34.329543] mmc0: error -22 whilst initialising SD card [ 34.592061] mmc0: invalid bus width [ 34.592084] mmc0: error -22 whilst initialising SD card In the traces you can see sd_scr is different Changes in v2: - Made the bus width check stricter. It now requires the value to match the spec. - Rebased on SD Trace Event patch drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 3b2e09fa72c5..a73f3dbb6029 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -229,6 +229,13 @@ static int mmc_decode_scr(struct mmc_card *card) trace_sd_scr(card, scr); + /* SD Spec says: any SD Card shall set at least bits 0 and 2 */ + if (!(scr->bus_widths & SD_SCR_BUS_WIDTH_1) || + !(scr->bus_widths & SD_SCR_BUS_WIDTH_4)) { + pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); + return -EINVAL; + } + return 0; }