NetBSD Problem Report #56829

From www@netbsd.org  Fri May 13 15:09:37 2022
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 66E6E1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 13 May 2022 15:09:37 +0000 (UTC)
Message-Id: <20220513150935.ABCBD1A923C@mollari.NetBSD.org>
Date: Fri, 13 May 2022 15:09:35 +0000 (UTC)
From: logix@foobar.franken.de
Reply-To: logix@foobar.franken.de
To: gnats-bugs@NetBSD.org
Subject: miniroot.fs no longer boots
X-Send-Pr-Version: www-1.0

>Number:         56829
>Category:       port-sparc64
>Synopsis:       miniroot.fs no longer boots
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sparc64-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 13 15:10:00 +0000 2022
>Closed-Date:    Sat May 14 10:06:25 +0000 2022
>Last-Modified:  Sat May 14 10:06:25 +0000 2022
>Originator:     Harold Gutch
>Release:        HEAD
>Organization:
>Environment:
QEMU 7.0.0 running on Fedora 33; issue also occurs on hardware (U60)
>Description:
Booting miniroot.fs both on hardware (by Björn Johannesson who originally pointed this out via IRC) and in QEMU results in:

NetBSD IEEE 1275 Multi-FS Bootblock
Version $NetBSD: bootblk.fth,v 1.16 2021/07/24 21:31:36 andvar Exp $
NetBSD/sparc64 OpenFirmware Boot, Revision 1.20 (Mon May  2 10:50:02 UTC 2022)
OF_map_phys(0xfe64000,40960,0xfef64000,-1) failed
alloc: out of memory
EXIT


This has been the case since the switch to gcc10 (Apr 17 2021).
>How-To-Repeat:
curl -s https://nycdn.netbsd.org/pub/NetBSD-daily/HEAD/latest/sparc64/installation/miniroot/miniroot.fs.gz | gzip -cd > miniroot.fs
qemu-system-sparc64 -nographic -m 128 -hda miniroot.fs -serial stdio -monitor none
>Fix:
It is sufficient to:
- EITHER build Locore.c with gcc9
  OR build Locore.c with gcc10 and -ON (with N < 2)
- link ofwboot (even with a post gcc10-switch toolchain)
- build miniroot.fs
to successfully boot.

Ultimately this is probably a compiler bug (introduced between gcc 9 and 10).  The following patch makes it also work, but so will also various other changes like initializing args.status with -1 and also printf() statements at various places.  In a similar spirit, removing lines 690/691 does NOT help (note that none of the other OF_* calls even checks status).

Until the actual bug is found and fixed, compiling Locore.c with -O1 (or -O0) is probably the best strategy.

diff -u src/src/sys/arch/sparc/stand/ofwboot/Locore.c Locore.c 
--- src/src/sys/arch/sparc/stand/ofwboot/Locore.c.old       2022-05-08 20:05:41.809070077 +0200
+++ src/src/sys/arch/sparc/stand/ofwboot/Locore.c    2022-05-13 13:16:07.292747887 +0200
@@ -684,6 +684,7 @@
        args.vaddr = ADR2CELL(vaddr);
        args.paddr_hi = HDQ2CELL_HI(paddr);
        args.paddr_lo = HDQ2CELL_LO(paddr);
+       args.status = 0;

        if (openfirmware(&args) == -1)
                return -1;

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-sparc64/56829: miniroot.fs no longer boots
Date: Fri, 13 May 2022 17:35:57 +0200

 Note: it works with real OF:

 SC Alert: Host System has Reset
 Probing system devices
 Probing memory
 Probing I/O buses

 Sun Fire V210, No Keyboard
 Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 OpenBoot 4.22.33, 4096 MB memory installed, Serial #54908397.
 Ethernet address 0:3:ba:45:d5:ed, Host ID: 8345d5ed.



 Rebooting with command: boot disk:b                                   
 Boot device: /pci@1c,600000/scsi@2/disk@0,0:b  File and args: 
 NetBSD IEEE 1275 Multi-FS Bootblock
 Version $NetBSD: bootblk.fth,v 1.16 2021/07/24 21:31:36 andvar Exp $
 >> NetBSD/sparc64 OpenFirmware Boot, Revision 1.20 (Thu May 12 18:47:29 UTC 2022)
 =0xc8d7b8
 Loading netbsd: 13162360+510776+334648 [744960+489214]=0xefc4e8
 [   1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
 [   1.0000000]     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 [   1.0000000]     2018, 2019, 2020, 2021, 2022
 [   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 9.99.96 (GENERIC) #0: Thu May 12 18:47:29 UTC 2022
 [   1.0000000]  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/sparc64/compile/GENERIC
 [...]

 Martin

From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@netbsd.org
Cc: port-sparc64-maintainer@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: port-sparc64/56829: miniroot.fs no longer boots
Date: Sat, 14 May 2022 06:38:57 +1000

 this appears to be a bad call to "map", in both ofwboot and the
 kernel itself.  Harold tested a change i suggested in ofwboot
 where the OF_map_phys() code was changed to not have any returns
 (the 1275 docs don't list any), and it works in qemu.

 for ofwboot, OF_map_phys() needs the "status" and "retaddr"
 members removed from the "args", and the "if (args.status)"
 code removed, and the success return value switched to 0,
 not args.retaddr.

 for the kernel, similar for prom_map_phys() is probably needed.


 .mrg.

From: "Harold Gutch" <hgutch@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56829 CVS commit: src/sys/arch
Date: Sat, 14 May 2022 07:11:23 +0000

 Module Name:	src
 Committed By:	hgutch
 Date:		Sat May 14 07:11:23 UTC 2022

 Modified Files:
 	src/sys/arch/sparc/stand/ofwboot: Locore.c
 	src/sys/arch/sparc64/sparc64: ofw_machdep.c

 Log Message:
 PR 56829: Fix "map" call to Open Firmware and no longer mess up OFW stack.
 This unbreaks miniroot.fs.

 Thanks to Björn Johannesson for originally pointing this out and to
 mrg@ for pointing out the actual issue and suggesting a fix.


 To generate a diff of this commit:
 cvs rdiff -u -r1.16 -r1.17 src/sys/arch/sparc/stand/ofwboot/Locore.c
 cvs rdiff -u -r1.50 -r1.51 src/sys/arch/sparc64/sparc64/ofw_machdep.c

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

State-Changed-From-To: open->closed
State-Changed-By: hgutch@NetBSD.org
State-Changed-When: Sat, 14 May 2022 10:06:25 +0000
State-Changed-Why:
Fixed in Qemu and hardware (confirmed by Björn Johannesson).


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.