svn commit: r357390 - in projects/clang1000-import: include lib/libc/stdlib share/man/man4 sys/compat/linux sys/dev/tpm sys/fs/devfs sys/fs/pseudofs sys/fs/tmpfs sys/kern sys/riscv/sifive sys/sys s...
Dimitry Andric
dim at FreeBSD.org
Sat Feb 1 22:07:41 UTC 2020
Author: dim
Date: Sat Feb 1 22:07:37 2020
New Revision: 357390
URL: https://svnweb.freebsd.org/changeset/base/357390
Log:
Merge ^/head r357368 through r357388.
Modified:
projects/clang1000-import/include/stdlib.h
projects/clang1000-import/lib/libc/stdlib/Symbol.map
projects/clang1000-import/lib/libc/stdlib/rand.3
projects/clang1000-import/lib/libc/stdlib/rand.c
projects/clang1000-import/lib/libc/stdlib/random.3
projects/clang1000-import/lib/libc/stdlib/random.c
projects/clang1000-import/lib/libc/stdlib/random.h
projects/clang1000-import/share/man/man4/hwpstate_intel.4
projects/clang1000-import/sys/compat/linux/linux_getcwd.c
projects/clang1000-import/sys/dev/tpm/tpm_crb.c
projects/clang1000-import/sys/dev/tpm/tpm_tis.c
projects/clang1000-import/sys/fs/devfs/devfs_vnops.c
projects/clang1000-import/sys/fs/pseudofs/pseudofs_vnops.c
projects/clang1000-import/sys/fs/tmpfs/tmpfs_vnops.c
projects/clang1000-import/sys/kern/kern_sig.c
projects/clang1000-import/sys/kern/vfs_cache.c
projects/clang1000-import/sys/kern/vfs_default.c
projects/clang1000-import/sys/kern/vnode_if.src
projects/clang1000-import/sys/riscv/sifive/fu540_prci.c
projects/clang1000-import/sys/sys/syscallsubr.h
projects/clang1000-import/sys/sys/vnode.h
projects/clang1000-import/sys/vm/vm_page.c
projects/clang1000-import/sys/vm/vm_page.h
projects/clang1000-import/sys/x86/cpufreq/hwpstate_intel.c
projects/clang1000-import/sys/x86/include/specialreg.h
projects/clang1000-import/sys/x86/x86/identcpu.c
projects/clang1000-import/tests/sys/net/if_epair.c
Directory Properties:
projects/clang1000-import/ (props changed)
Modified: projects/clang1000-import/include/stdlib.h
==============================================================================
--- projects/clang1000-import/include/stdlib.h Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/include/stdlib.h Sat Feb 1 22:07:37 2020 (r357390)
@@ -73,7 +73,11 @@ typedef struct {
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-#define RAND_MAX 0x7ffffffd
+/*
+ * I.e., INT_MAX; rand(3) returns a signed integer but must produce output in
+ * the range [0, RAND_MAX], so half of the possible output range is unused.
+ */
+#define RAND_MAX 0x7fffffff
__BEGIN_DECLS
#ifdef _XLOCALE_H_
Modified: projects/clang1000-import/lib/libc/stdlib/Symbol.map
==============================================================================
--- projects/clang1000-import/lib/libc/stdlib/Symbol.map Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/lib/libc/stdlib/Symbol.map Sat Feb 1 22:07:37 2020 (r357390)
@@ -54,8 +54,6 @@ FBSD_1.0 {
radixsort;
sradixsort;
rand_r;
- rand;
- srand;
srandom;
srandomdev;
initstate;
@@ -125,6 +123,8 @@ FBSD_1.5 {
FBSD_1.6 {
qsort_s;
+ rand;
+ srand;
};
FBSDprivate_1.0 {
Modified: projects/clang1000-import/lib/libc/stdlib/rand.3
==============================================================================
--- projects/clang1000-import/lib/libc/stdlib/rand.3 Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/lib/libc/stdlib/rand.3 Sat Feb 1 22:07:37 2020 (r357390)
@@ -32,7 +32,7 @@
.\" @(#)rand.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd December 14, 2019
+.Dd February 1, 2020
.Dt RAND 3
.Os
.Sh NAME
@@ -59,49 +59,52 @@ Applications which require unpredictable random number
instead.
.Ef
.Pp
-These interfaces are obsoleted by
-.Xr random 3 .
-.Pp
The
.Fn rand
function computes a sequence of pseudo-random integers in the range
of 0 to
-.Dv RAND_MAX
-(as defined by the header file
-.In stdlib.h ) .
+.Dv RAND_MAX ,
+inclusive.
.Pp
The
.Fn srand
-function sets its argument
+function seeds the algorithm with the
.Fa seed
-as the seed for a new sequence of
-pseudo-random numbers to be returned by
-.Fn rand .
-These sequences are repeatable by calling
+parameter.
+Repeatable sequences of
+.Fn rand
+output may be obtained by calling
.Fn srand
-with the same seed value.
+with the same
+.Fa seed .
+.Fn rand
+is implicitly initialized as if
+.Fn srand "1"
+had been invoked explicitly.
.Pp
-If no
-.Fa seed
-value is provided, the functions are automatically
-seeded with a value of 1.
-.Pp
-The
+In
+.Fx 13 ,
+.Fn rand
+is implemented using the same 128-byte state LFSR generator algorithm as
+.Xr random 3 .
+However, the legacy
.Fn rand_r
-function
-provides the same functionality as
-.Fn rand .
-A pointer to the context value
-.Fa ctx
-must be supplied by the caller.
-.Pp
-For better generator quality, use
-.Xr random 3
-or
-.Xr lrand48 3 .
+function is not (and can not be, because of its limited
+.Fa *ctx
+size).
+.Fn rand_r
+implements the historical, poor-quality Park-Miller 32-bit LCG and should not
+be used in new designs.
+.Sh IMPLEMENTATION NOTES
+Since
+.Fx 13 ,
+.Fn rand
+is implemented with the same generator as
+.Xr random 3 ,
+so the low-order bits should no longer be significantly worse than the
+high-order bits.
.Sh SEE ALSO
.Xr arc4random 3 ,
-.Xr lrand48 3 ,
.Xr random 3 ,
.Xr random 4
.Sh STANDARDS
@@ -115,5 +118,32 @@ conform to
.Pp
The
.Fn rand_r
-function is marked as obsolescent in POSIX and may be removed in a future
-revision of the standard.
+function is not part of
+.St -isoC
+and is marked obsolescent in
+.St -p1003.1-2008 .
+It may be removed in a future revision of POSIX.
+.Sh CAVEATS
+Prior to
+.Fx 13 ,
+.Fn rand
+used the historical Park-Miller generator with 32 bits of state and produced
+poor quality output, especially in the lower bits.
+.Fn rand
+in earlier versions of
+.Fx ,
+as well as other standards-conforming implementations, may continue to produce
+poor quality output.
+.Pp
+.Em These functions should not be used in portable applications that want a
+.Em high quality or high performance pseudorandom number generator .
+One possible replacement,
+.Xr random 3 ,
+is portable to Linux — but it is not especially fast, nor standardized.
+.Pp
+If broader portability or better performance is desired, any of the widely
+available and permissively licensed SFC64/32, JSF64/32, PCG64/32, or SplitMix64
+algorithm implementations may be embedded in your application.
+These algorithms have the benefit of requiring less space than
+.Xr random 3
+and being quite fast (in header inline implementations).
Modified: projects/clang1000-import/lib/libc/stdlib/rand.c
==============================================================================
--- projects/clang1000-import/lib/libc/stdlib/rand.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/lib/libc/stdlib/rand.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -40,11 +40,60 @@ __FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/param.h>
#include <sys/sysctl.h>
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <syslog.h>
#include "un-namespace.h"
+#include "random.h"
+
+/*
+ * Implement rand(3), the standard C PRNG API, using the non-standard but
+ * higher quality random(3) implementation and the same size 128-byte state
+ * LFSR as the random(3) default.
+ *
+ * It turns out there are portable applications that want a PRNG but are too
+ * lazy to use better-but-nonstandard interfaces like random(3), when
+ * available, and too lazy to import higher-quality and faster PRNGs into their
+ * codebase (such as any of SFC, JSF, 128-bit LCGs, PCG, or Splitmix64).
+ *
+ * Since we're stuck with rand(3) due to the C standard, we can at least have
+ * it produce a relatively good PRNG sequence using our existing random(3)
+ * LFSR. The random(3) design is not particularly fast nor compact, but it has
+ * the advantage of being the one already in the tree.
+ */
+static struct __random_state *rand3_state;
+
+static void
+initialize_rand3(void)
+{
+ int error;
+
+ rand3_state = allocatestate(TYPE_3);
+ error = initstate_r(rand3_state, 1, rand3_state->rst_randtbl, BREAK_3);
+ assert(error == 0);
+}
+
+int
+rand(void)
+{
+ if (rand3_state == NULL)
+ initialize_rand3();
+ return ((int)random_r(rand3_state));
+}
+
+void
+srand(unsigned seed)
+{
+ if (rand3_state == NULL)
+ initialize_rand3();
+ srandom_r(rand3_state, seed);
+}
+
+/*
+ * FreeBSD 12 and prior compatibility implementation of rand(3).
+ */
static int
do_rand(unsigned long *ctx)
{
@@ -71,7 +120,9 @@ do_rand(unsigned long *ctx)
return (x);
}
-
+/*
+ * Can't fix this garbage; too little state.
+ */
int
rand_r(unsigned *ctx)
{
@@ -84,21 +135,23 @@ rand_r(unsigned *ctx)
return (r);
}
-
static u_long next = 1;
+int __rand_fbsd12(void);
int
-rand(void)
+__rand_fbsd12(void)
{
return (do_rand(&next));
}
+__sym_compat(rand, __rand_fbsd12, FBSD_1.0);
+void __srand_fbsd12(unsigned seed);
void
-srand(unsigned seed)
+__srand_fbsd12(unsigned seed)
{
next = seed;
}
-
+__sym_compat(srand, __srand_fbsd12, FBSD_1.0);
void __sranddev_fbsd12(void);
void
Modified: projects/clang1000-import/lib/libc/stdlib/random.3
==============================================================================
--- projects/clang1000-import/lib/libc/stdlib/random.3 Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/lib/libc/stdlib/random.3 Sat Feb 1 22:07:37 2020 (r357390)
@@ -28,7 +28,7 @@
.\" @(#)random.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd January 20, 2020
+.Dd February 1, 2020
.Dt RANDOM 3
.Os
.Sh NAME
@@ -74,8 +74,7 @@ The period of this random number generator is very lar
.Pp
If initialized with less than 32 bytes of state,
.Fn random
-uses the same poor-quality Park-Miller LCG as
-.Xr rand 3 .
+uses the poor-quality 32-bit Park-Miller LCG.
.Pp
The
.Fn random
@@ -85,9 +84,6 @@ functions are analagous to
.Xr rand 3
and
.Xr srand 3 .
-The difference is that
-.Xr rand 3
-is a worse pseudo-random number generator.
.Pp
Like
.Xr rand 3 ,
Modified: projects/clang1000-import/lib/libc/stdlib/random.c
==============================================================================
--- projects/clang1000-import/lib/libc/stdlib/random.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/lib/libc/stdlib/random.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -104,48 +104,13 @@ __FBSDID("$FreeBSD$");
* byte buffer it is about 5 percent faster.
*/
-/*
- * For each of the currently supported random number generators, we have a
- * break value on the amount of state information (you need at least this
- * many bytes of state info to support this random number generator), a degree
- * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
- * the separation between the two lower order coefficients of the trinomial.
- */
-#define TYPE_0 0 /* linear congruential */
-#define BREAK_0 8
-#define DEG_0 0
-#define SEP_0 0
-
-#define TYPE_1 1 /* x**7 + x**3 + 1 */
-#define BREAK_1 32
-#define DEG_1 7
-#define SEP_1 3
-
-#define TYPE_2 2 /* x**15 + x + 1 */
-#define BREAK_2 64
-#define DEG_2 15
-#define SEP_2 1
-
-#define TYPE_3 3 /* x**31 + x**3 + 1 */
-#define BREAK_3 128
-#define DEG_3 31
-#define SEP_3 3
-
-#define TYPE_4 4 /* x**63 + x + 1 */
-#define BREAK_4 256
-#define DEG_4 63
-#define SEP_4 1
-
-/*
- * Array versions of the above information to make code run faster --
- * relies on fact that TYPE_i == i.
- */
-#define MAX_TYPES 5 /* max number of types above */
-
#define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */
static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
-static const int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
+static const int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
+static const int breaks[MAX_TYPES] = {
+ BREAK_0, BREAK_1, BREAK_2, BREAK_3, BREAK_4
+};
/*
* Initially, everything is set up as if from:
@@ -523,4 +488,20 @@ long
random(void)
{
return (random_r(&implicit));
+}
+
+struct __random_state *
+allocatestate(unsigned type)
+{
+ size_t asize;
+
+ /* No point using this interface to get the Park-Miller LCG. */
+ if (type < TYPE_1)
+ abort();
+ /* Clamp to widest supported variant. */
+ if (type > (MAX_TYPES - 1))
+ type = (MAX_TYPES - 1);
+
+ asize = sizeof(struct __random_state) + (size_t)breaks[type];
+ return (malloc(asize));
}
Modified: projects/clang1000-import/lib/libc/stdlib/random.h
==============================================================================
--- projects/clang1000-import/lib/libc/stdlib/random.h Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/lib/libc/stdlib/random.h Sat Feb 1 22:07:37 2020 (r357390)
@@ -27,6 +27,44 @@
#pragma once
+/*
+ * For each of the currently supported random number generators, we have a
+ * break value on the amount of state information (you need at least this
+ * many bytes of state info to support this random number generator), a degree
+ * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
+ * the separation between the two lower order coefficients of the trinomial.
+ */
+#define TYPE_0 0 /* linear congruential */
+#define BREAK_0 8
+#define DEG_0 0
+#define SEP_0 0
+
+#define TYPE_1 1 /* x**7 + x**3 + 1 */
+#define BREAK_1 32
+#define DEG_1 7
+#define SEP_1 3
+
+#define TYPE_2 2 /* x**15 + x + 1 */
+#define BREAK_2 64
+#define DEG_2 15
+#define SEP_2 1
+
+#define TYPE_3 3 /* x**31 + x**3 + 1 */
+#define BREAK_3 128
+#define DEG_3 31
+#define SEP_3 3
+
+#define TYPE_4 4 /* x**63 + x + 1 */
+#define BREAK_4 256
+#define DEG_4 63
+#define SEP_4 1
+
+/*
+ * Array versions of the above information to make code run faster --
+ * relies on fact that TYPE_i == i.
+ */
+#define MAX_TYPES 5 /* max number of types above */
+
/* A full instance of the random(3) generator. */
struct __random_state {
uint32_t *rst_fptr;
@@ -40,6 +78,7 @@ struct __random_state {
uint32_t rst_randtbl[];
};
+struct __random_state *allocatestate(unsigned type);
int initstate_r(struct __random_state *, unsigned, uint32_t *, size_t);
long random_r(struct __random_state *);
void srandom_r(struct __random_state *, unsigned);
Modified: projects/clang1000-import/share/man/man4/hwpstate_intel.4
==============================================================================
--- projects/clang1000-import/share/man/man4/hwpstate_intel.4 Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/share/man/man4/hwpstate_intel.4 Sat Feb 1 22:07:37 2020 (r357390)
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 22, 2020
+.Dd February 1, 2020
.Dt HWPSTATE_INTEL 4
.Os
.Sh NAME
@@ -49,7 +49,15 @@ Can be used to disable
.Nm ,
allowing other compatible drivers to manage performance states, like
.Xr est 4 .
-.Pq default 0
+Defaults to
+.Dv Qq 0
+(enabled).
+.It Va machdep.hwpstate_pkg_ctrl
+Selects between package-level control (the default) and per-core control.
+.Dv Qq 1
+selects package-level control and
+.Dv Qq 0
+selects core-level control.
.El
.Sh SYSCTL VARIABLES
The following
Modified: projects/clang1000-import/sys/compat/linux/linux_getcwd.c
==============================================================================
--- projects/clang1000-import/sys/compat/linux/linux_getcwd.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/compat/linux/linux_getcwd.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/syscallsubr.h>
+#include <sys/vnode.h>
#include <sys/proc.h>
#include <sys/malloc.h>
@@ -60,28 +60,25 @@ __FBSDID("$FreeBSD$");
* Find pathname of process's current directory.
*/
int
-linux_getcwd(struct thread *td, struct linux_getcwd_args *args)
+linux_getcwd(struct thread *td, struct linux_getcwd_args *uap)
{
- char *path;
- int error, lenused;
+ char *buf, *retbuf;
+ size_t buflen;
+ int error;
- /*
- * Linux returns ERANGE instead of EINVAL.
- */
- if (args->bufsize < 2)
+ buflen = uap->bufsize;
+ if (__predict_false(buflen < 2))
return (ERANGE);
+ if (buflen > LINUX_PATH_MAX)
+ buflen = LINUX_PATH_MAX;
- path = malloc(LINUX_PATH_MAX, M_LINUX, M_WAITOK);
-
- error = kern___getcwd(td, path, UIO_SYSSPACE, args->bufsize,
- LINUX_PATH_MAX);
+ buf = malloc(buflen, M_TEMP, M_WAITOK);
+ error = vn_getcwd(td, buf, &retbuf, &buflen);
if (error == 0) {
- lenused = strlen(path) + 1;
- error = copyout(path, args->buf, lenused);
+ error = copyout(retbuf, uap->buf, buflen);
if (error == 0)
- td->td_retval[0] = lenused;
+ td->td_retval[0] = buflen;
}
-
- free(path, M_LINUX);
+ free(buf, M_TEMP);
return (error);
}
Modified: projects/clang1000-import/sys/dev/tpm/tpm_crb.c
==============================================================================
--- projects/clang1000-import/sys/dev/tpm/tpm_crb.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/dev/tpm/tpm_crb.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -70,7 +70,8 @@ __FBSDID("$FreeBSD$");
#define TPM_CRB_CTRL_STS_ERR_BIT BIT(0)
#define TPM_CRB_CTRL_STS_IDLE_BIT BIT(1)
-#define TPM_CRB_CTRL_CANCEL_CMD BIT(0)
+#define TPM_CRB_CTRL_CANCEL_CMD 0x1
+#define TPM_CRB_CTRL_CANCEL_CLEAR 0x0
#define TPM_CRB_CTRL_START_CMD BIT(0)
@@ -298,7 +299,7 @@ tpmcrb_cancel_cmd(struct tpm_sc *sc)
return (false);
}
- WR4(sc, TPM_CRB_CTRL_CANCEL, ~TPM_CRB_CTRL_CANCEL_CMD);
+ WR4(sc, TPM_CRB_CTRL_CANCEL, TPM_CRB_CTRL_CANCEL_CLEAR;
return (true);
}
@@ -330,7 +331,7 @@ tpmcrb_transmit(struct tpm_sc *sc, size_t length)
return (EIO);
}
/* Clear cancellation bit */
- WR4(sc, TPM_CRB_CTRL_CANCEL, ~TPM_CRB_CTRL_CANCEL_CMD);
+ WR4(sc, TPM_CRB_CTRL_CANCEL, TPM_CRB_CTRL_CANCEL_CLEAR;
/* Switch device to idle state if necessary */
if (!(RD4(sc, TPM_CRB_CTRL_STS) & TPM_CRB_CTRL_STS_IDLE_BIT)) {
Modified: projects/clang1000-import/sys/dev/tpm/tpm_tis.c
==============================================================================
--- projects/clang1000-import/sys/dev/tpm/tpm_tis.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/dev/tpm/tpm_tis.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -386,12 +386,11 @@ tpmtis_go_ready(struct tpm_sc *sc)
mask = TPM_STS_CMD_RDY;
sc->intr_type = TPM_INT_STS_CMD_RDY;
- OR4(sc, TPM_STS, TPM_STS_CMD_RDY);
+ WR4(sc, TPM_STS, TPM_STS_CMD_RDY);
bus_barrier(sc->mem_res, TPM_STS, 4, BUS_SPACE_BARRIER_WRITE);
if (!tpm_wait_for_u32(sc, TPM_STS, mask, mask, TPM_TIMEOUT_B))
return (false);
- AND4(sc, TPM_STS, ~TPM_STS_CMD_RDY);
return (true);
}
Modified: projects/clang1000-import/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- projects/clang1000-import/sys/fs/devfs/devfs_vnops.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/fs/devfs/devfs_vnops.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -274,7 +274,7 @@ devfs_vptocnp(struct vop_vptocnp_args *ap)
struct vnode **dvp = ap->a_vpp;
struct devfs_mount *dmp;
char *buf = ap->a_buf;
- int *buflen = ap->a_buflen;
+ size_t *buflen = ap->a_buflen;
struct devfs_dirent *dd, *de;
int i, error;
Modified: projects/clang1000-import/sys/fs/pseudofs/pseudofs_vnops.c
==============================================================================
--- projects/clang1000-import/sys/fs/pseudofs/pseudofs_vnops.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/fs/pseudofs/pseudofs_vnops.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -377,7 +377,7 @@ pfs_vptocnp(struct vop_vptocnp_args *ap)
struct pfs_node *pn;
struct mount *mp;
char *buf = ap->a_buf;
- int *buflen = ap->a_buflen;
+ size_t *buflen = ap->a_buflen;
char pidbuf[PFS_NAMELEN];
pid_t pid = pvd->pvd_pid;
int len, i, error, locked;
Modified: projects/clang1000-import/sys/fs/tmpfs/tmpfs_vnops.c
==============================================================================
--- projects/clang1000-import/sys/fs/tmpfs/tmpfs_vnops.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/fs/tmpfs/tmpfs_vnops.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -1491,7 +1491,7 @@ tmpfs_vptocnp_dir(struct tmpfs_node *tn, struct tmpfs_
static int
tmpfs_vptocnp_fill(struct vnode *vp, struct tmpfs_node *tn,
- struct tmpfs_node *tnp, char *buf, int *buflen, struct vnode **dvp)
+ struct tmpfs_node *tnp, char *buf, size_t *buflen, struct vnode **dvp)
{
struct tmpfs_dirent *de;
int error, i;
@@ -1531,7 +1531,7 @@ tmpfs_vptocnp(struct vop_vptocnp_args *ap)
struct tmpfs_dirent *de;
struct tmpfs_mount *tm;
char *buf;
- int *buflen;
+ size_t *buflen;
int error;
vp = ap->a_vp;
Modified: projects/clang1000-import/sys/kern/kern_sig.c
==============================================================================
--- projects/clang1000-import/sys/kern/kern_sig.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/kern/kern_sig.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -3608,6 +3608,7 @@ coredump(struct thread *td)
struct vnode *vp;
struct flock lf;
struct vattr vattr;
+ size_t fullpathsize;
int error, error1, locked;
char *name; /* name of corefile */
void *rl_cookie;
@@ -3711,13 +3712,14 @@ coredump(struct thread *td)
* if the path of the core is relative, add the current dir in front if it.
*/
if (name[0] != '/') {
- fullpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
- if (kern___getcwd(td, fullpath, UIO_SYSSPACE, MAXPATHLEN, MAXPATHLEN) != 0) {
- free(fullpath, M_TEMP);
+ fullpathsize = MAXPATHLEN;
+ freepath = malloc(fullpathsize, M_TEMP, M_WAITOK);
+ if (vn_getcwd(td, freepath, &fullpath, &fullpathsize) != 0) {
+ free(freepath, M_TEMP);
goto out2;
}
devctl_safe_quote_sb(sb, fullpath);
- free(fullpath, M_TEMP);
+ free(freepath, M_TEMP);
sbuf_putc(sb, '/');
}
devctl_safe_quote_sb(sb, name);
Modified: projects/clang1000-import/sys/kern/vfs_cache.c
==============================================================================
--- projects/clang1000-import/sys/kern/vfs_cache.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/kern/vfs_cache.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -364,7 +364,7 @@ STATNODE_COUNTER(numposhits, "Number of cache hits (po
STATNODE_COUNTER(numnegzaps,
"Number of cache hits (negative) we do not want to cache");
STATNODE_COUNTER(numneghits, "Number of cache hits (negative)");
-/* These count for kern___getcwd(), too. */
+/* These count for vn_getcwd(), too. */
STATNODE_COUNTER(numfullpathcalls, "Number of fullpath search calls");
STATNODE_COUNTER(numfullpathfail1, "Number of fullpath search errors (ENOTDIR)");
STATNODE_COUNTER(numfullpathfail2,
@@ -388,7 +388,7 @@ STATNODE_COUNTER(shrinking_skipped,
static void cache_zap_locked(struct namecache *ncp, bool neg_locked);
static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir,
- char *buf, char **retbuf, u_int buflen);
+ char *buf, char **retbuf, size_t *buflen);
static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries");
@@ -2167,39 +2167,35 @@ vfs_cache_lookup(struct vop_lookup_args *ap)
return (error);
}
-/*
- * XXX All of these sysctls would probably be more productive dead.
- */
-static int __read_mostly disablecwd;
-SYSCTL_INT(_debug, OID_AUTO, disablecwd, CTLFLAG_RW, &disablecwd, 0,
- "Disable the getcwd syscall");
-
/* Implementation of the getcwd syscall. */
int
sys___getcwd(struct thread *td, struct __getcwd_args *uap)
{
+ char *buf, *retbuf;
+ size_t buflen;
+ int error;
- return (kern___getcwd(td, uap->buf, UIO_USERSPACE, uap->buflen,
- MAXPATHLEN));
+ buflen = uap->buflen;
+ if (__predict_false(buflen < 2))
+ return (EINVAL);
+ if (buflen > MAXPATHLEN)
+ buflen = MAXPATHLEN;
+
+ buf = malloc(buflen, M_TEMP, M_WAITOK);
+ error = vn_getcwd(td, buf, &retbuf, &buflen);
+ if (error == 0)
+ error = copyout(retbuf, uap->buf, buflen);
+ free(buf, M_TEMP);
+ return (error);
}
int
-kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg, size_t buflen,
- size_t path_max)
+vn_getcwd(struct thread *td, char *buf, char **retbuf, size_t *buflen)
{
- char *bp, *tmpbuf;
struct filedesc *fdp;
struct vnode *cdir, *rdir;
int error;
- if (__predict_false(disablecwd))
- return (ENODEV);
- if (__predict_false(buflen < 2))
- return (EINVAL);
- if (buflen > path_max)
- buflen = path_max;
-
- tmpbuf = malloc(buflen, M_TEMP, M_WAITOK);
fdp = td->td_proc->p_fd;
FILEDESC_SLOCK(fdp);
cdir = fdp->fd_cdir;
@@ -2207,33 +2203,18 @@ kern___getcwd(struct thread *td, char *buf, enum uio_s
rdir = fdp->fd_rdir;
vrefact(rdir);
FILEDESC_SUNLOCK(fdp);
- error = vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, buflen);
+ error = vn_fullpath1(td, cdir, rdir, buf, retbuf, buflen);
vrele(rdir);
vrele(cdir);
- if (!error) {
- if (bufseg == UIO_SYSSPACE)
- bcopy(bp, buf, strlen(bp) + 1);
- else
- error = copyout(bp, buf, strlen(bp) + 1);
#ifdef KTRACE
- if (KTRPOINT(curthread, KTR_NAMEI))
- ktrnamei(bp);
+ if (KTRPOINT(curthread, KTR_NAMEI) && error == 0)
+ ktrnamei(*retbuf);
#endif
- }
- free(tmpbuf, M_TEMP);
return (error);
}
/*
- * Thus begins the fullpath magic.
- */
-
-static int __read_mostly disablefullpath;
-SYSCTL_INT(_debug, OID_AUTO, disablefullpath, CTLFLAG_RW, &disablefullpath, 0,
- "Disable the vn_fullpath function");
-
-/*
* Retrieve the full filesystem path that correspond to a vnode from the name
* cache (if available)
*/
@@ -2243,20 +2224,20 @@ vn_fullpath(struct thread *td, struct vnode *vn, char
char *buf;
struct filedesc *fdp;
struct vnode *rdir;
+ size_t buflen;
int error;
- if (__predict_false(disablefullpath))
- return (ENODEV);
if (__predict_false(vn == NULL))
return (EINVAL);
- buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
+ buflen = MAXPATHLEN;
+ buf = malloc(buflen, M_TEMP, M_WAITOK);
fdp = td->td_proc->p_fd;
FILEDESC_SLOCK(fdp);
rdir = fdp->fd_rdir;
vrefact(rdir);
FILEDESC_SUNLOCK(fdp);
- error = vn_fullpath1(td, vn, rdir, buf, retbuf, MAXPATHLEN);
+ error = vn_fullpath1(td, vn, rdir, buf, retbuf, &buflen);
vrele(rdir);
if (!error)
@@ -2277,14 +2258,14 @@ vn_fullpath_global(struct thread *td, struct vnode *vn
char **retbuf, char **freebuf)
{
char *buf;
+ size_t buflen;
int error;
- if (__predict_false(disablefullpath))
- return (ENODEV);
if (__predict_false(vn == NULL))
return (EINVAL);
- buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
- error = vn_fullpath1(td, vn, rootvnode, buf, retbuf, MAXPATHLEN);
+ buflen = MAXPATHLEN;
+ buf = malloc(buflen, M_TEMP, M_WAITOK);
+ error = vn_fullpath1(td, vn, rootvnode, buf, retbuf, &buflen);
if (!error)
*freebuf = buf;
else
@@ -2293,7 +2274,7 @@ vn_fullpath_global(struct thread *td, struct vnode *vn
}
int
-vn_vptocnp(struct vnode **vp, struct ucred *cred, char *buf, u_int *buflen)
+vn_vptocnp(struct vnode **vp, struct ucred *cred, char *buf, size_t *buflen)
{
struct vnode *dvp;
struct namecache *ncp;
@@ -2355,18 +2336,21 @@ vn_vptocnp(struct vnode **vp, struct ucred *cred, char
}
/*
- * The magic behind kern___getcwd() and vn_fullpath().
+ * The magic behind vn_getcwd() and vn_fullpath().
*/
static int
vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir,
- char *buf, char **retbuf, u_int buflen)
+ char *buf, char **retbuf, size_t *len)
{
int error, slash_prefixed;
#ifdef KDTRACE_HOOKS
struct vnode *startvp = vp;
#endif
struct vnode *vp1;
+ size_t buflen;
+ buflen = *len;
+
buflen--;
buf[buflen] = '\0';
error = 0;
@@ -2457,6 +2441,7 @@ vn_fullpath1(struct thread *td, struct vnode *vp, stru
SDT_PROBE3(vfs, namecache, fullpath, return, 0, startvp, buf + buflen);
*retbuf = buf + buflen;
+ *len -= buflen;
return (0);
}
@@ -2515,9 +2500,6 @@ vn_commname(struct vnode *vp, char *buf, u_int buflen)
* Requires a locked, referenced vnode.
* Vnode is re-locked on success or ENODEV, otherwise unlocked.
*
- * If sysctl debug.disablefullpath is set, ENODEV is returned,
- * vnode is left locked and path remain untouched.
- *
* If vp is a directory, the call to vn_fullpath_global() always succeeds
* because it falls back to the ".." lookup if the namecache lookup fails.
*/
@@ -2531,10 +2513,6 @@ vn_path_to_global_path(struct thread *td, struct vnode
int error;
ASSERT_VOP_ELOCKED(vp, __func__);
-
- /* Return ENODEV if sysctl debug.disablefullpath==1 */
- if (__predict_false(disablefullpath))
- return (ENODEV);
/* Construct global filesystem path from vp. */
VOP_UNLOCK(vp);
Modified: projects/clang1000-import/sys/kern/vfs_default.c
==============================================================================
--- projects/clang1000-import/sys/kern/vfs_default.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/kern/vfs_default.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -804,7 +804,7 @@ vop_stdvptocnp(struct vop_vptocnp_args *ap)
struct vnode **dvp = ap->a_vpp;
struct ucred *cred = ap->a_cred;
char *buf = ap->a_buf;
- int *buflen = ap->a_buflen;
+ size_t *buflen = ap->a_buflen;
char *dirbuf, *cpos;
int i, error, eofflag, dirbuflen, flags, locked, len, covered;
off_t off;
Modified: projects/clang1000-import/sys/kern/vnode_if.src
==============================================================================
--- projects/clang1000-import/sys/kern/vnode_if.src Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/kern/vnode_if.src Sat Feb 1 22:07:37 2020 (r357390)
@@ -640,7 +640,7 @@ vop_vptocnp {
OUT struct vnode **vpp;
IN struct ucred *cred;
INOUT char *buf;
- INOUT int *buflen;
+ INOUT size_t *buflen;
};
Modified: projects/clang1000-import/sys/riscv/sifive/fu540_prci.c
==============================================================================
--- projects/clang1000-import/sys/riscv/sifive/fu540_prci.c Sat Feb 1 21:47:34 2020 (r357389)
+++ projects/clang1000-import/sys/riscv/sifive/fu540_prci.c Sat Feb 1 22:07:37 2020 (r357390)
@@ -45,11 +45,21 @@ __FBSDID("$FreeBSD$");
#include <machine/cpu.h>
#include <dev/extres/clk/clk.h>
+#include <dev/extres/clk/clk_fixed.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/openfirm.h>
+#include <gnu/dts/include/dt-bindings/clock/sifive-fu540-prci.h>
+
+static struct ofw_compat_data compat_data[] = {
+ { "sifive,aloeprci0", 1 },
+ { "sifive,ux00prci0", 1 },
+ { "sifive,fu540-c000-prci", 1 },
+ { NULL, 0 },
+};
+
static struct resource_spec prci_spec[] = {
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
RESOURCE_SPEC_END
@@ -68,6 +78,7 @@ struct prci_softc {
struct prci_clk_pll_sc {
struct prci_softc *parent_sc;
+ uint32_t reg;
};
#define PRCI_LOCK(sc) mtx_lock(&(sc)->mtx)
@@ -75,17 +86,51 @@ struct prci_clk_pll_sc {
#define PRCI_ASSERT_LOCKED(sc) mtx_assert(&(sc)->mtx, MA_OWNED);
#define PRCI_ASSERT_UNLOCKED(sc) mtx_assert(&(sc)->mtx, MA_NOTOWNED);
-#define PRCI_COREPLL 0x4
-#define PRCI_COREPLL_DIVR_MASK 0x3f
-#define PRCI_COREPLL_DIVR_SHIFT 0
-#define PRCI_COREPLL_DIVF_MASK 0x7fc0
-#define PRCI_COREPLL_DIVF_SHIFT 6
-#define PRCI_COREPLL_DIVQ_MASK 0x38000
-#define PRCI_COREPLL_DIVQ_SHIFT 15
+#define PRCI_COREPLL_CFG0 0x4
+#define PRCI_DDRPLL_CFG0 0xC
+#define PRCI_GEMGXLPLL_CFG0 0x1C
+#define PRCI_PLL_DIVR_MASK 0x3f
+#define PRCI_PLL_DIVR_SHIFT 0
+#define PRCI_PLL_DIVF_MASK 0x7fc0
+#define PRCI_PLL_DIVF_SHIFT 6
+#define PRCI_PLL_DIVQ_MASK 0x38000
+#define PRCI_PLL_DIVQ_SHIFT 15
+
#define PRCI_READ(_sc, _reg) \
bus_space_read_4((_sc)->bst, (_sc)->bsh, (_reg))
+struct prci_pll_def {
+ uint32_t id;
+ const char *name;
+ uint32_t reg;
+};
+
+#define PLL(_id, _name, _base) \
+{ \
+ .id = (_id), \
+ .name = (_name), \
+ .reg = (_base), \
+}
+
+/* PLL Clocks */
+struct prci_pll_def pll_clks[] = {
+ PLL(PRCI_CLK_COREPLL, "coreclk", PRCI_COREPLL_CFG0),
+ PLL(PRCI_CLK_DDRPLL, "ddrclk", PRCI_DDRPLL_CFG0),
+ PLL(PRCI_CLK_GEMGXLPLL, "gemgxclk", PRCI_GEMGXLPLL_CFG0),
+};
+
+/* Fixed divisor clock TLCLK. */
+struct clk_fixed_def tlclk_def = {
+ .clkdef.id = PRCI_CLK_TLCLK,
+ .clkdef.name = "prci_tlclk",
+ .clkdef.parent_names = (const char *[]){"coreclk"},
+ .clkdef.parent_cnt = 1,
+ .clkdef.flags = CLK_NODE_STATIC_STRINGS,
+ .mult = 1,
+ .div = 2,
+};
+
static int
prci_clk_pll_init(struct clknode *clk, device_t dev)
{
@@ -121,11 +166,11 @@ prci_clk_pll_recalc(struct clknode *clk, uint64_t *fre
}
/* Calculate the PLL output */
- val = PRCI_READ(sc->parent_sc, PRCI_COREPLL);
+ val = PRCI_READ(sc->parent_sc, sc->reg);
- divf = (val & PRCI_COREPLL_DIVF_MASK) >> PRCI_COREPLL_DIVF_SHIFT;
- divq = (val & PRCI_COREPLL_DIVQ_MASK) >> PRCI_COREPLL_DIVQ_SHIFT;
- divr = (val & PRCI_COREPLL_DIVR_MASK) >> PRCI_COREPLL_DIVR_SHIFT;
+ divf = (val & PRCI_PLL_DIVF_MASK) >> PRCI_PLL_DIVF_SHIFT;
+ divq = (val & PRCI_PLL_DIVQ_MASK) >> PRCI_PLL_DIVQ_SHIFT;
+ divr = (val & PRCI_PLL_DIVR_MASK) >> PRCI_PLL_DIVR_SHIFT;
*freq = refclk / (divr + 1) * (2 * (divf + 1)) / (1 << divq);
@@ -151,7 +196,7 @@ prci_probe(device_t dev)
if (!ofw_bus_status_okay(dev))
return (ENXIO);
- if (!ofw_bus_is_compatible(dev, "sifive,aloeprci0"))
+ if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
return (ENXIO);
device_set_desc(dev, "SiFive FU540 Power Reset Clocking Interrupt");
@@ -160,7 +205,8 @@ prci_probe(device_t dev)
}
static void
-prci_pll_register(struct prci_softc *parent_sc, struct clknode_init_def *clkdef)
+prci_pll_register(struct prci_softc *parent_sc, struct clknode_init_def *clkdef,
+ uint32_t reg)
{
struct clknode *clk;
struct prci_clk_pll_sc *sc;
@@ -172,6 +218,7 @@ prci_pll_register(struct prci_softc *parent_sc, struct
sc = clknode_get_softc(clk);
sc->parent_sc = parent_sc;
+ sc->reg = reg;
clknode_register(parent_sc->clkdom, clk);
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-projects
mailing list