CVS commit: src/sys/dev/bluetooth

2017-09-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Sep  3 23:11:19 UTC 2017

Modified Files:
src/sys/dev/bluetooth: bth5.c bth5.h

Log Message:
Remove references to BlueCore.
Enable XON/XOFF flowcontrol in SLIP layer depending on config response.
Send an acknowlegment packet on timeout/retry.
Compute tx{ack,seq} and rx{ack,seq} according to the specification.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/bluetooth/bth5.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/bluetooth/bth5.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/bluetooth/bth5.c
diff -u src/sys/dev/bluetooth/bth5.c:1.4 src/sys/dev/bluetooth/bth5.c:1.5
--- src/sys/dev/bluetooth/bth5.c:1.4	Mon Aug 14 12:51:11 2017
+++ src/sys/dev/bluetooth/bth5.c	Sun Sep  3 23:11:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bth5.c,v 1.4 2017/08/14 12:51:11 nat Exp $	*/
+/*	$NetBSD: bth5.c,v 1.5 2017/09/03 23:11:19 nat Exp $	*/
 /*
  * Copyright (c) 2017 Nathanial Sloss 
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.4 2017/08/14 12:51:11 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.5 2017/09/03 23:11:19 nat Exp $");
 
 #include 
 #include 
@@ -110,14 +110,16 @@ struct bth5_softc {
 	MBUFQ_HEAD() sc_seqq;			/* Sequencing Layer queue */
 	MBUFQ_HEAD() sc_seq_retryq;		/* retry queue */
 	uint32_t sc_seq_txseq;
-	uint32_t sc_seq_txack;
 	uint32_t sc_seq_expected_rxseq;
+	uint32_t sc_seq_total_rxpkts;
+	uint32_t sc_seq_winack;
 	uint32_t sc_seq_winspace;
 	uint32_t sc_seq_retries;
 	callout_t sc_seq_timer;
 	uint32_t sc_seq_timeout;
 	uint32_t sc_seq_winsize;
 	uint32_t sc_seq_retry_limit;
+	bool	 sc_oof_flow_control;
 
 	/* variables of Datagram Queue Layer */
 	MBUFQ_HEAD() sc_dgq;			/* Datagram Queue Layer queue */
@@ -500,10 +502,13 @@ bth5_slip_transmit(struct tty *tp)
 	struct mbuf *m;
 	int count, rlen;
 	uint8_t *rptr;
+	int s;
 
 	m = sc->sc_txp;
 	if (m == NULL) {
+		s = spltty();
 		sc->sc_flags &= ~BTH5_XMIT;
+		splx(s);
 		bth5_mux_transmit(sc);
 		return 0;
 	}
@@ -526,12 +531,18 @@ bth5_slip_transmit(struct tty *tp)
 		count++;
 
 		if (sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_PKTEND ||
-		sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XON ||
-		sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XOFF ||
 		sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_ESCAPE) {
 			rlen++;
 			rptr++;
 		}
+		if (sc->sc_oof_flow_control == true) {
+			if (sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XON ||
+			sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XOFF) {
+rlen++;
+rptr++;
+			}
+		}
+
 		sc->sc_slip_txrsv = 0;
 	}
 
@@ -571,7 +582,8 @@ bth5_slip_transmit(struct tty *tp)
 			}
 			DPRINTFN(4, ("0x%02x ", BTH5_SLIP_ESCAPE_PKTEND));
 			rptr++;
-		} else if (*rptr == BTH5_SLIP_XON) {
+		} else if (sc->sc_oof_flow_control == true && *rptr ==
+			 BTH5_SLIP_XON) {
 			if (putc(BTH5_SLIP_ESCAPE, >t_outq) < 0)
 break;
 			count++;
@@ -583,7 +595,8 @@ bth5_slip_transmit(struct tty *tp)
 			}
 			DPRINTFN(4, ("0x%02x ", BTH5_SLIP_ESCAPE_XON));
 			rptr++;
-		} else if (*rptr == BTH5_SLIP_XOFF) {
+		} else if (sc->sc_oof_flow_control == true && *rptr ==
+			 BTH5_SLIP_XOFF) {
 			if (putc(BTH5_SLIP_ESCAPE, >t_outq) < 0)
 break;
 			count++;
@@ -728,10 +741,12 @@ bth5_slip_receive(int c, struct tty *tp)
 			if (c == BTH5_SLIP_ESCAPE_PKTEND)
 mtod(m, uint8_t *)[m->m_len++] =
 BTH5_SLIP_PKTEND;
-			else if (c == BTH5_SLIP_ESCAPE_XON)
+			else if (sc->sc_oof_flow_control == true &&
+		c == BTH5_SLIP_ESCAPE_XON)
 mtod(m, uint8_t *)[m->m_len++] =
 BTH5_SLIP_XON;
-			else if (c == BTH5_SLIP_ESCAPE_XOFF)
+			else if (sc->sc_oof_flow_control == true &&
+		c == BTH5_SLIP_ESCAPE_XOFF)
 mtod(m, uint8_t *)[m->m_len++] =
 BTH5_SLIP_XOFF;
 			else if (c == BTH5_SLIP_ESCAPE_ESCAPE)
@@ -921,6 +936,7 @@ bth5_mux_transmit(struct bth5_softc *sc)
 {
 	struct mbuf *m;
 	bth5_hdr_t *hdrp;
+	int s;
 
 	DPRINTFN(2, ("%s: mux transmit: sc_flags=0x%x, choke=%d",
 	device_xname(sc->sc_dev), sc->sc_flags, sc->sc_mux_choke));
@@ -963,8 +979,12 @@ bth5_mux_transmit(struct bth5_softc *sc)
 		hdrp->flags |= BTH5_FLAGS_PROTOCOL_REL;		/* Reliable */
 		goto transmit;
 	}
-	sc->sc_flags &= ~BTH5_XMIT;
-	bth5_start(sc);
+
+	s = spltty();
+	if ((sc->sc_flags & BTH5_XMIT) == 0)
+		bth5_start(sc);
+	splx(s);
+
 	if (sc->sc_mux_send_ack == true) {
 		m = bth5_create_ackpkt();
 		if (m != NULL)
@@ -975,6 +995,7 @@ bth5_mux_transmit(struct bth5_softc *sc)
 
 	/* Nothing to send */
 	DPRINTFN(2, ("\n"));
+
 	return;
 
 transmit:
@@ -1017,6 +1038,9 @@ bth5_mux_receive(struct bth5_softc *sc, 
 	if (BTH5_FLAGS_SEQ(hdrp->flags) == 0 &&
 	hdrp->ident == BTH5_IDENT_ACKPKT &&
 	BTH5_GET_PLEN(hdrp) == 0) {
+		sc->sc_seq_txseq = BTH5_FLAGS_ACK(hdrp->flags);
+		bth5_send_ack_command(sc);
+		bth5_mux_transmit(sc);
 		m_freem(m);
 		return;
 	}
@@ -1076,11 

CVS commit: src/usr.sbin/btattach

2017-09-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Sep  3 22:54:12 UTC 2017

Modified Files:
src/usr.sbin/btattach: init_bcm43xx.c

Log Message:
Fix copyright error.

Ok plunky@.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btattach/init_bcm43xx.c

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

Modified files:

Index: src/usr.sbin/btattach/init_bcm43xx.c
diff -u src/usr.sbin/btattach/init_bcm43xx.c:1.4 src/usr.sbin/btattach/init_bcm43xx.c:1.5
--- src/usr.sbin/btattach/init_bcm43xx.c:1.4	Mon Aug 14 05:28:23 2017
+++ src/usr.sbin/btattach/init_bcm43xx.c	Sun Sep  3 22:54:12 2017
@@ -1,7 +1,7 @@
-/*	$NetBSD: init_bcm43xx.c,v 1.4 2017/08/14 05:28:23 nat Exp $	*/
+/*	$NetBSD: init_bcm43xx.c,v 1.5 2017/09/03 22:54:12 nat Exp $	*/
 
 /*-
- * Copyright (c) 2017 Iain Hibbert
+ * Copyright (c) 2017 Nathanial Sloss 
  * All rights reserved.
  *
  * Copyright (c) 2008 Iain Hibbert
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: init_bcm43xx.c,v 1.4 2017/08/14 05:28:23 nat Exp $");
+__RCSID("$NetBSD: init_bcm43xx.c,v 1.5 2017/09/03 22:54:12 nat Exp $");
 
 #include 
 



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

2017-09-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep  3 13:59:17 UTC 2017

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

Log Message:
Add 'console=fb' cmdline support.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_platform.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/sunxi_platform.c
diff -u src/sys/arch/arm/sunxi/sunxi_platform.c:1.7 src/sys/arch/arm/sunxi/sunxi_platform.c:1.8
--- src/sys/arch/arm/sunxi/sunxi_platform.c:1.7	Fri Aug 25 00:07:03 2017
+++ src/sys/arch/arm/sunxi/sunxi_platform.c	Sun Sep  3 13:59:17 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_platform.c,v 1.7 2017/08/25 00:07:03 jmcneill Exp $ */
+/* $NetBSD: sunxi_platform.c,v 1.8 2017/09/03 13:59:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -31,7 +31,7 @@
 #include "opt_fdt_arm.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.7 2017/08/25 00:07:03 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.8 2017/09/03 13:59:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -58,6 +58,8 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_platfo
 
 #include 
 
+#include 
+
 #define	SUNXI_REF_FREQ	2400
 
 #define	SUN4I_TIMER_BASE	0x01c20c00
@@ -144,8 +146,24 @@ sunxi_platform_uart_freq(void)
 }
 
 static void
-sunxi_platform_null_bootstrap(void)
+sunxi_platform_bootstrap(void)
+{
+	if (match_bootconf_option(boot_args, "console", "fb")) {
+		void *fdt_data = __UNCONST(fdtbus_get_data());
+		const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
+		const int framebuffer_off =
+		fdt_path_offset(fdt_data, "/chosen/framebuffer");
+		if (chosen_off >= 0 && framebuffer_off >= 0)
+			fdt_setprop_string(fdt_data, chosen_off, "stdout-path",
+			"/chosen/framebuffer");
+	}
+}
+
+static void
+sunxi_platform_psci_bootstrap(void)
 {
+	psci_fdt_bootstrap();
+	sunxi_platform_bootstrap();
 }
 
 static void
@@ -200,7 +218,7 @@ sun6i_platform_reset(void)
 
 static const struct arm_platform sun5i_platform = {
 	.devmap = sunxi_platform_devmap,
-	.bootstrap = sunxi_platform_null_bootstrap,
+	.bootstrap = sunxi_platform_bootstrap,
 	.init_attach_args = sunxi_platform_init_attach_args,
 	.early_putchar = sunxi_platform_early_putchar,
 	.device_register = sunxi_platform_device_register,
@@ -213,7 +231,7 @@ ARM_PLATFORM(sun5i_a13, "allwinner,sun5i
 
 static const struct arm_platform sun6i_platform = {
 	.devmap = sunxi_platform_devmap,
-	.bootstrap = psci_fdt_bootstrap,
+	.bootstrap = sunxi_platform_psci_bootstrap,
 	.init_attach_args = sunxi_platform_init_attach_args,
 	.early_putchar = sunxi_platform_early_putchar,
 	.device_register = sunxi_platform_device_register,
@@ -226,7 +244,7 @@ ARM_PLATFORM(sun6i_a31, "allwinner,sun6i
 
 static const struct arm_platform sun8i_platform = {
 	.devmap = sunxi_platform_devmap,
-	.bootstrap = psci_fdt_bootstrap,
+	.bootstrap = sunxi_platform_psci_bootstrap,
 	.init_attach_args = sunxi_platform_init_attach_args,
 	.early_putchar = sunxi_platform_early_putchar,
 	.device_register = sunxi_platform_device_register,
@@ -241,7 +259,7 @@ ARM_PLATFORM(sun8i_a83t, "allwinner,sun8
 
 static const struct arm_platform sun50i_platform = {
 	.devmap = sunxi_platform_devmap,
-	.bootstrap = sunxi_platform_null_bootstrap,
+	.bootstrap = sunxi_platform_bootstrap,
 	.init_attach_args = sunxi_platform_init_attach_args,
 	.early_putchar = sunxi_platform_early_putchar,
 	.device_register = sunxi_platform_device_register,



CVS commit: src/tests/lib/libm

2017-09-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Sep  3 13:41:19 UTC 2017

Modified Files:
src/tests/lib/libm: t_round.c

Log Message:
Fix verb form.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libm/t_round.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/libm/t_round.c
diff -u src/tests/lib/libm/t_round.c:1.8 src/tests/lib/libm/t_round.c:1.9
--- src/tests/lib/libm/t_round.c:1.8	Sun Sep  3 13:29:55 2017
+++ src/tests/lib/libm/t_round.c	Sun Sep  3 13:41:19 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_round.c,v 1.8 2017/09/03 13:29:55 maya Exp $ */
+/* $NetBSD: t_round.c,v 1.9 2017/09/03 13:41:19 wiz Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@ ATF_TC_BODY(rounding_alpha_simple, tc)
 	uint64_t unsigned_even = rounding_alpha_simple_even;
 
 	ATF_CHECK_MSG(unsigned_even % 2 == 0,
-	"2^63 casted to uint64_t is odd (got %"PRIu64")", unsigned_even);
+	"2^63 cast to uint64_t is odd (got %"PRIu64")", unsigned_even);
 
 }
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/lib/libm

2017-09-03 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Sep  3 13:29:55 UTC 2017

Modified Files:
src/tests/lib/libm: t_round.c

Log Message:
Use a global double to stop GCC from optimizing the test away
Better diagnostic messages
More familiar test for 'even number'


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libm/t_round.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/libm/t_round.c
diff -u src/tests/lib/libm/t_round.c:1.7 src/tests/lib/libm/t_round.c:1.8
--- src/tests/lib/libm/t_round.c:1.7	Wed Aug 30 22:55:41 2017
+++ src/tests/lib/libm/t_round.c	Sun Sep  3 13:29:55 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_round.c,v 1.7 2017/08/30 22:55:41 maya Exp $ */
+/* $NetBSD: t_round.c,v 1.8 2017/09/03 13:29:55 maya Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -103,8 +103,8 @@ ATF_TC_BODY(rounding_alpha, tc)
 u = (gimpy_limb_t) d;
 
 for (; i > 0; i--) {
-printf("i=%d, u: %"PRIu64"\n", i, u);
-ATF_CHECK(!(u & 1));
+ATF_CHECK_MSG((u % 2 == 0),
+		"%"PRIu64" is not an even number! (iteration %d)", u , i);
 u = u >> 1;
 }
 }
@@ -115,13 +115,15 @@ ATF_TC_HEAD(rounding_alpha_simple, tc)
 	atf_tc_set_md_var(tc, "descr","Checking double to uint64_t edge case");
 }
 
+
+double rounding_alpha_simple_even = 9223372036854775808.00; /* 2^63 */
+
 ATF_TC_BODY(rounding_alpha_simple, tc)
 {
-	double even = 9223372036854775808.00; /* 2^63 */
-	uint64_t unsigned_even = even;
+	uint64_t unsigned_even = rounding_alpha_simple_even;
 
 	ATF_CHECK_MSG(unsigned_even % 2 == 0,
-	"2^63 casted to uint64_t is odd");
+	"2^63 casted to uint64_t is odd (got %"PRIu64")", unsigned_even);
 
 }
 ATF_TP_ADD_TCS(tp)



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

2017-09-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Sep  3 09:19:51 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Declare onfault_restore, and be stricter with SMEP.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/amd64/amd64/trap.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/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.98 src/sys/arch/amd64/amd64/trap.c:1.99
--- src/sys/arch/amd64/amd64/trap.c:1.98	Sun Sep  3 09:01:03 2017
+++ src/sys/arch/amd64/amd64/trap.c	Sun Sep  3 09:19:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.98 2017/09/03 09:01:03 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.99 2017/09/03 09:19:51 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.98 2017/09/03 09:01:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.99 2017/09/03 09:19:51 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -153,6 +153,13 @@ int	trap_types = __arraycount(trap_type)
 
 #define	IDTVEC(name)	__CONCAT(X, name)
 
+static void
+onfault_restore(struct trapframe *frame, void *onfault, int error)
+{
+	frame->tf_rip = (uintptr_t)onfault;
+	frame->tf_rax = error;
+}
+
 static void *
 onfault_handler(const struct pcb *pcb, const struct trapframe *tf)
 {
@@ -405,11 +412,7 @@ trap(struct trapframe *frame)
 		/* Check for copyin/copyout fault. */
 		onfault = onfault_handler(pcb, frame);
 		if (onfault != NULL) {
-copyefault:
-			error = EFAULT;
-copyfault:
-			frame->tf_rip = (uintptr_t)onfault;
-			frame->tf_rax = error;
+			onfault_restore(frame, onfault, EFAULT);
 			return;
 		}
 
@@ -537,7 +540,8 @@ copyfault:
 		 */
 		onfault = pcb->pcb_onfault;
 		if (onfault == fusuintrfailure) {
-			goto copyefault;
+			onfault_restore(frame, fusuintrfailure, EFAULT);
+			return;
 		}
 		if (cpu_intr_p() || (l->l_pflag & LP_INTR) != 0) {
 			goto we_re_toast;
@@ -547,7 +551,7 @@ copyfault:
 
 		if (frame->tf_err & PGEX_X) {
 			/* SMEP might have brought us here */
-			if (cr2 > VM_MIN_ADDRESS && cr2 <= VM_MAXUSER_ADDRESS)
+			if (cr2 < VM_MAXUSER_ADDRESS)
 panic("prevented execution of %p (SMEP)",
 (void *)cr2);
 		}
@@ -658,8 +662,11 @@ faultcommon:
 
 		if (type == T_PAGEFLT) {
 			onfault = onfault_handler(pcb, frame);
-			if (onfault != NULL)
-goto copyfault;
+			if (onfault != NULL) {
+onfault_restore(frame, onfault, error);
+return;
+			}
+
 			printf("uvm_fault(%p, 0x%lx, %d) -> %x\n",
 			map, va, ftype, error);
 			goto we_re_toast;



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

2017-09-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Sep  3 09:01:03 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Treat page faults from iretq/etc as fatal, otherwise we could hide kernel
stack bugs. Note that it would be good to call check_swapgs from trap0e,
but a few things need to be fixed before that.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/amd64/amd64/trap.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/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.97 src/sys/arch/amd64/amd64/trap.c:1.98
--- src/sys/arch/amd64/amd64/trap.c:1.97	Sun Sep  3 08:52:18 2017
+++ src/sys/arch/amd64/amd64/trap.c	Sun Sep  3 09:01:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.97 2017/09/03 08:52:18 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.98 2017/09/03 09:01:03 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.97 2017/09/03 08:52:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.98 2017/09/03 09:01:03 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -401,6 +401,7 @@ trap(struct trapframe *frame)
 	case T_TSSFLT:
 		if (p == NULL)
 			goto we_re_toast;
+
 		/* Check for copyin/copyout fault. */
 		onfault = onfault_handler(pcb, frame);
 		if (onfault != NULL) {
@@ -412,7 +413,6 @@ copyfault:
 			return;
 		}
 
-kernelfault:
 		trap_user_kernelmode(frame, type, l, p);
 		goto we_re_toast;
 
@@ -662,7 +662,7 @@ faultcommon:
 goto copyfault;
 			printf("uvm_fault(%p, 0x%lx, %d) -> %x\n",
 			map, va, ftype, error);
-			goto kernelfault;
+			goto we_re_toast;
 		}
 
 		KSI_INIT_TRAP();



CVS commit: src/sys/arch/amd64

2017-09-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Sep  3 08:52:18 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S trap.c
src/sys/arch/amd64/conf: ALL

Log Message:
Remove useless debug code, and split trap() into smaller functions, easier
to understand. NMIs take another, faster path now. No functional change
beyond that.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/amd64/amd64_trap.S
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/amd64/conf/ALL

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/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.9 src/sys/arch/amd64/amd64/amd64_trap.S:1.10
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.9	Thu Aug 31 10:30:58 2017
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Sun Sep  3 08:52:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.9 2017/08/31 10:30:58 maxv Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.10 2017/09/03 08:52:18 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2017 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.9 2017/08/31 10:30:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.10 2017/09/03 08:52:18 maxv Exp $");
 #endif
 
 /*
@@ -135,7 +135,7 @@ IDTVEC(trap02)
 	swapgs
 	movq	%rsp,%rdi
 	incq	CPUVAR(NTRAP)
-	call	_C_LABEL(trap)
+	call	_C_LABEL(nmitrap)
 	swapgs
 	jmp	nmileave
 

Index: src/sys/arch/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.96 src/sys/arch/amd64/amd64/trap.c:1.97
--- src/sys/arch/amd64/amd64/trap.c:1.96	Mon Apr 24 17:03:43 2017
+++ src/sys/arch/amd64/amd64/trap.c	Sun Sep  3 08:52:18 2017
@@ -1,11 +1,11 @@
-/*	$NetBSD: trap.c,v 1.96 2017/04/24 17:03:43 chs Exp $	*/
+/*	$NetBSD: trap.c,v 1.97 2017/09/03 08:52:18 maxv Exp $	*/
 
-/*-
- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
+/*
+ * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Charles M. Hannum.
+ * by Charles M. Hannum, and by Maxime Villard.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*-
+/*
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
  *
@@ -63,12 +63,8 @@
  *	@(#)trap.c	7.4 (Berkeley) 5/13/91
  */
 
-/*
- * 386 Trap and System call handling
- */
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.96 2017/04/24 17:03:43 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.97 2017/09/03 08:52:18 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -126,6 +122,7 @@ dtrace_trap_func_t	dtrace_trap_func = NU
 dtrace_doubletrap_func_t	dtrace_doubletrap_func = NULL;
 #endif
 
+void nmitrap(struct trapframe *);
 void trap(struct trapframe *);
 void trap_return_fault_return(struct trapframe *) __dead;
 
@@ -154,16 +151,8 @@ const char * const trap_type[] = {
 };
 int	trap_types = __arraycount(trap_type);
 
-#ifdef DEBUG
-int	trapdebug = 0;
-#endif
-
 #define	IDTVEC(name)	__CONCAT(X, name)
 
-#ifdef TRAP_SIGDEBUG
-static void frame_dump(struct trapframe *, struct pcb *);
-#endif
-
 static void *
 onfault_handler(const struct pcb *pcb, const struct trapframe *tf)
 {
@@ -210,6 +199,115 @@ trap_print(const struct trapframe *frame
 	l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l));
 }
 
+void
+nmitrap(struct trapframe *frame)
+{
+	const int type = T_NMI;
+
+	if (nmi_dispatch(frame))
+		return;
+	/* NMI can be hooked up to a pushbutton for debugging */
+	if (kgdb_trap(type, frame))
+		return;
+	if (kdb_trap(type, 0, frame))
+		return;
+	/* machine/parity/power fail/"kitchen sink" faults */
+
+	x86_nmi();
+}
+
+/*
+ * Did we receive in kernel mode a trap that ought to be considered as a user
+ * trap? If this function returns, the answer is no.
+ *
+ * Such traps can be triggered when the kernel fails to return to userland,
+ * because of incorrect segment registers.
+ */
+#ifndef Xen
+static void trap_user_kernelmode(struct trapframe *, int, lwp_t *, proc_t *);
+
+static void
+trap_user_kernelmode(struct trapframe *frame, int type, lwp_t *l, proc_t *p)
+{
+	struct trapframe *vframe;
+	ksiginfo_t ksi;
+
+	if (frame->tf_rip == 0) {
+		/*
+		 * Assume that if we jumped to null we probably did it via a
+		 * null function pointer, so print the return address.
+		 */
+		printf("kernel jumped to null; return addr was %p\n",
+		*(void **)frame->tf_rsp);
+		return;
+	}
+
+	KSI_INIT_TRAP();
+	ksi.ksi_signo = SIGSEGV;
+	ksi.ksi_code = SEGV_ACCERR;
+	ksi.ksi_trap = type;
+
+	/*
+	 * Get %rsp value before fault - there may be a pad word below the
+	 * trap frame.
+	 */
+	vframe = (void 

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

2017-09-03 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep  3 06:24:49 UTC 2017

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

Log Message:
Remove redundant static function declaration


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.102 src/sys/arch/x86/x86/intr.c:1.103
--- src/sys/arch/x86/x86/intr.c:1.102	Mon Jul 31 18:54:40 2017
+++ src/sys/arch/x86/x86/intr.c	Sun Sep  3 06:24:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.102 2017/07/31 18:54:40 maxv Exp $	*/
+/*	$NetBSD: intr.c,v 1.103 2017/09/03 06:24:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.102 2017/07/31 18:54:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.103 2017/09/03 06:24:49 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -247,8 +247,6 @@ static struct intrsource *intr_get_io_in
 static void intr_free_io_intrsource_direct(struct intrsource *);
 static int intr_num_handlers(struct intrsource *);
 
-static const char *legacy_intr_string(int, char *, size_t, struct pic *);
-
 static int intr_find_unused_slot(struct cpu_info *, int *);
 static void intr_activate_xcall(void *, void *);
 static void intr_deactivate_xcall(void *, void *);