Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4358972ybg; Mon, 21 Oct 2019 07:50:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjmDI3exsrUf6IlvI3SXlVBMpeV7uH/4sy2fr+BDbmRpsVjVzYNa+jCI1HyC0ULjJ3aE2b X-Received: by 2002:a05:6402:1507:: with SMTP id f7mr25636313edw.68.1571669427785; Mon, 21 Oct 2019 07:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571669427; cv=none; d=google.com; s=arc-20160816; b=xsjBmJX57UE69NT9Fy5gbj7U9WZ5kaAFWK9lfoz0CGmR+0seLQP1tZtCDkm0LWXAcQ fFqhvc4eLy6jqZR8ZaozYNyMnJx2JIt0QkCC+1kh6v2iEv0FkVeV8AtwzXRQu/3IkOH0 sWn4hpTA3zKzBIzQuCWu/98oZUkzfn9sX5zkNXyg8iYTihJv+mHsfyBkUoIlgT7EZR1m E3H+ybwvniy0/xVYLbmxsxkoGjfjzeQEVikC1iFJJl1sjvoQB/5rkAis/2xGJrnbyvh2 nfk3i26jgsMTFSgT+faEfQ5eK4gCYjJu4O7GZXCoUYhaKWT8hLq12F7MSKk92UyUTz+e FDdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jW5VBJqbIKfc0TSTZ4BubhIyInqE5Fh+T6DH/lX3Eug=; b=mDRTMOzxC4/uW2+i77ao5oEFlAQmRJsnfWg26CI2Bf1QsfSIjVC3ywWS2Q3g9AY4VV K809+wi3hFVTRnJUHbCAOS3asBN6p94qdvUBv9L728cE5U2ijB9xV20hsTyUyB1Yd1Zr CZfazNgto2umx0v0PEbjIZwsbTLiv65oyqWphZ8oPS2q6b4nTlidIXC5okzLHDRknDKj PUeux8yvfqG1FFhBJAh4jXmYOuj3/nUCZ71Ts3I2OQ4uDxymzdBMgiIO+vKcaHLSeQ3+ 6hDTlDS+zrUErPb+ylkBGRTr3BfO7HJu5sbD5hWKTS97l2MlZi0hQ0lE1sHCVi/VggwC 14SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YYqrP+N6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id j51si10099232ede.301.2019.10.21.07.50.04; Mon, 21 Oct 2019 07:50:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YYqrP+N6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728289AbfJUOtP (ORCPT + 99 others); Mon, 21 Oct 2019 10:49:15 -0400 Received: from mail-vk1-f194.google.com ([209.85.221.194]:37130 "EHLO mail-vk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726955AbfJUOtP (ORCPT ); Mon, 21 Oct 2019 10:49:15 -0400 Received: by mail-vk1-f194.google.com with SMTP id v78so2817476vke.4 for ; Mon, 21 Oct 2019 07:49:14 -0700 (PDT) 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=jW5VBJqbIKfc0TSTZ4BubhIyInqE5Fh+T6DH/lX3Eug=; b=YYqrP+N6Nifpgr/HxnzrSkEW2+xxljCCdzjzcfweZwOUgpaW3wnUS0oAI/P9Qz3PZv IZ66ZNy/lLtc/nd98M4LE/URKM6mr4OHM+/JeRJ4GISUJeecJRAnyqE6eUNK/vaa+sAm bROawRG0+OPvXB+zEsOYAO5WYXkRFjUhVCgGPcRgeI+uyUyr+EdzWETJDdLHWbKMMD9R 0quIcCw6d079pjMY2fDEcShGViQTwRD74LNX5q3GIMoSnlqtfqPSOIHFerV+LBoB393H 28+w7/p4m1WsdkPObaOxX7x1NFQyeEJfWo/BHCQIBSfTyILp7UGwI4Hn2Kx2U6QxBmI6 KeUQ== 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=jW5VBJqbIKfc0TSTZ4BubhIyInqE5Fh+T6DH/lX3Eug=; b=SEDMsn0MRjGzQaTvbcJhe5osYN7nD0cIPnOYhQSfXHXpe8io6Re7eRNhrA8aXB1MAL /w2UqrT/FI67rISXGucmtLjsdhtQzabALSTvljFhsriF/xdLgtD+92bpdinPoDFITnQi th68iMUHHeajsiwoa8FonHs2fO69rqDf55XFRu7tcdKuonzpOOZV6UoQW7WE/g0ysuT3 +NWt3qh+9RxhP7reTO1kBcy2BsjQ6pw3IG2uqgyN2N2wDNSw7b9bxDpGQIJQR5beQ0Sf kchR2VlbFdDJn5MegFWb8j/a6moc2GKNtTTL14N5OfnIKELmwkJ45BUnd7TWvrppY1d+ mYCw== X-Gm-Message-State: APjAAAWvCHwdc58wzD4hR+8lsJDRrEoDgbXmHihHl/FJQHxDXfLNva1J EgQDFHUYptVp4X095xNe8/u7mR3EKLJxQlhCSnu9Lg== X-Received: by 2002:a1f:a293:: with SMTP id l141mr13126073vke.43.1571669353545; Mon, 21 Oct 2019 07:49:13 -0700 (PDT) MIME-Version: 1.0 References: <1571637541-119016-1-git-send-email-jianxin.pan@amlogic.com> <1jwocybgpw.fsf@starbuckisacylon.baylibre.com> In-Reply-To: <1jwocybgpw.fsf@starbuckisacylon.baylibre.com> From: Ulf Hansson Date: Mon, 21 Oct 2019 16:48:37 +0200 Message-ID: Subject: Re: [PATCH] mmc: fix mmc dma operation To: Jerome Brunet Cc: Neil Armstrong , Jianxin Pan , Kevin Hilman , Nan Li , "open list:ARM/Amlogic Meson..." , "linux-mmc@vger.kernel.org" , Linux Kernel Mailing List , Victor Wan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 21 Oct 2019 at 11:17, Jerome Brunet wrote: > > > On Mon 21 Oct 2019 at 09:57, Neil Armstrong wrote: > > > Hi, > > > > Thanks for the fix. > > > > First, you should add "mmc: meson-gx:" in the subject. > > > > On 21/10/2019 07:59, Jianxin Pan wrote: > >> From: Nan Li > >> > >> In MMC dma transfer, the region requested by dma_map_sg() may be released > >> by dma_unmap_sg() before the transfer is completed. > >> > >> Put the unmap operation in front of mmc_request_done() to avoid this. > > > > Since we have seen this problem (yet), could you briefly how you've > triggered it ? > > > > > You should add a "Fixes:" tag so it can be backported on stable kernels. > > > >> > >> Signed-off-by: Nan Li > >> Signed-off-by: Jianxin Pan > >> --- > >> drivers/mmc/host/meson-gx-mmc.c | 15 ++++++++------- > >> 1 file changed, 8 insertions(+), 7 deletions(-) > >> > >> diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c > >> index e712315..7667e8a 100644 > >> --- a/drivers/mmc/host/meson-gx-mmc.c > >> +++ b/drivers/mmc/host/meson-gx-mmc.c > >> @@ -173,6 +173,7 @@ struct meson_host { > >> int irq; > >> > >> bool vqmmc_enabled; > >> + bool needs_pre_post_req; > >> }; > >> > >> #define CMD_CFG_LENGTH_MASK GENMASK(8, 0) > >> @@ -654,6 +655,8 @@ static void meson_mmc_request_done(struct mmc_host *mmc, > >> struct meson_host *host = mmc_priv(mmc); > >> > >> host->cmd = NULL; > >> + if (host->needs_pre_post_req) > >> + meson_mmc_post_req(mmc, mrq, 0); > >> mmc_request_done(host->mmc, mrq); > >> } > >> > >> @@ -803,25 +806,23 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) > >> static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) > >> { > >> struct meson_host *host = mmc_priv(mmc); > >> - bool needs_pre_post_req = mrq->data && > >> + > >> + host->needs_pre_post_req = mrq->data && > >> !(mrq->data->host_cookie & SD_EMMC_PRE_REQ_DONE); > >> > >> - if (needs_pre_post_req) { > >> + if (host->needs_pre_post_req) { > >> meson_mmc_get_transfer_mode(mmc, mrq); > >> if (!meson_mmc_desc_chain_mode(mrq->data)) > >> - needs_pre_post_req = false; > >> + host->needs_pre_post_req = false; > >> } > >> > >> - if (needs_pre_post_req) > >> + if (host->needs_pre_post_req) > >> meson_mmc_pre_req(mmc, mrq); > >> > >> /* Stop execution */ > >> writel(0, host->regs + SD_EMMC_START); > >> > >> meson_mmc_start_cmd(mmc, mrq->sbc ?: mrq->cmd); > >> - > >> - if (needs_pre_post_req) > >> - meson_mmc_post_req(mmc, mrq, 0); > >> } > > The code around all this is getting quite difficult to follow eventhough > it does not actually do much > > The root of the problem seems be that meson_mmc_pre_req() and > meson_mmc_post_req() are passed to framework but also called manually > from meson_mmc_request(). > > Because of this, some code is added to make sure we don't do things twice. > Maybe I'm missing something but it look weird ? Ulf, could you give us > your view ? This is tricky, unfortunately. The main problem boils done to that, there is no guarantee that the ->pre|post_request() host callbacks is called at all, as that depends on if the mmc block layer has more than one requests in the pipe to send. Additionally, that of course varies dynamically on a running system. > > As far as I can tell: > * pre_req : determine if we use CHAIN_MODE or not AND > dma_map_sg() if we do > * post_req : dma_unmap_sg() if previously allocated > > Do we really need to do all this meson_mmc_request() ? Shouldn't we let the > framework do the calls to pre/post_req for us ? Whether we theoretically could simplify the path, by for example always calling the ->pre|post_request() callbacks if those exists, is probably too late to change. Well, unless we can change all host drivers implementing them as well... so it's probably just easier to accept this as is. One thing though, make sure you have a nice self descriptive naming of variables and functions, to deal with this. That helps a lot. Kind regards Uffe