NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-powerpc/59386: t_spinlock test is failing



>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
>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@localhost:/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!



Home | Main Index | Thread Index | Old Index