Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp391287pxb; Wed, 24 Feb 2021 05:11:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwspJERC7TznWC1qqZSB9bBr9ueC/s6OAce2iMu3DodqDimKignH8ujnVwc2ApFaZTNt2qV X-Received: by 2002:a17:906:b055:: with SMTP id bj21mr31359675ejb.355.1614172284213; Wed, 24 Feb 2021 05:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614172284; cv=none; d=google.com; s=arc-20160816; b=MYizvwqW+rCX9cqBLqc6nUTC05VBNQi7jmSZM48LuAqXJP1EpCqSzhXOKVBZlTdVns HaygzjjLiwGKI5AvT1CIDM83Qvm78hS1K8WzPu5F/TZUguowLuQrS2uRACB3K6mV0wqt KmImKGxGPNjLXPHv+BFeBud9eED4rojADJ8USbprHB+bdd9BE9Cmx6pUFdXYDFYSz9aP f8CrByM8JBLRn5Dqvm+owVYhidHFQBe7Cl/aybnTu9cuypzDLmL7FVtryuNsSXpPIC/M XelaoGhMhkpwvgM5Jjw1Uw7qI8w+of7oLc1bOLKVhSk0Nlwr7gCiDiaA0/NYT370u8/5 PExA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=EyhfWhZhAToV4IgTCU4iPv/+ohaLe5MZm3s4lowppmQ=; b=Ou2uv0V0rU+LAuyZAUUv7LRdoUjMWSY9HhZxiyAVqSOf9db4p1h4+2hDllOYRnSe5L eyCYcvn3aSdKyWPhQ83VPK5cN4loHcbcNeWSXfIZ0Xw5heiooA3VbJZEROkBwcfjnQyU c+97QMhRdyIhcsDhTC6W5IFl3iuCt4fZGsELPh6VitFUqbGXQ3BEc+YJ4dqIsbwyr0zf 4MjSZQxqKSIztd7TLdJW2Ol+gRxl0wBAgBdTuAgkaFiNM3xjfoJfdbKbwj5gME8KliJF 1LUr8sBdjwF1mrfZmS435kGjMxBpGHf7GKy/W7DA45aYJwLaEhwAW9yGBaZh4n4Iu4FW rH0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rk12si1290590ejb.580.2021.02.24.05.10.58; Wed, 24 Feb 2021 05:11:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234893AbhBXKy6 (ORCPT + 99 others); Wed, 24 Feb 2021 05:54:58 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:37894 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233832AbhBXKyT (ORCPT ); Wed, 24 Feb 2021 05:54:19 -0500 Received: from ironmsg07-lv.qualcomm.com (HELO ironmsg07-lv.qulacomm.com) ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 24 Feb 2021 02:53:36 -0800 X-QCInternal: smtphost Received: from ironmsg01-blr.qualcomm.com ([10.86.208.130]) by ironmsg07-lv.qulacomm.com with ESMTP/TLS/AES256-SHA; 24 Feb 2021 02:53:34 -0800 X-QCInternal: smtphost Received: from hydcbspbld03.qualcomm.com ([10.242.221.48]) by ironmsg01-blr.qualcomm.com with ESMTP; 24 Feb 2021 16:23:11 +0530 Received: by hydcbspbld03.qualcomm.com (Postfix, from userid 2304101) id 11D8F2147E; Wed, 24 Feb 2021 16:23:10 +0530 (IST) From: Pradeep P V K To: adrian.hunter@intel.com, ulf.hansson@linaro.org Cc: asutoshd@codeaurora.org, stummala@codeaurora.org, rampraka@codeaurora.org, vbadigan@codeaurora.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Pradeep P V K Subject: [PATCH V1] mmc: sdhci: Check for reset prior to DMA address unmap Date: Wed, 24 Feb 2021 16:23:05 +0530 Message-Id: <1614163985-38914-1-git-send-email-pragalla@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For data read commands, SDHC may initiate data transfers even before it completely process the command response. In case command itself fails, driver un-maps the memory associated with data transfer but this memory can still be accessed by SDHC for the already initiated data transfer. This scenario can lead to un-mapped memory access error. To avoid this scenario, reset SDHC (when command fails) prior to un-mapping memory. Resetting SDHC ensures that all in-flight data transfers are either aborted or completed. So we don't run into this scenario. Swap the reset, un-map steps sequence in sdhci_request_done(). Suggested-by: Veerabhadrarao Badiganti Signed-off-by: Pradeep P V K --- drivers/mmc/host/sdhci.c | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 646823d..e78d84c 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2996,6 +2996,35 @@ static bool sdhci_request_done(struct sdhci_host *host) spin_unlock_irqrestore(&host->lock, flags); return true; } + /* + * The controller needs a reset of internal state machines + * upon error conditions. + */ + if (sdhci_needs_reset(host, mrq)) { + /* + * Do not finish until command and data lines are available for + * reset. Note there can only be one other mrq, so it cannot + * also be in mrqs_done, otherwise host->cmd and host->data_cmd + * would both be null. + */ + if (host->cmd || host->data_cmd) { + spin_unlock_irqrestore(&host->lock, flags); + return true; + } + + /* Some controllers need this kick or reset won't work here */ + if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) + /* This is to force an update */ + host->ops->set_clock(host, host->clock); + + /* Spec says we should do both at the same time, but Ricoh + * controllers do not like that. + */ + sdhci_do_reset(host, SDHCI_RESET_CMD); + sdhci_do_reset(host, SDHCI_RESET_DATA); + + host->pending_reset = false; + } /* * Always unmap the data buffers if they were mapped by @@ -3060,35 +3089,6 @@ static bool sdhci_request_done(struct sdhci_host *host) } } - /* - * The controller needs a reset of internal state machines - * upon error conditions. - */ - if (sdhci_needs_reset(host, mrq)) { - /* - * Do not finish until command and data lines are available for - * reset. Note there can only be one other mrq, so it cannot - * also be in mrqs_done, otherwise host->cmd and host->data_cmd - * would both be null. - */ - if (host->cmd || host->data_cmd) { - spin_unlock_irqrestore(&host->lock, flags); - return true; - } - - /* Some controllers need this kick or reset won't work here */ - if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) - /* This is to force an update */ - host->ops->set_clock(host, host->clock); - - /* Spec says we should do both at the same time, but Ricoh - controllers do not like that. */ - sdhci_do_reset(host, SDHCI_RESET_CMD); - sdhci_do_reset(host, SDHCI_RESET_DATA); - - host->pending_reset = false; - } - host->mrqs_done[i] = NULL; spin_unlock_irqrestore(&host->lock, flags); -- 2.7.4