Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1056123pxb; Thu, 4 Mar 2021 02:00:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxj/54kmNAW4yy1SCOjOXwJxLSKjhO1MfDij1KJdBV8DRVhDg6k1F+Nx2aKBUj9OaO3WBbw X-Received: by 2002:a50:d302:: with SMTP id g2mr3386134edh.75.1614852001321; Thu, 04 Mar 2021 02:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614852001; cv=none; d=google.com; s=arc-20160816; b=v+wk1BMXG8DsTIXkTCq9+FbmDLWW7zkHokDjceaLnCroB5eMONzZ2I/KxUUM8AYzNW 9IPrxM0htZgFEOGnaD9yfuPQWZpHqPJdsYJAjxcS6PIO1K2ZHX/294HOpMlbQOJJTk6+ GqbFCrLRMm8txejiqoq++JWjKDdtW5PFlHQeDvq3o2b+I+himHAkpndrYJL67qvhcSMx 4cLUFZvJg7MRH2/W8kMDbSltajSCGZTmjaH4D8GwGf8tXBFfwfsNPY+bx5PXVyHKqI6O v5/J0u0Eot3/vEuovZEJv3iTv7Y7M3Lhdgl9I95SxfmU7CIS5BET7eq5Eqk2KuNiGCXC sOgA== 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 :dkim-signature; bh=hlKZT3PXiH47bGzOpyYt6xrfZof0MRy4XjtG/q4k+mU=; b=ie6DczkCOf3Ats0BMXNoayKZPeJ57h2PfDY4TwfKKG9Z/etY1GtP/bVFFNEf/jfqV7 nuTUZ6w5ebJT7Sef2RotorkS3Vx6coPlmS66l6LmjCpZcpO039BfmLgXXFPZoYx4B9P7 uW/W9WJRfwqXY9a+bYFle3QCbasegHnJQcsJcZFcang3VzYallTZQNjaqcL8qasFMBBS eClHs9P/4y6aKxS1CKSGYzGikSG1wJgnJ+xChD05f+UexLB0h8Y6f5Cq/FF8K2zVx0D7 qYVnbpsakIznI6qsS1dueHWqj6dG1Ixotx22cf6/6vQQznWbm8NzQXIqiCMC5ptUXwLN XtIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@qti.qualcomm.com header.s=qcdkim header.b=cJ0SlEuG; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=qti.qualcomm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv19si1919217ejc.109.2021.03.04.01.59.38; Thu, 04 Mar 2021 02:00:01 -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; dkim=fail header.i=@qti.qualcomm.com header.s=qcdkim header.b=cJ0SlEuG; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=qti.qualcomm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233790AbhCCQBe (ORCPT + 99 others); Wed, 3 Mar 2021 11:01:34 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:64266 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232268AbhCCL2i (ORCPT ); Wed, 3 Mar 2021 06:28:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qti.qualcomm.com; i=@qti.qualcomm.com; q=dns/txt; s=qcdkim; t=1614770913; x=1646306913; h=from:to:cc:subject:date:message-id; bh=YhmKslpzi+cHH3vU8pK14563hq3M1o4bf8szMh+VDvE=; b=cJ0SlEuGThFCyfhmB2G6RzPWRIjYX3DrfVgsbM0snkVatNHu9ytss6ss M6rrgN4Uv4hnTlF9vvFkvTqeEkiLHOEppU1BdqxdUvu5y1UVGDbGE/grt XCkqRtkc3boKkdHx6hQQuB7KwyaqRF4t0cyKqwRc0Aq5VLlKeXDzcasSY A=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 03 Mar 2021 00:32:40 -0800 X-QCInternal: smtphost Received: from ironmsg01-blr.qualcomm.com ([10.86.208.130]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/AES256-SHA; 03 Mar 2021 00:32:38 -0800 X-QCInternal: smtphost Received: from hydcbspbld03.qualcomm.com ([10.242.221.48]) by ironmsg01-blr.qualcomm.com with ESMTP; 03 Mar 2021 14:02:15 +0530 Received: by hydcbspbld03.qualcomm.com (Postfix, from userid 2304101) id 4ED122147B; Wed, 3 Mar 2021 14:02:14 +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 V2] mmc: sdhci: Check for reset prior to DMA address unmap Date: Wed, 3 Mar 2021 14:02:11 +0530 Message-Id: <1614760331-43499-1-git-send-email-pragalla@qti.qualcomm.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pradeep P V K 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(). Changes since V1: - Added an empty line and fixed the comment style. - Retained the Acked-by signoff. Suggested-by: Veerabhadrarao Badiganti Signed-off-by: Pradeep P V K Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci.c | 60 +++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 646823d..130fd2d 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2998,6 +2998,37 @@ 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; + } + + /* * Always unmap the data buffers if they were mapped by * sdhci_prepare_data() whenever we finish with a request. * This avoids leaking DMA mappings on error. @@ -3060,35 +3091,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