* [PATCH v2 net 1/1] stmmac: fix potential division by 0
@ 2022-12-10 22:37 Piergiorgio Beruto
2022-12-11 11:18 ` Andrew Lunn
2022-12-12 23:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Piergiorgio Beruto @ 2022-12-10 22:37 UTC (permalink / raw)
To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
Richard Cochran, Julien Beraud
Cc: netdev, Andreww Lunn
When the MAC is connected to a 10 Mb/s PHY and the PTP clock is derived
from the MAC reference clock (default), the clk_ptp_rate becomes too
small and the calculated sub second increment becomes 0 when computed by
the stmmac_config_sub_second_increment() function within
stmmac_init_tstamp_counter().
Therefore, the subsequent div_u64 in stmmac_init_tstamp_counter()
operation triggers a divide by 0 exception as shown below.
[ 95.062067] socfpga-dwmac ff700000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0
[ 95.076440] socfpga-dwmac ff700000.ethernet eth0: PHY [stmmac-0:08] driver [NCN26000] (irq=49)
[ 95.095964] dwmac1000: Master AXI performs any burst length
[ 95.101588] socfpga-dwmac ff700000.ethernet eth0: No Safety Features support found
[ 95.109428] Division by zero in kernel.
[ 95.113447] CPU: 0 PID: 239 Comm: ifconfig Not tainted 6.1.0-rc7-centurion3-1.0.3.0-01574-gb624218205b7-dirty #77
[ 95.123686] Hardware name: Altera SOCFPGA
[ 95.127695] unwind_backtrace from show_stack+0x10/0x14
[ 95.132938] show_stack from dump_stack_lvl+0x40/0x4c
[ 95.137992] dump_stack_lvl from Ldiv0+0x8/0x10
[ 95.142527] Ldiv0 from __aeabi_uidivmod+0x8/0x18
[ 95.147232] __aeabi_uidivmod from div_u64_rem+0x1c/0x40
[ 95.152552] div_u64_rem from stmmac_init_tstamp_counter+0xd0/0x164
[ 95.158826] stmmac_init_tstamp_counter from stmmac_hw_setup+0x430/0xf00
[ 95.165533] stmmac_hw_setup from __stmmac_open+0x214/0x2d4
[ 95.171117] __stmmac_open from stmmac_open+0x30/0x44
[ 95.176182] stmmac_open from __dev_open+0x11c/0x134
[ 95.181172] __dev_open from __dev_change_flags+0x168/0x17c
[ 95.186750] __dev_change_flags from dev_change_flags+0x14/0x50
[ 95.192662] dev_change_flags from devinet_ioctl+0x2b4/0x604
[ 95.198321] devinet_ioctl from inet_ioctl+0x1ec/0x214
[ 95.203462] inet_ioctl from sock_ioctl+0x14c/0x3c4
[ 95.208354] sock_ioctl from vfs_ioctl+0x20/0x38
[ 95.212984] vfs_ioctl from sys_ioctl+0x250/0x844
[ 95.217691] sys_ioctl from ret_fast_syscall+0x0/0x4c
[ 95.222743] Exception stack(0xd0ee1fa8 to 0xd0ee1ff0)
[ 95.227790] 1fa0: 00574c4f be9aeca4 00000003 00008914 be9aeca4 be9aec50
[ 95.235945] 1fc0: 00574c4f be9aeca4 0059f078 00000036 be9aee8c be9aef7a 00000015 00000000
[ 95.244096] 1fe0: 005a01f0 be9aec38 004d7484 b6e67d74
Signed-off-by: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
Fixes: 91a2559c1dc5 ("net: stmmac: Fix sub-second increment")
---
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 3 ++-
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index 764832f4dae1..8b50f03056b7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -47,7 +47,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,
if (!(value & PTP_TCR_TSCTRLSSR))
data = (data * 1000) / 465;
- data &= PTP_SSIR_SSINC_MASK;
+ if (data > PTP_SSIR_SSINC_MAX)
+ data = PTP_SSIR_SSINC_MAX;
reg_value = data;
if (gmac4)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
index 53172a439810..bf619295d079 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
@@ -64,7 +64,7 @@
#define PTP_TCR_TSENMACADDR BIT(18)
/* SSIR defines */
-#define PTP_SSIR_SSINC_MASK 0xff
+#define PTP_SSIR_SSINC_MAX 0xff
#define GMAC4_PTP_SSIR_SSINC_SHIFT 16
/* Auxiliary Control defines */
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net 1/1] stmmac: fix potential division by 0
2022-12-10 22:37 [PATCH v2 net 1/1] stmmac: fix potential division by 0 Piergiorgio Beruto
@ 2022-12-11 11:18 ` Andrew Lunn
2022-12-12 23:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2022-12-11 11:18 UTC (permalink / raw)
To: Piergiorgio Beruto
Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
Richard Cochran, Julien Beraud, netdev
On Sat, Dec 10, 2022 at 11:37:22PM +0100, Piergiorgio Beruto wrote:
> When the MAC is connected to a 10 Mb/s PHY and the PTP clock is derived
> from the MAC reference clock (default), the clk_ptp_rate becomes too
> small and the calculated sub second increment becomes 0 when computed by
> the stmmac_config_sub_second_increment() function within
> stmmac_init_tstamp_counter().
>
> Therefore, the subsequent div_u64 in stmmac_init_tstamp_counter()
> operation triggers a divide by 0 exception as shown below.
>
> [ 95.062067] socfpga-dwmac ff700000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0
> [ 95.076440] socfpga-dwmac ff700000.ethernet eth0: PHY [stmmac-0:08] driver [NCN26000] (irq=49)
> [ 95.095964] dwmac1000: Master AXI performs any burst length
> [ 95.101588] socfpga-dwmac ff700000.ethernet eth0: No Safety Features support found
> [ 95.109428] Division by zero in kernel.
> [ 95.113447] CPU: 0 PID: 239 Comm: ifconfig Not tainted 6.1.0-rc7-centurion3-1.0.3.0-01574-gb624218205b7-dirty #77
> [ 95.123686] Hardware name: Altera SOCFPGA
> [ 95.127695] unwind_backtrace from show_stack+0x10/0x14
> [ 95.132938] show_stack from dump_stack_lvl+0x40/0x4c
> [ 95.137992] dump_stack_lvl from Ldiv0+0x8/0x10
> [ 95.142527] Ldiv0 from __aeabi_uidivmod+0x8/0x18
> [ 95.147232] __aeabi_uidivmod from div_u64_rem+0x1c/0x40
> [ 95.152552] div_u64_rem from stmmac_init_tstamp_counter+0xd0/0x164
> [ 95.158826] stmmac_init_tstamp_counter from stmmac_hw_setup+0x430/0xf00
> [ 95.165533] stmmac_hw_setup from __stmmac_open+0x214/0x2d4
> [ 95.171117] __stmmac_open from stmmac_open+0x30/0x44
> [ 95.176182] stmmac_open from __dev_open+0x11c/0x134
> [ 95.181172] __dev_open from __dev_change_flags+0x168/0x17c
> [ 95.186750] __dev_change_flags from dev_change_flags+0x14/0x50
> [ 95.192662] dev_change_flags from devinet_ioctl+0x2b4/0x604
> [ 95.198321] devinet_ioctl from inet_ioctl+0x1ec/0x214
> [ 95.203462] inet_ioctl from sock_ioctl+0x14c/0x3c4
> [ 95.208354] sock_ioctl from vfs_ioctl+0x20/0x38
> [ 95.212984] vfs_ioctl from sys_ioctl+0x250/0x844
> [ 95.217691] sys_ioctl from ret_fast_syscall+0x0/0x4c
> [ 95.222743] Exception stack(0xd0ee1fa8 to 0xd0ee1ff0)
> [ 95.227790] 1fa0: 00574c4f be9aeca4 00000003 00008914 be9aeca4 be9aec50
> [ 95.235945] 1fc0: 00574c4f be9aeca4 0059f078 00000036 be9aee8c be9aef7a 00000015 00000000
> [ 95.244096] 1fe0: 005a01f0 be9aec38 004d7484 b6e67d74
>
> Signed-off-by: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
> Fixes: 91a2559c1dc5 ("net: stmmac: Fix sub-second increment")
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net 1/1] stmmac: fix potential division by 0
2022-12-10 22:37 [PATCH v2 net 1/1] stmmac: fix potential division by 0 Piergiorgio Beruto
2022-12-11 11:18 ` Andrew Lunn
@ 2022-12-12 23:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-12-12 23:20 UTC (permalink / raw)
To: Piergiorgio Beruto
Cc: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet, kuba,
pabeni, mcoquelin.stm32, richardcochran, julien.beraud, netdev,
andrew
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 10 Dec 2022 23:37:22 +0100 you wrote:
> When the MAC is connected to a 10 Mb/s PHY and the PTP clock is derived
> from the MAC reference clock (default), the clk_ptp_rate becomes too
> small and the calculated sub second increment becomes 0 when computed by
> the stmmac_config_sub_second_increment() function within
> stmmac_init_tstamp_counter().
>
> Therefore, the subsequent div_u64 in stmmac_init_tstamp_counter()
> operation triggers a divide by 0 exception as shown below.
>
> [...]
Here is the summary with links:
- [v2,net,1/1] stmmac: fix potential division by 0
https://git.kernel.org/netdev/net/c/ede5a389852d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-12 23:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-10 22:37 [PATCH v2 net 1/1] stmmac: fix potential division by 0 Piergiorgio Beruto
2022-12-11 11:18 ` Andrew Lunn
2022-12-12 23:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).