NetBSD Problem Report #57394

From www@netbsd.org  Sat May  6 22:04:41 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 202781A923A
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  6 May 2023 22:04:41 +0000 (UTC)
Message-Id: <20230506220439.6C4901A923D@mollari.NetBSD.org>
Date: Sat,  6 May 2023 22:04:39 +0000 (UTC)
From: nullnilaki@gmail.com
Reply-To: nullnilaki@gmail.com
To: gnats-bugs@NetBSD.org
Subject: CPU unable to attach mainbus on NetBSD 10.0_BETA(Current?) on Power Macintosh 9600(G2)
X-Send-Pr-Version: www-1.0

>Number:         57394
>Category:       port-macppc
>Synopsis:       CPU unable to attach mainbus on NetBSD 10.0_BETA(Current?) on Power Macintosh 9600(G2)
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    port-macppc-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat May 06 22:05:00 +0000 2023
>Last-Modified:  Tue May 09 10:55:01 +0000 2023
>Originator:     Naruaki Etomi
>Release:        NetBSD 10.0_BETA
>Organization:
>Environment:
# uname -a
NetBSD  10.0_BETA NetBSD 10.0_BETA (GENERIC) #12: Sat May  6 21:41:55 UTC 2023  naruaki@localhost:/usr/obj.macppc/sys/arch/macppc/compile/GENERIC macppc
>Description:
OF_finddevice("/cpus") function return -1 on G2 Mac... 
https://nxr.netbsd.org/xref/src/sys/arch/macppc/macppc/mainbus.c?r=1.25#78

---------------------------------------------------------------------------------------------

>> NetBSD/macppc OpenFirmware Boot, Revision 1.13 (Thu Aug  4 15:30:37 UTC 2022)
no active packageno active package11764700+167212 [485280+462037]=0xc48ae0
 start=0x100000
[   1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
[   1.0000000]     2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
[   1.0000000]     2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023
[   1.0000000]     The NetBSD Foundation, Inc.  All rights reserved.
[   1.0000000] Copyright (c) 1982, 1986, 1989, 1991, 1993
[   1.0000000]     The Regents of the University of California.  All rights reserved.

[   1.0000000] NetBSD 10.0_BETA (GENERIC) #11: Sat May  6 21:22:58 UTC 2023
[   1.0000000] 	naruaki@localhost:/usr/obj.macppc/sys/arch/macppc/compile/GENERIC
[   1.0000000] total memory = 98304 KB
[   1.0000000] avail memory = 81412 KB
[   1.0000000] found Grand Central PIC at f3000000
[   1.0000000] bootpath: scsi/sd@0/netbsd
[   1.0000000] mainbus0 (root)
[   1.0000000] memory0 at mainbus0
[   1.0000000] bandit0 at mainbus0

>How-To-Repeat:
Boot  NetBSD 10.0_BETA on G2 Mac
>Fix:
diff -Naru macppc.orig/mainbus.c macppc/mainbus.c
--- macppc.orig/mainbus.c       2023-05-06 21:29:45.203239936 +0000
+++ macppc/mainbus.c    2023-05-06 21:37:04.495657936 +0000
@@ -76,7 +76,7 @@
        devhandle_t selfh = device_handle(self);

        cpus = OF_finddevice("/cpus");
-       if (cpus != 0) {
+       if (cpus > 0) {
                node = OF_child(cpus);
                while (node != 0) {
                        ca.ca_name = "cpu";

---------------------------------------------------------------------------------------------

>> NetBSD/macppc OpenFirmware Boot, Revision 1.13 (Thu Aug  4 15:30:37 UTC 2022)
no active packageno active package11764700+167212 [485280+462037]=0xc48ae0
 start=0x100000
[   1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
[   1.0000000]     2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
[   1.0000000]     2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023
[   1.0000000]     The NetBSD Foundation, Inc.  All rights reserved.
[   1.0000000] Copyright (c) 1982, 1986, 1989, 1991, 1993
[   1.0000000]     The Regents of the University of California.  All rights reserved.

[   1.0000000] NetBSD 10.0_BETA (GENERIC) #12: Sat May  6 21:41:55 UTC 2023
[   1.0000000] 	naruaki@localhost:/usr/obj.macppc/sys/arch/macppc/compile/GENERIC
[   1.0000000] total memory = 98304 KB
[   1.0000000] avail memory = 81412 KB
[   1.0000000] found Grand Central PIC at f3000000
[   1.0000000] bootpath: scsi/sd@0/netbsd
[   1.0000000] mainbus0 (root)
[   1.0000000] cpu0 at mainbus0: 604e (Revision 2.2), ID 0 (primary)
[   1.0000000] cpu0: HID0 0x8000c084<EMCP,ICE,DCE,SGE,BHT>, powersave: 1
[   1.0000000] cpu0: 200.00 MHz
[   1.0000000] cpu1 at mainbus0: ID 1
[   1.0000000] cpu1: processor off-line; multiprocessor support not present in kernel
[   1.0000000] memory0 at mainbus0
[   1.0000000] bandit0 at mainbus0
[   1.0000000] pci0 at bandit0 bus 0
[   1.0000000] pchb0 at pci0 dev 11 function 0

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-macppc/57394: CPU unable to attach mainbus on NetBSD
 10.0_BETA(Current?) on Power Macintosh 9600(G2)
Date: Sun, 7 May 2023 09:51:44 +0200

 On Sat, May 06, 2023 at 10:05:00PM +0000, nullnilaki@gmail.com wrote:

 > OF_finddevice("/cpus") function return -1 on G2 Mac... 

 -1 is the expected error message everwhere, and != 0 is just a bogus
 test. Furthermore the sign of the handle should not matter, so > 0 is
 clearly wrong.

 The test should be != -1, see
 https://nxr.netbsd.org/xref/src/sys/arch/powerpc/powerpc/openfirm.c#345

 Martin

From: Michael <macallan1888@gmail.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-macppc/57394: CPU unable to attach mainbus on NetBSD
 10.0_BETA(Current?) on Power Macintosh 9600(G2)
Date: Tue, 9 May 2023 04:50:22 -0400

 >  > OF_finddevice("/cpus") function return -1 on G2 Mac...   
 >  
 >  -1 is the expected error message everwhere, and != 0 is just a bogus
 >  test. Furthermore the sign of the handle should not matter, so > 0 is
 >  clearly wrong.
 >  
 >  The test should be != -1, see
 >  https://nxr.netbsd.org/xref/src/sys/arch/powerpc/powerpc/openfirm.c#345

 I dimly remember some Apple OF variants returning 0 on (some) errors,
 there was a reason why checks for 0 or -1 are littered all over the
 place other than my forgetfulness.
 Time to check on my oddball collection, I'd expect something like that
 to pop in one of the 2.0x variants.

 have fun
 Michael


From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: port-macppc-maintainer@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org, nullnilaki@gmail.com
Subject: Re: port-macppc/57394: CPU unable to attach mainbus on NetBSD
 10.0_BETA(Current?) on Power Macintosh 9600(G2)
Date: Tue, 9 May 2023 11:24:10 +0200

 On Tue, May 09, 2023 at 08:55:01AM +0000, Michael wrote:
 >  >  The test should be != -1, see
 >  >  https://nxr.netbsd.org/xref/src/sys/arch/powerpc/powerpc/openfirm.c#345
 >  
 >  I dimly remember some Apple OF variants returning 0 on (some) errors,
 >  there was a reason why checks for 0 or -1 are littered all over the
 >  place other than my forgetfulness.

 OK, in that case (the OF call works but returns 0) we need to check for
 both -1 and 0 here.

 Martin

From: "Michael Lorenz" <macallan@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57394 CVS commit: src/sys/arch/macppc/macppc
Date: Tue, 9 May 2023 10:49:47 +0000

 Module Name:	src
 Committed By:	macallan
 Date:		Tue May  9 10:49:47 UTC 2023

 Modified Files:
 	src/sys/arch/macppc/macppc: mainbus.c

 Log Message:
 check for proper error value from OF_finddevice()
 should fix PR57394


 To generate a diff of this commit:
 cvs rdiff -u -r1.25 -r1.26 src/sys/arch/macppc/macppc/mainbus.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.