Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp350221rdh; Wed, 7 Feb 2024 06:42:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHly20a62rnZr3RMB8OVCsdM5rL0gcCGbrx0NvIMDuIkgLdMT+E8zkQ8WWUd9pBJYw6ZTqr X-Received: by 2002:a05:6358:591b:b0:178:cf5d:4372 with SMTP id g27-20020a056358591b00b00178cf5d4372mr3549537rwf.5.1707316934133; Wed, 07 Feb 2024 06:42:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707316934; cv=pass; d=google.com; s=arc-20160816; b=XQs5X79nz+fPUrCtiFqWOH0KHWacnllTr7v0S2KLBerYBe8u0GW2qt0I9PsmkkHd8q YJclXe7ogpVptnomjredtUwiUbC0z+W6gVZNIMxP8THJZwpCPEh6CZ3cKCIhk1Hncq01 wQAhaAq451n9TCMhP0uTMy/sflbXeVjmHptanVI5XqZdolCA1ilSQ086zEPRBLaFshyh 023hyK5O9fPme8DgfALP5CYnBYz6p1EyrPFvpwCGyYn1YsfN3yHk6iTzkN2L/BZso/lA rfZO3unup+iw8hd0gNJFeub/DbTumhbTVp3ufKkygTFhqLHMCFuqurk7csIMO2v3GdCg z6rA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Sq7ZJbDZLAMy8T7FyyWWi2GOv8gIvDS+3jrvU7YRdaY=; fh=MGx/vhVDsMoka7iy4zEkOK06eAzElyenXKJ+e/5UH2k=; b=vLKDKmF8V94VyWKzIhyFErVzAC13bfjPlkX0uWhXIJJhvFmcycAAihLhAy6M+7wA3n +DhRB5pkmtKsPCRoQNH9CU0DXOa+RHj84scDtvhwxVD/idF2LwCBfQ9kLPsPIdnLYhHT D6X/+zlDbjFxcbmjyfV4iEkY2eDCdK/fzsPfxc+tR3jhqUtJznmKvCGJowu4/CH59uo7 6BdhHPaYpxni2roIjsPOZxmFmb73IvpUFoq0+FTi8ssntOluWVWV3a6L6x0peIxYdEF/ 4WAMFA2RTfS7on3EV2HDNJDYixoyTavaEhV4ZgkOvQIyBXsSYWx8hVRk2GvAor7HIj/p MbTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=04fb+g1I; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-56632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCVmo39eUYSbOVce3Wmf0bNYx9XYqqSVE+/+fds6bRpGYjlePMibjGJ3ODh/I6oMyFgdQS+FzIMneNHateVAeAvC9hWCxESXs5stDW2omA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l129-20020a633e87000000b005d3646ae6f1si1706325pga.4.2024.02.07.06.42.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:42:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=04fb+g1I; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-56632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2853EB26331 for ; Wed, 7 Feb 2024 14:40:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18FFD7CF07; Wed, 7 Feb 2024 14:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="04fb+g1I" Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D42D87F462; Wed, 7 Feb 2024 14:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707316816; cv=none; b=Ddgjz3F8yi728a6wkqPdhmH/rNvbws1Z6NrJvgSYWe3iZu02gHiruvhMRyj6DD3nRx7FY3gqdBP2mqO63aU/OqnvCAX502UMv96Os9teE2VKTjFimAYxQtyBP/2kavXb7OdTot2JBw2XOQuMEB8T1GPhCInFZVY/rHT6pLqdQsQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707316816; c=relaxed/simple; bh=4tr2qSeMuyecmok1jZeROECD97y61s1o/yoCPX/e63c=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=RlKvWbfPx0OEN1yOsTrdO9fD1A4Ev6t0s0FzulH2tIu8TuCfYyyGE7EMU86Stkb9aQwf6+MAlYq3Ugs9LBOjAB5L+DvLxyAbVkcNxnxAVe0fhQfYc2o//weCeW91VH3emXn/14S7HRaY9VV+f1CXpfzXPSd8RGvra0RbDoqqBjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=04fb+g1I; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0369458.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 417B6FV8014970; Wed, 7 Feb 2024 15:40:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=selector1; bh=Sq7ZJbD ZLAMy8T7FyyWWi2GOv8gIvDS+3jrvU7YRdaY=; b=04fb+g1IBhu2ruzJdlx07k+ tPs+febTod1nR0oFl7R5ZpK6VGAGlnEOkwKxZGq1Rg0lolAOs8/jjwYplUUbKIMo SdOWEkhJcbog7wQtgtEGHPQSJJOLiHzoaYsAhoVAPcz+Cfga/osOUJjS4HhPJ8KB g/Yvfp50n42NsFcRXQV7t0U8daAGks5Bp/Xx0VZeSsr9gtrKdMBE2J5lCkJoiix2 v1zyXEjg5VsEAcWo9zJWSlUIJK3OHKuM6h3taIluV64NI9IDJ8MBVUQH/IRM5bIw G+4EC886zu3rG77wb+94+Y6uMPJ/I5CEFsDtb24hY0LQ4yFssq/77jb035ct7Xg= = Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w1yx46fr6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Feb 2024 15:40:05 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0461D100058; Wed, 7 Feb 2024 15:40:03 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id E77EA24259D; Wed, 7 Feb 2024 15:40:02 +0100 (CET) Received: from localhost (10.201.22.200) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 7 Feb 2024 15:40:02 +0100 From: Christophe Kerello To: , , , CC: , , , Christophe Kerello Subject: [PATCH] mmc: mmci: stm32: fix DMA API overlapping mappings warning Date: Wed, 7 Feb 2024 15:39:51 +0100 Message-ID: <20240207143951.938144-1-christophe.kerello@foss.st.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHFCAS1NODE1.st.com (10.75.129.72) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-07_06,2024-01-31_01,2023-05-22_02 Turning on CONFIG_DMA_API_DEBUG_SG results in the following warning: DMA-API: mmci-pl18x 48220000.mmc: cacheline tracking EEXIST, overlapping mappings aren't supported WARNING: CPU: 1 PID: 51 at kernel/dma/debug.c:568 add_dma_entry+0x234/0x2f4 Modules linked in: CPU: 1 PID: 51 Comm: kworker/1:2 Not tainted 6.1.28 #1 Hardware name: STMicroelectronics STM32MP257F-EV1 Evaluation Board (DT) Workqueue: events_freezable mmc_rescan Call trace: add_dma_entry+0x234/0x2f4 debug_dma_map_sg+0x198/0x350 __dma_map_sg_attrs+0xa0/0x110 dma_map_sg_attrs+0x10/0x2c sdmmc_idma_prep_data+0x80/0xc0 mmci_prep_data+0x38/0x84 mmci_start_data+0x108/0x2dc mmci_request+0xe4/0x190 __mmc_start_request+0x68/0x140 mmc_start_request+0x94/0xc0 mmc_wait_for_req+0x70/0x100 mmc_send_tuning+0x108/0x1ac sdmmc_execute_tuning+0x14c/0x210 mmc_execute_tuning+0x48/0xec mmc_sd_init_uhs_card.part.0+0x208/0x464 mmc_sd_init_card+0x318/0x89c mmc_attach_sd+0xe4/0x180 mmc_rescan+0x244/0x320 DMA API debug brings to light leaking dma-mappings as dma_map_sg and dma_unmap_sg are not correctly balanced. If an error occurs in mmci_cmd_irq function, only mmci_dma_error function is called and as this API is not managed on stm32 variant, dma_unmap_sg is never called in this error path. Signed-off-by: Christophe Kerello --- drivers/mmc/host/mmci_stm32_sdmmc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c index 35067e1e6cd8..f5da7f9baa52 100644 --- a/drivers/mmc/host/mmci_stm32_sdmmc.c +++ b/drivers/mmc/host/mmci_stm32_sdmmc.c @@ -225,6 +225,8 @@ static int sdmmc_idma_start(struct mmci_host *host, unsigned int *datactrl) struct scatterlist *sg; int i; + host->dma_in_progress = true; + if (!host->variant->dma_lli || data->sg_len == 1 || idma->use_bounce_buffer) { u32 dma_addr; @@ -263,9 +265,30 @@ static int sdmmc_idma_start(struct mmci_host *host, unsigned int *datactrl) return 0; } +static void sdmmc_idma_error(struct mmci_host *host) +{ + struct mmc_data *data = host->data; + struct sdmmc_idma *idma = host->dma_priv; + + if (!dma_inprogress(host)) + return; + + writel_relaxed(0, host->base + MMCI_STM32_IDMACTRLR); + host->dma_in_progress = false; + data->host_cookie = 0; + + if (!idma->use_bounce_buffer) + dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, + mmc_get_dma_dir(data)); +} + static void sdmmc_idma_finalize(struct mmci_host *host, struct mmc_data *data) { + if (!dma_inprogress(host)) + return; + writel_relaxed(0, host->base + MMCI_STM32_IDMACTRLR); + host->dma_in_progress = false; if (!data->host_cookie) sdmmc_idma_unprep_data(host, data, 0); @@ -676,6 +699,7 @@ static struct mmci_host_ops sdmmc_variant_ops = { .dma_setup = sdmmc_idma_setup, .dma_start = sdmmc_idma_start, .dma_finalize = sdmmc_idma_finalize, + .dma_error = sdmmc_idma_error, .set_clkreg = mmci_sdmmc_set_clkreg, .set_pwrreg = mmci_sdmmc_set_pwrreg, .busy_complete = sdmmc_busy_complete, -- 2.25.1