Received: by 2002:a17:90a:37e8:0:0:0:0 with SMTP id v95csp4239867pjb; Mon, 21 Oct 2019 02:17:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwu3AgvMKWRbi4t+hGYs+t2q8VSSKOHlqyhSBdSgwwpSXgSzjzpBiN7z5q6fxsI43SmTfv1 X-Received: by 2002:a05:6402:17a6:: with SMTP id j6mr23331654edy.99.1571649474408; Mon, 21 Oct 2019 02:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571649474; cv=none; d=google.com; s=arc-20160816; b=Dp3OfwhrNLJz9qSrogo0+ZJ5eXLdA96I9UIkbGAkTQ9EhjHx7rS0m/nbRBNju4nBFl Rc5MthQINWCC5HoiSfkv3YICvvTUYs0PMM2/9XvhHecFhrkG3tDckAy/+f8+/1asnVcl u6JFQTjd52DpMJ1cHuqWFtGRAbbTc5LvI7actH481pSYyqwF/pcFDidPf+dwn18J3Ppa hhw1MmEGVMnhiyMqNpbjnVrT14L+dY49jjshkL5F4kmfF/6Dqp6x7vdoaDS7IxyL6tsP PvAi9ayDMvqfx5OGo7J0yXET8ah1Ejyt5+TKhSErRQNYeHUD45Z+26gPv5mUZFuQCdGw hkzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:dkim-signature; bh=fyXVzNh3bAaYBk42fBdJzICclG09jxX+kSBbHAatABk=; b=A0+0IYjGNc6+GcAoepxOSfX1n3CHvGJPLWCIBnmbdo7Oq9qXOa9xXee3HsX3qyHXmZ 4GEIz/NlafyNGyvwEZm4p5IWxe3ZomwsSmw0wEW+b6NRYgQbU29tQindSaze/HmhGrv6 JjcAPnR5Xr7VfLshcvop8+LjFGJ16HO+7qRj7sCYI59XLArBpno4J1Jg4NUUEeUkweRz WYML66m/IbxlX2c2hd0BehHR+dCt4jagjJgOyiYsQdSOmU9X6jzL1JNDDAg5g7dPVLjj YCiV4iCwnui8sz0/KJuhWDUavvMY98OiJpTihO3AgUFhLPGgwTeZtVkpbchJAkakKMsX 1NTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=p4S4M34g; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f47si9720638ede.263.2019.10.21.02.17.31; Mon, 21 Oct 2019 02:17:54 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=p4S4M34g; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727547AbfJUJRV (ORCPT + 99 others); Mon, 21 Oct 2019 05:17:21 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39848 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726181AbfJUJRU (ORCPT ); Mon, 21 Oct 2019 05:17:20 -0400 Received: by mail-wm1-f68.google.com with SMTP id r141so2368378wme.4 for ; Mon, 21 Oct 2019 02:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=fyXVzNh3bAaYBk42fBdJzICclG09jxX+kSBbHAatABk=; b=p4S4M34gvq7oiAB7J7289QTGzutBGVytHXmZcMwYdJALNOpROj/preCC22gLSwW5TA SZs3A+KB5ZLSMPlDwl+QqnbvsdWVWFULUMjp9tYBU0MwSYNvYf9UUTMNbRmzMM1EnayT 578LwJ+f5/z6e/UV0xFr1Tgnd3uik7trySc2j5I4N0yn8wCA9nzqA/oR4CQk7UXXjaTP +VKoQ4TUgX0iNs0XTVtH+X7HcNzxcButh2wy1rSmARSZmcuZm14bzgbx8Vq7CvY2qMMX f/lEMkuP1Evq6gn2STPlsSqrhq3BURnK3x9rCVJ2tO/KCFF3HQ/jv3lr8L34ooUyPPHi u5lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=fyXVzNh3bAaYBk42fBdJzICclG09jxX+kSBbHAatABk=; b=A7HtJ6LpElHHuo7RFrxJkuv1GAB3GJbgkDnfYmQY0U3bON3JDB+HOUvzw+FIbl0Tjd 3BzDlsI4AhpERojd/vpDgJbux6KBf+fG3BMUoeveWxnO/+4k5TJVcxRSzOCaXeKshl4q bE6+xbvutJxv25g3BA0K8LL8tf19cXz78gSOo8JJalBZfmqpfD4KR6WSAxrkIf3v32sl NDfLN4N9/T9TzBV2Jl4tnaa5EKoUcha4E8uKO961GJPahS3MrKWo+jUwqTdH4w5btaap EvLaUINMPTQ+8SzeVcVxRp6SL7h5rcb7Oo7+8Jmr7plmW5+rfVx8Z0etpu3g35pf6asN A68A== X-Gm-Message-State: APjAAAUn5BAB8mZWiXwYrcAy6LDcbw+Uf9cJhnSIQsEB21/RkGY7oHsV zW6VjPCsXnMiqOUA23ABl2hHhQ== X-Received: by 2002:a1c:ed04:: with SMTP id l4mr19199540wmh.116.1571649437343; Mon, 21 Oct 2019 02:17:17 -0700 (PDT) Received: from localhost (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id f6sm13170666wrm.61.2019.10.21.02.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 02:17:16 -0700 (PDT) References: <1571637541-119016-1-git-send-email-jianxin.pan@amlogic.com> User-agent: mu4e 1.3.3; emacs 26.2 From: Jerome Brunet To: Neil Armstrong , Jianxin Pan , Ulf Hansson , Kevin Hilman Cc: Nan Li , linux-amlogic@lists.infradead.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Victor Wan Subject: Re: [PATCH] mmc: fix mmc dma operation In-reply-to: Date: Mon, 21 Oct 2019 11:17:15 +0200 Message-ID: <1jwocybgpw.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain 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 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 ? 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 ? >> >> static void meson_mmc_read_resp(struct mmc_host *mmc, struct mmc_command *cmd) >> > Neil