Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iQ7nD-0003f5-Hj for mharc-grub-devel@gnu.org; Thu, 31 Oct 2019 06:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42390) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQ7n8-0003XL-NP for grub-devel@gnu.org; Thu, 31 Oct 2019 06:34:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQ7n6-00011f-Tc for grub-devel@gnu.org; Thu, 31 Oct 2019 06:34:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52698) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iQ7n6-00010e-Kz for grub-devel@gnu.org; Thu, 31 Oct 2019 06:34:56 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C07EA81105 for ; Thu, 31 Oct 2019 10:34:55 +0000 (UTC) Received: by mail-wm1-f69.google.com with SMTP id z5so1776190wma.5 for ; Thu, 31 Oct 2019 03:34:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tBOzriQO2bXchBJuVs6mKaZD8NEjpNBHELxgT5zfn5U=; b=jOuUp40hyYFTqWixbgRV9FCP8r36+lSbzFGSaOgLuc5HBmjHIg1xNiCsxHHn7t3k8A 1PpeqOUQiAprfCC1UpYym7E19ZtTfwPoygiyk2I7pgmOr0yUp4D+rW3z0Nof/Ye1disW amoWe8ZKwIrx3kZvORMQgFnk7YxrTAhR5PxiovkhK5Lq0iKyy815dqDnlr3Yv3jH+rGE L8sOq6hiSe59kpUQyLHBOwMAl01Silaa/lLkxn0HcfgL4t5hNCDUhrr3qYdeXcNNVoJU Jx5BOr3FWIBaTRPqbAvHbf0wQVD9kcM91FJ7tcbfkO4kNvhpeLCR3QSu2xKxvoQeRSN1 SaHA== X-Gm-Message-State: APjAAAWyY1RB9nDcZ9enCiWlUljji5JnWeQ3ZUerZ01E7jHv3N+sSOVY MOXC6NHcXGBCbAZ1FCY7lXNv7ax8WzWw85QVFkks7Ins0xRMdjtAfhfdcGPtjcs8kbV7hlx+ryr nJThZSbulQ9s= X-Received: by 2002:a1c:9c82:: with SMTP id f124mr4711151wme.25.1572518094272; Thu, 31 Oct 2019 03:34:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgvbA3AxRzJuinzMMB95Ua0QkBDXnvOTbKmat+tED94bt34bpYRGPlj614iN1xnyVQZZx+Fw== X-Received: by 2002:a1c:9c82:: with SMTP id f124mr4711127wme.25.1572518094040; Thu, 31 Oct 2019 03:34:54 -0700 (PDT) Received: from minerva.redhat.com ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id e9sm3428562wrr.13.2019.10.31.03.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 03:34:53 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Masahiro Matsuya , Javier Martinez Canillas Subject: [PATCH] ofnet: Fix incorrect mask for ppc64 Date: Thu, 31 Oct 2019 11:34:50 +0100 Message-Id: <20191031103450.3436-1-javierm@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Oct 2019 10:35:01 -0000 From: Masahiro Matsuya 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=3Dauto,duplex=3Dauto,192.168.88.10,,192.16= 8.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 (=3D0xfffffc00= ) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.i= pv4) 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 (=3D0xfffffc00= ) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.i= pv4) 1111 1111 1111 1111 1111 1100 0000 0000 # grub_swap_bytes32(grub_le_to_cp= u32 (subnet_mask.ipv4)) 0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_c= pu32 (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 Signed-off-by: Javier Martinez Canillas --- 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/i= eee1275/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, ch= ar *bootpath, flags); inter->vlantag =3D vlantag; grub_net_add_ipv4_local (inter, - __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.= ipv4))); - + __builtin_clz (~grub_swap_bytes32(grub_le_to_c= pu32 (subnet_mask.ipv4)))); } =20 if (gateway_addr.ipv4 !=3D 0) --=20 2.21.0