CVS commit: src/common/dist/zlib

2017-11-11 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Sun Nov 12 07:55:05 UTC 2017

Modified Files:
src/common/dist/zlib: inflate.c

Log Message:
Restore a local change (in rev1.4) that was lost on zlib 1.12.10 merge.

The rev 1.4 changelog:
> Disable a sanity check output buffer != NULL in _STANDALONE case.
> Some kernels are loaded at address 0x0 by bootloaders and
> output buffer address could be zero in such case.
>
> Fixes "read text" errors on loading install floppy of NetBSD/news68k 4.0,
> reported by KIYOHARA Takashi on port-news68k.

This problem may also affect other m68k ports which use a gzipped install
kernel and kernel text address located at PA 0x0.

Should be pulled up to netbsd-8.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/common/dist/zlib/inflate.c

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

Modified files:

Index: src/common/dist/zlib/inflate.c
diff -u src/common/dist/zlib/inflate.c:1.5 src/common/dist/zlib/inflate.c:1.6
--- src/common/dist/zlib/inflate.c:1.5	Tue Jan 10 01:27:41 2017
+++ src/common/dist/zlib/inflate.c	Sun Nov 12 07:55:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: inflate.c,v 1.5 2017/01/10 01:27:41 christos Exp $	*/
+/*	$NetBSD: inflate.c,v 1.6 2017/11/12 07:55:05 tsutsui Exp $	*/
 
 /* inflate.c -- zlib decompression
  * Copyright (C) 1995-2016 Mark Adler
@@ -644,9 +644,16 @@ int flush;
 static const unsigned short order[19] = /* permutation of code lengths */
 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
 
+#if defined(__NetBSD__) && defined(_STANDALONE)
+/* Some kernels are loaded at address 0x0 so strm->next_out could be NULL */
+if (inflateStateCheck(strm) ||
+(strm->next_in == Z_NULL && strm->avail_in != 0))
+return Z_STREAM_ERROR;
+#else
 if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
 (strm->next_in == Z_NULL && strm->avail_in != 0))
 return Z_STREAM_ERROR;
+#endif
 
 state = (struct inflate_state FAR *)strm->state;
 if (state->mode == TYPE) state->mode = TYPEDO;  /* skip check */



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

2017-11-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Nov 12 05:11:36 UTC 2017

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

Log Message:
 Remove obsoleted comment. This comment should have been removed in rev. 1.97.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.110 src/sys/dev/pci/ixgbe/ixgbe.c:1.111
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.110	Thu Nov  9 09:33:28 2017
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sun Nov 12 05:11:36 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.110 2017/11/09 09:33:28 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.111 2017/11/12 05:11:36 msaitoh Exp $ */
 
 /**
 
@@ -5976,7 +5976,6 @@ ixgbe_configure_interrupts(struct adapte
 
 	if (ixgbe_num_queues != 0)
 		queues = ixgbe_num_queues;
-	/* Set max queues to 8 when autoconfiguring */
 	else
 		queues = min(queues,
 		min(mac->max_tx_queues, mac->max_rx_queues));



CVS commit: src/doc

2017-11-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 12 03:03:53 UTC 2017

Modified Files:
src/doc: 3RDPARTY CHANGES

Log Message:
new acpica


To generate a diff of this commit:
cvs rdiff -u -r1.1481 -r1.1482 src/doc/3RDPARTY
cvs rdiff -u -r1.2329 -r1.2330 src/doc/CHANGES

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

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1481 src/doc/3RDPARTY:1.1482
--- src/doc/3RDPARTY:1.1481	Sat Oct 28 06:35:48 2017
+++ src/doc/3RDPARTY	Sat Nov 11 22:03:53 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1481 2017/10/28 10:35:48 jmcneill Exp $
+#	$NetBSD: 3RDPARTY,v 1.1482 2017/11/12 03:03:53 christos Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -40,8 +40,8 @@
 #
 
 Package:	acpica
-Version:	20170831
-Current Vers:	20170831
+Version:	20171110
+Current Vers:	20170111
 Maintainer:	Intel
 Archive Site:	http://www.acpica.org/downloads/
 Home Page:	http://www.acpica.org/

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2329 src/doc/CHANGES:1.2330
--- src/doc/CHANGES:1.2329	Fri Oct 27 21:12:04 2017
+++ src/doc/CHANGES	Sat Nov 11 22:03:53 2017
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2329 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2330 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -79,3 +79,4 @@ Changes from NetBSD 8.0 to NetBSD 9.0:
 	kernhist(9): Reworked the export-via-sysctl code to use uintptr_t
 		arguments, PR kern/52639.  Requires contemporaneous update
 		of vmstat(1). [pgoyette 20171028]
+	acpi(4): Updated ACPICA to 20171110. [christos 2017]



CVS commit: src/external/bsd/acpica/bin/iasl

2017-11-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 12 03:02:15 UTC 2017

Modified Files:
src/external/bsd/acpica/bin/iasl: Makefile

Log Message:
new files for acpica-20171110


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/external/bsd/acpica/bin/iasl/Makefile

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

Modified files:

Index: src/external/bsd/acpica/bin/iasl/Makefile
diff -u src/external/bsd/acpica/bin/iasl/Makefile:1.16 src/external/bsd/acpica/bin/iasl/Makefile:1.17
--- src/external/bsd/acpica/bin/iasl/Makefile:1.16	Tue Oct 10 15:17:57 2017
+++ src/external/bsd/acpica/bin/iasl/Makefile	Sat Nov 11 22:02:15 2017
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.16 2017/10/10 19:17:57 christos Exp $
+# $NetBSD: Makefile,v 1.17 2017/11/12 03:02:15 christos Exp $
 
 .if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64")
 PROG=	iasl
@@ -25,9 +25,11 @@ DPSRCS= aslcompilerparse.y aslcompilerle
 .PATH:	${TOPDIR}
 SRCS+= \
 	adfile.c \
+	aslallocate.c \
 	aslanalyze.c \
 	aslascii.c \
 	aslbtypes.c \
+	aslcache.c \
 	aslcodegen.c \
 	aslcompile.c \
 	aslcompilerlex.c \



CVS commit: src/sys/dev/acpi/acpica

2017-11-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 12 02:59:55 UTC 2017

Modified Files:
src/sys/dev/acpi/acpica: OsdSchedule.c

Log Message:
Provide a primitive incrementing counter if we are call since the new
Acpi dispatcher requires us to have one when we are cold (shudder).


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/acpi/acpica/OsdSchedule.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/acpi/acpica/OsdSchedule.c
diff -u src/sys/dev/acpi/acpica/OsdSchedule.c:1.18 src/sys/dev/acpi/acpica/OsdSchedule.c:1.19
--- src/sys/dev/acpi/acpica/OsdSchedule.c:1.18	Sat Jan  9 16:14:42 2016
+++ src/sys/dev/acpi/acpica/OsdSchedule.c	Sat Nov 11 21:59:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: OsdSchedule.c,v 1.18 2016/01/09 21:14:42 christos Exp $	*/
+/*	$NetBSD: OsdSchedule.c,v 1.19 2017/11/12 02:59:55 christos Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: OsdSchedule.c,v 1.18 2016/01/09 21:14:42 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: OsdSchedule.c,v 1.19 2017/11/12 02:59:55 christos Exp $");
 
 #include 
 #include 
@@ -168,12 +168,14 @@ AcpiOsStall(UINT32 Microseconds)
 UINT64
 AcpiOsGetTimer(void)
 {
+	static UINT64 xt;
 	struct timeval tv;
 	UINT64 t;
 
 	/* XXX During early boot there is no (decent) timer available yet. */
-	if (cold)
-		panic("acpi: timer op not yet supported during boot");
+	if (cold) {
+		return xt += 100;
+	}
 
 	microtime();
 	t = (UINT64)10 * tv.tv_usec;



CVS import: src/sys/external/bsd/acpica/dist

2017-11-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 12 01:38:38 UTC 2017

Update of /cvsroot/src/sys/external/bsd/acpica/dist
In directory ivanova.netbsd.org:/tmp/cvs-serv4586

Log Message:

10 November 2017. Summary of changes for version 20171110:


1) ACPICA kernel-resident subsystem:

This release implements full support for ACPI 6.2A:
NFIT - Added a new subtable, "Platform Capabilities Structure"
No other changes to ACPICA were required, since ACPI 6.2A is primarily an 
errata release of the specification.

Other ACPI table changes:
IORT: Added the SMMUv3 Device ID mapping index. Hanjun Guo
PPTT: Added cache attribute flag definitions to actbl1.h. Jeremy 
Linton

Utilities: Modified the string/integer conversion functions to use 
internal 64-bit divide support instead of a native divide. On 32-bit 
platforms, a 64-bit divide typically requires a library function which 
may not be present in the build (kernel or otherwise).

Implemented a targeted error message for timeouts returned from the 
Embedded Controller device driver. This is seen frequently enough to 
special-case an AE_TIME returned from an EC operation region access:
"Timeout from EC hardware or EC device driver"

Changed the "ACPI Exception" message prefix to "ACPI Error" so that all 
runtime error messages have the identical prefix.


2) iASL Compiler/Disassembler and Tools:

AcpiXtract: Fixed a problem with table header detection within the 
acpidump file. Processing a table could be ended early if a 0x40 (@) 
appears in the original binary table, resulting in the @ symbol appearing 
in the decoded ASCII field at the end of the acpidump text line. The 
symbol caused acpixtract to incorrectly think it had reached the end of 
the current table and the beginning of a new table.

AcpiXtract: Added an option (-f) to ignore some errors during table 
extraction. This initial implementation ignores non-ASCII and non-
printable characters found in the acpidump text file.

TestSuite(ASLTS)/AcpiExec: Fixed and restored the memory usage statistics 
for ASLTS. This feature is used to track memory allocations from 
different memory caches within the ACPICA code. At the end of an ASLTS 
run, these memory statistics are recorded and stored in a log file.

Debugger (user-space version): Implemented a simple "Background" command. 
Creates a new thread to execute a control method in the background, while 
control returns to the debugger prompt to allow additional commands.
Syntax: Background  [Arguments]


29 September 2017. Summary of changes for version 20170929:


1) ACPICA kernel-resident subsystem:

Redesigned and implemented an improved ASL While() loop timeout 
mechanism. This mechanism is used to prevent infinite loops in the kernel 
AML interpreter caused by either non-responsive hardware or incorrect AML 
code. The new implementation uses AcpiOsGetTimer instead of a simple 
maximum loop count, and is thus more accurate and constant across 
different machines. The default timeout is currently 30 seconds, but this 
may be adjusted later.

Renamed the ACPI_AML_INFINITE_LOOP exception to AE_AML_LOOP_TIMEOUT to 
better reflect the new implementation of the loop timeout mechanism.

Updated the AcpiGetTimerDuration interface to cleanup the 64-bit support 
and to fix an off-by-one error. Jung-uk Kim.

Fixed an EFI build problem by updating the makefiles to for a new file 
that was added, utstrsuppt.c


2) iASL Compiler/Disassembler and Tools:

Implemented full support for the PDTT, SDEV, and TPM2 ACPI tables. This 
includes support in the table disassembler, compiler, and template 
generator.

iASL: Added an exception for an illegal type of recursive method 
invocation. If a method creates named objects, the first recursive call 
will fail at runtime. This change adds an error detection at compile time 
to catch the problem up front. Note: Marking such a method as 
"serialized" will not help with this problem, because the same thread can 
acquire the method mutex more than once. Example compiler and runtime 
output:

Method (MTH1)
{
Name (INT1, 1)
MTH1 ()
}

dsdt.asl 22: MTH1 ()
Error6152 -  ^ Illegal recursive call to method
   that creates named objects (MTH1)

Previous runtime exception:
ACPI Error: [INT1] Namespace lookup failure,
AE_ALREADY_EXISTS (20170831/dswload2-465)

iASL: Updated support for External() opcodes to improve namespace 
management and error detection. These changes are related to issues seen 
with multiple-segment namespace pathnames within External declarations, 
such as below:

External(\_SB.PCI0.GFX0, DeviceObj)
External(\_SB.PCI0.GFX0.ALSI)

iASL: Implemented support for multi-line error/warning messages. This 
enables more detailed and helpful error messages as below, from the 
initial deployment for the duplicate names error:


CVS commit: src/external/gpl3/gcc/dist

2017-11-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Nov 12 00:36:48 UTC 2017

Modified Files:
src/external/gpl3/gcc/dist: LAST_UPDATED MD5SUMS NEWS config.sub
configure configure.ac
src/external/gpl3/gcc/dist/INSTALL: binaries.html build.html
configure.html download.html finalinstall.html gfdl.html index.html
old.html prerequisites.html specific.html test.html
src/external/gpl3/gcc/dist/gcc: ChangeLog Makefile.in auto-profile.c
builtins.c common.opt config.gcc diagnostic.c dwarf2out.c expr.c
gcc.c gengtype-lex.c graphite-isl-ast-to-gimple.c system.h
tree-cfg.c
src/external/gpl3/gcc/dist/gcc/c-family: c-opts.c
src/external/gpl3/gcc/dist/gcc/config/arm: arm.c arm.h arm.md freebsd.h
src/external/gpl3/gcc/dist/gcc/config/i386: cpuid.h driver-i386.c
i386.c i386.h pmm_malloc.h
src/external/gpl3/gcc/dist/gcc/config/pa: pa.h
src/external/gpl3/gcc/dist/gcc/config/rs6000: rs6000.c
src/external/gpl3/gcc/dist/gcc/config/sh: sh.c
src/external/gpl3/gcc/dist/gcc/config/sparc: sparc.md
src/external/gpl3/gcc/dist/gcc/doc: aot-compile.1 cppinternals.info
fsf-funding.7 gc-analyze.1 gccinstall.info gccint.info gcj-dbtool.1
gcj.1 gcj.info gcov.texi gfdl.7 gfortran.1 gij.1 gpl.7 grmic.1
invoke.texi jcf-dump.1 jv-convert.1 rebuild-gcj-db.1
src/external/gpl3/gcc/dist/libgcc: config.host
src/external/gpl3/gcc/dist/libgcc/config/xtensa: unwind-dw2-xtensa.c
src/external/gpl3/gcc/dist/libgomp: libgomp.info
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common:
sanitizer_common_interceptors.inc sanitizer_linux.cc
sanitizer_linux.h sanitizer_platform_limits_posix.cc
sanitizer_platform_limits_posix.h
src/external/gpl3/gcc/dist/libsanitizer/tsan: tsan_platform_linux.cc
src/external/gpl3/gcc/dist/libstdc++-v3: acinclude.m4 configure
src/external/gpl3/gcc/dist/libstdc++-v3/include/std: complex
Removed Files:
src/external/gpl3/gcc/dist/gcc/config/i386: pcommitintrin.h
stringop.opt

Log Message:
merge GCC 5.5.0.  this does not include updated man/info pages (yet).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/gpl3/gcc/dist/LAST_UPDATED \
src/external/gpl3/gcc/dist/MD5SUMS
cvs rdiff -u -r1.6 -r1.7 src/external/gpl3/gcc/dist/NEWS
cvs rdiff -u -r1.10 -r1.11 src/external/gpl3/gcc/dist/config.sub \
src/external/gpl3/gcc/dist/configure
cvs rdiff -u -r1.9 -r1.10 src/external/gpl3/gcc/dist/configure.ac
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc/dist/INSTALL/binaries.html \
src/external/gpl3/gcc/dist/INSTALL/download.html \
src/external/gpl3/gcc/dist/INSTALL/finalinstall.html \
src/external/gpl3/gcc/dist/INSTALL/gfdl.html \
src/external/gpl3/gcc/dist/INSTALL/index.html \
src/external/gpl3/gcc/dist/INSTALL/old.html \
src/external/gpl3/gcc/dist/INSTALL/test.html
cvs rdiff -u -r1.5 -r1.6 src/external/gpl3/gcc/dist/INSTALL/build.html \
src/external/gpl3/gcc/dist/INSTALL/configure.html \
src/external/gpl3/gcc/dist/INSTALL/prerequisites.html \
src/external/gpl3/gcc/dist/INSTALL/specific.html
cvs rdiff -u -r1.14 -r1.15 src/external/gpl3/gcc/dist/gcc/ChangeLog \
src/external/gpl3/gcc/dist/gcc/gcc.c
cvs rdiff -u -r1.13 -r1.14 src/external/gpl3/gcc/dist/gcc/Makefile.in
cvs rdiff -u -r1.2 -r1.3 src/external/gpl3/gcc/dist/gcc/auto-profile.c \
src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c
cvs rdiff -u -r1.9 -r1.10 src/external/gpl3/gcc/dist/gcc/builtins.c \
src/external/gpl3/gcc/dist/gcc/expr.c
cvs rdiff -u -r1.5 -r1.6 src/external/gpl3/gcc/dist/gcc/common.opt \
src/external/gpl3/gcc/dist/gcc/system.h
cvs rdiff -u -r1.36 -r1.37 src/external/gpl3/gcc/dist/gcc/config.gcc
cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gcc/dist/gcc/diagnostic.c
cvs rdiff -u -r1.7 -r1.8 src/external/gpl3/gcc/dist/gcc/dwarf2out.c \
src/external/gpl3/gcc/dist/gcc/tree-cfg.c
cvs rdiff -u -r1.6 -r1.7 src/external/gpl3/gcc/dist/gcc/gengtype-lex.c
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc/dist/gcc/c-family/c-opts.c
cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gcc/dist/gcc/config/arm/arm.c \
src/external/gpl3/gcc/dist/gcc/config/arm/freebsd.h
cvs rdiff -u -r1.14 -r1.15 src/external/gpl3/gcc/dist/gcc/config/arm/arm.h
cvs rdiff -u -r1.11 -r1.12 src/external/gpl3/gcc/dist/gcc/config/arm/arm.md
cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gcc/dist/gcc/config/i386/cpuid.h \
src/external/gpl3/gcc/dist/gcc/config/i386/pmm_malloc.h
cvs rdiff -u -r1.6 -r1.7 \
src/external/gpl3/gcc/dist/gcc/config/i386/driver-i386.c
cvs rdiff -u -r1.13 -r1.14 src/external/gpl3/gcc/dist/gcc/config/i386/i386.c
cvs rdiff -u -r1.5 -r1.6 src/external/gpl3/gcc/dist/gcc/config/i386/i386.h
cvs rdiff -u -r1.1.1.1 -r0 \
src/external/gpl3/gcc/dist/gcc/config/i386/pcommitintrin.h \
 

CVS commit: src/games/factor

2017-11-11 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Nov 11 23:48:44 UTC 2017

Modified Files:
src/games/factor: factor.6 factor.c

Log Message:
Add -h option to factor(6): duplicate factors are printed in
"human-readable" form of x^n.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/games/factor/factor.6
cvs rdiff -u -r1.27 -r1.28 src/games/factor/factor.c

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

Modified files:

Index: src/games/factor/factor.6
diff -u src/games/factor/factor.6:1.13 src/games/factor/factor.6:1.14
--- src/games/factor/factor.6:1.13	Thu Oct  2 21:36:37 2014
+++ src/games/factor/factor.6	Sat Nov 11 23:48:44 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: factor.6,v 1.13 2014/10/02 21:36:37 ast Exp $
+.\"	$NetBSD: factor.6,v 1.14 2017/11/11 23:48:44 rin Exp $
 .\"
 .\" Copyright (c) 1989, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -35,7 +35,7 @@
 .\"
 .\" By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\
 .\"
-.Dd May 15, 2010
+.Dd Nov 12, 2017
 .Dt FACTOR 6
 .Os
 .Sh NAME
@@ -43,6 +43,7 @@
 .Nd factor a number
 .Sh SYNOPSIS
 .Nm
+.Op Fl h
 .Op Ar number ...
 .Sh DESCRIPTION
 The
@@ -54,15 +55,20 @@ and the list of
 .Pq prime
 factors on a single line.
 Factors are listed in ascending order, and are preceded by a space.
-If a factor divides a value more than once, it will be printed more than once.
+By default, if a factor divides a value more than once, it will be
+printed more than once.
 .Pp
 When
 .Nm
-is invoked with one or more arguments, each argument will be factored.
+is invoked with one or more
+.Ar number
+arguments, each argument will be factored.
 .Pp
 When
 .Nm
-is invoked with no arguments,
+is invoked with no
+.Ar number
+arguments,
 .Nm
 reads numbers, one per line, from standard input, until end of file or error.
 Leading white-space and empty lines are ignored.
@@ -84,6 +90,15 @@ If
 .Nm
 is compiled without OpenSSL it is limited to the maximum value of
 .Vt unsigned long .
+.Pp
+The following option is available:
+.Bl -tag -width flag
+.It Fl h
+If the
+.Fl h
+flag is specified, factors will be printed in "human-readable" format.
+If a factor x divides a value n (>1) times, it will appear as x^n.
+.El
 .Sh DIAGNOSTICS
 Out of range or invalid input results in
 an appropriate error message to standard error.

Index: src/games/factor/factor.c
diff -u src/games/factor/factor.c:1.27 src/games/factor/factor.c:1.28
--- src/games/factor/factor.c:1.27	Thu Oct  2 21:36:37 2014
+++ src/games/factor/factor.c	Sat Nov 11 23:48:44 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: factor.c,v 1.27 2014/10/02 21:36:37 ast Exp $	*/
+/*	$NetBSD: factor.c,v 1.28 2017/11/11 23:48:44 rin Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)factor.c	8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: factor.c,v 1.27 2014/10/02 21:36:37 ast Exp $");
+__RCSID("$NetBSD: factor.c,v 1.28 2017/11/11 23:48:44 rin Exp $");
 #endif
 #endif /* not lint */
 
@@ -52,15 +52,18 @@ __RCSID("$NetBSD: factor.c,v 1.27 2014/1
  * By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\
  *
  * usage:
- *	factor [number] ...
+ *	factor [-h] [number] ...
  *
- * The form of the output is:
+ * By Default, the form of the output is:
  *
  *	number: factor1 factor1 factor2 factor3 factor3 factor3 ...
  *
  * where factor1 <= factor2 <= factor3 <= ...
  *
- * If no args are given, the list of numbers are read from stdin.
+ * If the -h flag is specified, the output is in "human-readable" format.
+ * Duplicate factors are printed in the form of x^n.
+ *
+ * If no number args are given, the list of numbers are read from stdin.
  */
 
 #include 
@@ -103,7 +106,7 @@ static int BN_dec2bn(BIGNUM **a, const c
 static BN_CTX *ctx;			/* just use a global context */
 #endif
 
-static void pr_fact(BIGNUM *);		/* print factors of a value */
+static void pr_fact(BIGNUM *, int);	/* print factors of a value */
 static void BN_print_dec_fp(FILE *, const BIGNUM *);
 static void usage(void) __dead;
 #ifdef HAVE_OPENSSL
@@ -132,7 +135,7 @@ int
 main(int argc, char *argv[])
 {
 	BIGNUM *val;
-	int ch;
+	int ch, hflag;
 	char *p, buf[LINE_MAX];		/* > max number of digits. */
 
 #ifdef HAVE_OPENSSL 
@@ -142,8 +145,12 @@ main(int argc, char *argv[])
 	if (val == NULL)
 		errx(1, "can't initialise bignum");
 
-	while ((ch = getopt(argc, argv, "")) != -1)
+	hflag = 0;
+	while ((ch = getopt(argc, argv, "h")) != -1)
 		switch (ch) {
+		case 'h':
+			hflag = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -166,7 +173,7 @@ main(int argc, char *argv[])
 errx(1, "negative numbers aren't permitted.");
 			if (BN_dec2bn(, buf) == 0)
 errx(1, "%s: illegal numeric format.", argv[0]);
-			pr_fact(val);
+			pr_fact(val, hflag);
 		}
 	/* Factor the arguments. */
 	else
@@ -175,7 +182,7 @@ main(int argc, char *argv[])
 		

CVS commit: src/sys/arch/x86/x86

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 21:05:58 UTC 2017

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Add KASSERT to confirm no change in xen intr MP-safety annotations.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/x86/x86/intr.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/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.111 src/sys/arch/x86/x86/intr.c:1.112
--- src/sys/arch/x86/x86/intr.c:1.111	Sat Nov 11 19:25:29 2017
+++ src/sys/arch/x86/x86/intr.c	Sat Nov 11 21:05:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.111 2017/11/11 19:25:29 riastradh Exp $	*/
+/*	$NetBSD: intr.c,v 1.112 2017/11/11 21:05:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.111 2017/11/11 19:25:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.112 2017/11/11 21:05:58 riastradh Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1226,6 +1226,13 @@ intr_establish_xname(int legacy_irq, str
 	if (pic->pic_type == PIC_XEN) {
 		struct intrhand *rih;
 
+		/*
+		 * event_set_handler interprets `level != IPL_VM' to
+		 * mean MP-safe, so we require the caller to match that
+		 * for the moment.
+		 */
+		KASSERT(known_mpsafe == (level != IPL_VM));
+
 		event_set_handler(pin, handler, arg, level, xname);
 
 		rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);



CVS commit: src/sys/arch/xen/xen

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 21:03:01 UTC 2017

Modified Files:
src/sys/arch/xen/xen: if_xennet_xenbus.c xbd_xenbus.c xbdback_xenbus.c
xencons.c xennetback_xenbus.c

Log Message:
Restore MP-safety annotations in intr_establish_xname.

In the old API, event_set_handler would assume MP-unsafe for IPL_VM
and MP-safe for all other levels (IPL_SCHED, IPL_HIGH).  The recent
Xen interrupt rototill started passing known_mpsafe=true for _all_
interrupt handlers.  Change it to known_mpsafe=false for the IPL_VM
(= IPL_CLOCK, IPL_NET) ones.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/xen/xen/xennetback_xenbus.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/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.72 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.73
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.72	Mon Nov  6 15:27:09 2017
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sat Nov 11 21:03:01 2017
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.72 2017/11/06 15:27:09 cherry Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.73 2017/11/11 21:03:01 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.72 2017/11/06 15:27:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.73 2017/11/11 21:03:01 riastradh Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -514,8 +514,8 @@ xennet_xenbus_resume(device_t dev, const
 		goto abort_resume;
 	aprint_verbose_dev(dev, "using event channel %d\n",
 	sc->sc_evtchn);
-	sc->sc_ih = intr_establish_xname(0, _pic, sc->sc_evtchn, IST_LEVEL, IPL_NET,
-	_handler, sc, true, device_xname(dev));
+	sc->sc_ih = intr_establish_xname(0, _pic, sc->sc_evtchn, IST_LEVEL,
+	IPL_NET, _handler, sc, false, device_xname(dev));
 	KASSERT(sc->sc_ih != NULL);
 	return true;
 

Index: src/sys/arch/xen/xen/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.77 src/sys/arch/xen/xen/xbd_xenbus.c:1.78
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.77	Mon Nov  6 15:27:09 2017
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Sat Nov 11 21:03:01 2017
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.77 2017/11/06 15:27:09 cherry Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.78 2017/11/11 21:03:01 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.77 2017/11/06 15:27:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.78 2017/11/11 21:03:01 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -452,8 +452,8 @@ xbd_xenbus_resume(device_t dev, const pm
 
 	aprint_verbose_dev(dev, "using event channel %d\n",
 	sc->sc_evtchn);
-	sc->sc_ih = intr_establish_xname(0, _pic, sc->sc_evtchn, IST_LEVEL, IPL_BIO, _handler, sc, true, "clock");
-	
+	sc->sc_ih = intr_establish_xname(0, _pic, sc->sc_evtchn, IST_LEVEL,
+	IPL_BIO, _handler, sc, false, device_xname(dev));
 	KASSERT(sc->sc_ih != NULL);
 
 again:

Index: src/sys/arch/xen/xen/xbdback_xenbus.c
diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.64 src/sys/arch/xen/xen/xbdback_xenbus.c:1.65
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.64	Mon Nov  6 15:27:09 2017
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sat Nov 11 21:03:01 2017
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.64 2017/11/06 15:27:09 cherry Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.65 2017/11/11 21:03:01 riastradh Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.64 2017/11/06 15:27:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.65 2017/11/11 21:03:01 riastradh Exp $");
 
 #include 
 #include 
@@ -637,8 +637,9 @@ xbdback_connect(struct xbdback_instance 
 	XENPRINTF(("xbdback %s: connect evchannel %d\n", xbusd->xbusd_path, xbdi->xbdi_evtchn));
 	xbdi->xbdi_evtchn = evop.u.bind_interdomain.local_port;
 
-	xbdi->xbdi_ih = intr_establish_xname(0, _pic, xbdi->xbdi_evtchn, IST_LEVEL, IPL_BIO,
-	xbdback_evthandler, xbdi, true, xbdi->xbdi_name);
+	xbdi->xbdi_ih = intr_establish_xname(0, _pic, xbdi->xbdi_evtchn,
+	IST_LEVEL, IPL_BIO, xbdback_evthandler, xbdi, false,
+	xbdi->xbdi_name);
 	KASSERT(xbdi->xbdi_ih != NULL);
 	aprint_verbose("xbd backend domain %d handle %#x (%d) "
 	"using event channel %d, protocol %s\n", xbdi->xbdi_domid,

Index: src/sys/arch/xen/xen/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.42 src/sys/arch/xen/xen/xencons.c:1.43

CVS commit: src/sys/arch/amd64/include

2017-11-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Nov 11 20:23:49 UTC 2017

Modified Files:
src/sys/arch/amd64/include: vmparam.h

Log Message:
bump PAGER_MAP_DEFAULT_SIZE to 512MB.  this should allow more
concurrent IOs to be possible, and i'm unable to see pager_map
contention any more.

other larger platforms should probably do this too.

ok chs@.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/amd64/include/vmparam.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/arch/amd64/include/vmparam.h
diff -u src/sys/arch/amd64/include/vmparam.h:1.43 src/sys/arch/amd64/include/vmparam.h:1.44
--- src/sys/arch/amd64/include/vmparam.h:1.43	Sat Jun 24 13:43:36 2017
+++ src/sys/arch/amd64/include/vmparam.h	Sat Nov 11 20:23:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.43 2017/06/24 13:43:36 joerg Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.44 2017/11/11 20:23:49 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -57,6 +57,12 @@
 #define	PAGE_MASK	(PAGE_SIZE - 1)
 
 /*
+ * Default pager_map of 16MB is awfully small.  There is have plenty
+ * of VA so use it.
+ */
+#define	PAGER_MAP_DEFAULT_SIZE (512 * 1024 * 1024)
+
+/*
  * USRSTACK is the top (end) of the user stack. Immediately above the
  * user stack resides the user structure, which is UPAGES long and contains
  * the kernel stack.



CVS commit: src/sys/arch/x86/x86

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 19:25:29 UTC 2017

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
KNF NFC


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/x86/x86/intr.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/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.110 src/sys/arch/x86/x86/intr.c:1.111
--- src/sys/arch/x86/x86/intr.c:1.110	Sat Nov 11 17:37:03 2017
+++ src/sys/arch/x86/x86/intr.c	Sat Nov 11 19:25:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.110 2017/11/11 17:37:03 riastradh Exp $	*/
+/*	$NetBSD: intr.c,v 1.111 2017/11/11 19:25:29 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.110 2017/11/11 17:37:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.111 2017/11/11 19:25:29 riastradh Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1210,7 +1210,7 @@ intr_num_handlers(struct intrsource *isp
 #else /* XEN */
 void *
 intr_establish(int legacy_irq, struct pic *pic, int pin,
-int type, int level, int (*handler)(void *) , void *arg,
+int type, int level, int (*handler)(void *), void *arg,
 bool known_mpsafe)
 {
 
@@ -1220,7 +1220,7 @@ intr_establish(int legacy_irq, struct pi
 
 void *
 intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
-int type, int level, int (*handler)(void *) , void *arg,
+int type, int level, int (*handler)(void *), void *arg,
 bool known_mpsafe, const char *xname)
 {
 	if (pic->pic_type == PIC_XEN) {
@@ -1228,8 +1228,7 @@ intr_establish_xname(int legacy_irq, str
 
 		event_set_handler(pin, handler, arg, level, xname);
 
-		rih = kmem_zalloc(sizeof(struct intrhand),
-	cold ? KM_NOSLEEP : KM_SLEEP);
+		rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);
 		if (rih == NULL) {
 			printf("%s: can't allocate handler info\n", __func__);
 			return NULL;
@@ -1244,7 +1243,6 @@ intr_establish_xname(int legacy_irq, str
 		 * All that goes away when we nuke event_set_handler()
 		 * et. al. and unify with x86/intr.c
 		 */
-		
 		rih->ih_pin = pin; /* port */
 		rih->ih_fun = handler;
 		rih->ih_arg = arg;
@@ -1273,8 +1271,9 @@ intr_establish_xname(int legacy_irq, str
 #else /* NIOAPIC */
 		return NULL;
 #endif /* NIOAPIC */
-	} else
+	} else {
 		snprintf(evname, sizeof(evname), "irq%d", legacy_irq);
+	}
 
 	evtchn = xen_pirq_alloc((intr_handle_t *)_irq, type);
 	pih = pirq_establish(legacy_irq & 0xff, evtchn, handler, arg, level,
@@ -1315,7 +1314,7 @@ intr_disestablish(struct intrhand *ih)
 	} else {
 		where = xc_unicast(0, intr_disestablish_xcall, ih, NULL, ci);
 		xc_wait(where);
-	}	
+	}
 	if (!msipic_is_msi_pic(isp->is_pic) && intr_num_handlers(isp) < 1) {
 		intr_free_io_intrsource_direct(isp);
 	}
@@ -1323,7 +1322,8 @@ intr_disestablish(struct intrhand *ih)
 	kmem_free(ih, sizeof(*ih));
 #else /* XEN */
 	if (ih->pic_type == PIC_XEN) {
-		event_remove_handler(ih->ih_pin, ih->ih_realfun, ih->ih_realarg);
+		event_remove_handler(ih->ih_pin, ih->ih_realfun,
+		ih->ih_realarg);
 		kmem_free(ih, sizeof(*ih));
 		return;
 	}



CVS commit: src/lib/libc/cdb

2017-11-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Nov 11 18:05:31 UTC 2017

Modified Files:
src/lib/libc/cdb: cdbw.c

Log Message:
Use a more efficient data structure for graph peeling.

New code is about 50% faster on amd64 and it consumes less memory.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/cdb/cdbw.c

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

Modified files:

Index: src/lib/libc/cdb/cdbw.c
diff -u src/lib/libc/cdb/cdbw.c:1.5 src/lib/libc/cdb/cdbw.c:1.6
--- src/lib/libc/cdb/cdbw.c:1.5	Sat Jul 21 22:49:37 2012
+++ src/lib/libc/cdb/cdbw.c	Sat Nov 11 18:05:31 2017
@@ -1,10 +1,10 @@
-/*	$NetBSD: cdbw.c,v 1.5 2012/07/21 22:49:37 joerg Exp $	*/
+/*	$NetBSD: cdbw.c,v 1.6 2017/11/11 18:05:31 alnsn Exp $	*/
 /*-
- * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
+ * Copyright (c) 2009, 2010, 2015 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Joerg Sonnenberger.
+ * by Joerg Sonnenberger and Alexander Nasonov.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: cdbw.c,v 1.5 2012/07/21 22:49:37 joerg Exp $");
+__RCSID("$NetBSD: cdbw.c,v 1.6 2017/11/11 18:05:31 alnsn Exp $");
 
 #include "namespace.h"
 
@@ -278,18 +278,31 @@ cdbw_stable_seeder(void)
 	return 0;
 }
 
-#define unused 0xU
+/*
+ * The algorithm below is based on paper
+ * Cache-Oblivious Peeling of Random Hypergraphs by Djamal Belazzougui,
+ * Paolo Boldi, Giuseppe Ottaviano, Rossano Venturini, and Sebastiano
+ * Vigna.
+ * http://zola.di.unipi.it/rossano/wp-content/papercite-data/pdf/dcc14.pdf
+ */
 
-struct vertex {
-	uint32_t l_edge, m_edge, r_edge;
+/*
+ * Data type for a valid oriented edge (v0, v1, v2), v1 < v2.
+ * The first vertex v0 is implicit and is determined by an index
+ * of the corresponding element in the state->oedges array.
+ * If the degree of v0 is greater than 1, other members don't
+ * make sense because they're a result of XORing multiple values.
+ */
+struct oedge {
+	uint32_t degree;   /* Degree of v0. */
+	uint32_t verts[2]; /* v1 and v2 */
+	uint32_t edge;
 };
 
 struct edge {
 	uint32_t idx;
 
 	uint32_t left, middle, right;
-	uint32_t l_prev, m_prev, l_next;
-	uint32_t r_prev, m_next, r_next;
 };
 
 struct state {
@@ -301,69 +314,49 @@ struct state {
 	uint32_t *g;
 	char *visited;
 
-	struct vertex *verts;
+	struct oedge *oedges;
 	struct edge *edges;
 	uint32_t output_index;
 	uint32_t *output_order;
 };
 
-static void
-remove_vertex(struct state *state, struct vertex *v)
+/*
+ * Add (delta == 1) or remove (delta == -1) the edge e from vertex v0.
+ */
+static inline void
+add_remove_edge(struct oedge *o, int delta, uint32_t e,
+uint32_t v0, uint32_t v1, uint32_t v2)
 {
-	struct edge *e;
-	struct vertex *vl, *vm, *vr;
 
-	if (v->l_edge != unused && v->m_edge != unused)
-		return;
-	if (v->l_edge != unused && v->r_edge != unused)
-		return;
-	if (v->m_edge != unused && v->r_edge != unused)
-		return;
-	if (v->l_edge == unused && v->m_edge == unused && v->r_edge == unused)
-		return;
-
-	if (v->l_edge != unused) {
-		e = >edges[v->l_edge];
-		if (e->l_next != unused)
-			return;
-	} else if (v->m_edge != unused) {
-		e = >edges[v->m_edge];
-		if (e->m_next != unused)
-			return;
-	} else {
-		if (v->r_edge == unused)
-			abort();
-		e = >edges[v->r_edge];
-		if (e->r_next != unused)
-			return;
-	}
-
-	state->output_order[--state->output_index] = e - state->edges;
-
-	vl = >verts[e->left];
-	vm = >verts[e->middle];
-	vr = >verts[e->right];
+	o[v0].verts[v1 < v2 ? 0 : 1] ^= v1;
+	o[v0].verts[v1 < v2 ? 1 : 0] ^= v2;
+	o[v0].degree += delta;
+	o[v0].edge ^= e;
+}
 
-	if (e->l_prev == unused)
-		vl->l_edge = e->l_next;
-	else
-		state->edges[e->l_prev].l_next = e->l_next;
-	if (e->l_next != unused)
-		state->edges[e->l_next].l_prev = e->l_prev;
+static inline void
+add_edge(struct oedge *o, uint32_t e,
+uint32_t v0, uint32_t v1, uint32_t v2)
+{
 
-	if (e->m_prev == unused)
-		vm->m_edge = e->m_next;
-	else
-		state->edges[e->m_prev].m_next = e->m_next;
-	if (e->m_next != unused)
-		state->edges[e->m_next].m_prev = e->m_prev;
+	add_remove_edge(o, 1, e, v0, v1, v2);
+}
 
-	if (e->r_prev == unused)
-		vr->r_edge = e->r_next;
-	else
-		state->edges[e->r_prev].r_next = e->r_next;
-	if (e->r_next != unused)
-		state->edges[e->r_next].r_prev = e->r_prev;
+static inline void
+remove_vertex(struct state *state, uint32_t v0)
+{
+	uint32_t e, v1, v2;
+	struct oedge *o = state->oedges;
+
+	if (o[v0].degree == 1) {
+		e = o[v0].edge;
+		v1 = o[v0].verts[0];
+		v2 = o[v0].verts[1];
+		o[v0].degree = 0;
+		add_remove_edge(o, -1, e, v1, v0, v2);
+		add_remove_edge(o, -1, e, v2, v0, v1);
+		state->output_order[--state->output_index] = e;
+	}
 }
 
 static int

CVS commit: src/sys/arch/x86/x86

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 17:37:03 UTC 2017

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Free ih when done.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/sys/arch/x86/x86/intr.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/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.109 src/sys/arch/x86/x86/intr.c:1.110
--- src/sys/arch/x86/x86/intr.c:1.109	Sat Nov 11 17:26:51 2017
+++ src/sys/arch/x86/x86/intr.c	Sat Nov 11 17:37:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.109 2017/11/11 17:26:51 riastradh Exp $	*/
+/*	$NetBSD: intr.c,v 1.110 2017/11/11 17:37:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.109 2017/11/11 17:26:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.110 2017/11/11 17:37:03 riastradh Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1324,6 +1324,7 @@ intr_disestablish(struct intrhand *ih)
 #else /* XEN */
 	if (ih->pic_type == PIC_XEN) {
 		event_remove_handler(ih->ih_pin, ih->ih_realfun, ih->ih_realarg);
+		kmem_free(ih, sizeof(*ih));
 		return;
 	}
 #if defined(DOM0OPS)



CVS commit: src/sys/arch/x86/x86

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 17:26:51 UTC 2017

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Pass xname through Xen intr_establish_xname to event_set_handler.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/x86/x86/intr.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/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.108 src/sys/arch/x86/x86/intr.c:1.109
--- src/sys/arch/x86/x86/intr.c:1.108	Sat Nov 11 07:52:41 2017
+++ src/sys/arch/x86/x86/intr.c	Sat Nov 11 17:26:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.108 2017/11/11 07:52:41 riastradh Exp $	*/
+/*	$NetBSD: intr.c,v 1.109 2017/11/11 17:26:51 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.108 2017/11/11 07:52:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.109 2017/11/11 17:26:51 riastradh Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1209,24 +1209,24 @@ intr_num_handlers(struct intrsource *isp
 
 #else /* XEN */
 void *
-intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
+intr_establish(int legacy_irq, struct pic *pic, int pin,
 int type, int level, int (*handler)(void *) , void *arg,
-bool known_mpsafe, const char *xname)
+bool known_mpsafe)
 {
-	/* XXX xname registration not supported */
-	return intr_establish(legacy_irq, pic, pin, type, level, handler, arg,
-	known_mpsafe);
+
+	return intr_establish_xname(legacy_irq, pic, pin, type, level,
+	handler, arg, known_mpsafe, "XEN");
 }
 
 void *
-intr_establish(int legacy_irq, struct pic *pic, int pin,
+intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
 int type, int level, int (*handler)(void *) , void *arg,
-bool known_mpsafe)
+bool known_mpsafe, const char *xname)
 {
 	if (pic->pic_type == PIC_XEN) {
 		struct intrhand *rih;
-		event_set_handler(pin, handler,
-		arg, level, "XEN");
+
+		event_set_handler(pin, handler, arg, level, xname);
 
 		rih = kmem_zalloc(sizeof(struct intrhand),
 	cold ? KM_NOSLEEP : KM_SLEEP);



CVS commit: src/sys/arch/xen/xen

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 17:02:53 UTC 2017

Modified Files:
src/sys/arch/xen/xen: evtchn.c

Log Message:
Back out previous KASSERTMSG for now.

The immediate problem appears to have been elsewhere, in the wrong
interrupt level passed by the Xen-specific intr_establish to
event_set_handler.

We should maybe restore these assertions later, but at least one was
violated before cherry's interrupt rototill anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/xen/xen/evtchn.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/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.77 src/sys/arch/xen/xen/evtchn.c:1.78
--- src/sys/arch/xen/xen/evtchn.c:1.77	Sat Nov 11 08:23:50 2017
+++ src/sys/arch/xen/xen/evtchn.c	Sat Nov 11 17:02:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.77 2017/11/11 08:23:50 riastradh Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.78 2017/11/11 17:02:53 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.77 2017/11/11 08:23:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.78 2017/11/11 17:02:53 riastradh Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -386,11 +386,6 @@ evtchn_do_event(int evtch, struct intrfr
 		ci->ci_ilevel = ih->ih_level;
 		ih_fun = (void *)ih->ih_fun;
 		ih_fun(ih->ih_arg, regs);
-		KASSERTMSG(ci->ci_ilevel == ih->ih_level,
-		"event handler %p for evtsource[%d] (%s) changed ipl:"
-		" %d != %d",
-		ih->ih_realfun, evtch, evtsource[evtch]->ev_evname,
-		ci->ci_ilevel, ih->ih_level);
 		ih = ih->ih_evt_next;
 	}
 	mutex_spin_exit([evtch]);
@@ -415,13 +410,6 @@ splx:
 	sti();
 	ih_fun = (void *)ih->ih_fun;
 	ih_fun(ih->ih_arg, regs);
-	KASSERTMSG(ci->ci_ilevel == i,
-	"interrupt handler %p"
-	" for interrupt source %s"
-	" changed ipl: %d != %d",
-	ih->ih_realfun,
-	ci->ci_isources[i]->is_xname,
-	ci->ci_ilevel, i);
 	cli();
 }
 hypervisor_enable_ipl(i);



CVS commit: src/sys/dev/ic

2017-11-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Nov 11 16:49:13 UTC 2017

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
change several of error logs in ahci_intr_port() to use AHCIDEBUG_PRINT()
so they don't show unless debugging; e.g. the AHCI_P_IX_TFES seems to be
triggered normally by ATAPI with 'Media Change' error

adresses 'dmesg spam: ahcisata0 port 1: active 2 is 0x4001 tfd 0x2051'
thread by Stefan Hertenberger on current-users@


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.59 src/sys/dev/ic/ahcisata_core.c:1.60
--- src/sys/dev/ic/ahcisata_core.c:1.59	Fri Oct 20 07:06:07 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Nov 11 16:49:13 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.59 2017/10/20 07:06:07 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.60 2017/11/11 16:49:13 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.59 2017/10/20 07:06:07 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.60 2017/11/11 16:49:13 jdolecek Exp $");
 
 #include 
 #include 
@@ -572,6 +572,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 
 	is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
 	AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), is);
+
 	AHCIDEBUG_PRINT((
 	"ahci_intr_port %s port %d is 0x%x CI 0x%x SACT 0x%x TFD 0x%x\n",
 	AHCINAME(sc),
@@ -604,8 +605,10 @@ ahci_intr_port(struct ahci_softc *sc, st
 >> AHCI_P_CMD_CCS_SHIFT;
 			}
 
-			aprint_error("%s port %d: active %x is 0x%x tfd 0x%x\n",
-			AHCINAME(sc), chp->ch_channel, sact, is, tfd);
+			AHCIDEBUG_PRINT((
+			"%s port %d: TFE: sact 0x%x is 0x%x tfd 0x%x\n",
+			AHCINAME(sc), chp->ch_channel, sact, is, tfd),
+			DEBUG_INTR);
 		} else {
 			/* mark an error, and set BSY */
 			tfd = (WDCE_ABRT << AHCI_P_TFD_ERR_SHIFT) |
@@ -613,9 +616,10 @@ ahci_intr_port(struct ahci_softc *sc, st
 		}
 
 		if (is & AHCI_P_IX_IFS) {
-			aprint_error("%s port %d: SERR 0x%x\n",
+			AHCIDEBUG_PRINT(("%s port %d: SERR 0x%x\n",
 			AHCINAME(sc), chp->ch_channel,
-			AHCI_READ(sc, AHCI_P_SERR(chp->ch_channel)));
+			AHCI_READ(sc, AHCI_P_SERR(chp->ch_channel))),
+			DEBUG_INTR);
 		}
 
 		if (!achp->ahcic_recovering)
@@ -628,8 +632,8 @@ ahci_intr_port(struct ahci_softc *sc, st
 			if (!achp->ahcic_recovering)
 recover = true;
 
-			aprint_error("%s port %d: transfer aborted 0x%x\n",
-			AHCINAME(sc), chp->ch_channel, tfd);
+			AHCIDEBUG_PRINT(("%s port %d: transfer aborted 0x%x\n",
+			AHCINAME(sc), chp->ch_channel, tfd), DEBUG_INTR);
 
 		}
 	} else {



CVS commit: src/external/bsd/atf/dist/tools

2017-11-11 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sat Nov 11 14:16:06 UTC 2017

Modified Files:
src/external/bsd/atf/dist/tools: fs.cpp

Log Message:
don't use auto_ptr with memory allocated by C code
silences alloc-dealloc-mismatch warnings from asan

from joerg


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/atf/dist/tools/fs.cpp

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

Modified files:

Index: src/external/bsd/atf/dist/tools/fs.cpp
diff -u src/external/bsd/atf/dist/tools/fs.cpp:1.3 src/external/bsd/atf/dist/tools/fs.cpp:1.4
--- src/external/bsd/atf/dist/tools/fs.cpp:1.3	Tue Feb 11 18:13:45 2014
+++ src/external/bsd/atf/dist/tools/fs.cpp	Sat Nov 11 14:16:06 2017
@@ -707,11 +707,17 @@ impl::cleanup(const path& p)
 impl::path
 impl::get_current_dir(void)
 {
-std::auto_ptr< char > cwd;
-cwd.reset(getcwd(NULL, 0));
-if (cwd.get() == NULL)
+char *cwd = getcwd(NULL, 0);
+if (cwd == NULL)
 throw tools::system_error(IMPL_NAME "::get_current_dir()",
 "getcwd() failed", errno);
 
-return path(cwd.get());
+try {
+impl::path p(cwd);
+free(cwd);
+return p;
+} catch(...) {
+free(cwd);
+throw;
+}
 }



CVS commit: src/sys/arch/amd64/stand/prekern

2017-11-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 11 13:50:57 UTC 2017

Modified Files:
src/sys/arch/amd64/stand/prekern: mm.c

Log Message:
Detect collisions from bootspace directly.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/stand/prekern/mm.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/amd64/stand/prekern/mm.c
diff -u src/sys/arch/amd64/stand/prekern/mm.c:1.10 src/sys/arch/amd64/stand/prekern/mm.c:1.11
--- src/sys/arch/amd64/stand/prekern/mm.c:1.10	Sat Nov 11 12:51:06 2017
+++ src/sys/arch/amd64/stand/prekern/mm.c	Sat Nov 11 13:50:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mm.c,v 1.10 2017/11/11 12:51:06 maxv Exp $	*/
+/*	$NetBSD: mm.c,v 1.11 2017/11/11 13:50:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -238,18 +238,12 @@ mm_map_head()
 static vaddr_t
 mm_randva_kregion(size_t size)
 {
-	static struct {
-		vaddr_t sva;
-		vaddr_t eva;
-	} regions[4];
-	static size_t idx = 0;
+	vaddr_t sva, eva;
 	vaddr_t randva;
 	uint64_t rnd;
 	size_t i;
 	bool ok;
 
-	ASSERT(idx < 4);
-
 	while (1) {
 		rnd = mm_rand_num64();
 		randva = rounddown(KASLR_WINDOW_BASE +
@@ -257,14 +251,18 @@ mm_randva_kregion(size_t size)
 
 		/* Detect collisions */
 		ok = true;
-		for (i = 0; i < idx; i++) {
-			if ((regions[i].sva <= randva) &&
-			(randva < regions[i].eva)) {
+		for (i = 0; i < BTSPACE_NSEGS; i++) {
+			if (bootspace.segs[i].type == BTSEG_NONE) {
+continue;
+			}
+			sva = bootspace.segs[i].va;
+			eva = sva + bootspace.segs[i].sz;
+
+			if ((sva <= randva) && (randva < eva)) {
 ok = false;
 break;
 			}
-			if ((regions[i].sva < randva + size) &&
-			(randva + size <= regions[i].eva)) {
+			if ((sva < randva + size) && (randva + size <= eva)) {
 ok = false;
 break;
 			}
@@ -274,10 +272,6 @@ mm_randva_kregion(size_t size)
 		}
 	}
 
-	regions[idx].eva = randva;
-	regions[idx].sva = randva + size;
-	idx++;
-
 	mm_map_tree(randva, randva + size);
 
 	return randva;



CVS commit: src/sys/arch

2017-11-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 11 12:51:06 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/amd64/stand/prekern: mm.c prekern.h
src/sys/arch/i386/i386: machdep.c
src/sys/arch/x86/include: pmap.h
src/sys/arch/x86/x86: db_memrw.c pmap.c

Log Message:
Modify the layout of the bootspace structure, in such a way that it can
contain several kernel segments of the same type (eg several .text
segments). Some parts are still a bit messy but will be cleaned up soon.

I cannot compile-test this change on i386, but it seems fine enough.

NOTE: you need to rebuild and reinstall a new prekern after this change.


To generate a diff of this commit:
cvs rdiff -u -r1.275 -r1.276 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/stand/prekern/mm.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/stand/prekern/prekern.h
cvs rdiff -u -r1.798 -r1.799 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/db_memrw.c
cvs rdiff -u -r1.263 -r1.264 src/sys/arch/x86/x86/pmap.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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.275 src/sys/arch/amd64/amd64/machdep.c:1.276
--- src/sys/arch/amd64/amd64/machdep.c:1.275	Sat Nov  4 08:50:47 2017
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Nov 11 12:51:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.276 2017/11/11 12:51:06 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.276 2017/11/11 12:51:06 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1507,6 +1507,7 @@ init_bootspace(void)
 	extern char __rodata_start;
 	extern char __data_start;
 	extern char __kernel_end;
+	size_t i = 0;
 
 	memset(, 0, sizeof(bootspace));
 
@@ -1514,17 +1515,23 @@ init_bootspace(void)
 	bootspace.head.pa = KERNTEXTOFF - KERNBASE;
 	bootspace.head.sz = 0;
 
-	bootspace.text.va = KERNTEXTOFF;
-	bootspace.text.pa = KERNTEXTOFF - KERNBASE;
-	bootspace.text.sz = (size_t)&__rodata_start - KERNTEXTOFF;
-
-	bootspace.rodata.va = (vaddr_t)&__rodata_start;
-	bootspace.rodata.pa = (paddr_t)&__rodata_start - KERNBASE;
-	bootspace.rodata.sz = (size_t)&__data_start - (size_t)&__rodata_start;
-
-	bootspace.data.va = (vaddr_t)&__data_start;
-	bootspace.data.pa = (paddr_t)&__data_start - KERNBASE;
-	bootspace.data.sz = (size_t)&__kernel_end - (size_t)&__data_start;
+	bootspace.segs[i].type = BTSEG_TEXT;
+	bootspace.segs[i].va = KERNTEXTOFF;
+	bootspace.segs[i].pa = KERNTEXTOFF - KERNBASE;
+	bootspace.segs[i].sz = (size_t)&__rodata_start - KERNTEXTOFF;
+	i++;
+
+	bootspace.segs[i].type = BTSEG_RODATA;
+	bootspace.segs[i].va = (vaddr_t)&__rodata_start;
+	bootspace.segs[i].pa = (paddr_t)&__rodata_start - KERNBASE;
+	bootspace.segs[i].sz = (size_t)&__data_start - (size_t)&__rodata_start;
+	i++;
+
+	bootspace.segs[i].type = BTSEG_DATA;
+	bootspace.segs[i].va = (vaddr_t)&__data_start;
+	bootspace.segs[i].pa = (paddr_t)&__data_start - KERNBASE;
+	bootspace.segs[i].sz = (size_t)&__kernel_end - (size_t)&__data_start;
+	i++;
 
 	bootspace.boot.va = (vaddr_t)&__kernel_end;
 	bootspace.boot.pa = (paddr_t)&__kernel_end - KERNBASE;
@@ -2009,6 +2016,7 @@ mm_md_kernacc(void *ptr, vm_prot_t prot,
 {
 	const vaddr_t v = (vaddr_t)ptr;
 	vaddr_t kva, kva_end;
+	size_t i;
 
 	kva = bootspace.head.va;
 	kva_end = kva + bootspace.head.sz;
@@ -2017,33 +2025,19 @@ mm_md_kernacc(void *ptr, vm_prot_t prot,
 		return 0;
 	}
 
-	kva = bootspace.text.va;
-	kva_end = kva + bootspace.text.sz;
-	if (v >= kva && v < kva_end) {
-		*handled = true;
-		if (prot & VM_PROT_WRITE) {
-			return EFAULT;
-		}
-		return 0;
-	}
-
-	kva = bootspace.rodata.va;
-	kva_end = kva + bootspace.rodata.sz;
-	if (v >= kva && v < kva_end) {
+	for (i = 0; i < BTSPACE_NSEGS; i++) {
+		kva = bootspace.segs[i].va;
+		kva_end = kva + bootspace.segs[i].sz;
 		*handled = true;
-		if (prot & VM_PROT_WRITE) {
-			return EFAULT;
+		if (bootspace.segs[i].type == BTSEG_TEXT ||
+		bootspace.segs[i].type == BTSEG_RODATA) {
+			if (prot & VM_PROT_WRITE) {
+return EFAULT;
+			}
 		}
 		return 0;
 	}
 
-	kva = bootspace.data.va;
-	kva_end = kva + bootspace.data.sz;
-	if (v >= kva && v < kva_end) {
-		*handled = true;
-		return 0;
-	}
-
 	kva = bootspace.boot.va;
 	kva_end = kva + bootspace.boot.sz;
 	if (v >= kva && v < kva_end) {

Index: src/sys/arch/amd64/stand/prekern/mm.c
diff -u src/sys/arch/amd64/stand/prekern/mm.c:1.9 src/sys/arch/amd64/stand/prekern/mm.c:1.10
--- src/sys/arch/amd64/stand/prekern/mm.c:1.9	Thu Nov  9 15:24:39 2017
+++ 

CVS commit: src/sys/arch

2017-11-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 11 11:00:47 UTC 2017

Modified Files:
src/sys/arch/x86/x86: cpu.c fpu.c identcpu.c
src/sys/arch/xen/x86: cpu.c

Log Message:
Recommit

http://mail-index.netbsd.org/source-changes/2017/11/08/msg089525.html

but use __INITIAL_MXCSR_MASK__ on Xen until someone figures out what's
wrong with the Xen fpu.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/x86/x86/fpu.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/xen/x86/cpu.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/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.140 src/sys/arch/x86/x86/cpu.c:1.141
--- src/sys/arch/x86/x86/cpu.c:1.140	Sat Nov 11 09:10:19 2017
+++ src/sys/arch/x86/x86/cpu.c	Sat Nov 11 11:00:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.140 2017/11/11 09:10:19 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.141 2017/11/11 11:00:46 maxv Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.140 2017/11/11 09:10:19 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.141 2017/11/11 11:00:46 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -541,6 +541,7 @@ cpu_childdetached(device_t self, device_
 void
 cpu_init(struct cpu_info *ci)
 {
+	extern int x86_fpu_save;
 	uint32_t cr4 = 0;
 
 	lcr0(rcr0() | CR0_WP);
@@ -584,6 +585,10 @@ cpu_init(struct cpu_info *ci)
 		lcr4(cr4);
 	}
 
+	if (x86_fpu_save >= FPU_SAVE_FXSAVE) {
+		fpuinit_mxcsr_mask();
+	}
+
 	/* If xsave is enabled, enable all fpu features */
 	if (cr4 & CR4_OSXSAVE)
 		wrxcr(0, x86_xsave_features & XCR0_FPU);

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.26 src/sys/arch/x86/x86/fpu.c:1.27
--- src/sys/arch/x86/x86/fpu.c:1.26	Sat Nov 11 09:10:19 2017
+++ src/sys/arch/x86/x86/fpu.c	Sat Nov 11 11:00:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.26 2017/11/11 09:10:19 bouyer Exp $	*/
+/*	$NetBSD: fpu.c,v 1.27 2017/11/11 11:00:46 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.26 2017/11/11 09:10:19 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.27 2017/11/11 11:00:46 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -235,21 +235,20 @@ fpuinit_mxcsr_mask(void)
 {
 #ifndef XEN
 	union savefpu fpusave __aligned(16);
-	u_long cr0, psl;
+	u_long psl;
 
 	memset(, 0, sizeof(fpusave));
 
 	/* Disable interrupts, and enable FPU */
 	psl = x86_read_psl();
 	x86_disable_intr();
-	cr0 = rcr0();
-	lcr0(cr0 & ~(CR0_EM|CR0_TS));
+	clts();
 
 	/* Fill in the FPU area */
 	fxsave();
 
 	/* Restore previous state */
-	lcr0(cr0);
+	stts();
 	x86_write_psl(psl);
 
 	if (fpusave.sv_xmm.fx_mxcsr_mask == 0) {
@@ -258,9 +257,6 @@ fpuinit_mxcsr_mask(void)
 		x86_fpu_mxcsr_mask = fpusave.sv_xmm.fx_mxcsr_mask;
 	}
 #else
-	/*
-	 * XXX: Does the detection above work on Xen?
-	 */
 	x86_fpu_mxcsr_mask = __INITIAL_MXCSR_MASK__;
 #endif
 }

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.66 src/sys/arch/x86/x86/identcpu.c:1.67
--- src/sys/arch/x86/x86/identcpu.c:1.66	Sat Nov 11 09:10:19 2017
+++ src/sys/arch/x86/x86/identcpu.c	Sat Nov 11 11:00:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.66 2017/11/11 09:10:19 bouyer Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.67 2017/11/11 11:00:46 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.66 2017/11/11 09:10:19 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.67 2017/11/11 11:00:46 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -753,8 +753,6 @@ cpu_probe_fpu(struct cpu_info *ci)
 
 	x86_fpu_save = FPU_SAVE_FXSAVE;
 
-	fpuinit_mxcsr_mask();
-
 	/* See if xsave (for AVX) is supported */
 	if ((ci->ci_feat_val[1] & CPUID2_XSAVE) == 0)
 		return;

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.115 src/sys/arch/xen/x86/cpu.c:1.116
--- src/sys/arch/xen/x86/cpu.c:1.115	Sat Nov 11 09:10:19 2017
+++ src/sys/arch/xen/x86/cpu.c	Sat Nov 11 11:00:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.115 2017/11/11 09:10:19 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.116 2017/11/11 11:00:47 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.115 2017/11/11 09:10:19 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.116 2017/11/11 11:00:47 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -540,6 +540,10 @@ cpu_init(struct cpu_info *ci)
 			lcr4(rcr4() | CR4_OSXMMEXCPT);
 	}
 
+	if (x86_fpu_save >= FPU_SAVE_FXSAVE) 

CVS commit: src/sys/arch

2017-11-11 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Nov 11 09:10:19 UTC 2017

Modified Files:
src/sys/arch/x86/x86: cpu.c fpu.c identcpu.c
src/sys/arch/xen/x86: cpu.c

Log Message:
Revert http://mail-index.netbsd.org/source-changes/2017/11/08/msg089525.html,
it breaks Xen:
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/amd64/201711082340Z_anita.txt


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/x86/fpu.c
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/xen/x86/cpu.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/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.139 src/sys/arch/x86/x86/cpu.c:1.140
--- src/sys/arch/x86/x86/cpu.c:1.139	Wed Nov  8 17:52:22 2017
+++ src/sys/arch/x86/x86/cpu.c	Sat Nov 11 09:10:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.139 2017/11/08 17:52:22 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.140 2017/11/11 09:10:19 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.139 2017/11/08 17:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.140 2017/11/11 09:10:19 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -541,7 +541,6 @@ cpu_childdetached(device_t self, device_
 void
 cpu_init(struct cpu_info *ci)
 {
-	extern int x86_fpu_save;
 	uint32_t cr4 = 0;
 
 	lcr0(rcr0() | CR0_WP);
@@ -585,10 +584,6 @@ cpu_init(struct cpu_info *ci)
 		lcr4(cr4);
 	}
 
-	if (x86_fpu_save >= FPU_SAVE_FXSAVE) {
-		fpuinit_mxcsr_mask();
-	}
-
 	/* If xsave is enabled, enable all fpu features */
 	if (cr4 & CR4_OSXSAVE)
 		wrxcr(0, x86_xsave_features & XCR0_FPU);

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.25 src/sys/arch/x86/x86/fpu.c:1.26
--- src/sys/arch/x86/x86/fpu.c:1.25	Wed Nov  8 17:52:22 2017
+++ src/sys/arch/x86/x86/fpu.c	Sat Nov 11 09:10:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.25 2017/11/08 17:52:22 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.26 2017/11/11 09:10:19 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.25 2017/11/08 17:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.26 2017/11/11 09:10:19 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -233,21 +233,23 @@ fpuinit(struct cpu_info *ci)
 void
 fpuinit_mxcsr_mask(void)
 {
+#ifndef XEN
 	union savefpu fpusave __aligned(16);
-	u_long psl;
+	u_long cr0, psl;
 
 	memset(, 0, sizeof(fpusave));
 
 	/* Disable interrupts, and enable FPU */
 	psl = x86_read_psl();
 	x86_disable_intr();
-	clts();
+	cr0 = rcr0();
+	lcr0(cr0 & ~(CR0_EM|CR0_TS));
 
 	/* Fill in the FPU area */
 	fxsave();
 
 	/* Restore previous state */
-	stts();
+	lcr0(cr0);
 	x86_write_psl(psl);
 
 	if (fpusave.sv_xmm.fx_mxcsr_mask == 0) {
@@ -255,6 +257,12 @@ fpuinit_mxcsr_mask(void)
 	} else {
 		x86_fpu_mxcsr_mask = fpusave.sv_xmm.fx_mxcsr_mask;
 	}
+#else
+	/*
+	 * XXX: Does the detection above work on Xen?
+	 */
+	x86_fpu_mxcsr_mask = __INITIAL_MXCSR_MASK__;
+#endif
 }
 
 /*

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.65 src/sys/arch/x86/x86/identcpu.c:1.66
--- src/sys/arch/x86/x86/identcpu.c:1.65	Wed Nov  8 17:52:22 2017
+++ src/sys/arch/x86/x86/identcpu.c	Sat Nov 11 09:10:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.65 2017/11/08 17:52:22 maxv Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.66 2017/11/11 09:10:19 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.65 2017/11/08 17:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.66 2017/11/11 09:10:19 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -753,6 +753,8 @@ cpu_probe_fpu(struct cpu_info *ci)
 
 	x86_fpu_save = FPU_SAVE_FXSAVE;
 
+	fpuinit_mxcsr_mask();
+
 	/* See if xsave (for AVX) is supported */
 	if ((ci->ci_feat_val[1] & CPUID2_XSAVE) == 0)
 		return;

Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.114 src/sys/arch/xen/x86/cpu.c:1.115
--- src/sys/arch/xen/x86/cpu.c:1.114	Sat Nov 11 06:16:52 2017
+++ src/sys/arch/xen/x86/cpu.c	Sat Nov 11 09:10:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.114 2017/11/11 06:16:52 riastradh Exp $	*/
+/*	$NetBSD: cpu.c,v 1.115 2017/11/11 09:10:19 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.114 2017/11/11 06:16:52 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.115 2017/11/11 09:10:19 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -540,10 +540,6 @@ cpu_init(struct cpu_info *ci)
 			

CVS commit: src/sys/arch/xen/xen

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 08:23:50 UTC 2017

Modified Files:
src/sys/arch/xen/xen: evtchn.c

Log Message:
Add kasserts to help diagnose xen interrupt level bug.

https://mail-index.netbsd.org/tech-kern/2017/11/09/msg022571.html


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/xen/xen/evtchn.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/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.76 src/sys/arch/xen/xen/evtchn.c:1.77
--- src/sys/arch/xen/xen/evtchn.c:1.76	Sat Nov 11 08:22:08 2017
+++ src/sys/arch/xen/xen/evtchn.c	Sat Nov 11 08:23:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.76 2017/11/11 08:22:08 riastradh Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.77 2017/11/11 08:23:50 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.76 2017/11/11 08:22:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.77 2017/11/11 08:23:50 riastradh Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -386,6 +386,11 @@ evtchn_do_event(int evtch, struct intrfr
 		ci->ci_ilevel = ih->ih_level;
 		ih_fun = (void *)ih->ih_fun;
 		ih_fun(ih->ih_arg, regs);
+		KASSERTMSG(ci->ci_ilevel == ih->ih_level,
+		"event handler %p for evtsource[%d] (%s) changed ipl:"
+		" %d != %d",
+		ih->ih_realfun, evtch, evtsource[evtch]->ev_evname,
+		ci->ci_ilevel, ih->ih_level);
 		ih = ih->ih_evt_next;
 	}
 	mutex_spin_exit([evtch]);
@@ -410,6 +415,13 @@ splx:
 	sti();
 	ih_fun = (void *)ih->ih_fun;
 	ih_fun(ih->ih_arg, regs);
+	KASSERTMSG(ci->ci_ilevel == i,
+	"interrupt handler %p"
+	" for interrupt source %s"
+	" changed ipl: %d != %d",
+	ih->ih_realfun,
+	ci->ci_isources[i]->is_xname,
+	ci->ci_ilevel, i);
 	cli();
 }
 hypervisor_enable_ipl(i);



CVS commit: src/sys/arch/xen/xen

2017-11-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 11 08:22:08 UTC 2017

Modified Files:
src/sys/arch/xen/xen: evtchn.c

Log Message:
#if DIAGNOSTIC panic ---> KASSERTMSG


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/xen/xen/evtchn.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/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.75 src/sys/arch/xen/xen/evtchn.c:1.76
--- src/sys/arch/xen/xen/evtchn.c:1.75	Fri Nov 10 19:24:17 2017
+++ src/sys/arch/xen/xen/evtchn.c	Sat Nov 11 08:22:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.75 2017/11/10 19:24:17 riastradh Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.76 2017/11/11 08:22:08 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.75 2017/11/10 19:24:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.76 2017/11/11 08:22:08 riastradh Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -314,12 +314,9 @@ evtchn_do_event(int evtch, struct intrfr
 	int i;
 	uint32_t iplbit;
 
-#ifdef DIAGNOSTIC
-	if (evtch >= NR_EVENT_CHANNELS) {
-		printf("event number %d > NR_IRQS\n", evtch);
-		panic("evtchn_do_event");
-	}
-#endif
+	KASSERTMSG(evtch >= 0, "negative evtch: %d", evtch);
+	KASSERTMSG(evtch < NR_EVENT_CHANNELS,
+	"evtch number %d > NR_EVENT_CHANNELS", evtch);
 
 #ifdef IRQ_DEBUG
 	if (evtch == IRQ_DEBUG)
@@ -337,11 +334,7 @@ evtchn_do_event(int evtch, struct intrfr
 		return 0;
 	}
 
-#ifdef DIAGNOSTIC
-	if (evtsource[evtch] == NULL) {
-		panic("evtchn_do_event: unknown event");
-	}
-#endif
+	KASSERTMSG(evtsource[evtch] != NULL, "unknown event %d", evtch);
 	ci->ci_data.cpu_nintr++;
 	evtsource[evtch]->ev_evcnt.ev_count++;
 	ilevel = ci->ci_ilevel;
@@ -851,12 +844,9 @@ event_set_handler(int evtch, int (*func)
 	printf("event_set_handler IRQ %d handler %p\n", evtch, func);
 #endif
 
-#ifdef DIAGNOSTIC
-	if (evtch >= NR_EVENT_CHANNELS) {
-		printf("evtch number %d > NR_EVENT_CHANNELS\n", evtch);
-		panic("event_set_handler");
-	}
-#endif
+	KASSERTMSG(evtch >= 0, "negative evtch: %d", evtch);
+	KASSERTMSG(evtch < NR_EVENT_CHANNELS,
+	"evtch number %d > NR_EVENT_CHANNELS", evtch);
 
 #if 0
 	printf("event_set_handler evtch %d handler %p level %d\n", evtch,