Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3049546rwe; Mon, 29 Aug 2022 05:08:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7LdiQMUnRafMGOaORB4PO4tidJ4nuESVB/4BkaQozJPs1PHMvA7y0aVnslktoiemvIwF0n X-Received: by 2002:a17:906:8a4e:b0:740:2450:d69a with SMTP id gx14-20020a1709068a4e00b007402450d69amr9356169ejc.523.1661774929381; Mon, 29 Aug 2022 05:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661774929; cv=none; d=google.com; s=arc-20160816; b=zFV5MNO0pk3ikhBCPWHN7OskHNCkXgyUmXZ+az2kGnRo6gXBb2eZm/ElETs6Bn1RDe 7Q+cddqbO1hFhHPffKHhPnBGxtyYsQQEgANZ1pj76SmQ8gDDEKtHl8MYieg9WH7cBSZe 7JpJqKgDDGJPqZ7dtvpMVnIAbrd/GOhUtDjgUjAeyt8Wi7m1HNyhiWSxhe5ETkLQp5tb QFZtx1rKcyzGnFHMNZQecABCkR2Oe1juv2K3/x1NgTSk0zeS3wdFXHvHhUSE9KtMezrF X/J9sMCGkMyUs0s0IV9466y4Trd/RGJoB4CxylpgCMBK3yUm0m7RhuL9wzDiSZIZx21U NuXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iOagCnbkQ+L5NIiMtHsV5oEOZ8y452SsfOCrNWraMo0=; b=YjChQmZIa8DNVohixk1JZw5uuMvzTlB+7cJFK1iKt+lOU5//pchnAC6ijyz4R0i46T 6moqwrBWGyzH7yM+tbLfqaYqgkZvi4RwWnVJfVJHb04B0vZWU69SsFs29WMsLtEgPHqV SRgWr0v8Opx3XlpSdMlLNBk3FTcXOSpWmHamTk1Sd6bihwkgpGH8wA2dPttA0z1Sbsto fVonrqujaoUj+Xj8g91Snp/z4nTbMgpOAIm6aeD0Y88gi00ksE1MZnJx87TFhcQJikGa VIBBl9IqSOWfAdPNu/r0E+c1uDsxccl9tLHmeo8q+BmzriguL5ndt1Jrat9n/2g/fCqX D55w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UgfCpt/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id my17-20020a1709065a5100b00711da52c6e4si5387332ejc.309.2022.08.29.05.08.23; Mon, 29 Aug 2022 05:08:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UgfCpt/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbiH2LWF (ORCPT + 99 others); Mon, 29 Aug 2022 07:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbiH2LUj (ORCPT ); Mon, 29 Aug 2022 07:20:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2184566A49; Mon, 29 Aug 2022 04:14:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 85B9AB80FB3; Mon, 29 Aug 2022 11:13:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD0BEC433D6; Mon, 29 Aug 2022 11:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771585; bh=gtulpLrNC9Vr2OGeOpWy446vUQ2NNprrFCbro7zgi+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UgfCpt/49qwh7mvyiUVi9CxitNythR4hzuU39Ufi4Jl4zkXlx/6c7/UWMOdgYTx3r yyvEM2gOh1+leFItfHjMVv498KEGXb3XML6xK9J8BvVJW+uNk9TRaZWexjMNEqe2Mv gw49053ff4gAdohL7cK5D9xqCbxGlUtX6HkXB9FM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergei Antonov , Andrew Lunn , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.19 046/158] net: moxa: get rid of asymmetry in DMA mapping/unmapping Date: Mon, 29 Aug 2022 12:58:16 +0200 Message-Id: <20220829105810.698091357@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergei Antonov [ Upstream commit 0ee7828dfc56e97d71e51e6374dc7b4eb2b6e081 ] Since priv->rx_mapping[i] is maped in moxart_mac_open(), we should unmap it from moxart_mac_stop(). Fixes 2 warnings. 1. During error unwinding in moxart_mac_probe(): "goto init_fail;", then moxart_mac_free_memory() calls dma_unmap_single() with priv->rx_mapping[i] pointers zeroed. WARNING: CPU: 0 PID: 1 at kernel/dma/debug.c:963 check_unmap+0x704/0x980 DMA-API: moxart-ethernet 92000000.mac: device driver tries to free DMA memory it has not allocated [device address=0x0000000000000000] [size=1600 bytes] CPU: 0 PID: 1 Comm: swapper Not tainted 5.19.0+ #60 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x34/0x44 dump_stack_lvl from __warn+0xbc/0x1f0 __warn from warn_slowpath_fmt+0x94/0xc8 warn_slowpath_fmt from check_unmap+0x704/0x980 check_unmap from debug_dma_unmap_page+0x8c/0x9c debug_dma_unmap_page from moxart_mac_free_memory+0x3c/0xa8 moxart_mac_free_memory from moxart_mac_probe+0x190/0x218 moxart_mac_probe from platform_probe+0x48/0x88 platform_probe from really_probe+0xc0/0x2e4 2. After commands: ip link set dev eth0 down ip link set dev eth0 up WARNING: CPU: 0 PID: 55 at kernel/dma/debug.c:570 add_dma_entry+0x204/0x2ec DMA-API: moxart-ethernet 92000000.mac: cacheline tracking EEXIST, overlapping mappings aren't supported CPU: 0 PID: 55 Comm: ip Not tainted 5.19.0+ #57 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x34/0x44 dump_stack_lvl from __warn+0xbc/0x1f0 __warn from warn_slowpath_fmt+0x94/0xc8 warn_slowpath_fmt from add_dma_entry+0x204/0x2ec add_dma_entry from dma_map_page_attrs+0x110/0x328 dma_map_page_attrs from moxart_mac_open+0x134/0x320 moxart_mac_open from __dev_open+0x11c/0x1ec __dev_open from __dev_change_flags+0x194/0x22c __dev_change_flags from dev_change_flags+0x14/0x44 dev_change_flags from devinet_ioctl+0x6d4/0x93c devinet_ioctl from inet_ioctl+0x1ac/0x25c v1 -> v2: Extraneous change removed. Fixes: 6c821bd9edc9 ("net: Add MOXA ART SoCs ethernet driver") Signed-off-by: Sergei Antonov Reviewed-by: Andrew Lunn Link: https://lore.kernel.org/r/20220819110519.1230877-1-saproj@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/moxa/moxart_ether.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index f11f1cb92025f..3b6beb96ca856 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -74,11 +74,6 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr) static void moxart_mac_free_memory(struct net_device *ndev) { struct moxart_mac_priv_t *priv = netdev_priv(ndev); - int i; - - for (i = 0; i < RX_DESC_NUM; i++) - dma_unmap_single(&priv->pdev->dev, priv->rx_mapping[i], - priv->rx_buf_size, DMA_FROM_DEVICE); if (priv->tx_desc_base) dma_free_coherent(&priv->pdev->dev, @@ -193,6 +188,7 @@ static int moxart_mac_open(struct net_device *ndev) static int moxart_mac_stop(struct net_device *ndev) { struct moxart_mac_priv_t *priv = netdev_priv(ndev); + int i; napi_disable(&priv->napi); @@ -204,6 +200,11 @@ static int moxart_mac_stop(struct net_device *ndev) /* disable all functions */ writel(0, priv->base + REG_MAC_CTRL); + /* unmap areas mapped in moxart_mac_setup_desc_ring() */ + for (i = 0; i < RX_DESC_NUM; i++) + dma_unmap_single(&priv->pdev->dev, priv->rx_mapping[i], + priv->rx_buf_size, DMA_FROM_DEVICE); + return 0; } -- 2.35.1