* [PATCH net-next] stmmac: fix signed 64-bit division
@ 2018-07-06 13:36 Arnd Bergmann
2018-07-06 13:58 ` Gustavo A. R. Silva
2018-07-07 12:17 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-07-06 13:36 UTC (permalink / raw)
To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller
Cc: Arnd Bergmann, Gustavo A. R. Silva, netdev, linux-kernel
I link error on 32-bit ARM points to yet another arithmetic bug:
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.o: In function `tc_setup_cbs':
stmmac_tc.c:(.text+0x148): undefined reference to `__aeabi_uldivmod'
stmmac_tc.c:(.text+0x1fc): undefined reference to `__aeabi_uldivmod'
stmmac_tc.c:(.text+0x308): undefined reference to `__aeabi_uldivmod'
stmmac_tc.c:(.text+0x320): undefined reference to `__aeabi_uldivmod'
stmmac_tc.c:(.text+0x33c): undefined reference to `__aeabi_uldivmod'
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.o:stmmac_tc.c:(.text+0x3a4): more undefined references to `__aeabi_uldivmod' follow
I observe that the last change to add the 'ul' prefix was incorrect,
as it did not turn the result of the multiplication into a 64-bit
expression on 32-bit architectures. Further, it seems that the
do_div() macro gets confused by the fact that we pass a signed
variable rather than unsigned into it.
This changes the code to instead use the div_s64() helper that is
meant for signed division, along with changing the constant suffix
to 'll' to actually make it a 64-bit argument everywhere, fixing
both of the issues I pointed out.
I'm not completely convinced that this makes the code correct, but
I'm fairly sure that we have two problems less than before.
Fixes: 1f705bc61aee ("net: stmmac: Add support for CBS QDISC")
Fixes: c18a9c096683 ("net: stmmac_tc: use 64-bit arithmetic instead of 32-bit")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index 8fedc288d138..1a96dd9c1091 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -321,18 +321,16 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
speed_div = (priv->speed == SPEED_100) ? 100000 : 1000000;
/* Final adjustments for HW */
- value = qopt->idleslope * 1024UL * ptr;
- do_div(value, speed_div);
+ value = div_s64(qopt->idleslope * 1024ll * ptr, speed_div);
priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0);
- value = -qopt->sendslope * 1024UL * ptr;
- do_div(value, speed_div);
+ value = div_s64(-qopt->sendslope * 1024ll * ptr, speed_div);
priv->plat->tx_queues_cfg[queue].send_slope = value & GENMASK(31, 0);
- value = qopt->hicredit * 1024UL * 8;
+ value = qopt->hicredit * 1024ll * 8;
priv->plat->tx_queues_cfg[queue].high_credit = value & GENMASK(31, 0);
- value = qopt->locredit * 1024UL * 8;
+ value = qopt->locredit * 1024ll * 8;
priv->plat->tx_queues_cfg[queue].low_credit = value & GENMASK(31, 0);
ret = stmmac_config_cbs(priv, priv->hw,
--
2.9.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] stmmac: fix signed 64-bit division
2018-07-06 13:36 [PATCH net-next] stmmac: fix signed 64-bit division Arnd Bergmann
@ 2018-07-06 13:58 ` Gustavo A. R. Silva
2018-07-07 12:17 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-06 13:58 UTC (permalink / raw)
To: Arnd Bergmann, Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
David S. Miller
Cc: netdev, linux-kernel
Hi Arnd,
On 07/06/2018 08:36 AM, Arnd Bergmann wrote:
> I link error on 32-bit ARM points to yet another arithmetic bug:
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_tc.o: In function `tc_setup_cbs':
> stmmac_tc.c:(.text+0x148): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x1fc): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x308): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x320): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x33c): undefined reference to `__aeabi_uldivmod'
> drivers/net/ethernet/stmicro/stmmac/stmmac_tc.o:stmmac_tc.c:(.text+0x3a4): more undefined references to `__aeabi_uldivmod' follow
>
> I observe that the last change to add the 'ul' prefix was incorrect,
> as it did not turn the result of the multiplication into a 64-bit
> expression on 32-bit architectures. Further, it seems that the
> do_div() macro gets confused by the fact that we pass a signed
> variable rather than unsigned into it.
>
Thanks for this fix.
> This changes the code to instead use the div_s64() helper that is
> meant for signed division, along with changing the constant suffix
> to 'll' to actually make it a 64-bit argument everywhere, fixing
> both of the issues I pointed out.
>
> I'm not completely convinced that this makes the code correct, but
> I'm fairly sure that we have two problems less than before.
>
> Fixes: 1f705bc61aee ("net: stmmac: Add support for CBS QDISC")
> Fixes: c18a9c096683 ("net: stmmac_tc: use 64-bit arithmetic instead of 32-bit")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> index 8fedc288d138..1a96dd9c1091 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
> @@ -321,18 +321,16 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
> speed_div = (priv->speed == SPEED_100) ? 100000 : 1000000;
>
> /* Final adjustments for HW */
> - value = qopt->idleslope * 1024UL * ptr;
> - do_div(value, speed_div);
> + value = div_s64(qopt->idleslope * 1024ll * ptr, speed_div);
> priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0);
>
> - value = -qopt->sendslope * 1024UL * ptr;
> - do_div(value, speed_div);
> + value = div_s64(-qopt->sendslope * 1024ll * ptr, speed_div);
> priv->plat->tx_queues_cfg[queue].send_slope = value & GENMASK(31, 0);
>
> - value = qopt->hicredit * 1024UL * 8;
> + value = qopt->hicredit * 1024ll * 8;
> priv->plat->tx_queues_cfg[queue].high_credit = value & GENMASK(31, 0);
>
> - value = qopt->locredit * 1024UL * 8;
> + value = qopt->locredit * 1024ll * 8;
> priv->plat->tx_queues_cfg[queue].low_credit = value & GENMASK(31, 0);
>
> ret = stmmac_config_cbs(priv, priv->hw,
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] stmmac: fix signed 64-bit division
2018-07-06 13:36 [PATCH net-next] stmmac: fix signed 64-bit division Arnd Bergmann
2018-07-06 13:58 ` Gustavo A. R. Silva
@ 2018-07-07 12:17 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-07-07 12:17 UTC (permalink / raw)
To: arnd
Cc: peppe.cavallaro, alexandre.torgue, joabreu, gustavo, netdev,
linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 6 Jul 2018 15:36:07 +0200
> I link error on 32-bit ARM points to yet another arithmetic bug:
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_tc.o: In function `tc_setup_cbs':
> stmmac_tc.c:(.text+0x148): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x1fc): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x308): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x320): undefined reference to `__aeabi_uldivmod'
> stmmac_tc.c:(.text+0x33c): undefined reference to `__aeabi_uldivmod'
> drivers/net/ethernet/stmicro/stmmac/stmmac_tc.o:stmmac_tc.c:(.text+0x3a4): more undefined references to `__aeabi_uldivmod' follow
>
> I observe that the last change to add the 'ul' prefix was incorrect,
> as it did not turn the result of the multiplication into a 64-bit
> expression on 32-bit architectures. Further, it seems that the
> do_div() macro gets confused by the fact that we pass a signed
> variable rather than unsigned into it.
>
> This changes the code to instead use the div_s64() helper that is
> meant for signed division, along with changing the constant suffix
> to 'll' to actually make it a 64-bit argument everywhere, fixing
> both of the issues I pointed out.
>
> I'm not completely convinced that this makes the code correct, but
> I'm fairly sure that we have two problems less than before.
>
> Fixes: 1f705bc61aee ("net: stmmac: Add support for CBS QDISC")
> Fixes: c18a9c096683 ("net: stmmac_tc: use 64-bit arithmetic instead of 32-bit")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Applied, thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-07-07 12:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06 13:36 [PATCH net-next] stmmac: fix signed 64-bit division Arnd Bergmann
2018-07-06 13:58 ` Gustavo A. R. Silva
2018-07-07 12:17 ` David Miller
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).