Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2469762pxj; Mon, 10 May 2021 03:53:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+4dEW/Yz4djFN+LBP1xRcTREbXdMhKJiVQGX8o75FJKGQmfKWlcoA3n49NIJhC6bqRCfp X-Received: by 2002:a92:dc92:: with SMTP id c18mr21016933iln.252.1620643982809; Mon, 10 May 2021 03:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620643982; cv=none; d=google.com; s=arc-20160816; b=A/z/kX8g63osOAMQT4PnLdhYq9dM2tG672lJDBThJzcZe9xGIhh55hrIVcWZrhabH6 rxNSKTz/lsgGlGIIPfHHobnl6hE2nq+cFQQPiSBEN7iszrbZQQCUhbdWkzY5Gh8jouZc EzCNm0+A1gzOgUTDnylUz2mR4LrjaZ/7pBSd31fxlW0/t6qneaKd5niIMrHSyqUVgO66 7+e9G6TlIHal+wFIwLa3lpOnxBIcjLDt2Nr4aqGZePQ6ESlU5FKJq/AuEf1BmcOywJCM +QfbTGDGigZzgRYbAA478EnIWaGbQ0dmnaJf58cFnQh3J5wziVZhAsq6zFEzUulQZyPI JPbw== 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=UBgTgWuV5KO3s4XRRSvNO1IKSQJ9SB6uvHfitKv9EZg=; b=hAExb8MFnd3uLDUtHqZqukaotosigyAzRg3MAmva2Qej1KtApoBJjuvFGs9vcjXGRi l6rty/n3gvUfyDu9j7LYN3+qVchMmj2TpmUsyqA3op9D4f19hicnJzuKaTAwHMlCRpIo XR6yUdWvFuYQwBBX7EmOYpblMuiVrE61/bO4PphFjWRDP7TCq4/lb4dt7XX208F2qt6R ciFMLJtKsWNMa8yAuo095lVqIPFYuCSpdcl4zzjht7qLG3sMhxZQFtbNur8nxvzuxrOq rpEygfyRxQlIz0AOtSDzXyxr9PVUBokCnYCZTrx3sw2KLfKCPsxgA/m0RJpR+jbzxnCq P7fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=em+UokEV; 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 s11si15061419jaj.108.2021.05.10.03.52.50; Mon, 10 May 2021 03:53:02 -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=em+UokEV; 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 S232323AbhEJKw2 (ORCPT + 99 others); Mon, 10 May 2021 06:52:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232034AbhEJKl5 (ORCPT ); Mon, 10 May 2021 06:41:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC8776197B; Mon, 10 May 2021 10:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642737; bh=J55OhXl7bt+Rg0RRs1ct9kI544Z6zpEdcRAC0jMMGlE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=em+UokEVAc59X/RDG27t0gkn/Tvctb+1g2Lpl4FQwAaLsuv1l48EqOCVA39Nn4DpT lSJSYAN6ntjlJrv1W2Lh6tOrwRRaVeq/z6zm5KTKouLCa5hgqU5uuQz9BEaNsMNZG7 MvnEsQ/1IdX+JMs4Hn/wJMlnB6I02VcHAY60/F0A= 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.10 030/299] mmc: sdhci: Check for reset prior to DMA address unmap Date: Mon, 10 May 2021 12:17:07 +0200 Message-Id: <20210510102005.846794630@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 @@ -2998,6 +2998,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. @@ -3060,35 +3091,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);