Skip to contentSkip to conversation

mlxsw: spectrum_qdisc: Fix 64-bit division error in mlxsw_sp_qdisc_tbf_rate_kbps

PATCH Superseded Nathan Chancellor 6 participants 8 messages Jan 30, 2020 – Feb 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlxsw: spectrum_qdisc: Fix 64-bit division error in mlxsw_sp_qdisc_tbf_rate_kbps

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +1 -1
index 79a2801d59f6..65e681ef01e8 100644
@@ -614,7 +614,7 @@ mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p)
 	/* TBF interface is in bytes/s, whereas Spectrum ASIC is configured in
 	 * Kbits/s.
 	 */
-	return p->rate.rate_bytes_ps / 1000 * 8;
+	return div_u64(p->rate.rate_bytes_ps, 1000 * 8);
 }
 
 static int
Signature · 1 line
2.25.0
#1 lore raw
Quoted 19 lines · Nathan Chancellor

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +0 -0
index 79a2801d59f6..65e681ef01e8 100644

drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p) · line 617

Quoted 5 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +1 -1
@@ -614,7 +614,7 @@ mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p)
 	/* TBF interface is in bytes/s, whereas Spectrum ASIC is configured in
 	 * Kbits/s.
 	 */
-	return p->rate.rate_bytes_ps / 1000 * 8;
+	return div_u64(p->rate.rate_bytes_ps, 1000 * 8);

not quite right AFAICT.

try either

	return div_u64(p->rate.rate_bytes_ps * 8, 1000);
or
	return div_u64(p->rate.rate_bytes_ps, 1000) * 8;
Quoted 4 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +0 -0
 }
 
 static int
Signature · 1 line
~Randy
#2 lore raw
Quoted 28 lines · Randy Dunlap
Quoted 19 lines · Nathan Chancellor

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +0 -0
index 79a2801d59f6..65e681ef01e8 100644

drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p) · line 617

Quoted 5 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +1 -1
@@ -614,7 +614,7 @@ mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p)
 	/* TBF interface is in bytes/s, whereas Spectrum ASIC is configured in
 	 * Kbits/s.
 	 */
-	return p->rate.rate_bytes_ps / 1000 * 8;
+	return div_u64(p->rate.rate_bytes_ps, 1000 * 8);

not quite right AFAICT.

Quoted 5 lines

try either

	return div_u64(p->rate.rate_bytes_ps * 8, 1000);
or
	return div_u64(p->rate.rate_bytes_ps, 1000) * 8;

Gah, I swear I can math... Thank you for catching this, v2 incoming with the later because I think it looks better.

Cheers,
Nathan

Quoted 9 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +0 -0
 }
 
 static int
Signature · 1 line
~Randy
#3 lore raw
Quoted 29 lines · Nathan Chancellor
Quoted 28 lines · Randy Dunlap
Quoted 19 lines · Nathan Chancellor

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +0 -0
index 79a2801d59f6..65e681ef01e8 100644

drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p) · line 617

Quoted 5 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +1 -1
@@ -614,7 +614,7 @@ mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p)
 	/* TBF interface is in bytes/s, whereas Spectrum ASIC is configured in
 	 * Kbits/s.
 	 */
-	return p->rate.rate_bytes_ps / 1000 * 8;
+	return div_u64(p->rate.rate_bytes_ps, 1000 * 8);

not quite right AFAICT.

Quoted 8 lines
Quoted 5 lines

try either

	return div_u64(p->rate.rate_bytes_ps * 8, 1000);
or
	return div_u64(p->rate.rate_bytes_ps, 1000) * 8;

Gah, I swear I can math... Thank you for catching this, v2 incoming with the later because I think it looks better.

Yes, that's the correct choice. Divide first, that way we can't overflow.

Thanks for taking care of this.

#4 lore raw

PATCH v2 1/1 mlxsw: spectrum_qdisc: Fix 64-bit division error in mlxsw_sp_qdisc_tbf_rate_kbps

In reply to Nathan Chancellor

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")

---

v1 -> v2:

* Fix incorrect math as pointed out by Randy Dunlap

 drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c +1 -1
index 79a2801d59f6..02526c53d4f5 100644
@@ -614,7 +614,7 @@ mlxsw_sp_qdisc_tbf_rate_kbps(struct tc_tbf_qopt_offload_replace_params *p)
 	/* TBF interface is in bytes/s, whereas Spectrum ASIC is configured in
 	 * Kbits/s.
 	 */
-	return p->rate.rate_bytes_ps / 1000 * 8;
+	return div_u64(p->rate.rate_bytes_ps, 1000) * 8;
 }
 
 static int
Signature · 1 line
2.25.0
Reviewed-by Tested-by on v2 1/1
#5 lore raw
Quoted 10 lines · Nathan Chancellor

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")

Thanks, Nathan.

Acked-by on v2 1/1
#6 lore raw
In reply to Nathan Chancellor
Quoted 10 lines · Fri, Jan 31, 2020 at 02:51:23AM CET, [email protected] wrote:

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")
maintainer Applied
#7 lore raw
In reply to Nathan Chancellor
Quoted 10 lines · Nathan Chancellor

When building arm32 allmodconfig:

ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/mellanox/mlxsw/mlxsw_spectrum.ko] undefined!

rate_bytes_ps has type u64, we need to use a 64-bit division helper to avoid a build error.

Fixes a44f58c41bfb ("mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc")

Applied, thank you.