net: moxa: get rid of asymmetry in DMA mapping/unmapping
Subsystems (2)
PATCH v2 1/1 net: moxa: get rid of asymmetry in DMA mapping/unmapping
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.
--- drivers/net/ethernet/moxa/moxart_ether.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +6 -5
@@ -71,11 +71,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,
@@ -187,6 +182,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);
@@ -198,6 +194,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 ; }
Signature · 1 line
2.32.0
Quoted 43 lines · Sergei Antonov
Since priv->rx_mapping[i] is maped in
moxart_mac_open(), we should unmap it frommoxart_mac_stop(). Fixes 2 warnings.1. During error unwinding in
moxart_mac_probe(): "gotoinit_fail;", thenmoxart_mac_free_memory()callsdma_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/0x2e42. After commands:
ip link set dev eth0 down
ip link set dev eth0 upWARNING: 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
Quoted 5 lines
v1 -> v2:
Extraneous change removed.Fixes 6c821bd9edc9 ("net: Add MOXA ART SoCs ethernet driver")Signed-off-by Sergei Antonov <[email protected]>
Andrew
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Fri, 19 Aug 2022 14:05:19 +0300 you wrote:
Since priv->rx_mapping[i] is maped in
moxart_mac_open(), we should unmap it frommoxart_mac_stop(). Fixes 2 warnings.1. During error unwinding in
moxart_mac_probe(): "gotoinit_fail;", thenmoxart_mac_free_memory()callsdma_unmap_single()with priv->rx_mapping[i] pointers zeroed.[...]
Here is the summary with links:
- [v2] net: moxa: get rid of asymmetry in DMA mapping/unmapping
https://git.kernel.org/netdev/net/c/0ee7828dfc56
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html