? arch/i386/compile/DEBUG.MP ? arch/i386/conf/DEBUG.MP ? kern/kern_srp.c ? sys/_srp.h ? sys/srp.h Index: arch/i386/i386/mutex.S =================================================================== RCS file: /cvs/src/sys/arch/i386/i386/mutex.S,v retrieving revision 1.9 diff -u -p -r1.9 mutex.S --- arch/i386/i386/mutex.S 10 Jul 2013 21:31:11 -0000 1.9 +++ arch/i386/i386/mutex.S 28 Apr 2015 13:09:36 -0000 @@ -45,7 +45,7 @@ ENTRY(__mtx_init) #define SOFF 8 -ENTRY(mtx_enter) +ENTRY(__mtx_enter) pushl %ebp movl %esp, %ebp 1: movl SOFF(%ebp), %ecx @@ -92,7 +92,7 @@ ENTRY(mtx_enter) 6: .asciz "mtx_enter: locking against myself" #endif -ENTRY(mtx_enter_try) +ENTRY(__mtx_enter_try) pushl %ebp movl %esp, %ebp 1: movl SOFF(%ebp), %ecx @@ -140,7 +140,7 @@ ENTRY(mtx_enter_try) #endif -ENTRY(mtx_leave) +ENTRY(__mtx_leave) pushl %ebp movl %esp, %ebp movl SOFF(%ebp), %ecx Index: arch/i386/include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/i386/include/mutex.h,v retrieving revision 1.7 diff -u -p -r1.7 mutex.h --- arch/i386/include/mutex.h 29 Mar 2014 18:09:29 -0000 1.7 +++ arch/i386/include/mutex.h 28 Apr 2015 13:09:36 -0000 @@ -36,6 +36,7 @@ struct mutex { int mtx_wantipl; int mtx_oldipl; void *mtx_owner; + int mtx_tick; }; /* Index: arch/sparc64/conf/ld.script =================================================================== RCS file: /cvs/src/sys/arch/sparc64/conf/ld.script,v retrieving revision 1.7 diff -u -p -r1.7 ld.script --- arch/sparc64/conf/ld.script 26 Nov 2014 20:06:53 -0000 1.7 +++ arch/sparc64/conf/ld.script 28 Apr 2015 13:09:36 -0000 @@ -40,7 +40,7 @@ SECTIONS { *(.rodata*) } - . = 0x01800000; + . = 0x02000000; .data : { *(.data) Index: arch/sparc64/include/cpu.h =================================================================== RCS file: /cvs/src/sys/arch/sparc64/include/cpu.h,v retrieving revision 1.86 diff -u -p -r1.86 cpu.h --- arch/sparc64/include/cpu.h 15 Oct 2014 21:54:13 -0000 1.86 +++ arch/sparc64/include/cpu.h 28 Apr 2015 13:09:36 -0000 @@ -78,6 +78,8 @@ #include #include +#include +#include /* * The cpu_info structure is part of a 64KB structure mapped both the kernel @@ -113,11 +115,13 @@ struct cpu_info { struct cpu_info *ci_next; struct proc *ci_fpproc; + u_int64_t ci_crit; int ci_number; int ci_flags; int ci_upaid; #ifdef MULTIPROCESSOR int ci_itid; + struct srp_hazard ci_srp_hazards[8]; #endif int ci_node; u_int32_t ci_randseed; @@ -155,6 +159,7 @@ struct cpu_info { #ifdef GPROF struct gmonparam *ci_gmon; #endif + struct ktr_ring *ci_ktr; }; #define CPUF_RUNNING 0x0001 /* CPU is running */ Index: arch/sparc64/include/endian.h =================================================================== RCS file: /cvs/src/sys/arch/sparc64/include/endian.h,v retrieving revision 1.7 diff -u -p -r1.7 endian.h --- arch/sparc64/include/endian.h 22 Oct 2014 23:56:47 -0000 1.7 +++ arch/sparc64/include/endian.h 28 Apr 2015 13:09:36 -0000 @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.7 2014/10/22 23:56:47 dlg Exp $ */ +/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:09 guenther Exp $ */ #ifndef _MACHINE_ENDIAN_H_ #define _MACHINE_ENDIAN_H_ @@ -72,6 +72,12 @@ __swapm64(volatile __uint64_t *m, __uint #undef __ASI_P_L #define __HAVE_MD_SWAPIO + +__uint16_t __swap16md(__uint16_t); +__uint32_t __swap32md(__uint32_t); +__uint64_t __swap64md(__uint64_t); + +#define __HAVE_MD_SWAP #endif /* _KERNEL */ Index: arch/sparc64/include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/sparc64/include/mutex.h,v retrieving revision 1.4 diff -u -p -r1.4 mutex.h --- arch/sparc64/include/mutex.h 29 Mar 2014 18:09:30 -0000 1.4 +++ arch/sparc64/include/mutex.h 28 Apr 2015 13:09:36 -0000 @@ -32,6 +32,7 @@ struct mutex { volatile void *mtx_owner; /* mutex.S relies upon this being first */ int mtx_wantipl; int mtx_oldipl; + long mtx_tick; }; /* Index: arch/sparc64/include/tcb.h =================================================================== RCS file: /cvs/src/sys/arch/sparc64/include/tcb.h,v retrieving revision 1.4 diff -u -p -r1.4 tcb.h --- arch/sparc64/include/tcb.h 29 Mar 2014 18:09:30 -0000 1.4 +++ arch/sparc64/include/tcb.h 28 Apr 2015 13:09:36 -0000 @@ -36,41 +36,11 @@ /* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ #define TLS_VARIANT 2 -#if 0 /* XXX perhaps use the gcc global register extension? */ struct thread_control_block; -__register__ struct thread_control_block *__tcb __asm__ ("%g7"); +register struct thread_control_block *__tcb __asm__ ("%g7"); #define TCB_GET() (__tcb) #define TCB_GET_MEMBER(member) ((void *)(__tcb->member)) -#define TCB_SET(tcb) ((__tcb) = (tcb)) - -#else - -#include /* for offsetof */ - -/* Get a pointer to the TCB itself */ -static inline void * -__sparc64_get_tcb(void) -{ - void *val; - __asm__ ("mov %%g7, %0" : "=r" (val)); - return val; -} -#define TCB_GET() __sparc64_get_tcb() - -/* Get the value of a specific member in the TCB */ -static inline void * -__sparc64_read_tcb(int offset) -{ - void *val; - __asm__ ("ldx [%%g7 + %1], %0" : "=r" (val) : "r" (offset)); - return val; -} -#define TCB_GET_MEMBER(member) \ - __sparc64_read_tcb(offsetof(struct thread_control_block, member)) - -#define TCB_SET(tcb) __asm volatile("mov %0, %%g7" : : "r" (tcb)) - -#endif /* 0 */ +#define TCB_SET(tcb) do { ((__tcb) = (tcb)); } while (0) #endif /* _KERNEL */ Index: arch/sparc64/sparc64/machdep.c =================================================================== RCS file: /cvs/src/sys/arch/sparc64/sparc64/machdep.c,v retrieving revision 1.172 diff -u -p -r1.172 machdep.c --- arch/sparc64/sparc64/machdep.c 10 Dec 2014 15:29:53 -0000 1.172 +++ arch/sparc64/sparc64/machdep.c 28 Apr 2015 13:09:36 -0000 @@ -2144,3 +2144,21 @@ blink_led_timeout(void *vsc) t = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); timeout_add(&sc->bls_to, t); } + +__uint16_t +__swap16md(__uint16_t x) +{ + return (__swap16gen(x)); +} + +__uint32_t +__swap32md(__uint32_t x) +{ + return (__swap32gen(x)); +} + +__uint64_t +__swap64md(__uint64_t x) +{ + return (__swap64gen(x)); +} Index: arch/sparc64/sparc64/mutex.S =================================================================== RCS file: /cvs/src/sys/arch/sparc64/sparc64/mutex.S,v retrieving revision 1.8 diff -u -p -r1.8 mutex.S --- arch/sparc64/sparc64/mutex.S 14 Jul 2013 21:22:09 -0000 1.8 +++ arch/sparc64/sparc64/mutex.S 28 Apr 2015 13:09:36 -0000 @@ -44,7 +44,7 @@ ENTRY(__mtx_init) retl stw %g0, [%o0 + MTX_OLDIPL] -ENTRY(mtx_enter) +ENTRY(__mtx_enter) rdpr %pil, %g4 GET_CURCPU(%g1) 1: @@ -80,7 +80,7 @@ ENTRY(mtx_enter) retl membar #LoadLoad | #LoadStore -ENTRY(mtx_enter_try) +ENTRY(__mtx_enter_try) rdpr %pil, %g4 GET_CURCPU(%g1) 1: @@ -112,7 +112,7 @@ ENTRY(mtx_enter_try) retl mov 1, %o0 -ENTRY(mtx_leave) +ENTRY(__mtx_leave) #ifdef DIAGNOSTIC GET_CURCPU(%g1) ld [%g1 + CI_MUTEX_LEVEL], %g5 Index: arch/sparc64/sparc64/pmap.c =================================================================== RCS file: /cvs/src/sys/arch/sparc64/sparc64/pmap.c,v retrieving revision 1.91 diff -u -p -r1.91 pmap.c --- arch/sparc64/sparc64/pmap.c 10 Apr 2015 18:08:31 -0000 1.91 +++ arch/sparc64/sparc64/pmap.c 28 Apr 2015 13:09:36 -0000 @@ -1379,10 +1379,12 @@ pmap_init(void) panic("pmap_init: CLSIZE!=1"); /* Setup a pool for additional pvlist structures */ - pool_init(&pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pv_entry", NULL); - pool_setipl(&pv_pool, IPL_VM); - pool_init(&pmap_pool, sizeof(struct pmap), 0, 0, 0, "pmappl", - &pool_allocator_nointr); + pool_init(&pv_pool, sizeof(struct pv_entry), 0, 0, PR_WAITOK, + "pv_entry", NULL); + pool_setipl(&pv_pool, IPL_NONE); + pool_init(&pmap_pool, sizeof(struct pmap), 0, 0, PR_WAITOK, + "pmappl", NULL); + pool_setipl(&pmap_pool, IPL_NONE); } /* Start of non-cachable physical memory on UltraSPARC-III. */ Index: arch/vax/mscp/mscp_subr.c =================================================================== RCS file: /cvs/src/sys/arch/vax/mscp/mscp_subr.c,v retrieving revision 1.12 diff -u -p -r1.12 mscp_subr.c --- arch/vax/mscp/mscp_subr.c 5 Dec 2012 23:20:15 -0000 1.12 +++ arch/vax/mscp/mscp_subr.c 28 Apr 2015 13:09:36 -0000 @@ -159,7 +159,7 @@ mscp_attach(parent, self, aux) mi->mi_rsp.mri_size = NRSP; mi->mi_rsp.mri_desc = mi->mi_uda->mp_ca.ca_rspdsc; mi->mi_rsp.mri_ring = mi->mi_uda->mp_rsp; - SIMPLEQ_INIT(&mi->mi_resq); + bufq_init(&mi->mi_bufq, BUFQ_FIFO); if (mscp_init(mi)) { printf("%s: can't init, controller hung\n", @@ -448,7 +448,7 @@ mscp_intr(mi) /* * If there are any not-yet-handled request, try them now. */ - if (SIMPLEQ_FIRST(&mi->mi_resq)) + if (bufq_peek(&mi->mi_bufq)) mscp_kickaway(mi); } @@ -482,10 +482,7 @@ mscp_strategy(bp, usc) struct mscp_softc *mi = (void *)usc; int s = spl6(); -/* SIMPLEQ_INSERT_TAIL(&mi->mi_resq, bp, xxx) */ - bp->b_actf = NULL; - *mi->mi_resq.sqh_last = bp; - mi->mi_resq.sqh_last = &bp->b_actf; + bufq_queue(&mi->mi_bufq, bp); mscp_kickaway(mi); splx(s); } @@ -499,7 +496,7 @@ mscp_kickaway(mi) struct mscp *mp; int next; - while ((bp = SIMPLEQ_FIRST(&mi->mi_resq))) { + while ((bp = bufq_dequeue(&mi->mi_bufq))) { /* * Ok; we are ready to try to start a xfer. Get a MSCP packet * and try to start... @@ -512,6 +509,7 @@ mscp_kickaway(mi) * By some (strange) reason we didn't get a MSCP packet. * Just return and wait for free packets. */ + bufq_requeue(&mi->mi_bufq, bp); return; } @@ -532,8 +530,6 @@ mscp_kickaway(mi) bp->b_resid = next; (*mi->mi_me->me_fillin)(bp, mp); (*mi->mi_mc->mc_go)(mi->mi_dev.dv_parent, &mi->mi_xi[next]); - if ((mi->mi_resq.sqh_first = bp->b_actf) == NULL) - mi->mi_resq.sqh_last = &mi->mi_resq.sqh_first; #if 0 mi->mi_w = bp->b_actf; #endif Index: arch/vax/mscp/mscpvar.h =================================================================== RCS file: /cvs/src/sys/arch/vax/mscp/mscpvar.h,v retrieving revision 1.7 diff -u -p -r1.7 mscpvar.h --- arch/vax/mscp/mscpvar.h 1 Nov 2011 20:50:11 -0000 1.7 +++ arch/vax/mscp/mscpvar.h 28 Apr 2015 13:09:36 -0000 @@ -188,7 +188,7 @@ struct mscp_softc { bus_space_handle_t mi_iph; /* initialisation and polling */ bus_space_handle_t mi_sah; /* status & address (read part) */ bus_space_handle_t mi_swh; /* status & address (write part) */ - SIMPLEQ_HEAD(, buf) mi_resq; /* While waiting for packets */ + struct bufq mi_bufq; /* While waiting for packets */ }; /* mi_flags */ Index: conf/files =================================================================== RCS file: /cvs/src/sys/conf/files,v retrieving revision 1.591 diff -u -p -r1.591 files --- conf/files 28 Dec 2014 21:32:44 -0000 1.591 +++ conf/files 28 Apr 2015 13:09:36 -0000 @@ -681,6 +681,7 @@ file kern/kern_rwlock.c file kern/kern_physio.c file kern/kern_proc.c file kern/kern_prot.c +file kern/kern_ktr.c file kern/kern_resource.c file kern/kern_sched.c file kern/kern_sensors.c @@ -701,6 +702,7 @@ file kern/subr_autoconf.c file kern/subr_disk.c file kern/subr_evcount.c file kern/subr_extent.c +#file kern/kern_srp.c file kern/subr_hibernate.c hibernate file kern/subr_log.c file kern/subr_poison.c diagnostic @@ -857,6 +859,7 @@ file crypto/sha1.c (inet & ipsec) | cr file crypto/sha2.c file crypto/blf.c (inet & ipsec) | crypto | vnd file crypto/cast.c (inet & ipsec) | crypto +file crypto/chacha.c file crypto/ecb_enc.c (inet & ipsec) | crypto file crypto/set_key.c (inet & ipsec) | crypto file crypto/ecb3_enc.c (inet & ipsec) | crypto Index: crypto/chacha.c =================================================================== RCS file: crypto/chacha.c diff -N crypto/chacha.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ crypto/chacha.c 28 Apr 2015 13:09:36 -0000 @@ -0,0 +1,219 @@ +/* $OpenBSD$ */ + +/* +chacha-merged.c version 20080118 +D. J. Bernstein +Public domain. +*/ + +#include +#include + +#include + +#define U8TO32_LITTLE(p) \ + (((uint32_t)((p)[0]) ) | \ + ((uint32_t)((p)[1]) << 8) | \ + ((uint32_t)((p)[2]) << 16) | \ + ((uint32_t)((p)[3]) << 24)) + +#define U32TO8_LITTLE(p, v) do { \ + (p)[0] = (v) ; \ + (p)[1] = (v) >> 8; \ + (p)[2] = (v) >> 16; \ + (p)[3] = (v) >> 24; \ +} while (0) + +#define ROTATE(v, n) ((v) << (n) | ((v) >> (32 - (n)))) + +static void +chacha_key_setup(chacha_ctx *ctx, const uint32_t *c, + const uint32_t *k1, const uint32_t *k2) +{ + ctx->input[0] = lemtoh32(&c[0]); + ctx->input[1] = lemtoh32(&c[1]); + ctx->input[2] = lemtoh32(&c[2]); + ctx->input[3] = lemtoh32(&c[3]); + + ctx->input[4] = lemtoh32(&k1[0]); + ctx->input[5] = lemtoh32(&k1[1]); + ctx->input[6] = lemtoh32(&k1[2]); + ctx->input[7] = lemtoh32(&k1[3]); + + ctx->input[8] = lemtoh32(&k2[0]); + ctx->input[9] = lemtoh32(&k2[1]); + ctx->input[10] = lemtoh32(&k2[2]); + ctx->input[11] = lemtoh32(&k2[3]); +} + +void +chacha_128key_setup(chacha_ctx *ctx, const chacha_128key *key) +{ + static const char tau[16] = "expand 16-byte k"; + + chacha_key_setup(ctx, (uint32_t *)tau, key->k, key->k); +} + +void +chacha_256key_setup(chacha_ctx *ctx, const chacha_256key *key) +{ + static const char sigma[16] = "expand 32-byte k"; + + chacha_key_setup(ctx, (uint32_t *)sigma, key->k, key->k + 4); +} + +void +chacha_iv_setup(chacha_ctx *ctx, const chacha_iv *iv) +{ + ctx->input[12] = 0; + ctx->input[13] = 0; + ctx->input[14] = lemtoh32(&iv->iv[0]); + ctx->input[15] = lemtoh32(&iv->iv[1]); +} + +#define QUARTERROUND(a, b, c, d) do { \ + a += b; d = ROTATE(d ^ a, 16); \ + c += d; b = ROTATE(b ^ c, 12); \ + a += b; d = ROTATE(d ^ a, 8); \ + c += d; b = ROTATE(b ^ c, 7); \ +} while (0) + +static inline void +chacha_round(chacha_ctx *ctx, chacha_ctx *state) +{ + uint32_t *x = state->input; + u_int i; + + *state = *ctx; + + for (i = 20; i > 0; i -= 2) { + QUARTERROUND(x[0], x[4], x[8], x[12]); + QUARTERROUND(x[1], x[5], x[9], x[13]); + QUARTERROUND(x[2], x[6], x[10], x[14]); + QUARTERROUND(x[3], x[7], x[11], x[15]); + QUARTERROUND(x[0], x[5], x[10], x[15]); + QUARTERROUND(x[1], x[6], x[11], x[12]); + QUARTERROUND(x[2], x[7], x[8], x[13]); + QUARTERROUND(x[3], x[4], x[9], x[14]); + } + + /* unrolled loop is fast */ + x[0] += ctx->input[0]; + x[1] += ctx->input[1]; + x[2] += ctx->input[2]; + x[3] += ctx->input[3]; + x[4] += ctx->input[4]; + x[5] += ctx->input[5]; + x[6] += ctx->input[6]; + x[7] += ctx->input[7]; + x[8] += ctx->input[8]; + x[9] += ctx->input[9]; + x[10] += ctx->input[10]; + x[11] += ctx->input[11]; + x[12] += ctx->input[12]; + x[13] += ctx->input[13]; + x[14] += ctx->input[14]; + x[15] += ctx->input[15]; + + if (++ctx->input[12] == 0) + ++ctx->input[13]; +} + +static inline void +chacha_xorwr(const chacha_ctx *state, uint8_t *dst, const uint8_t *src) +{ + + /* unrolled loop is fast */ + U32TO8_LITTLE(dst, state->input[0] ^ U8TO32_LITTLE(src)); + U32TO8_LITTLE(dst + 4, state->input[1] ^ U8TO32_LITTLE(src + 4)); + U32TO8_LITTLE(dst + 8, state->input[2] ^ U8TO32_LITTLE(src + 8)); + U32TO8_LITTLE(dst + 12, state->input[3] ^ U8TO32_LITTLE(src + 12)); + U32TO8_LITTLE(dst + 16, state->input[4] ^ U8TO32_LITTLE(src + 16)); + U32TO8_LITTLE(dst + 20, state->input[5] ^ U8TO32_LITTLE(src + 20)); + U32TO8_LITTLE(dst + 24, state->input[6] ^ U8TO32_LITTLE(src + 24)); + U32TO8_LITTLE(dst + 28, state->input[7] ^ U8TO32_LITTLE(src + 28)); + U32TO8_LITTLE(dst + 32, state->input[8] ^ U8TO32_LITTLE(src + 32)); + U32TO8_LITTLE(dst + 36, state->input[9] ^ U8TO32_LITTLE(src + 36)); + U32TO8_LITTLE(dst + 40, state->input[10] ^ U8TO32_LITTLE(src + 40)); + U32TO8_LITTLE(dst + 44, state->input[11] ^ U8TO32_LITTLE(src + 44)); + U32TO8_LITTLE(dst + 48, state->input[12] ^ U8TO32_LITTLE(src + 48)); + U32TO8_LITTLE(dst + 52, state->input[13] ^ U8TO32_LITTLE(src + 52)); + U32TO8_LITTLE(dst + 56, state->input[14] ^ U8TO32_LITTLE(src + 56)); + U32TO8_LITTLE(dst + 60, state->input[15] ^ U8TO32_LITTLE(src + 60)); +} + +void +chacha_encrypt(chacha_ctx *ctx, void *d, const void *s, size_t len) +{ + chacha_ctx state; + const uint8_t *src = s; + uint8_t *dst = d; + + if (len == 0) + return; + + while (len >= CHACHA_BLOCK_LEN) { + chacha_round(ctx, &state); + + chacha_xorwr(&state, dst, src); + + dst += CHACHA_BLOCK_LEN; + src += CHACHA_BLOCK_LEN; + len -= CHACHA_BLOCK_LEN; + } + + if (len > 0) { + uint8_t tmp[CHACHA_BLOCK_LEN]; + + memcpy(tmp, src, len); + chacha_encrypt(ctx, tmp, tmp, sizeof(tmp)); + memcpy(dst, tmp, len); + } +} + +static inline void +chacha_wr(const chacha_ctx *state, uint8_t *dst) +{ + U32TO8_LITTLE(dst, state->input[0]); + U32TO8_LITTLE(dst + 4, state->input[1]); + U32TO8_LITTLE(dst + 8, state->input[2]); + U32TO8_LITTLE(dst + 12, state->input[3]); + U32TO8_LITTLE(dst + 16, state->input[4]); + U32TO8_LITTLE(dst + 20, state->input[5]); + U32TO8_LITTLE(dst + 24, state->input[6]); + U32TO8_LITTLE(dst + 28, state->input[7]); + U32TO8_LITTLE(dst + 32, state->input[8]); + U32TO8_LITTLE(dst + 36, state->input[9]); + U32TO8_LITTLE(dst + 40, state->input[10]); + U32TO8_LITTLE(dst + 44, state->input[11]); + U32TO8_LITTLE(dst + 48, state->input[12]); + U32TO8_LITTLE(dst + 52, state->input[13]); + U32TO8_LITTLE(dst + 56, state->input[14]); + U32TO8_LITTLE(dst + 60, state->input[15]); +} + +void +chacha_stream(chacha_ctx *ctx, void *d, size_t len) +{ + chacha_ctx state; + uint8_t *dst = d; + + if (len == 0) + return; + + while (len >= CHACHA_BLOCK_LEN) { + chacha_round(ctx, &state); + + chacha_wr(&state, dst); + + dst += CHACHA_BLOCK_LEN; + len -= CHACHA_BLOCK_LEN; + } + + if (len > 0) { + uint8_t tmp[CHACHA_BLOCK_LEN]; + + chacha_stream(ctx, tmp, sizeof(tmp)); + memcpy(dst, tmp, len); + } +} Index: crypto/chacha.h =================================================================== RCS file: crypto/chacha.h diff -N crypto/chacha.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ crypto/chacha.h 28 Apr 2015 13:09:36 -0000 @@ -0,0 +1,41 @@ +/* $OpenBSD$ */ + +/* +chacha-merged.c version 20080118 +D. J. Bernstein +Public domain. +*/ + +#ifndef _CHACHA_H_ +#define _CHACHA_H_ + +typedef struct { + uint32_t input[16]; /* could be compressed */ +} chacha_ctx; + +typedef struct { + uint32_t k[4]; +} chacha_128key; + +typedef struct { + uint32_t k[8]; +} chacha_256key; + +typedef struct { + uint32_t iv[2]; +} chacha_iv; + +#define CHACHA_128KEY_LEN sizeof(chacha_128key) +#define CHACHA_256KEY_LEN sizeof(chacha_256key) +#define CHACHA_IV_LEN sizeof(chacha_iv) +#define CHACHA_BLOCK_LEN 64 + +void chacha_128key_setup(chacha_ctx *, const chacha_128key *); +void chacha_256key_setup(chacha_ctx *, const chacha_256key *); +void chacha_iv_setup(chacha_ctx *, const chacha_iv *); +void chacha_stream(chacha_ctx *, void *, size_t) + __bounded((__buffer__, 2, 3)); +void chacha_encrypt(chacha_ctx *, void *, const void *, size_t) + __bounded((__buffer__, 2, 4)) __bounded((__buffer__, 3, 4)); + +#endif /* _CHACHA_H_ */ Index: dev/rnd.c =================================================================== RCS file: /cvs/src/sys/dev/rnd.c,v retrieving revision 1.173 diff -u -p -r1.173 rnd.c --- dev/rnd.c 14 Mar 2015 03:38:46 -0000 1.173 +++ dev/rnd.c 28 Apr 2015 13:09:36 -0000 @@ -128,8 +128,7 @@ #include -#define KEYSTREAM_ONLY -#include +#include #include @@ -214,11 +213,11 @@ struct timer_rand_state { /* There is on #define QEVSLOW (QEVLEN * 3 / 4) /* yet another 0.75 for 60-minutes hour /-; */ #define QEVSBITS 10 -#define KEYSZ 32 -#define IVSZ 8 -#define BLOCKSZ 64 +#define KEYSZ CHACHA_256KEY_LEN +#define IVSZ CHACHA_IV_LEN +#define BLOCKSZ CHACHA_BLOCK_LEN #define RSBUFSZ (16*BLOCKSZ) -#define EBUFSIZE KEYSZ + IVSZ +#define EBUFSIZE (KEYSZ + IVSZ) struct rand_event { struct timer_rand_state *re_state; @@ -488,10 +487,6 @@ extract_entropy(u_int8_t *buf) u_char digest[SHA512_DIGEST_LENGTH]; SHA2_CTX shactx; -#if SHA512_DIGEST_LENGTH < EBUFSIZE -#error "need more bigger hash output" -#endif - /* * INTENTIONALLY not protected by entropylock. Races during * memcpy() result in acceptable input data; races during @@ -568,8 +563,8 @@ static inline void _rs_init(u_char *buf, size_t n) { KASSERT(n >= KEYSZ + IVSZ); - chacha_keysetup(&rs, buf, KEYSZ * 8, 0); - chacha_ivsetup(&rs, buf + KEYSZ); + chacha_256key_setup(&rs, (chacha_256key *)buf); + chacha_iv_setup(&rs, (chacha_iv *)(buf + KEYSZ)); } static void @@ -629,11 +624,8 @@ _rs_stir_if_needed(size_t len) static inline void _rs_rekey(u_char *dat, size_t datlen) { -#ifndef KEYSTREAM_ONLY - memset(rs_buf, 0, RSBUFSZ); -#endif /* fill rs_buf with the keystream */ - chacha_encrypt_bytes(&rs, rs_buf, rs_buf, RSBUFSZ); + chacha_stream(&rs, rs_buf, RSBUFSZ); /* mix in optional user provided data */ if (dat) { size_t i, m; @@ -821,7 +813,10 @@ randomclose(dev_t dev, int flag, int mod int randomread(dev_t dev, struct uio *uio, int ioflag) { - u_char lbuf[KEYSZ+IVSZ]; + struct { + chacha_256key key; + chacha_iv iv; + } lbuf; chacha_ctx lctx; size_t total = uio->uio_resid; u_char *buf; @@ -832,22 +827,19 @@ randomread(dev_t dev, struct uio *uio, i buf = malloc(POOLBYTES, M_TEMP, M_WAITOK); if (total > ARC4_MAIN_MAX_BYTES) { - arc4random_buf(lbuf, sizeof(lbuf)); - chacha_keysetup(&lctx, lbuf, KEYSZ * 8, 0); - chacha_ivsetup(&lctx, lbuf + KEYSZ); - explicit_bzero(lbuf, sizeof(lbuf)); + arc4random_buf(&lbuf, sizeof(lbuf)); + chacha_256key_setup(&lctx, &lbuf.key); + chacha_iv_setup(&lctx, &lbuf.iv); + explicit_bzero(&lbuf, sizeof(lbuf)); myctx = 1; } while (ret == 0 && uio->uio_resid > 0) { int n = min(POOLBYTES, uio->uio_resid); - if (myctx) { -#ifndef KEYSTREAM_ONLY - memset(buf, 0, n); -#endif - chacha_encrypt_bytes(&lctx, buf, buf, n); - } else + if (myctx) + chacha_stream(&lctx, buf, n); + else arc4random_buf(buf, n); ret = uiomovei(buf, n, uio); if (ret == 0 && uio->uio_resid > 0) Index: dev/vscsi.c =================================================================== RCS file: /cvs/src/sys/dev/vscsi.c,v retrieving revision 1.38 diff -u -p -r1.38 vscsi.c --- dev/vscsi.c 14 Mar 2015 03:38:46 -0000 1.38 +++ dev/vscsi.c 28 Apr 2015 13:09:36 -0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -671,7 +672,7 @@ vscsi_ccb_get(void *cookie) ccb = pool_get(&sc->sc_ccb_pool, PR_NOWAIT); if (ccb != NULL) { - ccb->ccb_tag = sc->sc_ccb_tag++; + ccb->ccb_tag = atomic_inc_int_nv(&sc->sc_ccb_tag); ccb->ccb_datalen = 0; } Index: dev/ata/atascsi.c =================================================================== RCS file: /cvs/src/sys/dev/ata/atascsi.c,v retrieving revision 1.123 diff -u -p -r1.123 atascsi.c --- dev/ata/atascsi.c 14 Mar 2015 03:38:47 -0000 1.123 +++ dev/ata/atascsi.c 28 Apr 2015 13:09:36 -0000 @@ -277,7 +277,7 @@ atascsi_probe(struct scsi_link *link) return (ENXIO); } - type = as->as_methods->probe(as->as_cookie, port, link->lun); + type = as->as_methods->ata_probe(as->as_cookie, port, link->lun); switch (type) { case ATA_PORT_T_DISK: break; @@ -437,7 +437,7 @@ error: free(ap, M_DEVBUF, 0); unsupported: - as->as_methods->free(as->as_cookie, port, link->lun); + as->as_methods->ata_free(as->as_cookie, port, link->lun); return (rv); } @@ -464,7 +464,7 @@ atascsi_free(struct scsi_link *link) free(ap, M_DEVBUF, 0); ahp->ahp_ports[link->lun] = NULL; - as->as_methods->free(as->as_cookie, port, link->lun); + as->as_methods->ata_free(as->as_cookie, port, link->lun); if (link->lun == ahp->ahp_nports - 1) { /* we've already freed all of ahp->ahp_ports, now Index: dev/ata/atascsi.h =================================================================== RCS file: /cvs/src/sys/dev/ata/atascsi.h,v retrieving revision 1.48 diff -u -p -r1.48 atascsi.h --- dev/ata/atascsi.h 9 Dec 2013 11:44:52 -0000 1.48 +++ dev/ata/atascsi.h 28 Apr 2015 13:09:36 -0000 @@ -343,8 +343,8 @@ struct ata_xfer { */ struct atascsi_methods { - int (*probe)(void *, int, int); - void (*free)(void *, int, int); + int (*ata_probe)(void *, int, int); + void (*ata_free)(void *, int, int); struct ata_xfer * (*ata_get_xfer)(void *, int); void (*ata_put_xfer)(struct ata_xfer *); void (*ata_cmd)(struct ata_xfer *); Index: kern/init_main.c =================================================================== RCS file: /cvs/src/sys/kern/init_main.c,v retrieving revision 1.237 diff -u -p -r1.237 init_main.c --- kern/init_main.c 12 Apr 2015 11:12:09 -0000 1.237 +++ kern/init_main.c 28 Apr 2015 13:09:36 -0000 @@ -76,6 +76,7 @@ #include #include #include +#include #include #include @@ -457,6 +458,8 @@ main(void *framep) (void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0); dostartuphooks(); + + ktr_enable(); #if NVSCSI > 0 config_rootfound("vscsi", NULL); Index: kern/kern_ktr.c =================================================================== RCS file: kern/kern_ktr.c diff -N kern/kern_ktr.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ kern/kern_ktr.c 28 Apr 2015 13:09:36 -0000 @@ -0,0 +1,164 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2014 David Gwynne + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +#include + +#define KTR_ENTRIES (128 * 1024) + +struct ktr_entry *ktr_entries; +u_int ktr_index; + +void ktr_dump(void); +void ktr_find(void); + +int ktr_enabled = 0; +int ktr_lines = 8; +vaddr_t ktr_vaddr = 0; + +struct ktr_entry *ktr_next(void); +void ktr_print(struct ktr_entry *); + +struct ktr_entry * +ktr_next(void) +{ + extern int ticks; + struct ktr_entry *e; + u_int idx; + + idx = atomic_inc_int_nv(&ktr_index) - 1; + e = &ktr_entries[idx % KTR_ENTRIES]; + + e->ktr_tick = ticks; + e->ktr_cpu = cpu_number(); + + return (e); +} + +void +__ktr_log(const char *file, u_int line, const char *event, int64_t data) +{ + struct ktr_entry *e = ktr_next(); + + e->ktr_file = file; + e->ktr_line = line; + e->ktr_event = event; + e->ktr_thing = "N/A"; + + e->ktr_type = KTR_LLD; + e->ktr_payload.lld = data; +} + +void +__ktr_ext(const char *file, u_int line, const char *event, const char *thing, + void *addr, size_t len) +{ + struct ktr_entry *e = ktr_next(); + + e->ktr_file = file; + e->ktr_line = line; + e->ktr_event = event; + e->ktr_thing = thing; + + e->ktr_type = KTR_EXT; + e->ktr_payload.ext.addr = (vaddr_t)addr; + e->ktr_payload.ext.len = len; +} + +void +ktr_enable(void) +{ + ktr_entries = mallocarray(sizeof(*ktr_entries), KTR_ENTRIES, + M_DEVBUF, M_WAITOK|M_ZERO); + ktr_enabled = 1; +} + +void +ktr_find(void) +{ + vaddr_t addr = ktr_vaddr; + struct ktr_entry *e; + u_int i, idx; + u_int lines = MIN(ktr_lines, KTR_ENTRIES); + + idx = ktr_index; + + printf("%s: looking for %p\n", __func__, (void *)addr); + + for (i = 0; i < lines; i++) { + idx--; + e = &ktr_entries[idx % KTR_ENTRIES]; + + if (e->ktr_file == NULL || + e->ktr_type != KTR_EXT) + continue; + + if (addr < e->ktr_payload.ext.addr || + addr >= e->ktr_payload.ext.addr + e->ktr_payload.ext.len) + continue; + + ktr_print(e); + } +} + +void +ktr_dump(void) +{ + struct ktr_entry *e; + extern int ticks; + u_int i, idx; + u_int lines = MIN(ktr_lines, KTR_ENTRIES); + + idx = ktr_index; + + for (i = 0; i < lines; i++) { + idx--; + e = &ktr_entries[idx % KTR_ENTRIES]; + + if (e->ktr_file == NULL) + continue; + + ktr_print(e); + } +} + +void +ktr_print(struct ktr_entry *e) +{ + printf(" cpu%d@%d: \"%s\" \"%s\" (%s[%u]) ", e->ktr_cpu, + e->ktr_tick, e->ktr_event, e->ktr_thing, + e->ktr_file, e->ktr_line); + switch (e->ktr_type) { + case KTR_LLD: + printf("lld: %lld", e->ktr_payload.lld); + break; + case KTR_EXT: + printf("ext: %p+%zu", + (void *)e->ktr_payload.ext.addr, + e->ktr_payload.ext.len); + break; + case KTR_PTR: + printf("ptr: %p", (void *)e->ktr_payload.ptr); + break; + } + printf("\n"); +} Index: kern/kern_lock.c =================================================================== RCS file: /cvs/src/sys/kern/kern_lock.c,v retrieving revision 1.46 diff -u -p -r1.46 kern_lock.c --- kern/kern_lock.c 14 Sep 2014 14:17:25 -0000 1.46 +++ kern/kern_lock.c 28 Apr 2015 13:09:36 -0000 @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef MP_LOCKDEBUG /* CPU-dependent timing, this needs to be settable from ddb. */ @@ -121,18 +122,102 @@ _kernel_lock_init(void) * and the lower half of the kernel. */ +extern int ticks; +int _kernel_tick = 0; + void -_kernel_lock(void) +__kernel_lock(const char *f, u_int l) { +// int t = ticks; + SCHED_ASSERT_UNLOCKED(); __mp_lock(&kernel_lock); + +// _kernel_tick = ticks; +// ktr_log(f, l, "KERNEL_LOCK", _kernel_tick - t); } void -_kernel_unlock(void) +__kernel_unlock(const char *f, u_int l) { +// int diff; + +// diff = ticks - _kernel_tick; +// ktr_log(f, l, "KERNEL_UNLOCK", diff); +// if (ktr_enabled && !cold && diff > 500000) { +// printf("%s: (%s[%u]) big diff %d\n", __func__, f, l, diff); +// //ktr_enabled = 0; +// } + __mp_unlock(&kernel_lock); } + +int +__kernel_release_all(const char *f, u_int l) +{ +// int diff; + +// diff = ticks - _kernel_tick; +// ktr_log(f, l, "KERNEL_RELEASE_ALL", diff); +// if (ktr_enabled && !cold && diff > 500000) { +// printf("%s: (%s[%u]) big diff %d\n", __func__, f, l, diff); +// //ktr_enabled = 0; +// } + + return (__mp_release_all(&kernel_lock)); +} + +void +__kernel_acquire_count(const char *f, u_int l, int c) +{ +// int t = ticks; + + SCHED_ASSERT_UNLOCKED(); + __mp_acquire_count(&kernel_lock, c); + +// _kernel_tick = ticks; +// ktr_log(f, l, "KERNEL_ACQUIRE", _kernel_tick - t); +} + +inline void +_mtx_enter(struct mutex *mtx, const char *f, u_int l) +{ +// int t = ticks; + + __mtx_enter(mtx); + +// mtx->mtx_tick = ticks; + +// ktr_log(f, l, "mtx_enter", mtx->mtx_tick - t); +} + +inline void +_mtx_leave(struct mutex *mtx, const char *f, u_int l) +{ +// int diff = ticks - mtx->mtx_tick; + +// ktr_log(f, l, "mtx_leave", diff); + + __mtx_leave(mtx); +} + +inline int +_mtx_enter_try(struct mutex *mtx, const char *f, u_int l) +{ +// int t = ticks; + int rv; + + rv = __mtx_enter_try(mtx); +// if (rv == 0) +// return (rv); + +// mtx->mtx_tick = ticks; + +// ktr_log(f, l, "mtx_enter", mtx->mtx_tick - t); + + return (rv); +} + int _kernel_lock_held(void) Index: kern/kern_malloc.c =================================================================== RCS file: /cvs/src/sys/kern/kern_malloc.c,v retrieving revision 1.128 diff -u -p -r1.128 kern_malloc.c --- kern/kern_malloc.c 14 Mar 2015 03:38:50 -0000 1.128 +++ kern/kern_malloc.c 28 Apr 2015 13:09:36 -0000 @@ -40,6 +40,7 @@ #include #include #include +#include #include @@ -117,9 +118,9 @@ struct rwlock sysctl_kmemlock = RWLOCK_I * helps to detect memory reuse problems and avoid free list corruption. */ struct kmem_freelist { - int32_t kf_spare0; + const char *kf_file; int16_t kf_type; - int16_t kf_spare1; + int16_t kf_line; XSIMPLEQ_ENTRY(kmem_freelist) kf_flist; }; @@ -141,11 +142,44 @@ struct timeval malloc_errintvl = { 5, 0 struct timeval malloc_lasterr; #endif +void malloc_chk(void *); +struct timeout malloc_tick = TIMEOUT_INITIALIZER(malloc_chk, NULL); + +void +malloc_chk(void *null) +{ + static int indx = MINBUCKET; + struct kmembuckets *kbp = &bucket[indx]; + struct kmem_freelist *freep; + size_t sz = 1 << indx; + size_t pidx; + u_int32_t word; + int s; + + s = splvm(); + XSIMPLEQ_FOREACH(freep, &kbp->kb_freelist, kf_flist) { + if (poison_check(freep + 1, sz - sizeof(*freep), + &pidx, &word)) { + const char *type = freep->kf_type < M_LAST ? + memname[freep->kf_type] : "???"; + panic("%s: %s data modified in %p+%zu, free() %s[%u]", + __func__, type, freep, sz, + freep->kf_file, freep->kf_line); + } + } + splx(s); + + if (++indx >= nitems(bucket)) + indx = MINBUCKET; + + timeout_add(&malloc_tick, 1); +} + /* * Allocate a block of memory */ void * -malloc(size_t size, int type, int flags) +__ktr_malloc(const char *f, u_int l, size_t size, int type, int flags) { struct kmembuckets *kbp; struct kmemusage *kup; @@ -241,6 +275,8 @@ malloc(size_t size, int type, int flags) splx(s); return (NULL); } + ktr_ext(f, l, "uvm_km_kmemalloc_pla", memname[type], + va, ptoa(npg)); #ifdef KMEMSTATS kbp->kb_total += kbp->kb_elmpercl; #endif @@ -268,8 +304,10 @@ malloc(size_t size, int type, int flags) * Copy in known text to detect modification * after freeing. */ - poison_mem(cp, allocsize); + freep->kf_file = __FILE__; freep->kf_type = M_FREE; + freep->kf_line = __LINE__; + poison_mem(freep + 1, allocsize - sizeof(*freep)); #endif /* DIAGNOSTIC */ XSIMPLEQ_INSERT_HEAD(&kbp->kb_freelist, freep, kf_flist); if (cp <= va) @@ -305,23 +343,20 @@ malloc(size_t size, int type, int flags) } } - /* Fill the fields that we've used with poison */ - poison_mem(freep, sizeof(*freep)); - /* and check that the data hasn't been modified. */ if (freshalloc == 0) { size_t pidx; uint32_t pval; - if (poison_check(va, allocsize, &pidx, &pval)) { - panic("%s %zd of object %p size 0x%lx %s %s" - " (0x%x != 0x%x)\n", - "Data modified on freelist: word", - pidx, va, size, "previous type", - savedtype, ((int32_t*)va)[pidx], pval); + if (poison_check(freep + 1, allocsize - sizeof(*freep), + &pidx, &pval)) { + const char *type = freep->kf_type < M_LAST ? + memname[freep->kf_type] : "???"; + panic("%s: %s data modified in %p+%zu, free() %s[%u]", + __func__, type, freep, allocsize, + freep->kf_file, freep->kf_line); } } - freep->kf_spare0 = 0; #endif /* DIAGNOSTIC */ #ifdef KMEMSTATS kup = btokup(va); @@ -345,6 +380,8 @@ out: if ((flags & M_ZERO) && va != NULL) memset(va, 0, size); + if (va != NULL) + ktr_ext(f, l, "malloc", savedtype, va, allocsize); return (va); } @@ -352,7 +389,7 @@ out: * Free a block of memory allocated by malloc. */ void -free(void *addr, int type, size_t freedsize) +__ktr_free(const char *f, u_int l, void *addr, int type, size_t freedsize) { struct kmembuckets *kbp; struct kmemusage *kup; @@ -385,6 +422,9 @@ free(void *addr, int type, size_t freeds kbp = &bucket[kup->ku_indx]; if (size > MAXALLOCSAVE) size = kup->ku_pagecnt << PAGE_SHIFT; + + ktr_ext(f, l, "free", memname[type], addr, size); + s = splvm(); #ifdef DIAGNOSTIC if (freedsize != 0 && freedsize > size) @@ -406,6 +446,8 @@ free(void *addr, int type, size_t freeds addr, size, memname[type], alloc); #endif /* DIAGNOSTIC */ if (size > MAXALLOCSAVE) { + ktr_ext(f, l, "uvm_km_free", memname[type], + addr, ptoa(kup->ku_pagecnt)); uvm_km_free(kmem_map, (vaddr_t)addr, ptoa(kup->ku_pagecnt)); #ifdef KMEMSTATS ksp->ks_memuse -= size; @@ -422,6 +464,7 @@ free(void *addr, int type, size_t freeds } freep = (struct kmem_freelist *)addr; #ifdef DIAGNOSTIC + #if 0 /* * Check for multiple frees. Use a quick check to see if * it looks free before laboriously searching the freelist. @@ -435,16 +478,18 @@ free(void *addr, int type, size_t freeds panic("free: duplicated free"); } } + #endif /* * Copy in known text to detect modification after freeing * and to make it look free. Also, save the type being freed * so we can list likely culprit if modification is detected * when the object is reallocated. */ - poison_mem(addr, size); - freep->kf_spare0 = poison_value(freep); + freep->kf_file = f; freep->kf_type = type; + freep->kf_line = l; + poison_mem(freep + 1, size - sizeof(*freep)); #endif /* DIAGNOSTIC */ #ifdef KMEMSTATS kup->ku_freecnt++; @@ -562,6 +607,7 @@ kmeminit(void) #ifdef MALLOC_DEBUG debug_malloc_init(); #endif + timeout_add(&malloc_tick, 1); } /* @@ -719,7 +765,8 @@ malloc_printit( #define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) void * -mallocarray(size_t nmemb, size_t size, int type, int flags) +__ktr_mallocarray(const char *f, u_int l, + size_t nmemb, size_t size, int type, int flags) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && nmemb > 0 && SIZE_MAX / nmemb < size) { @@ -727,5 +774,5 @@ mallocarray(size_t nmemb, size_t size, i return (NULL); panic("mallocarray: overflow %zu * %zu", nmemb, size); } - return (malloc(size * nmemb, type, flags)); + return (__ktr_malloc(f, l, size * nmemb, type, flags)); } Index: kern/kern_synch.c =================================================================== RCS file: /cvs/src/sys/kern/kern_synch.c,v retrieving revision 1.119 diff -u -p -r1.119 kern_synch.c --- kern/kern_synch.c 14 Mar 2015 03:38:50 -0000 1.119 +++ kern/kern_synch.c 28 Apr 2015 13:09:36 -0000 @@ -100,7 +100,7 @@ extern int safepri; * call should be interrupted by the signal (return EINTR). */ int -tsleep(const volatile void *ident, int priority, const char *wmesg, int timo) +__tsleep(const volatile void *ident, int priority, const char *wmesg, int timo) { struct sleep_state sls; int error, error1; @@ -145,7 +145,7 @@ tsleep(const volatile void *ident, int p * entered the sleep queue we drop the mutex. After sleeping we re-lock. */ int -msleep(const volatile void *ident, struct mutex *mtx, int priority, +__msleep(const volatile void *ident, struct mutex *mtx, int priority, const char *wmesg, int timo) { struct sleep_state sls; @@ -361,7 +361,7 @@ unsleep(struct proc *p) * Make a number of processes sleeping on the specified identifier runnable. */ void -wakeup_n(const volatile void *ident, int n) +__wakeup_n(const volatile void *ident, int n) { struct slpque *qp; struct proc *p; @@ -385,15 +385,6 @@ wakeup_n(const volatile void *ident, int } } SCHED_UNLOCK(s); -} - -/* - * Make all processes sleeping on the specified identifier runnable. - */ -void -wakeup(const volatile void *chan) -{ - wakeup_n(chan, -1); } int Index: kern/kern_task.c =================================================================== RCS file: /cvs/src/sys/kern/kern_task.c,v retrieving revision 1.14 diff -u -p -r1.14 kern_task.c --- kern/kern_task.c 9 Feb 2015 03:15:41 -0000 1.14 +++ kern/kern_task.c 28 Apr 2015 13:09:36 -0000 @@ -70,6 +70,8 @@ void taskq_init(void); /* called in init void taskq_create_thread(void *); int taskq_sleep(const volatile void *, struct mutex *, int, const char *, int); +int taskq_msleep(const volatile void *, struct mutex *, int, + const char *, int); int taskq_next_work(struct taskq *, struct task *, sleepfn); void taskq_thread(void *); @@ -242,6 +244,13 @@ taskq_sleep(const volatile void *ident, } int +taskq_msleep(const volatile void *ident, struct mutex *mtx, int priority, + const char *wmesg, int tmo) +{ + return (msleep(ident, mtx, priority, wmesg, tmo)); +} + +int taskq_next_work(struct taskq *tq, struct task *work, sleepfn tqsleep) { struct task *next; @@ -273,7 +282,7 @@ taskq_next_work(struct taskq *tq, struct void taskq_thread(void *xtq) { - sleepfn tqsleep = msleep; + sleepfn tqsleep = taskq_msleep; struct taskq *tq = xtq; struct task work; int last; Index: kern/kern_tc.c =================================================================== RCS file: /cvs/src/sys/kern/kern_tc.c,v retrieving revision 1.28 diff -u -p -r1.28 kern_tc.c --- kern/kern_tc.c 10 Dec 2014 02:44:47 -0000 1.28 +++ kern/kern_tc.c 28 Apr 2015 13:09:36 -0000 @@ -147,21 +147,23 @@ binuptime(struct bintime *bt) } void -nanouptime(struct timespec *tsp) +__nanouptime(const char *f, u_int l, struct timespec *tsp) { struct bintime bt; binuptime(&bt); bintime2timespec(&bt, tsp); + ktr_ext(f, l, "nanouptime", "(null)", tsp, sizeof(tsp)); } void -microuptime(struct timeval *tvp) +__microuptime(const char *f, u_int l, struct timeval *tvp) { struct bintime bt; binuptime(&bt); bintime2timeval(&bt, tvp); + ktr_ext(f, l, "microuptime", "(null)", tvp, sizeof(tvp)); } void @@ -173,25 +175,27 @@ bintime(struct bintime *bt) } void -nanotime(struct timespec *tsp) +__nanotime(const char *f, u_int l, struct timespec *tsp) { struct bintime bt; bintime(&bt); bintime2timespec(&bt, tsp); + ktr_ext(f, l, "nanotime", "(null)", tsp, sizeof(tsp)); } void -microtime(struct timeval *tvp) +__microtime(const char *f, u_int l, struct timeval *tvp) { struct bintime bt; bintime(&bt); bintime2timeval(&bt, tvp); + ktr_ext(f, l, "microtime", "(null)", tvp, sizeof(tvp)); } void -getnanouptime(struct timespec *tsp) +__getnanouptime(const char *f, u_int l, struct timespec *tsp) { struct timehands *th; u_int gen; @@ -201,10 +205,11 @@ getnanouptime(struct timespec *tsp) gen = th->th_generation; bintime2timespec(&th->th_offset, tsp); } while (gen == 0 || gen != th->th_generation); + ktr_ext(f, l, "getnanotime", "(null)", tsp, sizeof(tsp)); } void -getmicrouptime(struct timeval *tvp) +__getmicrouptime(const char *f, u_int l, struct timeval *tvp) { struct timehands *th; u_int gen; @@ -214,10 +219,11 @@ getmicrouptime(struct timeval *tvp) gen = th->th_generation; bintime2timeval(&th->th_offset, tvp); } while (gen == 0 || gen != th->th_generation); + ktr_ext(f, l, "getmicrotime", "(null)", tvp, sizeof(tvp)); } void -getnanotime(struct timespec *tsp) +__getnanotime(const char *f, u_int l, struct timespec *tsp) { struct timehands *th; u_int gen; @@ -230,7 +236,7 @@ getnanotime(struct timespec *tsp) } void -getmicrotime(struct timeval *tvp) +__getmicrotime(const char *f, u_int l, struct timeval *tvp) { struct timehands *th; u_int gen; Index: kern/sched_bsd.c =================================================================== RCS file: /cvs/src/sys/kern/sched_bsd.c,v retrieving revision 1.41 diff -u -p -r1.41 sched_bsd.c --- kern/sched_bsd.c 14 Mar 2015 03:38:50 -0000 1.41 +++ kern/sched_bsd.c 28 Apr 2015 13:09:36 -0000 @@ -294,7 +294,7 @@ updatepri(struct proc *p) * performs a voluntary context switch. */ void -yield(void) +__yield(void) { struct proc *p = curproc; int s; @@ -361,8 +361,8 @@ mi_switch(void) * Release the kernel_lock, as we are about to yield the CPU. */ sched_count = __mp_release_all_but_one(&sched_lock); - if (__mp_lock_held(&kernel_lock)) - hold_count = __mp_release_all(&kernel_lock); + if (KERNEL_HELD()) + hold_count = KERNEL_RELEASE(); else hold_count = 0; #endif @@ -451,7 +451,7 @@ mi_switch(void) * we reacquire the interlock and the scheduler lock. */ if (hold_count) - __mp_acquire_count(&kernel_lock, hold_count); + KERNEL_ACQUIRE(hold_count); __mp_acquire_count(&sched_lock, sched_count + 1); #endif } Index: kern/subr_poison.c =================================================================== RCS file: /cvs/src/sys/kern/subr_poison.c,v retrieving revision 1.13 diff -u -p -r1.13 subr_poison.c --- kern/subr_poison.c 14 Mar 2015 03:38:50 -0000 1.13 +++ kern/subr_poison.c 28 Apr 2015 13:09:36 -0000 @@ -20,6 +20,8 @@ #include +#include + /* * The POISON is used as known text to copy into free objects so * that modifications after frees can be detected. @@ -34,7 +36,6 @@ #else #define POISON1 ((unsigned) 0xdeafbead) #endif -#define POISON_SIZE 64 uint32_t poison_value(void *v) @@ -57,40 +58,74 @@ poison_value(void *v) } void +poison_stream(chacha_ctx *ctx) +{ + static chacha_ctx template; + static int poison_init; + + if (__predict_false(poison_init == 0)) { + chacha_256key key; + arc4random_buf(&key, sizeof(key)); + chacha_256key_setup(&template, &key); + poison_init = 1; + } + + memcpy(ctx, &template, sizeof(*ctx)); +} + +void poison_mem(void *v, size_t len) { - uint32_t *ip = v; - size_t i; - uint32_t poison; - - poison = poison_value(v); - - if (len > POISON_SIZE) - len = POISON_SIZE; - len = len / sizeof(*ip); - for (i = 0; i < len; i++) - ip[i] = poison; + uint8_t block[CHACHA_BLOCK_LEN]; + chacha_ctx stream; + u_int64_t iv = (vaddr_t)v; + uint8_t *m = v; + + poison_stream(&stream); + chacha_iv_setup(&stream, (chacha_iv *)&iv); + chacha_stream(&stream, block, sizeof(block)); + + while (len > sizeof(block)) { + memcpy(m, block, sizeof(block)); + m += sizeof(block); + len -= sizeof(block); + } + + if (len > 0) + memcpy(m, block, len); } int poison_check(void *v, size_t len, size_t *pidx, uint32_t *pval) { - uint32_t *ip = v; - size_t i; - uint32_t poison; - - poison = poison_value(v); - - if (len > POISON_SIZE) - len = POISON_SIZE; - len = len / sizeof(*ip); + uint8_t block[CHACHA_BLOCK_LEN]; + chacha_ctx stream; + u_int64_t iv = (vaddr_t)v; + u_int *b = (u_int *)block, *m = v; + u_int bv, mv; + int rv = 0; + u_int i; + + poison_stream(&stream); + chacha_iv_setup(&stream, (chacha_iv *)&iv); + chacha_stream(&stream, block, sizeof(block)); + + len /= sizeof(mv); + for (i = 0; i < len; i++) { - if (ip[i] != poison) { + mv = m[i]; + bv = b[i % (sizeof(block) / sizeof(bv))]; + if (mv != bv) { *pidx = i; - *pval = poison; - return 1; + *pval = bv; + + printf("%s: %p+%zu: memory 0x%08x != poison 0x%08x" + " (^=0x%08x)\n", __func__, v, i * sizeof(mv), + mv, bv, mv ^ bv); + + rv = 1; } } - return 0; -} + return (rv); +} Index: kern/subr_pool.c =================================================================== RCS file: /cvs/src/sys/kern/subr_pool.c,v retrieving revision 1.185 diff -u -p -r1.185 subr_pool.c --- kern/subr_pool.c 21 Apr 2015 13:15:54 -0000 1.185 +++ kern/subr_pool.c 28 Apr 2015 13:09:36 -0000 @@ -166,8 +166,8 @@ void pool_gc_sched(void *); struct timeout pool_gc_tick = TIMEOUT_INITIALIZER(pool_gc_sched, NULL); void pool_gc_pages(void *); struct task pool_gc_task = TASK_INITIALIZER(pool_gc_pages, NULL); -int pool_wait_free = 1; -int pool_wait_gc = 8; +int pool_wait_free = 0; +int pool_wait_gc = 1; static inline int phtree_compare(struct pool_item_header *a, struct pool_item_header *b) @@ -428,7 +428,7 @@ struct pool_get_memory { * Grab an item from the pool. */ void * -pool_get(struct pool *pp, int flags) +__pool_get(const char *f, u_int l, struct pool *pp, int flags) { void *v = NULL; int slowdown = 0; @@ -469,6 +469,8 @@ pool_get(struct pool *pp, int flags) if (ISSET(flags, PR_ZERO)) memset(v, 0, pp->pr_size); +// ktr_ext(f, l, "pool_get", pp->pr_wchan, v, pp->pr_size); + return (v); fail: @@ -635,7 +637,7 @@ pool_do_get(struct pool *pp, int flags, * Return resource to the pool. */ void -pool_put(struct pool *pp, void *v) +__pool_put(const char *f, u_int l, struct pool *pp, void *v) { struct pool_item *pi = v; struct pool_item_header *ph, *freeph = NULL; @@ -646,6 +648,8 @@ pool_put(struct pool *pp, void *v) panic("%s: NULL item", __func__); #endif +// ktr_ext(f, l, "pool_put", pp->pr_wchan, v, pp->pr_size); + mtx_enter(&pp->pr_mtx); if (pp->pr_ipl != -1) @@ -1422,6 +1426,10 @@ pool_allocator_alloc(struct pool *pp, in } } #endif + if (v != NULL) { + ktr_ext(__FILE__, __LINE__, __func__, + pp->pr_wchan, v, pp->pr_pgsize); + } return (v); } @@ -1430,6 +1438,9 @@ void pool_allocator_free(struct pool *pp, void *v) { struct pool_allocator *pa = pp->pr_alloc; + + ktr_ext(__FILE__, __LINE__, __func__, + pp->pr_wchan, v, pp->pr_pgsize); KERNEL_LOCK(); (*pa->pa_free)(pp, v); Index: kern/subr_prf.c =================================================================== RCS file: /cvs/src/sys/kern/subr_prf.c,v retrieving revision 1.85 diff -u -p -r1.85 subr_prf.c --- kern/subr_prf.c 14 Mar 2015 03:38:50 -0000 1.85 +++ kern/subr_prf.c 28 Apr 2015 13:09:36 -0000 @@ -119,7 +119,7 @@ int db_panic = 1; #ifdef DDB_SAFE_CONSOLE int db_console = 1; #else -int db_console = 0; +int db_console = 1; #endif /* Index: kern/uipc_mbuf.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.203 diff -u -p -r1.203 uipc_mbuf.c --- kern/uipc_mbuf.c 13 Apr 2015 08:45:48 -0000 1.203 +++ kern/uipc_mbuf.c 28 Apr 2015 13:09:36 -0000 @@ -125,8 +125,8 @@ void nmbclust_update(void); void m_zero(struct mbuf *); -const char *mclpool_warnmsg = - "WARNING: mclpools limit reached; increase kern.maxclusters"; +const char *mbufpl_warnmsg = + "WARNING: mbuf limit reached; increase kern.maxclusters"; /* * Initialize the mbuf allocator. @@ -168,25 +168,7 @@ mbinit(void) void nmbclust_update(void) { - int i; - /* - * Set the hard limit on the mclpools to the number of - * mbuf clusters the kernel is to support. Log the limit - * reached message max once a minute. - */ - for (i = 0; i < nitems(mclsizes); i++) { - (void)pool_sethardlimit(&mclpools[i], nmbclust, - mclpool_warnmsg, 60); - /* - * XXX this needs to be reconsidered. - * Setting the high water mark to nmbclust is too high - * but we need to have enough spare buffers around so that - * allocations in interrupt context don't fail or mclgeti() - * drivers may end up with empty rings. - */ - pool_sethiwat(&mclpools[i], nmbclust); - } - pool_sethiwat(&mbpool, nmbclust); + (void)pool_sethardlimit(&mbpool, nmbclust, mbufpl_warnmsg, 60); } /* Index: kern/uipc_socket.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.137 diff -u -p -r1.137 uipc_socket.c --- kern/uipc_socket.c 14 Mar 2015 03:38:51 -0000 1.137 +++ kern/uipc_socket.c 28 Apr 2015 13:09:36 -0000 @@ -1440,15 +1440,18 @@ somove(struct socket *so, int wait) void sorwakeup(struct socket *so) { + int wake = 1; + #ifdef SOCKET_SPLICE if (so->so_rcv.sb_flagsintr & SB_SPLICE) (void) somove(so, M_DONTWAIT); if (isspliced(so)) return; #endif - sowakeup(so, &so->so_rcv); if (so->so_upcall) - (*(so->so_upcall))(so, so->so_upcallarg, M_DONTWAIT); + wake = (*(so->so_upcall))(so, so->so_upcallarg, M_DONTWAIT); + if (wake) + sowakeup(so, &so->so_rcv); } void Index: nfs/nfs_socket.c =================================================================== RCS file: /cvs/src/sys/nfs/nfs_socket.c,v retrieving revision 1.108 diff -u -p -r1.108 nfs_socket.c --- nfs/nfs_socket.c 14 Mar 2015 03:38:52 -0000 1.108 +++ nfs/nfs_socket.c 28 Apr 2015 13:09:36 -0000 @@ -1560,17 +1560,17 @@ nfs_msg(struct nfsreq *rep, char *msg) * Essentially do as much as possible non-blocking, else punt and it will * be called with M_WAIT from an nfsd. */ -void -nfsrv_rcv(struct socket *so, caddr_t arg, int waitflag) +int +nfsrv_rcv(struct socket *so, void *arg, int waitflag) { - struct nfssvc_sock *slp = (struct nfssvc_sock *)arg; + struct nfssvc_sock *slp = arg; struct mbuf *m; struct mbuf *mp, *nam; struct uio auio; int flags, error; if ((slp->ns_flag & SLP_VALID) == 0) - return; + return (1); #ifdef notdef /* * Define this to test for nfsds handling this under heavy load. @@ -1663,6 +1663,8 @@ dorecs: if (waitflag == M_DONTWAIT && (slp->ns_rec || (slp->ns_flag & (SLP_NEEDQ | SLP_DISCONN)))) nfsrv_wakenfsd(slp); + + return (0); } /* Index: nfs/nfs_syscalls.c =================================================================== RCS file: /cvs/src/sys/nfs/nfs_syscalls.c,v retrieving revision 1.99 diff -u -p -r1.99 nfs_syscalls.c --- nfs/nfs_syscalls.c 14 Mar 2015 03:38:52 -0000 1.99 +++ nfs/nfs_syscalls.c 28 Apr 2015 13:09:36 -0000 @@ -279,8 +279,8 @@ nfssvc_addsock(struct file *fp, struct m fp->f_count++; slp->ns_fp = fp; s = splsoftnet(); - so->so_upcallarg = (caddr_t)slp; so->so_upcall = nfsrv_rcv; + so->so_upcallarg = slp; slp->ns_flag = (SLP_VALID | SLP_NEEDQ); nfsrv_wakenfsd(slp); splx(s); Index: nfs/nfs_var.h =================================================================== RCS file: /cvs/src/sys/nfs/nfs_var.h,v retrieving revision 1.60 diff -u -p -r1.60 nfs_var.h --- nfs/nfs_var.h 11 Jun 2013 16:42:17 -0000 1.60 +++ nfs/nfs_var.h 28 Apr 2015 13:09:36 -0000 @@ -192,7 +192,7 @@ int nfs_rcvlock(struct nfsreq *); void nfs_rcvunlock(int *); int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int); void nfs_msg(struct nfsreq *, char *); -void nfsrv_rcv(struct socket *, caddr_t, int); +int nfsrv_rcv(struct socket *, void *, int); int nfsrv_getstream(struct nfssvc_sock *, int); int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **); Index: sys/ktr.h =================================================================== RCS file: sys/ktr.h diff -N sys/ktr.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/ktr.h 28 Apr 2015 13:09:36 -0000 @@ -0,0 +1,65 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2014 David Gwynne + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _SYS_KTR_H_ +#define _SYS_KTR_H_ + +struct ktr_entry { + union { + struct { + vaddr_t addr; + size_t len; + } ext; + int64_t lld; + vaddr_t ptr; + } ktr_payload; + const char * ktr_thing; + const char * ktr_event; + const char * ktr_file; + u_int ktr_line; + int ktr_tick; + int ktr_cpu; + enum { + KTR_LLD, + KTR_PTR, + KTR_EXT + } ktr_type; +}; + +extern int ktr_enabled; + +void __ktr_log(const char *, u_int, const char *, int64_t); +void __ktr_ext(const char *, u_int, const char *, const char *, void *, size_t); +void ktr_enable(void); + +#define KTR_LOG(_event, _data) do { \ + if (ktr_enabled) \ + __ktr_log(__FILE__, __LINE__, (_event), (_data)); \ +} while (0) + +#define ktr_log(_f, _l, _event, _data) do { \ + if (ktr_enabled) \ + __ktr_log((_f), (_l), (_event), (_data)); \ +} while (0) + +#define ktr_ext(_f, _l, _e, _t, _addr, _len) do { \ + if (ktr_enabled) \ + __ktr_ext((_f), (_l), (_e), (_t), (_addr), (_len)); \ +} while (0) + +#endif /* _SYS_KTR_H_ */ Index: sys/malloc.h =================================================================== RCS file: /cvs/src/sys/sys/malloc.h,v retrieving revision 1.111 diff -u -p -r1.111 malloc.h --- sys/malloc.h 12 Jul 2014 18:43:32 -0000 1.111 +++ sys/malloc.h 28 Apr 2015 13:09:36 -0000 @@ -391,11 +391,18 @@ extern struct kmemusage *kmemusage; extern char *kmembase; extern struct kmembuckets bucket[]; -void *malloc(size_t, int, int); -void *mallocarray(size_t, size_t, int, int); -void free(void *, int, size_t); +void *__ktr_malloc(const char *, u_int, size_t, int, int); +void *__ktr_mallocarray(const char *, u_int, size_t, size_t, int, int); +void __ktr_free(const char *, u_int, void *, int, size_t); int sysctl_malloc(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +#define malloc(_s, _t, _f) \ + __ktr_malloc(__FILE__, __LINE__, (_s), (_t), (_f)) +#define mallocarray(_s, _m, _t, _f) \ + __ktr_mallocarray(__FILE__, __LINE__, (_s), (_m), (_t), (_f)) +#define free(_p, _t, _s) \ + __ktr_free(__FILE__, __LINE__, (_p), (_t), (_s)) size_t malloc_roundup(size_t); void malloc_printit(int (*)(const char *, ...)); Index: sys/mutex.h =================================================================== RCS file: /cvs/src/sys/sys/mutex.h,v retrieving revision 1.7 diff -u -p -r1.7 mutex.h --- sys/mutex.h 13 Aug 2009 13:24:55 -0000 1.7 +++ sys/mutex.h 28 Apr 2015 13:09:36 -0000 @@ -42,16 +42,30 @@ * "mtx_enter(foo); mtx_enter(bar); mtx_leave(foo); mtx_leave(bar);" */ +#include + #include +#ifdef _KERNEL + /* * Some architectures need to do magic for the ipl, so they need a macro. */ #ifndef mtx_init void mtx_init(struct mutex *, int); #endif -void mtx_enter(struct mutex *); -void mtx_leave(struct mutex *); -int mtx_enter_try(struct mutex *); +void __mtx_enter(struct mutex *); +void __mtx_leave(struct mutex *); +int __mtx_enter_try(struct mutex *); -#endif +void _mtx_enter(struct mutex *, const char *, u_int); +void _mtx_leave(struct mutex *, const char *, u_int); +int _mtx_enter_try(struct mutex *, const char *, u_int); + +#define mtx_enter(_m) _mtx_enter((_m), __func__, __LINE__) +#define mtx_leave(_m) _mtx_leave((_m), __func__, __LINE__) +#define mtx_enter_try(_m) _mtx_enter_try((_m), __func__, __LINE__) + +#endif /* _KERNEL */ + +#endif /* _SYS_MUTEX_H_ */ Index: sys/pool.h =================================================================== RCS file: /cvs/src/sys/sys/pool.h,v retrieving revision 1.57 diff -u -p -r1.57 pool.h --- sys/pool.h 10 Feb 2015 06:16:13 -0000 1.57 +++ sys/pool.h 28 Apr 2015 13:09:36 -0000 @@ -185,14 +185,17 @@ struct uvm_constraint_range; /* XXX */ void pool_set_constraints(struct pool *, const struct kmem_pa_mode *mode); -void *pool_get(struct pool *, int) __malloc; +void *__pool_get(const char *, u_int, struct pool *, int) __malloc; void pool_request_init(struct pool_request *, void (*)(void *, void *), void *); void pool_request(struct pool *, struct pool_request *); -void pool_put(struct pool *, void *); +void __pool_put(const char *, u_int, struct pool *, void *); int pool_reclaim(struct pool *); void pool_reclaim_all(void); int pool_prime(struct pool *, int); + +#define pool_get(_p, _f) __pool_get(__FILE__, __LINE__, (_p), (_f)) +#define pool_put(_p, _m) __pool_put(__FILE__, __LINE__, (_p), (_m)) #ifdef DDB /* Index: sys/sched.h =================================================================== RCS file: /cvs/src/sys/sys/sched.h,v retrieving revision 1.38 diff -u -p -r1.38 sched.h --- sys/sched.h 11 Jan 2015 19:34:52 -0000 1.38 +++ sys/sched.h 28 Apr 2015 13:09:36 -0000 @@ -184,7 +184,7 @@ void remrunqueue(struct proc *); } while (0) #if defined(MULTIPROCESSOR) -#include +#include /* * XXX Instead of using struct lock for the kernel lock and thus requiring us Index: sys/socketvar.h =================================================================== RCS file: /cvs/src/sys/sys/socketvar.h,v retrieving revision 1.58 diff -u -p -r1.58 socketvar.h --- sys/socketvar.h 19 Jan 2015 19:57:59 -0000 1.58 +++ sys/socketvar.h 28 Apr 2015 13:09:36 -0000 @@ -122,8 +122,8 @@ struct socket { #define SB_NOINTR 0x40 /* operations not interruptible */ #define SB_KNOTE 0x80 /* kernel note attached */ - void (*so_upcall)(struct socket *so, caddr_t arg, int waitf); - caddr_t so_upcallarg; /* Arg for above */ + int (*so_upcall)(struct socket *so, void *arg, int waitf); + void * so_upcallarg; /* Arg for above */ uid_t so_euid, so_ruid; /* who opened the socket */ gid_t so_egid, so_rgid; pid_t so_cpid; /* pid of process that opened socket */ Index: sys/syscall_mi.h =================================================================== RCS file: /cvs/src/sys/sys/syscall_mi.h,v retrieving revision 1.5 diff -u -p -r1.5 syscall_mi.h --- sys/syscall_mi.h 11 May 2014 00:12:44 -0000 1.5 +++ sys/syscall_mi.h 28 Apr 2015 13:09:36 -0000 @@ -55,6 +55,8 @@ mi_syscall(struct proc *p, register_t co int lock = !(callp->sy_flags & SY_NOLOCK); int error; + KTR_LOG("syscall in", callp - sysent); + /* refresh the thread's cache of the process's creds */ refreshcreds(p); @@ -85,6 +87,8 @@ mi_syscall(struct proc *p, register_t co if (lock) KERNEL_UNLOCK(); } + + KTR_LOG("syscall err", error); return (error); } Index: sys/systm.h =================================================================== RCS file: /cvs/src/sys/sys/systm.h,v retrieving revision 1.107 diff -u -p -r1.107 systm.h --- sys/systm.h 10 Feb 2015 21:56:10 -0000 1.107 +++ sys/systm.h 28 Apr 2015 13:09:36 -0000 @@ -42,6 +42,7 @@ #include #include +#include /* * The `securelevel' variable controls the security level of the system. @@ -252,12 +253,51 @@ int sleep_finish_signal(struct sleep_sta void sleep_queue_init(void); struct mutex; -void wakeup_n(const volatile void *, int); -void wakeup(const volatile void *); +void __wakeup_n(const volatile void *, int); +#define wakeup_n(_p, _n) do { \ + KTR_LOG("wakeup n", (long)(_p)); \ + __wakeup_n((_p), (_n)); \ +} while (0) #define wakeup_one(c) wakeup_n((c), 1) -int tsleep(const volatile void *, int, const char *, int); -int msleep(const volatile void *, struct mutex *, int, const char*, int); -void yield(void); +#define wakeup(c) wakeup_n((c), -1) +int __tsleep(const volatile void *, int, const char *, int); +static inline int +_tsleep(const volatile void *a, int b, const char *c, int d, + const char *f, u_int l) +{ + int rv; + + ktr_log(f, l, "tsleep in", (long)a); + rv = __tsleep(a, b, c, d); + ktr_log(f, l, "tsleep out", (long)a); + + return (rv); +} +#define tsleep(_a, _b, _c, _d) \ + _tsleep((_a), (_b), (_c), (_d), __func__, __LINE__) + +int __msleep(const volatile void *, struct mutex *, int, const char*, int); +static inline int +_msleep(const volatile void *a, struct mutex *b, int c, const char *d, int e, + const char *f, u_int l) +{ + int rv; + + ktr_log(f, l, "msleep in", (long)a); + rv = __msleep(a, b, c, d, e); + ktr_log(f, l, "msleep out", (long)a); + + return (rv); +} +#define msleep(_a, _b, _c, _d, _e) \ + _msleep((_a), (_b), (_c), (_d), (_e), __func__, __LINE__) + +void __yield(void); +#define yield() do { \ + KTR_LOG("yield in", (long)curproc); \ + __yield(); \ + KTR_LOG("yield out", (long)curproc); \ +} while (0) void wdog_register(int (*)(void *, int), void *); void wdog_shutdown(void *); @@ -332,13 +372,25 @@ void user_config(void); #if defined(MULTIPROCESSOR) void _kernel_lock_init(void); -void _kernel_lock(void); -void _kernel_unlock(void); int _kernel_lock_held(void); +void __kernel_lock(const char *, u_int); +#define _kernel_lock() __kernel_lock(__func__, __LINE__) +void __kernel_unlock(const char *, u_int); +#define _kernel_unlock() __kernel_unlock(__func__, __LINE__) +int __kernel_release_all(const char *, u_int); +#define _kernel_release_all() __kernel_release_all(__func__, __LINE__) +void __kernel_acquire_count(const char *, u_int, int); +#define _kernel_acquire_count(_c) \ + __kernel_acquire_count(__func__, __LINE__, (_c)) + +void __kernel_aquire_count(const char *, u_int, int); #define KERNEL_LOCK_INIT() _kernel_lock_init() +#define KERNEL_HELD() _kernel_lock_held() #define KERNEL_LOCK() _kernel_lock() #define KERNEL_UNLOCK() _kernel_unlock() +#define KERNEL_RELEASE() _kernel_release_all() +#define KERNEL_ACQUIRE(_c) _kernel_acquire_count(_c) #define KERNEL_ASSERT_LOCKED() KASSERT(_kernel_lock_held()) #define KERNEL_ASSERT_UNLOCKED() KASSERT(!_kernel_lock_held()) Index: sys/time.h =================================================================== RCS file: /cvs/src/sys/sys/time.h,v retrieving revision 1.35 diff -u -p -r1.35 time.h --- sys/time.h 25 Oct 2013 04:42:48 -0000 1.35 +++ sys/time.h 28 Apr 2015 13:09:36 -0000 @@ -273,18 +273,27 @@ extern volatile time_t time_uptime; /* S */ void bintime(struct bintime *); -void nanotime(struct timespec *); -void microtime(struct timeval *); +void __nanotime(const char *f, u_int l, struct timespec *); +#define nanotime(_ts) __nanotime(__FILE__, __LINE__, (_ts)) +void __microtime(const char *f, u_int l, struct timeval *); +#define microtime(_tv) __microtime(__FILE__, __LINE__, (_tv)) -void getnanotime(struct timespec *); -void getmicrotime(struct timeval *); +void __getnanotime(const char *f, u_int l, struct timespec *); +#define getnanotime(_ts) __getnanotime(__FILE__, __LINE__, (_ts)) +void __getmicrotime(const char *f, u_int l, struct timeval *); +#define getmicrotime(_tv) __getmicrotime(__FILE__, __LINE__, (_tv)) void binuptime(struct bintime *); -void nanouptime(struct timespec *); -void microuptime(struct timeval *); +void __nanouptime(const char *f, u_int l, struct timespec *); +#define nanouptime(_ts) __nanouptime(__FILE__, __LINE__, (_ts)) +void __microuptime(const char *f, u_int l, struct timeval *); +#define microuptime(_tv) __microuptime(__FILE__, __LINE__, (_tv)) + +void __getnanouptime(const char *f, u_int l, struct timespec *); +#define getnanouptime(_ts) __getnanouptime(__FILE__, __LINE__, (_ts)) +void __getmicrouptime(const char *f, u_int l, struct timeval *); +#define getmicrouptime(_tv) __getmicrouptime(__FILE__, __LINE__, (_tv)) -void getnanouptime(struct timespec *); -void getmicrouptime(struct timeval *); struct proc; int clock_gettime(struct proc *, clockid_t, struct timespec *);