Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2457355pxj; Mon, 10 May 2021 03:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6tQdchbjSbkPS0Dn+lvriVX13Zen8CAgK3e+14hj3l7XU+Vha8gVJHmWrgMTCP1N3XZ+z X-Received: by 2002:a17:907:6289:: with SMTP id nd9mr24265250ejc.384.1620642712268; Mon, 10 May 2021 03:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620642712; cv=none; d=google.com; s=arc-20160816; b=WsINrKIKHZuJcUOzND3dsf6R+/WE9dDcE3dVr2FF11/rHCmvc2nazZ2LqDSIqtHwAJ dWlc6HYspksEPKdmCGWSjaE48FbHCrbJ5sgh6slzuA5sqM3y+a4kS0055oPo2wcard+u WQWkIGH7HZj+47uZHqloFOMHBO/UpQ6rwFFqSo8rfFKVISW+nFuj6sTWNEiaoNCmvX3G uFVP6ZhvdB4N6P2oSlDP2Jib4IYJpp7k28Wd2omTseCyQ6DTuTPI9zF3SIRIIVJeHXsB Wc31ahoQwnFkoHzK18aHdmx8B6nlN+9PVXuTMJeSziO/cHadDd7mxzWa157bAX+aN32V E3dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mJ3lTGfHaD3Td+z+qU56S+9Lit3tvg9hYg7wMCvnSKg=; b=u70SSw9TXJRh/c5NxPZQTwjWWmdGJvn4nGIXCTghUmTQURwSz4L5s3UXrwxcgn/LZM D5tfqCKBZPyeaJxb7dWqubb8n6qNiaoLGva+7GvA00KuxLf688uexoG1eF0v9f6mttC/ APOkRq89BrIy2863mLGAbEasHRJVVS+DE0iV3Gz4K/JTBozgTLxjMO31gkkikQJReG4f Xzndym7GozShjGEdbs24Vvgt7VexTMctjooWz6e2DVaKHtmKJIz9sI5UpV+6mSHzXfDY wXAu7+s+gxWM8iSjttoH45OdndXFW5fbcueKvM0cQvPhXmy4SVI5doaX2yjo1x/Mm9GD hObw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wYn5yuqA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si13535760ede.114.2021.05.10.03.31.29; Mon, 10 May 2021 03:31:52 -0700 (PDT) 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=pass header.i=@linuxfoundation.org header.s=korg header.b=wYn5yuqA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231713AbhEJK2p (ORCPT + 99 others); Mon, 10 May 2021 06:28:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:60482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231374AbhEJK0j (ORCPT ); Mon, 10 May 2021 06:26:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A552461574; Mon, 10 May 2021 10:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642334; bh=am4yCvCqepaXfaCxCE2/BgsmmG/JwxboL0ErhGzBseY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wYn5yuqAoRGX2fJKlenwcLTY4DDkbva1LGYukxmzgiEReejdeGFCIGjEZ1Hbaabb3 EUc1r6T9TJDzC2oPAjAuN04k2qAzqlDlSO7aso4oI+FtOjBiOBDjoFyTz4Sdv7L3dA HjR9UNdAl1lvLpGGMupzByYjzzAlOiXhABpNAEDM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Veerabhadrarao Badiganti , Pradeep P V K , Adrian Hunter , Ulf Hansson Subject: [PATCH 5.4 017/184] mmc: sdhci: Check for reset prior to DMA address unmap Date: Mon, 10 May 2021 12:18:31 +0200 Message-Id: <20210510101950.783394194@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510101950.200777181@linuxfoundation.org> References: <20210510101950.200777181@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pradeep P V K commit 21e35e898aa9ef7781632959db8613a5380f2eae upstream. 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 Acked-by: Adrian Hunter Link: https://lore.kernel.org/r/1614760331-43499-1-git-send-email-pragalla@qti.qualcomm.com Cc: stable@vger.kernel.org # v4.9+ Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/sdhci.c | 60 ++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 29 deletions(-) --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2648,6 +2648,37 @@ static bool sdhci_request_done(struct sd } /* + * 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. @@ -2699,35 +2730,6 @@ static bool sdhci_request_done(struct sd } } - /* - * 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);