Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1383147pxb; Thu, 4 Mar 2021 09:54:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPlP2Sok2eZCvXeXhWo5bhOKWKqJGIrOICgPYSMH0vyeI2Ht8VG8YBnHNrctKu4mg0wT0G X-Received: by 2002:a17:906:f9d8:: with SMTP id lj24mr5623249ejb.200.1614880487059; Thu, 04 Mar 2021 09:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614880487; cv=none; d=google.com; s=arc-20160816; b=lSWxccGaT9vlM5uyi/okLZVn6j4yYK+/1mjg3vYHQIeJU7YDKcC5EVyZTgoRIDAJzY sdzN2C45M7iSf47K1mhsVZ9DGHgM1rdBh5gF4I9Jjv/KuOItBv6JBKdZKPZWn+ka31Na PoTuAI5xs2wfVBVsIbGlsTnOL9MnF4UJol7K5Yz0jKqq0KMA+j++6u47fclqCHp9/SeE 3RBqMM6YsVjZDsjlKJ+juMV5U1HoCWU4pvXHgsiT78GaeFyFyzHbHPNaD4N/dXm3AZLj U3rst37EteyYKMb1qwnWGGQ+vcvmQyQKigIb5C7aLozL0kYemvVx71mMEW6fG7v7lAUZ TAPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=dyltIQ8oRrwKvMEyJ11sgR7hrRe+moPL6rUKrk/x2wk=; b=qnSP6acoS0JXl+tG1n6Hm9SRMs7pmiikrk76pwA6Dl+eil70zpQ4X5L2Ca7LBAZgq+ bkNTdADytlRVlVRQeY1iTB0SMMJ0dE2cVhJ6wWozC4AouAhcumCGg8D6Uv3hi/YzS1Nv Ovs646elf5NIPx5fa7fnOD/oh37Tj+sYTxfn36u0wCC48A8jjmF0bV60b/EdqhUq1Cl6 02refFDPo+VktMVT5zfbCiZhR8jCf0palPbSFCOUAw7I6RgVu68m/GgCUYWhjaBXTSH7 MBXeiYfkWKuXReaGLVRnFlWs7QwGNaZViBgzhvCc8N00mM0mCT5BncgVXyyxFJV2Cxe5 26EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=XN4l+55C; 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 cf26si10299794ejb.702.2021.03.04.09.54.24; Thu, 04 Mar 2021 09:54:47 -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=pass header.i=@mg.codeaurora.org header.s=smtp header.b=XN4l+55C; 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 S234101AbhCDPRk (ORCPT + 99 others); Thu, 4 Mar 2021 10:17:40 -0500 Received: from z11.mailgun.us ([104.130.96.11]:43706 "EHLO z11.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233886AbhCDPRJ (ORCPT ); Thu, 4 Mar 2021 10:17:09 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1614871007; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=dyltIQ8oRrwKvMEyJ11sgR7hrRe+moPL6rUKrk/x2wk=; b=XN4l+55C+Wcp6wI2J0nDolVNvlPcSJo9UBhnSFdJ2+zZRzDvZ1q8mlYdULz3uT67KuII9t4S B/hXV39UGdGdlKHdXG2uB0QBBpaTlnR4NrUU2BLEGmCU/xask6Th8UFGw1qO+psbhFP0jwZT vMi1Ml4lOf+0Lp0/OckAPuCM/uI= X-Mailgun-Sending-Ip: 104.130.96.11 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 6040f9d4c862e1b9fd27f3f5 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 04 Mar 2021 15:16:36 GMT Sender: pragalla=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 9B837C43461; Thu, 4 Mar 2021 15:16:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: pragalla) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9EED9C433CA; Thu, 4 Mar 2021 15:16:35 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 04 Mar 2021 20:46:35 +0530 From: pragalla@codeaurora.org To: Ulf Hansson Cc: Pradeep P V K , Adrian Hunter , Asutosh Das , Sahitya Tummala , Ram Prakash Gupta , Veerabhadrarao Badiganti , linux-mmc@vger.kernel.org, Linux Kernel Mailing List Subject: Re: [PATCH V2] mmc: sdhci: Check for reset prior to DMA address unmap In-Reply-To: References: <1614760331-43499-1-git-send-email-pragalla@qti.qualcomm.com> Message-ID: <3962320b58beaa4626ed69b3120d4246@codeaurora.org> X-Sender: pragalla@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-03-04 19:19, Ulf Hansson wrote: > On Wed, 3 Mar 2021 at 09:32, Pradeep P V K > wrote: >> >> 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 Hi Uffe, > > Seems like it might be a good idea to tag this for stable? I did that, > but awaiting for your confirmation. > Yes, this fix is applicable for all stable starting from 4.9 (n/a for 4.4). Kindly go ahead. > So, applied for next, thanks! > > Kind regards > Uffe > Thanks and Regards, Pradeep > >> --- >> 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 >>