Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3467892yba; Tue, 16 Apr 2019 11:58:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1n6J+mR06Ee1+czG3ValpZv/IXyNJLo/xtpexUSgBClxyrFTaFLVBB2EBniLlPG9VIQFZ X-Received: by 2002:a63:e045:: with SMTP id n5mr79067962pgj.230.1555441100812; Tue, 16 Apr 2019 11:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555441100; cv=none; d=google.com; s=arc-20160816; b=ydIhAdgZLgTneTjV7QUyqyF0a67/RrA2brJO4iP2RHGzDHgPOXp2hDaxLG2l1fkb4s Oppyji/Z+wDU1KaaAFaSkJZahZVl/4qbWvScNeqMTfa5VsNhBbtSyKJQ4etIUctPmDZR vg91u0ZCH2UT2+JoAU7HrF+MgQWqMoRyjMoerrmpUKg/35i0058U//XD/vz/MuiXvVlv p3JdDn/ITNVsAxeEIAWZW1oIHtJ4jkwKcbt8Jik28aqROwOM7RZLi3rpt2FBFK9HvFDV wjd5SPCOJLmNT6uU4VuabDkhGP4bbvDEtuOZeedRFqR+yH/kq70gvjKvD/Repqb/XVkp UMqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=l1KWYHAuYUVf8bjjh0jDa0cfeK+F4GWiyYfdHN7gxb4=; b=O+yLMFLZr6QnKkfJuZum6YOJcAedWscL6mf4ZAxMeivQfZWpiU+ZrMivHhUL1H5L4J Thxcjdf5Q0qHP+8uQw7SsOEuYZgkf2jumEkQkE0eJIjaeZWeoapgVhkhEu/VsMT9kYCe IEmhPYSieMq9P+bQYfATVE0r6A1zxFX1Fb9iMSP4PEbKupQSQgCSCVk8yGO8VIeZV9Ym tqFeueO6M6h87mzmGZq0DGHftB9la9R42HPFdIBOCyH7t+V4GVzZVSbr8IPhF/AKJ59d pIgi2A53EvA6uQjs/StCNOMFytqKpG0Srn9ILtmsXq9kMtKFNi8iSVkBNGZ3Q7GXdtB0 05MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JunfYtDI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si42559137pln.54.2019.04.16.11.58.04; Tue, 16 Apr 2019 11:58:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JunfYtDI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730335AbfDPS5K (ORCPT + 99 others); Tue, 16 Apr 2019 14:57:10 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:34532 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730290AbfDPS5K (ORCPT ); Tue, 16 Apr 2019 14:57:10 -0400 Received: by mail-io1-f65.google.com with SMTP id n11so18540673ioh.1 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=pzn1kW3yw7RbmYnmHxQ24MjYFJfX0qe9HCH2ZxzuLjheByoR7ejONprnNI9K5FwgIC gTkj13AnDegWinZDHX5h7C2zqaPP7XFOuCos30oYwSlPf2Apsyacvh1R3tnkTqmGqI+n seG0Y4HzJYJpBd/KDO/T9dI63wvoyJTE/EMTM1I0EneeL8PnAGj6dlO2ymaBDXWqYs86 MTqj39PkBufEF1ikq8YlhSmX5/1JiK6lY4/hpMdIicewBEcxRJvS/5170yrk4r8Tqn/F DrnLkpFR8iC62zsHmTR/FXS/pylrZ+qJF1k2C4ifVpjmn2qouvtVwyXdYDPWEJnQNsAV 88XA== X-Gm-Message-State: APjAAAXKlGuTuguaBIO6QdyQW9eqvRFxCVxBFxKooKQg1WuSO5re3Fyi /KRcWKEKePZPR0iVVU/9JQNH5w== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.21.0.392.gf8f6787159e-goog