Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1873646lql; Wed, 13 Mar 2024 10:24:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/7o8pJeIMrcOzSkdZU7JD8DG662KQsxQ+KufojTlUVYj9IhNAjmn+wiSlS76kfBCUGSGvDtJV/1TJTA3dD7sOUOE+BvH/tZjeT5MarA== X-Google-Smtp-Source: AGHT+IGUCZfAXFJ6vsOw+LU0AUQc5MZ9e5nA5YOLxpWZfl68wGJSUi7f8CAxQEkRxjQ3S/6nZPse X-Received: by 2002:a17:906:c784:b0:a46:61ef:2846 with SMTP id cw4-20020a170906c78400b00a4661ef2846mr1232521ejb.66.1710350642156; Wed, 13 Mar 2024 10:24:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710350642; cv=pass; d=google.com; s=arc-20160816; b=olElM1fjdcT4I24qBaOm4/0uYwok0azT3H/weefsSmnXjAk5YOIpf5thnNzzeymOfv JZgZzAned0Sg9X9O+7a/3gHyGW7wZl9FL/uVGtpbwpZ6dQMQdf+OdUQhobeYcbreE9dY +0p32QZ8pmray6WbLoijbd/8J2H0nBf6g2NSIhWjlj/Avyskr6vdjrvcC7+9iSXZAhWA iZ6M0GJDrHsMoX3EGRTvOoJPhgmOfyyleoWtPosh+P8NU20/l0gztaGiEpWPXiUR9VoQ E06RtFSHJdGHqIEexUSAMP23o4DD196VUg2RObvH8DkZsa8cAb57WnSk3W3S4gVIR6C6 O3Hg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=txeu50H0pN1pQ9tDLilkRBLaE3M6T/8oByqTwGCBoGc=; fh=8ieCNqw3K+/cgEEp5DvqRqgRLYc1BCF2qb1XpWyyaV4=; b=Pbgh+yFSmfisn11VPGM61Axs52fOxEulF9UfhvD2qRFJpOYUGSyZ3IxDOR6OTiC+C5 s3wtAZLhQuEFs0XqLW+KbvVIbNZdMBQueHrycVYBdUUkCS1EJaNUWe3uTxCrY/Zb+Th8 lcANYO0NX51EepwH2jRBYcyq4VLbOxvQ11YDdR84nhSTfnPej6tADOU/6Du4/tCs4Vsr 2RTHvIgmOtBdUmJbxl+Z0Ec/ecGQcXmCJjhlczh8zX3FOYaGpUYeYKmOdfK2QI1XN83b MIZ0GmEpJra/KgzXbnqBVOgeBSVDksHcon2R1vChMJuJQBhLQhPTDZD/hAq4Q3Z91+C8 cgYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CahHFGXW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101942-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101942-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u16-20020a1709064ad000b00a45ffbef23bsi4621841ejt.33.2024.03.13.10.24.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101942-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CahHFGXW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101942-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101942-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 401A81F2654B for ; Wed, 13 Mar 2024 17:21:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9BDA626DB; Wed, 13 Mar 2024 16:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CahHFGXW" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0134350A88; Wed, 13 Mar 2024 16:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348149; cv=none; b=QA0O96Ze4HAJ3w9XWEZ4IUJbTgoVDUgo+hMT3Yk1A9Ik1BM2ziaSTh6tRKB3b2f4kWLjRlr9Gv4Dl5iocPwPjSMua95jZAS5wC46OrE61y6dUcD5FHDockIAf5av8DZv8AczsEhMwBT/KQBbvlW156csGvA687jknacCvDUOLgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348149; c=relaxed/simple; bh=BKKvaSPOJcIzN9AKZ4t/6eH1vXhiFpdAhQlKssnCZxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aaDbcuqk+qV4sNvbXYCAgpdBswYsXb4HogOR2D97RKgbXWP5rPtGCaV4HaaVNHzBgmI8X3nTFTSFoMYHMkHt8zHEDRLcBFRkuG7BeG9rFT7uO91PDoIEL1jLP77GB0qoh5bxGtLYTv0okJJ4HvmJo7esCoXTdpjzTkmAUVoG0o4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CahHFGXW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F54FC43390; Wed, 13 Mar 2024 16:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348148; bh=BKKvaSPOJcIzN9AKZ4t/6eH1vXhiFpdAhQlKssnCZxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CahHFGXWtHcL18LsOZS2utOmDNW+yieTLJvMpSaT/6wqC/8HTMB1/2aTfT1FiR4dC 8WTku8vWfOR+xptNQ4onOoIIuwNc4l/0UbXaSIkuE09Q/fQ+KwghKln+UfoE/kFH4B wYxacbZIR6/I6vYx6eDnGhVOjGJbHN8HEm+OpGGOoJDsEb8uxLMNAnWo/JVgkg+0ht aZW4Myt1nzp3aWeVEw7h8sNmolv8THsCYC2aYfdYrG7PNVlwwVoq5tHXJUSYSMgRO8 jbwllfsFWUsdY36BRpqhICZHfXUDCbCaKxMXPgEoaGWhW0LqfqPcF8o13bAn5vrb3L xGesmZuznfTcQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe Kerello , Ulf Hansson , Sasha Levin Subject: [PATCH 5.15 02/76] mmc: mmci: stm32: fix DMA API overlapping mappings warning Date: Wed, 13 Mar 2024 12:41:09 -0400 Message-ID: <20240313164223.615640-3-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164223.615640-1-sashal@kernel.org> References: <20240313164223.615640-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.152-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.15.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.15.152-rc1 X-KernelTest-Deadline: 2024-03-15T16:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Christophe Kerello [ Upstream commit 6b1ba3f9040be5efc4396d86c9752cdc564730be ] 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 Fixes: 46b723dd867d ("mmc: mmci: add stm32 sdmmc variant") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240207143951.938144-1-christophe.kerello@foss.st.com Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- 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 11ae0cb479239..e3201a621870a 100644 --- a/drivers/mmc/host/mmci_stm32_sdmmc.c +++ b/drivers/mmc/host/mmci_stm32_sdmmc.c @@ -200,6 +200,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; @@ -238,9 +240,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); @@ -566,6 +589,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.43.0