Skip to contentSkip to conversation

ofnet: Fix incorrect mask for ppc64

PATCH In review Javier Martinez Canillas 2 participants 5 messages Oct 31, 2019 – Dec 13, 2019 1 message not in the archive Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ofnet: Fix incorrect mask for ppc64

From: Masahiro Matsuya <[email protected]>

The netmask configured in firmware is not respected on ppc64 (big endian). When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath().

/vdevice/l-lan@30000002:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512

The netmask in this bootpath is no problem, since it's a value specified in firmware. But, The value of 'subnet_mask.ipv4' was set with 0xfffffc00, and __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)) returned 16 (not 22). As a result, 16 was used for netmask wrongly.

1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) 1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32 (subnet_mask.ipv4)

And, the count of zero with __builtin_ctz can be 16. This patch changes it as below.

1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00)
0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) 1111 1111 1111 1111 1111 1100 0000 0000 # grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)) 0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))

The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit)

---

 grub-core/net/drivers/ieee1275/ofnet.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/drivers/ieee1275/ofnet.c +1 -2
index ac4e62a95c9..3860b6f78d8 100644
@@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
                                  flags);
       inter->vlantag = vlantag;
       grub_net_add_ipv4_local (inter,
-                          __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)));
-
+                          __builtin_clz (~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))));
     }
 
   if (gateway_addr.ipv4 != 0)
Signature · 1 line
2.21.0
#1 lore raw

Please don't chain swap_bytes32 with le_to_cpu32 as it's a less readable equivalent of be_to_cpu32

Quoted 69 lines · On Thu, 31 Oct 2019, 11:38 Javier Martinez Canillas, <[email protected]> wrote:

From: Masahiro Matsuya <[email protected]>

The netmask configured in firmware is not respected on ppc64 (big endian). When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath().

/vdevice/l-lan@30000002
:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512

The netmask in this bootpath is no problem, since it's a value specified in firmware. But, The value of 'subnet_mask.ipv4' was set with 0xfffffc00, and __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)) returned 16 (not 22).
As a result, 16 was used for netmask wrongly.

1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4)
1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32 (subnet_mask.ipv4)

And, the count of zero with __builtin_ctz can be 16. This patch changes it as below.

1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4)
1111 1111 1111 1111 1111 1100 0000 0000 # grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))
0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))

The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit)

---

 grub-core/net/drivers/ieee1275/ofnet.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
(quoted diff) +0 -0

grub-core/net/drivers/ieee1275/ofnet.c
index ac4e62a95c9..3860b6f78d8 100644

net/drivers/ieee1275/ofnet.c +1 -2
@@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath,
 char *bootpath,
                                  flags);
       inter->vlantag = vlantag;
       grub_net_add_ipv4_local (inter,
-                          __builtin_ctz (~grub_le_to_cpu32
 (subnet_mask.ipv4)));
-
+                          __builtin_clz
 (~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))));
     }
   if (gateway_addr.ipv4 != 0)

--
2.21.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw

Hello Vladimir,

Thanks a lot for your feedback.

Quoted 3 lines · Vladimir 'phcoder' Serbinenko

Please don't chain swap_bytes32 with le_to_cpu32 as it's a less readable equivalent of be_to_cpu32

That's correct. In fact I think that the patch is wrong and what we should do is just to drop the grub_le_to_cpu32() instead. I'll get access to a ppc64le machine to test and post a v2 doing that.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat

A message that is not in the archive (sent off-list or not yet received): CAEaD8JM72huEttkCkM1-NWpkYkEEwQM8aLGhj6PSzd90Df-KCg@mail.gmail.com

#4 lore raw

PATCH 1/1 ofnet: Fix incorrect mask for ppc64

---------- Forwarded message ---------
From: Vladimir 'phcoder' Serbinenko <[email protected]>
Date: Fri, 13 Dec 2019, 15:56
Subject: Re: [PATCH] ofnet: Fix incorrect mask for ppc64
To: Javier Martinez Canillas <[email protected]>

Quoted 4 lines · On Fri, 13 Dec 2019, 15:33 Javier Martinez Canillas, <[email protected]> wrote:

Hello Vladimir,

Thanks a lot for your feedback.

Quoted 9 lines
Quoted 3 lines · Vladimir 'phcoder' Serbinenko

Please don't chain swap_bytes32 with le_to_cpu32 as it's a less readable equivalent of be_to_cpu32

That's correct. In fact I think that the patch is wrong and what we should do is just to drop the grub_le_to_cpu32() instead. I'll get access to a ppc64le machine to test and post a v2 doing that.

ppc64le machine boots in big-endian mode. The only supported architecture with BE OFW is i386-ieee1275 but I'm not even sure there are i386-ieee1275 machines with ofnet.

Quoted 8 lines

Best regards,
--
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat

#5 lore raw
Quoted 22 lines · On Fri, 13 Dec 2019, 15:56 Vladimir 'phcoder' Serbinenko, <[email protected]>…

---------- Forwarded message ---------
From: Vladimir 'phcoder' Serbinenko <[email protected]>
Date: Fri, 13 Dec 2019, 15:56
Subject: Re: [PATCH] ofnet: Fix incorrect mask for ppc64
To: Javier Martinez Canillas <[email protected]>

Quoted 9 lines · On Fri, 13 Dec 2019, 15:33 Javier Martinez Canillas, <[email protected]> wrote:

Hello Vladimir,

Thanks a lot for your feedback.

Quoted 3 lines · Vladimir 'phcoder' Serbinenko

Please don't chain swap_bytes32 with le_to_cpu32 as it's a less readable equivalent of be_to_cpu32

Quoted 8 lines
Quoted 4 lines

That's correct. In fact I think that the patch is wrong and what we should do is just to drop the grub_le_to_cpu32() instead. I'll get access to a ppc64le machine to test and post a v2 doing that.

ppc64le machine boots in big-endian mode. The only supported architecture with BE OFW is i386-ieee1275 but I'm not even sure there are i386-ieee1275 machines with ofnet.

I mean LE OFW. Given that IP addresses are generally stored in BE order, I think be_to_cpu32 is reasonable but probably no machine is impacted either way.
Maybe some qemu config could have i386-ieee1275 with ofnet but generally i386-ieee1275 is dead target

Quoted 8 lines
Quoted 8 lines

Best regards,
--
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat