NetBSD Problem Report #59386

From www@netbsd.org  Fri May  2 22:07:21 2025
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)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id CE4321A9239
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  2 May 2025 22:07:21 +0000 (UTC)
Message-Id: <20250502220720.106851A923C@mollari.NetBSD.org>
Date: Fri,  2 May 2025 22:07:20 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: t_spinlock test is failing
X-Send-Pr-Version: www-1.0

>Number:         59386
>Category:       port-powerpc
>Synopsis:       t_spinlock test is failing
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-powerpc-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 02 22:10:00 +0000 2025
>Last-Modified:  Sat May 03 05:00:02 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The PowerBSD Spinners, Lkd
>Environment:
NetBSD 10.99.14 (GETHSEMANE) #400: Tue Apr 29 11:59:02 CEST 2025 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/macppc/compile/GETHSEMANE
>Description:
Test failure on real powerpc hardware, not a qemu imitation thereof:

*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 0: 6685976 != 3424027 + 3262072 (off by 123)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 1: 6685969 != 3424027 + 3262072 (off by 130)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 2: 6685977 != 3424027 + 3262072 (off by 122)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 3: 6685978 != 3424027 + 3262072 (off by 121)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 4: 6685980 != 3424027 + 3262072 (off by 119)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 5: 6686029 != 3424027 + 3262072 (off by 70)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 6: 6686081 != 3424027 + 3262072 (off by 18)
*** Check failed: /work/src/tests/lib/libc/membar/t_spinlock.c:147: 7: 6686087 != 3424027 + 3262072 (off by 12)

https://www.netbsd.org/~martin/macppc-atf/246_atf.html#lib_libc_membar_t_spinlock_spinlock

Relevant code:

     67 static void
     68 lock(void)
     69 {
     70 
     71 	while (atomic_swap_uint(&lockbit, 1))
     72 		continue;
     73 	membar_acquire();
     74 }
     75 
     76 static void
     77 unlock(void)
     78 {
     79 
     80 	membar_release();
     81 #ifdef __HAVE_HASHLOCKED_ATOMICS
     82 	(void)atomic_cas_uint(&lockbit, 1, 0);
     83 #else
     84 	lockbit = 0;
     85 #endif
     86 }
     87 
     88 static void *
     89 thread(void *cookie)
     90 {
     91 	unsigned me = (unsigned)(uintptr_t)cookie;
     92 	uint64_t C_local = 0, C0[__arraycount(C)];
     93 	unsigned i;
     94 
     95 	while (!times_up) {
     96 		C_local++;
     97 		lock();
     98 		for (i = 0; i < __arraycount(C); i++)
     99 			C0[i] = C[i].v;
    100 		__insn_barrier();
    101 		for (i = __arraycount(C); i --> 0;)
    102 			C[i].v = C0[i] + 1;
    103 		unlock();
    104 	}
    105 
    106 	TC[me] = C_local;
    107 
    108 	return NULL;
    109 }

https://nxr.netbsd.org/xref/src/tests/lib/libc/membar/t_spinlock.c?r=1.4#67

     38 ENTRY(_membar_acquire)
     39 	/*
     40 	 * It is tempting to use isync to order load-before-load/store.
...
     87 	 * lwsync orders everything except store-before-load, so it
     88 	 * serves here -- see below in membar_release in lwsync.
     89 	 * Except we can't use it on booke, so use sync for now.
     90 	 */
     91 	sync
     92 	blr
     93 END(_membar_acquire)
     94 ATOMIC_OP_ALIAS(membar_acquire,_membar_acquire)
     95 
     96 ENTRY(_membar_release)
     97 	/*
...
    114 	 * In brief, lwsync is an acquire-release barrier -- it orders
    115 	 * load-before-load/store and load/store-before-store, but not
    116 	 * store-before-load.  Except we can't use it on booke, so use
    117 	 * sync for now.
    118 	 */
    119 	sync
    120 	blr
    121 END(_membar_release)
    122 ATOMIC_OP_ALIAS(membar_release,_membar_release)

https://nxr.netbsd.org/xref/src/common/lib/libc/arch/powerpc/atomic/membar_ops.S?r=1.6#38

     37 ENTRY(_atomic_swap_32)
     38 	mr	%r10,%r3
     39 1:	lwarx	%r3,0,%r10
     40 	IBM405_ERRATA77_DCBT(0,%r10)
     41 	stwcx.	%r4,0,%r10
     42 	beqlr+
     43 	b	1b
     44 END(_atomic_swap_32)
     45 ATOMIC_OP_ALIAS(atomic_swap_32,_atomic_swap_32)
     46 
     47 ATOMIC_OP_ALIAS(atomic_swap_uint,_atomic_swap_32)
     48 STRONG_ALIAS(_atomic_swap_uint,_atomic_swap_32)

https://nxr.netbsd.org/xref/src/common/lib/libc/arch/powerpc/atomic/atomic_swap.S?r=1.9#37

I don't see any shenanigans on powerpc with a uniprocessor alternative in case, e.g., we missed a _libc_init, like we had on sparc with rtld for a while.
>How-To-Repeat:
cd /usr/tests/lib/libc/membar
atf-run t_spinlock | atf-report
>Fix:
Yes, please!

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59386 CVS commit: src/tests/lib/libc/membar
Date: Fri, 2 May 2025 22:30:44 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri May  2 22:30:44 UTC 2025

 Modified Files:
 	src/tests/lib/libc/membar: t_spinlock.c

 Log Message:
 t_spinlock: Mark this xfail on powerpc.

 Not sure under exactly what circumstances it fails -- possible it's
 only a subset of powerpc CPUs, dunno yet.

 PR port-powerpc/59386: t_spinlock test is failing


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/membar/t_spinlock.c

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

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: PR/59386 CVS commit: src/tests/lib/libc/membar
Date: Sat, 3 May 2025 06:57:07 +0200

 On Fri, May 02, 2025 at 10:35:02PM +0000, Taylor R Campbell wrote:
 >  Not sure under exactly what circumstances it fails -- possible it's
 >  only a subset of powerpc CPUs, dunno yet.

 It is also possible that this particular hardware has some issues, I have
 been unable to reproduce it on e.g. a G5 powermac.

 Martin

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-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.