From nobody@FreeBSD.org  Wed Nov 13 13:25:20 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 0B6784AE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Nov 2013 13:25:20 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id EFCE1219C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Nov 2013 13:25:19 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id rADDPJJ9077364
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Nov 2013 13:25:19 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id rADDPJKL077353;
	Wed, 13 Nov 2013 13:25:19 GMT
	(envelope-from nobody)
Message-Id: <201311131325.rADDPJKL077353@oldred.freebsd.org>
Date: Wed, 13 Nov 2013 13:25:19 GMT
From: Howard Su <howard0su@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Crash when ctrl-c while process is enter 
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         183926
>Category:       arm
>Synopsis:       Crash when ctrl-c while process is enter
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-arm
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 13 13:30:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Wed Nov 20 00:50:00 UTC 2013
>Originator:     Howard Su
>Release:        -Current
>Organization:
>Environment:
FreeBSD beaglebone 11.0-CURRENT FreeBSD 11.0-CURRENT #9 42a79a9(dtrace_arm)-dirty: Tue Nov 12 21:56:17 CST 2013     howardsu@FreeBSD:/usr/home/howardsu/usr/obj/arm.armv6/usr/home/howardsu/usr/freebsd/sys/BEAGLEBONE  arm

>Description:
consistent repro a crash related signal deliver and mutex/cond operation in arm platform.

I notice this when I was play with dtrace arm port from gonozo. the _sleep function is a simpler version of dtrace_sleep in libdtrace. In case you need a real case, please refer that file @ cddl/contrib/opensolaris/lib/libdtrace/dt_work.c.
>How-To-Repeat:
Compile and run the attached C code.

Press Ctrl-C when shows "enter".

>Fix:


Patch attached with submission follows:

#include <stdio.h>
#include <pthread.h>
#include <signal.h>

pthread_cond_t cv;
pthread_mutex_t lock;
pthread_condattr_t ca;
pthread_mutexattr_t ma;

int done = 0;

void _sleep()
{
	struct timespec tv;

	clock_gettime(CLOCK_REALTIME,&tv);
	tv.tv_sec += 1;
	tv.tv_nsec = 0;

	(void) pthread_mutex_lock(&lock);
	(void) pthread_cond_timedwait(&cv, &lock, &tv);
	(void) pthread_mutex_unlock(&lock);
}

static void
intr(int signo)
{
	done++;
}


int main()
{
	struct sigaction act;

	pthread_condattr_init(&ca);
	pthread_mutexattr_init(&ma);
	pthread_mutex_init(&lock, &ma);
	pthread_cond_init(&cv, &ca);


	(void) sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = intr;

	(void) sigaction(SIGINT, &act, NULL);

	while(!done)
	{
		printf("enter\n");
		_sleep();
		printf("exit\n");
	}

	printf("done\n");
	return 0;
}


>Release-Note:
>Audit-Trail:

From: Howard Su <howard0su@gmail.com>
To: bug-followup@FreeBSD.org, howard0su@gmail.com
Cc:  
Subject: Re: arm/183926: Crash when ctrl-c while process is enter
Date: Thu, 14 Nov 2013 09:14:20 +0800

 --001a11c1e2102caa3d04eb18cd9b
 Content-Type: text/plain; charset=ISO-8859-1
 
 The following change make problem goes away.
 
 index 252d780..c7c44a9 100644
 --- a/sys/arm/conf/BEAGLEBONE
 +++ b/sys/arm/conf/BEAGLEBONE
 @@ -59,9 +59,9 @@ options       KDB
  options        DDB                     #Enable the kernel debugger
  options        INVARIANTS              #Enable calls of extra sanity
 checking
  options        INVARIANT_SUPPORT       #Extra sanity checks of internal
 structures, required by INVARIANTS
 -options        WITNESS                 #Enable checks to detect deadlocks
 and cycles
 -options        WITNESS_SKIPSPIN        #Don't run witness on spinlocks for
 speed
 -#options       DIAGNOSTIC
 +#options       WITNESS                 #Enable checks to detect deadlocks
 and cycles
 +#options       WITNESS_SKIPSPIN        #Don't run witness on spinlocks for
 speed
 +options        DIAGNOSTIC
 
 
 -- 
 -Howard
 
 --001a11c1e2102caa3d04eb18cd9b
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 <div dir=3D"ltr">The following change make problem goes away.<br><br>index =
 252d780..c7c44a9 100644<br>--- a/sys/arm/conf/BEAGLEBONE<br>+++ b/sys/arm/c=
 onf/BEAGLEBONE<br>@@ -59,9 +59,9 @@ options=A0=A0=A0=A0=A0=A0 KDB<br>=A0opt=
 ions=A0=A0=A0=A0=A0=A0=A0 DDB=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
 =A0=A0=A0=A0=A0 #Enable the kernel debugger<br>
 =A0options=A0=A0=A0=A0=A0=A0=A0 INVARIANTS=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
 =A0=A0 #Enable calls of extra sanity checking<br>=A0options=A0=A0=A0=A0=A0=
 =A0=A0 INVARIANT_SUPPORT=A0=A0=A0=A0=A0=A0 #Extra sanity checks of internal=
  structures, required by INVARIANTS<br>-options=A0=A0=A0=A0=A0=A0=A0 WITNES=
 S=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #Enable checks to detect =
 deadlocks and cycles<br>
 -options=A0=A0=A0=A0=A0=A0=A0 WITNESS_SKIPSPIN=A0=A0=A0=A0=A0=A0=A0 #Don&#3=
 9;t run witness on spinlocks for speed<br>-#options=A0=A0=A0=A0=A0=A0 DIAGN=
 OSTIC<br>+#options=A0=A0=A0=A0=A0=A0 WITNESS=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
 =A0=A0=A0=A0=A0=A0 #Enable checks to detect deadlocks and cycles<br>+#optio=
 ns=A0=A0=A0=A0=A0=A0 WITNESS_SKIPSPIN=A0=A0=A0=A0=A0=A0=A0 #Don&#39;t run w=
 itness on spinlocks for speed<br>
 +options=A0=A0=A0=A0=A0=A0=A0 DIAGNOSTIC<br><br clear=3D"all"><br>-- <br>-H=
 oward
 </div>
 
 --001a11c1e2102caa3d04eb18cd9b--

From: Howard Su <howard0su@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: arm/183926: Crash when ctrl-c while process is enter
Date: Wed, 20 Nov 2013 08:42:24 +0800

 --001a11343d08fbe31b04eb910db8
 Content-Type: text/plain; charset=ISO-8859-1
 
 it was an artifact of experimental code. This is confirmed by me and
 Ian@so that this is not able to reproduce in stock kernel.
 
 -- 
 -Howard
 
 --001a11343d08fbe31b04eb910db8
 Content-Type: text/html; charset=ISO-8859-1
 
 it was an artifact of experimental code. This is confirmed by me and Ian@ so that this is not able to reproduce in stock kernel.<br><br>-- <br>-Howard<br>
 
 --001a11343d08fbe31b04eb910db8--
>Unformatted:
