All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ofnet: Fix incorrect mask for ppc64
@ 2019-10-31 10:34 Javier Martinez Canillas
  2019-10-31 11:58 ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Javier Martinez Canillas @ 2019-10-31 10:34 UTC (permalink / raw)
  To: grub-devel; +Cc: Masahiro Matsuya, Javier Martinez Canillas

From: Masahiro Matsuya <mmatsuya@redhat.com>

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)

Signed-off-by: Masahiro Matsuya <mmatsuya@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---

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

diff --git grub-core/net/drivers/ieee1275/ofnet.c grub-core/net/drivers/ieee1275/ofnet.c
index ac4e62a95c9..3860b6f78d8 100644
--- grub-core/net/drivers/ieee1275/ofnet.c
+++ grub-core/net/drivers/ieee1275/ofnet.c
@@ -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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ofnet: Fix incorrect mask for ppc64
  2019-10-31 10:34 [PATCH] ofnet: Fix incorrect mask for ppc64 Javier Martinez Canillas
@ 2019-10-31 11:58 ` Vladimir 'phcoder' Serbinenko
  2019-12-13 14:33   ` Javier Martinez Canillas
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2019-10-31 11:58 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 2746 bytes --]

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

On Thu, 31 Oct 2019, 11:38 Javier Martinez Canillas, <javierm@redhat.com>
wrote:

> From: Masahiro Matsuya <mmatsuya@redhat.com>
>
> 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)
>
> Signed-off-by: Masahiro Matsuya <mmatsuya@redhat.com>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
>
>  grub-core/net/drivers/ieee1275/ofnet.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git grub-core/net/drivers/ieee1275/ofnet.c
> grub-core/net/drivers/ieee1275/ofnet.c
> index ac4e62a95c9..3860b6f78d8 100644
> --- grub-core/net/drivers/ieee1275/ofnet.c
> +++ grub-core/net/drivers/ieee1275/ofnet.c
> @@ -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
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 3668 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ofnet: Fix incorrect mask for ppc64
  2019-10-31 11:58 ` Vladimir 'phcoder' Serbinenko
@ 2019-12-13 14:33   ` Javier Martinez Canillas
       [not found]     ` <CAEaD8JM72huEttkCkM1-NWpkYkEEwQM8aLGhj6PSzd90Df-KCg@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Javier Martinez Canillas @ 2019-12-13 14:33 UTC (permalink / raw)
  To: The development of GNU GRUB, Vladimir 'phcoder' Serbinenko

Hello Vladimir,

Thanks a lot for your feedback.

On 10/31/19 12:58 PM, Vladimir 'phcoder' Serbinenko wrote:
> 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,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Fwd: [PATCH] ofnet: Fix incorrect mask for ppc64
       [not found]     ` <CAEaD8JM72huEttkCkM1-NWpkYkEEwQM8aLGhj6PSzd90Df-KCg@mail.gmail.com>
@ 2019-12-13 14:56       ` Vladimir 'phcoder' Serbinenko
  2019-12-13 14:59         ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2019-12-13 14:56 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]

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




On Fri, 13 Dec 2019, 15:33 Javier Martinez Canillas, <javierm@redhat.com>
wrote:

> Hello Vladimir,
>
> Thanks a lot for your feedback.
>
> On 10/31/19 12:58 PM, Vladimir 'phcoder' Serbinenko wrote:
> > 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.

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

[-- Attachment #2: Type: text/html, Size: 1928 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ofnet: Fix incorrect mask for ppc64
  2019-12-13 14:56       ` Fwd: " Vladimir 'phcoder' Serbinenko
@ 2019-12-13 14:59         ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2019-12-13 14:59 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1430 bytes --]

On Fri, 13 Dec 2019, 15:56 Vladimir 'phcoder' Serbinenko, <phcoder@gmail.com>
wrote:

>
> ---------- Forwarded message ---------
> From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
> Date: Fri, 13 Dec 2019, 15:56
> Subject: Re: [PATCH] ofnet: Fix incorrect mask for ppc64
> To: Javier Martinez Canillas <javierm@redhat.com>
>
>
>
>
> On Fri, 13 Dec 2019, 15:33 Javier Martinez Canillas, <javierm@redhat.com>
> wrote:
>
>> Hello Vladimir,
>>
>> Thanks a lot for your feedback.
>>
>> On 10/31/19 12:58 PM, Vladimir 'phcoder' Serbinenko wrote:
>> > 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.
>
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

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

[-- Attachment #2: Type: text/html, Size: 2895 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-13 14:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 10:34 [PATCH] ofnet: Fix incorrect mask for ppc64 Javier Martinez Canillas
2019-10-31 11:58 ` Vladimir 'phcoder' Serbinenko
2019-12-13 14:33   ` Javier Martinez Canillas
     [not found]     ` <CAEaD8JM72huEttkCkM1-NWpkYkEEwQM8aLGhj6PSzd90Df-KCg@mail.gmail.com>
2019-12-13 14:56       ` Fwd: " Vladimir 'phcoder' Serbinenko
2019-12-13 14:59         ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.