svn commit: r333576 - in head/sys: kern sys ufs/ffs

2018-05-13 Thread Konstantin Belousov
Author: kib
Date: Sun May 13 09:47:28 2018
New Revision: 333576
URL: https://svnweb.freebsd.org/changeset/base/333576

Log:
  Detect and optimize reads from the hole on UFS.
  
  - Create getblkx(9) variant of getblk(9) which can return error.
  - Add GB_NOSPARSE flag for getblk()/getblkx() which requests that BMAP
was performed before the buffer is created, and EJUSTRETURN returned
in case the requested block does not exist.
  - Make ffs_read() use GB_NOSPARSE to avoid instantiating buffer (and
allocating the pages for it), copying from zero_region instead.
  
  The end result is less page allocations and buffer recycling when a
  hole is read, which is important for some benchmarks.
  
  Requested and reviewed by:jeff
  Tested by:pho
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D14917

Modified:
  head/sys/kern/vfs_bio.c
  head/sys/kern/vfs_cluster.c
  head/sys/sys/buf.h
  head/sys/ufs/ffs/ffs_vnops.c

Modified: head/sys/kern/vfs_bio.c
==
--- head/sys/kern/vfs_bio.c Sat May 12 20:00:29 2018(r333575)
+++ head/sys/kern/vfs_bio.c Sun May 13 09:47:28 2018(r333576)
@@ -2138,30 +2138,37 @@ breadn_flags(struct vnode *vp, daddr_t blkno, int size
 void (*ckhashfunc)(struct buf *), struct buf **bpp)
 {
struct buf *bp;
-   int readwait, rv;
+   struct thread *td;
+   int error, readwait, rv;
 
CTR3(KTR_BUF, "breadn(%p, %jd, %d)", vp, blkno, size);
+   td = curthread;
/*
-* Can only return NULL if GB_LOCK_NOWAIT flag is specified.
+* Can only return NULL if GB_LOCK_NOWAIT or GB_SPARSE flags
+* are specified.
 */
-   *bpp = bp = getblk(vp, blkno, size, 0, 0, flags);
-   if (bp == NULL)
-   return (EBUSY);
+   error = getblkx(vp, blkno, size, 0, 0, flags, &bp);
+   if (error != 0) {
+   *bpp = NULL;
+   return (error);
+   }
+   flags &= ~GB_NOSPARSE;
+   *bpp = bp;
 
/*
 * If not found in cache, do some I/O
 */
readwait = 0;
if ((bp->b_flags & B_CACHE) == 0) {
-   if (!TD_IS_IDLETHREAD(curthread)) {
+   if (!TD_IS_IDLETHREAD(td)) {
 #ifdef RACCT
if (racct_enable) {
-   PROC_LOCK(curproc);
-   racct_add_buf(curproc, bp, 0);
-   PROC_UNLOCK(curproc);
+   PROC_LOCK(td->td_proc);
+   racct_add_buf(td->td_proc, bp, 0);
+   PROC_UNLOCK(td->td_proc);
}
 #endif /* RACCT */
-   curthread->td_ru.ru_inblock++;
+   td->td_ru.ru_inblock++;
}
bp->b_iocmd = BIO_READ;
bp->b_flags &= ~B_INVAL;
@@ -3822,8 +3829,21 @@ has_addr:
}
 }
 
+struct buf *
+getblk(struct vnode *vp, daddr_t blkno, int size, int slpflag, int slptimeo,
+int flags)
+{
+   struct buf *bp;
+   int error;
+
+   error = getblkx(vp, blkno, size, slpflag, slptimeo, flags, &bp);
+   if (error != 0)
+   return (NULL);
+   return (bp);
+}
+
 /*
- * getblk:
+ * getblkx:
  *
  * Get a block given a specified block and offset into a file/device.
  * The buffers B_DONE bit will be cleared on return, making it almost
@@ -3858,12 +3878,13 @@ has_addr:
  * intends to issue a READ, the caller must clear B_INVAL and BIO_ERROR
  * prior to issuing the READ.  biodone() will *not* clear B_INVAL.
  */
-struct buf *
-getblk(struct vnode *vp, daddr_t blkno, int size, int slpflag, int slptimeo,
-int flags)
+int
+getblkx(struct vnode *vp, daddr_t blkno, int size, int slpflag, int slptimeo,
+int flags, struct buf **bpp)
 {
struct buf *bp;
struct bufobj *bo;
+   daddr_t d_blkno;
int bsize, error, maxsize, vmio;
off_t offset;
 
@@ -3878,6 +3899,7 @@ getblk(struct vnode *vp, daddr_t blkno, int size, int 
flags &= ~(GB_UNMAPPED | GB_KVAALLOC);
 
bo = &vp->v_bufobj;
+   d_blkno = blkno;
 loop:
BO_RLOCK(bo);
bp = gbincore(bo, blkno);
@@ -3889,7 +3911,7 @@ loop:
 */
lockflags = LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK;
 
-   if (flags & GB_LOCK_NOWAIT)
+   if ((flags & GB_LOCK_NOWAIT) != 0)
lockflags |= LK_NOWAIT;
 
error = BUF_TIMELOCK(bp, lockflags,
@@ -3902,8 +3924,8 @@ loop:
if (error == ENOLCK)
goto loop;
/* We timed out or were interrupted. */
-   else if (error)
-   return (NULL);
+   else if (error != 0)
+   return (error);
  

svn commit: r333577 - in head: include lib/libc/softfloat/bits64 lib/msun lib/msun/man lib/msun/src

2018-05-13 Thread Konstantin Belousov
Author: kib
Date: Sun May 13 09:54:34 2018
New Revision: 333577
URL: https://svnweb.freebsd.org/changeset/base/333577

Log:
  Add implementations for clog(3), clogf(3), and clog(3).
  
  PR:   216863
  Submitted by: bde, Steven G. Kargl 
  MFC after:2 weeks

Added:
  head/lib/msun/man/clog.3   (contents, props changed)
  head/lib/msun/src/s_clog.c   (contents, props changed)
  head/lib/msun/src/s_clogf.c   (contents, props changed)
  head/lib/msun/src/s_clogl.c   (contents, props changed)
Modified:
  head/include/complex.h
  head/lib/libc/softfloat/bits64/softfloat-macros
  head/lib/msun/Makefile
  head/lib/msun/Symbol.map
  head/lib/msun/man/complex.3
  head/lib/msun/src/math_private.h

Modified: head/include/complex.h
==
--- head/include/complex.h  Sun May 13 09:47:28 2018(r333576)
+++ head/include/complex.h  Sun May 13 09:54:34 2018(r333577)
@@ -101,6 +101,10 @@ float complex  cexpf(float complex);
 double cimag(double complex) __pure2;
 float  cimagf(float complex) __pure2;
 long doublecimagl(long double complex) __pure2;
+double complex clog(double complex);
+float complex  clogf(float complex);
+long double complex
+   clogl(long double complex);
 double complex conj(double complex) __pure2;
 float complex  conjf(float complex) __pure2;
 long double complex

Modified: head/lib/libc/softfloat/bits64/softfloat-macros
==
--- head/lib/libc/softfloat/bits64/softfloat-macros Sun May 13 09:47:28 
2018(r333576)
+++ head/lib/libc/softfloat/bits64/softfloat-macros Sun May 13 09:54:34 
2018(r333577)
@@ -157,7 +157,7 @@ INLINE void
 z0 = a0>>count;
 }
 else {
-z1 = ( count < 64 ) ? ( a0>>( count & 63 ) ) : 0;
+z1 = ( count < 128 ) ? ( a0>>( count & 63 ) ) : 0;
 z0 = 0;
 }
 *z1Ptr = z1;

Modified: head/lib/msun/Makefile
==
--- head/lib/msun/Makefile  Sun May 13 09:47:28 2018(r333576)
+++ head/lib/msun/Makefile  Sun May 13 09:54:34 2018(r333577)
@@ -57,7 +57,7 @@ COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \
k_cos.c k_cosf.c k_exp.c k_expf.c k_rem_pio2.c k_sin.c k_sinf.c \
k_tan.c k_tanf.c \
s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_carg.c s_cargf.c s_cargl.c \
-   s_cbrt.c s_cbrtf.c s_ceil.c s_ceilf.c \
+   s_cbrt.c s_cbrtf.c s_ceil.c s_ceilf.c s_clog.c s_clogf.c \
s_copysign.c s_copysignf.c s_cos.c s_cosf.c \
s_csqrt.c s_csqrtf.c s_erf.c s_erff.c \
s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c \
@@ -101,7 +101,8 @@ COMMON_SRCS+=   catrigl.c \
e_lgammal.c e_lgammal_r.c \
e_remainderl.c e_sinhl.c e_sqrtl.c \
invtrig.c k_cosl.c k_sinl.c k_tanl.c \
-   s_asinhl.c s_atanl.c s_cbrtl.c s_ceill.c s_cosl.c s_cprojl.c \
+   s_asinhl.c s_atanl.c s_cbrtl.c s_ceill.c \
+   s_clogl.c s_cosl.c s_cprojl.c \
s_csqrtl.c s_erfl.c s_exp2l.c s_expl.c s_floorl.c s_fmal.c \
s_fmaxl.c s_fminl.c s_frexpl.c s_logbl.c s_logl.c s_nanl.c \
s_nextafterl.c s_nexttoward.c s_remquol.c s_rintl.c s_roundl.c \
@@ -133,7 +134,8 @@ INCS+=  fenv.h math.h
 
 MAN=   acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \
ceil.3 cacos.3 ccos.3 ccosh.3 cexp.3 \
-   cimag.3 copysign.3 cos.3 cosh.3 csqrt.3 erf.3 exp.3 fabs.3 fdim.3 \
+   cimag.3 clog.3 copysign.3 cos.3 cosh.3 csqrt.3 erf.3 \
+   exp.3 fabs.3 fdim.3 \
feclearexcept.3 feenableexcept.3 fegetenv.3 \
fegetround.3 fenv.3 floor.3 \
fma.3 fmax.3 fmod.3 hypot.3 ieee.3 ieee_test.3 ilogb.3 j0.3 \
@@ -166,6 +168,7 @@ MLINKS+=cimag.3 cimagf.3 cimag.3 cimagl.3 \
cimag.3 conj.3 cimag.3 conjf.3 cimag.3 conjl.3 \
cimag.3 cproj.3 cimag.3 cprojf.3 cimag.3 cprojl.3 \
cimag.3 creal.3 cimag.3 crealf.3 cimag.3 creall.3
+MLINKS+=clog.3 clogf.3 clog.3 clogl.3
 MLINKS+=copysign.3 copysignf.3 copysign.3 copysignl.3
 MLINKS+=cos.3 cosf.3 cos.3 cosl.3
 MLINKS+=cosh.3 coshf.3 cosh.3 coshl.3

Modified: head/lib/msun/Symbol.map
==
--- head/lib/msun/Symbol.mapSun May 13 09:47:28 2018(r333576)
+++ head/lib/msun/Symbol.mapSun May 13 09:54:34 2018(r333577)
@@ -294,6 +294,9 @@ FBSD_1.5 {
casinl;
catanl;
catanhl;
+   clog;
+   clogf;
+   clogl;
sincos;
sincosf;
sincosl;

Added: head/lib/msun/man/clog.3
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/msun/man/clog.3Sun May 13 09:54:34 2018(r333577)
@@ -0,0 +1,103 @@
+.\" Copyright (c) 2017 Steven G. Kargl 
+.\" All rights

svn commit: r333587 - head/sys/i386/include

2018-05-13 Thread Konstantin Belousov
Author: kib
Date: Sun May 13 20:10:02 2018
New Revision: 333587
URL: https://svnweb.freebsd.org/changeset/base/333587

Log:
  Fix PMC_IN_TRAP_HANDLER() for i386 after the 4/4 split.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/include/pmc_mdep.h

Modified: head/sys/i386/include/pmc_mdep.h
==
--- head/sys/i386/include/pmc_mdep.hSun May 13 19:48:30 2018
(r333586)
+++ head/sys/i386/include/pmc_mdep.hSun May 13 20:10:02 2018
(r333587)
@@ -145,8 +145,8 @@ struct pmc_mdep;
 #definePMC_IN_USERSPACE(va) ((va) <= VM_MAXUSER_ADDRESS)
 
 #definePMC_IN_TRAP_HANDLER(PC) \
-   ((PC) >= (uintptr_t) start_exceptions &&\
-(PC) < (uintptr_t) end_exceptions)
+   ((PC) >= (uintptr_t)start_exceptions + setidt_disp &&   \
+(PC) < (uintptr_t) end_exceptions + setidt_disp)
 
 #definePMC_AT_FUNCTION_PROLOGUE_PUSH_BP(I) \
(((I) & 0x00ff) == 0xe58955) /* pushl %ebp; movl %esp,%ebp */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r333597 - head/sys/sys

2018-05-14 Thread Konstantin Belousov
On Mon, May 14, 2018 at 12:56:33AM +, Matt Macy wrote:
> Author: mmacy
> Date: Mon May 14 00:56:33 2018
> New Revision: 333597
> URL: https://svnweb.freebsd.org/changeset/base/333597
> 
> Log:
>   pmc: fix buildworld
>   
>   hid ck_queue.h from user
>   
>   Approved by:sbruno
> 
> Modified:
>   head/sys/sys/pmc.h
> 
> Modified: head/sys/sys/pmc.h
> ==
> --- head/sys/sys/pmc.hMon May 14 00:21:04 2018(r333596)
> +++ head/sys/sys/pmc.hMon May 14 00:56:33 2018(r333597)
> @@ -40,8 +40,10 @@
>  #include 
>  #include 
>  #include 
> +#ifdef _KERNEL
>  #include 
>  #include 
Kernel must not use userspace headers.

> +#endif
>  
>  #define  PMC_MODULE_NAME "hwpmc"
>  #define  PMC_NAME_MAX64 /* HW counter name size */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r333840 - head/sys/kern

2018-05-19 Thread Konstantin Belousov
On Sat, May 19, 2018 at 04:07:00AM +, Matt Macy wrote:
> Author: mmacy
> Date: Sat May 19 04:07:00 2018
> New Revision: 333840
> URL: https://svnweb.freebsd.org/changeset/base/333840
> 
> Log:
>   filt_timerdetach: only assign to old if we're going to check it in
>   a KASSERT
You also removed the decrement from non-debug builds.

> 
> Modified:
>   head/sys/kern/kern_event.c
> 
> Modified: head/sys/kern/kern_event.c
> ==
> --- head/sys/kern/kern_event.cSat May 19 04:05:36 2018
> (r333839)
> +++ head/sys/kern/kern_event.cSat May 19 04:07:00 2018
> (r333840)
> @@ -751,12 +751,14 @@ static void
>  filt_timerdetach(struct knote *kn)
>  {
>   struct kq_timer_cb_data *kc;
> +#ifdef INVARIANTS
>   unsigned int old;
> +#endif
>  
>   kc = kn->kn_ptr.p_v;
>   callout_drain(&kc->c);
>   free(kc, M_KQUEUE);
> - old = atomic_fetchadd_int(&kq_ncallouts, -1);
> + DBGSET(old, atomic_fetchadd_int(&kq_ncallouts, -1));
>   KASSERT(old > 0, ("Number of callouts cannot become negative"));
>   kn->kn_status |= KN_DETACHED;   /* knlist_remove sets it */
>  }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r333844 - head/sys/kern

2018-05-19 Thread Konstantin Belousov
On Sat, May 19, 2018 at 12:22:48PM +0200, Hans Petter Selasky wrote:
> On 05/19/18 06:13, Matt Macy wrote:
> > va_start(ap, fmt);
> > -   res = make_dev_credv(0, &dev, devsw, unit, cr, uid, gid, mode, fmt, ap);
> > +   DBGSET(res, make_dev_credv(0, &dev, devsw, unit, cr, uid, gid, mode, 
> > fmt, ap));
> 
> Is the make_dev_credv() called stubbed for non-debug builds?

Apparently not.  And my note about timer filter was also wrong.

But this is indeed very unusual and error-prone macro, which seems to
be removed in r333862.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r333891 - head/sys/x86/x86

2018-05-19 Thread Konstantin Belousov
Author: kib
Date: Sat May 19 20:26:33 2018
New Revision: 333891
URL: https://svnweb.freebsd.org/changeset/base/333891

Log:
  Fix IBRS handling around MWAIT.
  
  The intent was to disable IBPB and IBRS around MWAIT, and re-enable on
  the sleep end.
  
  Reviewed by:  emaste
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/sys/x86/x86/cpu_machdep.c

Modified: head/sys/x86/x86/cpu_machdep.c
==
--- head/sys/x86/x86/cpu_machdep.c  Sat May 19 19:53:23 2018
(r333890)
+++ head/sys/x86/x86/cpu_machdep.c  Sat May 19 20:26:33 2018
(r333891)
@@ -166,11 +166,11 @@ acpi_cpu_idle_mwait(uint32_t mwait_hint)
KASSERT(atomic_load_int(state) == STATE_SLEEPING,
("cpu_mwait_cx: wrong monitorbuf state"));
atomic_store_int(state, STATE_MWAIT);
-   handle_ibrs_entry();
+   handle_ibrs_exit();
cpu_monitor(state, 0, 0);
if (atomic_load_int(state) == STATE_MWAIT)
cpu_mwait(MWAIT_INTRBREAK, mwait_hint);
-   handle_ibrs_exit();
+   handle_ibrs_entry();
 
/*
 * We should exit on any event that interrupts mwait, because
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r333892 - head/sys/x86/xen

2018-05-19 Thread Konstantin Belousov
Author: kib
Date: Sat May 19 20:28:59 2018
New Revision: 333892
URL: https://svnweb.freebsd.org/changeset/base/333892

Log:
  Fix PCID+PTI pmap operations on Xen/HVM.
  
  Install appropriate pti-aware shootdown IPI handlers, otherwise user
  page tables do not get enough invalidations.  The non-pti handlers
  were used so far.
  
  Reported and tested by:   cperciva
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/sys/x86/xen/xen_apic.c

Modified: head/sys/x86/xen/xen_apic.c
==
--- head/sys/x86/xen/xen_apic.c Sat May 19 20:26:33 2018(r333891)
+++ head/sys/x86/xen/xen_apic.c Sat May 19 20:28:59 2018(r333892)
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -439,6 +440,46 @@ xen_invltlb_pcid(void *arg)
invltlb_pcid_handler();
return (FILTER_HANDLED);
 }
+
+static int
+xen_invltlb_invpcid_pti(void *arg)
+{
+
+   invltlb_invpcid_pti_handler();
+   return (FILTER_HANDLED);
+}
+
+static int
+xen_invlpg_invpcid_handler(void *arg)
+{
+
+   invlpg_invpcid_handler();
+   return (FILTER_HANDLED);
+}
+
+static int
+xen_invlpg_pcid_handler(void *arg)
+{
+
+   invlpg_pcid_handler();
+   return (FILTER_HANDLED);
+}
+
+static int
+xen_invlrng_invpcid_handler(void *arg)
+{
+
+   invlrng_invpcid_handler();
+   return (FILTER_HANDLED);
+}
+
+static int
+xen_invlrng_pcid_handler(void *arg)
+{
+
+   invlrng_pcid_handler();
+   return (FILTER_HANDLED);
+}
 #endif
 
 static int
@@ -529,8 +570,18 @@ xen_setup_cpus(void)
 
 #ifdef __amd64__
if (pmap_pcid_enabled) {
-   xen_ipis[IPI_TO_IDX(IPI_INVLTLB)].filter = invpcid_works ?
-   xen_invltlb_invpcid : xen_invltlb_pcid;
+   if (pti)
+   xen_ipis[IPI_TO_IDX(IPI_INVLTLB)].filter =
+   invpcid_works ? xen_invltlb_invpcid_pti :
+   xen_invltlb_pcid;
+   else
+   xen_ipis[IPI_TO_IDX(IPI_INVLTLB)].filter =
+   invpcid_works ? xen_invltlb_invpcid :
+   xen_invltlb_pcid;
+   xen_ipis[IPI_TO_IDX(IPI_INVLPG)].filter = invpcid_works ?
+   xen_invlpg_invpcid_handler : xen_invlpg_pcid_handler;
+   xen_ipis[IPI_TO_IDX(IPI_INVLRNG)].filter = invpcid_works ?
+   xen_invlrng_invpcid_handler : xen_invlrng_pcid_handler;
}
 #endif
CPU_FOREACH(i)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r333896 - head/sys/x86/x86

2018-05-19 Thread Konstantin Belousov
Author: kib
Date: Sat May 19 21:36:55 2018
New Revision: 333896
URL: https://svnweb.freebsd.org/changeset/base/333896

Log:
  Style.
  
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/sys/x86/x86/cpu_machdep.c

Modified: head/sys/x86/x86/cpu_machdep.c
==
--- head/sys/x86/x86/cpu_machdep.c  Sat May 19 21:26:07 2018
(r333895)
+++ head/sys/x86/x86/cpu_machdep.c  Sat May 19 21:36:55 2018
(r333896)
@@ -773,11 +773,11 @@ hw_ibrs_recalculate(void)
 
if ((cpu_ia32_arch_caps & IA32_ARCH_CAP_IBRS_ALL) != 0) {
if (hw_ibrs_disable) {
-   v= rdmsr(MSR_IA32_SPEC_CTRL);
+   v = rdmsr(MSR_IA32_SPEC_CTRL);
v &= ~(uint64_t)IA32_SPEC_CTRL_IBRS;
wrmsr(MSR_IA32_SPEC_CTRL, v);
} else {
-   v= rdmsr(MSR_IA32_SPEC_CTRL);
+   v = rdmsr(MSR_IA32_SPEC_CTRL);
v |= IA32_SPEC_CTRL_IBRS;
wrmsr(MSR_IA32_SPEC_CTRL, v);
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r333990 - head/sys/amd64/amd64

2018-05-21 Thread Konstantin Belousov
Author: kib
Date: Mon May 21 18:41:16 2018
New Revision: 333990
URL: https://svnweb.freebsd.org/changeset/base/333990

Log:
  Add missed barrier for pm_gen/pm_active interaction.
  
  When we issue shootdown IPIs, we first assign zero to pm_gens to
  indicate the need to flush on the next context switch in case our IPI
  misses the context, next we read pm_active. On context switch we set
  our bit in pm_active, then we read pm_gen. It is crucial that both
  threads see the memory in the program order, otherwise invalidation
  thread might read pm_active bit as zero and the context switching
  thread might read pm_gen as zero.
  
  IA32 allows CPU for both reads to see zero. We must use the barriers
  between write and read. The pm_active bit set is already locked, so
  only the invalidation functions need it.
  
  I never saw it in real life, or at least I do not have a good
  reproduction case. I found this during code inspection when hunting
  for the Xen TLB issue reported by cperciva.
  
  Reviewed by:  alc, markj
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D15506

Modified:
  head/sys/amd64/amd64/pmap.c

Modified: head/sys/amd64/amd64/pmap.c
==
--- head/sys/amd64/amd64/pmap.c Mon May 21 17:33:52 2018(r333989)
+++ head/sys/amd64/amd64/pmap.c Mon May 21 18:41:16 2018(r333990)
@@ -1721,6 +1721,18 @@ pmap_invalidate_page(pmap_t pmap, vm_offset_t va)
if (cpuid != i)
pmap->pm_pcids[i].pm_gen = 0;
}
+
+   /*
+* The fence is between stores to pm_gen and the read of
+* the pm_active mask.  We need to ensure that it is
+* impossible for us to miss the bit update in pm_active
+* and simultaneously observe a non-zero pm_gen in
+* pmap_activate_sw(), otherwise TLB update is missed.
+* Without the fence, IA32 allows such an outcome.
+* Note that pm_active is updated by a locked operation,
+* which provides the reciprocal fence.
+*/
+   atomic_thread_fence_seq_cst();
}
mask = &pmap->pm_active;
}
@@ -1792,6 +1804,8 @@ pmap_invalidate_range(pmap_t pmap, vm_offset_t sva, vm
if (cpuid != i)
pmap->pm_pcids[i].pm_gen = 0;
}
+   /* See comment int pmap_invalidate_page(). */
+   atomic_thread_fence_seq_cst();
}
mask = &pmap->pm_active;
}
@@ -1863,6 +1877,8 @@ pmap_invalidate_all(pmap_t pmap)
if (cpuid != i)
pmap->pm_pcids[i].pm_gen = 0;
}
+   /* See comment int pmap_invalidate_page(). */
+   atomic_thread_fence_seq_cst();
}
mask = &pmap->pm_active;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r333992 - head/sys/amd64/amd64

2018-05-21 Thread Konstantin Belousov
Author: kib
Date: Mon May 21 19:15:05 2018
New Revision: 333992
URL: https://svnweb.freebsd.org/changeset/base/333992

Log:
  Fix grammar.
  
  Submitted by: alc
  MFC after:1 week

Modified:
  head/sys/amd64/amd64/pmap.c

Modified: head/sys/amd64/amd64/pmap.c
==
--- head/sys/amd64/amd64/pmap.c Mon May 21 18:59:34 2018(r333991)
+++ head/sys/amd64/amd64/pmap.c Mon May 21 19:15:05 2018(r333992)
@@ -1804,7 +1804,7 @@ pmap_invalidate_range(pmap_t pmap, vm_offset_t sva, vm
if (cpuid != i)
pmap->pm_pcids[i].pm_gen = 0;
}
-   /* See comment int pmap_invalidate_page(). */
+   /* See the comment in pmap_invalidate_page(). */
atomic_thread_fence_seq_cst();
}
mask = &pmap->pm_active;
@@ -1877,7 +1877,7 @@ pmap_invalidate_all(pmap_t pmap)
if (cpuid != i)
pmap->pm_pcids[i].pm_gen = 0;
}
-   /* See comment int pmap_invalidate_page(). */
+   /* See the comment in pmap_invalidate_page(). */
atomic_thread_fence_seq_cst();
}
mask = &pmap->pm_active;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334003 - head/sys/amd64/amd64

2018-05-21 Thread Konstantin Belousov
Author: kib
Date: Mon May 21 21:05:55 2018
New Revision: 334003
URL: https://svnweb.freebsd.org/changeset/base/334003

Log:
  Preserve other bits in IA32_SPEC_CTL MSR when changing the IBRS and
  STIBP states.
  
  Tested by:emaste (previous version)
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/sys/amd64/amd64/support.S

Modified: head/sys/amd64/amd64/support.S
==
--- head/sys/amd64/amd64/support.S  Mon May 21 21:04:31 2018
(r334002)
+++ head/sys/amd64/amd64/support.S  Mon May 21 21:05:55 2018
(r334003)
@@ -958,8 +958,9 @@ ENTRY(handle_ibrs_entry)
cmpb$0,hw_ibrs_active(%rip)
je  1f
movl$MSR_IA32_SPEC_CTRL,%ecx
-   movl$(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
-   movl$(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32,%edx
+   rdmsr
+   orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
+   orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32,%edx
wrmsr
movb$1,PCPU(IBPB_SET)
testl   $CPUID_STDEXT_SMEP,cpu_stdext_feature(%rip)
@@ -972,8 +973,9 @@ ENTRY(handle_ibrs_exit)
cmpb$0,PCPU(IBPB_SET)
je  1f
movl$MSR_IA32_SPEC_CTRL,%ecx
-   xorl%eax,%eax
-   xorl%edx,%edx
+   rdmsr
+   andl$~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
+   andl$~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
wrmsr
movb$0,PCPU(IBPB_SET)
 1: ret
@@ -987,8 +989,9 @@ ENTRY(handle_ibrs_exit_rs)
pushq   %rdx
pushq   %rcx
movl$MSR_IA32_SPEC_CTRL,%ecx
-   xorl%eax,%eax
-   xorl%edx,%edx
+   rdmsr
+   andl$~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
+   andl$~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
wrmsr
popq%rcx
popq%rdx
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334004 - in head/sys/x86: include x86

2018-05-21 Thread Konstantin Belousov
Author: kib
Date: Mon May 21 21:07:13 2018
New Revision: 334004
URL: https://svnweb.freebsd.org/changeset/base/334004

Log:
  Add definition for Intel Speculative Store Bypass Disable MSR bits
  
  Security: CVE-2018-3639
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/sys/x86/include/specialreg.h
  head/sys/x86/x86/identcpu.c

Modified: head/sys/x86/include/specialreg.h
==
--- head/sys/x86/include/specialreg.h   Mon May 21 21:05:55 2018
(r334003)
+++ head/sys/x86/include/specialreg.h   Mon May 21 21:07:13 2018
(r334004)
@@ -428,10 +428,12 @@
 #defineCPUID_STDEXT3_IBPB  0x0400
 #defineCPUID_STDEXT3_STIBP 0x0800
 #defineCPUID_STDEXT3_ARCH_CAP  0x2000
+#defineCPUID_STDEXT3_SSBD  0x8000
 
 /* MSR IA32_ARCH_CAP(ABILITIES) bits */
 #defineIA32_ARCH_CAP_RDCL_NO   0x0001
 #defineIA32_ARCH_CAP_IBRS_ALL  0x0002
+#defineIA32_ARCH_CAP_SSBD_NO   0x0004
 
 /*
  * CPUID manufacturers identifiers
@@ -704,6 +706,7 @@
 /* MSR IA32_SPEC_CTRL */
 #defineIA32_SPEC_CTRL_IBRS 0x0001
 #defineIA32_SPEC_CTRL_STIBP0x0002
+#defineIA32_SPEC_CTRL_SSBD 0x0004
 
 /* MSR IA32_PRED_CMD */
 #defineIA32_PRED_CMD_IBPB_BARRIER  0x0001ULL

Modified: head/sys/x86/x86/identcpu.c
==
--- head/sys/x86/x86/identcpu.c Mon May 21 21:05:55 2018(r334003)
+++ head/sys/x86/x86/identcpu.c Mon May 21 21:07:13 2018(r334004)
@@ -990,6 +990,7 @@ printcpuinfo(void)
   "\033IBPB"
   "\034STIBP"
   "\036ARCH_CAP"
+  "\040SSBD"
   );
}
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334005 - in head/sys: amd64/amd64 amd64/include dev/cpuctl x86/acpica x86/include x86/x86

2018-05-21 Thread Konstantin Belousov
Author: kib
Date: Mon May 21 21:08:19 2018
New Revision: 334005
URL: https://svnweb.freebsd.org/changeset/base/334005

Log:
  Add Intel Spec Store Bypass Disable control.
  
  Speculative Store Bypass (SSB) is a speculative execution side channel
  vulnerability identified by Jann Horn of Google Project Zero (GPZ) and
  Ken Johnson of the Microsoft Security Response Center (MSRC)
  https://bugs.chromium.org/p/project-zero/issues/detail?id=1528.
  Updated Intel microcode introduces a MSR bit to disable SSB as a
  mitigation for the vulnerability.
  
  Introduce a sysctl hw.spec_store_bypass_disable to provide global
  control over the SSBD bit, akin to the existing sysctl that controls
  IBRS. The sysctl can be set to one of three values:
  0: off
  1: on
  2: auto
  
  Future work will enable applications to control SSBD on a per-process
  basis (when it is not enabled globally).
  
  SSBD bit detection and control was verified with prerelease microcode.
  
  Security: CVE-2018-3639
  Tested by:emaste (previous version, without updated microcode)
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/sys/amd64/amd64/initcpu.c
  head/sys/amd64/amd64/machdep.c
  head/sys/amd64/include/md_var.h
  head/sys/dev/cpuctl/cpuctl.c
  head/sys/x86/acpica/acpi_wakeup.c
  head/sys/x86/include/x86_var.h
  head/sys/x86/x86/cpu_machdep.c

Modified: head/sys/amd64/amd64/initcpu.c
==
--- head/sys/amd64/amd64/initcpu.c  Mon May 21 21:07:13 2018
(r334004)
+++ head/sys/amd64/amd64/initcpu.c  Mon May 21 21:08:19 2018
(r334005)
@@ -224,6 +224,7 @@ initializecpu(void)
pg_nx = PG_NX;
}
hw_ibrs_recalculate();
+   hw_ssb_recalculate(false);
switch (cpu_vendor_id) {
case CPU_VENDOR_AMD:
init_amd();

Modified: head/sys/amd64/amd64/machdep.c
==
--- head/sys/amd64/amd64/machdep.c  Mon May 21 21:07:13 2018
(r334004)
+++ head/sys/amd64/amd64/machdep.c  Mon May 21 21:08:19 2018
(r334005)
@@ -1843,6 +1843,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
thread0.td_critnest = 0;
 
TUNABLE_INT_FETCH("hw.ibrs_disable", &hw_ibrs_disable);
+   TUNABLE_INT_FETCH("hw.spec_store_bypass_disable", &hw_ssb_disable);
 
TSEXIT();
 

Modified: head/sys/amd64/include/md_var.h
==
--- head/sys/amd64/include/md_var.h Mon May 21 21:07:13 2018
(r334004)
+++ head/sys/amd64/include/md_var.h Mon May 21 21:08:19 2018
(r334005)
@@ -39,6 +39,7 @@
 extern uint64_t*vm_page_dump;
 extern int hw_lower_amd64_sharedpage;
 extern int hw_ibrs_disable;
+extern int hw_ssb_disable;
 
 /*
  * The file "conf/ldscript.amd64" defines the symbol "kernphys".  Its

Modified: head/sys/dev/cpuctl/cpuctl.c
==
--- head/sys/dev/cpuctl/cpuctl.cMon May 21 21:07:13 2018
(r334004)
+++ head/sys/dev/cpuctl/cpuctl.cMon May 21 21:08:19 2018
(r334005)
@@ -529,6 +529,7 @@ cpuctl_do_eval_cpu_features(int cpu, struct thread *td
identify_cpu2();
hw_ibrs_recalculate();
restore_cpu(oldcpu, is_bound, td);
+   hw_ssb_recalculate(true);
printcpuinfo();
return (0);
 }

Modified: head/sys/x86/acpica/acpi_wakeup.c
==
--- head/sys/x86/acpica/acpi_wakeup.c   Mon May 21 21:07:13 2018
(r334004)
+++ head/sys/x86/acpica/acpi_wakeup.c   Mon May 21 21:08:19 2018
(r334005)
@@ -244,6 +244,7 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
 #endif
 #ifdef __amd64__
hw_ibrs_active = 0;
+   hw_ssb_active = 0;
cpu_stdext_feature3 = 0;
CPU_FOREACH(i) {
pc = pcpu_find(i);

Modified: head/sys/x86/include/x86_var.h
==
--- head/sys/x86/include/x86_var.h  Mon May 21 21:07:13 2018
(r334004)
+++ head/sys/x86/include/x86_var.h  Mon May 21 21:08:19 2018
(r334005)
@@ -85,6 +85,7 @@ externuint64_t xsave_mask;
 extern u_int   max_apic_id;
 extern int pti;
 extern int hw_ibrs_active;
+extern int hw_ssb_active;
 
 struct pcb;
 struct thread;
@@ -137,6 +138,7 @@ int isa_nmi(int cd);
 void   handle_ibrs_entry(void);
 void   handle_ibrs_exit(void);
 void   hw_ibrs_recalculate(void);
+void   hw_ssb_recalculate(bool all_cpus);
 void   nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame);
 void   nmi_call_kdb_smp(u_int type, struct trapframe *frame);
 void   nmi_handle_intr(u_int type, struct trapframe *frame);

Modified: head/sys/x86/x86/cpu

svn commit: r334031 - head/lib/libc/stdio

2018-05-22 Thread Konstantin Belousov
Author: kib
Date: Tue May 22 11:05:40 2018
New Revision: 334031
URL: https://svnweb.freebsd.org/changeset/base/334031

Log:
  Implement printf(3) family %m format string extension.
  
  Reviewed by:  ed, dim (code only)
  Sponsored by: Mellanox Technologies
  MFC after:1 week

Modified:
  head/lib/libc/stdio/printf.3
  head/lib/libc/stdio/vfprintf.c

Modified: head/lib/libc/stdio/printf.3
==
--- head/lib/libc/stdio/printf.3Tue May 22 10:31:06 2018
(r334030)
+++ head/lib/libc/stdio/printf.3Tue May 22 11:05:40 2018
(r334031)
@@ -32,7 +32,7 @@
 .\" @(#)printf.3   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd July 30, 2016
+.Dd May 22, 2018
 .Dt PRINTF 3
 .Os
 .Sh NAME
@@ -651,6 +651,12 @@ integer indicated by the
 .Vt "int *"
 (or variant) pointer argument.
 No argument is converted.
+.It Cm m
+Print the string representation of the error code stored in the
+.Dv errno
+variable at the beginning of the call, as returned by
+.Xr strerror 3 .
+No argument is taken.
 .It Cm %
 A
 .Ql %
@@ -730,6 +736,12 @@ and
 .Cm \&%U
 are not standard and
 are provided only for backward compatibility.
+The conversion format
+.Cm \&%m
+is also not standard and provides the popular extension from the
+.Tn GNU C
+library.
+.Pp
 The effect of padding the
 .Cm %p
 format with zeros (either by the
@@ -767,9 +779,11 @@ or the return value would be too large to be represent
 .El
 .Sh SEE ALSO
 .Xr printf 1 ,
+.Xr errno 2 ,
 .Xr fmtcheck 3 ,
 .Xr scanf 3 ,
 .Xr setlocale 3 ,
+.Xr strerror 3 ,
 .Xr wprintf 3
 .Sh STANDARDS
 Subject to the caveats noted in the
@@ -822,6 +836,12 @@ and
 .Fn vdprintf
 functions were added in
 .Fx 8.0 .
+The
+.Cm \&%m
+format extension first appeared in the
+.Tn GNU C
+library, and was implemented in
+.Fx 12.0 .
 .Sh BUGS
 The
 .Nm

Modified: head/lib/libc/stdio/vfprintf.c
==
--- head/lib/libc/stdio/vfprintf.c  Tue May 22 10:31:06 2018
(r334030)
+++ head/lib/libc/stdio/vfprintf.c  Tue May 22 11:05:40 2018
(r334031)
@@ -317,6 +317,7 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0
int ret;/* return value accumulator */
int width;  /* width from format (%8d), or 0 */
int prec;   /* precision from format; <0 for N/A */
+   int saved_errno;
char sign;  /* sign prefix (' ', '+', '-', or \0) */
struct grouping_state gs; /* thousands' grouping info */
 
@@ -466,6 +467,7 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0
savserr = fp->_flags & __SERR;
fp->_flags &= ~__SERR;
 
+   saved_errno = errno;
convbuf = NULL;
fmt = (char *)fmt0;
argtable = NULL;
@@ -776,6 +778,11 @@ fp_common:
}
break;
 #endif /* !NO_FLOATING_POINT */
+   case 'm':
+   cp = strerror(saved_errno);
+   size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);
+   sign = '\0';
+   break;
case 'n':
/*
 * Assignment-like behavior is specified if the
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334038 - head/sys/amd64/include

2018-05-22 Thread Konstantin Belousov
Author: kib
Date: Tue May 22 13:25:15 2018
New Revision: 334038
URL: https://svnweb.freebsd.org/changeset/base/334038

Log:
  Enable IBRS when entering an interrupt handler from usermode.
  
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/amd64/include/asmacros.h

Modified: head/sys/amd64/include/asmacros.h
==
--- head/sys/amd64/include/asmacros.h   Tue May 22 13:21:44 2018
(r334037)
+++ head/sys/amd64/include/asmacros.h   Tue May 22 13:25:15 2018
(r334038)
@@ -260,6 +260,7 @@ X\vec_name:
jz  1f  /* yes, leave PCB_FULL_IRET alone */
movqPCPU(CURPCB),%r8
andl$~PCB_FULL_IRET,PCB_FLAGS(%r8)
+   callhandle_ibrs_entry
 1:
.endm
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334040 - head/sys/i386/include

2018-05-22 Thread Konstantin Belousov
Author: kib
Date: Tue May 22 13:30:56 2018
New Revision: 334040
URL: https://svnweb.freebsd.org/changeset/base/334040

Log:
  Fix double-load of %cr3 and double-copy of the stack frame for the
  kernel entry from userspace vm86.
  
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/i386/include/asmacros.h

Modified: head/sys/i386/include/asmacros.h
==
--- head/sys/i386/include/asmacros.hTue May 22 13:28:05 2018
(r334039)
+++ head/sys/i386/include/asmacros.hTue May 22 13:30:56 2018
(r334040)
@@ -218,7 +218,7 @@
testl   $PCB_VM86CALL, PCB_FLAGS(%eax)
jnz 3f
NMOVE_STACKS
-   jmp 2f
+   jmp 3f
 1: testb   $SEL_RPL_MASK, TF_CS(%esp)
jz  3f
 2: MOVE_STACKS
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334042 - head/sys/i386/include

2018-05-22 Thread Konstantin Belousov
Author: kib
Date: Tue May 22 13:45:40 2018
New Revision: 334042
URL: https://svnweb.freebsd.org/changeset/base/334042

Log:
  Use local unique labels inside most often used macros.
  
  Discussed with:   bde
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/i386/include/asmacros.h

Modified: head/sys/i386/include/asmacros.h
==
--- head/sys/i386/include/asmacros.hTue May 22 13:45:24 2018
(r334041)
+++ head/sys/i386/include/asmacros.hTue May 22 13:45:40 2018
(r334042)
@@ -189,9 +189,9 @@
movlPCPU(KESP0), %edx
movl$TF_SZ, %ecx
testl   $PSL_VM, TF_EFLAGS(%esp)
-   jz  1001f
+   jz  .L\@.1
addl$VM86_STACK_SPACE, %ecx
-1001:  subl%ecx, %edx
+.L\@.1:subl%ecx, %edx
movl%edx, %edi
movl%esp, %esi
rep; movsb
@@ -199,9 +199,9 @@
.endm
 
.macro  LOAD_KCR3
-   call1000f
-1000:  popl%eax
-   movl(tramp_idleptd - 1000b)(%eax), %eax
+   call.L\@.1
+.L\@.1:popl%eax
+   movl(tramp_idleptd - .L\@.1)(%eax), %eax
movl%eax, %cr3
.endm
 
@@ -212,17 +212,17 @@
 
.macro  KENTER
testl   $PSL_VM, TF_EFLAGS(%esp)
-   jz  1f
+   jz  .L\@.1
LOAD_KCR3
movlPCPU(CURPCB), %eax
testl   $PCB_VM86CALL, PCB_FLAGS(%eax)
-   jnz 3f
+   jnz .L\@.3
NMOVE_STACKS
-   jmp 3f
-1: testb   $SEL_RPL_MASK, TF_CS(%esp)
-   jz  3f
-2: MOVE_STACKS
-3:
+   jmp .L\@.3
+.L\@.1:testb   $SEL_RPL_MASK, TF_CS(%esp)
+   jz  .L\@.3
+.L\@.2:MOVE_STACKS
+.L\@.3:
.endm
 
 #endif /* LOCORE */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334064 - head/sys/x86/x86

2018-05-22 Thread Konstantin Belousov
Author: kib
Date: Tue May 22 20:50:19 2018
New Revision: 334064
URL: https://svnweb.freebsd.org/changeset/base/334064

Log:
  Fix UP build.
  
  Reported by:  jhb
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/x86/x86/cpu_machdep.c

Modified: head/sys/x86/x86/cpu_machdep.c
==
--- head/sys/x86/x86/cpu_machdep.c  Tue May 22 20:00:56 2018
(r334063)
+++ head/sys/x86/x86/cpu_machdep.c  Tue May 22 20:50:19 2018
(r334064)
@@ -69,9 +69,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#ifdef SMP
 #include 
-#endif
 #include 
 
 #include 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334103 - in head/sys/i386: i386 include

2018-05-23 Thread Konstantin Belousov
Author: kib
Date: Wed May 23 16:31:46 2018
New Revision: 334103
URL: https://svnweb.freebsd.org/changeset/base/334103

Log:
  Support IBRS for i386.
  
  Tested by:pho
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D15522

Modified:
  head/sys/i386/i386/exception.s
  head/sys/i386/i386/genassym.c
  head/sys/i386/i386/support.s
  head/sys/i386/include/asmacros.h

Modified: head/sys/i386/i386/exception.s
==
--- head/sys/i386/i386/exception.s  Wed May 23 16:28:31 2018
(r334102)
+++ head/sys/i386/i386/exception.s  Wed May 23 16:31:46 2018
(r334103)
@@ -310,6 +310,8 @@ IDTVEC(dbg)
jz  calltrap
 dbg_user:
NMOVE_STACKS
+   movl$handle_ibrs_entry,%eax
+   call*%eax
pushl   %esp
movl$trap,%eax
call*%eax
@@ -337,6 +339,8 @@ nmi_mchk_common:
 * Do not switch to the thread kernel stack, otherwise we might
 * obliterate the previous context partially copied from the
 * trampoline stack.
+* Do not re-enable IBRS, there is no good place to store
+* previous state if we come from the kernel.
 */
movl%cr3, %eax
movl%eax, TF_ERR(%esp)
@@ -364,6 +368,8 @@ IDTVEC(int0x80_syscall)
SET_KERNEL_SREGS
cld
MOVE_STACKS
+   movl$handle_ibrs_entry,%eax
+   call*%eax
sti
FAKE_MCOUNT(TF_EIP(%esp))
pushl   %esp
@@ -509,7 +515,9 @@ doreti_exit:
jmp 2f
 1: testl   $SEL_RPL_MASK, TF_CS(%esp)
jz  doreti_popl_fs
-2: movl%esp, %esi
+2: movl$handle_ibrs_exit,%eax
+   call*%eax
+   movl%esp, %esi
movlPCPU(TRAMPSTK), %edx
subl%ecx, %edx
movl%edx, %edi

Modified: head/sys/i386/i386/genassym.c
==
--- head/sys/i386/i386/genassym.c   Wed May 23 16:28:31 2018
(r334102)
+++ head/sys/i386/i386/genassym.c   Wed May 23 16:31:46 2018
(r334103)
@@ -221,6 +221,7 @@ ASSYM(PC_PRIVATE_TSS, offsetof(struct pcpu, pc_private
 ASSYM(PC_KESP0, offsetof(struct pcpu, pc_kesp0));
 ASSYM(PC_TRAMPSTK, offsetof(struct pcpu, pc_trampstk));
 ASSYM(PC_COPYOUT_BUF, offsetof(struct pcpu, pc_copyout_buf));
+ASSYM(PC_IBPB_SET, offsetof(struct pcpu, pc_ibpb_set));
 
 #ifdef DEV_APIC
 ASSYM(LA_EOI, LAPIC_EOI * LAPIC_MEM_MUL);

Modified: head/sys/i386/i386/support.s
==
--- head/sys/i386/i386/support.sWed May 23 16:28:31 2018
(r334102)
+++ head/sys/i386/i386/support.sWed May 23 16:31:46 2018
(r334103)
@@ -433,9 +433,31 @@ msr_onfault:
ret
 
 ENTRY(handle_ibrs_entry)
-   ret
+   cmpb$0,hw_ibrs_active
+   je  1f
+   movl$MSR_IA32_SPEC_CTRL,%ecx
+   rdmsr
+   orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
+   orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32,%edx
+   wrmsr
+   movb$1,PCPU(IBPB_SET)
+   /*
+* i386 does not implement SMEP, but the 4/4 split makes this not
+* that important.
+*/
+1: ret
 END(handle_ibrs_entry)
 
 ENTRY(handle_ibrs_exit)
-   ret
+   cmpb$0,PCPU(IBPB_SET)
+   je  1f
+   pushl   %ecx
+   movl$MSR_IA32_SPEC_CTRL,%ecx
+   rdmsr
+   andl$~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
+   andl$~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
+   wrmsr
+   popl%ecx
+   movb$0,PCPU(IBPB_SET)
+1: ret
 END(handle_ibrs_exit)

Modified: head/sys/i386/include/asmacros.h
==
--- head/sys/i386/include/asmacros.hWed May 23 16:28:31 2018
(r334102)
+++ head/sys/i386/include/asmacros.hWed May 23 16:31:46 2018
(r334103)
@@ -218,10 +218,14 @@
testl   $PCB_VM86CALL, PCB_FLAGS(%eax)
jnz .L\@.3
NMOVE_STACKS
+   movl$handle_ibrs_entry,%edx
+   call*%edx
jmp .L\@.3
 .L\@.1:testb   $SEL_RPL_MASK, TF_CS(%esp)
jz  .L\@.3
 .L\@.2:MOVE_STACKS
+   movl$handle_ibrs_entry,%edx
+   call*%edx
 .L\@.3:
.endm
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334111 - head/lib/libc/sys

2018-05-23 Thread Konstantin Belousov
Author: kib
Date: Wed May 23 17:55:30 2018
New Revision: 334111
URL: https://svnweb.freebsd.org/changeset/base/334111

Log:
  Note that PT_SETSTEP is auto-cleared.
  
  Wording and reviewed by:  jhb
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days
  Differential revision:https://reviews.freebsd.org/D15054

Modified:
  head/lib/libc/sys/ptrace.2

Modified: head/lib/libc/sys/ptrace.2
==
--- head/lib/libc/sys/ptrace.2  Wed May 23 17:44:29 2018(r334110)
+++ head/lib/libc/sys/ptrace.2  Wed May 23 17:55:30 2018(r334111)
@@ -2,7 +2,7 @@
 .\"$NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
 .\"
 .\" This file is in the public domain.
-.Dd December 1, 2017
+.Dd May 22, 2018
 .Dt PTRACE 2
 .Os
 .Sh NAME
@@ -606,6 +606,7 @@ The return value from
 is the count of array entries filled in.
 .It Dv PT_SETSTEP
 This request will turn on single stepping of the specified process.
+Stepping is automatically disabled when a single step trap is caught.
 .It Dv PT_CLEARSTEP
 This request will turn off single stepping of the specified process.
 .It Dv PT_SUSPEND
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334119 - in head/sys: amd64/amd64 i386/i386

2018-05-23 Thread Konstantin Belousov
Author: kib
Date: Wed May 23 21:25:49 2018
New Revision: 334119
URL: https://svnweb.freebsd.org/changeset/base/334119

Log:
  Style.
  
  Wording and reviewed by:  jhb
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days
  Differential revision:https://reviews.freebsd.org/D15054

Modified:
  head/sys/amd64/amd64/machdep.c
  head/sys/i386/i386/machdep.c

Modified: head/sys/amd64/amd64/machdep.c
==
--- head/sys/amd64/amd64/machdep.c  Wed May 23 21:02:14 2018
(r334118)
+++ head/sys/amd64/amd64/machdep.c  Wed May 23 21:25:49 2018
(r334119)
@@ -1985,6 +1985,7 @@ ptrace_single_step(struct thread *td)
 int
 ptrace_clear_single_step(struct thread *td)
 {
+
td->td_frame->tf_rflags &= ~PSL_T;
return (0);
 }

Modified: head/sys/i386/i386/machdep.c
==
--- head/sys/i386/i386/machdep.cWed May 23 21:02:14 2018
(r334118)
+++ head/sys/i386/i386/machdep.cWed May 23 21:25:49 2018
(r334119)
@@ -2771,6 +2771,7 @@ ptrace_single_step(struct thread *td)
 int
 ptrace_clear_single_step(struct thread *td)
 {
+
td->td_frame->tf_eflags &= ~PSL_T;
return (0);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334121 - head/sys/i386/i386

2018-05-23 Thread Konstantin Belousov
Author: kib
Date: Wed May 23 21:26:41 2018
New Revision: 334121
URL: https://svnweb.freebsd.org/changeset/base/334121

Log:
  Stop obliterating actual exception type for emulated traps from vm86.
  
  Wording and reviewed by:  jhb
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D15054

Modified:
  head/sys/i386/i386/trap.c

Modified: head/sys/i386/i386/trap.c
==
--- head/sys/i386/i386/trap.c   Wed May 23 21:26:33 2018(r334120)
+++ head/sys/i386/i386/trap.c   Wed May 23 21:26:41 2018(r334121)
@@ -357,7 +357,6 @@ user_trctrap_out:
if (frame->tf_eflags & PSL_VM) {
signo = vm86_emulate((struct vm86frame *)frame);
if (signo == SIGTRAP) {
-   type = T_TRCTRAP;
load_dr6(rdr6() | 0x4000);
goto user_trctrap_out;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334122 - in head/sys: amd64/amd64 i386/i386 sys

2018-05-23 Thread Konstantin Belousov
Author: kib
Date: Wed May 23 21:39:29 2018
New Revision: 334122
URL: https://svnweb.freebsd.org/changeset/base/334122

Log:
  x86: stop unconditionally clearing PSL_T on the trace trap.
  
  We certainly should clear PSL_T when calling the SIGTRAP signal
  handler, which is already done by all x86 sendsig(9) ABI code.  On the
  other hand, there is no obvious reason why PSL_T needs to be cleared
  when returning from the signal handler.  For instance, Linux allows
  userspace to set PSL_T and keep tracing enabled for the desired
  period.  There are userspace programs which would use PSL_T if we make
  it possible, for instance sbcl.
  
  Remember if PSL_T was set by PT_STEP or PT_SETSTEP by mean of TDB_STEP
  flag, and only clear it when the flag is set.
  
  Discussed with:   Ali Mashtizadeh
  Reviewed by:  jhb (previous version)
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D15054

Modified:
  head/sys/amd64/amd64/machdep.c
  head/sys/amd64/amd64/trap.c
  head/sys/i386/i386/machdep.c
  head/sys/i386/i386/trap.c
  head/sys/sys/proc.h

Modified: head/sys/amd64/amd64/machdep.c
==
--- head/sys/amd64/amd64/machdep.c  Wed May 23 21:26:41 2018
(r334121)
+++ head/sys/amd64/amd64/machdep.c  Wed May 23 21:39:29 2018
(r334122)
@@ -1978,7 +1978,12 @@ ptrace_set_pc(struct thread *td, unsigned long addr)
 int
 ptrace_single_step(struct thread *td)
 {
-   td->td_frame->tf_rflags |= PSL_T;
+
+   PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+   if ((td->td_frame->tf_rflags & PSL_T) == 0) {
+   td->td_frame->tf_rflags |= PSL_T;
+   td->td_dbgflags |= TDB_STEP;
+   }
return (0);
 }
 
@@ -1986,7 +1991,9 @@ int
 ptrace_clear_single_step(struct thread *td)
 {
 
+   PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
td->td_frame->tf_rflags &= ~PSL_T;
+   td->td_dbgflags &= ~TDB_STEP;
return (0);
 }
 

Modified: head/sys/amd64/amd64/trap.c
==
--- head/sys/amd64/amd64/trap.c Wed May 23 21:26:41 2018(r334121)
+++ head/sys/amd64/amd64/trap.c Wed May 23 21:39:29 2018(r334122)
@@ -285,8 +285,14 @@ trap(struct trapframe *frame)
signo = SIGTRAP;
ucode = TRAP_TRACE;
dr6 = rdr6();
-   if (dr6 & DBREG_DR6_BS)
-   frame->tf_rflags &= ~PSL_T;
+   if ((dr6 & DBREG_DR6_BS) != 0) {
+   PROC_LOCK(td->td_proc);
+   if ((td->td_dbgflags & TDB_STEP) != 0) {
+   td->td_frame->tf_rflags &= ~PSL_T;
+   td->td_dbgflags &= ~TDB_STEP;
+   }
+   PROC_UNLOCK(td->td_proc);
+   }
break;
 
case T_ARITHTRAP:   /* arithmetic trap */

Modified: head/sys/i386/i386/machdep.c
==
--- head/sys/i386/i386/machdep.cWed May 23 21:26:41 2018
(r334121)
+++ head/sys/i386/i386/machdep.cWed May 23 21:39:29 2018
(r334122)
@@ -2764,7 +2764,12 @@ ptrace_set_pc(struct thread *td, u_long addr)
 int
 ptrace_single_step(struct thread *td)
 {
-   td->td_frame->tf_eflags |= PSL_T;
+
+   PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+   if ((td->td_frame->tf_eflags & PSL_T) == 0) {
+   td->td_frame->tf_eflags |= PSL_T;
+   td->td_dbgflags |= TDB_STEP;
+   }
return (0);
 }
 
@@ -2772,7 +2777,9 @@ int
 ptrace_clear_single_step(struct thread *td)
 {
 
+   PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
td->td_frame->tf_eflags &= ~PSL_T;
+   td->td_dbgflags &= ~TDB_STEP;
return (0);
 }
 

Modified: head/sys/i386/i386/trap.c
==
--- head/sys/i386/i386/trap.c   Wed May 23 21:26:41 2018(r334121)
+++ head/sys/i386/i386/trap.c   Wed May 23 21:39:29 2018(r334122)
@@ -337,8 +337,14 @@ user_trctrap_out:
signo = SIGTRAP;
ucode = TRAP_TRACE;
dr6 = rdr6();
-   if (dr6 & DBREG_DR6_BS)
-   frame->tf_eflags &= ~PSL_T;
+   if ((dr6 & DBREG_DR6_BS) != 0) {
+   PROC_LOCK(td->td_proc);
+   if ((td->td_dbgflags & TDB_STEP) != 0) {
+   td->td_frame->tf_eflags &= ~PSL_T;
+   td->td_dbgflags &= ~TDB_STEP;
+   }
+   PROC_UNLOCK(td->

svn commit: r334210 - head/sys/i386/i386

2018-05-25 Thread Konstantin Belousov
Author: kib
Date: Fri May 25 16:24:20 2018
New Revision: 334210
URL: https://svnweb.freebsd.org/changeset/base/334210

Log:
  Cleanup.  Remove unused instruction and label.
  
  Tested by:bde
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/swtch.s

Modified: head/sys/i386/i386/swtch.s
==
--- head/sys/i386/i386/swtch.s  Fri May 25 13:59:48 2018(r334209)
+++ head/sys/i386/i386/swtch.s  Fri May 25 16:24:20 2018(r334210)
@@ -186,10 +186,6 @@ ENTRY(cpu_switch)
lock
 #endif
btsl%esi, PM_ACTIVE(%ebx)   /* set new */
-   jmp sw1
-
-sw0:
-   SETOP   %esi,TD_LOCK(%edi)  /* Switchout td_lock */
 sw1:
BLOCK_SPIN(%ecx)
/*
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334211 - in head/sys/i386: i386 include

2018-05-25 Thread Konstantin Belousov
Author: kib
Date: Fri May 25 16:29:22 2018
New Revision: 334211
URL: https://svnweb.freebsd.org/changeset/base/334211

Log:
  Optimize i386 pmap_extract_and_hold().
  
  In particular, stop using pmap_pte() to read non-promoted pte while
  walking the page table.  pmap_pte() needs to shoot down the kernel
  mapping globally which causes IPI broadcast.  Since
  pmap_extract_and_hold() is used for slow copyin(9), it is very
  significant hit for the 4/4 kernels.
  
  Instead, create single purpose per-processor page frame and use it to
  locally map page table page inside the critical section, to avoid
  reuse of the frame by other thread if context switched.
  
  Measurement demostrated very significant improvements in any load that
  utilizes copyin/copyout.
  
  Found and benchmarked by: bde
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/pmap.c
  head/sys/i386/include/pcpu.h

Modified: head/sys/i386/i386/pmap.c
==
--- head/sys/i386/i386/pmap.c   Fri May 25 16:24:20 2018(r334210)
+++ head/sys/i386/i386/pmap.c   Fri May 25 16:29:22 2018(r334211)
@@ -692,6 +692,10 @@ pmap_init_reserved_pages(void)
pc->pc_copyout_saddr = kva_alloc(ptoa(2));
if (pc->pc_copyout_saddr == 0)
panic("unable to allocate sleepable copyout KVA");
+   pc->pc_pmap_eh_va = kva_alloc(ptoa(1));
+   if (pc->pc_pmap_eh_va == 0)
+   panic("unable to allocate pmap_extract_and_hold KVA");
+   pc->pc_pmap_eh_ptep = (char *)vtopte(pc->pc_pmap_eh_va);
 
/*
 * Skip if the mappings have already been initialized,
@@ -1598,8 +1602,8 @@ pmap_extract(pmap_t pmap, vm_offset_t va)
 vm_page_t
 pmap_extract_and_hold(pmap_t pmap, vm_offset_t va, vm_prot_t prot)
 {
-   pd_entry_t pde;
-   pt_entry_t pte, *ptep;
+   pd_entry_t pde, newpf;
+   pt_entry_t *eh_ptep, pte, *ptep;
vm_page_t m;
vm_paddr_t pa;
 
@@ -1619,9 +1623,17 @@ retry:
vm_page_hold(m);
}
} else {
-   ptep = pmap_pte(pmap, va);
+   newpf = pde & PG_FRAME;
+   critical_enter();
+   eh_ptep = (pt_entry_t *)PCPU_GET(pmap_eh_ptep);
+   if ((*eh_ptep & PG_FRAME) != newpf) {
+   *eh_ptep = newpf | PG_RW | PG_V | PG_A | PG_M;
+   invlcaddr((void *)PCPU_GET(pmap_eh_va));
+   }
+   ptep = (pt_entry_t *)PCPU_GET(pmap_eh_va) +
+   (i386_btop(va) & (NPTEPG - 1));
pte = *ptep;
-   pmap_pte_release(ptep);
+   critical_exit();
if (pte != 0 &&
((pte & PG_RW) || (prot & VM_PROT_WRITE) == 0)) {
if (vm_page_pa_tryrelock(pmap, pte & PG_FRAME,

Modified: head/sys/i386/include/pcpu.h
==
--- head/sys/i386/include/pcpu.hFri May 25 16:24:20 2018
(r334210)
+++ head/sys/i386/include/pcpu.hFri May 25 16:29:22 2018
(r334211)
@@ -76,9 +76,11 @@
struct  mtx pc_copyout_mlock;   \
struct  sx pc_copyout_slock;\
char*pc_copyout_buf;\
+   vm_offset_t pc_pmap_eh_va;  \
+   caddr_t pc_pmap_eh_ptep;
\
uint32_t pc_smp_tlb_done;   /* TLB op acknowledgement */\
uint32_t pc_ibpb_set;   \
-   char__pad[546]
+   char__pad[538]
 
 #ifdef _KERNEL
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334216 - head/usr.sbin/bhyve

2018-05-25 Thread Konstantin Belousov
On Fri, May 25, 2018 at 06:54:40PM +, Marcelo Araujo wrote:
> Author: araujo
> Date: Fri May 25 18:54:40 2018
> New Revision: 334216
> URL: https://svnweb.freebsd.org/changeset/base/334216
> 
> Log:
>   After a long discussion about assert(3), we gonna use a HardenedBSD
>   approach to chek strdup(3) memory allocation.
>   
>   Submitted by:   Shaw Webb 
>   Reported by:brooks
>   Obtained from:  HardenedBSD
> 
> Modified:
>   head/usr.sbin/bhyve/bhyverun.c
> 
> Modified: head/usr.sbin/bhyve/bhyverun.c
> ==
> --- head/usr.sbin/bhyve/bhyverun.cFri May 25 18:11:13 2018
> (r334215)
> +++ head/usr.sbin/bhyve/bhyverun.cFri May 25 18:54:40 2018
> (r334216)
> @@ -193,7 +193,8 @@ topology_parse(const char *opt)
>   c = 1, n = 1, s = 1, t = 1;
>   ns = false, scts = false;
>   str = strdup(opt);
> - assert(str != NULL);
> + if (str == NULL)
> + goto out;
>  
>   while ((cp = strsep(&str, ",")) != NULL) {
>   if (sscanf(cp, "%i%n", &tmp, &chk) == 1) {
> @@ -225,6 +226,7 @@ topology_parse(const char *opt)
>   goto out;
>   }
>   free(str);
> + str = NULL;
>  
>   /*
>* Range check 1 <= n <= UINT16_MAX all values
> @@ -253,7 +255,8 @@ topology_parse(const char *opt)
>   return(0);
>  
>  out:
> - free(str);
> + if (str != NULL)
This check is useless.  Free(3) is fine handling NULL argument.

> + free(str);
>   return (-1);
>  }
>  
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334361 - head/usr.sbin/pmc

2018-05-30 Thread Konstantin Belousov
On Wed, May 30, 2018 at 12:06:17AM +, Matt Macy wrote:
> Author: mmacy
> Date: Wed May 30 00:06:17 2018
> New Revision: 334361
> URL: https://svnweb.freebsd.org/changeset/base/334361
> 
> Log:
>   pmc: don't break build with format issues
> 
> Modified:
>   head/usr.sbin/pmc/Makefile
> 
> Modified: head/usr.sbin/pmc/Makefile
> ==
> --- head/usr.sbin/pmc/MakefileTue May 29 23:08:33 2018
> (r334360)
> +++ head/usr.sbin/pmc/MakefileWed May 30 00:06:17 2018
> (r334361)
> @@ -9,4 +9,5 @@ LIBADD=   kvm pmc m ncursesw pmcstat elf
>  
>  SRCS=pmc.c pmc_util.c cmd_pmc_stat.c
>  
> +CWARNFLAGS.cmd_pmc_stat.c=   -Wno-format
>  .include 
So this builds knownly broken binary instead of stopping.

If I understand your troubles right, the usual solution for them is
printf("%jx", (uintmax_t)trouble);
used in many places around the kernel, less so in userspace.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334397 - head/sys/i386/i386

2018-05-30 Thread Konstantin Belousov
Author: kib
Date: Wed May 30 20:24:21 2018
New Revision: 334397
URL: https://svnweb.freebsd.org/changeset/base/334397

Log:
  Avoid unneccessary TLB shootdowns in pmap_unwire_ptp() for user pmaps,
  which no longer create recursive page table mappings.
  
  Benchmarked by:   bde
  Tested by:pho
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/pmap.c

Modified: head/sys/i386/i386/pmap.c
==
--- head/sys/i386/i386/pmap.c   Wed May 30 20:16:17 2018(r334396)
+++ head/sys/i386/i386/pmap.c   Wed May 30 20:24:21 2018(r334397)
@@ -1872,7 +1872,6 @@ pmap_unwire_ptp(pmap_t pmap, vm_page_t m, struct spgli
 static void
 _pmap_unwire_ptp(pmap_t pmap, vm_page_t m, struct spglist *free)
 {
-   vm_offset_t pteva;
 
/*
 * unmap the page table page
@@ -1881,16 +1880,13 @@ _pmap_unwire_ptp(pmap_t pmap, vm_page_t m, struct spgl
--pmap->pm_stats.resident_count;
 
/*
-* Do an invltlb to make the invalidated mapping
-* take effect immediately.
+* There is not need to invalidate the recursive mapping since
+* we never instantiate such mapping for the usermode pmaps,
+* and never remove page table pages from the kernel pmap.
+* Put page on a list so that it is released since all TLB
+* shootdown is done.
 */
-   pteva = VM_MAXUSER_ADDRESS + i386_ptob(m->pindex);
-   pmap_invalidate_page(pmap, pteva);
-
-   /* 
-* Put page on a list so that it is released after
-* *ALL* TLB shootdown is done
-*/
+   MPASS(pmap != kernel_pmap);
pmap_add_delayed_free_list(m, free, TRUE);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334398 - head/sys/i386/i386

2018-05-30 Thread Konstantin Belousov
Author: kib
Date: Wed May 30 20:26:47 2018
New Revision: 334398
URL: https://svnweb.freebsd.org/changeset/base/334398

Log:
  Do use pmap_pte_quick() in pmap_enter_quick_locked().
  
  Benchmarked by:   bde
  Tested by:pho
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/pmap.c

Modified: head/sys/i386/i386/pmap.c
==
--- head/sys/i386/i386/pmap.c   Wed May 30 20:24:21 2018(r334397)
+++ head/sys/i386/i386/pmap.c   Wed May 30 20:26:47 2018(r334398)
@@ -3916,14 +3916,14 @@ pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, v
mpte = NULL;
}
 
-   /* XXXKIB: pmap_pte_quick() instead ? */
-   pte = pmap_pte(pmap, va);
+   sched_pin();
+   pte = pmap_pte_quick(pmap, va);
if (*pte) {
if (mpte != NULL) {
mpte->wire_count--;
mpte = NULL;
}
-   pmap_pte_release(pte);
+   sched_unpin();
return (mpte);
}
 
@@ -3941,7 +3941,7 @@ pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, v

mpte = NULL;
}
-   pmap_pte_release(pte);
+   sched_unpin();
return (mpte);
}
 
@@ -3963,7 +3963,7 @@ pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, v
pte_store(pte, pa | PG_V | PG_U);
else
pte_store(pte, pa | PG_V | PG_U | PG_MANAGED);
-   pmap_pte_release(pte);
+   sched_unpin();
return (mpte);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334399 - head/sys/i386/i386

2018-05-30 Thread Konstantin Belousov
Author: kib
Date: Wed May 30 20:39:22 2018
New Revision: 334399
URL: https://svnweb.freebsd.org/changeset/base/334399

Log:
  Restore pmap_copy() for 4/4 i386 pmap.
  
  Create yet another temporal pte mapping routine pmap_pte_quick3(),
  which is the copy of the pmap_pte_quick() and relies on the
  pvh_global_lock to protect the frame.  It accounts into the same
  counters as pmap_pte_quick().  It is needed since pmap_copy() uses
  pmap_pte_quick() already, and since a user pmap is no longer current
  pmap.
  
  pmap_copy() still provides the advantage for real-world workloads
  involving lot of forks where processes do not exec immediately.
  
  Benchmarked by:   bde
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/pmap.c

Modified: head/sys/i386/i386/pmap.c
==
--- head/sys/i386/i386/pmap.c   Wed May 30 20:26:47 2018(r334398)
+++ head/sys/i386/i386/pmap.c   Wed May 30 20:39:22 2018(r334399)
@@ -264,10 +264,10 @@ caddr_t CADDR3;
  */
 static caddr_t crashdumpmap;
 
-static pt_entry_t *PMAP1 = NULL, *PMAP2;
-static pt_entry_t *PADDR1 = NULL, *PADDR2;
+static pt_entry_t *PMAP1 = NULL, *PMAP2, *PMAP3;
+static pt_entry_t *PADDR1 = NULL, *PADDR2, *PADDR3;
 #ifdef SMP
-static int PMAP1cpu;
+static int PMAP1cpu, PMAP3cpu;
 static int PMAP1changedcpu;
 SYSCTL_INT(_debug, OID_AUTO, PMAP1changedcpu, CTLFLAG_RD, 
   &PMAP1changedcpu, 0,
@@ -658,6 +658,7 @@ pmap_bootstrap(vm_paddr_t firstaddr)
 */
SYSMAP(pt_entry_t *, PMAP1, PADDR1, 1)
SYSMAP(pt_entry_t *, PMAP2, PADDR2, 1)
+   SYSMAP(pt_entry_t *, PMAP3, PADDR3, 1)
 
mtx_init(&PMAP2mutex, "PMAP2", NULL, MTX_DEF);
 
@@ -1563,6 +1564,40 @@ pmap_pte_quick(pmap_t pmap, vm_offset_t va)
return (0);
 }
 
+static pt_entry_t *
+pmap_pte_quick3(pmap_t pmap, vm_offset_t va)
+{
+   pd_entry_t newpf;
+   pd_entry_t *pde;
+
+   pde = pmap_pde(pmap, va);
+   if (*pde & PG_PS)
+   return (pde);
+   if (*pde != 0) {
+   rw_assert(&pvh_global_lock, RA_WLOCKED);
+   KASSERT(curthread->td_pinned > 0, ("curthread not pinned"));
+   newpf = *pde & PG_FRAME;
+   if ((*PMAP3 & PG_FRAME) != newpf) {
+   *PMAP3 = newpf | PG_RW | PG_V | PG_A | PG_M;
+#ifdef SMP
+   PMAP3cpu = PCPU_GET(cpuid);
+#endif
+   invlcaddr(PADDR3);
+   PMAP1changed++;
+   } else
+#ifdef SMP
+   if (PMAP3cpu != PCPU_GET(cpuid)) {
+   PMAP3cpu = PCPU_GET(cpuid);
+   invlcaddr(PADDR3);
+   PMAP1changedcpu++;
+   } else
+#endif
+   PMAP1unchanged++;
+   return (PADDR3 + (i386_btop(va) & (NPTEPG - 1)));
+   }
+   return (0);
+}
+
 /*
  * Routine:pmap_extract
  * Function:
@@ -4166,6 +4201,109 @@ void
 pmap_copy(pmap_t dst_pmap, pmap_t src_pmap, vm_offset_t dst_addr, vm_size_t 
len,
 vm_offset_t src_addr)
 {
+   struct spglist free;
+   pt_entry_t *src_pte, *dst_pte, ptetemp;
+   pd_entry_t srcptepaddr;
+   vm_page_t dstmpte, srcmpte;
+   vm_offset_t addr, end_addr, pdnxt;
+   u_int ptepindex;
+
+   if (dst_addr != src_addr)
+   return;
+
+   end_addr = src_addr + len;
+
+   rw_wlock(&pvh_global_lock);
+   if (dst_pmap < src_pmap) {
+   PMAP_LOCK(dst_pmap);
+   PMAP_LOCK(src_pmap);
+   } else {
+   PMAP_LOCK(src_pmap);
+   PMAP_LOCK(dst_pmap);
+   }
+   sched_pin();
+   for (addr = src_addr; addr < end_addr; addr = pdnxt) {
+   KASSERT(addr < PMAP_TRM_MIN_ADDRESS,
+   ("pmap_copy: invalid to pmap_copy the trampoline"));
+
+   pdnxt = (addr + NBPDR) & ~PDRMASK;
+   if (pdnxt < addr)
+   pdnxt = end_addr;
+   ptepindex = addr >> PDRSHIFT;
+
+   srcptepaddr = src_pmap->pm_pdir[ptepindex];
+   if (srcptepaddr == 0)
+   continue;
+
+   if (srcptepaddr & PG_PS) {
+   if ((addr & PDRMASK) != 0 || addr + NBPDR > end_addr)
+   continue;
+   if (dst_pmap->pm_pdir[ptepindex] == 0 &&
+   ((srcptepaddr & PG_MANAGED) == 0 ||
+   pmap_pv_insert_pde(dst_pmap, addr, srcptepaddr &
+   PG_PS_FRAME))) {
+   dst_pmap->pm_pdir[ptepindex] = srcptepaddr &
+   ~PG_W;
+   dst_pmap->pm_stats.resident_count +=
+   NBPDR / PAGE_SIZE;
+   pmap_pde_mappings++;
+   }
+   continue;
+   }
+
+

svn commit: r334400 - head/sys/i386/i386

2018-05-30 Thread Konstantin Belousov
Author: kib
Date: Wed May 30 20:43:48 2018
New Revision: 334400
URL: https://svnweb.freebsd.org/changeset/base/334400

Log:
  Extract code for fast mapping of pte from pmap_extract_and_hold()
  into the helper function pmap_pte_ufast().
  
  Benchmarked by:   bde
  Tested by:pho
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/pmap.c

Modified: head/sys/i386/i386/pmap.c
==
--- head/sys/i386/i386/pmap.c   Wed May 30 20:39:22 2018(r334399)
+++ head/sys/i386/i386/pmap.c   Wed May 30 20:43:48 2018(r334400)
@@ -1598,6 +1598,26 @@ pmap_pte_quick3(pmap_t pmap, vm_offset_t va)
return (0);
 }
 
+static pt_entry_t
+pmap_pte_ufast(pmap_t pmap, vm_offset_t va, pd_entry_t pde)
+{
+   pt_entry_t *eh_ptep, pte, *ptep;
+
+   PMAP_LOCK_ASSERT(pmap, MA_OWNED);
+   pde &= PG_FRAME;
+   critical_enter();
+   eh_ptep = (pt_entry_t *)PCPU_GET(pmap_eh_ptep);
+   if ((*eh_ptep & PG_FRAME) != pde) {
+   *eh_ptep = pde | PG_RW | PG_V | PG_A | PG_M;
+   invlcaddr((void *)PCPU_GET(pmap_eh_va));
+   }
+   ptep = (pt_entry_t *)PCPU_GET(pmap_eh_va) + (i386_btop(va) &
+   (NPTEPG - 1));
+   pte = *ptep;
+   critical_exit();
+   return (pte);
+}
+
 /*
  * Routine:pmap_extract
  * Function:
@@ -1637,8 +1657,8 @@ pmap_extract(pmap_t pmap, vm_offset_t va)
 vm_page_t
 pmap_extract_and_hold(pmap_t pmap, vm_offset_t va, vm_prot_t prot)
 {
-   pd_entry_t pde, newpf;
-   pt_entry_t *eh_ptep, pte, *ptep;
+   pd_entry_t pde;
+   pt_entry_t pte;
vm_page_t m;
vm_paddr_t pa;
 
@@ -1658,17 +1678,7 @@ retry:
vm_page_hold(m);
}
} else {
-   newpf = pde & PG_FRAME;
-   critical_enter();
-   eh_ptep = (pt_entry_t *)PCPU_GET(pmap_eh_ptep);
-   if ((*eh_ptep & PG_FRAME) != newpf) {
-   *eh_ptep = newpf | PG_RW | PG_V | PG_A | PG_M;
-   invlcaddr((void *)PCPU_GET(pmap_eh_va));
-   }
-   ptep = (pt_entry_t *)PCPU_GET(pmap_eh_va) +
-   (i386_btop(va) & (NPTEPG - 1));
-   pte = *ptep;
-   critical_exit();
+   pte = pmap_pte_ufast(pmap, va, pde);
if (pte != 0 &&
((pte & PG_RW) || (prot & VM_PROT_WRITE) == 0)) {
if (vm_page_pa_tryrelock(pmap, pte & PG_FRAME,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334401 - head/sys/i386/i386

2018-05-30 Thread Konstantin Belousov
Author: kib
Date: Wed May 30 20:47:20 2018
New Revision: 334401
URL: https://svnweb.freebsd.org/changeset/base/334401

Log:
  Use pmap_pte_ufast() instead of pmap_pte() in pmap_extract(),
  pmap_is_prefaultable() and pmap_incore(), pushing the number of
  shootdown IPIs back to the 3/1 kernel.
  
  Benchmarked by:   bde
  Tested by:pho
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/pmap.c

Modified: head/sys/i386/i386/pmap.c
==
--- head/sys/i386/i386/pmap.c   Wed May 30 20:43:48 2018(r334400)
+++ head/sys/i386/i386/pmap.c   Wed May 30 20:47:20 2018(r334401)
@@ -1628,7 +1628,7 @@ vm_paddr_t 
 pmap_extract(pmap_t pmap, vm_offset_t va)
 {
vm_paddr_t rtval;
-   pt_entry_t *pte;
+   pt_entry_t pte;
pd_entry_t pde;
 
rtval = 0;
@@ -1638,9 +1638,8 @@ pmap_extract(pmap_t pmap, vm_offset_t va)
if ((pde & PG_PS) != 0)
rtval = (pde & PG_PS_FRAME) | (va & PDRMASK);
else {
-   pte = pmap_pte(pmap, va);
-   rtval = (*pte & PG_FRAME) | (va & PAGE_MASK);
-   pmap_pte_release(pte);
+   pte = pmap_pte_ufast(pmap, va, pde);
+   rtval = (pte & PG_FRAME) | (va & PAGE_MASK);
}
}
PMAP_UNLOCK(pmap);
@@ -4787,19 +4786,14 @@ pmap_is_modified_pvh(struct md_page *pvh)
 boolean_t
 pmap_is_prefaultable(pmap_t pmap, vm_offset_t addr)
 {
-   pd_entry_t *pde;
-   pt_entry_t *pte;
+   pd_entry_t pde;
boolean_t rv;
 
rv = FALSE;
PMAP_LOCK(pmap);
-   pde = pmap_pde(pmap, addr);
-   if (*pde != 0 && (*pde & PG_PS) == 0) {
-   pte = pmap_pte(pmap, addr);
-   if (pte != NULL)
-   rv = *pte == 0;
-   pmap_pte_release(pte);
-   }
+   pde = *pmap_pde(pmap, addr);
+   if (pde != 0 && (pde & PG_PS) == 0)
+   rv = pmap_pte_ufast(pmap, addr, pde) == 0;
PMAP_UNLOCK(pmap);
return (rv);
 }
@@ -5584,25 +5578,23 @@ pmap_change_attr(vm_offset_t va, vm_size_t size, int m
 int
 pmap_mincore(pmap_t pmap, vm_offset_t addr, vm_paddr_t *locked_pa)
 {
-   pd_entry_t *pdep;
-   pt_entry_t *ptep, pte;
+   pd_entry_t pde;
+   pt_entry_t pte;
vm_paddr_t pa;
int val;
 
PMAP_LOCK(pmap);
 retry:
-   pdep = pmap_pde(pmap, addr);
-   if (*pdep != 0) {
-   if (*pdep & PG_PS) {
-   pte = *pdep;
+   pde = *pmap_pde(pmap, addr);
+   if (pde != 0) {
+   if ((pde & PG_PS) != 0) {
+   pte = pde;
/* Compute the physical address of the 4KB page. */
-   pa = ((*pdep & PG_PS_FRAME) | (addr & PDRMASK)) &
+   pa = ((pde & PG_PS_FRAME) | (addr & PDRMASK)) &
PG_FRAME;
val = MINCORE_SUPER;
} else {
-   ptep = pmap_pte(pmap, addr);
-   pte = *ptep;
-   pmap_pte_release(ptep);
+   pte = pmap_pte_ufast(pmap, addr, pde);
pa = pte & PG_FRAME;
val = 0;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334507 - head/sys/vm

2018-06-01 Thread Konstantin Belousov
Author: kib
Date: Fri Jun  1 23:50:51 2018
New Revision: 334507
URL: https://svnweb.freebsd.org/changeset/base/334507

Log:
  Only check for MAP_32BIT when available.
  
  Reported by:  mmacy
  Sponsored by: The FreeBSD Foundation
  MFC after:10 days

Modified:
  head/sys/vm/vm_mmap.c

Modified: head/sys/vm/vm_mmap.c
==
--- head/sys/vm/vm_mmap.c   Fri Jun  1 23:49:32 2018(r334506)
+++ head/sys/vm/vm_mmap.c   Fri Jun  1 23:50:51 2018(r334507)
@@ -242,7 +242,10 @@ kern_mmap(struct thread *td, uintptr_t addr0, size_t s
return (EINVAL);
if ((flags & MAP_GUARD) != 0 && (prot != PROT_NONE || fd != -1 ||
pos != 0 || (flags & ~(MAP_FIXED | MAP_GUARD | MAP_EXCL |
-   MAP_32BIT | MAP_ALIGNMENT_MASK)) != 0))
+#ifdef MAP_32BIT
+   MAP_32BIT |
+#endif
+   MAP_ALIGNMENT_MASK)) != 0))
return (EINVAL);
 
/*
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334515 - head/usr.bin/top

2018-06-02 Thread Konstantin Belousov
On Sat, Jun 02, 2018 at 03:31:14AM +, Eitan Adler wrote:
> Author: eadler
> Date: Sat Jun  2 03:31:14 2018
> New Revision: 334515
> URL: https://svnweb.freebsd.org/changeset/base/334515
> 
> Log:
>   top(1): avoid casting malloc
> 
> Modified:
>   head/usr.bin/top/display.c
>   head/usr.bin/top/machine.c
> 
> Modified: head/usr.bin/top/display.c
> ==
> --- head/usr.bin/top/display.cSat Jun  2 03:25:15 2018
> (r334514)
> +++ head/usr.bin/top/display.cSat Jun  2 03:31:14 2018
> (r334515)
> @@ -147,7 +147,7 @@ display_resize(void)
>  }
>  
>  /* now, allocate space for the screen buffer */
> -screenbuf = (char *)malloc(lines * display_width);
> +screenbuf = malloc(lines * display_width);
>  if (screenbuf == (char *)NULL)
>  {
>   /* oops! */
> @@ -203,20 +203,20 @@ int display_init(struct statics * statics)
>   /* save pointers and allocate space for names */
>   procstate_names = statics->procstate_names;
>   num_procstates = string_count(procstate_names);
> - lprocstates = (int *)malloc(num_procstates * sizeof(int));
> + lprocstates = malloc(num_procstates * sizeof(int));
It seems that this and other changed mallocs() better be spelled as
calloc(3).

>  
>   cpustate_names = statics->cpustate_names;
>  
>   swap_names = statics->swap_names;
>   num_swap = string_count(swap_names);
> - lswap = (int *)malloc(num_swap * sizeof(int));
> + lswap = malloc(num_swap * sizeof(int));
>   num_cpustates = string_count(cpustate_names);
> - lcpustates = (int *)malloc(num_cpustates * sizeof(int) * 
> statics->ncpus);
> - cpustate_columns = (int *)malloc(num_cpustates * sizeof(int));
> + lcpustates = malloc(num_cpustates * sizeof(int) * statics->ncpus);
> + cpustate_columns = malloc(num_cpustates * sizeof(int));
>  
>   memory_names = statics->memory_names;
>   num_memory = string_count(memory_names);
> - lmemory = (int *)malloc(num_memory * sizeof(int));
> + lmemory = malloc(num_memory * sizeof(int));
>  
>   arc_names = statics->arc_names;
>   carc_names = statics->carc_names;
> 
> Modified: head/usr.bin/top/machine.c
> ==
> --- head/usr.bin/top/machine.cSat Jun  2 03:25:15 2018
> (r334514)
> +++ head/usr.bin/top/machine.cSat Jun  2 03:31:14 2018
> (r334515)
> @@ -990,7 +990,7 @@ format_next_process(caddr_t xhandle, char *(*get_useri
>   break;
>   }
>  
> - cmdbuf = (char *)malloc(cmdlen + 1);
> + cmdbuf = malloc(cmdlen + 1);
>   if (cmdbuf == NULL) {
>   warn("malloc(%d)", cmdlen + 1);
>   return NULL;
> @@ -1025,7 +1025,7 @@ format_next_process(caddr_t xhandle, char *(*get_useri
>   size_t len;
>  
>   argbuflen = cmdlen * 4;
> - argbuf = (char *)malloc(argbuflen + 1);
> + argbuf = malloc(argbuflen + 1);
>   if (argbuf == NULL) {
>   warn("malloc(%zu)", argbuflen + 1);
>   free(cmdbuf);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334595 - in head: sys/dev/hwpmc sys/kern sys/sys usr.sbin/pmcstat

2018-06-04 Thread Konstantin Belousov
On Mon, Jun 04, 2018 at 01:10:23AM +, Matt Macy wrote:
> @@ -2214,6 +2236,11 @@ pmc_hook_handler(struct thread *td, int function, void
>  
>   pmc_capture_user_callchain(PCPU_GET(cpuid), PMC_HR,
>   (struct trapframe *) arg);
> +
> + KASSERT(td->td_pinned == 1,
> + ("[pmc,%d] invalid td_pinned value", __LINE__));
> + sched_unpin();  /* Can migrate safely now. */
sched_pin() is called from pmc_post_callchain_callback(), which is
called from userret(). userret() is executed with interrupts and
preemption enabled, so there is a non-trivial chance that the thread
already migrated.

In fact, I do not see a need to disable migration for the thread if user
callchain is planned to be gathered. You only need to remember the cpu
where the interrupt occured, to match it against the request.  Or are
per-cpu PMC registers still accessed during callchain collection ?

> +int
> +pmc_process_interrupt(int cpu, int ring, struct pmc *pm, struct trapframe 
> *tf,
> +int inuserspace)
> +{
> + struct thread *td;
> +
> + td = curthread;
> + if ((pm->pm_flags & PMC_F_USERCALLCHAIN) &&
> + td && td->td_proc &&
> + (td->td_proc->p_flag & P_KPROC) == 0 &&
> + !inuserspace) {
I am curious why a lot of the pmc code checks for curthread != NULL and,
like this fragment, for curproc != NULL.  I am sure that at least on x86,
we never let curthread point to the garbage, even during the context
switches.  NMI handler has the same cargo-cult check, BTW.

Also, please fix the indentation of the conditions block.

> + atomic_add_int(&curthread->td_pmcpend, 1);
You can use atomic_store_int() there, I believe,  Then there would be
no locked op executed at all, on x86.

> @@ -375,6 +375,7 @@ struct thread {
>   void*td_lkpi_task;  /* LinuxKPI task struct pointer */
>   TAILQ_ENTRY(thread) td_epochq;  /* (t) Epoch queue. */
>   epoch_section_t td_epoch_section; /* (t) epoch section object */
> + int td_pmcpend;
Why this member was not put into the zeroed region ?  Wouldn't a garbage
there cause uneccessary ASTs ?

___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334595 - in head: sys/dev/hwpmc sys/kern sys/sys usr.sbin/pmcstat

2018-06-04 Thread Konstantin Belousov
On Mon, Jun 04, 2018 at 03:08:15PM +0300, Konstantin Belousov wrote:
> On Mon, Jun 04, 2018 at 01:10:23AM +, Matt Macy wrote:
> > @@ -2214,6 +2236,11 @@ pmc_hook_handler(struct thread *td, int function, 
> > void
> >  
> > pmc_capture_user_callchain(PCPU_GET(cpuid), PMC_HR,
> > (struct trapframe *) arg);
> > +
> > +   KASSERT(td->td_pinned == 1,
> > +   ("[pmc,%d] invalid td_pinned value", __LINE__));
> > +   sched_unpin();  /* Can migrate safely now. */
> sched_pin() is called from pmc_post_callchain_callback(), which is
> called from userret(). userret() is executed with interrupts and
> preemption enabled, so there is a non-trivial chance that the thread
> already migrated.
> 
> In fact, I do not see a need to disable migration for the thread if user
> callchain is planned to be gathered. You only need to remember the cpu
> where the interrupt occured, to match it against the request.  Or are
> per-cpu PMC registers still accessed during callchain collection ?

And more, it is safe to access userspace from userret() so you can
walk usermode stack in the pmc callback directly, without scheduling
an ast.

> 
> > +int
> > +pmc_process_interrupt(int cpu, int ring, struct pmc *pm, struct trapframe 
> > *tf,
> > +int inuserspace)
> > +{
> > +   struct thread *td;
> > +
> > +   td = curthread;
> > +   if ((pm->pm_flags & PMC_F_USERCALLCHAIN) &&
> > +   td && td->td_proc &&
> > +   (td->td_proc->p_flag & P_KPROC) == 0 &&
> > +   !inuserspace) {
> I am curious why a lot of the pmc code checks for curthread != NULL and,
> like this fragment, for curproc != NULL.  I am sure that at least on x86,
> we never let curthread point to the garbage, even during the context
> switches.  NMI handler has the same cargo-cult check, BTW.
> 
> Also, please fix the indentation of the conditions block.
> 
> > +   atomic_add_int(&curthread->td_pmcpend, 1);
> You can use atomic_store_int() there, I believe,  Then there would be
> no locked op executed at all, on x86.
> 
> > @@ -375,6 +375,7 @@ struct thread {
> > void*td_lkpi_task;  /* LinuxKPI task struct pointer */
> > TAILQ_ENTRY(thread) td_epochq;  /* (t) Epoch queue. */
> > epoch_section_t td_epoch_section; /* (t) epoch section object */
> > +   int td_pmcpend;
> Why this member was not put into the zeroed region ?  Wouldn't a garbage
> there cause uneccessary ASTs ?
> 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334595 - in head: sys/dev/hwpmc sys/kern sys/sys usr.sbin/pmcstat

2018-06-05 Thread Konstantin Belousov
On Mon, Jun 04, 2018 at 10:27:21AM -0700, Matthew Macy wrote:
> On Mon, Jun 4, 2018 at 5:08 AM, Konstantin Belousov  
> wrote:
> > On Mon, Jun 04, 2018 at 01:10:23AM +, Matt Macy wrote:
> >> @@ -2214,6 +2236,11 @@ pmc_hook_handler(struct thread *td, int function, 
> >> void
> >>
> >>   pmc_capture_user_callchain(PCPU_GET(cpuid), PMC_HR,
> >>   (struct trapframe *) arg);
> >> +
> >> + KASSERT(td->td_pinned == 1,
> >> + ("[pmc,%d] invalid td_pinned value", __LINE__));
> >> + sched_unpin();  /* Can migrate safely now. */
> > sched_pin() is called from pmc_post_callchain_callback(), which is
> > called from userret(). userret() is executed with interrupts and
> > preemption enabled, so there is a non-trivial chance that the thread
> > already migrated.
> >
> > In fact, I do not see a need to disable migration for the thread if user
> > callchain is planned to be gathered. You only need to remember the cpu
> > where the interrupt occured, to match it against the request.  Or are
> > per-cpu PMC registers still accessed during callchain collection ?
> 
> The buffers are pcpu. Although it would in principle be safe in this
> case since I
> don't modify the read/write indices. However, I'd have to add another field 
> for
> the CPU and it doesn't handle the case of multiple migrations.
> 
You already moved the collection to userret(), thanks. So the only
reason to sched_pin() in pmc_process_thread_userret() is to make
pmc_capture_user_callchain() to operate on the stable cpu ?

May be, add a comment there, and move the assert that td_pinned > 0, into
pmc_capture_user_callchain() ?

> >
> >> +int
> >> +pmc_process_interrupt(int cpu, int ring, struct pmc *pm, struct trapframe 
> >> *tf,
> >> +int inuserspace)
> >> +{
> >> + struct thread *td;
> >> +
> >> + td = curthread;
> >> + if ((pm->pm_flags & PMC_F_USERCALLCHAIN) &&
> >> + td && td->td_proc &&
> >> + (td->td_proc->p_flag & P_KPROC) == 0 &&
> >> + !inuserspace) {
> > I am curious why a lot of the pmc code checks for curthread != NULL and,
> > like this fragment, for curproc != NULL.  I am sure that at least on x86,
> > we never let curthread point to the garbage, even during the context
> > switches.  NMI handler has the same cargo-cult check, BTW.
> 
> I didn't think they could be NULL, but have been cargo culting the
> existing code.
You already cleaned this, thanks.

> 
> > Also, please fix the indentation of the conditions block.
> 
> 
> >
> >> + atomic_add_int(&curthread->td_pmcpend, 1);
> > You can use atomic_store_int() there, I believe,  Then there would be
> > no locked op executed at all, on x86.
> 
> Storing a 1 would enable me to early terminate the loop.
> 
> >
> >> @@ -375,6 +375,7 @@ struct thread {
> >>   void*td_lkpi_task;  /* LinuxKPI task struct pointer */
> >>   TAILQ_ENTRY(thread) td_epochq;  /* (t) Epoch queue. */
> >>   epoch_section_t td_epoch_section; /* (t) epoch section object */
> >> + int td_pmcpend;
> > Why this member was not put into the zeroed region ?  Wouldn't a garbage
> > there cause uneccessary ASTs ?
> 
> It would cause _1_ unnecessary check for callchains after initial
> creation. Putting it in the zero area would break the ABI.
We do not care about KBI stability on HEAD.  If you care about it more than
usual, you can bump __FreeBSD_version to prevent older modules from load,
when struct thread layout changed.

Practically we change KBI as needed without special measures.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334617 - in head: . etc

2018-06-05 Thread Konstantin Belousov
On Tue, Jun 05, 2018 at 09:24:02AM -0600, Brad Davis wrote:
> On Tue, Jun 5, 2018, at 7:00 AM, Alexander Leidinger wrote:
> > 
> > Quoting Brad Davis  (from Mon, 04 Jun 2018 12:55:50 
> > -0600):
> > 
> > > On Mon, Jun 4, 2018, at 12:47 PM, Rodney W. Grimes wrote:
> > >> [ Charset UTF-8 unsupported, converting... ]
> > >> > On Mon, Jun 4, 2018, at 10:57 AM, Rodney W. Grimes wrote:
> > >> > > > On Mon, Jun 4, 2018, at 9:29 AM, Rodney W. Grimes wrote:
> > 
> > >> > > > > I believe there are also other external consumers of this.
> > >> > > >
> > >> > > > Such as?
> > >> > >
> > >> > > Iirc some of the make release stuff calls into here, but that
> > >> > > may of changed to use src/Makefile targets.  distrib-dirs comes
> > >> > > to mind.
> > >> >
> > >> > Sure, but those can go away or be updated as needed..
> > >>
> > >> So again, no plan yet?
> > >
> > > Most of them are gone, I am still in progress on some of it.  See  
> > > the github branch above.
> > >
> > > My testing is all done by building release VMs and comparing them  
> > > against a VM built from the last merge from HEAD.  So I will update  
> > > the release stuff as I go.  It is my responsibility to keep the  
> > > release stuff working as I change these.
> > 
> > Have you checked mergemaster? IIRC it uses the distribution target.
> 
> Yup, this does not affect the distribution target.

I find it often very useful to do
(cd src/etc/rc.d && make install)
Same for defaults and several other directories which in fact contains
non-editable content.  Is this planned to keep working ?
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334617 - in head: . etc

2018-06-05 Thread Konstantin Belousov
On Tue, Jun 05, 2018 at 12:13:05PM -0600, Brad Davis wrote:
> On Tue, Jun 5, 2018, at 10:46 AM, Konstantin Belousov wrote:
> > I find it often very useful to do
> > (cd src/etc/rc.d && make install)
> > Same for defaults and several other directories which in fact contains
> > non-editable content.  Is this planned to keep working ?
> 
> The short answer is, no.  All rc.d scripts get moved to the src of the 
> program they start.
> 
> That said, if there is a big need for this, we can see about options to keep 
> them working.
> 
> What are you trying to accomplish when you do this?  Just verify the rc.d 
> scripts match your src tree?

I avoid mergemaster/etcupdate and whatever else. rc.d and /etc/rc,
/etc/rc.subr /etc/rc.network are not suitable to etc, they are binaries
provided by the project not for the user editing.

When upgrading the host, esp. on HEAD, i usually refresh scripts by this
procedure and avoid any editing and implied conflict resolution for real
configs.

Not being able to easily install clean copies of these scripts would
be very inconvenient and time consuming.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334617 - in head: . etc

2018-06-05 Thread Konstantin Belousov
On Wed, Jun 06, 2018 at 01:39:00AM +0700, Eugene Grosbein wrote:
> 06.06.2018 1:26, Konstantin Belousov wrote:
> 
> >>> I find it often very useful to do
> >>>   (cd src/etc/rc.d && make install)
> >>> Same for defaults and several other directories which in fact contains
> >>> non-editable content.  Is this planned to keep working ?
> >>
> >> The short answer is, no.  All rc.d scripts get moved to the src of the 
> >> program they start.
> >>
> >> That said, if there is a big need for this, we can see about options to 
> >> keep them working.
> >>
> >> What are you trying to accomplish when you do this?  Just verify the rc.d 
> >> scripts match your src tree?
> > 
> > I avoid mergemaster/etcupdate and whatever else. rc.d and /etc/rc,
> > /etc/rc.subr /etc/rc.network are not suitable to etc, they are binaries
> > provided by the project not for the user editing.
> > 
> > When upgrading the host, esp. on HEAD, i usually refresh scripts by this
> > procedure and avoid any editing and implied conflict resolution for real
> > configs.
> > 
> > Not being able to easily install clean copies of these scripts would
> > be very inconvenient and time consuming.
> 
> I found that "mergemaster -iFUP" deals with unchanged files including 
> mentioned rc* scripts just fine.
> That is, it automatically refreshes unchanged files without any silly 
> questions just for change of $FreeBSD$.

No, you missed the point.  Whatever nice is the handling of unchanged files,
use of mergemaster forces me to handle changed files, which is exactly
what I do not want/need to do.  Yes, I update crashboxes very often, and
I want to get all new code, including the startup scripts, when I update.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334708 - head/sys/kern

2018-06-06 Thread Konstantin Belousov
On Wed, Jun 06, 2018 at 12:57:12PM +, Justin Hibbits wrote:
> Author: jhibbits
> Date: Wed Jun  6 12:57:11 2018
> New Revision: 334708
> URL: https://svnweb.freebsd.org/changeset/base/334708
> 
> Log:
>   Add a memory barrier after taking a reference on the vnode holdcnt in _vhold
>   
>   This is needed to avoid a race between the VNASSERT() below, and another
>   thread updating the VI_FREE flag, on weakly-ordered architectures.
>   
>   On a 72-thread POWER9, without this barrier a 'make -j72 buildworld' would
>   panic on the assert regularly.
>   
>   It may be possible to use a weaker barrier, and I'll investigate that once
>   all stability issues are worked out on POWER9.
> 
> Modified:
>   head/sys/kern/vfs_subr.c
> 
> Modified: head/sys/kern/vfs_subr.c
> ==
> --- head/sys/kern/vfs_subr.c  Wed Jun  6 10:46:24 2018(r334707)
> +++ head/sys/kern/vfs_subr.c  Wed Jun  6 12:57:11 2018(r334708)
> @@ -2807,6 +2807,9 @@ _vhold(struct vnode *vp, bool locked)
>   CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
>   if (!locked) {
>   if (refcount_acquire_if_not_zero(&vp->v_holdcnt)) {
> +#if !defined(__amd64__) && !defined(__i386__)
> + mb();
> +#endif
>   VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
>   ("_vhold: vnode with holdcnt is free"));
>   return;
First, mb() must not be used in the FreeBSD code at all.
Look at atomic_thread_fenceXXX(9) KPI.

Second, you need the reciprocal fence between clearing of VI_FREE and
refcount_acquire(), otherwise the added barrier is nop.  Most likely,
you got away with it because there is a mutex unlock between clearing
of VI_FREE and acquire, which release semantic you abused.

Does the fence needed for the non-invariants case ? 

Fourth, doesn't v_usecount has the same issues WRT inactivation ?

___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334617 - in head: . etc

2018-06-06 Thread Konstantin Belousov
On Wed, Jun 06, 2018 at 02:06:48PM -0600, Ian Lepore wrote:
> On Wed, 2018-06-06 at 11:33 -0700, Rodney W. Grimes wrote:
> > > 
> > > 
> > > On Tue, Jun 5, 2018, at 1:28 PM, Konstantin Belousov wrote:
> > > > 
> > > > On Wed, Jun 06, 2018 at 01:39:00AM +0700, Eugene Grosbein wrote:
> > > > > 
> > > > > 06.06.2018 1:26, Konstantin Belousov wrote:
> > > > > 
> > > > > > 
> > > > > > > 
> > > > > > > > 
> > > > > > > > I find it often very useful to do
> > > > > > > >  (cd src/etc/rc.d && make install)
> > > > > > > > Same for defaults and several other directories which in
> > > > > > > > fact
> > > > > > > > contains> > >>> non-editable content.  Is this planned to
> > > > > > > > keep working ?
> > > > > > > The short answer is, no.  All rc.d scripts get moved to the
> > > > > > > src
> > > > > > > of the program they start.> > >>
> > > > > > > That said, if there is a big need for this, we can see
> > > > > > > about
> > > > > > > options to keep them working.> > >>
> > > > > > > What are you trying to accomplish when you do this?  Just
> > > > > > > verify
> > > > > > > the rc.d scripts match your src tree?> > >
> > > > > > I avoid mergemaster/etcupdate and whatever else. rc.d and
> > > > > > /etc/rc,> > > /etc/rc.subr /etc/rc.network are not suitable
> > > > > > to etc, they are
> > > > > > binaries> > > provided by the project not for the user
> > > > > > editing.
> > > > > > 
> > > > > > When upgrading the host, esp. on HEAD, i usually refresh
> > > > > > scripts
> > > > > > by this> > > procedure and avoid any editing and implied
> > > > > > conflict resolution
> > > > > > for real> > > configs.
> > > > > > 
> > > > > > Not being able to easily install clean copies of these
> > > > > > scripts
> > > > > > would> > > be very inconvenient and time consuming.
> > > > > I found that "mergemaster -iFUP" deals with unchanged files
> > > > > including mentioned rc* scripts just fine.> > That is, it
> > > > > automatically refreshes unchanged files without any
> > > > > silly questions just for change of $FreeBSD$.>
> > > > No, you missed the point.  Whatever nice is the handling of
> > > > unchanged files,> use of mergemaster forces me to handle changed
> > > > files, which is exactly> what I do not want/need to do.  Yes, I
> > > > update crashboxes very
> > > > often, and> I want to get all new code, including the startup
> > > > scripts, when
> > > > I update.
> > > The startup scripts will be installed as part of installworld.
> > So each installworld would wipe over the top of any localmod
> > /etc/rc.d/ and other stuff
> > that mght exist?
> > One of the reasons that etc/Makefile is detached from Installword is
> > so that
> > /etc does not get perturbuted unless specifically requested.
> > 
> 
> I don't understand the drama over this.  rc.d startup scripts are
> *binaries*. Users are not expected to modify the system installed
> binaries, and if they do, it is expected that the next installworld
> will replace them with the system binaries again.

I agree with this, but the scripts are installed into /etc.

I proposed to move them somewhere, e.g. to /sbin/rc* or to /libexec/rc*.
If moved first, then the proposed change would be much more logical and
probably easier to fit into the workflows of FreeBSD consumers.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334799 - head/sys/amd64/amd64

2018-06-07 Thread Konstantin Belousov
Author: kib
Date: Thu Jun  7 17:04:34 2018
New Revision: 334799
URL: https://svnweb.freebsd.org/changeset/base/334799

Log:
  Account for dmap limit when selecting the pages for the bootstrap
  pagetables.
  
  physmap[] can be inconsistent with the physical memory limit due to
  buggy bios, or to the hw.physmem tunable. Since bootstrap pagetables
  are initialized by accesses through the DMAP, we must ensure that DMAP
  really cover the selected pages. This is only relevant when machine
  has less than 4G RAM and buggy BIOS, which is the combination on Acer
  Chromebook 720.
  
  The call to mp_bootaddress() is moved later to have Maxmem initialized.
  
  An alternative could be to always cover 4G for DMAP, but this change
  seems to be simpler.
  
  Reported and tested by:   grembo
  Reviewed by:  royger
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D15675

Modified:
  head/sys/amd64/amd64/machdep.c
  head/sys/amd64/amd64/mp_machdep.c

Modified: head/sys/amd64/amd64/machdep.c
==
--- head/sys/amd64/amd64/machdep.c  Thu Jun  7 16:35:09 2018
(r334798)
+++ head/sys/amd64/amd64/machdep.c  Thu Jun  7 17:04:34 2018
(r334799)
@@ -1248,15 +1248,6 @@ getmemsize(caddr_t kmdp, u_int64_t first)
}
 
/*
-* Make hole for "AP -> long mode" bootstrap code.  The
-* mp_bootaddress vector is only available when the kernel
-* is configured to support APs and APs for the system start
-* in real mode mode (e.g. SMP bare metal).
-*/
-   if (init_ops.mp_bootaddress)
-   init_ops.mp_bootaddress(physmap, &physmap_idx);
-
-   /*
 * Maxmem isn't the "maximum memory", it's one larger than the
 * highest page of the physical address space.  It should be
 * called something like "Maxphyspage".  We may adjust this
@@ -1293,6 +1284,15 @@ getmemsize(caddr_t kmdp, u_int64_t first)
if (atop(physmap[physmap_idx + 1]) != Maxmem &&
(boothowto & RB_VERBOSE))
printf("Physical memory use set to %ldK\n", Maxmem * 4);
+
+   /*
+* Make hole for "AP -> long mode" bootstrap code.  The
+* mp_bootaddress vector is only available when the kernel
+* is configured to support APs and APs for the system start
+* in real mode mode (e.g. SMP bare metal).
+*/
+   if (init_ops.mp_bootaddress)
+   init_ops.mp_bootaddress(physmap, &physmap_idx);
 
/* call pmap initialization to make new kernel address space */
pmap_bootstrap(&first);

Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Thu Jun  7 16:35:09 2018
(r334798)
+++ head/sys/amd64/amd64/mp_machdep.c   Thu Jun  7 17:04:34 2018
(r334799)
@@ -113,12 +113,16 @@ mp_bootaddress(vm_paddr_t *physmap, unsigned int *phys
allocated = false;
for (i = *physmap_idx; i <= *physmap_idx; i -= 2) {
/*
-* Find a memory region big enough below the 4GB boundary to
-* store the initial page tables. Note that it needs to be
-* aligned to a page boundary.
+* Find a memory region big enough below the 4GB
+* boundary to store the initial page tables.  Region
+* must be mapped by the direct map.
+*
+* Note that it needs to be aligned to a page
+* boundary.
 */
-   if (physmap[i] >= GiB(4) ||
-   (physmap[i + 1] - round_page(physmap[i])) < (PAGE_SIZE * 3))
+   if (physmap[i] >= GiB(4) || physmap[i + 1] -
+   round_page(physmap[i]) < PAGE_SIZE * 3 ||
+   physmap[i + 1] > Maxmem)
continue;
 
allocated = true;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334708 - head/sys/kern

2018-06-07 Thread Konstantin Belousov
On Fri, Jun 08, 2018 at 07:03:04AM +0200, Mateusz Guzik wrote:
> Part of the problem is lack of primitives like READ_ONCE/WRITE_ONCE as
> seen in the linux kernel, someone should hack up equivalents.
Only replying to this statement right now.  What is the semantic of
the _ONCE operations ?  Isn't it the same as atomic_load/store (without
fences) ?
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334708 - head/sys/kern

2018-06-08 Thread Konstantin Belousov
On Thu, Jun 07, 2018 at 11:02:29PM -0700, Ryan Libby wrote:
> On Thu, Jun 7, 2018 at 10:03 PM, Mateusz Guzik  wrote:
> > On Fri, Jun 8, 2018 at 6:29 AM, Ryan Libby  wrote:
> >>
> >> On Thu, Jun 7, 2018 at 8:32 PM, Mark Johnston  wrote:
> >> > On Wed, Jun 06, 2018 at 05:03:11PM +0300, Konstantin Belousov wrote:
> >> >> On Wed, Jun 06, 2018 at 12:57:12PM +, Justin Hibbits wrote:
> >> >> > Author: jhibbits
> >> >> > Date: Wed Jun  6 12:57:11 2018
> >> >> > New Revision: 334708
> >> >> > URL: https://svnweb.freebsd.org/changeset/base/334708
> >> >> >
> >> >> > Log:
> >> >> >   Add a memory barrier after taking a reference on the vnode holdcnt
> >> >> > in _vhold
> >> >> >
> >> >> >   This is needed to avoid a race between the VNASSERT() below, and
> >> >> > another
> >> >> >   thread updating the VI_FREE flag, on weakly-ordered architectures.
> >> >> >
> >> >> >   On a 72-thread POWER9, without this barrier a 'make -j72
> >> >> > buildworld' would
> >> >> >   panic on the assert regularly.
> >> >> >
> >> >> >   It may be possible to use a weaker barrier, and I'll investigate
> >> >> > that once
> >> >> >   all stability issues are worked out on POWER9.
> >> >> >
> >> >> > Modified:
> >> >> >   head/sys/kern/vfs_subr.c
> >> >> >
> >> >> > Modified: head/sys/kern/vfs_subr.c
> >> >> >
> >> >> > ==
> >> >> > --- head/sys/kern/vfs_subr.cWed Jun  6 10:46:24 2018
> >> >> > (r334707)
> >> >> > +++ head/sys/kern/vfs_subr.cWed Jun  6 12:57:11 2018
> >> >> > (r334708)
> >> >> > @@ -2807,6 +2807,9 @@ _vhold(struct vnode *vp, bool locked)
> >> >> > CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
> >> >> > if (!locked) {
> >> >> > if (refcount_acquire_if_not_zero(&vp->v_holdcnt)) {
> >> >> > +#if !defined(__amd64__) && !defined(__i386__)
> >> >> > +   mb();
> >> >> > +#endif
> >> >> > VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
> >> >> > ("_vhold: vnode with holdcnt is free"));
> >> >> > return;
> >> >> First, mb() must not be used in the FreeBSD code at all.
> >> >> Look at atomic_thread_fenceXXX(9) KPI.
> >> >>
> >> >> Second, you need the reciprocal fence between clearing of VI_FREE and
> >> >> refcount_acquire(), otherwise the added barrier is nop.  Most likely,
> >> >> you got away with it because there is a mutex unlock between clearing
> >> >> of VI_FREE and acquire, which release semantic you abused.
> >> >
> >> > I note that vnlru_free_locked() clears VI_FREE and increments v_holdcnt
> >> > without an intervening release fence. At this point the caller has not
> >> > purged the vnode from the name cache, so it seems possible that the
> >> > panicking thread observed the two stores out of order. In particular, it
> >> > seems to me that the patch below is necessary, but possibly (probably?)
> >> > not sufficient:
> >>
> >> Mark, Justin, and I looked at this.
> >>
> >> I think that the VNASSERT itself is not quite valid, since it is
> >> checking the value of v_iflag without the vnode interlock held (and
> >> without the vop lock also).  If the rule is that we normally need the
> >> vnode interlock to check VI_FREE, then I don't think that possible
> >> reordering between the refcount_acquire and VI_FREE clearing in
> >> vnlru_free_locked is necessarily a problem in production.
> >
> >
> > Checking it without any locks is perfectly valid in this case. It is done
> > after v_holdcnt gets bumped from a non-zero value. So at that time it
> > is at least two. Of course that result is stale as an arbitrary number of
> > other threads could have bumped and dropped the ref past that point.
> > The minimum value is 1 since we hold the ref. But this means the
> > vnode must not be on 

svn commit: r334851 - head/sys/arm64/arm64

2018-06-08 Thread Konstantin Belousov
Author: kib
Date: Fri Jun  8 18:32:26 2018
New Revision: 334851
URL: https://svnweb.freebsd.org/changeset/base/334851

Log:
  Restore release semantic for the old thread unlock on arm64.
  
  With the introduction of pmap_switch(), the DSB instruction on the
  address map switch is not necessary executed, which is fixed by
  changing the unlock store to release.  Also remove comment which
  documented pre-pmap_switch() code.
  
  Reviewed by:  andrew
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/arm64/arm64/swtch.S

Modified: head/sys/arm64/arm64/swtch.S
==
--- head/sys/arm64/arm64/swtch.SFri Jun  8 18:24:46 2018
(r334850)
+++ head/sys/arm64/arm64/swtch.SFri Jun  8 18:32:26 2018
(r334851)
@@ -165,10 +165,9 @@ ENTRY(cpu_switch)
mov x0, x19
 
/*
-* Release the old thread. This doesn't need to be a store-release
-* as the above dsb instruction will provide release semantics.
+* Release the old thread.
 */
-   str x2, [x0, #TD_LOCK]
+   stlrx2, [x0, #TD_LOCK]
 #if defined(SCHED_ULE) && defined(SMP)
/* Spin if TD_LOCK points to a blocked_lock */
ldr x2, =_C_LABEL(blocked_lock)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334708 - head/sys/kern

2018-06-08 Thread Konstantin Belousov
On Fri, Jun 08, 2018 at 02:30:10PM -0400, Mark Johnston wrote:
> On Fri, Jun 08, 2018 at 08:37:55PM +0300, Konstantin Belousov wrote:
> > On Thu, Jun 07, 2018 at 11:02:29PM -0700, Ryan Libby wrote:
> > > On Thu, Jun 7, 2018 at 10:03 PM, Mateusz Guzik  wrote:
> > > > Checking it without any locks is perfectly valid in this case. It is 
> > > > done
> > > > after v_holdcnt gets bumped from a non-zero value. So at that time it
> > > > is at least two. Of course that result is stale as an arbitrary number 
> > > > of
> > > > other threads could have bumped and dropped the ref past that point.
> > > > The minimum value is 1 since we hold the ref. But this means the
> > > > vnode must not be on the free list and that's what the assertion is
> > > > verifying.
> > > >
> > > > The problem is indeed lack of ordering against the code clearing the
> > > > flag for the case where 2 threads to vhold and one does the 0->1
> > > > transition.
> > > >
> > > > That said, the fence is required for the assertion to work.
> > > >
> > > 
> > > Yeah, I agree with this logic.  What I mean is that reordering between
> > > v_holdcnt 0->1 and v_iflag is normally settled by the release and
> > > acquisition of the vnode interlock, which we are supposed to hold for
> > > v_*i*flag.  A quick scan seems to show all of the checks of VI_FREE that
> > > are not asserts do hold the vnode interlock.  So, I'm just saying that I
> > > don't think the possible reordering affects them.
> > But do we know that only VI_FREE checks are affected ?
> > 
> > My concern is that users of _vhold() rely on seeing up to date state of the
> > vnode, and VI_FREE is only an example of the problem.  Most likely, the
> > code which fetched the vnode pointer before _vhold() call, should guarantee
> > visibility.
> 
> Wouldn't this be a problem only if we permit lockless accesses of vnode
> state outside of _vhold() and other vnode subroutines? The current
> protocol requires that the interlock be held, and this synchronizes with
> code which performs 0->1 and 1->0 transitions of the hold count. If this
> requirement is relaxed in the future, then fences would indeed be
> needed.

I do not claim that my concern is a real problem. I stated it as a
thing to look at when deciding whether the fences should be added
(unconditionally ?).

If you argument is that the only current lock-less protocol for the
struct vnode state is the v_holdcnt transitions for > 1, then I can
agree with it.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334928 - head/lib/libc/stdlib

2018-06-10 Thread Konstantin Belousov
Author: kib
Date: Sun Jun 10 17:54:44 2018
New Revision: 334928
URL: https://svnweb.freebsd.org/changeset/base/334928

Log:
  libc qsort(3): stop aliasing.
  
  Qsort swap code aliases the sorted array elements to ints and longs in
  order to do swap by machine words.  Unfortunately this breaks with the
  full code optimization, e.g. LTO.
  
  See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83201 which seems to
  reference code directly copied from libc/stdlib/qsort.c.
  
  PR:   228780
  Reported by:  mli...@suse.cz
  Reviewed by:  brooks
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D15714

Modified:
  head/lib/libc/stdlib/qsort.c

Modified: head/lib/libc/stdlib/qsort.c
==
--- head/lib/libc/stdlib/qsort.cSun Jun 10 16:44:18 2018
(r334927)
+++ head/lib/libc/stdlib/qsort.cSun Jun 10 17:54:44 2018
(r334928)
@@ -43,53 +43,27 @@ typedef int  cmp_t(void *, const void *, const void 
*
 typedef int cmp_t(const void *, const void *);
 #endif
 static inline char *med3(char *, char *, char *, cmp_t *, void *);
-static inline void  swapfunc(char *, char *, size_t, int, int);
 
 #defineMIN(a, b)   ((a) < (b) ? a : b)
 
 /*
  * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
  */
-#defineswapcode(TYPE, parmi, parmj, n) {   \
-   size_t i = (n) / sizeof (TYPE); \
-   TYPE *pi = (TYPE *) (parmi);\
-   TYPE *pj = (TYPE *) (parmj);\
-   do {\
-   TYPEt = *pi;\
-   *pi++ = *pj;\
-   *pj++ = t;  \
-   } while (--i > 0);  \
-}
 
-#defineSWAPINIT(TYPE, a, es) swaptype_ ## TYPE =   \
-   ((char *)a - (char *)0) % sizeof(TYPE) ||   \
-   es % sizeof(TYPE) ? 2 : es == sizeof(TYPE) ? 0 : 1;
-
 static inline void
-swapfunc(char *a, char *b, size_t n, int swaptype_long, int swaptype_int)
+swapfunc(char *a, char *b, size_t es)
 {
-   if (swaptype_long <= 1)
-   swapcode(long, a, b, n)
-   else if (swaptype_int <= 1)
-   swapcode(int, a, b, n)
-   else
-   swapcode(char, a, b, n)
+   char t;
+
+   do {
+   t = *a;
+   *a++ = *b;
+   *b++ = t;
+   } while (--es > 0);
 }
 
-#defineswap(a, b)  \
-   if (swaptype_long == 0) {   \
-   long t = *(long *)(a);  \
-   *(long *)(a) = *(long *)(b);\
-   *(long *)(b) = t;   \
-   } else if (swaptype_int == 0) { \
-   int t = *(int *)(a);\
-   *(int *)(a) = *(int *)(b);  \
-   *(int *)(b) = t;\
-   } else  \
-   swapfunc(a, b, es, swaptype_long, swaptype_int)
-
 #definevecswap(a, b, n)\
-   if ((n) > 0) swapfunc(a, b, n, swaptype_long, swaptype_int)
+   if ((n) > 0) swapfunc(a, b, n)
 
 #ifdef I_AM_QSORT_R
 #defineCMP(t, x, y) (cmp((t), (x), (y)))
@@ -121,17 +95,16 @@ qsort(void *a, size_t n, size_t es, cmp_t *cmp)
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
size_t d1, d2;
int cmp_result;
-   int swaptype_long, swaptype_int, swap_cnt;
+   int swap_cnt;
 
-loop:  SWAPINIT(long, a, es);
-   SWAPINIT(int, a, es);
+loop:
swap_cnt = 0;
if (n < 7) {
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
for (pl = pm; 
 pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
 pl -= es)
-   swap(pl, pl - es);
+   swapfunc(pl, pl - es, es);
return;
}
pm = (char *)a + (n / 2) * es;
@@ -147,7 +120,7 @@ loop:   SWAPINIT(long, a, es);
}
pm = med3(pl, pm, pn, cmp, thunk);
}
-   swap(a, pm);
+   swapfunc(a, pm, es);
pa = pb = (char *)a + es;
 
pc = pd = (char *)a + (n - 1) * es;
@@ -155,7 +128,7 @@ loop:   SWAPINIT(long, a, es);
while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) {
if (cmp_result == 0) {
swap_cnt = 1;
-   swap(pa, pb);
+   swapfunc(pa, pb, es);
pa += es;
}
pb += es;
@@ -163,14 +136,14 @@ loop: SWA

Re: svn commit: r334928 - head/lib/libc/stdlib

2018-06-11 Thread Konstantin Belousov
On Mon, Jun 11, 2018 at 03:48:52PM +1000, Bruce Evans wrote:
> Change TYPE to unsigned char[sizeof(old TYPE)] and use memcpy() to assign
> the variables to fix this with small churn and without the pessimizations
> in this commit.  This gives portable code back to K&R1978 + memcpy(), and
> is as efficient as the above when the above works.  On x86, even gcc-3.3
> produces a load and store for memcpy(p, q, sizeof(register_t)) when p and
> q are void *.
> 
> Change TYPE to unsigned char[n] and use a single memcpy() without a loop
> to assign the variables to fix this with larger churn and with different
> (smaller?) pessimizations than in this commit.  Setup and initialization
> for this method is also simpler.  This uses the newfangled VLA feature,
> and since n is variable for qsort(), builtin memcpy() with length n
> doesn't work so well.
Either results in the unacceptable stack use.

I can limit the char[es] and memcpy to some value of es, but I do not
see a point.  I will not object if somebody decides to do it.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334952 - head/sys/amd64/amd64

2018-06-11 Thread Konstantin Belousov
Author: kib
Date: Mon Jun 11 15:28:20 2018
New Revision: 334952
URL: https://svnweb.freebsd.org/changeset/base/334952

Log:
  Fix braino in r334799.  Maxmem is in pages.
  
  Reported by:  ae, pho
  Tested by:pho
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/amd64/amd64/mp_machdep.c

Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Mon Jun 11 15:18:31 2018
(r334951)
+++ head/sys/amd64/amd64/mp_machdep.c   Mon Jun 11 15:28:20 2018
(r334952)
@@ -122,7 +122,7 @@ mp_bootaddress(vm_paddr_t *physmap, unsigned int *phys
 */
if (physmap[i] >= GiB(4) || physmap[i + 1] -
round_page(physmap[i]) < PAGE_SIZE * 3 ||
-   physmap[i + 1] > Maxmem)
+   atop(physmap[i + 1]) > Maxmem)
continue;
 
allocated = true;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334994 - head/sys/i386/i386

2018-06-12 Thread Konstantin Belousov
Author: kib
Date: Tue Jun 12 10:41:26 2018
New Revision: 334994
URL: https://svnweb.freebsd.org/changeset/base/334994

Log:
  Fix typo.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/trap.c

Modified: head/sys/i386/i386/trap.c
==
--- head/sys/i386/i386/trap.c   Tue Jun 12 08:43:49 2018(r334993)
+++ head/sys/i386/i386/trap.c   Tue Jun 12 10:41:26 2018(r334994)
@@ -218,7 +218,7 @@ trap(struct trapframe *frame)
type = frame->tf_trapno;
 
KASSERT((read_eflags() & PSL_I) == 0,
-   ("trap: interrupts enaabled, type %d frame %p", type, frame));
+   ("trap: interrupts enabled, type %d frame %p", type, frame));
 
 #ifdef SMP
/* Handler for NMI IPIs used for stopping CPUs. */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334995 - head/sys/i386/i386

2018-06-12 Thread Konstantin Belousov
Author: kib
Date: Tue Jun 12 10:43:20 2018
New Revision: 334995
URL: https://svnweb.freebsd.org/changeset/base/334995

Log:
  All exceptions IDT descriptors must use interrupt gates on 4/4 kernel.
  Fix it for #MF.
  
  Noted by: rlibby
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/machdep.c

Modified: head/sys/i386/i386/machdep.c
==
--- head/sys/i386/i386/machdep.cTue Jun 12 10:41:26 2018
(r334994)
+++ head/sys/i386/i386/machdep.cTue Jun 12 10:43:20 2018
(r334995)
@@ -2253,7 +2253,7 @@ i386_setidt1(void)
GSEL(GCODE_SEL, SEL_KPL));
setidt(IDT_PF, &IDTVEC(page), SDT_SYS386IGT, SEL_KPL,
GSEL(GCODE_SEL, SEL_KPL));
-   setidt(IDT_MF, &IDTVEC(fpu), SDT_SYS386TGT, SEL_KPL,
+   setidt(IDT_MF, &IDTVEC(fpu), SDT_SYS386IGT, SEL_KPL,
GSEL(GCODE_SEL, SEL_KPL));
setidt(IDT_AC, &IDTVEC(align), SDT_SYS386IGT, SEL_KPL,
GSEL(GCODE_SEL, SEL_KPL));
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335072 - head/sys/amd64/amd64

2018-06-13 Thread Konstantin Belousov
Author: kib
Date: Wed Jun 13 17:55:09 2018
New Revision: 335072
URL: https://svnweb.freebsd.org/changeset/base/335072

Log:
  Enable eager FPU context switch by default on amd64.
  
  With compilers making increasing use of vector instructions the
  performance benefit of lazily switching FPU state is no longer a
  desirable tradeoff.  Linux switched to eager FPU context switch some
  time ago, and the idea was floated on the FreeBSD-current mailing list
  some years ago[1].
  
  Enable eager FPU context switch by default on amd64, with a tunable/sysctl
  available to turn it back off.
  
  [1] https://lists.freebsd.org/pipermail/freebsd-current/2015-March/055198.html
  
  Reviewed by:  jhb
  Tested by:pho
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/amd64/amd64/cpu_switch.S
  head/sys/amd64/amd64/fpu.c

Modified: head/sys/amd64/amd64/cpu_switch.S
==
--- head/sys/amd64/amd64/cpu_switch.S   Wed Jun 13 17:42:55 2018
(r335071)
+++ head/sys/amd64/amd64/cpu_switch.S   Wed Jun 13 17:55:09 2018
(r335072)
@@ -128,10 +128,10 @@ done_store_dr:
 
/* have we used fp, and need a save? */
cmpq%rdi,PCPU(FPCURTHREAD)
-   jne 3f
+   jne 2f
movqPCB_SAVEFPU(%r8),%r8
clts
-   cmpl$0,use_xsave
+   cmpl$0,use_xsave(%rip)
jne 1f
fxsave  (%r8)
jmp 2f
@@ -143,12 +143,7 @@ ctx_switch_xsave:
/* This is patched to xsaveopt if supported, see fpuinit_bsp1() */
xsave   (%r8)
movq%rcx,%rdx
-2: smsw%ax
-   orb $CR0_TS,%al
-   lmsw%ax
-   xorl%eax,%eax
-   movq%rax,PCPU(FPCURTHREAD)
-3:
+2:
/* Save is done.  Now fire up new thread. Leave old vmspace. */
movq%rsi,%r12
movq%rdi,%r13
@@ -238,6 +233,8 @@ done_load_dr:
movqPCB_RBX(%r8),%rbx
movqPCB_RIP(%r8),%rax
movq%rax,(%rsp)
+   movqPCPU(CURTHREAD),%rdi
+   callfpu_activate_sw
ret
 
/*

Modified: head/sys/amd64/amd64/fpu.c
==
--- head/sys/amd64/amd64/fpu.c  Wed Jun 13 17:42:55 2018(r335071)
+++ head/sys/amd64/amd64/fpu.c  Wed Jun 13 17:55:09 2018(r335072)
@@ -142,6 +142,11 @@ static voidfpu_clean_state(void);
 SYSCTL_INT(_hw, HW_FLOATINGPT, floatingpoint, CTLFLAG_RD,
 SYSCTL_NULL_INT_PTR, 1, "Floating point instructions executed in 
hardware");
 
+int lazy_fpu_switch = 0;
+SYSCTL_INT(_hw, OID_AUTO, lazy_fpu_switch, CTLFLAG_RWTUN | CTLFLAG_NOFETCH,
+&lazy_fpu_switch, 0,
+"Lazily load FPU context after context switch");
+
 int use_xsave; /* non-static for cpu_switch.S */
 uint64_t xsave_mask;   /* the same */
 static uma_zone_t fpu_save_area_zone;
@@ -242,6 +247,7 @@ fpuinit_bsp1(void)
uint64_t xsave_mask_user;
bool old_wp;
 
+   TUNABLE_INT_FETCH("hw.lazy_fpu_switch", &lazy_fpu_switch);
if (!use_xsave)
return;
cpuid_count(0xd, 0x0, cp);
@@ -651,6 +657,45 @@ fputrap_sse(void)
return (fpetable[(mxcsr & (~mxcsr >> 7)) & 0x3f]);
 }
 
+static void
+restore_fpu_curthread(struct thread *td)
+{
+   struct pcb *pcb;
+
+   /*
+* Record new context early in case frstor causes a trap.
+*/
+   PCPU_SET(fpcurthread, td);
+
+   stop_emulating();
+   fpu_clean_state();
+   pcb = td->td_pcb;
+
+   if ((pcb->pcb_flags & PCB_FPUINITDONE) == 0) {
+   /*
+* This is the first time this thread has used the FPU or
+* the PCB doesn't contain a clean FPU state.  Explicitly
+* load an initial state.
+*
+* We prefer to restore the state from the actual save
+* area in PCB instead of directly loading from
+* fpu_initialstate, to ignite the XSAVEOPT
+* tracking engine.
+*/
+   bcopy(fpu_initialstate, pcb->pcb_save,
+   cpu_max_ext_state_size);
+   fpurestore(pcb->pcb_save);
+   if (pcb->pcb_initial_fpucw != __INITIAL_FPUCW__)
+   fldcw(pcb->pcb_initial_fpucw);
+   if (PCB_USER_FPU(pcb))
+   set_pcb_flags(pcb, PCB_FPUINITDONE |
+   PCB_USERFPUINITDONE);
+   else
+   set_pcb_flags(pcb, PCB_FPUINITDONE);
+   } else
+   fpurestore(pcb->pcb_save);
+}
+
 /*
  * Device Not Available (DNA, #NM) exception handler.
  *
@@ -661,7 +706,9 @@ fputrap_sse(void)
 void
 fpudna(void)
 {
+   struct thread *td;
 
+   td = curthread;
/*
 * This handler is entered with interrupts enabled, so context
 * switches may occur before critical_enter() is executed.  If
@@ -675,7 +72

svn commit: r335089 - head/sys/i386/i386

2018-06-13 Thread Konstantin Belousov
Author: kib
Date: Wed Jun 13 21:10:23 2018
New Revision: 335089
URL: https://svnweb.freebsd.org/changeset/base/335089

Log:
  Enable eager FPU context switch by default on i386 too, based on
  amd64 r335072.
  
  Security: CVE-2018-3665
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/i386/i386/npx.c
  head/sys/i386/i386/swtch.s

Modified: head/sys/i386/i386/npx.c
==
--- head/sys/i386/i386/npx.cWed Jun 13 20:35:56 2018(r335088)
+++ head/sys/i386/i386/npx.cWed Jun 13 21:10:23 2018(r335089)
@@ -191,6 +191,11 @@ inthw_float;
 SYSCTL_INT(_hw, HW_FLOATINGPT, floatingpoint, CTLFLAG_RD,
 &hw_float, 0, "Floating point instructions executed in hardware");
 
+int lazy_fpu_switch = 0;
+SYSCTL_INT(_hw, OID_AUTO, lazy_fpu_switch, CTLFLAG_RWTUN | CTLFLAG_NOFETCH,
+&lazy_fpu_switch, 0,
+"Lazily load FPU context after context switch");
+
 int use_xsave;
 uint64_t xsave_mask;
 static uma_zone_t fpu_save_area_zone;
@@ -319,6 +324,7 @@ npxinit_bsp1(void)
u_int cp[4];
uint64_t xsave_mask_user;
 
+   TUNABLE_INT_FETCH("hw.lazy_fpu_switch", &lazy_fpu_switch);
if (cpu_fxsr && (cpu_feature2 & CPUID2_XSAVE) != 0) {
use_xsave = 1;
TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave);
@@ -777,6 +783,42 @@ npxtrap_sse(void)
return (fpetable[(mxcsr & (~mxcsr >> 7)) & 0x3f]);
 }
 
+static void
+restore_npx_curthread(struct thread *td, struct pcb *pcb)
+{
+
+   /*
+* Record new context early in case frstor causes a trap.
+*/
+   PCPU_SET(fpcurthread, td);
+
+   stop_emulating();
+   if (cpu_fxsr)
+   fpu_clean_state();
+
+   if ((pcb->pcb_flags & PCB_NPXINITDONE) == 0) {
+   /*
+* This is the first time this thread has used the FPU or
+* the PCB doesn't contain a clean FPU state.  Explicitly
+* load an initial state.
+*
+* We prefer to restore the state from the actual save
+* area in PCB instead of directly loading from
+* npx_initialstate, to ignite the XSAVEOPT
+* tracking engine.
+*/
+   bcopy(npx_initialstate, pcb->pcb_save, cpu_max_ext_state_size);
+   fpurstor(pcb->pcb_save);
+   if (pcb->pcb_initial_npxcw != __INITIAL_NPXCW__)
+   fldcw(pcb->pcb_initial_npxcw);
+   pcb->pcb_flags |= PCB_NPXINITDONE;
+   if (PCB_USER_FPU(pcb))
+   pcb->pcb_flags |= PCB_NPXUSERINITDONE;
+   } else {
+   fpurstor(pcb->pcb_save);
+   }
+}
+
 /*
  * Implement device not available (DNA) exception
  *
@@ -790,11 +832,13 @@ static int err_count = 0;
 int
 npxdna(void)
 {
+   struct thread *td;
 
if (!hw_float)
return (0);
+   td = curthread;
critical_enter();
-   if (PCPU_GET(fpcurthread) == curthread) {
+   if (PCPU_GET(fpcurthread) == td) {
printf("npxdna: fpcurthread == curthread %d times\n",
++err_count);
stop_emulating();
@@ -805,39 +849,10 @@ npxdna(void)
printf("npxdna: fpcurthread = %p (%d), curthread = %p (%d)\n",
   PCPU_GET(fpcurthread),
   PCPU_GET(fpcurthread)->td_proc->p_pid,
-  curthread, curthread->td_proc->p_pid);
+  td, td->td_proc->p_pid);
panic("npxdna");
}
-   stop_emulating();
-   /*
-* Record new context early in case frstor causes a trap.
-*/
-   PCPU_SET(fpcurthread, curthread);
-
-   if (cpu_fxsr)
-   fpu_clean_state();
-
-   if ((curpcb->pcb_flags & PCB_NPXINITDONE) == 0) {
-   /*
-* This is the first time this thread has used the FPU or
-* the PCB doesn't contain a clean FPU state.  Explicitly
-* load an initial state.
-*
-* We prefer to restore the state from the actual save
-* area in PCB instead of directly loading from
-* npx_initialstate, to ignite the XSAVEOPT
-* tracking engine.
-*/
-   bcopy(npx_initialstate, curpcb->pcb_save, 
cpu_max_ext_state_size);
-   fpurstor(curpcb->pcb_save);
-   if (curpcb->pcb_initial_npxcw != __INITIAL_NPXCW__)
-   fldcw(curpcb->pcb_initial_npxcw);
-   curpcb->pcb_flags |= PCB_NPXINITDONE;
-   if (PCB_USER_FPU(curpcb))
-   curpcb->pcb_flags |= PCB_NPXUSERINITDONE;
-   } else {
-   fpurstor(curpcb->pcb_save);
-   }
+   restore_npx_curthread(td, td->td_pcb);
critical_exit();
 
return (1);
@@ -861,8 +876,20 @@ npxsave(addr)
 

svn commit: r335131 - in head/sys: amd64/amd64 i386/i386

2018-06-14 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 14 10:33:26 2018
New Revision: 335131
URL: https://svnweb.freebsd.org/changeset/base/335131

Log:
  Remove printf() in #NM handler.
  
  Give up and remove the almost useless informational message reporting
  that device not available exception occured while our state tracking
  indicates the current CPU has FPU context loaded for the current
  thread.
  
  It seems that this is recurring bug with some VM monitors.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/amd64/amd64/fpu.c
  head/sys/i386/i386/npx.c

Modified: head/sys/amd64/amd64/fpu.c
==
--- head/sys/amd64/amd64/fpu.c  Thu Jun 14 10:00:19 2018(r335130)
+++ head/sys/amd64/amd64/fpu.c  Thu Jun 14 10:33:26 2018(r335131)
@@ -723,7 +723,12 @@ fpudna(void)
KASSERT((curpcb->pcb_flags & PCB_FPUNOSAVE) == 0,
("fpudna while in fpu_kern_enter(FPU_KERN_NOCTX)"));
if (PCPU_GET(fpcurthread) == td) {
-   printf("fpudna: fpcurthread == curthread\n");
+   /*
+* Some virtual machines seems to set %cr0.TS at
+* arbitrary moments.  Silently clear the TS bit
+* regardless of the eager/lazy FPU context switch
+* mode.
+*/
stop_emulating();
critical_exit();
return;

Modified: head/sys/i386/i386/npx.c
==
--- head/sys/i386/i386/npx.cThu Jun 14 10:00:19 2018(r335130)
+++ head/sys/i386/i386/npx.cThu Jun 14 10:33:26 2018(r335131)
@@ -826,9 +826,6 @@ restore_npx_curthread(struct thread *td, struct pcb *p
  * and not necessarily for every context switch, but it is too hard to
  * access foreign pcb's.
  */
-
-static int err_count = 0;
-
 int
 npxdna(void)
 {
@@ -839,8 +836,12 @@ npxdna(void)
td = curthread;
critical_enter();
if (PCPU_GET(fpcurthread) == td) {
-   printf("npxdna: fpcurthread == curthread %d times\n",
-   ++err_count);
+   /*
+* Some virtual machines seems to set %cr0.TS at
+* arbitrary moments.  Silently clear the TS bit
+* regardless of the eager/lazy FPU context switch
+* mode.
+*/
stop_emulating();
critical_exit();
return (1);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335132 - in head/sys: amd64/amd64 i386/i386

2018-06-14 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 14 11:09:51 2018
New Revision: 335132
URL: https://svnweb.freebsd.org/changeset/base/335132

Log:
  Reorganize code flow in fpudna()/npxdna() to highlight the critical
  section scope.  Sprinkle __predict_false() for conditions known to
  never occur or occur only on rare platforms.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/amd64/amd64/fpu.c
  head/sys/i386/i386/npx.c

Modified: head/sys/amd64/amd64/fpu.c
==
--- head/sys/amd64/amd64/fpu.c  Thu Jun 14 10:33:26 2018(r335131)
+++ head/sys/amd64/amd64/fpu.c  Thu Jun 14 11:09:51 2018(r335132)
@@ -722,7 +722,7 @@ fpudna(void)
 
KASSERT((curpcb->pcb_flags & PCB_FPUNOSAVE) == 0,
("fpudna while in fpu_kern_enter(FPU_KERN_NOCTX)"));
-   if (PCPU_GET(fpcurthread) == td) {
+   if (__predict_false(PCPU_GET(fpcurthread) == td)) {
/*
 * Some virtual machines seems to set %cr0.TS at
 * arbitrary moments.  Silently clear the TS bit
@@ -730,15 +730,15 @@ fpudna(void)
 * mode.
 */
stop_emulating();
-   critical_exit();
-   return;
+   } else {
+   if (__predict_false(PCPU_GET(fpcurthread) != NULL)) {
+   panic(
+   "fpudna: fpcurthread = %p (%d), curthread = %p (%d)\n",
+   PCPU_GET(fpcurthread),
+   PCPU_GET(fpcurthread)->td_tid, td, td->td_tid);
+   }
+   restore_fpu_curthread(td);
}
-   if (PCPU_GET(fpcurthread) != NULL) {
-   panic("fpudna: fpcurthread = %p (%d), curthread = %p (%d)\n",
-   PCPU_GET(fpcurthread), PCPU_GET(fpcurthread)->td_tid,
-   td, td->td_tid);
-   }
-   restore_fpu_curthread(td);
critical_exit();
 }
 

Modified: head/sys/i386/i386/npx.c
==
--- head/sys/i386/i386/npx.cThu Jun 14 10:33:26 2018(r335131)
+++ head/sys/i386/i386/npx.cThu Jun 14 11:09:51 2018(r335132)
@@ -835,7 +835,7 @@ npxdna(void)
return (0);
td = curthread;
critical_enter();
-   if (PCPU_GET(fpcurthread) == td) {
+   if (__predict_false(PCPU_GET(fpcurthread) == td)) {
/*
 * Some virtual machines seems to set %cr0.TS at
 * arbitrary moments.  Silently clear the TS bit
@@ -843,19 +843,18 @@ npxdna(void)
 * mode.
 */
stop_emulating();
-   critical_exit();
-   return (1);
+   } else {
+   if (__predict_false(PCPU_GET(fpcurthread) != NULL)) {
+   printf(
+   "npxdna: fpcurthread = %p (%d), curthread = %p (%d)\n",
+   PCPU_GET(fpcurthread),
+   PCPU_GET(fpcurthread)->td_proc->p_pid,
+   td, td->td_proc->p_pid);
+   panic("npxdna");
+   }
+   restore_npx_curthread(td, td->td_pcb);
}
-   if (PCPU_GET(fpcurthread) != NULL) {
-   printf("npxdna: fpcurthread = %p (%d), curthread = %p (%d)\n",
-  PCPU_GET(fpcurthread),
-  PCPU_GET(fpcurthread)->td_proc->p_pid,
-  td, td->td_proc->p_pid);
-   panic("npxdna");
-   }
-   restore_npx_curthread(td, td->td_pcb);
critical_exit();
-
return (1);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335135 - head/sys/amd64/linux

2018-06-14 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 14 12:35:57 2018
New Revision: 335135
URL: https://svnweb.freebsd.org/changeset/base/335135

Log:
  linuxolator/amd64: Don't mangle %r10 on return from syscall for EJUSTRETURN.
  
  This fixes the %r10 content for rt_sigreturn.
  
  Submitted by: Yanko Yankulov 
  MFC after:1 week

Modified:
  head/sys/amd64/linux/linux_sysvec.c

Modified: head/sys/amd64/linux/linux_sysvec.c
==
--- head/sys/amd64/linux/linux_sysvec.c Thu Jun 14 12:14:51 2018
(r335134)
+++ head/sys/amd64/linux/linux_sysvec.c Thu Jun 14 12:35:57 2018
(r335135)
@@ -228,7 +228,8 @@ linux_set_syscall_retval(struct thread *td, int error)
 * the syscall.  So, do not clobber %rdx and %r10.
 */
td->td_retval[1] = frame->tf_rdx;
-   frame->tf_r10 = frame->tf_rcx;
+   if (error != EJUSTRETURN)
+   frame->tf_r10 = frame->tf_rcx;
 
cpu_set_syscall_retval(td, error);
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335171 - head/sys/vm

2018-06-14 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 14 19:41:02 2018
New Revision: 335171
URL: https://svnweb.freebsd.org/changeset/base/335171

Log:
  Handle the race between fork/vm_object_split() and faults.
  
  If fault started before vmspace_fork() locked the map, and then during
  fork, vm_map_copy_entry()->vm_object_split() is executed, it is
  possible that the fault instantiate the page into the original object
  when the page was already copied into the new object (see
  vm_map_split() for the orig/new objects terminology). This can happen
  if split found a busy page (e.g. from the fault) and slept dropping
  the objects lock, which allows the swap pager to instantiate
  read-behind pages for the fault.  Then the restart of the scan can see
  a page in the scanned range, where it was already copied to the upper
  object.
  
  Fix it by instantiating the read-ahead pages before
  swap_pager_getpages() method drops the lock to allocate pbuf.  The
  object scan would see the whole range prefilled with the busy pages
  and not proceed the range.
  
  Note that vm_fault rechecks the map generation count after the object
  unlock, so that it restarts the handling if raced with split, and
  re-lookups the right page from the upper object.
  
  In collaboration with:alc
  Tested by:pho
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/vm/swap_pager.c

Modified: head/sys/vm/swap_pager.c
==
--- head/sys/vm/swap_pager.cThu Jun 14 19:01:40 2018(r335170)
+++ head/sys/vm/swap_pager.cThu Jun 14 19:41:02 2018(r335171)
@@ -1096,21 +1096,24 @@ swap_pager_getpages(vm_object_t object, vm_page_t *ma,
 int *rahead)
 {
struct buf *bp;
-   vm_page_t mpred, msucc, p;
+   vm_page_t bm, mpred, msucc, p;
vm_pindex_t pindex;
daddr_t blk;
-   int i, j, maxahead, maxbehind, reqcount, shift;
+   int i, maxahead, maxbehind, reqcount;
 
reqcount = count;
 
-   VM_OBJECT_WUNLOCK(object);
-   bp = getpbuf(&nsw_rcount);
-   VM_OBJECT_WLOCK(object);
-
-   if (!swap_pager_haspage(object, ma[0]->pindex, &maxbehind, &maxahead)) {
-   relpbuf(bp, &nsw_rcount);
+   /*
+* Determine the final number of read-behind pages and
+* allocate them BEFORE releasing the object lock.  Otherwise,
+* there can be a problematic race with vm_object_split().
+* Specifically, vm_object_split() might first transfer pages
+* that precede ma[0] in the current object to a new object,
+* and then this function incorrectly recreates those pages as
+* read-behind pages in the current object.
+*/
+   if (!swap_pager_haspage(object, ma[0]->pindex, &maxbehind, &maxahead))
return (VM_PAGER_FAIL);
-   }
 
/*
 * Clip the readahead and readbehind ranges to exclude resident pages.
@@ -1132,35 +1135,31 @@ swap_pager_getpages(vm_object_t object, vm_page_t *ma,
*rbehind = pindex - mpred->pindex - 1;
}
 
+   bm = ma[0];
+   for (i = 0; i < count; i++)
+   ma[i]->oflags |= VPO_SWAPINPROG;
+
/*
 * Allocate readahead and readbehind pages.
 */
-   shift = rbehind != NULL ? *rbehind : 0;
-   if (shift != 0) {
-   for (i = 1; i <= shift; i++) {
+   if (rbehind != NULL) {
+   for (i = 1; i <= *rbehind; i++) {
p = vm_page_alloc(object, ma[0]->pindex - i,
VM_ALLOC_NORMAL);
-   if (p == NULL) {
-   /* Shift allocated pages to the left. */
-   for (j = 0; j < i - 1; j++)
-   bp->b_pages[j] =
-   bp->b_pages[j + shift - i + 1];
+   if (p == NULL)
break;
-   }
-   bp->b_pages[shift - i] = p;
+   p->oflags |= VPO_SWAPINPROG;
+   bm = p;
}
-   shift = i - 1;
-   *rbehind = shift;
+   *rbehind = i - 1;
}
-   for (i = 0; i < reqcount; i++)
-   bp->b_pages[i + shift] = ma[i];
if (rahead != NULL) {
for (i = 0; i < *rahead; i++) {
p = vm_page_alloc(object,
ma[reqcount - 1]->pindex + i + 1, VM_ALLOC_NORMAL);
if (p == NULL)
break;
-   bp->b_pages[shift + reqcount + i] = p;
+   p->oflags |= VPO_SWAPINPROG;
}
*rahead = i;
}
@@ -1171,15 +1170,18 @@ swap_pager_getpages(vm_object_t object, vm_page_t *ma,
 
vm_object_pip_add(object, count);
 
-   for (i = 0; i < co

Re: svn commit: r335171 - head/sys/vm

2018-06-14 Thread Konstantin Belousov
On Thu, Jun 14, 2018 at 07:41:02PM +, Konstantin Belousov wrote:
> Author: kib
> Date: Thu Jun 14 19:41:02 2018
> New Revision: 335171
> URL: https://svnweb.freebsd.org/changeset/base/335171
> 
> Log:
>   Handle the race between fork/vm_object_split() and faults.
>   
>   If fault started before vmspace_fork() locked the map, and then during
>   fork, vm_map_copy_entry()->vm_object_split() is executed, it is
>   possible that the fault instantiate the page into the original object
>   when the page was already copied into the new object (see
>   vm_map_split() for the orig/new objects terminology). This can happen
>   if split found a busy page (e.g. from the fault) and slept dropping
>   the objects lock, which allows the swap pager to instantiate
>   read-behind pages for the fault.  Then the restart of the scan can see
>   a page in the scanned range, where it was already copied to the upper
>   object.
>   
>   Fix it by instantiating the read-ahead pages before
>   swap_pager_getpages() method drops the lock to allocate pbuf.  The
>   object scan would see the whole range prefilled with the busy pages
>   and not proceed the range.
>   
>   Note that vm_fault rechecks the map generation count after the object
>   unlock, so that it restarts the handling if raced with split, and
>   re-lookups the right page from the upper object.
>   
>   In collaboration with:  alc
Reviewed by:markj
Sorry.

>   Tested by:  pho
>   Sponsored by:   The FreeBSD Foundation
>   MFC after:  1 week
Differential revision:  https://reviews.freebsd.org/D15293

> 
> Modified:
>   head/sys/vm/swap_pager.c
> 
> Modified: head/sys/vm/swap_pager.c
> ==
> --- head/sys/vm/swap_pager.c  Thu Jun 14 19:01:40 2018(r335170)
> +++ head/sys/vm/swap_pager.c  Thu Jun 14 19:41:02 2018(r335171)
> @@ -1096,21 +1096,24 @@ swap_pager_getpages(vm_object_t object, vm_page_t *ma,
>  int *rahead)
>  {
>   struct buf *bp;
> - vm_page_t mpred, msucc, p;
> + vm_page_t bm, mpred, msucc, p;
>   vm_pindex_t pindex;
>   daddr_t blk;
> - int i, j, maxahead, maxbehind, reqcount, shift;
> + int i, maxahead, maxbehind, reqcount;
>  
>   reqcount = count;
>  
> - VM_OBJECT_WUNLOCK(object);
> - bp = getpbuf(&nsw_rcount);
> - VM_OBJECT_WLOCK(object);
> -
> - if (!swap_pager_haspage(object, ma[0]->pindex, &maxbehind, &maxahead)) {
> - relpbuf(bp, &nsw_rcount);
> + /*
> +  * Determine the final number of read-behind pages and
> +  * allocate them BEFORE releasing the object lock.  Otherwise,
> +  * there can be a problematic race with vm_object_split().
> +  * Specifically, vm_object_split() might first transfer pages
> +  * that precede ma[0] in the current object to a new object,
> +  * and then this function incorrectly recreates those pages as
> +  * read-behind pages in the current object.
> +  */
> + if (!swap_pager_haspage(object, ma[0]->pindex, &maxbehind, &maxahead))
>   return (VM_PAGER_FAIL);
> - }
>  
>   /*
>* Clip the readahead and readbehind ranges to exclude resident pages.
> @@ -1132,35 +1135,31 @@ swap_pager_getpages(vm_object_t object, vm_page_t *ma,
>   *rbehind = pindex - mpred->pindex - 1;
>   }
>  
> + bm = ma[0];
> + for (i = 0; i < count; i++)
> + ma[i]->oflags |= VPO_SWAPINPROG;
> +
>   /*
>* Allocate readahead and readbehind pages.
>*/
> - shift = rbehind != NULL ? *rbehind : 0;
> - if (shift != 0) {
> - for (i = 1; i <= shift; i++) {
> + if (rbehind != NULL) {
> + for (i = 1; i <= *rbehind; i++) {
>   p = vm_page_alloc(object, ma[0]->pindex - i,
>   VM_ALLOC_NORMAL);
> - if (p == NULL) {
> - /* Shift allocated pages to the left. */
> - for (j = 0; j < i - 1; j++)
> - bp->b_pages[j] =
> - bp->b_pages[j + shift - i + 1];
> + if (p == NULL)
>   break;
> - }
> - bp->b_pages[shift - i] = p;
> + p->oflags |= VPO_SWAPINPROG;
> + bm = p;
>   }
> - shift = i - 1;
> - *rbehind = shift;
> + *rbehind = i - 1;
>   }
> - for (i = 0; i < reqcount; i++)

Re: svn commit: r335171 - head/sys/vm

2018-06-15 Thread Konstantin Belousov
On Fri, Jun 15, 2018 at 11:03:06AM +0100, Steven Hartland wrote:
> On 15/06/2018 00:07, Alan Cox wrote:
> >
> >> On Jun 14, 2018, at 5:54 PM, Steven Hartland 
> >>  >> > wrote:
> >>
> >> Out of interest, how would this exhibit itself?
> >>
> >
> > A panic in vm_page_insert_after().
> >
> So just to confirm this couldn't cause random memory corruption of the 
> parent process?

No, or to put it more sincere, I highly doubt it.

Also, I do not think that this Go issue will be solved serendipitously
by some FreeBSD bug fix.  So far it is indicative that either the
situation is too unique for the Go runtime so it is not exposed by other
programs (which is quite doubtful), or this is a bug in Go runtime.

The only way forward is to understand what exactly is broken for the
situation.  This requires at least deep knowledge the Go garbage collector
internal working, which itself supposes understanding of the Go runtime
and Go environment.  I do not mean explanation of the assert, but the
root cause that eventually triggers the assert.  They are somewhat
disjoint in time, I believe.

I once tried to look at the Go gc, but after spending a day, realized that
I need to use 2-3 weeks to learn the system, which made me abandon the
attempt.

So the pre-req for fixing this bug is for somebody who interested in Go,
to spend enough time to explain the root-cause condition to the external
world.  I have no idea is it OS problem, Go runtime problem, or an issue
with the port of Go runtime to FreeBSD.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335199 - head/sys/compat/linprocfs

2018-06-15 Thread Konstantin Belousov
Author: kib
Date: Fri Jun 15 13:56:58 2018
New Revision: 335199
URL: https://svnweb.freebsd.org/changeset/base/335199

Log:
  linprocfs: add TracerPid to /proc/pid/status.
  Also fix the value of parent pid if the process is traced.
  
  Submitted by: Yanko Yankulov 
  MFC after:1 week

Modified:
  head/sys/compat/linprocfs/linprocfs.c

Modified: head/sys/compat/linprocfs/linprocfs.c
==
--- head/sys/compat/linprocfs/linprocfs.c   Fri Jun 15 13:53:37 2018
(r335198)
+++ head/sys/compat/linprocfs/linprocfs.c   Fri Jun 15 13:56:58 2018
(r335199)
@@ -829,8 +829,8 @@ linprocfs_doprocstatus(PFS_FILL_ARGS)
 * Credentials
 */
sbuf_printf(sb, "Pid:\t%d\n",   p->p_pid);
-   sbuf_printf(sb, "PPid:\t%d\n",  p->p_pptr ?
-   p->p_pptr->p_pid : 0);
+   sbuf_printf(sb, "PPid:\t%d\n",  kp.ki_ppid );
+   sbuf_printf(sb, "TracerPid:\t%d\n", kp.ki_tracer );
sbuf_printf(sb, "Uid:\t%d %d %d %d\n",  p->p_ucred->cr_ruid,
p->p_ucred->cr_uid,
p->p_ucred->cr_svuid,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335253 - in head: . contrib/ofed contrib/ofed/include contrib/ofed/infiniband-diags/build contrib/ofed/libcxgb4 contrib/ofed/libibcm contrib/ofed/libibmad contrib/ofed/libibnetdisc con...

2018-06-16 Thread Konstantin Belousov
Author: kib
Date: Sat Jun 16 15:05:05 2018
New Revision: 335253
URL: https://svnweb.freebsd.org/changeset/base/335253

Log:
  Rework ofed build.
  
  Aligns the build with the FreeBSD traditional approach to not build in
  contrib/, and to track inter-dependencies between libraries.
  
  With help from:   bdrewery
  Reviewed by:  bdrewery, hselasky
  Sponsored by: Mellanox Technologies
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D15648

Added:
  head/lib/ofed/
  head/lib/ofed/Makefile   (contents, props changed)
  head/lib/ofed/Makefile.inc   (contents, props changed)
  head/lib/ofed/complib/
  head/lib/ofed/complib/Makefile
 - copied, changed from r335252, head/contrib/ofed/opensm/complib/Makefile
  head/lib/ofed/include/
  head/lib/ofed/include/Makefile
 - copied, changed from r335252, head/contrib/ofed/include/Makefile
  head/lib/ofed/libcxgb4/
  head/lib/ofed/libcxgb4/Makefile
 - copied, changed from r335252, head/contrib/ofed/libcxgb4/Makefile
  head/lib/ofed/libibcm/
  head/lib/ofed/libibcm/Makefile
 - copied, changed from r335252, head/contrib/ofed/libibcm/Makefile
  head/lib/ofed/libibmad/
  head/lib/ofed/libibmad/Makefile
 - copied, changed from r335252, head/contrib/ofed/libibmad/Makefile
  head/lib/ofed/libibnetdisc/
  head/lib/ofed/libibnetdisc/Makefile
 - copied, changed from r335252, head/contrib/ofed/libibnetdisc/Makefile
  head/lib/ofed/libibumad/
  head/lib/ofed/libibumad/Makefile
 - copied, changed from r335252, head/contrib/ofed/libibumad/Makefile
  head/lib/ofed/libibverbs/
  head/lib/ofed/libibverbs/Makefile
 - copied, changed from r335252, head/contrib/ofed/libibverbs/Makefile
  head/lib/ofed/libmlx4/
  head/lib/ofed/libmlx4/Makefile
 - copied, changed from r335252, head/contrib/ofed/libmlx4/Makefile
  head/lib/ofed/libmlx5/
  head/lib/ofed/libmlx5/Makefile
 - copied, changed from r335252, head/contrib/ofed/libmlx5/Makefile
  head/lib/ofed/libopensm/
  head/lib/ofed/libopensm/Makefile
 - copied, changed from r335252, head/contrib/ofed/opensm/libopensm/Makefile
  head/lib/ofed/librdmacm/
  head/lib/ofed/librdmacm/Makefile
 - copied, changed from r335252, head/contrib/ofed/librdmacm/Makefile
  head/lib/ofed/libvendor/
  head/lib/ofed/libvendor/Makefile
 - copied, changed from r335252, head/contrib/ofed/opensm/libvendor/Makefile
  head/usr.bin/ofed/
  head/usr.bin/ofed/Makefile   (contents, props changed)
  head/usr.bin/ofed/infiniband-diags/
  head/usr.bin/ofed/infiniband-diags/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/Makefile
  head/usr.bin/ofed/infiniband-diags/Makefile.inc
 - copied, changed from r335252, 
head/contrib/ofed/infiniband-diags/build/Makefile.inc
  head/usr.bin/ofed/infiniband-diags/dump_fts/
  head/usr.bin/ofed/infiniband-diags/dump_fts/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/dump_fts/Makefile
  head/usr.bin/ofed/infiniband-diags/ibaddr/
  head/usr.bin/ofed/infiniband-diags/ibaddr/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibaddr/Makefile
  head/usr.bin/ofed/infiniband-diags/ibcacheedit/
  head/usr.bin/ofed/infiniband-diags/ibcacheedit/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibcacheedit/Makefile
  head/usr.bin/ofed/infiniband-diags/ibccconfig/
  head/usr.bin/ofed/infiniband-diags/ibccconfig/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibccconfig/Makefile
  head/usr.bin/ofed/infiniband-diags/ibccquery/
  head/usr.bin/ofed/infiniband-diags/ibccquery/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibccquery/Makefile
  head/usr.bin/ofed/infiniband-diags/iblinkinfo/
  head/usr.bin/ofed/infiniband-diags/iblinkinfo/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/iblinkinfo/Makefile
  head/usr.bin/ofed/infiniband-diags/ibmirror/
  head/usr.bin/ofed/infiniband-diags/ibmirror/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibmirror/Makefile
  head/usr.bin/ofed/infiniband-diags/ibnetdiscover/
  head/usr.bin/ofed/infiniband-diags/ibnetdiscover/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibnetdiscover/Makefile
  head/usr.bin/ofed/infiniband-diags/ibping/
  head/usr.bin/ofed/infiniband-diags/ibping/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibping/Makefile
  head/usr.bin/ofed/infiniband-diags/ibportstate/
  head/usr.bin/ofed/infiniband-diags/ibportstate/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/build/ibportstate/Makefile
  head/usr.bin/ofed/infiniband-diags/ibqueryerrors/
  head/usr.bin/ofed/infiniband-diags/ibqueryerrors/Makefile
 - copied unchanged from r335252, 
head/contrib/ofed/infiniband-diags/

svn commit: r335257 - in head: lib/libthr/arch/common sys/dev/cm sys/dev/pdq sys/modules/arcnet sys/modules/cm sys/modules/libmbpool sys/modules/vxge sys/ofed/drivers/infiniband/debug

2018-06-16 Thread Konstantin Belousov
Author: kib
Date: Sat Jun 16 16:16:24 2018
New Revision: 335257
URL: https://svnweb.freebsd.org/changeset/base/335257

Log:
  Remove some empty directories

Deleted:
  head/lib/libthr/arch/common/
  head/sys/dev/cm/
  head/sys/dev/pdq/
  head/sys/modules/arcnet/
  head/sys/modules/cm/
  head/sys/modules/libmbpool/
  head/sys/modules/vxge/
  head/sys/ofed/drivers/infiniband/debug/
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335258 - head/lib/libthr/support

2018-06-16 Thread Konstantin Belousov
Author: kib
Date: Sat Jun 16 17:11:23 2018
New Revision: 335258
URL: https://svnweb.freebsd.org/changeset/base/335258

Log:
  Remove unused file.
  
  The thr_new(2) syscall is called through libc stub.  r154212 stopped
  generating it for libthr but did not cleaned the unused remnants.
  
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Deleted:
  head/lib/libthr/support/
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r335276 - in head/stand/i386: gptboot zfsboot

2018-06-20 Thread Konstantin Belousov
On Tue, Jun 19, 2018 at 08:34:18PM -0400, Allan Jude wrote:
> On 2018-06-17 07:32, Eugene Grosbein wrote:
> > 17.06.2018 10:18, Allan Jude wrote:
> > 
> >> Author: allanjude
> >> Date: Sun Jun 17 03:18:56 2018
> >> New Revision: 335276
> >> URL: https://svnweb.freebsd.org/changeset/base/335276
> >>
> >> Log:
> >>   gptboot, zfsboot, gptzfsboot: Enable the video and serial consoles early
> >>   
> >>   Normally the serial console is not enabled until /boot.config is read and
> >>   we know how the serial console should be configured.  Initialize the
> >>   consoles early in 'dual' mode (serial & keyboard) with a default serial
> >>   rate of 115200. Then serial is re-initialized once the disk is decrypted
> >>   and the /boot.config file can be read.
> >>   
> >>   This allows the GELIBoot passphrase to be provided via the serial 
> >> console.
> >>   
> >>   PR:  221526
> >>   Requested by:many
> >>   Reviewed by: imp
> >>   Sponsored by:Klara Systems
> >>   Differential Revision:   https://reviews.freebsd.org/D15862
> > 
> > I had several cases when booting FreeBSD/amd64 with motherboard having no 
> > serial ports
> > hang hard early at boot unless I rebuilt boot media configuring it to NOT 
> > try accessing
> > missing serial ports. I even could reproduce that with VirtualBox machine 
> > configured
> > with no serial ports (not same as existing bug inactive serial port).
> > 
> > Should there be some way to disable this serial ports configuration at 
> > compile time?
> > 
> > 
> > 
> 
> I think what we'll do it compile it both ways, and use the non-serial
> one by default, because it is safer. Then you can just use
> 'gptboot-serial' if you want serial support.
> 
> This will likely make Warner a bit sad, since we are just finally
> getting around to reducing the number of different bootcode files.

I think we should follow the hardware trends there and apply a policy
where new features are not added to the CSM boot. All modern machines
can be booted in UEFI mode, and if some modern machine cannot, then we
need it fixed.  We should encourage users to make new installs boot by
UEFI.

The feature from the commit is only relevant for machines that require
CSM boot or do not have UEFI option at all, am I right ? With the policy
applied, an additional CSM-boot bootblock would be not shipped.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r335276 - in head/stand/i386: gptboot zfsboot

2018-06-20 Thread Konstantin Belousov
On Wed, Jun 20, 2018 at 09:43:31AM -0600, Ian Lepore wrote:
> On Wed, 2018-06-20 at 12:22 +0300, Konstantin Belousov wrote:
> > On Tue, Jun 19, 2018 at 08:34:18PM -0400, Allan Jude wrote:
> > > 
> > > On 2018-06-17 07:32, Eugene Grosbein wrote:
> > > > 
> > > > 17.06.2018 10:18, Allan Jude wrote:
> > > > 
> > > > > 
> > > > > Author: allanjude
> > > > > Date: Sun Jun 17 03:18:56 2018
> > > > > New Revision: 335276
> > > > > URL: https://svnweb.freebsd.org/changeset/base/335276
> > > > > 
> > > > > Log:
> > > > >   gptboot, zfsboot, gptzfsboot: Enable the video and serial consoles 
> > > > > early
> > > > >   
> > > > >   Normally the serial console is not enabled until /boot.config is 
> > > > > read and
> > > > >   we know how the serial console should be configured.  Initialize the
> > > > >   consoles early in 'dual' mode (serial & keyboard) with a default 
> > > > > serial
> > > > >   rate of 115200. Then serial is re-initialized once the disk is 
> > > > > decrypted
> > > > >   and the /boot.config file can be read.
> > > > >   
> > > > >   This allows the GELIBoot passphrase to be provided via the serial 
> > > > > console.
> > > > >   
> > > > >   PR: 221526
> > > > >   Requested by:   many
> > > > >   Reviewed by:imp
> > > > >   Sponsored by:   Klara Systems
> > > > >   Differential Revision:  https://reviews.freebsd.org/D15862
> > > > I had several cases when booting FreeBSD/amd64 with motherboard having 
> > > > no serial ports
> > > > hang hard early at boot unless I rebuilt boot media configuring it to 
> > > > NOT try accessing
> > > > missing serial ports. I even could reproduce that with VirtualBox 
> > > > machine configured
> > > > with no serial ports (not same as existing bug inactive serial port).
> > > > 
> > > > Should there be some way to disable this serial ports configuration at 
> > > > compile time?
> > > > 
> > > > 
> > > > 
> > > I think what we'll do it compile it both ways, and use the non-serial
> > > one by default, because it is safer. Then you can just use
> > > 'gptboot-serial' if you want serial support.
> > > 
> > > This will likely make Warner a bit sad, since we are just finally
> > > getting around to reducing the number of different bootcode files.
> > I think we should follow the hardware trends there and apply a policy
> > where new features are not added to the CSM boot. All modern machines
> > can be booted in UEFI mode, and if some modern machine cannot, then we
> > need it fixed.  We should encourage users to make new installs boot by
> > UEFI.
> > 
> > The feature from the commit is only relevant for machines that require
> > CSM boot or do not have UEFI option at all, am I right ? With the policy
> > applied, an additional CSM-boot bootblock would be not shipped.
> > 
> 
> I think it is far too early to say that the code for booting without
> efi is abandonware. I have half a dozen x86 boxes in use here, and only
> one of them is even able to boot efi, and its default resolution in efi
> mode confuses the kvm switch it's connected to, so even on that I have
> to use legacy bios boot.
I do not propose to abandon bios boot, or even to declare it legacy
with the proper meaning. I mean that CSM is disappearing on the newest
platforms, and should become only used on old machines or i386.  With that
attitude, adding a features for it, esp. by the cost of the user confusion,
is not worth the efforts.  It still should be maintained for the foreseable
future.

If the machines where you get the trouble is newer than say 5 years, 
then they should boot with UEFI.  If not, the problem in loader.efi
needs to be fixed.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r335276 - in head/stand/i386: gptboot zfsboot

2018-06-20 Thread Konstantin Belousov
On Wed, Jun 20, 2018 at 10:05:16AM -0600, Warner Losh wrote:
> On Wed, Jun 20, 2018 at 10:03 AM, Konstantin Belousov 
> wrote:
> 
> > On Wed, Jun 20, 2018 at 09:43:31AM -0600, Ian Lepore wrote:
> > > On Wed, 2018-06-20 at 12:22 +0300, Konstantin Belousov wrote:
> > > > On Tue, Jun 19, 2018 at 08:34:18PM -0400, Allan Jude wrote:
> > > > >
> > > > > On 2018-06-17 07:32, Eugene Grosbein wrote:
> > > > > >
> > > > > > 17.06.2018 10:18, Allan Jude wrote:
> > > > > >
> > > > > > >
> > > > > > > Author: allanjude
> > > > > > > Date: Sun Jun 17 03:18:56 2018
> > > > > > > New Revision: 335276
> > > > > > > URL: https://svnweb.freebsd.org/changeset/base/335276
> > > > > > >
> > > > > > > Log:
> > > > > > >   gptboot, zfsboot, gptzfsboot: Enable the video and serial
> > consoles early
> > > > > > >
> > > > > > >   Normally the serial console is not enabled until /boot.config
> > is read and
> > > > > > >   we know how the serial console should be
> > configured.  Initialize the
> > > > > > >   consoles early in 'dual' mode (serial & keyboard) with a
> > default serial
> > > > > > >   rate of 115200. Then serial is re-initialized once the disk is
> > decrypted
> > > > > > >   and the /boot.config file can be read.
> > > > > > >
> > > > > > >   This allows the GELIBoot passphrase to be provided via the
> > serial console.
> > > > > > >
> > > > > > >   PR: 221526
> > > > > > >   Requested by:   many
> > > > > > >   Reviewed by:imp
> > > > > > >   Sponsored by:   Klara Systems
> > > > > > >   Differential Revision:  https://reviews.freebsd.org/D15862
> > > > > > I had several cases when booting FreeBSD/amd64 with motherboard
> > having no serial ports
> > > > > > hang hard early at boot unless I rebuilt boot media configuring it
> > to NOT try accessing
> > > > > > missing serial ports. I even could reproduce that with VirtualBox
> > machine configured
> > > > > > with no serial ports (not same as existing bug inactive serial
> > port).
> > > > > >
> > > > > > Should there be some way to disable this serial ports
> > configuration at compile time?
> > > > > >
> > > > > >
> > > > > >
> > > > > I think what we'll do it compile it both ways, and use the non-serial
> > > > > one by default, because it is safer. Then you can just use
> > > > > 'gptboot-serial' if you want serial support.
> > > > >
> > > > > This will likely make Warner a bit sad, since we are just finally
> > > > > getting around to reducing the number of different bootcode files.
> > > > I think we should follow the hardware trends there and apply a policy
> > > > where new features are not added to the CSM boot. All modern machines
> > > > can be booted in UEFI mode, and if some modern machine cannot, then we
> > > > need it fixed.  We should encourage users to make new installs boot by
> > > > UEFI.
> > > >
> > > > The feature from the commit is only relevant for machines that require
> > > > CSM boot or do not have UEFI option at all, am I right ? With the
> > policy
> > > > applied, an additional CSM-boot bootblock would be not shipped.
> > > >
> > >
> > > I think it is far too early to say that the code for booting without
> > > efi is abandonware. I have half a dozen x86 boxes in use here, and only
> > > one of them is even able to boot efi, and its default resolution in efi
> > > mode confuses the kvm switch it's connected to, so even on that I have
> > > to use legacy bios boot.
> > I do not propose to abandon bios boot, or even to declare it legacy
> > with the proper meaning. I mean that CSM is disappearing on the newest
> > platforms, and should become only used on old machines or i386.  With that
> > attitude, adding a features for it, esp. by the cost of the user confusion,
> > is not worth the efforts.  It still should be maintained for the foreseable
> > future.
> >
> > If the machines where you get the trouble is newer than say 5 years,
> > then they should boot with UEFI.  If not, the problem in loader.efi
> > needs to be fixed.
> >
> 
> There is no problem in loader.efi that's specific to geli. It already uses
> the UEFI boot loader config. While there's some issues downstream (eg
> kernel messages), this specific issue is a non-issue for loader.efi.

I referenced the problems that Ian has with UEFI boot on his machines,
not the serial console and geli change above.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r335456 - head/share/man/man7

2018-06-20 Thread Konstantin Belousov
On Wed, Jun 20, 2018 at 07:16:51PM +, Edward Tomasz Napierala wrote:
> Author: trasz
> Date: Wed Jun 20 19:16:51 2018
> New Revision: 335456
> URL: https://svnweb.freebsd.org/changeset/base/335456
> 
> Log:
>   Improve wording.
>   
>   MFC after:  2 weeks
> 
> Modified:
>   head/share/man/man7/development.7
> 
> Modified: head/share/man/man7/development.7
> ==
> --- head/share/man/man7/development.7 Wed Jun 20 18:51:38 2018
> (r335455)
> +++ head/share/man/man7/development.7 Wed Jun 20 19:16:51 2018
> (r335456)
> @@ -24,7 +24,7 @@
>  .\"
>  .\" $FreeBSD$
>  .\"
> -.Dd May 11, 2018
> +.Dd June 20, 2018
>  .Dt DEVELOPMENT 7
>  .Os
>  .Sh NAME
> @@ -81,7 +81,7 @@ Build instructions can be found in
>  .Xr build 7
>  and
>  .Xr release 7 .
> -Kernel APIs are usually documented, use
> +Kernel APIs are documented in section 9 manual pages; use
Kernel API is an oxymoron.  Section 9 describes Kernel Programming
Interfaces, the A from Application is not needed.  We usually abbreviate
it as KPI.

Kernel API are syscalls, if anything.
>  .Ql "apropos -s 9 ''"
>  for a list.
>  Regression test suite is described in
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335503 - in head/sys: kern sys

2018-06-21 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 21 21:07:25 2018
New Revision: 335503
URL: https://svnweb.freebsd.org/changeset/base/335503

Log:
  Update proc->p_ptevents annotation to reflect the actual locking.
  
  Submitted by: Yanko Yankulov 
  Reviewed by:  jhb
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D15954

Modified:
  head/sys/kern/sys_process.c
  head/sys/sys/proc.h

Modified: head/sys/kern/sys_process.c
==
--- head/sys/kern/sys_process.c Thu Jun 21 21:03:58 2018(r335502)
+++ head/sys/kern/sys_process.c Thu Jun 21 21:07:25 2018(r335503)
@@ -688,6 +688,7 @@ void
 proc_set_traced(struct proc *p, bool stop)
 {
 
+   sx_assert(&proctree_lock, SX_XLOCKED);
PROC_LOCK_ASSERT(p, MA_OWNED);
p->p_flag |= P_TRACED;
if (stop)

Modified: head/sys/sys/proc.h
==
--- head/sys/sys/proc.h Thu Jun 21 21:03:58 2018(r335502)
+++ head/sys/sys/proc.h Thu Jun 21 21:07:25 2018(r335503)
@@ -633,7 +633,7 @@ struct proc {
u_int   p_stype;/* (c) Stop event type. */
charp_step; /* (c) Process is stopped. */
u_char  p_pfsflags; /* (c) Procfs flags. */
-   u_int   p_ptevents; /* (c) ptrace() event mask. */
+   u_int   p_ptevents; /* (c + e) ptrace() event mask. */
struct nlminfo  *p_nlminfo; /* (?) Only used by/for lockd. */
struct kaioinfo *p_aioinfo; /* (y) ASYNC I/O info. */
struct thread   *p_singlethread;/* (c + j) If single threading this is 
it */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r335504 - in head/sys: kern sys

2018-06-21 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 21 21:12:49 2018
New Revision: 335504
URL: https://svnweb.freebsd.org/changeset/base/335504

Log:
  fork: avoid endless wait with PTRACE_FORK and RFSTOPPED.
  
  An RFSTOPPED thread can't clean TDB_STOPATFORK, which is done in the
  fork_return() in its context, so parent is stuck forever.  Triggered
  when trying to ptrace linux process.  Instead of waiting for the new
  thread to clear TDB_STOPATFORK, tag it as traced and reparent to the
  debugger in do_fork(), and let it only notify the debugger when run.
  
  Submitted by: Yanko Yankulov 
  Reviewed by:  jhb
  MFC after:1 week
  X-MFC-Note:   keep p_dbgwait placeholder intact
  Differential revision:https://reviews.freebsd.org/D15857

Modified:
  head/sys/kern/kern_fork.c
  head/sys/kern/kern_proc.c
  head/sys/kern/kern_sig.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_fork.c
==
--- head/sys/kern/kern_fork.c   Thu Jun 21 21:07:25 2018(r335503)
+++ head/sys/kern/kern_fork.c   Thu Jun 21 21:12:49 2018(r335504)
@@ -721,18 +721,6 @@ do_fork(struct thread *td, struct fork_req *fr, struct
 * but before we wait for the debugger.
 */
_PHOLD(p2);
-   if (p1->p_ptevents & PTRACE_FORK) {
-   /*
-* Arrange for debugger to receive the fork event.
-*
-* We can report PL_FLAG_FORKED regardless of
-* P_FOLLOWFORK settings, but it does not make a sense
-* for runaway child.
-*/
-   td->td_dbgflags |= TDB_FORK;
-   td->td_dbg_forked = p2->p_pid;
-   td2->td_dbgflags |= TDB_STOPATFORK;
-   }
if (fr->fr_flags & RFPPWAIT) {
td->td_pflags |= TDP_RFPPWAIT;
td->td_rfppwait_p = p2;
@@ -756,7 +744,42 @@ do_fork(struct thread *td, struct fork_req *fr, struct
procdesc_finit(p2->p_procdesc, fp_procdesc);
fdrop(fp_procdesc, td);
}
-
+   
+   /*
+* Speculative check for PTRACE_FORK. PTRACE_FORK is not
+* synced with forks in progress so it is OK if we miss it
+* if being set atm.
+*/
+   if ((p1->p_ptevents & PTRACE_FORK) != 0) {
+   sx_xlock(&proctree_lock);
+   PROC_LOCK(p2);
+   
+   /*
+* p1->p_ptevents & p1->p_pptr are protected by both
+* process and proctree locks for modifications,
+* so owning proctree_lock allows the race-free read.
+*/
+   if ((p1->p_ptevents & PTRACE_FORK) != 0) {
+   /*
+* Arrange for debugger to receive the fork event.
+*
+* We can report PL_FLAG_FORKED regardless of
+* P_FOLLOWFORK settings, but it does not make a sense
+* for runaway child.
+*/
+   td->td_dbgflags |= TDB_FORK;
+   td->td_dbg_forked = p2->p_pid;
+   td2->td_dbgflags |= TDB_STOPATFORK;
+   proc_set_traced(p2, true);
+   CTR2(KTR_PTRACE,
+   "do_fork: attaching to new child pid %d: oppid %d",
+   p2->p_pid, p2->p_oppid);
+   proc_reparent(p2, p1->p_pptr);
+   }
+   PROC_UNLOCK(p2);
+   sx_xunlock(&proctree_lock);
+   }
+   
if ((fr->fr_flags & RFSTOPPED) == 0) {
/*
 * If RFSTOPPED not requested, make child runnable and
@@ -773,11 +796,6 @@ do_fork(struct thread *td, struct fork_req *fr, struct
}
 
PROC_LOCK(p2);
-   /*
-* Wait until debugger is attached to child.
-*/
-   while (td2->td_proc == p2 && (td2->td_dbgflags & TDB_STOPATFORK) != 0)
-   cv_wait(&p2->p_dbgwait, &p2->p_mtx);
_PRELE(p2);
racct_proc_fork_done(p2);
PROC_UNLOCK(p2);
@@ -1063,24 +1081,15 @@ fork_exit(void (*callout)(void *, struct trapframe *),
 void
 fork_return(struct thread *td, struct trapframe *frame)
 {
-   struct proc *p, *dbg;
+   struct proc *p;
 
p = td->td_proc;
if (td->td_dbgflags & TDB_STOPATFORK) {
-   sx_xlock(&proctree_lock);
PROC_LOCK(p);
-   if (p->p_pptr->p_ptevents & PTRACE_FORK) {
+   if ((p->p_flag & P_TRACED) != 0) {
/*
-* If debugger still wants auto-attach for the
-* parent's children, do it now.
+* Inform the debugger if one is still present.
 */
-   dbg = p->p_pptr->p_pptr;
-   proc_set_traced(p, true);
-  

svn commit: r335505 - head/sys/compat/linux

2018-06-21 Thread Konstantin Belousov
Author: kib
Date: Thu Jun 21 21:15:04 2018
New Revision: 335505
URL: https://svnweb.freebsd.org/changeset/base/335505

Log:
  linux_clone_thread: mark new thread as TDB_BORN.
  
  So that the ptrace code will catch it and report it to attached
  debugger.  Enables debugging of threaded Linux binaries with FreeBSD
  debugger.
  
  Submitted by: Yanko Yankulov 
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D15880

Modified:
  head/sys/compat/linux/linux_fork.c

Modified: head/sys/compat/linux/linux_fork.c
==
--- head/sys/compat/linux/linux_fork.c  Thu Jun 21 21:12:49 2018
(r335504)
+++ head/sys/compat/linux/linux_fork.c  Thu Jun 21 21:15:04 2018
(r335505)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -352,6 +353,9 @@ linux_clone_thread(struct thread *td, struct linux_clo
thread_unlock(td);
if (P_SHOULDSTOP(p))
newtd->td_flags |= TDF_ASTPENDING | TDF_NEEDSUSPCHK;
+   
+   if (p->p_ptevents & PTRACE_LWP)
+   newtd->td_dbgflags |= TDB_BORN;
PROC_UNLOCK(p);
 
tidhash_add(newtd);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326311 - in head/sys: amd64/amd64 arm64/arm64

2017-11-28 Thread Konstantin Belousov
Author: kib
Date: Tue Nov 28 09:34:43 2017
New Revision: 326311
URL: https://svnweb.freebsd.org/changeset/base/326311

Log:
  Fix index calculation for the page table pages for efirt 1:1 map.
  
  Stop issuing pre-assigned number to enumerate all page table pages,
  the assignment is incorrect.  Instead automatically calculate the next
  unused index. This index in fact does not serve any purpose except to
  be unique to satisfy vm_page_grab() interface, we do not look up the
  page by the index later.
  
  Reported and tested by:   emaste
  Reviewed by:  andrew
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  PR:   223906
  Differential revision:https://reviews.freebsd.org/D13273

Modified:
  head/sys/amd64/amd64/efirt_machdep.c
  head/sys/arm64/arm64/efirt_machdep.c

Modified: head/sys/amd64/amd64/efirt_machdep.c
==
--- head/sys/amd64/amd64/efirt_machdep.cTue Nov 28 06:31:39 2017
(r326310)
+++ head/sys/amd64/amd64/efirt_machdep.cTue Nov 28 09:34:43 2017
(r326311)
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
 static pml4_entry_t *efi_pml4;
 static vm_object_t obj_1t1_pt;
 static vm_page_t efi_pml4_page;
+static vm_pindex_t efi_1t1_idx;
 
 void
 efi_destroy_1t1_map(void)
@@ -85,10 +86,10 @@ efi_destroy_1t1_map(void)
 }
 
 static vm_page_t
-efi_1t1_page(vm_pindex_t idx)
+efi_1t1_page(void)
 {
 
-   return (vm_page_grab(obj_1t1_pt, idx, VM_ALLOC_NOBUSY |
+   return (vm_page_grab(obj_1t1_pt, efi_1t1_idx++, VM_ALLOC_NOBUSY |
VM_ALLOC_WIRED | VM_ALLOC_ZERO));
 }
 
@@ -106,7 +107,7 @@ efi_1t1_pte(vm_offset_t va)
pml4_idx = pmap_pml4e_index(va);
pml4e = &efi_pml4[pml4_idx];
if (*pml4e == 0) {
-   m = efi_1t1_page(1 + pml4_idx);
+   m = efi_1t1_page();
mphys =  VM_PAGE_TO_PHYS(m);
*pml4e = mphys | X86_PG_RW | X86_PG_V;
} else {
@@ -117,7 +118,7 @@ efi_1t1_pte(vm_offset_t va)
pdp_idx = pmap_pdpe_index(va);
pdpe += pdp_idx;
if (*pdpe == 0) {
-   m = efi_1t1_page(1 + NPML4EPG + (pml4_idx + 1) * (pdp_idx + 1));
+   m = efi_1t1_page();
mphys =  VM_PAGE_TO_PHYS(m);
*pdpe = mphys | X86_PG_RW | X86_PG_V;
} else {
@@ -128,8 +129,7 @@ efi_1t1_pte(vm_offset_t va)
pd_idx = pmap_pde_index(va);
pde += pd_idx;
if (*pde == 0) {
-   m = efi_1t1_page(1 + NPML4EPG + NPML4EPG * NPDPEPG +
-   (pml4_idx + 1) * (pdp_idx + 1) * (pd_idx + 1));
+   m = efi_1t1_page();
mphys = VM_PAGE_TO_PHYS(m);
*pde = mphys | X86_PG_RW | X86_PG_V;
} else {
@@ -155,8 +155,9 @@ efi_create_1t1_map(struct efi_md *map, int ndesc, int 
obj_1t1_pt = vm_pager_allocate(OBJT_PHYS, NULL, ptoa(1 +
NPML4EPG + NPML4EPG * NPDPEPG + NPML4EPG * NPDPEPG * NPDEPG),
VM_PROT_ALL, 0, NULL);
+   efi_1t1_idx = 0;
VM_OBJECT_WLOCK(obj_1t1_pt);
-   efi_pml4_page = efi_1t1_page(0);
+   efi_pml4_page = efi_1t1_page();
VM_OBJECT_WUNLOCK(obj_1t1_pt);
efi_pml4 = (pml4_entry_t *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(efi_pml4_page));
pmap_pinit_pml4(efi_pml4_page);

Modified: head/sys/arm64/arm64/efirt_machdep.c
==
--- head/sys/arm64/arm64/efirt_machdep.cTue Nov 28 06:31:39 2017
(r326310)
+++ head/sys/arm64/arm64/efirt_machdep.cTue Nov 28 09:34:43 2017
(r326311)
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
 static vm_object_t obj_1t1_pt;
 static vm_page_t efi_l0_page;
 static pd_entry_t *efi_l0;
+static vm_pindex_t efi_1t1_idx;
 
 void
 efi_destroy_1t1_map(void)
@@ -86,10 +87,10 @@ efi_destroy_1t1_map(void)
 }
 
 static vm_page_t
-efi_1t1_page(vm_pindex_t idx)
+efi_1t1_page(void)
 {
 
-   return (vm_page_grab(obj_1t1_pt, idx, VM_ALLOC_NOBUSY |
+   return (vm_page_grab(obj_1t1_pt, efi_1t1_idx++, VM_ALLOC_NOBUSY |
VM_ALLOC_WIRED | VM_ALLOC_ZERO));
 }
 
@@ -105,7 +106,7 @@ efi_1t1_l3(vm_offset_t va)
l0_idx = pmap_l0_index(va);
l0 = &efi_l0[l0_idx];
if (*l0 == 0) {
-   m = efi_1t1_page(1 + l0_idx);
+   m = efi_1t1_page();
mphys = VM_PAGE_TO_PHYS(m);
*l0 = mphys | L0_TABLE;
} else {
@@ -116,7 +117,7 @@ efi_1t1_l3(vm_offset_t va)
l1_idx = pmap_l1_index(va);
l1 += l1_idx;
if (*l1 == 0) {
-   m = efi_1t1_page(1 + L0_ENTRIES + (l0_idx + 1) * (l1_idx + 1));
+   m = efi_1t1_page();
mphys = VM_PAGE_TO_PHYS(m);
*l1 = mphys | L1_TABLE;
} else {
@@ -127,8 +128,7 @@ efi_1t1_l3(vm_offset_t va)
l2_idx = pmap_l2_index(va);
l2 += l2_idx;
if (*l2 == 0) {
-   m = efi_1t1_page(1 + L0_ENTRIES 

svn commit: r326363 - in head/sys/dev/mlx5: . mlx5_en

2017-11-29 Thread Konstantin Belousov
Author: kib
Date: Wed Nov 29 10:04:11 2017
New Revision: 326363
URL: https://svnweb.freebsd.org/changeset/base/326363

Log:
  Implement hardware mlx5(4) rx timestamps.
  
  Driver support is only provided for ConnectX4/5.
  
  System-time timestamp is calculated based on the free-running counter
  timestamp provided by hardware.  Driver periodically samples the
  counter to calibrate it against the system clock and uses linear
  interpolation to convert.  Stability of the crystal which drives the
  clock is +-50 ppm at the operational temperature, which makes the
  algorithm good enough.
  
  The calculation is somewhat delicate because all values are 64bit and
  overflow the naive formula for linear interpolation.  The calculation
  drops the least significant bits in advance, see the PREC shift in
  mlx5_mbuf_tstmp().
  
  Hardware stamps can be turned off by 'ifconfig mceN -hwrxtsmp'.  Buggy
  firmware might result in small but visible errors in the reported
  timestamps, detectable e.g. by nonsensical (negative) RTT values for
  LAN pings.
  
  Reviewed by:  gallatin, hselasky
  Sponsored by: Mellanox Technologies
  Differential revision:https://reviews.freebsd.org/D12638

Modified:
  head/sys/dev/mlx5/device.h
  head/sys/dev/mlx5/mlx5_en/en.h
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
  head/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c

Modified: head/sys/dev/mlx5/device.h
==
--- head/sys/dev/mlx5/device.h  Wed Nov 29 09:40:11 2017(r326362)
+++ head/sys/dev/mlx5/device.h  Wed Nov 29 10:04:11 2017(r326363)
@@ -619,6 +619,8 @@ struct mlx5_cqe64 {
u8  op_own;
 };
 
+#defineMLX5_CQE_TSTMP_PTP  (1ULL << 63)
+
 static inline bool get_cqe_lro_timestamp_valid(struct mlx5_cqe64 *cqe)
 {
return (cqe->lro_tcppsh_abort_dupack >> 7) & 1;

Modified: head/sys/dev/mlx5/mlx5_en/en.h
==
--- head/sys/dev/mlx5/mlx5_en/en.h  Wed Nov 29 09:40:11 2017
(r326362)
+++ head/sys/dev/mlx5/mlx5_en/en.h  Wed Nov 29 10:04:11 2017
(r326363)
@@ -650,6 +650,16 @@ struct mlx5e_flow_tables {
struct mlx5e_flow_table inner_rss;
 };
 
+#defineMLX5E_TSTMP_PREC 10
+
+struct mlx5e_clbr_point {
+   uint64_t base_curr;
+   uint64_t base_prev;
+   uint64_t clbr_hw_prev;
+   uint64_t clbr_hw_curr;
+   u_int clbr_gen;
+};
+
 struct mlx5e_priv {
/* priv data path fields - start */
int order_base_2_num_channels;
@@ -704,6 +714,12 @@ struct mlx5e_priv {
int media_active_last;
 
struct callout watchdog;
+
+   struct callout tstmp_clbr;
+   int clbr_done;
+   int clbr_curr;
+   struct mlx5e_clbr_point clbr_points[2];
+   u_int   clbr_gen;
 };
 
 #defineMLX5E_NET_IP_ALIGN 2

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cWed Nov 29 09:40:11 2017
(r326362)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cWed Nov 29 10:04:11 2017
(r326363)
@@ -154,6 +154,8 @@ static const struct {
 
 MALLOC_DEFINE(M_MLX5EN, "MLX5EN", "MLX5 Ethernet");
 
+static SYSCTL_NODE(_hw, OID_AUTO, mlx5, CTLFLAG_RW, 0, "MLX5 driver 
parameters");
+
 static void
 mlx5e_update_carrier(struct mlx5e_priv *priv)
 {
@@ -637,6 +639,109 @@ mlx5e_disable_async_events(struct mlx5e_priv *priv)
mtx_unlock(&priv->async_events_mtx);
 }
 
+static void mlx5e_calibration_callout(void *arg);
+static int mlx5e_calibration_duration = 20;
+static int mlx5e_fast_calibration = 1;
+static int mlx5e_normal_calibration = 30;
+
+static SYSCTL_NODE(_hw_mlx5, OID_AUTO, calibr, CTLFLAG_RW, 0,
+"MLX5 timestamp calibration parameteres");
+
+SYSCTL_INT(_hw_mlx5_calibr, OID_AUTO, duration, CTLFLAG_RWTUN,
+&mlx5e_calibration_duration, 0,
+"Duration of initial calibration");
+SYSCTL_INT(_hw_mlx5_calibr, OID_AUTO, fast, CTLFLAG_RWTUN,
+&mlx5e_fast_calibration, 0,
+"Recalibration interval during initial calibration");
+SYSCTL_INT(_hw_mlx5_calibr, OID_AUTO, normal, CTLFLAG_RWTUN,
+&mlx5e_normal_calibration, 0,
+"Recalibration interval during normal operations");
+
+/*
+ * Ignites the calibration process.
+ */
+static void
+mlx5e_reset_calibration_callout(struct mlx5e_priv *priv)
+{
+
+   if (priv->clbr_done == 0)
+   mlx5e_calibration_callout(priv);
+   else
+   callout_reset_curcpu(&priv->tstmp_clbr, (priv->clbr_done <
+   mlx5e_calibration_duration ? mlx5e_fast_calibration :
+   mlx5e_normal_calibration) * hz, mlx5e_calibration_callout,
+   priv);
+}
+
+static uint64_t
+mlx5e_timespec2usec(const struct timespec *ts)
+{
+
+   return ((uint64_t)ts->tv_sec * 10 + ts->tv_nsec);
+}
+
+static uint64_t
+mlx5e_hw_clock(struc

Re: svn commit: r326218 - head/sys/kern

2017-11-29 Thread Konstantin Belousov
On Wed, Nov 29, 2017 at 04:33:50PM +0100, Hans Petter Selasky wrote:
> Hi Nathan,
> 
> The chunk below causes sched_pin() to stop working and should be removed 
> from your commit ??!!
> 
> It probably explains the hangs seen recently reported by various brave 
> people running 12-current :-)
> 
> Specifically I see threads migrating between CPUs when td->td_pinned > 0 
> using the LinuxKPI RCU API, which in turn leads to a hang when trying to 
> synchronize RCU.
> 
> --HPS
> 
> diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
> index 5c8bae5afa1..bd4b505f6c3 100644
> --- a/sys/kern/sched_ule.c
> +++ b/sys/kern/sched_ule.c
> @@ -2453,7 +2453,7 @@ sched_add(struct thread *td, int flags)
>   * Pick the destination cpu and if it isn't ours transfer to the
>   * target cpu.
>   */
> -   td_get_sched(td)->ts_cpu = curcpu; /* Pick something valid to 
> start */
> +// td_get_sched(td)->ts_cpu = curcpu; /* Pick something valid to 
> start */
>  cpu = sched_pickcpu(td, flags);
>  tdq = sched_setcpu(td, cpu, flags);
>  tdq_add(tdq, td, flags);

To clarify.  It seems that this change breaks sched_bind().

It might be that LinuxKPI does use sched_pin() in somewhat questionable
way. Namely, the code puts the thread off the CPU (e.g. by taking a
lock). Then, is it guaranteed that the pinned thread returns to the same
cpu after sched_add() ?

I think that the second behaviour is not guaranteed, but it might
happens by the way the things are arranged. If guaranteed, then the
sched_pin() breakage is same as for sched_bind().
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326408 - in head: lib/libfetch sbin/recoverdisk share/examples/BSD_daemon share/examples/libusb20 sys/dev/led sys/dev/md sys/dev/mn sys/dev/ppbus sys/i386/i386 sys/kern sys/sys sys/x8

2017-11-30 Thread Konstantin Belousov
On Thu, Nov 30, 2017 at 08:33:45PM +, Pedro F. Giffuni wrote:
>   head/usr.sbin/ctm/ctm/ctm.c
>   head/usr.sbin/ctm/ctm/ctm_ed.c
>   head/usr.sbin/ctm/ctm/ctm_input.c
>   head/usr.sbin/ctm/ctm/ctm_pass1.c
>   head/usr.sbin/ctm/ctm/ctm_pass2.c
>   head/usr.sbin/ctm/ctm/ctm_pass3.c
>   head/usr.sbin/ctm/ctm/ctm_passb.c
>   head/usr.sbin/ctm/ctm/ctm_syntax.c

Does ctm in base serve any purpose ?

README file in the usr.sbin/ctm seems to claim that ctm is generic-purpose
tree diff and apply tool.  But also, near the end, the same text claims
that cvsup has replaced the ctm, hmm. Does anybody use ctm for any purpose,
not necessary keeping up FreeBSD source tree ?
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326424 - head/sys/vm

2017-12-01 Thread Konstantin Belousov
Author: kib
Date: Fri Dec  1 10:53:08 2017
New Revision: 326424
URL: https://svnweb.freebsd.org/changeset/base/326424

Log:
  Add comment for vm_map_find_min().
  
  Reviewed by:  alc
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days
  X-Differential revision:  https://reviews.freebsd.org/D13155

Modified:
  head/sys/vm/vm_map.c

Modified: head/sys/vm/vm_map.c
==
--- head/sys/vm/vm_map.cFri Dec  1 10:25:52 2017(r326423)
+++ head/sys/vm/vm_map.cFri Dec  1 10:53:08 2017(r326424)
@@ -1558,6 +1558,18 @@ again:
return (result);
 }
 
+/*
+ * vm_map_find_min() is a variant of vm_map_find() that takes an
+ * additional parameter (min_addr) and treats the given address
+ * (*addr) differently.  Specifically, it treats *addr as a hint
+ * and not as the minimum address where the mapping is created.
+ *
+ * This function works in two phases.  First, it tries to
+ * allocate above the hint.  If that fails and the hint is
+ * greater than min_addr, it performs a second pass, replacing
+ * the hint with min_addr as the minimum address for the
+ * allocation.
+ */
 int
 vm_map_find_min(vm_map_t map, vm_object_t object, vm_ooffset_t offset,
 vm_offset_t *addr, vm_size_t length, vm_offset_t min_addr,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326429 - head/sys/kern

2017-12-01 Thread Konstantin Belousov
Author: kib
Date: Fri Dec  1 11:18:19 2017
New Revision: 326429
URL: https://svnweb.freebsd.org/changeset/base/326429

Log:
  Destroy seltd st_mtx and st_wait in seltdfini().
  
  A correct destruction is important for WITNESS(4) and LOCK_PROFILING(9).
  
  Submitted by: Sebastian Huber 
  MFC after:1 week

Modified:
  head/sys/kern/sys_generic.c

Modified: head/sys/kern/sys_generic.c
==
--- head/sys/kern/sys_generic.c Fri Dec  1 11:14:13 2017(r326428)
+++ head/sys/kern/sys_generic.c Fri Dec  1 11:18:19 2017(r326429)
@@ -1884,6 +1884,8 @@ seltdfini(struct thread *td)
if (stp->st_free2)
uma_zfree(selfd_zone, stp->st_free2);
td->td_sel = NULL;
+   cv_destroy(&stp->st_wait);
+   mtx_destroy(&stp->st_mtx);
free(stp, M_SELECT);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326436 - head/usr.bin/vmstat

2017-12-01 Thread Konstantin Belousov
Author: kib
Date: Fri Dec  1 22:38:28 2017
New Revision: 326436
URL: https://svnweb.freebsd.org/changeset/base/326436

Log:
  vmstat: fix style(9) violations and bump WARNS.
  
  Based on the patch by:Pawel Biernacki 
  Sponsored by: Mysterious Code Ltd. (Pawel),
  The FreeBSD Foundation (me)
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D13228

Modified:
  head/usr.bin/vmstat/Makefile
  head/usr.bin/vmstat/vmstat.c

Modified: head/usr.bin/vmstat/Makefile
==
--- head/usr.bin/vmstat/MakefileFri Dec  1 22:26:36 2017
(r326435)
+++ head/usr.bin/vmstat/MakefileFri Dec  1 22:38:28 2017
(r326436)
@@ -5,6 +5,6 @@ PROG=   vmstat
 MAN=   vmstat.8
 LIBADD=devstat kvm memstat xo util
 
-WARNS?=1
+WARNS?=6
 
 .include 

Modified: head/usr.bin/vmstat/vmstat.c
==
--- head/usr.bin/vmstat/vmstat.cFri Dec  1 22:26:36 2017
(r326435)
+++ head/usr.bin/vmstat/vmstat.cFri Dec  1 22:38:28 2017
(r326436)
@@ -85,50 +85,38 @@ __FBSDID("$FreeBSD$");
 
 static char da[] = "da";
 
+enum x_stats { X_SUM, X_HZ, X_STATHZ, X_NCHSTATS, X_INTRNAMES, X_SINTRNAMES,
+X_INTRCNT, X_SINTRCNT, X_DEFICIT, X_REC, X_PGIN, X_XSTATS };
+
 static struct nlist namelist[] = {
-#define X_SUM  0
-   { "_vm_cnt" },
-#define X_HZ   1
-   { "_hz" },
-#define X_STATHZ   2
-   { "_stathz" },
-#define X_NCHSTATS 3
-   { "_nchstats" },
-#defineX_INTRNAMES 4
-   { "_intrnames" },
-#defineX_SINTRNAMES5
-   { "_sintrnames" },
-#defineX_INTRCNT   6
-   { "_intrcnt" },
-#defineX_SINTRCNT  7
-   { "_sintrcnt" },
+   [X_SUM] = { .n_name = "_vm_cnt", },
+   [X_HZ] = { .n_name = "_hz", },
+   [X_STATHZ] = { .n_name = "_stathz", },
+   [X_NCHSTATS] = { .n_name = "_nchstats", },
+   [X_INTRNAMES] = { .n_name = "_intrnames", },
+   [X_SINTRNAMES] = { .n_name = "_sintrnames", },
+   [X_INTRCNT] = { .n_name = "_intrcnt", },
+   [X_SINTRCNT] = { .n_name = "_sintrcnt", },
 #ifdef notyet
-#defineX_DEFICIT   XXX
-   { "_deficit" },
-#define X_REC  XXX
-   { "_rectime" },
-#define X_PGIN XXX
-   { "_pgintime" },
-#defineX_XSTATSXXX
-   { "_xstats" },
-#define X_END  XXX
-#else
-#define X_END  8
+   [X_DEFICIT] = { .n_name = "_deficit", },
+   [X_REC] = { .n_name = "_rectime", },
+   [X_PGIN] = { .n_name = "_pgintime", },
+   [X_XSTATS] = { .n_name = "_xstats", },
 #endif
-   { "" },
+   { .n_name = NULL, },
 };
 
-static struct statinfo cur, last;
-static int num_devices, maxshowdevs;
-static long generation;
-static struct device_selection *dev_select;
-static int num_selected;
 static struct devstat_match *matches;
-static int num_matches = 0;
-static int num_devices_specified, num_selections;
-static long select_generation;
-static char **specified_devices;
+static struct device_selection *dev_select;
+static struct statinfo cur, last;
 static devstat_select_mode select_mode;
+static size_t size_cp_times;
+static long *cur_cp_times, *last_cp_times;
+static long generation, select_generation;
+static int hz, hdrcnt, maxshowdevs;
+static int num_devices, num_devices_specified;
+static int num_matches, num_selected, num_selections;
+static char **specified_devices;
 
 static struct __vmmeter {
uint64_t v_swtch;
@@ -183,7 +171,7 @@ static struct __vmmeter {
 } sum, osum;
 
 #defineVMSTAT_DEFAULT_LINES20  /* Default number of 
`winlines'. */
-volatile sig_atomic_t wresized;/* Tty resized, when non-zero. 
*/
+static volatile sig_atomic_t wresized; /* Tty resized when non-zero. */
 static int winlines = VMSTAT_DEFAULT_LINES; /* Current number of tty rows. */
 
 static int aflag;
@@ -191,7 +179,7 @@ static int  nflag;
 static int Pflag;
 static int hflag;
 
-static kvm_t   *kd;
+static kvm_t   *kd;
 
 #defineFORKSTAT0x01
 #defineINTRSTAT0x02
@@ -199,11 +187,11 @@ static kvm_t   *kd;
 #defineSUMSTAT 0x08
 #defineTIMESTAT0x10
 #defineVMSTAT  0x20
-#define ZMEMSTAT   0x40
+#defineZMEMSTAT0x40
 #defineOBJSTAT 0x80
 
 static voidcpustats(void);
-static voidpcpustats(int, u_long, int);
+static voidpcpustats(u_long, int);
 static voiddevstats(void);
 static voiddoforkst(void);
 static voiddointr(unsigned int, int);
@@ -214,7 +202,6 @@ static void domemstat_malloc(void);
 static voiddomemstat_zone(void);
 static voidkread(int, void *, size_t);
 static voidkreado(int, void *, size_t, size_t);
-static char*kgetstr(const char *);
 static voidneedhdr(int);
 stat

Re: svn commit: r326554 - in head: . usr.bin/sponge usr.bin/sponge/tests usr.bin/tee

2017-12-05 Thread Konstantin Belousov
On Tue, Dec 05, 2017 at 03:55:10AM +, Eitan Adler wrote:
> Author: eadler
> Date: Tue Dec  5 03:55:10 2017
> New Revision: 326554
> URL: https://svnweb.freebsd.org/changeset/base/326554
> 
> Log:
>   sponge(1): initial commit
>   
>   sponge(1) is a utility that reads input until
>   complete, then opens the output file, then
>   writes to it. This makes it useful in pipelines
>   that read and write to the same file.
>   
>   Reviewed by:wblock, jilles, imp, cem, danfe (all: various 
> iterations)
>   Inspired by:https://joeyh.name/code/moreutils/
> 
> Added:
>   head/usr.bin/sponge/
>   head/usr.bin/sponge/Makefile   (contents, props changed)
>   head/usr.bin/sponge/sponge.1   (contents, props changed)
>   head/usr.bin/sponge/sponge.c   (contents, props changed)
>   head/usr.bin/sponge/tests/
>   head/usr.bin/sponge/tests/Makefile   (contents, props changed)
>   head/usr.bin/sponge/tests/Makefile.depend   (contents, props changed)
>   head/usr.bin/sponge/tests/sponge_test.sh   (contents, props changed)
> Modified:
>   head/.arclint
>   head/usr.bin/tee/tee.1
> 
> Modified: head/.arclint
> ==
> --- head/.arclint Tue Dec  5 02:23:36 2017(r326553)
> +++ head/.arclint Tue Dec  5 03:55:10 2017(r326554)
> @@ -9,7 +9,8 @@
>"type": "spelling"
>  },
>  "chmod": {
> -  "type": "chmod"
> +  "type": "chmod",
> +  "exclude": "(/tests/)"
>  },
>  "merge-conflict": {
>"type": "merge-conflict"
> 
> Added: head/usr.bin/sponge/Makefile
> ==
> --- /dev/null 00:00:00 1970   (empty, because file is newly added)
> +++ head/usr.bin/sponge/Makefile  Tue Dec  5 03:55:10 2017
> (r326554)
> @@ -0,0 +1,8 @@
> +# $FreeBSD$
> +
> +PROG=sponge
> +
> +HAS_TESTS=
> +SUBDIR.${MK_TESTS}+= tests
> +
> +.include 
> 
> Added: head/usr.bin/sponge/sponge.1
> ==
> --- /dev/null 00:00:00 1970   (empty, because file is newly added)
> +++ head/usr.bin/sponge/sponge.1  Tue Dec  5 03:55:10 2017
> (r326554)
> @@ -0,0 +1,75 @@
> +.\"  Eitan Adler.  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.
> +.\" 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 REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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$
> +.\"
> +.Dd November 1, 2017
> +.Dt SPONGE 1
> +.Os
> +.Sh NAME
> +.Nm sponge
> +.Nd buffer stdin and write to stdout
> +.Sh SYNOPSIS
> +.Nm
> +.Op Fl a
> +.Ar filename
> +.Sh DESCRIPTION
> +The
> +.Nm
> +utility reads standard in until complete, then opens
> +the output file and writes to it.
> +This makes it useful in pipelines that read a file and then write to it.
> +These options are available:
> +.Bl -tag -width indent
> +.It Fl a
> +Open
> +.Ar filename
> +in append mode.
> +.El
> +.Pp
> +If an attempt to allocate memory fails,
> +.Nm
> +fails without output.
> +The file is written even if earlier components
> +of the pipeline failed.
> +.Sh SEE ALSO
> +.Xr builtin 1 ,
> +.Xr csh 1 ,
> +.Xr getrusage 2 ,
> +.Xr tee 1 ,
> +.Xr wait 2
> +.Sh EXIT STATUS
> +.Ex -std
> +.Sh EXAMPLES
> +A
> +.Pa file
> +can be be sorted "in place" by executing
> +.Cm sort file | sponge file
> +.Sh HISTORY
> +The
> +.Nm
> +utility was written by
> +.An Eitan Adler Aq Mt ead...@freebsd.org
> +and first appeared
> +in
> +.Fx 12.0 .
> 
> Added: head/usr.bin/sponge/sponge.c
> ==
> --- /dev/null 00:00:00 1970   (empty, because file is newly added)
> +++ head/usr.bin/sponge/sponge.c  Tue Dec  5 03:55:10 2017

Re: svn commit: r326554 - in head: . usr.bin/sponge usr.bin/sponge/tests usr.bin/tee

2017-12-05 Thread Konstantin Belousov
On Tue, Dec 05, 2017 at 02:00:00PM +0100, Hans Petter Selasky wrote:
> On 12/05/17 13:58, Rodney W. Grimes wrote:
> > Further more, why does freebsd need this in base?
> 
> Hi,
> 
> I think this is useful. It could replace the "-i " (intermediate) option 
> for "sed" for example. It avoids creating temporary files when filtering 
> files, right?

No, if process fails during the operation, user data is destroyed
irretrievable.The usual trick of creating temporary file and renaming
ensure that old file is around until all data for new file is written
into buffer cache. With some existing filesystem support, it also
guarantees that the old file is around in case of the system crash.

All this assuming the tool' code matches its description, which is not.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326657 - head/sys/ufs/ufs

2017-12-07 Thread Konstantin Belousov
Author: kib
Date: Thu Dec  7 09:05:34 2017
New Revision: 326657
URL: https://svnweb.freebsd.org/changeset/base/326657

Log:
  Fix livelock in ufsdirhash_create().
  
  When more than one thread enters ufsdirhash_create() for the same
  directory and the inode dirhash is instantiated, but the dirhash' hash
  is not, all of them lock the dirhash shared and then try to upgrade.
  Since there are several threads owning the lock shared, upgrade fails
  and the same attempt is repeated, ad infinitum.
  
  To break the lockstep, lock the dirhash in exclusive mode after the
  failed try-upgrade.
  
  Reported and tested by:   pho
  Sponsored by: Mellanox Technologies
  MFC after:1 week

Modified:
  head/sys/ufs/ufs/ufs_dirhash.c

Modified: head/sys/ufs/ufs/ufs_dirhash.c
==
--- head/sys/ufs/ufs/ufs_dirhash.c  Thu Dec  7 07:55:38 2017
(r326656)
+++ head/sys/ufs/ufs/ufs_dirhash.c  Thu Dec  7 09:05:34 2017
(r326657)
@@ -192,9 +192,11 @@ ufsdirhash_create(struct inode *ip)
struct dirhash *ndh;
struct dirhash *dh;
struct vnode *vp;
+   bool excl;
 
ndh = dh = NULL;
vp = ip->i_vnode;
+   excl = false;
for (;;) {
/* Racy check for i_dirhash to prefetch a dirhash structure. */
if (ip->i_dirhash == NULL && ndh == NULL) {
@@ -231,8 +233,11 @@ ufsdirhash_create(struct inode *ip)
ufsdirhash_hold(dh);
VI_UNLOCK(vp);
 
-   /* Acquire a shared lock on existing hashes. */
-   sx_slock(&dh->dh_lock);
+   /* Acquire a lock on existing hashes. */
+   if (excl)
+   sx_xlock(&dh->dh_lock);
+   else
+   sx_slock(&dh->dh_lock);
 
/* The hash could've been recycled while we were waiting. */
VI_LOCK(vp);
@@ -253,9 +258,10 @@ ufsdirhash_create(struct inode *ip)
 * so we can recreate it.  If we fail the upgrade, drop our
 * lock and try again.
 */
-   if (sx_try_upgrade(&dh->dh_lock))
+   if (excl || sx_try_upgrade(&dh->dh_lock))
break;
sx_sunlock(&dh->dh_lock);
+   excl = true;
}
/* Free the preallocated structure if it was not necessary. */
if (ndh) {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-11 Thread Konstantin Belousov
On Mon, Dec 11, 2017 at 04:32:37AM +, Conrad Meyer wrote:
> Author: cem
> Date: Mon Dec 11 04:32:37 2017
> New Revision: 326758
> URL: https://svnweb.freebsd.org/changeset/base/326758
> 
> Log:
>   i386: Bump KSTACK_PAGES default to match amd64
i386 is not amd64, the change is wrong.

i386 has the word size two times smaller than amd64, which makes typical
frame smaller by 30-40% over same code on amd64. Also i386 has much
smaller available KVA size (tens of MB) and KVA fragmentation is both
more severe and more fatal due to this. I expect that your change will
make any non-trivial load which creates enough threads to either fail
randomly or deadlock.

If somebody tries to fit large load onto i386 machine, he must know what to
do and how to configure the kernel to adapt to the load (which does not
require the recompilation).
>   
>   Logically, extend r286288 to cover all threads, by default.
>   
>   The world has largely moved on from i386.  Most FreeBSD users and developers
>   test on amd64 hardware.  For better or worse, we have written a non-trivial
>   amount of kernel code that relies on stacks larger than 8 kB, and it "just
>   works" on amd64, so there has been little incentive to shrink it.
>   
>   amd64 had its KSTACK_PAGES bumped to 4 back in Peter's initial AMD64 commit,
>   r114349, in 2003.  Since that time, i386 has limped along on a stack half
>   the size.  We've even observed the stack overflows years ago, but neglected
>   to fix the issue; see the 20121223 and 20150728 entries in UPDATING.
>   
>   If anyone is concerned with this change, I suggest they configure their
>   AMD64 kernels with KSTACK_PAGES 2 and fix the fallout there first.  Eugene
>   has identified a list of high stack usage functions in the first PR below.
This suggestion is completely bogus.

>   
>   PR: 219476, 224218
>   Reported by:eugen@, Shreesh Holla 
>   Relnotes:   maybe
>   Sponsored by:   Dell EMC Isilon
> 
> Modified:
>   head/sys/i386/conf/NOTES
>   head/sys/i386/include/param.h
> 
> Modified: head/sys/i386/conf/NOTES
> ==
> --- head/sys/i386/conf/NOTES  Mon Dec 11 02:44:15 2017(r326757)
> +++ head/sys/i386/conf/NOTES  Mon Dec 11 04:32:37 2017(r326758)
> @@ -968,7 +968,7 @@ devicendis
>  # KSTACK_PAGES is the number of memory pages to assign to the kernel
>  # stack of each thread.
>  
> -options  KSTACK_PAGES=3
> +options  KSTACK_PAGES=5
>  
>  # Enable detailed accounting by the PV entry allocator.
>  
> 
> Modified: head/sys/i386/include/param.h
> ==
> --- head/sys/i386/include/param.h Mon Dec 11 02:44:15 2017
> (r326757)
> +++ head/sys/i386/include/param.h Mon Dec 11 04:32:37 2017
> (r326758)
> @@ -113,7 +113,7 @@
>  #define IOPAGES  2   /* pages of i/o permission bitmap */
>  
>  #ifndef KSTACK_PAGES
> -#define KSTACK_PAGES 2   /* Includes pcb! */
> +#define KSTACK_PAGES 4   /* Includes pcb! */
>  #endif
>  #define KSTACK_GUARD_PAGES 1 /* pages of kstack guard; 0 disables */
>  #if KSTACK_PAGES < 4
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-11 Thread Konstantin Belousov
On Mon, Dec 11, 2017 at 05:26:12PM +0700, Eugene Grosbein wrote:
> On 11.12.2017 16:19, Konstantin Belousov wrote:
> > On Mon, Dec 11, 2017 at 04:32:37AM +, Conrad Meyer wrote:
> >> Author: cem
> >> Date: Mon Dec 11 04:32:37 2017
> >> New Revision: 326758
> >> URL: https://svnweb.freebsd.org/changeset/base/326758
> >>
> >> Log:
> >>   i386: Bump KSTACK_PAGES default to match amd64
> > i386 is not amd64, the change is wrong.
> > 
> > i386 has the word size two times smaller than amd64, which makes typical
> > frame smaller by 30-40% over same code on amd64. Also i386 has much
> > smaller available KVA size (tens of MB) and KVA fragmentation is both
> > more severe and more fatal due to this. I expect that your change will
> > make any non-trivial load which creates enough threads to either fail
> > randomly or deadlock.
> > 
> > If somebody tries to fit large load onto i386 machine, he must know what to
> > do and how to configure the kernel to adapt to the load (which does not
> > require the recompilation).
> 
> Its very easy to get kernel stack overflow with 11-STABLE/i386
> without any significant load due to abuse of kernel stack in many kernel 
> subsystems
> as shown in the https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219476
> 
> Contrary, "enough threads" seems to be very non-trivial number of threads
> and pretty unusual load pattern for i386 as I run several such systems
> with kern.kstack_pages=4 for quite long time and have no problems.
> No random fails, no deadlocks. And with 2 pages only 11-STABLE/i386 is just 
> unusable
> if one utilizes SCTP, IPv6, some WiFi connectivity, IPSEC or even very small 
> ZFS pool.
> 
> I still wonder if there is really such load pattern that creates "enough 
> threads"
> for i386 to make 4-pages stack troublesome.
Yes, there is such load pattern, it is when you do create threads. Your
load, as described, is static. Peter' stress2 includes some tests which
will highlight the change.

I am quite impressed by your ability to make generalization from single data
point.  Moving issues around because you care about your load, and do not
care about other usage patterns, is certainly the way to go.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326764 - head/contrib/ofed/librdmacm

2017-12-11 Thread Konstantin Belousov
Author: kib
Date: Mon Dec 11 11:57:46 2017
New Revision: 326764
URL: https://svnweb.freebsd.org/changeset/base/326764

Log:
  ofed: Remove duplicated symbols from the version file.
  
  ld.bfd accepts multiple listing of the same symbol in the version script.
  lld is stricter and errors out.  Since arm64 and sometimes amd64 use lld,
  we should correct this cosmetic issue.
  
  Sponsored by: Mellanox Technologies
  Reviewed by:  hselasky
  Differential revision:https://reviews.freebsd.org/D13329

Modified:
  head/contrib/ofed/librdmacm/librdmacm.map

Modified: head/contrib/ofed/librdmacm/librdmacm.map
==
--- head/contrib/ofed/librdmacm/librdmacm.map   Mon Dec 11 05:21:48 2017
(r326763)
+++ head/contrib/ofed/librdmacm/librdmacm.map   Mon Dec 11 11:57:46 2017
(r326764)
@@ -60,10 +60,6 @@ RDMACM_1.0 {
rsetsockopt;
rgetsockopt;
rfcntl;
-   rpoll;
-   rselect;
-   rdma_get_src_port;
-   rdma_get_dst_port;
riomap;
riounmap;
riowrite;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326765 - head/contrib/ofed/include

2017-12-11 Thread Konstantin Belousov
Author: kib
Date: Mon Dec 11 11:59:45 2017
New Revision: 326765
URL: https://svnweb.freebsd.org/changeset/base/326765

Log:
  ofed: Define barriers for mips and arm.
  
  I used the strongest barriers available on the architectures, so if
  the future analysis show that it is excessive, the barriers could be
  relaxed. Still, it is unlikely that it is meaningful to run IB on 32bit
  ARM or current MIPS machines, so the change is to make WITH_OFED to pass
  tinderbox.
  
  Sponsored by: Mellanox Technologies
  Reviewed by:  hselasky
  Differential revision:https://reviews.freebsd.org/D13329

Modified:
  head/contrib/ofed/include/udma_barrier.h

Modified: head/contrib/ofed/include/udma_barrier.h
==
--- head/contrib/ofed/include/udma_barrier.hMon Dec 11 11:57:46 2017
(r326764)
+++ head/contrib/ofed/include/udma_barrier.hMon Dec 11 11:59:45 2017
(r326765)
@@ -96,6 +96,14 @@
 #define udma_to_device_barrier() asm volatile("dsb st" ::: "memory");
 #elif defined(__sparc__) || defined(__s390x__)
 #define udma_to_device_barrier() asm volatile("" ::: "memory")
+#elif defined(__mips__)
+#include 
+#include 
+#define udma_to_device_barrier() mips_sync()
+#elif defined(__arm__)
+#include 
+#include 
+#define udma_to_device_barrier() dmb()
 #else
 #error No architecture specific memory barrier defines found!
 #endif
@@ -128,6 +136,10 @@
 #define udma_from_device_barrier() asm volatile("dsb ld" ::: "memory");
 #elif defined(__sparc__) || defined(__s390x__)
 #define udma_from_device_barrier() asm volatile("" ::: "memory")
+#elif defined(__mips__)
+#define udma_from_device_barrier() mips_sync()
+#elif defined(__arm__)
+#define udma_from_device_barrier() dmb()
 #else
 #error No architecture specific memory barrier defines found!
 #endif
@@ -192,6 +204,10 @@
 #define mmio_flush_writes() asm volatile("dsb st" ::: "memory");
 #elif defined(__sparc__) || defined(__s390x__)
 #define mmio_flush_writes() asm volatile("" ::: "memory")
+#elif defined(__mips__)
+#define mmio_flush_writes() mips_sync()
+#elif defined(__arm__)
+#define mmio_flush_writes() dmb()
 #else
 #error No architecture specific memory barrier defines found!
 #endif
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-11 Thread Konstantin Belousov
On Mon, Dec 11, 2017 at 06:03:36PM +0700, Eugene Grosbein wrote:
> I do not try to contradict other usage patterns. In fact, I'm eager to know
> a practical example of such pattern: a task, an application, anything real?
Plain workstation use, like X11+browser+editor+some other programs easily
allocates 1000+ threads.  It was still possible to use 32bit x86 for that,
of course in max memory config without PAE, and without ZFS.  Add some
load that involves network, for instance torrent client, to establish the
pressure on KVA.

I am almost sure that users would get troubles now.

> 
> I already know how to bring FreeBSD down to its kneels using stress tests
> but that's not what I'm looking for in this case of kstack_pages.
> 
Stress test is useful due to its canary nature.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-11 Thread Konstantin Belousov
On Mon, Dec 11, 2017 at 07:09:10AM -0800, Rodney W. Grimes wrote:
> The current comment about a pcb, I thought that code was changed
> so we only put the pointer to a pcb on the stack.

pcb is on top of the stack, followed by the userspace FPU registers save
area.  I do not see any sense in existence of pcb in modern kernel, it is
a remnant of the user area that was swappable.  Currently pcb is swappable
as well, but the value of this is much less then the overhead we pay by
the stack space reduction.

FPU save area is the on of the problem which makes us increase the amd64
stack size, AVX or even AVX512 make the things much worse.  It is unlikely
that somebody would run 32bit kernel on machine capable of that extensions,
i.e. Haswell or Skylake.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-11 Thread Konstantin Belousov
On Mon, Dec 11, 2017 at 07:33:08AM -0800, Rodney W. Grimes wrote:
> > On Mon, Dec 11, 2017 at 07:09:10AM -0800, Rodney W. Grimes wrote:
> > > The current comment about a pcb, I thought that code was changed
> > > so we only put the pointer to a pcb on the stack.
> > 
> > pcb is on top of the stack, followed by the userspace FPU registers save
> > area.  I do not see any sense in existence of pcb in modern kernel, it is
> > a remnant of the user area that was swappable.  Currently pcb is swappable
> > as well, but the value of this is much less then the overhead we pay by
> > the stack space reduction.
> 
> How about KSTACK_PAGES should be KSTAKE_BYTES/PAGESIZE, and we
> need a much better formula for define of KSTACK_BYTES so that
> these facts are more accurately defined?
The FPU save area size depends on CPU we booted on, so if we increase
(or decrease) it statically, we make a decision that is not good for
one or another generation of processors.

> 
> And a compile time assert if this ever growes to something unreasonable
> that would cause other issues.
So far it is an overkill, Intel did not passed the page boundary with all
extensions defined.

> 
> I fully agree with you that just bumping KSTACK_PAGES is very much
> the wrong way to fix the i386 issue of certain code not running,
> it is that code that should be examined for over usage of the stack.
In fact there is a tunable which I added to avoid recompiling kernel if
specific load requires large stack, keeping ZFS in mind.

> 
> I can assert that the base i386 system is very usable for tons of
> things without this change, I have at least 30 VM's running FreeBSD
> 11.1/i386 in some very small footprints, typically 64MB, that have
> zero issues.  But then they are not using any of the code that
> sited as problem areas.
> 
> > FPU save area is the on of the problem which makes us increase the amd64
> > stack size, AVX or even AVX512 make the things much worse.  It is unlikely
> > that somebody would run 32bit kernel on machine capable of that extensions,
> > i.e. Haswell or Skylake.
> 
> Your igonoring the virutalization world, host is a skylake or haswell, guest
> is i386 as it has small memory needs and no use to waste half of all pointers.
If you are serious about avoiding the waste, then you would also disable
unused extensions eating save area space, e.g. AVX512.  AVX might be still
useful (but not required) if AESNI or SHA extensions are used.

> 
> We need to break the developers model that i386 is dead and that i386 is
> not running on extremly modern hardware due to the factor of virtualization.
> 
> Output from one of my VM's running inside bhyve:
> 
>  # uname -a
> FreeBSD filestore.dnsmgr.net 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: 
> Fri Jul 21 04:10:47 UTC 2017 
> r...@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  i386
> 
>  # dmesg | head -24
> Copyright (c) 1992-2017 The FreeBSD Project.
> Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
> The Regents of the University of California. All rights reserved.
> FreeBSD is a registered trademark of The FreeBSD Foundation.
> FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017
> r...@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
> FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 
> 4.0.0)
> VT(vga): resolution 640x480
> info: [drm] Initialized drm 1.1.0 20060810
> CPU: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz (2494.39-MHz K8-class CPU)
This is quite old processor, IvyBridge is 6 generations old :).
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-14 Thread Konstantin Belousov
On Thu, Dec 14, 2017 at 06:34:21PM +0700, Eugene Grosbein wrote:
> On 13.12.2017 04:55, John Baldwin wrote:
> > On 12/12/17 3:09 PM, Eugene Grosbein wrote:
> >> On 13.12.2017 02:32, John Baldwin wrote:
> >>
> >>> Certainly for MIPS I have found that compiling with clang
> >>> instead of gcc for mips64 gives a kernel that panics for stack overflow 
> >>> for any
> >>> use of NFS.  It might be that this is due to something MIPS-specific, but 
> >>> it
> >>> might be worthwhile retesting with kstack_pages=2 and building the kernel
> >>> with CROSS_TOOLCHAIN=i386-gcc after installing the appropriate package.
> >>
> >> You may want to check NFS code that uses stack heavily.
> >> Here are numbers for i386 (bytes-on-stack, module, what function):
> >>
> >> 1344 nfs_nfsdport.o :
> >> 1152 nfs_nfsdserv.o :
> >> 1128 nfs_nfsdserv.o :
> >> 952 nfs_nfsdserv.o :
> >> 664 nfs_nfsdserv.o :
> >> 640 nfs_nfsdserv.o :
> >> 624 nfs_nfsdserv.o :
> >> 608 nfs_nfsdserv.o :
> >> 600 nfs_clvfsops.o :
> > 
> > My point is that you should compare gcc with clang as 10.x switched to
> > clang and that may be a factor in the stack overflows beginning with 10.x.
> 
> I think thats's NFS code who is guilty. You can see example of amd64 (sic!) 
> kstack exhaustion
> due to 40+ frames deep call chain here:
> 
> https://lists.freebsd.org/pipermail/freebsd-stable/2017-July/087429.html

Yes, NFS crosses network/VFS and often VM boundaries, so each subsystem
adds its usual stack use footprint to the overall picture.  NFS reconnect
is especially hard in this regard, and in case the direct dispatch is
triggered (in this case over loopback) machine has no chance.

The backtrace you cited just reinforces the point that the i386 commit
is wrong. It breaks the workload we aims as the main FreeBSD target,
which is generic-purpose Unix workstation or server. The commit tries
to make defaults fit for specific appliance load of router with IPSEC
or ZFS on i386, which require extensive tuning on i386 anyway. Worse,
as you prove above, the commit in fact does not fix the issues, it only
papers over them and move easily triggered faults from one configuration
to another.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-14 Thread Konstantin Belousov
On Thu, Dec 14, 2017 at 07:04:57PM +0700, Eugene Grosbein wrote:
> On 14.12.2017 18:51, Konstantin Belousov wrote:
> 
> >> I think thats's NFS code who is guilty. You can see example of amd64 
> >> (sic!) kstack exhaustion
> >> due to 40+ frames deep call chain here:
> >>
> >> https://lists.freebsd.org/pipermail/freebsd-stable/2017-July/087429.html
> > 
> > Yes, NFS crosses network/VFS and often VM boundaries, so each subsystem
> > adds its usual stack use footprint to the overall picture.  NFS reconnect
> > is especially hard in this regard, and in case the direct dispatch is
> > triggered (in this case over loopback) machine has no chance.
> > 
> > The backtrace you cited just reinforces the point that the i386 commit
> > is wrong. It breaks the workload we aims as the main FreeBSD target,
> > which is generic-purpose Unix workstation or server. The commit tries
> > to make defaults fit for specific appliance load of router with IPSEC
> > or ZFS on i386, which require extensive tuning on i386 anyway. Worse,
> > as you prove above, the commit in fact does not fix the issues, it only
> > papers over them and move easily triggered faults from one configuration
> > to another.
> 
> Modern FreeBSD usage as workstation/server should not exclude IPv6, SCTP, 
> WiFi,
> and even ZFS nor IPSEC for i386. GENERIC kernel should not panic due to low 
> volume
> network activity with default settings.
And two ponies should be given to everybody who wishes for them.

> 
> Perhaps, it's time to make KVA_PAGES loader tunnable too?
Sure, make it the tunable.  Just to make you know in advance, this is quite
delicate.

> And/or increase its default for i386 upto some value corresponding to stable 
> management
> of kern.threads.max_threads_per_proc=1500 (by default) with kstack_pages=4 ?
> 
> Maybe, KVA_PAGES=384 (1.5GB for 1500 threads)?
Sigh. This would make i386 even less usable for everybody, perhaps
except you. Because default 3G of UVA is too small for some common tasks
(thanks clang, but also e.g. pypy), and you reduce the user address
space even more.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326851 - head/sys/fs/devfs

2017-12-14 Thread Konstantin Belousov
Author: kib
Date: Thu Dec 14 13:41:11 2017
New Revision: 326851
URL: https://svnweb.freebsd.org/changeset/base/326851

Log:
  In devfs_lookupx() dotdot lookup case, avoid dereferencing
  dvp->v_mount after dvp is unlocked.
  
  The vnode might be reclaimed after unlock, so v_mount becomes NULL.
  Cache the struct mount pointer before the unlock, the struct is
  type-stable.
  
  Note that devfs_allocv() reads mp->mnt_data but does not operate on it
  further when dirent is doomed.  The unmount cannot proceed until all
  dirents are reclaimed.
  
  Reported and tested by:   pho
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week

Modified:
  head/sys/fs/devfs/devfs_vnops.c

Modified: head/sys/fs/devfs/devfs_vnops.c
==
--- head/sys/fs/devfs/devfs_vnops.c Thu Dec 14 13:19:43 2017
(r326850)
+++ head/sys/fs/devfs/devfs_vnops.c Thu Dec 14 13:41:11 2017
(r326851)
@@ -896,6 +896,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlo
struct devfs_dirent *de, *dd;
struct devfs_dirent **dde;
struct devfs_mount *dmp;
+   struct mount *mp;
struct cdev *cdev;
int error, flags, nameiop, dvplocked;
char specname[SPECNAMELEN + 1], *pname;
@@ -907,7 +908,8 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlo
td = cnp->cn_thread;
flags = cnp->cn_flags;
nameiop = cnp->cn_nameiop;
-   dmp = VFSTODEVFS(dvp->v_mount);
+   mp = dvp->v_mount;
+   dmp = VFSTODEVFS(mp);
dd = dvp->v_data;
*vpp = NULLVP;
 
@@ -940,8 +942,8 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlo
return (ENOENT);
dvplocked = VOP_ISLOCKED(dvp);
VOP_UNLOCK(dvp, 0);
-   error = devfs_allocv(de, dvp->v_mount,
-   cnp->cn_lkflags & LK_TYPE_MASK, vpp);
+   error = devfs_allocv(de, mp, cnp->cn_lkflags & LK_TYPE_MASK,
+   vpp);
*dm_unlock = 0;
vn_lock(dvp, dvplocked | LK_RETRY);
return (error);
@@ -1026,8 +1028,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlo
return (0);
}
}
-   error = devfs_allocv(de, dvp->v_mount, cnp->cn_lkflags & LK_TYPE_MASK,
-   vpp);
+   error = devfs_allocv(de, mp, cnp->cn_lkflags & LK_TYPE_MASK, vpp);
*dm_unlock = 0;
return (error);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-14 Thread Konstantin Belousov
On Thu, Dec 14, 2017 at 07:59:03PM +0700, Eugene Grosbein wrote:
> On 14.12.2017 19:26, Konstantin Belousov wrote:
> 
> > Sigh. This would make i386 even less usable for everybody, perhaps
> > except you. Because default 3G of UVA is too small for some common tasks
> > (thanks clang, but also e.g. pypy), and you reduce the user address
> > space even more.
> 
> Those who need 3GB of UVA within single process should not use 32 bit system 
> in first place, should they?

Why do you even consider it acceptable to break the configuration just
because you are not interested in the workload ?

3G cumulative VA does not translate into 3G of usable addresses: the bss
is reserved, the address space is fragmented due to need of growing
stack to not conflict with mmaped regions. As result, applications get
slightly less than 2G usable without tricks, and to apply the tricks
apps must know details of the AS layout, i.e. breaking the portability.

386 arch configuration is not perfect but it provides the main intended
service of general-purpose workstation, with some limitation caused by
32bit of address space being somewhat low for modern code. Appliance
flavoring of the default 386 config is unacceptable.  Keep your tweaks
local.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r326758 - in head/sys/i386: conf include

2017-12-14 Thread Konstantin Belousov
On Thu, Dec 14, 2017 at 10:39:18PM +0700, Eugene Grosbein wrote:
> On 14.12.2017 22:23, Konstantin Belousov wrote:
> 
> >>> Sigh. This would make i386 even less usable for everybody, perhaps
> >>> except you. Because default 3G of UVA is too small for some common tasks
> >>> (thanks clang, but also e.g. pypy), and you reduce the user address
> >>> space even more.
> >>
> >> Those who need 3GB of UVA within single process should not use 32 bit 
> >> system in first place, should they?
> > 
> > Why do you even consider it acceptable to break the configuration just
> > because you are not interested in the workload ?
> 
> I do not consider it is acceptable. I'm trying to find compromise.
If you do not find the proposed change acceptable, why do you propose
it at all ?

> 
> > 3G cumulative VA does not translate into 3G of usable addresses: the bss
> > is reserved, the address space is fragmented due to need of growing
> > stack to not conflict with mmaped regions. As result, applications get
> > slightly less than 2G usable without tricks, and to apply the tricks
> > apps must know details of the AS layout, i.e. breaking the portability.
> > 
> > 386 arch configuration is not perfect but it provides the main intended
> > service of general-purpose workstation, with some limitation caused by
> > 32bit of address space being somewhat low for modern code. Appliance
> > flavoring of the default 386 config is unacceptable.  Keep your tweaks
> > local.
> 
> Do you think that kstack overflow of general-purpose workstation using NFS
> or IPv6 or WiFi with SCTP is OK? I do not.

Kernel stack overflow is not 'OK', but two things are equally troublesome:
- papering over the problem of large structures allocated on stack by
  increasing the stack size;
- ignoring the explanation why the stack increase is problematic by itself
  and generating thread consisting of 50+ content-less messages claiming
  that 'it fixes the problem for me'.

The proper route to fix the issues was already explained more than
several times, and you (and I, and other people) participated in the
ongoing efforts there. If it is so much important to you, wave the flag
and herd the action, by asking relevant people to help with fixes, be it
writing the patches, providing reviews or just finding the place where
the stack is abused. It requires identification and time to think and
develop specific changes for each place, and cannot happen in one day.
But it also would not break KVA-starved architectures and provide fixes
relevant to even KVA-ample machines, as you other example shown.

For the case of extreme use, there is still the tunable (and ZFS on i386
is extreme).
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326971 - in head/sys: amd64/include arm/include arm64/include i386/include mips/include powerpc/include riscv/include sparc64/include sys

2017-12-19 Thread Konstantin Belousov
==
--- head/sys/sparc64/include/atomic.h   Tue Dec 19 09:58:41 2017
(r326970)
+++ head/sys/sparc64/include/atomic.h   Tue Dec 19 09:59:20 2017
(r326971)
@@ -39,6 +39,8 @@
 #definewmb()   mb()
 #definermb()   mb()
 
+#include 
+
 /* Userland needs different ASI's. */
 #ifdef _KERNEL
 #define__ASI_ATOMICASI_N

Added: head/sys/sys/atomic_common.h
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/sys/atomic_common.hTue Dec 19 09:59:20 2017
(r326971)
@@ -0,0 +1,73 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2017 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Konstantin Belousov 
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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.
+ * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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 _SYS_ATOMIC_COMMON_H_
+#define_SYS_ATOMIC_COMMON_H_
+
+#ifndef _MACHINE_ATOMIC_H_
+#error do not include this header, use machine/atomic.h
+#endif
+
+#defineatomic_load_char(p) (*(volatile u_char *)(p))
+#defineatomic_load_short(p)(*(volatile u_short *)(p))
+#defineatomic_load_int(p)  (*(volatile u_int *)(p))
+#defineatomic_load_long(p) (*(volatile u_long *)(p))
+#defineatomic_load_ptr(p)  (*(volatile uintptr_t*)(p))
+#defineatomic_load_8(p)(*(volatile uint8_t *)(p))
+#defineatomic_load_16(p)   (*(volatile uint16_t *)(p))
+#defineatomic_load_32(p)   (*(volatile uint32_t *)(p))
+#ifdef _LP64
+#defineatomic_load_64(p)   (*(volatile uint64_t *)(p))
+#endif
+
+#defineatomic_store_char(p, v) \
+(*(volatile u_char *)(p) = (u_char)(v))
+#defineatomic_store_short(p, v)\
+(*(volatile u_short *)(p) = (u_short)(v))
+#defineatomic_store_int(p, v)  \
+(*(volatile u_int *)(p) = (u_int)(v))
+#defineatomic_store_long(p, v) \
+(*(volatile u_long *)(p) = (u_long)(v))
+#defineatomic_store_ptr(p, v)  \
+(*(uintptr_t *)(p) = (uintptr_t)(v))
+#defineatomic_store_8(p, v)\
+(*(volatile uint8_t *)(p) = (uint8_t)(v))
+#defineatomic_store_16(p, v)   \
+(*(volatile uint16_t *)(p) = (uint16_t)(v))
+#defineatomic_store_32(p, v)   \
+(*(volatile uint32_t *)(p) = (uint32_t)(v))
+#ifdef _LP64
+#defineatomic_store_64(p, v)   \
+(*(volatile uint64_t *)(p) = (uint64_t)(v))
+#endif
+
+#endif
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326973 - head/sys/kern

2017-12-19 Thread Konstantin Belousov
Author: kib
Date: Tue Dec 19 10:05:45 2017
New Revision: 326973
URL: https://svnweb.freebsd.org/changeset/base/326973

Log:
  Use atomic_load(9) to read ppsinfo sequence numbers.
  
  In this case volatile qualifiers enusre that a compiler does not
  optimize the accesses out.
  
  Reviewed by:  alc, jhb
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D13534

Modified:
  head/sys/kern/kern_tc.c

Modified: head/sys/kern/kern_tc.c
==
--- head/sys/kern/kern_tc.c Tue Dec 19 10:02:09 2017(r326972)
+++ head/sys/kern/kern_tc.c Tue Dec 19 10:05:45 2017(r326973)
@@ -1601,10 +1601,10 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_stat
tv.tv_usec = fapi->timeout.tv_nsec / 1000;
timo = tvtohz(&tv);
}
-   aseq = pps->ppsinfo.assert_sequence;
-   cseq = pps->ppsinfo.clear_sequence;
-   while (aseq == pps->ppsinfo.assert_sequence &&
-   cseq == pps->ppsinfo.clear_sequence) {
+   aseq = atomic_load_int(&pps->ppsinfo.assert_sequence);
+   cseq = atomic_load_int(&pps->ppsinfo.clear_sequence);
+   while (aseq == atomic_load_int(&pps->ppsinfo.assert_sequence) &&
+   cseq == atomic_load_int(&pps->ppsinfo.clear_sequence)) {
if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
if (pps->flags & PPSFLAG_MTX_SPIN) {
err = msleep_spin(pps, pps->driver_mtx,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326974 - head/sys/vm

2017-12-19 Thread Konstantin Belousov
Author: kib
Date: Tue Dec 19 10:06:55 2017
New Revision: 326974
URL: https://svnweb.freebsd.org/changeset/base/326974

Log:
  Perform all accesses to uma_reclaim_needed using atomic(9) KPI.
  
  Reviewed by:  alc, jhb
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D13534

Modified:
  head/sys/vm/uma_core.c

Modified: head/sys/vm/uma_core.c
==
--- head/sys/vm/uma_core.c  Tue Dec 19 10:05:45 2017(r326973)
+++ head/sys/vm/uma_core.c  Tue Dec 19 10:06:55 2017(r326974)
@@ -3170,14 +3170,14 @@ uma_reclaim_worker(void *arg __unused)
 
for (;;) {
sx_xlock(&uma_drain_lock);
-   while (uma_reclaim_needed == 0)
+   while (atomic_load_int(&uma_reclaim_needed) == 0)
sx_sleep(uma_reclaim, &uma_drain_lock, PVM, "umarcl",
hz);
sx_xunlock(&uma_drain_lock);
EVENTHANDLER_INVOKE(vm_lowmem, VM_LOW_KMEM);
sx_xlock(&uma_drain_lock);
uma_reclaim_locked(true);
-   uma_reclaim_needed = 0;
+   atomic_store_int(&uma_reclaim_needed, 0);
sx_xunlock(&uma_drain_lock);
/* Don't fire more than once per-second. */
pause("umarclslp", hz);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r326977 - head/sys/dev/mlx5/mlx5_en

2017-12-19 Thread Konstantin Belousov
Author: kib
Date: Tue Dec 19 14:11:41 2017
New Revision: 326977
URL: https://svnweb.freebsd.org/changeset/base/326977

Log:
  mlx5en: Avoid SFENCe on x86
  
  The IA32 memory model guarantees that all writes are seen in the program
  order.  Also, any access to the uncacheable memory flushes the store
  buffers.  As the consequence, SFENCE instruction is (almost) never needed,
  in particular, it is not needed to ensure the correct order of updates as
  seen by a PCIe device.
  
  Use atomic_thread_fence_rel() instead of wb() to only emit compiler barriers
  on x86 there.  Other architectures get the right barrier instruction as
  well.
  
  Reviewed by:  hselasky
  Sponsored by: Mellanox Technologies
  MFC after:1 week

Modified:
  head/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c  Tue Dec 19 11:44:24 2017
(r326976)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c  Tue Dec 19 14:11:41 2017
(r326977)
@@ -90,7 +90,7 @@ mlx5e_post_rx_wqes(struct mlx5e_rq *rq)
}
 
/* ensure wqes are visible to device before updating doorbell record */
-   wmb();
+   atomic_thread_fence_rel();
 
mlx5_wq_ll_update_db_record(&rq->wq);
 }
@@ -436,7 +436,7 @@ wq_ll_pop:
mlx5_cqwq_update_db_record(&rq->cq.wq);
 
/* ensure cq space is freed before enabling more cqes */
-   wmb();
+   atomic_thread_fence_rel();
return (i);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r327053 - head/sys/sparc64/include

2017-12-21 Thread Konstantin Belousov
On Thu, Dec 21, 2017 at 01:27:33AM +, Marius Strobl wrote:
> Author: marius
> Date: Thu Dec 21 01:27:32 2017
> New Revision: 327053
> URL: https://svnweb.freebsd.org/changeset/base/327053
> 
> Log:
>   Remove MD atomic_load_{32,64,int,long,ptr}(9) obsolete since the addition
>   of (conflicting) MI ones in r326971.
I am sorry. Initially I wrote the patch with only support for required
MI types int long ptr and run the tinderbox. Then I decided that there
is no reason to not provide the rest, but did not realized that tb is
needed again.

> 
> Modified:
>   head/sys/sparc64/include/atomic.h
> 
> Modified: head/sys/sparc64/include/atomic.h
> ==
> --- head/sys/sparc64/include/atomic.h Thu Dec 21 01:22:36 2017
> (r327052)
> +++ head/sys/sparc64/include/atomic.h Thu Dec 21 01:27:32 2017
> (r327053)
> @@ -258,11 +258,6 @@ atomic_fcmpset_rel_ ## name(volatile ptype p, vtype *e
>  }\
>   \
>  static __inline vtype
> \
> -atomic_load_ ## name(volatile ptype p)   
> \
> -{\
> - return ((vtype)atomic_cas((p), 0, 0, sz));  \
atomic_cas() does not have any barrier behavior, am I right ?
I.e., it does not prevent a reordering in RMO and PSO models.

> -}\
> -static __inline vtype
> \
>  atomic_load_acq_ ## name(volatile ptype p)   \
>  {\
>   return ((vtype)atomic_cas_acq((p), 0, 0, sz));  \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r327072 - head/sys/net

2017-12-21 Thread Konstantin Belousov
Author: kib
Date: Thu Dec 21 23:05:13 2017
New Revision: 327072
URL: https://svnweb.freebsd.org/changeset/base/327072

Log:
  Fix build for kernels with SCHED_4BSD.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/net/iflib.c

Modified: head/sys/net/iflib.c
==
--- head/sys/net/iflib.cThu Dec 21 22:48:02 2017(r327071)
+++ head/sys/net/iflib.cThu Dec 21 23:05:13 2017(r327072)
@@ -5127,7 +5127,7 @@ find_thread(int cpu, int thread_num)
 static int
 find_thread(int cpu, int thread_num __unused)
 {
-   return cpu_id;
+   return cpu;
 }
 #endif
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


  1   2   3   4   5   6   7   8   9   10   >