Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp274586ybs; Tue, 26 May 2020 08:54:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyffMfqWXzIjB1G5h0uccEJ0VA07Y3PfeEcg5GbqbDxbglM5MDOzaC+/aDvYOadhkWLeVbv X-Received: by 2002:a50:ed16:: with SMTP id j22mr20950835eds.300.1590508468269; Tue, 26 May 2020 08:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590508468; cv=none; d=google.com; s=arc-20160816; b=ia+8Py01vgZTpZdOC6Mv+No68bSSFDvHlFCac7XQ2CJfnv2KqB+Lwe4HQksF4scxTl JPgKwgT3JCLM0VdOdB96Ddpd5GZjjLU+7JVjXlKcC7/bX1zepRDDy23gANHMZcoXu6aM 4UeyRb0jpBDG5LCo7Y7tmwMjlXWrRoPf/TXPDmb/n9kySZ1K4jiWNivamtBqNn8CaEbt q/74aS0JabODJm1WjpT61LMSrdlC/JYXbVBYgfFWbx99Pd43duGfwDAndzYLzaxvHWKc PvIoTf43EaEjUPtyEh/oZiEMBEPz21atAJLGxAwkXJswkzOVnEZv6e+OR57heorj/VO6 CgSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=28hj2+Ej7SBWOqluQzlr/PMyBCU9CRAkIHe/tLkVNjw=; b=xwUIxh98tBXCWfXpy70ohuXbGQiVS5vGmCyQ7j8G1buRAXWu+9tqGaPQIBKV0JkGbe 3sGQqKlE2lMtbMBpRNzZYcuCrsILkOpusD+bPY68gJySDLaiVfZh+/epPn+TpVd/Hc/a l0kDBm7SXChHuKtZUOraP69P3rZwKrFQ/8Xgr4+KqzBeAnzWv9yZPEfTWkGHtXTs+nAo bVMsEQeycv3QtvZ2XYDXCnmOuEjRATFM2KXrPR5+GRnf6/e6yHIdecTnQuSC1BVNrsjf 0mLRFy1sdYKb+tyoD7NtruIzS0bOX8XbVeAc21fhc5S3Zdl2ppYJCqS46oHdqBz3BMCP 6O7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=GsZVjXqn; 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=st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id za5si87944ejb.698.2020.05.26.08.54.05; Tue, 26 May 2020 08:54:28 -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=@st.com header.s=STMicroelectronics header.b=GsZVjXqn; 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=st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729950AbgEZPv1 (ORCPT + 99 others); Tue, 26 May 2020 11:51:27 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:11144 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbgEZPvZ (ORCPT ); Tue, 26 May 2020 11:51:25 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04QFlssq011536; Tue, 26 May 2020 17:51:13 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=28hj2+Ej7SBWOqluQzlr/PMyBCU9CRAkIHe/tLkVNjw=; b=GsZVjXqn0Y5Ge/pr/QFhJzOz8y4IeQERAqhaB5m/gsKRQxujdzB33xHgiwM9K51iuGS4 DW7pk8lFiedObiO4JHPsj059bGMVenSStqc4e3oL9JIvZHSTV6EBaP3TgYEdS+MccqeW m7DDAF3mMkWeAymHb85hwMac43XfltluXXK76UnEuX8CwFwjoIW/fvZ8P8pUqDVvkm4A nwTZB2N32AMILtpuTOlMcyrZZdcs/QTTnMJzVOhLXCGz2uDfd+XEbvSpuW02XBz5kSH7 fRMCPg6uKvjevAXKLqOGF+TKMP2fN+itYJaqz/nxYuoC2xPdCGW6eL3EP4EPlNga2kuv ow== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 316sa20kgg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 May 2020 17:51:13 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DE1B610002A; Tue, 26 May 2020 17:51:12 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag6node1.st.com [10.75.127.16]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id CDE3E2C4B36; Tue, 26 May 2020 17:51:12 +0200 (CEST) Received: from localhost (10.75.127.50) by SFHDAG6NODE1.st.com (10.75.127.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 26 May 2020 17:51:12 +0200 From: Ludovic Barre To: Ulf Hansson , Rob Herring CC: , Maxime Coquelin , Alexandre Torgue , , , , , , Ludovic Barre Subject: [PATCH 1/2] mmc: mmci_sdmmc: fix DMA API warning overlapping mappings Date: Tue, 26 May 2020 17:51:02 +0200 Message-ID: <20200526155103.12514-2-ludovic.barre@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200526155103.12514-1-ludovic.barre@st.com> References: <20200526155103.12514-1-ludovic.barre@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG8NODE3.st.com (10.75.127.24) To SFHDAG6NODE1.st.com (10.75.127.16) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-05-26_02:2020-05-26,2020-05-26 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Turning on CONFIG_DMA_API_DEBUG_SG results in the following warning: WARNING: CPU: 1 PID: 20 at kernel/dma/debug.c:500 add_dma_entry+0x16c/0x17c DMA-API: exceeded 7 overlapping mappings of cacheline 0x031d2645 Modules linked in: CPU: 1 PID: 20 Comm: kworker/1:1 Not tainted 5.5.0-rc2-00021-gdeda30999c2b-dirty #49 Hardware name: STM32 (Device Tree Support) Workqueue: events_freezable mmc_rescan [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0xc0/0xd4) [] (dump_stack) from [] (__warn+0xd0/0xf8) [] (__warn) from [] (warn_slowpath_fmt+0x94/0xb8) [] (warn_slowpath_fmt) from [] (add_dma_entry+0x16c/0x17c) [] (add_dma_entry) from [] (debug_dma_map_sg+0xe4/0x3d4) [] (debug_dma_map_sg) from [] (sdmmc_idma_prep_data+0x94/0xf8) [] (sdmmc_idma_prep_data) from [] (mmci_prep_data+0x2c/0xb0) [] (mmci_prep_data) from [] (mmci_start_data+0x134/0x2f0) [] (mmci_start_data) from [] (mmci_request+0xe8/0x154) [] (mmci_request) from [] (mmc_start_request+0x94/0xbc) DMA api debug brings to light leaking dma-mappings, dma_map_sg and dma_unmap_sg are not correctly balanced. If a request is prepared, the dma_map/unmap are done in asynchronous call pre_req (prep_data) and post_req (unprep_data). In this case the dma-mapping is right balanced. But if the request was not prepared, the data->host_cookie is define to zero and the dma_map/unmap must be done in the request. The dma_map is called by mmci_dma_start (prep_data), but there is no dma_unmap in this case. This patch adds dma_unmap_sg when the dma is finalized and the data cookie is zero (request not prepared). Signed-off-by: Ludovic Barre --- drivers/mmc/host/mmci_stm32_sdmmc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c index 14f99d8aa3f0..2965b1c062e1 100644 --- a/drivers/mmc/host/mmci_stm32_sdmmc.c +++ b/drivers/mmc/host/mmci_stm32_sdmmc.c @@ -188,6 +188,9 @@ static int sdmmc_idma_start(struct mmci_host *host, unsigned int *datactrl) static void sdmmc_idma_finalize(struct mmci_host *host, struct mmc_data *data) { writel_relaxed(0, host->base + MMCI_STM32_IDMACTRLR); + + if (!data->host_cookie) + sdmmc_idma_unprep_data(host, data, 0); } static void mmci_sdmmc_set_clkreg(struct mmci_host *host, unsigned int desired) -- 2.17.1