Skip to contentSkip to conversation

net: openvswitch: use do_div() for 64-by-32 divisions:

PATCH In review Geert Uytterhoeven 4 participants 6 messages Apr 24, 2020 – Apr 25, 2020

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

PATCH 1/1 net: openvswitch: use do_div() for 64-by-32 divisions:

On 32-bit architectures (e.g. m68k):

ERROR: modpost: "__udivdi3" [net/openvswitch/openvswitch.ko] undefined!
ERROR: modpost: "__divdi3" [net/openvswitch/openvswitch.ko] undefined!

Fixes e57358873bb5d6ca ("net: openvswitch: use u64 for meter bucket")
Reported-by [email protected]
---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/meter.c +1 -1
index 915f31123f235c03..3498a5ab092ab2b8 100644
@@ -393,7 +393,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
 		 * Start with a full bucket.
 		 */
 		band->bucket = (band->burst_size + band->rate) * 1000ULL;
-		band_max_delta_t = band->bucket / band->rate;
+		band_max_delta_t = do_div(band->bucket, band->rate);
 		if (band_max_delta_t > meter->max_delta_t)
 			meter->max_delta_t = band_max_delta_t;
 		band++;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 18 lines · Geert Uytterhoeven

On 32-bit architectures (e.g. m68k):

ERROR: modpost: "__udivdi3" [net/openvswitch/openvswitch.ko] undefined!
ERROR: modpost: "__divdi3" [net/openvswitch/openvswitch.ko] undefined!

Fixes e57358873bb5d6ca ("net: openvswitch: use u64 for meter bucket")
Reported-by [email protected]
---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/meter.c +0 -0
index 915f31123f235c03..3498a5ab092ab2b8 100644

net/openvswitch/meter.c static struct dp_meter *dp_meter_create(struct nlattr **a) · line 399

Quoted 8 lines
net/openvswitch/meter.c +1 -1
@@ -393,7 +393,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
 		 * Start with a full bucket.
 		 */
 		band->bucket = (band->burst_size + band->rate) * 1000ULL;
-		band_max_delta_t = band->bucket / band->rate;
+		band_max_delta_t = do_div(band->bucket, band->rate);
 		if (band_max_delta_t > meter->max_delta_t)
 			meter->max_delta_t = band_max_delta_t;
 		band++;

This is fascinating... Have you tested this patch ?

Please double check what do_div() return value is supposed to be !

Thanks.

#2 lore raw

Hi Eric,

Quoted 13 lines · Eric Dumazet
Quoted 12 lines · Geert Uytterhoeven

On 32-bit architectures (e.g. m68k):

ERROR: modpost: "__udivdi3" [net/openvswitch/openvswitch.ko] undefined!
ERROR: modpost: "__divdi3" [net/openvswitch/openvswitch.ko] undefined!

Fixes e57358873bb5d6ca ("net: openvswitch: use u64 for meter bucket")
Reported-by [email protected]
---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
net/openvswitch/meter.c +0 -0
index 915f31123f235c03..3498a5ab092ab2b8 100644

net/openvswitch/meter.c static struct dp_meter *dp_meter_create(struct nlattr **a) · line 399

Quoted 8 lines
net/openvswitch/meter.c +1 -1
@@ -393,7 +393,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
               * Start with a full bucket.
               */
              band->bucket = (band->burst_size + band->rate) * 1000ULL;
-             band_max_delta_t = band->bucket / band->rate;
+             band_max_delta_t = do_div(band->bucket, band->rate);
              if (band_max_delta_t > meter->max_delta_t)
                      meter->max_delta_t = band_max_delta_t;
              band++;

This is fascinating... Have you tested this patch ?

Sorry, I should have said this is compile-tested only.

Quoted 1 line

Please double check what do_div() return value is supposed to be !

I do not have any openvswitch setups, let alone on the poor m68k box.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw
Quoted 33 lines · Geert Uytterhoeven

Hi Eric,

Quoted 13 lines · Eric Dumazet
Quoted 12 lines · Geert Uytterhoeven

On 32-bit architectures (e.g. m68k):

ERROR: modpost: "__udivdi3" [net/openvswitch/openvswitch.ko] undefined!
ERROR: modpost: "__divdi3" [net/openvswitch/openvswitch.ko] undefined!

Fixes e57358873bb5d6ca ("net: openvswitch: use u64 for meter bucket")
Reported-by [email protected]
---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
net/openvswitch/meter.c +0 -0
index 915f31123f235c03..3498a5ab092ab2b8 100644

net/openvswitch/meter.c static struct dp_meter *dp_meter_create(struct nlattr **a) · line 399

Quoted 8 lines
net/openvswitch/meter.c +1 -1
@@ -393,7 +393,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
               * Start with a full bucket.
               */
              band->bucket = (band->burst_size + band->rate) * 1000ULL;
-             band_max_delta_t = band->bucket / band->rate;
+             band_max_delta_t = do_div(band->bucket, band->rate);
              if (band_max_delta_t > meter->max_delta_t)
                      meter->max_delta_t = band_max_delta_t;
              band++;

This is fascinating... Have you tested this patch ?

Quoted 5 lines

Sorry, I should have said this is compile-tested only.

Quoted 1 line

Please double check what do_div() return value is supposed to be !

I do not have any openvswitch setups, let alone on the poor m68k box.

I think what Eric is referring to is this, from the documentation of do_div:

* do_div - returns 2 values: calculate remainder and update new dividend
* @n: uint64_t dividend (will be updated)
* @base: uint32_t divisor
*
* Summary:
* ``uint32_t remainder = n % base;``
* ``n = n / base;``
*
* Return: (uint32_t)remainder

Specifically that last part :)

-Toke

#4 lore raw

Hi Toke,

Quoted 41 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Geert Uytterhoeven
Quoted 13 lines · Eric Dumazet
Quoted 12 lines · Geert Uytterhoeven

On 32-bit architectures (e.g. m68k):

ERROR: modpost: "__udivdi3" [net/openvswitch/openvswitch.ko] undefined!
ERROR: modpost: "__divdi3" [net/openvswitch/openvswitch.ko] undefined!

Fixes e57358873bb5d6ca ("net: openvswitch: use u64 for meter bucket")
Reported-by [email protected]
---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
net/openvswitch/meter.c +0 -0
index 915f31123f235c03..3498a5ab092ab2b8 100644

net/openvswitch/meter.c static struct dp_meter *dp_meter_create(struct nlattr **a) · line 399

Quoted 8 lines
net/openvswitch/meter.c +1 -1
@@ -393,7 +393,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
               * Start with a full bucket.
               */
              band->bucket = (band->burst_size + band->rate) * 1000ULL;
-             band_max_delta_t = band->bucket / band->rate;
+             band_max_delta_t = do_div(band->bucket, band->rate);
              if (band_max_delta_t > meter->max_delta_t)
                      meter->max_delta_t = band_max_delta_t;
              band++;

This is fascinating... Have you tested this patch ?

Quoted 5 lines

Sorry, I should have said this is compile-tested only.

Quoted 1 line

Please double check what do_div() return value is supposed to be !

I do not have any openvswitch setups, let alone on the poor m68k box.

I think what Eric is referring to is this, from the documentation of do_div:

Quoted 9 lines

* do_div - returns 2 values: calculate remainder and update new dividend
* @n: uint64_t dividend (will be updated)
* @base: uint32_t divisor
*
* Summary:
* ``uint32_t remainder = n % base;``
* ``n = n / base;``
*
* Return: (uint32_t)remainder

Oops, that was a serious brain fart. Sorry for that!

That should have been div_u64() instead of do_div().
Feel free to update my patch while applying, else I'll send a v2 later.

/me hides in a brown paper bag for the whole weekend...

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw
Quoted 55 lines · Geert Uytterhoeven

Hi Toke,

Quoted 41 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Geert Uytterhoeven
Quoted 13 lines · Eric Dumazet
Quoted 12 lines · Geert Uytterhoeven

On 32-bit architectures (e.g. m68k):

ERROR: modpost: "__udivdi3" [net/openvswitch/openvswitch.ko] undefined!
ERROR: modpost: "__divdi3" [net/openvswitch/openvswitch.ko] undefined!

Fixes e57358873bb5d6ca ("net: openvswitch: use u64 for meter bucket")
Reported-by [email protected]
---
 net/openvswitch/meter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
net/openvswitch/meter.c +0 -0
index 915f31123f235c03..3498a5ab092ab2b8 100644

net/openvswitch/meter.c static struct dp_meter *dp_meter_create(struct nlattr **a) · line 399

Quoted 8 lines
net/openvswitch/meter.c +1 -1
@@ -393,7 +393,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
               * Start with a full bucket.
               */
              band->bucket = (band->burst_size + band->rate) * 1000ULL;
-             band_max_delta_t = band->bucket / band->rate;
+             band_max_delta_t = do_div(band->bucket, band->rate);
              if (band_max_delta_t > meter->max_delta_t)
                      meter->max_delta_t = band_max_delta_t;
              band++;

This is fascinating... Have you tested this patch ?

Quoted 5 lines

Sorry, I should have said this is compile-tested only.

Quoted 1 line

Please double check what do_div() return value is supposed to be !

I do not have any openvswitch setups, let alone on the poor m68k box.

I think what Eric is referring to is this, from the documentation of do_div:

Quoted 9 lines

* do_div - returns 2 values: calculate remainder and update new dividend
* @n: uint64_t dividend (will be updated)
* @base: uint32_t divisor
*
* Summary:
* ``uint32_t remainder = n % base;``
* ``n = n / base;``
*
* Return: (uint32_t)remainder

Quoted 6 lines

Oops, that was a serious brain fart. Sorry for that!

That should have been div_u64() instead of do_div().
Feel free to update my patch while applying, else I'll send a v2 later.

/me hides in a brown paper bag for the whole weekend...

I sent the patch with updated, change the reported tag, test it, and add more commit msg,
and author should be you. Thanks.

Quoted 10 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Signature · 1 line
Best regards, Tonghao