Received: by 2002:a05:6520:3645:b029:c0:f950:43e0 with SMTP id l5csp6301470lki; Thu, 4 Mar 2021 09:36:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDqrQSiZuXYpOcvIPO4iKODb3t/pvJlA5O8dtBjikik7liRroY9AhT5v4UtsI55UWnQhqa X-Received: by 2002:a17:906:5498:: with SMTP id r24mr5553400ejo.29.1614879367475; Thu, 04 Mar 2021 09:36:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614879367; cv=none; d=google.com; s=arc-20160816; b=nTVJab/1tMkOlA+ylNIuh3YiiWUfdK73MgB3HvSc6XA7zX8mP8voqMK3apNzAgUNtq cgbPYtQBEaQ2Vf1t8amm5iL9aSNYsb2pYeA9LUdL6oVovgephnc7yv70YjctGetzLncV eF2nn68FGJf6f3Vziy2w6kMLvG+9mlcIeWDYeUGCVbXa0z5L3h8Vh3knFmc9Ra3avGHa R8e7qdc2cqaPYqBoFKQh3333Tq6P2XFiQX79w/CqbDJLYBQG+5FMUDsJ+S/wo6hyIvB/ 4+xoPsaMTxA7VP+qoYnrB0UBhNXwctXGI0+yFYYAdtUDCmjQ5COb/snJzEUdIROwLElC uFWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cuj7PrrpTUGz6W6b+3LSWHrJMrhRSHgCKv4axOnp68A=; b=Tk+DWwWno1uxyF54uD/wzHCvUp7fm2GOxLLlpXcCiUiaVUY4P7watnmvAnwnC6+fn6 RM/u3UMrLCGO0bsj7D71P9V22wtNnNvGvNNf0tyrdNmccx+z0LUMSEsCO9e3qbB7SgYH dAirM4bmnqIwvIHbdMB3Oz4FaaAuy38Yvzf1BDqcEAEfJgPhPeVg7AtZp0wWwIUUuYO8 25KP6Ld/QPLB6qoob7A2AL9zPbDlNlZtdGkrpU8VYCQ02OGNTVfCY5PoYgiS7m7prTqJ oC2DKpf0HljEjMscRWSruG/2pN/AHTzRSajgJ6MfL48q7PG76y708TWPP5eSHEdSXeh4 8x6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zkoV0/hJ"; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x21si13199138eju.471.2021.03.04.09.35.43; Thu, 04 Mar 2021 09:36:07 -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=@linaro.org header.s=google header.b="zkoV0/hJ"; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241525AbhCDNvP (ORCPT + 99 others); Thu, 4 Mar 2021 08:51:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241602AbhCDNvN (ORCPT ); Thu, 4 Mar 2021 08:51:13 -0500 Received: from mail-vs1-xe29.google.com (mail-vs1-xe29.google.com [IPv6:2607:f8b0:4864:20::e29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5503FC061756 for ; Thu, 4 Mar 2021 05:50:33 -0800 (PST) Received: by mail-vs1-xe29.google.com with SMTP id z65so12247739vsz.12 for ; Thu, 04 Mar 2021 05:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cuj7PrrpTUGz6W6b+3LSWHrJMrhRSHgCKv4axOnp68A=; b=zkoV0/hJBCXr3hS9sIJVhnnxQzzfcseN453Du+BSX3NKMq/sEQUel/sgBOZUAnXoIL gJiyeeziPYCIxJQlyWGlgycgsb6PxUZpWYwvxGFCioOfZgYbnqzbgUyboNPWBSssbbWw ny33lLNgZO+oRrt9h1ss29rjEVoo0A2/u6UtF9KGFp73rdEGWnZugdgT+s2ckLlqBa2P 8YHzjD16VDVcTl58m1+GyAM4YUSPXR8c02dVIrEw/7ZAbdYB6TBWyrEbVIU95UJvxf3t I+7wEflKW+olGkIyBnENPAVqQERQATH95QvIMh8QdNkAtqMWLejv/8EOlqw1sL5rw+Lx 3ydQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cuj7PrrpTUGz6W6b+3LSWHrJMrhRSHgCKv4axOnp68A=; b=kyi9dy1MolZ5hRgN7A0GfdQivfmE9Tt+vjRL0yfAV+3vlH4IJHAZpp78YgjQVZ3n9w /KgGrR5qbJE77Dq5wk3kcpbfHsUg3mWQS5BXQa7TzpBJjZcBgerNaFJS13R5jlvBmH4m B/E6WbgFJYcbSDTpE9GLIAz4wpfr1sxDF4bmyNGAtLsIT+sg36vdIldNXuU4lypJmPHD QqoHMV9HhVcml8dFoFAgOAhIAKejubPFVS0vax+7HaX58yixqZvhSZl3X4KDSooyCZYB /C1J2z/0BfRUTVC/V2OZ3Z1fjh7PXhooMhVMmZ+KPhyk6Tm8HHUr49Zf4qYwUOC46NbJ GLqQ== X-Gm-Message-State: AOAM5338LyrN6sHlpWpcPlpFn2unuL+uxsX0yK3yKEyWD4XbjOtU/Xqd 6SLOCcjhstIa4cAkAisFmf1skRnU3azLbQXE1c3dDA== X-Received: by 2002:a67:c787:: with SMTP id t7mr2666358vsk.48.1614865832499; Thu, 04 Mar 2021 05:50:32 -0800 (PST) MIME-Version: 1.0 References: <1614760331-43499-1-git-send-email-pragalla@qti.qualcomm.com> In-Reply-To: <1614760331-43499-1-git-send-email-pragalla@qti.qualcomm.com> From: Ulf Hansson Date: Thu, 4 Mar 2021 14:49:55 +0100 Message-ID: Subject: Re: [PATCH V2] mmc: sdhci: Check for reset prior to DMA address unmap To: Pradeep P V K Cc: Adrian Hunter , Asutosh Das , Sahitya Tummala , Ram Prakash Gupta , Veerabhadrarao Badiganti , "linux-mmc@vger.kernel.org" , Linux Kernel Mailing List , Pradeep P V K Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Seems like it might be a good idea to tag this for stable? I did that, but awaiting for your confirmation. So, applied for next, thanks! Kind regards Uffe > --- > 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 >