CVS commit: src/tests/lib/libc/sys

2018-05-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May 16 03:52:35 UTC 2018

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add extra asserts in three ATF ptrace(2) tests

In traceme* tests after validate_status_stopped() include additional check
the verify the received signal with PT_GET_SIGINFO.

All tests passes.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/tests/lib/libc/sys/t_ptrace_wait.c

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.44 src/tests/lib/libc/sys/t_ptrace_wait.c:1.45
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.44	Wed May 16 03:18:38 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May 16 03:52:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.44 2018/05/16 03:18:38 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.45 2018/05/16 03:52:35 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.44 2018/05/16 03:18:38 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.45 2018/05/16 03:52:35 kamil Exp $");
 
 #include 
 #include 
@@ -93,6 +93,9 @@ traceme_raise(int sigval)
 	int status;
 #endif
 
+	struct ptrace_siginfo info;
+	memset(&info, 0, sizeof(info));
+
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -123,6 +126,20 @@ traceme_raise(int sigval)
 	default:
 		validate_status_stopped(status, sigval);
 
+		DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for "
+		"child\n");
+		SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info,
+		   sizeof(info)) != -1);
+
+		DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+		DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
+		"si_errno=%#x\n",
+		info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
+		info.psi_siginfo.si_errno);
+
+		ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
+		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
+
 		DPRINTF("Before resuming the child process where it left off "
 		"and without signal to be sent\n");
 		SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
@@ -170,6 +187,9 @@ traceme_sighandler_catch(int sigsent, vo
 	int status;
 #endif
 
+	struct ptrace_siginfo info;
+	memset(&info, 0, sizeof(info));
+
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -197,6 +217,18 @@ traceme_sighandler_catch(int sigsent, vo
 
 	validate_status_stopped(status, sigval);
 
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info))
+	!= -1);
+
+	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
+	info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
+	info.psi_siginfo.si_errno);
+
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
+
 	DPRINTF("Before resuming the child process where it left off and with "
 	"signal %s to be sent\n", strsignal(sigsent));
 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
@@ -253,6 +285,9 @@ traceme_signal_nohandler(int sigsent)
 	int expect_core = (sigsent == SIGABRT) ? 1 : 0;
 #endif
 
+	struct ptrace_siginfo info;
+	memset(&info, 0, sizeof(info));
+
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -277,6 +312,18 @@ traceme_signal_nohandler(int sigsent)
 
 	validate_status_stopped(status, sigval);
 
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info))
+	!= -1);
+
+	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
+	info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
+	info.psi_siginfo.si_errno);
+
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
+
 	DPRINTF("Before resuming the child process where it left off and with "
 	"signal %s to be sent\n", strsignal(sigsent));
 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);



CVS commit: src/tests/lib/libc/sys

2018-05-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May 16 03:18:38 UTC 2018

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Improve the description of traceme_vfork_breakpoint (ATF ptrace(2) test)

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/tests/lib/libc/sys/t_ptrace_wait.c

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.43 src/tests/lib/libc/sys/t_ptrace_wait.c:1.44
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.43	Wed May 16 02:47:25 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May 16 03:18:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.43 2018/05/16 02:47:25 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.44 2018/05/16 03:18:38 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.43 2018/05/16 02:47:25 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.44 2018/05/16 03:18:38 kamil Exp $");
 
 #include 
 #include 
@@ -461,7 +461,8 @@ ATF_TC(traceme_vfork_breakpoint);
 ATF_TC_HEAD(traceme_vfork_breakpoint, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
-	"Verify software breakpoint in a vfork(2)ed child");
+	"Verify PT_TRACE_ME followed by a software breakpoint in a "
+	"vfork(2)ed child");
 }
 
 ATF_TC_BODY(traceme_vfork_breakpoint, tc)



CVS commit: src/tests/lib/libc/sys

2018-05-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May 16 02:47:25 UTC 2018

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add a new ATF ptrace(2) test: traceme_vfork_exec

Verify PT_TRACE_ME followed by exec(3) in a vfork(2)ed child.

This tests passes correctly.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/tests/lib/libc/sys/t_ptrace_wait.c

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.42 src/tests/lib/libc/sys/t_ptrace_wait.c:1.43
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.42	Wed May 16 01:36:29 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May 16 02:47:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.42 2018/05/16 01:36:29 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.43 2018/05/16 02:47:25 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.42 2018/05/16 01:36:29 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.43 2018/05/16 02:47:25 kamil Exp $");
 
 #include 
 #include 
@@ -500,6 +500,67 @@ ATF_TC_BODY(traceme_vfork_breakpoint, tc
 
 /// 
 
+ATF_TC(traceme_vfork_exec);
+ATF_TC_HEAD(traceme_vfork_exec, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify PT_TRACE_ME followed by exec(3) in a vfork(2)ed child");
+}
+
+ATF_TC_BODY(traceme_vfork_exec, tc)
+{
+	const int sigval = SIGTRAP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+
+	struct ptrace_siginfo info;
+	memset(&info, 0, sizeof(info));
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = vfork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before calling execve(2) from child\n");
+		execlp("/bin/echo", "/bin/echo", NULL);
+
+		/* NOTREACHED */
+		FORKEE_ASSERTX(0 && "Not reached");
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
+
+	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
+	info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
+	info.psi_siginfo.si_errno);
+
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC);
+
+	DPRINTF("Before resuming the child process where it left off and "
+	"without signal to be sent\n");
+	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+
+/// 
+
 #if defined(TWAIT_HAVE_PID)
 ATF_TC(attach1);
 ATF_TC_HEAD(attach1, tc)
@@ -6969,6 +7030,8 @@ ATF_TP_ADD_TCS(tp)
 
 	ATF_TP_ADD_TC(tp, traceme_vfork_breakpoint);
 
+	ATF_TP_ADD_TC(tp, traceme_vfork_exec);
+
 	ATF_TP_ADD_TC_HAVE_PID(tp, attach1);
 	ATF_TP_ADD_TC_HAVE_PID(tp, attach2);
 	ATF_TP_ADD_TC(tp, attach3);



CVS commit: src/tests/lib/libc/sys

2018-05-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May 16 01:36:29 UTC 2018

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Improve the description of traceme_vfork_raise in ATF ptrace(2) tests

Set new description to:
 - "Verify PT_TRACE_ME followed by raise of " #sig " in a vfork(2)ed "
   "child"

The previous one was copy pasted from a different ATF test and not changed.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/tests/lib/libc/sys/t_ptrace_wait.c

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.41 src/tests/lib/libc/sys/t_ptrace_wait.c:1.42
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.41	Wed May 16 01:27:27 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May 16 01:36:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.41 2018/05/16 01:27:27 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.42 2018/05/16 01:36:29 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.41 2018/05/16 01:27:27 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.42 2018/05/16 01:36:29 kamil Exp $");
 
 #include 
 #include 
@@ -439,7 +439,8 @@ ATF_TC(test);	\
 ATF_TC_HEAD(test, tc)\
 {		\
 	atf_tc_set_md_var(tc, "descr",		\
-	"Verify " #sig " followed by _exit(2) in a vfork(2)ed child");	\
+	"Verify PT_TRACE_ME followed by raise of " #sig " in a vfork(2)ed "	\
+	"child");\
 }		\
 		\
 ATF_TC_BODY(test, tc)\



CVS commit: src/tests/lib/libc/sys

2018-05-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May 16 01:27:27 UTC 2018

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add a new ATF ptrace(2) test: traceme_vfork_breakpoint

Verify software breakpoint in a vfork(2)ed child.

The expected behavior is not to route this signal to the parent, even if
that parent is a tracer. The parent cannot handle it and it would lead to
the deadlock.

This test passes correctly.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/tests/lib/libc/sys/t_ptrace_wait.c

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.40 src/tests/lib/libc/sys/t_ptrace_wait.c:1.41
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.40	Wed May 16 00:42:15 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May 16 01:27:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.40 2018/05/16 00:42:15 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.41 2018/05/16 01:27:27 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.40 2018/05/16 00:42:15 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.41 2018/05/16 01:27:27 kamil Exp $");
 
 #include 
 #include 
@@ -456,6 +456,49 @@ TRACEME_VFORK_RAISE(traceme_vfork_raise5
 
 /// 
 
+ATF_TC(traceme_vfork_breakpoint);
+ATF_TC_HEAD(traceme_vfork_breakpoint, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify software breakpoint in a vfork(2)ed child");
+}
+
+ATF_TC_BODY(traceme_vfork_breakpoint, tc)
+{
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = vfork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before executing a software breakpoint\n");
+#ifdef PTRACE_BREAKPOINT_ASM
+		PTRACE_BREAKPOINT_ASM;
+#else
+		/* port me */
+#endif
+
+		/* NOTREACHED */
+		FORKEE_ASSERTX(0 && "This shall not be reached");
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+	validate_status_signaled(status, SIGTRAP, 1);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+}
+
+/// 
+
 #if defined(TWAIT_HAVE_PID)
 ATF_TC(attach1);
 ATF_TC_HEAD(attach1, tc)
@@ -6923,6 +6966,8 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, traceme_vfork_raise4);
 	ATF_TP_ADD_TC(tp, traceme_vfork_raise5);
 
+	ATF_TP_ADD_TC(tp, traceme_vfork_breakpoint);
+
 	ATF_TP_ADD_TC_HAVE_PID(tp, attach1);
 	ATF_TP_ADD_TC_HAVE_PID(tp, attach2);
 	ATF_TP_ADD_TC(tp, attach3);



CVS commit: src

2018-05-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May 16 00:42:16 UTC 2018

Modified Files:
src/sys/kern: kern_sig.c
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Correct handling of: vfork(2) + PT_TRACE_ME + raise(2)

Follow the FreeBSD approach of not routing signals to the parent that is
a became tracer after calling PT_TRACE_ME by the vfork(2)ed child (before
exec(3)/exit(3)).

Now if a child calls raise(3), the signal is processed directly to this
child.

Add new ATF ptrace(2) tests:
 - traceme_vfork_raise1 (SIGKILL)
 - traceme_vfork_raise2 (SIGSTOP) // temporarily disabled
 - traceme_vfork_raise3 (SIGABRT)
 - traceme_vfork_raise4 (SIGHUP)
 - traceme_vfork_raise5 (SIGCONT)

The FreeBSD implementation introduces P_PPTRACE for this special case.
Right know keep opencoding check of this case in the kernel. It might be
refactored in future.

The Linux kernel does not follow this approach and causes dead locking of
the processes (parent and child).

Defer handling SIGSTOP into future.

This is an intermediate step towards correct handling of fork(2) and
vfork(2) in the context of ptrace(2).

All new tests pass.
There are no regressions in existing ATF ptrace(2) tests.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.343 -r1.344 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.39 -r1.40 src/tests/lib/libc/sys/t_ptrace_wait.c

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

Modified files:

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.343 src/sys/kern/kern_sig.c:1.344
--- src/sys/kern/kern_sig.c:1.343	Sun May  6 13:40:51 2018
+++ src/sys/kern/kern_sig.c	Wed May 16 00:42:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.343 2018/05/06 13:40:51 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.344 2018/05/16 00:42:15 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.343 2018/05/06 13:40:51 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.344 2018/05/16 00:42:15 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -1720,10 +1720,10 @@ issignal(struct lwp *l)
 		 * If traced, always stop, and stay stopped until released
 		 * by the debugger.  If the our parent is our debugger waiting
 		 * for us and we vforked, don't hang as we could deadlock.
-		 *
-		 * XXX: support PT_TRACE_ME called after vfork(2)
 		 */
-		if ((p->p_slflag & PSL_TRACED) != 0 && signo != SIGKILL) {
+		if (ISSET(p->p_slflag, PSL_TRACED) && signo != SIGKILL &&
+		!(ISSET(p->p_lflag, PL_PPWAIT) &&
+		 (p->p_pptr == p->p_opptr))) {
 			/*
 			 * Take the signal, but don't remove it from the
 			 * siginfo queue, because the debugger can send

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.39 src/tests/lib/libc/sys/t_ptrace_wait.c:1.40
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.39	Sun May 13 23:14:47 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May 16 00:42:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.39 2018/05/13 23:14:47 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.40 2018/05/16 00:42:15 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.39 2018/05/13 23:14:47 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.40 2018/05/16 00:42:15 kamil Exp $");
 
 #include 
 #include 
@@ -379,6 +379,83 @@ ATF_TC_BODY(traceme_pid1_parent, tc)
 
 /// 
 
+static void
+traceme_vfork_raise(int sigval)
+{
+	const int exitval = 5;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+	int expect_core = (sigval == SIGABRT) ? 1 : 0;
+#endif
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = vfork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		switch (sigval) {
+		case SIGKILL:
+		case SIGABRT:
+		case SIGHUP:
+			/* NOTREACHED */
+			FORKEE_ASSERTX(0 && "This shall not be reached");
+		default:
+			DPRINTF("Before exiting of the child process\n");
+			_exit(exitval);
+		}
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+	switch (sigval) {
+	case SIGKILL:
+	case SIGABRT:
+	case SIGHUP:
+		validate_status_signaled(status, sigval, expect_core);
+		break;
+	case SIGSTOP:
+	case SIGCONT:
+		validate_status_exited(status, exitval);
+		break;
+	default:
+		/* NOTREACHED */
+		ATF_REQUIRE(0 && "NOT IMPLEMENTED");
+		break;
+	}
+
+	

CVS commit: src/sys/arch/arm/sunxi

2018-05-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed May 16 00:12:57 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi: sun50i_a64_acodec.c

Log Message:
Rename mic1 control to mic so audiorecord can use it


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sun50i_a64_acodec.c

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

Modified files:

Index: src/sys/arch/arm/sunxi/sun50i_a64_acodec.c
diff -u src/sys/arch/arm/sunxi/sun50i_a64_acodec.c:1.6 src/sys/arch/arm/sunxi/sun50i_a64_acodec.c:1.7
--- src/sys/arch/arm/sunxi/sun50i_a64_acodec.c:1.6	Tue May 15 01:26:45 2018
+++ src/sys/arch/arm/sunxi/sun50i_a64_acodec.c	Wed May 16 00:12:57 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_a64_acodec.c,v 1.6 2018/05/15 01:26:45 jmcneill Exp $ */
+/* $NetBSD: sun50i_a64_acodec.c,v 1.7 2018/05/16 00:12:57 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun50i_a64_acodec.c,v 1.6 2018/05/15 01:26:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun50i_a64_acodec.c,v 1.7 2018/05/16 00:12:57 jmcneill Exp $");
 
 #include 
 #include 
@@ -140,9 +140,9 @@ static const struct a64_acodec_mixer {
 
 	[A64_CODEC_RECORD_LINE_VOLUME]	= { AudioNline,
 	A64_CODEC_RECORD_CLASS, A64_LINEIN_CTRL, A64_LINEING },
-	[A64_CODEC_RECORD_MIC1_VOLUME]	= { "mic1",
+	[A64_CODEC_RECORD_MIC1_VOLUME]	= { AudioNmicrophone,
 	A64_CODEC_RECORD_CLASS, A64_MIC1_CTRL, A64_MIC1G },
-	[A64_CODEC_RECORD_MIC2_VOLUME]	= { "mic2",
+	[A64_CODEC_RECORD_MIC2_VOLUME]	= { AudioNmicrophone "2",
 	A64_CODEC_RECORD_CLASS, A64_MIC2_CTRL, A64_MIC2G },
 	[A64_CODEC_RECORD_AGC_VOLUME]	= { AudioNagc,
 	A64_CODEC_RECORD_CLASS, A64_ADC_CTRL, A64_ADCG },
@@ -482,9 +482,9 @@ a64_acodec_query_devinfo(void *priv, mix
 		di->un.s.num_mem = 4;
 		strcpy(di->un.s.member[0].label.name, AudioNline);
 		di->un.s.member[0].mask = A64_ADCMIX_SRC_LINEIN;
-		strcpy(di->un.s.member[1].label.name, "mic1");
+		strcpy(di->un.s.member[1].label.name, AudioNmicrophone);
 		di->un.s.member[1].mask = A64_ADCMIX_SRC_MIC1;
-		strcpy(di->un.s.member[2].label.name, "mic2");
+		strcpy(di->un.s.member[2].label.name, AudioNmicrophone "2");
 		di->un.s.member[2].mask = A64_ADCMIX_SRC_MIC2;
 		strcpy(di->un.s.member[3].label.name, AudioNdac);
 		di->un.s.member[3].mask = A64_ADCMIX_SRC_OMIXER;



CVS commit: src/sys

2018-05-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May 15 19:16:38 UTC 2018

Modified Files:
src/sys/netinet: ip_reass.c
src/sys/netinet6: frag6.c

Log Message:
When reassembling IPv4/IPv6 packets, ensure each fragment has been subject
to the same IPsec processing. That is to say, that all fragments are ESP,
or AH, or AH+ESP, or none.

The reassembly mechanism can be used both on the wire and inside an IPsec
tunnel, so we need to make sure all fragments of a packet were received
on only one side.

Even though I haven't tried, I believe there are configurations where it
would be possible for an attacker to inject an unencrypted fragment into a
legitimate stream of already-decrypted-and-authenticated fragments.

Typically on IPsec gateways with ESP tunnels, where we can encapsulate
fragments (as opposed to the general case, where we fragment encapsulated
data).

Note, for the record: a funnier thing, under IPv4, would be to send a
zero-sized !MFF fragment at the head of the packet, and manage to trigger
an ICMP error; M_DECRYPTED gets lost by the reassembly, and ICMP will reply
with the packet in clear (not encrypted).


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet/ip_reass.c
cvs rdiff -u -r1.73 -r1.74 src/sys/netinet6/frag6.c

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

Modified files:

Index: src/sys/netinet/ip_reass.c
diff -u src/sys/netinet/ip_reass.c:1.16 src/sys/netinet/ip_reass.c:1.17
--- src/sys/netinet/ip_reass.c:1.16	Thu May  3 07:25:49 2018
+++ src/sys/netinet/ip_reass.c	Tue May 15 19:16:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_reass.c,v 1.16 2018/05/03 07:25:49 maxv Exp $	*/
+/*	$NetBSD: ip_reass.c,v 1.17 2018/05/15 19:16:38 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.16 2018/05/03 07:25:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.17 2018/05/15 19:16:38 maxv Exp $");
 
 #include 
 #include 
@@ -93,7 +93,8 @@ typedef struct ipfr_queue {
 	struct in_addr		ipq_src;
 	struct in_addr		ipq_dst;
 	uint16_t		ipq_nfrags;	/* frags in this queue entry */
-	uint8_t 		ipq_tos;	/* TOS of this fragment */
+	uint8_t			ipq_tos;	/* TOS of this fragment */
+	int			ipq_ipsec;	/* IPsec flags */
 } ipfr_queue_t;
 
 /*
@@ -217,6 +218,7 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	struct ip *ip = ipqe->ipqe_ip, *qip;
 	const int hlen = ip->ip_hl << 2;
 	struct mbuf *m = ipqe->ipqe_m, *t;
+	int ipsecflags = m->m_flags & (M_DECRYPTED|M_AUTHIPHDR);
 	ipfr_qent_t *nq, *p, *q;
 	int i, next;
 
@@ -269,6 +271,7 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 		fp->ipq_p = ip->ip_p;
 		fp->ipq_id = ip->ip_id;
 		fp->ipq_tos = ip->ip_tos;
+		fp->ipq_ipsec = ipsecflags;
 		fp->ipq_src = ip->ip_src;
 		fp->ipq_dst = ip->ip_dst;
 		LIST_INSERT_HEAD(&ip_frags[hash], fp, ipq_q);
@@ -614,6 +617,7 @@ ip_reass_packet(struct mbuf **m0, struct
 	const int hlen = ip->ip_hl << 2;
 	const int len = ntohs(ip->ip_len);
 	struct mbuf *m = *m0;
+	int ipsecflags = m->m_flags & (M_DECRYPTED|M_AUTHIPHDR);
 	ipfr_queue_t *fp;
 	ipfr_qent_t *ipqe;
 	u_int hash, off, flen;
@@ -669,11 +673,20 @@ ip_reass_packet(struct mbuf **m0, struct
 		break;
 	}
 
-	/* Make sure that TOS matches previous fragments. */
-	if (fp && fp->ipq_tos != ip->ip_tos) {
-		IP_STATINC(IP_STAT_BADFRAGS);
-		mutex_exit(&ipfr_lock);
-		return EINVAL;
+	if (fp) {
+		/* All fragments must have the same IPsec flags. */
+		if (fp->ipq_ipsec != ipsecflags) {
+			IP_STATINC(IP_STAT_BADFRAGS);
+			mutex_exit(&ipfr_lock);
+			return EINVAL;
+		}
+
+		/* Make sure that TOS matches previous fragments. */
+		if (fp->ipq_tos != ip->ip_tos) {
+			IP_STATINC(IP_STAT_BADFRAGS);
+			mutex_exit(&ipfr_lock);
+			return EINVAL;
+		}
 	}
 
 	/*

Index: src/sys/netinet6/frag6.c
diff -u src/sys/netinet6/frag6.c:1.73 src/sys/netinet6/frag6.c:1.74
--- src/sys/netinet6/frag6.c:1.73	Thu May  3 07:25:49 2018
+++ src/sys/netinet6/frag6.c	Tue May 15 19:16:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.73 2018/05/03 07:25:49 maxv Exp $	*/
+/*	$NetBSD: frag6.c,v 1.74 2018/05/15 19:16:38 maxv Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.73 2018/05/03 07:25:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.74 2018/05/15 19:16:38 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -76,6 +76,7 @@ struct	ip6q {
 	struct ip6q	*ip6q_prev;
 	int		ip6q_unfrglen;	/* len of unfragmentable part */
 	int		ip6q_nfrag;	/* # of fragments */
+	int		ip6q_ipsec;	/* IPsec flags */
 };
 
 struct	ip6asfrag {
@@ -162,6 +163,7 @@ frag6_input(struct mbuf **mp, int *offp,
 	struct ip6q *q6;
 	struct ip6asfrag *af6, *ip6af, *af6dwn;
 	int offset = *offp, nxt, i, next;
+	int ipsecflags = m->m_flags & (M_DECRYPTED|M_AUTHIPHDR);
 	int first_frag = 0;
 	int fragoff, frgpartl

CVS commit: [netbsd-8] src/doc

2018-05-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 15 13:50:20 UTC 2018

Modified Files:
src/doc [netbsd-8]: CHANGES-8.0

Log Message:
Tickets #824 - #826


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.198 -r1.1.2.199 src/doc/CHANGES-8.0

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

Modified files:

Index: src/doc/CHANGES-8.0
diff -u src/doc/CHANGES-8.0:1.1.2.198 src/doc/CHANGES-8.0:1.1.2.199
--- src/doc/CHANGES-8.0:1.1.2.198	Mon May 14 19:24:10 2018
+++ src/doc/CHANGES-8.0	Tue May 15 13:50:20 2018
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-8.0,v 1.1.2.198 2018/05/14 19:24:10 martin Exp $
+# $NetBSD: CHANGES-8.0,v 1.1.2.199 2018/05/15 13:50:20 martin Exp $
 
 A complete list of changes from the initial NetBSD 8.0 branch on 2017-06-04
 until the 8.0 release:
@@ -13421,3 +13421,35 @@ sys/net/npf/npf_sendpkt.c			1.19
 	Fix use-after-free and strengthen.
 	[maxv, ticket #823]
 
+sys/dev/pci/ixgbe/ixv.c1.97
+
+	Fix panic or hangup when enabling debugging.
+	[msaitoh, ticket #824]
+
+distrib/sets/lists/man/mi			1.1586
+share/man/man4/audio.41.85
+share/man/man7/Makefile1.32
+share/man/man7/audio.71.1,1.2
+share/man/man7/intro.71.24
+share/man/man9/audio.91.46
+sys/dev/audio.c	1.453-1.455
+
+	Bring audio in line with specification published in
+	audio.7, in particular consistient naming of vchans for
+	audioctl & mixerctl as well as exposure of the audio_info
+	structure for the mix ring.
+
+	Addition of an audio specification to describe the workings
+	of the audio mixer.
+	[nat, ticket #825]
+
+sys/net/bpf.c	1.224
+sys/net/if.c	1.421-1.423
+sys/net/if_bridge.c1.155
+
+	Use if_is_mpsafe.
+	Protect packet input routines with KERNEL_LOCK and splsoftnet.
+	Protect if_deferred_start_softint with KERNEL_LOCK if the interface
+	is not MP-safe,
+	[ozaki-r, ticket #826]
+



CVS commit: [netbsd-8] src/sys/net

2018-05-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 15 13:48:37 UTC 2018

Modified Files:
src/sys/net [netbsd-8]: bpf.c if.c if_bridge.c

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #826):

sys/net/if_bridge.c: revision 1.155
sys/net/if.c: revision 1.421
sys/net/bpf.c: revision 1.224
sys/net/if.c: revision 1.422
sys/net/if.c: revision 1.423

Use if_is_mpsafe (NFC)

Protect packet input routines with KERNEL_LOCK and splsoftnet
if_input, i.e, ether_input and friends, now runs in softint without any
protections.  It's ok for ether_input itself because it's already MP-safe,
however, subsequent routines called from it such as carp_input and agr_input
aren't safe because they're not MP-safe.  Protect if_input with KERNEL_LOCK.
if_input can be called from a normal LWP context.  In that case we need to
prevent interrupts (softint) from running by splsoftnet to protect
non-MP-safe
codes (e.g., carp_input and agr_input).

Pointed out by mlelstv@

Protect if_deferred_start_softint with KERNEL_LOCK if the interface isn't
MP-safe


To generate a diff of this commit:
cvs rdiff -u -r1.216.6.5 -r1.216.6.6 src/sys/net/bpf.c
cvs rdiff -u -r1.394.2.9 -r1.394.2.10 src/sys/net/if.c
cvs rdiff -u -r1.134.6.9 -r1.134.6.10 src/sys/net/if_bridge.c

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

Modified files:

Index: src/sys/net/bpf.c
diff -u src/sys/net/bpf.c:1.216.6.5 src/sys/net/bpf.c:1.216.6.6
--- src/sys/net/bpf.c:1.216.6.5	Mon Feb  5 14:18:00 2018
+++ src/sys/net/bpf.c	Tue May 15 13:48:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $	*/
+/*	$NetBSD: bpf.c,v 1.216.6.6 2018/05/15 13:48:37 martin Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.6 2018/05/15 13:48:37 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -836,9 +836,13 @@ bpf_write(struct file *fp, off_t *offp, 
 	error = if_output_lock(ifp, ifp, m, (struct sockaddr *) &dst, NULL);
 
 	if (mc != NULL) {
-		if (error == 0)
+		if (error == 0) {
+			int s = splsoftnet();
+			KERNEL_LOCK_UNLESS_IFP_MPSAFE(ifp);
 			ifp->_if_input(ifp, mc);
-		else
+			KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(ifp);
+			splx(s);
+		} else
 			m_freem(mc);
 	}
 	/*

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.394.2.9 src/sys/net/if.c:1.394.2.10
--- src/sys/net/if.c:1.394.2.9	Wed Feb 28 18:54:43 2018
+++ src/sys/net/if.c	Tue May 15 13:48:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $	*/
+/*	$NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -716,8 +716,7 @@ if_initialize(ifnet_t *ifp)
 
 	if (if_is_link_state_changeable(ifp)) {
 		u_int flags = SOFTINT_NET;
-		flags |= ISSET(ifp->if_extflags, IFEF_MPSAFE) ?
-		SOFTINT_MPSAFE : 0;
+		flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0;
 		ifp->if_link_si = softint_establish(flags,
 		if_link_state_change_si, ifp);
 		if (ifp->if_link_si == NULL) {
@@ -834,11 +833,13 @@ struct if_percpuq *
 if_percpuq_create(struct ifnet *ifp)
 {
 	struct if_percpuq *ipq;
+	u_int flags = SOFTINT_NET;
+
+	flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0;
 
 	ipq = kmem_zalloc(sizeof(*ipq), KM_SLEEP);
 	ipq->ipq_ifp = ifp;
-	ipq->ipq_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE,
-	if_percpuq_softint, ipq);
+	ipq->ipq_si = softint_establish(flags, if_percpuq_softint, ipq);
 	ipq->ipq_ifqs = percpu_alloc(sizeof(struct ifqueue));
 	percpu_foreach(ipq->ipq_ifqs, &if_percpuq_init_ifq, NULL);
 
@@ -1066,11 +1067,13 @@ void
 if_deferred_start_init(struct ifnet *ifp, void (*func)(struct ifnet *))
 {
 	struct if_deferred_start *ids;
+	u_int flags = SOFTINT_NET;
+
+	flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0;
 
 	ids = kmem_zalloc(sizeof(*ids), KM_SLEEP);
 	ids->ids_ifp = ifp;
-	ids->ids_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE,
-	if_deferred_start_softint, ids);
+	ids->ids_si = softint_establish(flags, if_deferred_start_softint, ids);
 	if (func != NULL)
 		ids->ids_if_start = func;
 	else

Index: src/sys/net/if_bridge.c
diff -u src/sys/net/if_bridge.c:1.134.6.9 src/sys/net/if_bridge.c:1.134.6.10
--- src/sys/net/if_bridge.c:1.134.6.9	Wed Apr 18 14:11:42 2018
+++ src/sys/net/if_bridge.c	Tue May 15 13:48:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.134.6.9 2018/04/18 14:11:42 martin Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.134.6.10 2018/05/15 13:48:37 martin Exp $	*/
 
 /*
  * Copyright 200

CVS commit: [netbsd-8] src

2018-05-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 15 13:42:50 UTC 2018

Modified Files:
src/distrib/sets/lists/man [netbsd-8]: mi
src/share/man/man4 [netbsd-8]: audio.4
src/share/man/man7 [netbsd-8]: Makefile intro.7
src/share/man/man9 [netbsd-8]: audio.9
src/sys/dev [netbsd-8]: audio.c
Added Files:
src/share/man/man7 [netbsd-8]: audio.7

Log Message:
Pull up following revision(s) (requested by nat in ticket #825):

share/man/man7/Makefile: revision 1.32
share/man/man9/audio.9: revision 1.46
sys/dev/audio.c: revision 1.453
sys/dev/audio.c: revision 1.454
sys/dev/audio.c: revision 1.455
share/man/man7/audio.7: revision 1.1
share/man/man7/audio.7: revision 1.2
share/man/man7/intro.7: revision 1.24
share/man/man4/audio.4: revision 1.85
distrib/sets/lists/man/mi: revision 1.1586

Fix numbering of vchan mixer controls to correspond to the vchan number in
use.

This makes the numbering of vchans consistient for audioctl and mixerctl.
Expose the audio_info structure of vchan zero(0) the mix ring to allow
setting the hardware gain and balance via audioctl(1) using the -p 0
switch.

It is not possible to influence the hardware gain/blance from the
audio_info structure of vchans 1 onwards.  It is now possible to return
the audio mixers audio format from the audio_info structure of vchan 0 to
ease applications configuring for mmapped play back.

This is conformant to the audio specification posted on tech-kern see:

"NetBSD Audio Specification 2018"

or audio.7 manual page to be added in a follow up commit.
Add the audio mixer specification to section 7 of the manual.
See posting on tech-kern - "NetBSD Audio Specification 2018."
Update the introduction page to section 7 of the manual noting the audio
spec.

Various improvements, more markup, typo fixes.

Fix over cautious compiler error - setmode may not be initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.1557.2.3 -r1.1557.2.4 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.79.2.1 -r1.79.2.2 src/share/man/man4/audio.4
cvs rdiff -u -r1.31 -r1.31.8.1 src/share/man/man7/Makefile
cvs rdiff -u -r0 -r1.2.2.2 src/share/man/man7/audio.7
cvs rdiff -u -r1.23 -r1.23.24.1 src/share/man/man7/intro.7
cvs rdiff -u -r1.44 -r1.44.16.1 src/share/man/man9/audio.9
cvs rdiff -u -r1.357.2.11 -r1.357.2.12 src/sys/dev/audio.c

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

Modified files:

Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1557.2.3 src/distrib/sets/lists/man/mi:1.1557.2.4
--- src/distrib/sets/lists/man/mi:1.1557.2.3	Sat May 12 10:35:45 2018
+++ src/distrib/sets/lists/man/mi	Tue May 15 13:42:50 2018
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1557.2.3 2018/05/12 10:35:45 martin Exp $
+# $NetBSD: mi,v 1.1557.2.4 2018/05/15 13:42:50 martin Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2251,6 +2251,7 @@
 ./usr/share/man/cat5/wtmpx.0			man-sys-catman		.cat
 ./usr/share/man/cat5/ypserv.acl.0		man-obsolete		obsolete
 ./usr/share/man/cat7/ascii.0			man-reference-catman	.cat
+./usr/share/man/cat7/audio.0			man-reference-catman	.cat
 ./usr/share/man/cat7/atf.0			man-atf-catman		.cat,atf
 ./usr/share/man/cat7/c.0			man-reference-catman	.cat
 ./usr/share/man/cat7/c78.0			man-reference-catman	.cat
@@ -5271,6 +5272,7 @@
 ./usr/share/man/html5/wtmp.html			man-sys-htmlman		html
 ./usr/share/man/html5/wtmpx.html		man-sys-htmlman		html
 ./usr/share/man/html7/ascii.html		man-reference-htmlman	html
+./usr/share/man/html7/audio.html		man-reference-htmlman	html
 ./usr/share/man/html7/atf.html			man-atf-htmlman		html,atf
 ./usr/share/man/html7/c.html			man-reference-htmlman	html
 ./usr/share/man/html7/c78.html			man-reference-htmlman	html
@@ -8261,6 +8263,7 @@
 ./usr/share/man/man5/wtmpx.5			man-sys-man		.man
 ./usr/share/man/man5/ypserv.acl.5		man-obsolete		obsolete
 ./usr/share/man/man7/ascii.7			man-reference-man	.man
+./usr/share/man/man7/audio.7			man-reference-man	.man
 ./usr/share/man/man7/atf.7			man-atf-man		.man,atf
 ./usr/share/man/man7/c.7			man-reference-man	.man
 ./usr/share/man/man7/c78.7			man-reference-man	.man

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.79.2.1 src/share/man/man4/audio.4:1.79.2.2
--- src/share/man/man4/audio.4:1.79.2.1	Mon Jan 15 00:08:55 2018
+++ src/share/man/man4/audio.4	Tue May 15 13:42:50 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.79.2.1 2018/01/15 00:08:55 snj Exp $
+.\"	$NetBSD: audio.4,v 1.79.2.2 2018/05/15 13:42:50 martin Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 27, 2017
+.Dd May 15, 2018
 .Dt AUDIO 4
 .Os
 .Sh NAME
@@ -789,6 +789,8 @@ st

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-05-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 15 13:37:24 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #824):

sys/dev/pci/ixgbe/ixv.c: revision 1.97

Fix panic or hangup when "sysctl -w hw.ixgN.debug=1".
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.14 -r1.56.2.15 src/sys/dev/pci/ixgbe/ixv.c

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

Modified files:

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56.2.14 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.15
--- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.14	Sat Apr 14 10:25:11 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Tue May 15 13:37:24 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.56.2.14 2018/04/14 10:25:11 martin Exp $*/
+/*$NetBSD: ixv.c,v 1.56.2.15 2018/05/15 13:37:24 martin Exp $*/
 
 /**
 
@@ -2603,21 +2603,18 @@ ixv_print_debug_info(struct adapter *ada
 static int
 ixv_sysctl_debug(SYSCTLFN_ARGS)
 {
-	struct sysctlnode node;
-	struct adapter *adapter;
+	struct sysctlnode node = *rnode;
+	struct adapter *adapter = (struct adapter *)node.sysctl_data;
 	interror, result;
 
-	node = *rnode;
 	node.sysctl_data = &result;
 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
 
 	if (error || newp == NULL)
 		return error;
 
-	if (result == 1) {
-		adapter = (struct adapter *)node.sysctl_data;
+	if (result == 1)
 		ixv_print_debug_info(adapter);
-	}
 
 	return 0;
 } /* ixv_sysctl_debug */



CVS commit: src/sys/dev

2018-05-15 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 15 10:23:03 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Fix over cautious compiler error - setmode may not be initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.454 -r1.455 src/sys/dev/audio.c

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

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.454 src/sys/dev/audio.c:1.455
--- src/sys/dev/audio.c:1.454	Tue May 15 00:28:00 2018
+++ src/sys/dev/audio.c	Tue May 15 10:23:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.454 2018/05/15 00:28:00 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.455 2018/05/15 10:23:03 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss 
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.454 2018/05/15 00:28:00 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.455 2018/05/15 10:23:03 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4567,6 +4567,7 @@ audiosetinfo(struct audio_softc *sc, str
 	pp = vc->sc_pparams;	/* Temporary encoding storage in */
 	rp = vc->sc_rparams;	/* case setting the modes fails. */
 	nr = np = 0;
+	setmode = 0;
 
 	if (vc == &sc->sc_mixring)
 		goto done;
@@ -4624,7 +4625,6 @@ audiosetinfo(struct audio_softc *sc, str
 	if (np > 0 && (error = audio_check_params(&pp)))
 		return error;
 
-	setmode = 0;
 	if (nr > 0) {
 		if (!cleared) {
 			audio_clear_intr_unlocked(sc, vc);



CVS commit: src/sys/dev/fdt

2018-05-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue May 15 10:17:55 UTC 2018

Modified Files:
src/sys/dev/fdt: fdtvar.h

Log Message:
Build fix for FDT kernels without audio


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/fdt/fdtvar.h

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

Modified files:

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.31 src/sys/dev/fdt/fdtvar.h:1.32
--- src/sys/dev/fdt/fdtvar.h:1.31	Wed May  9 23:59:05 2018
+++ src/sys/dev/fdt/fdtvar.h	Tue May 15 10:17:55 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.31 2018/05/09 23:59:05 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.32 2018/05/15 10:17:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -36,7 +36,13 @@
 #include 
 #include 
 #include 
+
+#include "audio.h"
+#if NAUDIO > 0
 #include 
+#else
+typedef void *audio_dai_tag_t;
+#endif
 
 #include 
 



CVS commit: src/sys/dev/pci/ixgbe

2018-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue May 15 09:30:56 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
 The TQSMR register is not for receiving but for transmitting, so move the
initialization from ixgbe_initialize_receive_units() to
ixgbe_initialize_transmit_units(). No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/sys/dev/pci/ixgbe/ixgbe.c

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

Modified files:

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.151 src/sys/dev/pci/ixgbe/ixgbe.c:1.152
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.151	Thu May 10 03:15:28 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue May 15 09:30:56 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.151 2018/05/10 03:15:28 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.152 2018/05/15 09:30:56 msaitoh Exp $ */
 
 /**
 
@@ -583,7 +583,7 @@ ixgbe_initialize_receive_units(struct ad
 
 	for (i = 0; i < adapter->num_queues; i++, rxr++) {
 		u64 rdba = rxr->rxdma.dma_paddr;
-		u32 tqsmreg, reg;
+		u32 reg;
 		int regnum = i / 4;	/* 1 register per 4 queues */
 		int regshift = i % 4;	/* 4 bits per 1 queue */
 		j = rxr->me;
@@ -609,20 +609,6 @@ ixgbe_initialize_receive_units(struct ad
 		IXGBE_WRITE_REG(hw, IXGBE_RQSMR(regnum), reg);
 
 		/*
-		 * Set RQSMR (Receive Queue Statistic Mapping) register.
-		 * Register location for queue 0...7 are different between
-		 * 82598 and newer.
-		 */
-		if (adapter->hw.mac.type == ixgbe_mac_82598EB)
-			tqsmreg = IXGBE_TQSMR(regnum);
-		else
-			tqsmreg = IXGBE_TQSM(regnum);
-		reg = IXGBE_READ_REG(hw, tqsmreg);
-		reg &= ~(0x00ff << (regshift * 8));
-		reg |= i << (regshift * 8);
-		IXGBE_WRITE_REG(hw, tqsmreg, reg);
-
-		/*
 		 * Set DROP_EN iff we have no flow control and >1 queue.
 		 * Note that srrctl was cleared shortly before during reset,
 		 * so we do not need to clear the bit, but do it just in case
@@ -687,6 +673,9 @@ ixgbe_initialize_transmit_units(struct a
 	for (i = 0; i < adapter->num_queues; i++, txr++) {
 		u64 tdba = txr->txdma.dma_paddr;
 		u32 txctrl = 0;
+		u32 tqsmreg, reg;
+		int regnum = i / 4;	/* 1 register per 4 queues */
+		int regshift = i % 4;	/* 4 bits per 1 queue */
 		int j = txr->me;
 
 		IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
@@ -695,6 +684,19 @@ ixgbe_initialize_transmit_units(struct a
 		IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j),
 		adapter->num_tx_desc * sizeof(union ixgbe_adv_tx_desc));
 
+		/*
+		 * Set TQSMR (Transmit Queue Statistic Mapping) register.
+		 * Register location is different between 82598 and others.
+		 */
+		if (adapter->hw.mac.type == ixgbe_mac_82598EB)
+			tqsmreg = IXGBE_TQSMR(regnum);
+		else
+			tqsmreg = IXGBE_TQSM(regnum);
+		reg = IXGBE_READ_REG(hw, tqsmreg);
+		reg &= ~(0x00ff << (regshift * 8));
+		reg |= i << (regshift * 8);
+		IXGBE_WRITE_REG(hw, tqsmreg, reg);
+
 		/* Setup the HW Tx Head and Tail descriptor pointers */
 		IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
 		IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);



CVS commit: src/share/man/man7

2018-05-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue May 15 09:30:01 UTC 2018

Modified Files:
src/share/man/man7: audio.7

Log Message:
Various improvements, more markup, typo fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/man/man7/audio.7

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

Modified files:

Index: src/share/man/man7/audio.7
diff -u src/share/man/man7/audio.7:1.1 src/share/man/man7/audio.7:1.2
--- src/share/man/man7/audio.7:1.1	Tue May 15 00:54:01 2018
+++ src/share/man/man7/audio.7	Tue May 15 09:30:01 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.7,v 1.1 2018/05/15 00:54:01 nat Exp $
+.\"	$NetBSD: audio.7,v 1.2 2018/05/15 09:30:01 wiz Exp $
 .\"
 .\" Copyright (c) 2016 - 2018  Nathanial Sloss 
 .\" All rights reserved.
@@ -35,19 +35,29 @@ in-kernel audio mixer specification
 .Sh INTRODUCTION
 This document aims to describe all aspects of the in-kernel audio mixer
 included with
-.Nx 8 and onwards.
-Describing its current behavior as of 2018.
+.Nx 8
+and onwards, describing its current behavior as of 2018.
 .Sh VIRTUAL CHANNEL (VCHAN)
 This is the most fundamental element to the mixer.
 The vchan has all of the properties of the traditional single open
 .Nx
 audio channel.
-It consists of playback and record rings along with audio_info structures.
-.Pp
-Upon opening of /dev/audio or /dev/sound a new vchan and mixerctl structure is
-created.
-In the case of /dev/sound, audio_info structures are inherited from the last
-open of /dev/audio or /dev/sound.
+It consists of playback and record rings along with
+.Vt audio_info
+structures.
+.Pp
+Upon opening of
+.Pa /dev/audio
+or
+.Pa /dev/sound ,
+a new vchan and mixerctl structure is created.
+In the case of
+.Pa /dev/sound ,
+.Vt audio_info
+structures are inherited from the last open of
+.Pa /dev/audio
+or
+.Pa /dev/sound .
 .Pp
 All vchans are up or down sampled into the mix ring (intermediate) format
 before being sent to hardware.
@@ -61,37 +71,46 @@ It is described in the following diagram
 	VCHANn-/
 .Ed
 .Pp
-In the case of sysctl usemixer=0 (see below) there is only one vchan whose play
+In the case of
+.Xr sysctl 8
+.Dv usemixer=0
+(see below), there is only one vchan whose play
 and record rings are the hardware play/record rings.
 .Pp
-User accessible vchans are numbered starting at one(1).
-Vchan 0 is used internaly by the mixer for the mix ring and its ring buffers
+User accessible vchans are numbered starting at one (1).
+Vchan 0 is used internally by the mixer for the mix ring and its ring buffers
 are not user accessible.
 .Pp
 The only limit to the number of open vchans is the speed of the computer and the
 number of free file descriptors.
 .Sh BLOCK - SIZE / LATENCY
 A block of audio data is the basic unit for audio data.
-Audio applications will not commence play back until three(3) blocks have been
+Audio applications will not commence playback until three (3) blocks have been
 written - this is the source of latency in the mixer along with the size of the
 audio data block.
 .Pp
-For normal uses audio read/write their will be three blocks of audio data before
-play back commences one in the vchan, one in the mix ring and one in the
+For normal uses of audio read/write there will be three blocks of audio data before
+playback commences one in the vchan, one in the mix ring and one in the
 hardware ring.
 .Pp
 The size of the audio data block is dependent on the audio format configured
-by the application the latency sysctl and the underlying audio hardware.
+by the application the latency
+.Xr sysctl 8
+and the underlying audio hardware.
 .Pp
 Some audio hardware devices only support a static block size, as such the
 overall latency of the mixer for these devices cannot be changed.
-Other devices such as those supported by hdaudio allow the hardware block size
+Other devices such as those supported by
+.Xr hdaudio 4
+allow the hardware block size
 to be changed, allowing the latency of the mixer to change from 4
-milliseconds(ms) to 128 ms with the mixer intermediate format being 16 bit,
+milliseconds (ms) to 128 ms with the mixer intermediate format being 16 bit,
 stereo, 48 kHz.
 .Pp
 With regard to mmapped audio, blocks are played back immediately so the latency
-presented to applications is one third of the latency sysctl value.
+presented to applications is one third of the latency
+.Xr sysctl 8
+value.
 .Pp
 Latency can be calculated by the following formula:
 .Bd -literal
@@ -109,72 +128,101 @@ constraints.
 .Sh ADDED IOCTLS
 Two new ioctls have been added to accommodate mixing of multiple vchans:
 .Bl -tag -width indent
-.It Ar AUDIO_SETCHAN:
+.It Dv AUDIO_SETCHAN :
 Allows setting the target vchan to operate on for subsequent
-ioctl calls.
-.It Ar AUDIO_GETCHAN:
+.Xr ioctl 2
+calls.
+.It Dv AUDIO_GETCHAN :
 Returns the current vchan number.
 .El
 .Pp
-These ioctls were necessary as some audio applications 

CVS commit: src/share/man/man7

2018-05-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue May 15 09:13:36 UTC 2018

Modified Files:
src/share/man/man7: intro.7

Log Message:
Remove Tn.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/share/man/man7/intro.7

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

Modified files:

Index: src/share/man/man7/intro.7
diff -u src/share/man/man7/intro.7:1.24 src/share/man/man7/intro.7:1.25
--- src/share/man/man7/intro.7:1.24	Tue May 15 01:07:37 2018
+++ src/share/man/man7/intro.7	Tue May 15 09:13:36 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: intro.7,v 1.24 2018/05/15 01:07:37 nat Exp $
+.\"	$NetBSD: intro.7,v 1.25 2018/05/15 09:13:36 wiz Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -39,9 +39,7 @@
 This section contains miscellaneous documentation, including:
 .Bl -tag -width "mdoc.samples(7)" -offset indent
 .It Xr ascii 7
-map of
-.Tn ASCII
-character set
+map of ASCII character set
 .It Xr audio 7
 the
 .Nx audio specification