Date: Thu, 22 Aug 2013 04:36:16 +0000 (UTC) From: Neel Natu <neel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r254637 - in projects/bhyve_npt_pmap: include lib/libc/stdio share/man/man4 share/man/man9 sys/amd64/amd64 sys/boot/ficl sys/conf sys/dev/drm2/i915 sys/dev/drm2/ttm sys/dev/random sys/i... Message-ID: <201308220436.r7M4aGXv031135@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: neel Date: Thu Aug 22 04:36:15 2013 New Revision: 254637 URL: http://svnweb.freebsd.org/changeset/base/254637 Log: IFC @254163 Added: projects/bhyve_npt_pmap/sys/dev/random/random_adaptors.c - copied unchanged from r254163, head/sys/dev/random/random_adaptors.c projects/bhyve_npt_pmap/sys/dev/random/random_adaptors.h - copied unchanged from r254163, head/sys/dev/random/random_adaptors.h projects/bhyve_npt_pmap/tools/regression/lib/libc/stdio/test-mkostemp.c - copied unchanged from r254163, head/tools/regression/lib/libc/stdio/test-mkostemp.c projects/bhyve_npt_pmap/tools/tools/usbtest/ - copied from r254163, head/tools/tools/usbtest/ Modified: projects/bhyve_npt_pmap/include/stdlib.h projects/bhyve_npt_pmap/lib/libc/stdio/Makefile.inc projects/bhyve_npt_pmap/lib/libc/stdio/Symbol.map projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.3 projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.c projects/bhyve_npt_pmap/share/man/man4/random.4 projects/bhyve_npt_pmap/share/man/man9/mutex.9 projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c projects/bhyve_npt_pmap/sys/boot/ficl/loader.c projects/bhyve_npt_pmap/sys/conf/files projects/bhyve_npt_pmap/sys/dev/drm2/i915/i915_gem.c projects/bhyve_npt_pmap/sys/dev/drm2/ttm/ttm_bo_vm.c projects/bhyve_npt_pmap/sys/dev/random/ivy.c projects/bhyve_npt_pmap/sys/dev/random/nehemiah.c projects/bhyve_npt_pmap/sys/dev/random/probe.c projects/bhyve_npt_pmap/sys/dev/random/randomdev.c projects/bhyve_npt_pmap/sys/dev/random/randomdev.h projects/bhyve_npt_pmap/sys/dev/random/randomdev_soft.c projects/bhyve_npt_pmap/sys/dev/random/randomdev_soft.h projects/bhyve_npt_pmap/sys/dev/random/yarrow.c projects/bhyve_npt_pmap/sys/i386/i386/pmap.c projects/bhyve_npt_pmap/sys/kern/kern_mutex.c projects/bhyve_npt_pmap/sys/kern/subr_uio.c projects/bhyve_npt_pmap/sys/vm/_vm_radix.h projects/bhyve_npt_pmap/sys/vm/device_pager.c projects/bhyve_npt_pmap/sys/vm/sg_pager.c projects/bhyve_npt_pmap/sys/vm/vm_fault.c projects/bhyve_npt_pmap/sys/vm/vm_object.c projects/bhyve_npt_pmap/sys/vm/vm_object.h projects/bhyve_npt_pmap/sys/vm/vm_page.c projects/bhyve_npt_pmap/sys/vm/vm_page.h projects/bhyve_npt_pmap/sys/vm/vm_radix.c projects/bhyve_npt_pmap/sys/vm/vm_radix.h projects/bhyve_npt_pmap/tools/regression/lib/libc/stdio/Makefile projects/bhyve_npt_pmap/tools/tools/sysdoc/tunables.mdoc Directory Properties: projects/bhyve_npt_pmap/ (props changed) projects/bhyve_npt_pmap/lib/libc/ (props changed) projects/bhyve_npt_pmap/share/man/man4/ (props changed) projects/bhyve_npt_pmap/sys/ (props changed) projects/bhyve_npt_pmap/sys/boot/ (props changed) projects/bhyve_npt_pmap/sys/conf/ (props changed) Modified: projects/bhyve_npt_pmap/include/stdlib.h ============================================================================== --- projects/bhyve_npt_pmap/include/stdlib.h Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/include/stdlib.h Thu Aug 22 04:36:15 2013 (r254637) @@ -282,6 +282,8 @@ const char * int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); int l64a_r(long, char *, int); int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); +int mkostemp(char *, int); +int mkostemps(char *, int, int); void qsort_r(void *, size_t, size_t, void *, int (*)(void *, const void *, const void *)); int radixsort(const unsigned char **, int, const unsigned char *, Modified: projects/bhyve_npt_pmap/lib/libc/stdio/Makefile.inc ============================================================================== --- projects/bhyve_npt_pmap/lib/libc/stdio/Makefile.inc Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/lib/libc/stdio/Makefile.inc Thu Aug 22 04:36:15 2013 (r254637) @@ -60,7 +60,8 @@ MLINKS+=getc.3 fgetc.3 getc.3 getc_unloc getc.3 getchar_unlocked.3 getc.3 getw.3 MLINKS+=getline.3 getdelim.3 MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3 -MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3 +MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3 \ + mktemp.3 mkostemp.3 mktemp.3 mkostemps.3 MLINKS+=open_memstream.3 open_wmemstream.3 MLINKS+=printf.3 asprintf.3 printf.3 dprintf.3 printf.3 fprintf.3 \ printf.3 snprintf.3 printf.3 sprintf.3 \ Modified: projects/bhyve_npt_pmap/lib/libc/stdio/Symbol.map ============================================================================== --- projects/bhyve_npt_pmap/lib/libc/stdio/Symbol.map Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/lib/libc/stdio/Symbol.map Thu Aug 22 04:36:15 2013 (r254637) @@ -158,6 +158,8 @@ FBSD_1.3 { fmemopen; open_memstream; open_wmemstream; + mkostemp; + mkostemps; }; FBSDprivate_1.0 { Modified: projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.3 ============================================================================== --- projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.3 Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.3 Thu Aug 22 04:36:15 2013 (r254637) @@ -28,7 +28,7 @@ .\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd July 5, 2013 +.Dd August 8, 2013 .Dt MKTEMP 3 .Os .Sh NAME @@ -42,6 +42,10 @@ .Fn mktemp "char *template" .Ft int .Fn mkstemp "char *template" +.Ft int +.Fn mkostemp "char *template" "int oflags" +.Ft int +.Fn mkostemps "char *template" "int suffixlen" "int oflags" .Ft char * .Fn mkdtemp "char *template" .In unistd.h @@ -85,16 +89,41 @@ This avoids the race between testing for for use. .Pp The +.Fn mkostemp +function +is like +.Fn mkstemp +but allows specifying additional +.Xr open 2 +flags (defined in +.In fcntl.h ) . +The permitted flags are +.Dv O_APPEND , +.Dv O_DIRECT , +.Dv O_SHLOCK , +.Dv O_EXLOCK , +.Dv O_SYNC +and +.Dv O_CLOEXEC . +.Pp +The .Fn mkstemps -function acts the same as -.Fn mkstemp , -except it permits a suffix to exist in the template. +and +.Fn mkostemps +functions act the same as +.Fn mkstemp +and +.Fn mkostemp +respectively, +except they permit a suffix to exist in the template. The template should be of the form .Pa /tmp/tmpXXXXXXsuffix . The .Fn mkstemps +and +.Fn mkostemps function -is told the length of the suffix string. +are told the length of the suffix string. .Pp The .Fn mkdtemp @@ -110,9 +139,11 @@ functions return a pointer to the templa .Dv NULL on failure. The -.Fn mkstemp -and +.Fn mkstemp , +.Fn mkostemp .Fn mkstemps +and +.Fn mkostemps functions return \-1 if no suitable file could be created. If either call fails an error code is placed in the global variable @@ -120,7 +151,9 @@ If either call fails an error code is pl .Sh ERRORS The .Fn mkstemp , -.Fn mkstemps +.Fn mkostemp , +.Fn mkstemps , +.Fn mkostemps and .Fn mkdtemp functions @@ -133,8 +166,25 @@ The pathname portion of the template is .El .Pp The +.Fn mkostemp +and +.Fn mkostemps +functions +may also set +.Va errno +to the following value: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa oflags +argument is invalid. +.El +.Pp +The .Fn mkstemp , -.Fn mkstemps +.Fn mkostemp , +.Fn mkstemps , +.Fn mkostemps and .Fn mkdtemp functions @@ -145,9 +195,11 @@ to any value specified by the function. .Pp The -.Fn mkstemp -and +.Fn mkstemp , +.Fn mkostemp , .Fn mkstemps +and +.Fn mkostemps functions may also set .Va errno @@ -209,8 +261,11 @@ function is expected to conform to and is not specified by .St -p1003.1-2008 . The +.Fn mkostemp , .Fn mkstemps -function does not conform to any standard. +and +.Fn mkostemps +functions do not conform to any standard. .Sh HISTORY A .Fn mktemp @@ -232,6 +287,12 @@ function first appeared in .Ox 2.4 , and later in .Fx 3.4 . +The +.Fn mkostemp +and +.Fn mkostemps +functions appeared in +.Fx 10.0 . .Sh BUGS This family of functions produces filenames which can be guessed, though the risk is minimized when large numbers of @@ -248,6 +309,8 @@ and opening it for use particularly dangerous from a security perspective. Whenever it is possible, .Fn mkstemp +or +.Fn mkostemp should be used instead, since it does not have the race condition. If .Fn mkstemp Modified: projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.c ============================================================================== --- projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/lib/libc/stdio/mktemp.c Thu Aug 22 04:36:15 2013 (r254637) @@ -47,17 +47,33 @@ __FBSDID("$FreeBSD$"); char *_mktemp(char *); -static int _gettemp(char *, int *, int, int); +static int _gettemp(char *, int *, int, int, int); static const unsigned char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int +mkostemps(char *path, int slen, int oflags) +{ + int fd; + + return (_gettemp(path, &fd, 0, slen, oflags) ? fd : -1); +} + +int mkstemps(char *path, int slen) { int fd; - return (_gettemp(path, &fd, 0, slen) ? fd : -1); + return (_gettemp(path, &fd, 0, slen, 0) ? fd : -1); +} + +int +mkostemp(char *path, int oflags) +{ + int fd; + + return (_gettemp(path, &fd, 0, 0, oflags) ? fd : -1); } int @@ -65,19 +81,19 @@ mkstemp(char *path) { int fd; - return (_gettemp(path, &fd, 0, 0) ? fd : -1); + return (_gettemp(path, &fd, 0, 0, 0) ? fd : -1); } char * mkdtemp(char *path) { - return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); + return (_gettemp(path, (int *)NULL, 1, 0, 0) ? path : (char *)NULL); } char * _mktemp(char *path) { - return (_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL); + return (_gettemp(path, (int *)NULL, 0, 0, 0) ? path : (char *)NULL); } __warn_references(mktemp, @@ -90,7 +106,7 @@ mktemp(char *path) } static int -_gettemp(char *path, int *doopen, int domkdir, int slen) +_gettemp(char *path, int *doopen, int domkdir, int slen, int oflags) { char *start, *trv, *suffp, *carryp; char *pad; @@ -99,7 +115,9 @@ _gettemp(char *path, int *doopen, int do uint32_t rand; char carrybuf[MAXPATHLEN]; - if ((doopen != NULL && domkdir) || slen < 0) { + if ((doopen != NULL && domkdir) || slen < 0 || + (oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC | + O_CLOEXEC)) != 0) { errno = EINVAL; return (0); } @@ -151,7 +169,8 @@ _gettemp(char *path, int *doopen, int do for (;;) { if (doopen) { if ((*doopen = - _open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) + _open(path, O_CREAT|O_EXCL|O_RDWR|oflags, 0600)) >= + 0) return (1); if (errno != EEXIST) return (0); Modified: projects/bhyve_npt_pmap/share/man/man4/random.4 ============================================================================== --- projects/bhyve_npt_pmap/share/man/man4/random.4 Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/share/man/man4/random.4 Thu Aug 22 04:36:15 2013 (r254637) @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 7, 2012 +.Dd August 7, 2013 .Dt RANDOM 4 .Os .Sh NAME @@ -43,6 +43,13 @@ The device will probe for certain hardware entropy sources, and use these in preference to the fallback, which is a generator implemented in software. +If the kernel environment MIB's +.Va hw.nehemiah_rng_enable +or +.Va hw.ivy_rng_enable +are set to +.Dq Li 0 , +the associated hardware entropy source will be ignored. .Pp If the device is using the software generator, @@ -74,6 +81,7 @@ device, use the command line: .Pp which results in something like: .Bd -literal -offset indent +kern.random.adaptors: yarrow kern.random.sys.seeded: 1 kern.random.sys.harvest.ethernet: 1 kern.random.sys.harvest.point_to_point: 1 @@ -89,7 +97,9 @@ kern.random.yarrow.slowoverthresh: 2 (These would not be seen if a hardware generator is present.) .Pp -All settings are read/write. +Other than +.Dl kern.random.adaptors +all settings are read/write. .Pp The .Va kern.random.sys.seeded Modified: projects/bhyve_npt_pmap/share/man/man9/mutex.9 ============================================================================== --- projects/bhyve_npt_pmap/share/man/man9/mutex.9 Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/share/man/man9/mutex.9 Thu Aug 22 04:36:15 2013 (r254637) @@ -225,8 +225,10 @@ or lock, respectively, and also accept a .Fa flags argument. -In both cases, the only flag presently available for lock acquires is -.Dv MTX_QUIET . +In both cases, the only flags presently available for lock acquires are +.Dv MTX_QUIET +and +.Dv MTX_RECURSE . If the .Dv MTX_QUIET bit is turned on in the @@ -235,6 +237,12 @@ argument, then if .Dv KTR_LOCK tracing is being done, it will be silenced during the lock acquire. +If the +.Dv MTX_RECURSE +bit is turned on in the +.Fa flags +argument, then the mutex can be acquired recursively. +.Pp .Pp The .Fn mtx_trylock Modified: projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c ============================================================================== --- projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/amd64/amd64/pmap.c Thu Aug 22 04:36:15 2013 (r254637) @@ -380,7 +380,7 @@ static boolean_t pmap_enter_pde(pmap_t p static vm_page_t pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, vm_page_t mpte, struct rwlock **lockp); static void pmap_fill_ptp(pt_entry_t *firstpte, pt_entry_t newpte); -static void pmap_insert_pt_page(pmap_t pmap, vm_page_t mpte); +static int pmap_insert_pt_page(pmap_t pmap, vm_page_t mpte); static boolean_t pmap_is_modified_pvh(struct md_page *pvh); static boolean_t pmap_is_referenced_pvh(struct md_page *pvh); static void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode); @@ -1854,12 +1854,12 @@ pmap_add_delayed_free_list(vm_page_t m, * for mapping a distinct range of virtual addresses. The pmap's collection is * ordered by this virtual address range. */ -static __inline void +static __inline int pmap_insert_pt_page(pmap_t pmap, vm_page_t mpte) { PMAP_LOCK_ASSERT(pmap, MA_OWNED); - vm_radix_insert(&pmap->pm_root, mpte); + return (vm_radix_insert(&pmap->pm_root, mpte)); } /* @@ -3861,7 +3861,13 @@ setpte: ("pmap_promote_pde: page table page is out of range")); KASSERT(mpte->pindex == pmap_pde_pindex(va), ("pmap_promote_pde: page table page's pindex is wrong")); - pmap_insert_pt_page(pmap, mpte); + if (pmap_insert_pt_page(pmap, mpte)) { + atomic_add_long(&pmap_pde_p_failures, 1); + CTR2(KTR_PMAP, + "pmap_promote_pde: failure for va %#lx in pmap %p", va, + pmap); + return; + } /* * Promote the pv entries. Modified: projects/bhyve_npt_pmap/sys/boot/ficl/loader.c ============================================================================== --- projects/bhyve_npt_pmap/sys/boot/ficl/loader.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/boot/ficl/loader.c Thu Aug 22 04:36:15 2013 (r254637) @@ -518,12 +518,12 @@ static void pfread(FICL_VM *pVM) static void pfreaddir(FICL_VM *pVM) { #ifdef TESTMAIN - static union { - struct dirent dirent; - char buf[512]; - } u; - off_t off; - int len; + static struct dirent dirent; + struct stat sb; + char *buf; + off_t off, ptr; + u_int blksz; + int bufsz; #endif struct dirent *d; int fd; @@ -539,11 +539,39 @@ static void pfreaddir(FICL_VM *pVM) * We do the best we can to make freaddir work, but it's not at * all guaranteed. */ - off = lseek(fd, 0LL, SEEK_CUR); - len = getdents(fd, u.buf, sizeof(u.buf)); - d = (len != -1) ? &u.dirent : NULL; - if (d != NULL) - lseek(fd, off + d->d_reclen, SEEK_SET); + d = NULL; + buf = NULL; + do { + if (fd == -1) + break; + if (fstat(fd, &sb) == -1) + break; + blksz = (sb.st_blksize) ? sb.st_blksize : getpagesize(); + if ((blksz & (blksz - 1)) != 0) + break; + buf = malloc(blksz); + if (buf == NULL) + break; + off = lseek(fd, 0LL, SEEK_CUR); + if (off == -1) + break; + ptr = off; + if (lseek(fd, 0, SEEK_SET) == -1) + break; + bufsz = getdents(fd, buf, blksz); + while (bufsz > 0 && bufsz <= ptr) { + ptr -= bufsz; + bufsz = getdents(fd, buf, blksz); + } + if (bufsz <= 0) + break; + d = (void *)(buf + ptr); + dirent = *d; + off += d->d_reclen; + d = (lseek(fd, off, SEEK_SET) != off) ? NULL : &dirent; + } while (0); + if (buf != NULL) + free(buf); #else d = readdirfd(fd); #endif Modified: projects/bhyve_npt_pmap/sys/conf/files ============================================================================== --- projects/bhyve_npt_pmap/sys/conf/files Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/conf/files Thu Aug 22 04:36:15 2013 (r254637) @@ -2032,6 +2032,7 @@ rt2860.fw optional rt2860fw | ralfw \ dev/random/harvest.c standard dev/random/hash.c optional random dev/random/probe.c optional random +dev/random/random_adaptors.c standard dev/random/randomdev.c optional random dev/random/randomdev_soft.c optional random dev/random/yarrow.c optional random Modified: projects/bhyve_npt_pmap/sys/dev/drm2/i915/i915_gem.c ============================================================================== --- projects/bhyve_npt_pmap/sys/dev/drm2/i915/i915_gem.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/dev/drm2/i915/i915_gem.c Thu Aug 22 04:36:15 2013 (r254637) @@ -64,6 +64,9 @@ __FBSDID("$FreeBSD$"); #include <sys/sched.h> #include <sys/sf_buf.h> +#include <vm/vm.h> +#include <vm/vm_pageout.h> + static void i915_gem_object_flush_cpu_write_domain( struct drm_i915_gem_object *obj); static uint32_t i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, @@ -1443,8 +1446,14 @@ retry: vm_page_busy_sleep(m, "915pbs"); goto retry; } + if (vm_page_insert(m, vm_obj, OFF_TO_IDX(offset))) { + DRM_UNLOCK(dev); + VM_OBJECT_WUNLOCK(vm_obj); + VM_WAIT; + VM_OBJECT_WLOCK(vm_obj); + goto retry; + } m->valid = VM_PAGE_BITS_ALL; - vm_page_insert(m, vm_obj, OFF_TO_IDX(offset)); have_page: *mres = m; vm_page_xbusy(m); Modified: projects/bhyve_npt_pmap/sys/dev/drm2/ttm/ttm_bo_vm.c ============================================================================== --- projects/bhyve_npt_pmap/sys/dev/drm2/ttm/ttm_bo_vm.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/dev/drm2/ttm/ttm_bo_vm.c Thu Aug 22 04:36:15 2013 (r254637) @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include <vm/vm.h> #include <vm/vm_page.h> +#include <vm/vm_pageout.h> #define TTM_BO_VM_NUM_PREFAULT 16 @@ -221,16 +222,23 @@ reserve: ttm_bo_unreserve(bo); goto retry; } - m->valid = VM_PAGE_BITS_ALL; - *mres = m; m1 = vm_page_lookup(vm_obj, OFF_TO_IDX(offset)); if (m1 == NULL) { - vm_page_insert(m, vm_obj, OFF_TO_IDX(offset)); + if (vm_page_insert(m, vm_obj, OFF_TO_IDX(offset))) { + VM_OBJECT_WUNLOCK(vm_obj); + VM_WAIT; + VM_OBJECT_WLOCK(vm_obj); + ttm_mem_io_unlock(man); + ttm_bo_unreserve(bo); + goto retry; + } } else { KASSERT(m == m1, ("inconsistent insert bo %p m %p m1 %p offset %jx", bo, m, m1, (uintmax_t)offset)); } + m->valid = VM_PAGE_BITS_ALL; + *mres = m; vm_page_xbusy(m); if (oldm != NULL) { Modified: projects/bhyve_npt_pmap/sys/dev/random/ivy.c ============================================================================== --- projects/bhyve_npt_pmap/sys/dev/random/ivy.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/dev/random/ivy.c Thu Aug 22 04:36:15 2013 (r254637) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2013 David E. O'Brien <obrien@NUXI.org> * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org> * All rights reserved. * @@ -28,16 +29,19 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include "opt_cpu.h" - -#ifdef RDRAND_RNG - #include <sys/param.h> #include <sys/time.h> +#include <sys/kernel.h> #include <sys/lock.h> +#include <sys/module.h> #include <sys/mutex.h> #include <sys/selinfo.h> #include <sys/systm.h> + +#include <machine/md_var.h> +#include <machine/specialreg.h> + +#include <dev/random/random_adaptors.h> #include <dev/random/randomdev.h> #define RETRY_COUNT 10 @@ -46,7 +50,7 @@ static void random_ivy_init(void); static void random_ivy_deinit(void); static int random_ivy_read(void *, int); -struct random_systat random_ivy = { +struct random_adaptor random_ivy = { .ident = "Hardware, Intel IvyBridge+ RNG", .init = random_ivy_init, .deinit = random_ivy_deinit, @@ -114,4 +118,28 @@ random_ivy_read(void *buf, int c) return (c - count); } +static int +rdrand_modevent(module_t mod, int type, void *unused) +{ + + switch (type) { + case MOD_LOAD: + if (cpu_feature2 & CPUID2_RDRAND) { + random_adaptor_register("rdrand", &random_ivy); + EVENTHANDLER_INVOKE(random_adaptor_attach, &random_ivy); + return (0); + } else { +#ifndef KLD_MODULE + if (bootverbose) #endif + printf( + "%s: RDRAND feature is not present on this CPU\n", + random_ivy.ident); + return (0); + } + } + + return (EINVAL); +} + +RANDOM_ADAPTOR_MODULE(random_rdrand, rdrand_modevent, 1); Modified: projects/bhyve_npt_pmap/sys/dev/random/nehemiah.c ============================================================================== --- projects/bhyve_npt_pmap/sys/dev/random/nehemiah.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/dev/random/nehemiah.c Thu Aug 22 04:36:15 2013 (r254637) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2013 David E. O'Brien <obrien@NUXI.org> * Copyright (c) 2004 Mark R V Murray * All rights reserved. * @@ -28,19 +29,20 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include "opt_cpu.h" - -#ifdef PADLOCK_RNG - #include <sys/param.h> #include <sys/time.h> #include <sys/lock.h> #include <sys/mutex.h> +#include <sys/module.h> #include <sys/selinfo.h> #include <sys/systm.h> +#include <sys/kernel.h> #include <machine/pcb.h> +#include <machine/md_var.h> +#include <machine/specialreg.h> +#include <dev/random/random_adaptors.h> #include <dev/random/randomdev.h> #define RANDOM_BLOCK_SIZE 256 @@ -50,7 +52,7 @@ static void random_nehemiah_init(void); static void random_nehemiah_deinit(void); static int random_nehemiah_read(void *, int); -struct random_systat random_nehemiah = { +struct random_adaptor random_nehemiah = { .ident = "Hardware, VIA Nehemiah", .init = random_nehemiah_init, .deinit = random_nehemiah_deinit, @@ -208,4 +210,29 @@ random_nehemiah_read(void *buf, int c) return (c); } +static int +nehemiah_modevent(module_t mod, int type, void *unused) +{ + + switch (type) { + case MOD_LOAD: + if (via_feature_rng & VIA_HAS_RNG) { + random_adaptor_register("nehemiah", &random_nehemiah); + EVENTHANDLER_INVOKE(random_adaptor_attach, + &random_nehemiah); + return (0); + } else { +#ifndef KLD_MODULE + if (bootverbose) #endif + printf( + "%s: VIA RNG feature is not present on this CPU\n", + random_nehemiah.ident); + return (0); + } + } + + return (EINVAL); +} + +RANDOM_ADAPTOR_MODULE(nehemiah, nehemiah_modevent, 1); Modified: projects/bhyve_npt_pmap/sys/dev/random/probe.c ============================================================================== --- projects/bhyve_npt_pmap/sys/dev/random/probe.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/dev/random/probe.c Thu Aug 22 04:36:15 2013 (r254637) @@ -28,66 +28,35 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#if defined(__amd64__) || (defined(__i386__) && !defined(PC98)) +#if defined(__amd64__) || defined(__i386__) #include "opt_cpu.h" #endif -#include <sys/types.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> -#include <sys/malloc.h> -#include <sys/random.h> #include <sys/selinfo.h> -#include <sys/sysctl.h> - -#if defined(__amd64__) || (defined(__i386__) && !defined(PC98)) -#include <machine/cpufunc.h> -#include <machine/cputypes.h> -#include <machine/md_var.h> -#include <machine/specialreg.h> -#endif +#include <dev/random/random_adaptors.h> #include <dev/random/randomdev.h> -#include <dev/random/randomdev_soft.h> - -#if defined(__amd64__) || (defined(__i386__) && !defined(PC98)) -#ifdef PADLOCK_RNG -extern struct random_systat random_nehemiah; -#endif -#ifdef RDRAND_RNG -extern struct random_systat random_ivy; -#endif -#endif void -random_ident_hardware(struct random_systat **systat) +random_ident_hardware(struct random_adaptor **adaptor) { + struct random_adaptor *tmp; + int enable; - /* Set default to software */ - *systat = &random_yarrow; + /* Set default to software (yarrow) */ + *adaptor = random_adaptor_get("yarrow"); /* Then go looking for hardware */ -#if defined(__amd64__) || (defined(__i386__) && !defined(PC98)) -#ifdef PADLOCK_RNG - if (via_feature_rng & VIA_HAS_RNG) { - int enable; - - enable = 1; - TUNABLE_INT_FETCH("hw.nehemiah_rng_enable", &enable); - if (enable) - *systat = &random_nehemiah; - } -#endif -#ifdef RDRAND_RNG - if (cpu_feature2 & CPUID2_RDRAND) { - int enable; - - enable = 1; - TUNABLE_INT_FETCH("hw.ivy_rng_enable", &enable); - if (enable) - *systat = &random_ivy; - } -#endif -#endif + enable = 1; + TUNABLE_INT_FETCH("hw.nehemiah_rng_enable", &enable); + if (enable && (tmp = random_adaptor_get("nehemiah"))) + *adaptor = tmp; + + enable = 1; + TUNABLE_INT_FETCH("hw.ivy_rng_enable", &enable); + if (enable && (tmp = random_adaptor_get("rdrand"))) + *adaptor = tmp; } Copied: projects/bhyve_npt_pmap/sys/dev/random/random_adaptors.c (from r254163, head/sys/dev/random/random_adaptors.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/bhyve_npt_pmap/sys/dev/random/random_adaptors.c Thu Aug 22 04:36:15 2013 (r254637, copy of r254163, head/sys/dev/random/random_adaptors.c) @@ -0,0 +1,138 @@ +/*- + * Copyright (c) 2013 Arthur Mesh <arthurmesh@gmail.com> + * Copyright (c) 2013 David E. O'Brien <obrien@NUXI.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +__FBSDID("$FreeBSD$"); + +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/lock.h> +#include <sys/selinfo.h> +#include <sys/sysctl.h> +#include <sys/sx.h> +#include <sys/malloc.h> +#include <sys/queue.h> +#include <sys/libkern.h> + +#include <dev/random/random_adaptors.h> +#include <dev/random/randomdev.h> + +LIST_HEAD(adaptors_head, random_adaptors); +static struct adaptors_head adaptors = LIST_HEAD_INITIALIZER(adaptors); +static struct sx adaptors_lock; /* need a sleepable lock */ + +/* List for the dynamic sysctls */ +static struct sysctl_ctx_list random_clist; + +MALLOC_DEFINE(M_RANDOM_ADAPTORS, "random_adaptors", "Random adaptors buffers"); + +int +random_adaptor_register(const char *name, struct random_adaptor *rsp) +{ + struct random_adaptors *rpp; + + KASSERT(name != NULL && rsp != NULL, ("invalid input to %s", __func__)); + + rpp = malloc(sizeof(struct random_adaptors), M_RANDOM_ADAPTORS, M_WAITOK); + rpp->name = name; + rpp->rsp = rsp; + + sx_xlock(&adaptors_lock); + LIST_INSERT_HEAD(&adaptors, rpp, entries); + sx_xunlock(&adaptors_lock); + + return (0); +} + +struct random_adaptor * +random_adaptor_get(const char *name) +{ + struct random_adaptors *rpp; + struct random_adaptor *rsp; + + rsp = NULL; + + sx_slock(&adaptors_lock); + + LIST_FOREACH(rpp, &adaptors, entries) + if (strcmp(rpp->name, name) == 0) + rsp = rpp->rsp; + + sx_sunlock(&adaptors_lock); + + return (rsp); +} + +static void +random_adaptors_deinit(void *unused) +{ + + sx_destroy(&adaptors_lock); + sysctl_ctx_free(&random_clist); +} + +static int +random_sysctl_adaptors_handler(SYSCTL_HANDLER_ARGS) +{ + struct random_adaptors *rpp; + int error; + + error = 0; + + sx_slock(&adaptors_lock); + + if (LIST_EMPTY(&adaptors)) + error = SYSCTL_OUT(req, "", strlen("")); + + LIST_FOREACH(rpp, &adaptors, entries) { + if (0 != SYSCTL_OUT(req, rpp->name, strlen(rpp->name))) + break; + } + + sx_sunlock(&adaptors_lock); + + return (error); +} + +static void +random_adaptors_init(void *unused) +{ + + SYSCTL_PROC(_kern_random, OID_AUTO, adaptors, + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, + NULL, 0, random_sysctl_adaptors_handler, "", + "Random Number Generator adaptors"); + + sx_init(&adaptors_lock, "random_adaptors"); +} + +SYSCTL_NODE(_kern, OID_AUTO, random, CTLFLAG_RW, 0, "Random Number Generator"); + +SYSINIT(random_adaptors, SI_SUB_DRIVERS, SI_ORDER_FIRST, random_adaptors_init, + NULL); +SYSUNINIT(random_adaptors, SI_SUB_DRIVERS, SI_ORDER_FIRST, + random_adaptors_deinit, NULL); Copied: projects/bhyve_npt_pmap/sys/dev/random/random_adaptors.h (from r254163, head/sys/dev/random/random_adaptors.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/bhyve_npt_pmap/sys/dev/random/random_adaptors.h Thu Aug 22 04:36:15 2013 (r254637, copy of r254163, head/sys/dev/random/random_adaptors.h) @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2013 Arthur Mesh <arthurmesh@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __RANDOM_ADAPTORS_H__ +#define __RANDOM_ADAPTORS_H__ + +#include <sys/eventhandler.h> + +struct random_adaptors { + LIST_ENTRY(random_adaptors) entries; /* list of providers */ + const char *name; /* name of random adaptor */ + struct random_adaptor *rsp; +}; + +struct random_adaptor *random_adaptor_get(const char *); +int random_adaptor_register(const char *, struct random_adaptor *); + +/* + * random_adaptor's should be registered prior to + * random module (SI_SUB_DRIVERS/SI_ORDER_MIDDLE) + */ +#define RANDOM_ADAPTOR_MODULE(name, modevent, ver) \ + static moduledata_t name##_mod = { \ + #name, \ + modevent, \ + 0 \ + }; \ + DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, \ + SI_ORDER_SECOND); \ + MODULE_VERSION(name, ver); \ + MODULE_DEPEND(name, random, 1, 1, 1); + +typedef void (*random_adaptor_attach_hook)(void *, struct random_adaptor *); +EVENTHANDLER_DECLARE(random_adaptor_attach, random_adaptor_attach_hook); + +/* kern.random sysctls */ +#ifdef SYSCTL_DECL /* from sysctl.h */ +SYSCTL_DECL(_kern_random); +#endif /* SYSCTL_DECL */ + +#endif /* __RANDOM_ADAPTORS_H__ */ Modified: projects/bhyve_npt_pmap/sys/dev/random/randomdev.c ============================================================================== --- projects/bhyve_npt_pmap/sys/dev/random/randomdev.c Thu Aug 22 04:07:15 2013 (r254636) +++ projects/bhyve_npt_pmap/sys/dev/random/randomdev.c Thu Aug 22 04:36:15 2013 (r254637) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2013 Arthur Mesh <arthurmesh@gmail.com> * Copyright (c) 2000-2004 Mark R V Murray * All rights reserved. * @@ -70,12 +71,15 @@ static struct cdevsw random_cdevsw = { .d_name = "random", }; -struct random_systat *random_systat; +static struct random_adaptor *random_adaptor; +static eventhandler_tag attach_tag; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308220436.r7M4aGXv031135>