Skip to contentSkip to conversation

ofnet: Fix incorrect mask for ppc64

PATCH New Robbie Harwood 2 participants 3 messages Aug 24, 2022 – Sep 22, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover ofnet: Fix incorrect mask for ppc64

Changes in this version:

- Replaced changed swap_bytes32(le_to_cpu32()) with be_to_cpu32().

Please note that I'm not an expert on this platform and can only perform very basic testing there. However, this patch is functionally the same as one we've been carrying downstream since late 2016 without issue.

Be well,
--Robbie

Masahiro Matsuya (1):
net/drivers/ieee1275/ofnet: fix incorrect netmask

 grub-core/net/drivers/ieee1275/ofnet.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 1/1 net/drivers/ieee1275/ofnet: fix incorrect netmask

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_be_to_cpu32 (subnet_mask.ipv4) 0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_be_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(-)
grub-core/net/drivers/ieee1275/ofnet.c +1 -2
index 8c8398948b..78f03df8e2 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_be_to_cpu32 (subnet_mask.ipv4)));
     }
 
   if (gateway_addr.ipv4 != 0)
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2] net/drivers/ieee1275/ofnet: fix incorrect netmask

Quoted 26 lines · Robbie Harwood

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_be_to_cpu32 (subnet_mask.ipv4) 0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_be_to_cpu32 (subnet_mask.ipv4)

Quoted 5 lines

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

Daniel