Skip to content

Commit 7af037c

Browse files
Camel Guokuba-moo
authored andcommitted
net: stmmac: dump gmac4 DMA registers correctly
Unlike gmac100, gmac1000, gmac4 has 27 DMA registers and they are located at DMA_CHAN_BASE_ADDR (0x1100). In order for ethtool to dump gmac4 DMA registers correctly, this commit checks if a net_device has gmac4 and uses different logic to dump its DMA registers. This fixes the following KASAN warning, which can normally be triggered by a command similar like "ethtool -d eth0": BUG: KASAN: vmalloc-out-of-bounds in dwmac4_dump_dma_regs+0x6d4/0xb30 Write of size 4 at addr ffffffc010177100 by task ethtool/1839 kasan_report+0x200/0x21c __asan_report_store4_noabort+0x34/0x60 dwmac4_dump_dma_regs+0x6d4/0xb30 stmmac_ethtool_gregs+0x110/0x204 ethtool_get_regs+0x200/0x4b0 dev_ethtool+0x1dac/0x3800 dev_ioctl+0x7c0/0xb50 sock_ioctl+0x298/0x6c4 ... Fixes: fbf6822 ("net: stmmac: unify registers dumps methods") Signed-off-by: Camel Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4223f86 commit 7af037c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150

151151
#define NUM_DWMAC100_DMA_REGS 9
152152
#define NUM_DWMAC1000_DMA_REGS 23
153+
#define NUM_DWMAC4_DMA_REGS 27
153154

154155
void dwmac_enable_dma_transmission(void __iomem *ioaddr);
155156
void dwmac_enable_dma_irq(void __iomem *ioaddr, u32 chan, bool rx, bool tx);

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@
2121
#include "dwxgmac2.h"
2222

2323
#define REG_SPACE_SIZE 0x1060
24+
#define GMAC4_REG_SPACE_SIZE 0x116C
2425
#define MAC100_ETHTOOL_NAME "st_mac100"
2526
#define GMAC_ETHTOOL_NAME "st_gmac"
2627
#define XGMAC_ETHTOOL_NAME "st_xgmac"
2728

29+
/* Same as DMA_CHAN_BASE_ADDR defined in dwmac4_dma.h
30+
*
31+
* It is here because dwmac_dma.h and dwmac4_dam.h can not be included at the
32+
* same time due to the conflicting macro names.
33+
*/
34+
#define GMAC4_DMA_CHAN_BASE_ADDR 0x00001100
35+
2836
#define ETHTOOL_DMA_OFFSET 55
2937

3038
struct stmmac_stats {
@@ -434,6 +442,8 @@ static int stmmac_ethtool_get_regs_len(struct net_device *dev)
434442

435443
if (priv->plat->has_xgmac)
436444
return XGMAC_REGSIZE * 4;
445+
else if (priv->plat->has_gmac4)
446+
return GMAC4_REG_SPACE_SIZE;
437447
return REG_SPACE_SIZE;
438448
}
439449

@@ -446,8 +456,13 @@ static void stmmac_ethtool_gregs(struct net_device *dev,
446456
stmmac_dump_mac_regs(priv, priv->hw, reg_space);
447457
stmmac_dump_dma_regs(priv, priv->ioaddr, reg_space);
448458

449-
if (!priv->plat->has_xgmac) {
450-
/* Copy DMA registers to where ethtool expects them */
459+
/* Copy DMA registers to where ethtool expects them */
460+
if (priv->plat->has_gmac4) {
461+
/* GMAC4 dumps its DMA registers at its DMA_CHAN_BASE_ADDR */
462+
memcpy(&reg_space[ETHTOOL_DMA_OFFSET],
463+
&reg_space[GMAC4_DMA_CHAN_BASE_ADDR / 4],
464+
NUM_DWMAC4_DMA_REGS * 4);
465+
} else if (!priv->plat->has_xgmac) {
451466
memcpy(&reg_space[ETHTOOL_DMA_OFFSET],
452467
&reg_space[DMA_BUS_MODE / 4],
453468
NUM_DWMAC1000_DMA_REGS * 4);

0 commit comments

Comments
 (0)