Date: Sat, 10 Aug 2013 14:33:56 +0000 (UTC) From: Attilio Rao <attilio@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r254180 - in user/attilio/vmobj-readlock: include lib/libc/stdio lib/libproc share/man/man4 share/man/man9 sys/arm/arm sys/arm/s3c2xx0 sys/boot/ficl sys/conf sys/dev/random sys/kern sys... Message-ID: <201308101433.r7AEXuiH030448@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: attilio Date: Sat Aug 10 14:33:56 2013 New Revision: 254180 URL: http://svnweb.freebsd.org/changeset/base/254180 Log: MFC Added: user/attilio/vmobj-readlock/sys/dev/random/random_adaptors.c - copied unchanged from r254179, user/attilio/vmcontention/sys/dev/random/random_adaptors.c user/attilio/vmobj-readlock/sys/dev/random/random_adaptors.h - copied unchanged from r254179, user/attilio/vmcontention/sys/dev/random/random_adaptors.h user/attilio/vmobj-readlock/tools/regression/lib/libc/stdio/test-mkostemp.c - copied unchanged from r254179, user/attilio/vmcontention/tools/regression/lib/libc/stdio/test-mkostemp.c user/attilio/vmobj-readlock/tools/tools/usbtest/ - copied from r254179, user/attilio/vmcontention/tools/tools/usbtest/ Modified: user/attilio/vmobj-readlock/include/stdlib.h user/attilio/vmobj-readlock/lib/libc/stdio/Makefile.inc user/attilio/vmobj-readlock/lib/libc/stdio/Symbol.map user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.3 user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.c user/attilio/vmobj-readlock/lib/libproc/proc_sym.c user/attilio/vmobj-readlock/share/man/man4/random.4 user/attilio/vmobj-readlock/share/man/man4/rsu.4 user/attilio/vmobj-readlock/share/man/man9/mutex.9 user/attilio/vmobj-readlock/share/man/man9/vm_page_busy.9 user/attilio/vmobj-readlock/sys/arm/arm/bus_space_generic.c user/attilio/vmobj-readlock/sys/arm/s3c2xx0/s3c2xx0_space.c user/attilio/vmobj-readlock/sys/boot/ficl/loader.c user/attilio/vmobj-readlock/sys/conf/files user/attilio/vmobj-readlock/sys/dev/random/ivy.c user/attilio/vmobj-readlock/sys/dev/random/nehemiah.c user/attilio/vmobj-readlock/sys/dev/random/probe.c user/attilio/vmobj-readlock/sys/dev/random/randomdev.c user/attilio/vmobj-readlock/sys/dev/random/randomdev.h user/attilio/vmobj-readlock/sys/dev/random/randomdev_soft.c user/attilio/vmobj-readlock/sys/dev/random/randomdev_soft.h user/attilio/vmobj-readlock/sys/dev/random/yarrow.c user/attilio/vmobj-readlock/sys/kern/init_main.c user/attilio/vmobj-readlock/sys/kern/kern_malloc.c user/attilio/vmobj-readlock/sys/kern/kern_synch.c user/attilio/vmobj-readlock/sys/sys/proc.h user/attilio/vmobj-readlock/sys/vm/vm_page.c user/attilio/vmobj-readlock/sys/vm/vm_param.h user/attilio/vmobj-readlock/tools/regression/lib/libc/stdio/Makefile user/attilio/vmobj-readlock/tools/tools/sysdoc/tunables.mdoc user/attilio/vmobj-readlock/usr.sbin/watchdogd/watchdogd.c Directory Properties: user/attilio/vmobj-readlock/ (props changed) user/attilio/vmobj-readlock/lib/libc/ (props changed) user/attilio/vmobj-readlock/share/man/man4/ (props changed) user/attilio/vmobj-readlock/sys/ (props changed) user/attilio/vmobj-readlock/sys/boot/ (props changed) user/attilio/vmobj-readlock/sys/conf/ (props changed) Modified: user/attilio/vmobj-readlock/include/stdlib.h ============================================================================== --- user/attilio/vmobj-readlock/include/stdlib.h Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/include/stdlib.h Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/lib/libc/stdio/Makefile.inc ============================================================================== --- user/attilio/vmobj-readlock/lib/libc/stdio/Makefile.inc Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/lib/libc/stdio/Makefile.inc Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/lib/libc/stdio/Symbol.map ============================================================================== --- user/attilio/vmobj-readlock/lib/libc/stdio/Symbol.map Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/lib/libc/stdio/Symbol.map Sat Aug 10 14:33:56 2013 (r254180) @@ -158,6 +158,8 @@ FBSD_1.3 { fmemopen; open_memstream; open_wmemstream; + mkostemp; + mkostemps; }; FBSDprivate_1.0 { Modified: user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.3 ============================================================================== --- user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.3 Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.3 Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.c ============================================================================== --- user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/lib/libc/stdio/mktemp.c Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/lib/libproc/proc_sym.c ============================================================================== --- user/attilio/vmobj-readlock/lib/libproc/proc_sym.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/lib/libproc/proc_sym.c Sat Aug 10 14:33:56 2013 (r254180) @@ -299,6 +299,7 @@ proc_addr2sym(struct proc_handle *p, uin * the function. */ symcopy->st_value = rsym; + error = 0; goto out; } } Modified: user/attilio/vmobj-readlock/share/man/man4/random.4 ============================================================================== --- user/attilio/vmobj-readlock/share/man/man4/random.4 Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/share/man/man4/random.4 Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/share/man/man4/rsu.4 ============================================================================== --- user/attilio/vmobj-readlock/share/man/man4/rsu.4 Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/share/man/man4/rsu.4 Sat Aug 10 14:33:56 2013 (r254180) @@ -22,7 +22,6 @@ .Nm rsu .Nd Realtek RTL8188SU/RTL8192SU USB IEEE 802.11b/g/n wireless network device .Sh SYNOPSIS -.\.Cd "rsu* at uhub? port ?" To compile this driver into the kernel, place the following lines in your kernel configuration file: .Bd -ragged -offset indent @@ -120,6 +119,7 @@ The following adapters should work: .It Sweex LW154 .It TRENDnet TEW-648UB .It TRENDnet TEW-649UB +.El .Sh EXAMPLES Join an existing BSS network (i.e., connect to an access point): .Bd -literal -offset indent @@ -149,14 +149,14 @@ The driver will reset the hardware. This should not happen. .El .Sh SEE ALSO -.Xr arp 8 , +.Xr hostname 1 , .Xr intro 1 , -.Xr netintro 4 , .Xr usb 3 , -.Xr hostname 1 , -.Xr ifconfig 8, +.Xr netintro 4 , +.Xr rsufw 4 , .Xr wlan 4 , -.Xr rsufw 4 +.Xr arp 8 , +.Xr ifconfig 8 .Sh HISTORY The .Nm Modified: user/attilio/vmobj-readlock/share/man/man9/mutex.9 ============================================================================== --- user/attilio/vmobj-readlock/share/man/man9/mutex.9 Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/share/man/man9/mutex.9 Sat Aug 10 14:33:56 2013 (r254180) @@ -226,7 +226,7 @@ lock, respectively, and also accept a .Fa flags argument. In both cases, the only flags presently available for lock acquires are -.Dv MTX_QUIET +.Dv MTX_QUIET and .Dv MTX_RECURSE . If the @@ -243,7 +243,6 @@ bit is turned on in the .Fa flags argument, then the mutex can be acquired recursively. .Pp -.Pp The .Fn mtx_trylock attempts to acquire the Modified: user/attilio/vmobj-readlock/share/man/man9/vm_page_busy.9 ============================================================================== --- user/attilio/vmobj-readlock/share/man/man9/vm_page_busy.9 Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/share/man/man9/vm_page_busy.9 Sat Aug 10 14:33:56 2013 (r254180) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .Dd August 07, 2013 -.Dt vm_page_busy 9 +.Dt VM_PAGE_BUSY 9 .Os .Sh NAME .Nm vm_page_busied , Modified: user/attilio/vmobj-readlock/sys/arm/arm/bus_space_generic.c ============================================================================== --- user/attilio/vmobj-readlock/sys/arm/arm/bus_space_generic.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/arm/arm/bus_space_generic.c Sat Aug 10 14:33:56 2013 (r254180) @@ -104,21 +104,21 @@ generic_bs_alloc(void *t, bus_addr_t rst void generic_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size) { - vm_offset_t va, endva; + vm_offset_t va, endva, origva; - if (pmap_devmap_find_va((vm_offset_t)t, size) != NULL) { + if (pmap_devmap_find_va((vm_offset_t)h, size) != NULL) { /* Device was statically mapped; nothing to do. */ return; } - endva = round_page((vm_offset_t)t + size); - va = trunc_page((vm_offset_t)t); + endva = round_page((vm_offset_t)h + size); + origva = va = trunc_page((vm_offset_t)h); while (va < endva) { pmap_kremove(va); va += PAGE_SIZE; } - kva_free(va, endva - va); + kva_free(origva, endva - origva); } void Modified: user/attilio/vmobj-readlock/sys/arm/s3c2xx0/s3c2xx0_space.c ============================================================================== --- user/attilio/vmobj-readlock/sys/arm/s3c2xx0/s3c2xx0_space.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/arm/s3c2xx0/s3c2xx0_space.c Sat Aug 10 14:33:56 2013 (r254180) @@ -200,21 +200,21 @@ s3c2xx0_bs_map(void *t, bus_addr_t bpa, void s3c2xx0_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size) { - vm_offset_t va, endva; + vm_offset_t va, endva, origva; - if (pmap_devmap_find_va((vm_offset_t)t, size) != NULL) { + if (pmap_devmap_find_va((vm_offset_t)h, size) != NULL) { /* Device was statically mapped; nothing to do. */ return; } - endva = round_page((vm_offset_t)t + size); - va = trunc_page((vm_offset_t)t); + endva = round_page((vm_offset_t)h + size); + origva = va = trunc_page((vm_offset_t)h); while (va < endva) { pmap_kremove(va); va += PAGE_SIZE; } - kva_free(va, endva - va); + kva_free(origva, endva - origva); } int Modified: user/attilio/vmobj-readlock/sys/boot/ficl/loader.c ============================================================================== --- user/attilio/vmobj-readlock/sys/boot/ficl/loader.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/boot/ficl/loader.c Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/sys/conf/files ============================================================================== --- user/attilio/vmobj-readlock/sys/conf/files Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/conf/files Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/sys/dev/random/ivy.c ============================================================================== --- user/attilio/vmobj-readlock/sys/dev/random/ivy.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/dev/random/ivy.c Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/sys/dev/random/nehemiah.c ============================================================================== --- user/attilio/vmobj-readlock/sys/dev/random/nehemiah.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/dev/random/nehemiah.c Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/sys/dev/random/probe.c ============================================================================== --- user/attilio/vmobj-readlock/sys/dev/random/probe.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/dev/random/probe.c Sat Aug 10 14:33:56 2013 (r254180) @@ -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: user/attilio/vmobj-readlock/sys/dev/random/random_adaptors.c (from r254179, user/attilio/vmcontention/sys/dev/random/random_adaptors.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/attilio/vmobj-readlock/sys/dev/random/random_adaptors.c Sat Aug 10 14:33:56 2013 (r254180, copy of r254179, user/attilio/vmcontention/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: user/attilio/vmobj-readlock/sys/dev/random/random_adaptors.h (from r254179, user/attilio/vmcontention/sys/dev/random/random_adaptors.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/attilio/vmobj-readlock/sys/dev/random/random_adaptors.h Sat Aug 10 14:33:56 2013 (r254180, copy of r254179, user/attilio/vmcontention/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: user/attilio/vmobj-readlock/sys/dev/random/randomdev.c ============================================================================== --- user/attilio/vmobj-readlock/sys/dev/random/randomdev.c Sat Aug 10 14:30:09 2013 (r254179) +++ user/attilio/vmobj-readlock/sys/dev/random/randomdev.c Sat Aug 10 14:33:56 2013 (r254180) @@ -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; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308101433.r7AEXuiH030448>