Re: svn commit: r349296 - stable/10/usr.bin/calendar/calendars

2019-06-23 Thread Konstantin Belousov
On Sat, Jun 22, 2019 at 11:36:28PM +, Greg Lehey wrote:
> Author: grog
> Date: Sat Jun 22 23:36:28 2019
> New Revision: 349296
> URL: https://svnweb.freebsd.org/changeset/base/349296
> 
> Log:
>   Correct Konrad Zuse's year of birth.
> 
> Modified:
>   stable/10/usr.bin/calendar/calendars/calendar.birthday
> 
> Modified: stable/10/usr.bin/calendar/calendars/calendar.birthday
> ==
> --- stable/10/usr.bin/calendar/calendars/calendar.birthdaySat Jun 22 
> 22:43:40 2019(r349295)
> +++ stable/10/usr.bin/calendar/calendars/calendar.birthdaySat Jun 22 
> 23:36:28 2019(r349296)
> @@ -167,7 +167,7 @@
>  06/19FreeBSD project born, 1993
>  06/22Carl Hubbell born, 1903
>  06/22Meryl Streep born in Summit, New Jersey, 1949
> -06/22Konrad Zuse born in Berlin, 1919
> +06/22Konrad Zuse born in Berlin, 1910
>  06/23Alan Mathison Turing born, 1912
>  06/25Eric Arthur Blair (a.k.a. George Orwell) born, 1903
>  06/27Helen Keller born, 1880
Why is this committed to stable/10, without first doing it in HEAD, and
then merge to 12 and 11 beforehand ?
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r337245 - in stable/10/sys: amd64/amd64 i386/i386 i386/isa

2018-08-03 Thread Konstantin Belousov
Author: kib
Date: Fri Aug  3 14:12:37 2018
New Revision: 337245
URL: https://svnweb.freebsd.org/changeset/base/337245

Log:
  MFC r336683:
  Extend ranges of the critical sections to ensure that context switch
  code never sees FPU pcb flags not consistent with the hardware state.

Modified:
  stable/10/sys/amd64/amd64/fpu.c
  stable/10/sys/amd64/amd64/machdep.c
  stable/10/sys/i386/i386/machdep.c
  stable/10/sys/i386/isa/npx.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/fpu.c
==
--- stable/10/sys/amd64/amd64/fpu.c Fri Aug  3 14:08:39 2018
(r337244)
+++ stable/10/sys/amd64/amd64/fpu.c Fri Aug  3 14:12:37 2018
(r337245)
@@ -741,22 +741,22 @@ fpugetregs(struct thread *td)
int max_ext_n, i, owned;
 
pcb = td->td_pcb;
+   critical_enter();
if ((pcb->pcb_flags & PCB_USERFPUINITDONE) == 0) {
bcopy(fpu_initialstate, get_pcb_user_save_pcb(pcb),
cpu_max_ext_state_size);
get_pcb_user_save_pcb(pcb)->sv_env.en_cw =
pcb->pcb_initial_fpucw;
fpuuserinited(td);
+   critical_exit();
return (_MC_FPOWNED_PCB);
}
-   critical_enter();
if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {
fpusave(get_pcb_user_save_pcb(pcb));
owned = _MC_FPOWNED_FPU;
} else {
owned = _MC_FPOWNED_PCB;
}
-   critical_exit();
if (use_xsave) {
/*
 * Handle partially saved state.
@@ -776,6 +776,7 @@ fpugetregs(struct thread *td)
*xstate_bv |= bit;
}
}
+   critical_exit();
return (owned);
 }
 
@@ -784,6 +785,7 @@ fpuuserinited(struct thread *td)
 {
struct pcb *pcb;
 
+   CRITICAL_ASSERT(td);
pcb = td->td_pcb;
if (PCB_USER_FPU(pcb))
set_pcb_flags(pcb,
@@ -842,26 +844,25 @@ fpusetregs(struct thread *td, struct savefpu *addr, ch
 
addr->sv_env.en_mxcsr &= cpu_mxcsr_mask;
pcb = td->td_pcb;
+   error = 0;
critical_enter();
if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {
error = fpusetxstate(td, xfpustate, xfpustate_size);
-   if (error != 0) {
-   critical_exit();
-   return (error);
+   if (error == 0) {
+   bcopy(addr, get_pcb_user_save_td(td), sizeof(*addr));
+   fpurestore(get_pcb_user_save_td(td));
+   set_pcb_flags(pcb, PCB_FPUINITDONE |
+   PCB_USERFPUINITDONE);
}
-   bcopy(addr, get_pcb_user_save_td(td), sizeof(*addr));
-   fpurestore(get_pcb_user_save_td(td));
-   critical_exit();
-   set_pcb_flags(pcb, PCB_FPUINITDONE | PCB_USERFPUINITDONE);
} else {
-   critical_exit();
error = fpusetxstate(td, xfpustate, xfpustate_size);
-   if (error != 0)
-   return (error);
-   bcopy(addr, get_pcb_user_save_td(td), sizeof(*addr));
-   fpuuserinited(td);
+   if (error == 0) {
+   bcopy(addr, get_pcb_user_save_td(td), sizeof(*addr));
+   fpuuserinited(td);
+   }
}
-   return (0);
+   critical_exit();
+   return (error);
 }
 
 /*
@@ -1004,6 +1005,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx 
return (0);
}
pcb = td->td_pcb;
+   critical_enter();
KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save ==
get_pcb_user_save_pcb(pcb), ("mangled pcb_save"));
ctx->flags = 0;
@@ -1014,6 +1016,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx 
pcb->pcb_save = fpu_kern_ctx_savefpu(ctx);
set_pcb_flags(pcb, PCB_KERNFPU);
clear_pcb_flags(pcb, PCB_FPUINITDONE);
+   critical_exit();
return (0);
 }
 
@@ -1029,7 +1032,6 @@ fpu_kern_leave(struct thread *td, struct fpu_kern_ctx 
critical_enter();
if (curthread == PCPU_GET(fpcurthread))
fpudrop();
-   critical_exit();
pcb->pcb_save = ctx->prev;
if (pcb->pcb_save == get_pcb_user_save_pcb(pcb)) {
if ((pcb->pcb_flags & PCB_USERFPUINITDONE) != 0) {
@@ -1044,6 +1046,7 @@ fpu_kern_leave(struct thread *td, struct fpu_kern_ctx 
clear_pcb_flags(pcb, PCB_FPUINITDONE);
KASSERT(!PCB_USER_FPU(pcb), ("unpaired fpu_kern_leave"));
}
+   critical_exit();
return (0);
 }
 

Modified: stable/10/sys/amd64/amd64/machdep.c
==
--- stable/10/sys/amd64/amd64/machdep.c Fri Aug  3 14:08:39 2018 

svn commit: r335455 - in stable/10/sys: amd64/amd64 i386/i386 i386/isa

2018-06-20 Thread Konstantin Belousov
Author: kib
Date: Wed Jun 20 18:51:38 2018
New Revision: 335455
URL: https://svnweb.freebsd.org/changeset/base/335455

Log:
  MFC r335072, r335089, r335131, r335132:
  Enable eager FPU context switch on i386 and amd64.
  
  CVE:  CVE-2018-3665
  Tested by:emaste (smoke boot)

Modified:
  stable/10/sys/amd64/amd64/cpu_switch.S
  stable/10/sys/amd64/amd64/fpu.c
  stable/10/sys/i386/i386/swtch.s
  stable/10/sys/i386/isa/npx.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/cpu_switch.S
==
--- stable/10/sys/amd64/amd64/cpu_switch.S  Wed Jun 20 18:43:17 2018
(r335454)
+++ stable/10/sys/amd64/amd64/cpu_switch.S  Wed Jun 20 18:51:38 2018
(r335455)
@@ -111,10 +111,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
@@ -126,12 +126,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. */
movqTD_PCB(%rsi),%r8
@@ -255,6 +250,8 @@ done_load_dr:
movqPCB_RBX(%r8),%rbx
movqPCB_RIP(%r8),%rax
movq%rax,(%rsp)
+   movqPCPU(CURTHREAD),%rdi
+   callfpu_activate_sw
ret
 
/*

Modified: stable/10/sys/amd64/amd64/fpu.c
==
--- stable/10/sys/amd64/amd64/fpu.c Wed Jun 20 18:43:17 2018
(r335454)
+++ stable/10/sys/amd64/amd64/fpu.c Wed Jun 20 18:51:38 2018
(r335455)
@@ -139,6 +139,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,
+_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;
@@ -204,6 +209,7 @@ fpuinit_bsp1(void)
u_int cp[4];
uint64_t xsave_mask_user;
 
+   TUNABLE_INT_FETCH("hw.lazy_fpu_switch", _fpu_switch);
if ((cpu_feature2 & CPUID2_XSAVE) != 0) {
use_xsave = 1;
TUNABLE_INT_FETCH("hw.use_xsave", _xsave);
@@ -611,6 +617,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.
  *
@@ -621,7 +666,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
@@ -633,49 +680,38 @@ fpudna(void)
 */
critical_enter();
 
-   if (PCPU_GET(fpcurthread) == curthread) {
-   printf("fpudna: fpcurthread == curthread\n");
+   if (__predict_false(PCPU_GET(fpcurthread) == td)) {
+   /*
+* Some 

svn commit: r332069 - stable/10/sys/amd64/amd64

2018-04-05 Thread Konstantin Belousov
Author: kib
Date: Thu Apr  5 13:39:53 2018
New Revision: 332069
URL: https://svnweb.freebsd.org/changeset/base/332069

Log:
  MFC r331374:
  Fixes for ptrace(PT_GETXSTATE_INFO) related to the padding in struct
  ptrace_xstate_info).

Modified:
  stable/10/sys/amd64/amd64/ptrace_machdep.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/ptrace_machdep.c
==
--- stable/10/sys/amd64/amd64/ptrace_machdep.c  Thu Apr  5 12:59:50 2018
(r332068)
+++ stable/10/sys/amd64/amd64/ptrace_machdep.c  Thu Apr  5 13:39:53 2018
(r332069)
@@ -43,10 +43,20 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#ifdef COMPAT_FREEBSD32
+struct ptrace_xstate_info32 {
+   uint32_txsave_mask1, xsave_mask2;
+   uint32_txsave_len;
+};
+#endif
+
 static int
 cpu_ptrace_xstate(struct thread *td, int req, void *addr, int data)
 {
struct ptrace_xstate_info info;
+#ifdef COMPAT_FREEBSD32
+   struct ptrace_xstate_info32 info32;
+#endif
char *savefpu;
int error;
 
@@ -76,13 +86,28 @@ cpu_ptrace_xstate(struct thread *td, int req, void *ad
break;
 
case PT_GETXSTATE_INFO:
-   if (data != sizeof(info)) {
-   error  = EINVAL;
-   break;
+#ifdef COMPAT_FREEBSD32
+   if (SV_CURPROC_FLAG(SV_ILP32)) {
+   if (data != sizeof(info32)) {
+   error = EINVAL;
+   } else {
+   info32.xsave_len = cpu_max_ext_state_size;
+   info32.xsave_mask1 = xsave_mask;
+   info32.xsave_mask2 = xsave_mask >> 32;
+   error = copyout(, addr, data);
+   }
+   } else
+#endif
+   {
+   if (data != sizeof(info)) {
+   error  = EINVAL;
+   } else {
+   bzero(, sizeof(info));
+   info.xsave_len = cpu_max_ext_state_size;
+   info.xsave_mask = xsave_mask;
+   error = copyout(, addr, data);
+   }
}
-   info.xsave_len = cpu_max_ext_state_size;
-   info.xsave_mask = xsave_mask;
-   error = copyout(, addr, data);
break;
 
case PT_GETXSTATE:
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r329707 - stable/10/sys/vm

2018-02-21 Thread Konstantin Belousov
Author: kib
Date: Wed Feb 21 11:31:29 2018
New Revision: 329707
URL: https://svnweb.freebsd.org/changeset/base/329707

Log:
  MFC r329254:
  Ensure memory consistency on COW.

Modified:
  stable/10/sys/vm/vm_fault.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_fault.c
==
--- stable/10/sys/vm/vm_fault.c Wed Feb 21 11:29:07 2018(r329706)
+++ stable/10/sys/vm/vm_fault.c Wed Feb 21 11:31:29 2018(r329707)
@@ -893,6 +893,10 @@ readrest:
 */
pmap_copy_page(fs.m, fs.first_m);
fs.first_m->valid = VM_PAGE_BITS_ALL;
+   if ((fault_flags & VM_FAULT_WIRE) == 0) {
+   prot &= ~VM_PROT_WRITE;
+   fault_type &= ~VM_PROT_WRITE;
+   }
if (wired && (fault_flags &
VM_FAULT_WIRE) == 0) {
vm_page_lock(fs.first_m);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r327060 - stable/10/sys/fs/devfs

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

Log:
  MFC r326851:
  In devfs_lookupx() dotdot lookup case, avoid dereferencing
  dvp->v_mount after dvp is unlocked.

Modified:
  stable/10/sys/fs/devfs/devfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/devfs/devfs_vnops.c
==
--- stable/10/sys/fs/devfs/devfs_vnops.cThu Dec 21 13:30:56 2017
(r327059)
+++ stable/10/sys/fs/devfs/devfs_vnops.cThu Dec 21 13:32:49 2017
(r327060)
@@ -869,6 +869,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;
@@ -880,7 +881,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;
 
@@ -913,8 +915,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);
@@ -999,8 +1001,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-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r326846 - stable/10/sys/ufs/ufs

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

Log:
  MFC r326657:
  Fix livelock in ufsdirhash_create().

Modified:
  stable/10/sys/ufs/ufs/ufs_dirhash.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/ufs/ufs/ufs_dirhash.c
==
--- stable/10/sys/ufs/ufs/ufs_dirhash.c Thu Dec 14 11:41:12 2017
(r326845)
+++ stable/10/sys/ufs/ufs/ufs_dirhash.c Thu Dec 14 11:45:02 2017
(r326846)
@@ -189,9 +189,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) {
@@ -228,8 +230,11 @@ ufsdirhash_create(struct inode *ip)
ufsdirhash_hold(dh);
VI_UNLOCK(vp);
 
-   /* Acquire a shared lock on existing hashes. */
-   sx_slock(>dh_lock);
+   /* Acquire a lock on existing hashes. */
+   if (excl)
+   sx_xlock(>dh_lock);
+   else
+   sx_slock(>dh_lock);
 
/* The hash could've been recycled while we were waiting. */
VI_LOCK(vp);
@@ -250,9 +255,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_lock))
+   if (excl || sx_try_upgrade(>dh_lock))
break;
sx_sunlock(>dh_lock);
+   excl = true;
}
/* Free the preallocated structure if it was not necessary. */
if (ndh) {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r326523 - stable/10/sys/vm

2017-12-04 Thread Konstantin Belousov
Author: kib
Date: Mon Dec  4 10:05:59 2017
New Revision: 326523
URL: https://svnweb.freebsd.org/changeset/base/326523

Log:
  MFC r326424:
  Add comment for vm_map_find_min().

Modified:
  stable/10/sys/vm/vm_map.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_map.c
==
--- stable/10/sys/vm/vm_map.c   Mon Dec  4 09:58:38 2017(r326522)
+++ stable/10/sys/vm/vm_map.c   Mon Dec  4 10:05:59 2017(r326523)
@@ -1509,6 +1509,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-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r326397 - in stable/10: lib/libc/sys sys/kern sys/sys

2017-11-30 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 30 14:38:07 2017
New Revision: 326397
URL: https://svnweb.freebsd.org/changeset/base/326397

Log:
  MFC r326122:
  Kill all descendants of the reaper, even if they are descendants of a
  subordinate reaper.  Also, mark reapers when listing pids.
  
  PR:   223745

Modified:
  stable/10/lib/libc/sys/procctl.2
  stable/10/sys/kern/kern_procctl.c
  stable/10/sys/sys/procctl.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/procctl.2
==
--- stable/10/lib/libc/sys/procctl.2Thu Nov 30 14:19:47 2017
(r326396)
+++ stable/10/lib/libc/sys/procctl.2Thu Nov 30 14:38:07 2017
(r326397)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 21, 2015
+.Dd November 21, 2017
 .Dt PROCCTL 2
 .Os
 .Sh NAME
@@ -211,7 +211,7 @@ of the process.
 The
 .Fa pi_flags
 field returns the following flags, further describing the descendant:
-.Bl -tag -width "Dv REAPER_PIDINFO_VALID"
+.Bl -tag -width "Dv REAPER_PIDINFO_REAPER"
 .It Dv REAPER_PIDINFO_VALID
 Set to indicate that the
 .Vt procctl_reaper_pidinfo
@@ -226,6 +226,9 @@ of the returned array.
 The
 .Fa pi_pid
 field identifies the direct child of the reaper.
+.It Dv REAPER_PIDINFO_REAPER
+The reported process is itself a reaper.
+The descendants of the subordinate reaper are not reported.
 .El
 .It Dv PROC_REAP_KILL
 Request to deliver a signal to some subset of the descendants of the reaper.

Modified: stable/10/sys/kern/kern_procctl.c
==
--- stable/10/sys/kern/kern_procctl.c   Thu Nov 30 14:19:47 2017
(r326396)
+++ stable/10/sys/kern/kern_procctl.c   Thu Nov 30 14:38:07 2017
(r326397)
@@ -221,6 +221,8 @@ reap_getpids(struct thread *td, struct proc *p, struct
pip->pi_flags = REAPER_PIDINFO_VALID;
if (proc_realparent(p2) == reap)
pip->pi_flags |= REAPER_PIDINFO_CHILD;
+   if ((p2->p_treeflag & P_TREE_REAPER) != 0)
+   pip->pi_flags |= REAPER_PIDINFO_REAPER;
i++;
}
sx_sunlock(_lock);
@@ -231,20 +233,60 @@ reap_getpids(struct thread *td, struct proc *p, struct
return (error);
 }
 
+static void
+reap_kill_proc(struct thread *td, struct proc *p2, ksiginfo_t *ksi,
+struct procctl_reaper_kill *rk, int *error)
+{
+   int error1;
+
+   PROC_LOCK(p2);
+   error1 = p_cansignal(td, p2, rk->rk_sig);
+   if (error1 == 0) {
+   pksignal(p2, rk->rk_sig, ksi);
+   rk->rk_killed++;
+   *error = error1;
+   } else if (*error == ESRCH) {
+   rk->rk_fpid = p2->p_pid;
+   *error = error1;
+   }
+   PROC_UNLOCK(p2);
+}
+
+struct reap_kill_tracker {
+   struct proc *parent;
+   TAILQ_ENTRY(reap_kill_tracker) link;
+};
+
+TAILQ_HEAD(reap_kill_tracker_head, reap_kill_tracker);
+
+static void
+reap_kill_sched(struct reap_kill_tracker_head *tracker, struct proc *p2)
+{
+   struct reap_kill_tracker *t;
+
+   t = malloc(sizeof(struct reap_kill_tracker), M_TEMP, M_WAITOK);
+   t->parent = p2;
+   TAILQ_INSERT_TAIL(tracker, t, link);
+}
+
 static int
 reap_kill(struct thread *td, struct proc *p, struct procctl_reaper_kill *rk)
 {
struct proc *reap, *p2;
ksiginfo_t ksi;
-   int error, error1;
+   struct reap_kill_tracker_head tracker;
+   struct reap_kill_tracker *t;
+   int error;
 
sx_assert(_lock, SX_LOCKED);
if (IN_CAPABILITY_MODE(td))
return (ECAPMODE);
-   if (rk->rk_sig <= 0 || rk->rk_sig > _SIG_MAXSIG)
+   if (rk->rk_sig <= 0 || rk->rk_sig > _SIG_MAXSIG ||
+   (rk->rk_flags & ~(REAPER_KILL_CHILDREN |
+   REAPER_KILL_SUBTREE)) != 0 || (rk->rk_flags &
+   (REAPER_KILL_CHILDREN | REAPER_KILL_SUBTREE)) ==
+   (REAPER_KILL_CHILDREN | REAPER_KILL_SUBTREE))
return (EINVAL);
-   if ((rk->rk_flags & ~(REAPER_KILL_CHILDREN | REAPER_KILL_SUBTREE)) != 0)
-   return (EINVAL);
PROC_UNLOCK(p);
reap = (p->p_treeflag & P_TREE_REAPER) == 0 ? p->p_reaper : p;
ksiginfo_init();
@@ -255,26 +297,33 @@ reap_kill(struct thread *td, struct proc *p, struct pr
error = ESRCH;
rk->rk_killed = 0;
rk->rk_fpid = -1;
-   for (p2 = (rk->rk_flags & REAPER_KILL_CHILDREN) != 0 ?
-   LIST_FIRST(>p_children) : LIST_FIRST(>p_reaplist);
-   p2 != NULL;
-   p2 = (rk->rk_flags & REAPER_KILL_CHILDREN) != 0 ?
-   LIST_NEXT(p2, p_sibling) : LIST_NEXT(p2, p_reapsibling)) {
-   if ((rk->rk_flags & REAPER_KILL_SUBTREE) != 0 &&
-   p2->p_reapsubtree != rk->rk_subtree)
-   continue;
-   PROC_LOCK(p2);
-   error1 = p_cansignal(td, p2, rk->rk_sig);
-   if (error1 == 

svn commit: r326189 - stable/10/sys/vm

2017-11-25 Thread Konstantin Belousov
Author: kib
Date: Sat Nov 25 14:51:40 2017
New Revision: 326189
URL: https://svnweb.freebsd.org/changeset/base/326189

Log:
  MFC r326098:
  Return different error code for the guard page layout violation.
  
  PR:   223732

Modified:
  stable/10/sys/vm/vm_map.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_map.c
==
--- stable/10/sys/vm/vm_map.c   Sat Nov 25 14:47:24 2017(r326188)
+++ stable/10/sys/vm/vm_map.c   Sat Nov 25 14:51:40 2017(r326189)
@@ -3555,12 +3555,13 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos,
KASSERT(orient != (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP),
("bi-dir stack"));
 
-   sgp = (vm_size_t)stack_guard_page * PAGE_SIZE;
if (addrbos < vm_map_min(map) ||
-   addrbos > vm_map_max(map) ||
-   addrbos + max_ssize < addrbos ||
-   sgp >= max_ssize)
-   return (KERN_NO_SPACE);
+   addrbos + max_ssize > vm_map_max(map) ||
+   addrbos + max_ssize <= addrbos)
+   return (KERN_INVALID_ADDRESS);
+   sgp = (vm_size_t)stack_guard_page * PAGE_SIZE;
+   if (sgp >= max_ssize)
+   return (KERN_INVALID_ARGUMENT);
 
init_ssize = growsize;
if (max_ssize < init_ssize + sgp)
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r325757 - stable/10/sys/dev/hwpmc

2017-11-13 Thread Konstantin Belousov
Author: kib
Date: Mon Nov 13 09:10:17 2017
New Revision: 325757
URL: https://svnweb.freebsd.org/changeset/base/325757

Log:
  MFC r325671:
  Check that the pmc index is less than the number of hardware PMCs,
  instead of asserting the condition.

Modified:
  stable/10/sys/dev/hwpmc/hwpmc_mod.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hwpmc/hwpmc_mod.c
==
--- stable/10/sys/dev/hwpmc/hwpmc_mod.c Mon Nov 13 09:07:30 2017
(r325756)
+++ stable/10/sys/dev/hwpmc/hwpmc_mod.c Mon Nov 13 09:10:17 2017
(r325757)
@@ -2583,6 +2583,8 @@ pmc_find_pmc(pmc_id_t pmcid, struct pmc **pmc)
struct pmc_owner *po;
 
PMCDBG1(PMC,FND,1, "find-pmc id=%d", pmcid);
+   if (PMC_ID_TO_ROWINDEX(pmcid) >= md->pmd_npmc)
+   return (EINVAL);
 
if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL)
return ESRCH;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r325643 - stable/10/sys/kern

2017-11-10 Thread Konstantin Belousov
Author: kib
Date: Fri Nov 10 12:31:58 2017
New Revision: 325643
URL: https://svnweb.freebsd.org/changeset/base/325643

Log:
  MFC r325567:
  Zero whole struct ptrace_lwpinfo to not leak kernel stack data.
  
  Security: CVE-2017-1086

Modified:
  stable/10/sys/kern/sys_process.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/sys_process.c
==
--- stable/10/sys/kern/sys_process.cFri Nov 10 12:28:43 2017
(r325642)
+++ stable/10/sys/kern/sys_process.cFri Nov 10 12:31:58 2017
(r325643)
@@ -474,6 +474,7 @@ ptrace_lwpinfo_to32(const struct ptrace_lwpinfo *pl,
 struct ptrace_lwpinfo32 *pl32)
 {
 
+   bzero(pl32, sizeof(*pl32));
pl32->pl_lwpid = pl->pl_lwpid;
pl32->pl_event = pl->pl_event;
pl32->pl_flags = pl->pl_flags;
@@ -1276,6 +1277,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi
} else
 #endif
pl = addr;
+   bzero(pl, sizeof(*pl));
pl->pl_lwpid = td2->td_tid;
pl->pl_event = PL_EVENT_NONE;
pl->pl_flags = 0;
@@ -1296,8 +1298,6 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi
pl->pl_siginfo = td2->td_dbgksi.ksi_info;
}
}
-   if ((pl->pl_flags & PL_FLAG_SI) == 0)
-   bzero(>pl_siginfo, sizeof(pl->pl_siginfo));
if (td2->td_dbgflags & TDB_SCE)
pl->pl_flags |= PL_FLAG_SCE;
else if (td2->td_dbgflags & TDB_SCX)
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r325543 - in stable/10/sys: amd64/amd64 i386/i386 i386/isa

2017-11-08 Thread Konstantin Belousov
Author: kib
Date: Wed Nov  8 11:39:42 2017
New Revision: 325543
URL: https://svnweb.freebsd.org/changeset/base/325543

Log:
  MFC r325270:
  Consistently ensure that we do not load MXCSR with reserved bits set.

Modified:
  stable/10/sys/amd64/amd64/fpu.c
  stable/10/sys/amd64/amd64/machdep.c
  stable/10/sys/i386/i386/machdep.c
  stable/10/sys/i386/isa/npx.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/fpu.c
==
--- stable/10/sys/amd64/amd64/fpu.c Wed Nov  8 11:25:19 2017
(r325542)
+++ stable/10/sys/amd64/amd64/fpu.c Wed Nov  8 11:39:42 2017
(r325543)
@@ -804,6 +804,7 @@ fpusetregs(struct thread *td, struct savefpu *addr, ch
struct pcb *pcb;
int error;
 
+   addr->sv_env.en_mxcsr &= cpu_mxcsr_mask;
pcb = td->td_pcb;
critical_enter();
if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {

Modified: stable/10/sys/amd64/amd64/machdep.c
==
--- stable/10/sys/amd64/amd64/machdep.c Wed Nov  8 11:25:19 2017
(r325542)
+++ stable/10/sys/amd64/amd64/machdep.c Wed Nov  8 11:39:42 2017
(r325543)
@@ -2529,7 +2529,6 @@ static int
 set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
 size_t xfpustate_len)
 {
-   struct savefpu *fpstate;
int error;
 
if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
@@ -2542,9 +2541,8 @@ set_fpcontext(struct thread *td, mcontext_t *mcp, char
error = 0;
} else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
-   fpstate = (struct savefpu *)>mc_fpstate;
-   fpstate->sv_env.en_mxcsr &= cpu_mxcsr_mask;
-   error = fpusetregs(td, fpstate, xfpustate, xfpustate_len);
+   error = fpusetregs(td, (struct savefpu *)>mc_fpstate,
+   xfpustate, xfpustate_len);
} else
return (EINVAL);
return (error);

Modified: stable/10/sys/i386/i386/machdep.c
==
--- stable/10/sys/i386/i386/machdep.c   Wed Nov  8 11:25:19 2017
(r325542)
+++ stable/10/sys/i386/i386/machdep.c   Wed Nov  8 11:39:42 2017
(r325543)
@@ -3932,7 +3932,6 @@ static int
 set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
 size_t xfpustate_len)
 {
-   union savefpu *fpstate;
int error;
 
if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
@@ -3947,12 +3946,8 @@ set_fpcontext(struct thread *td, mcontext_t *mcp, char
} else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
 #ifdef DEV_NPX
-   fpstate = (union savefpu *)>mc_fpstate;
-#ifdef CPU_ENABLE_SSE
-   if (cpu_fxsr)
-   fpstate->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
-#endif
-   error = npxsetregs(td, fpstate, xfpustate, xfpustate_len);
+   error = npxsetregs(td, (union savefpu *)>mc_fpstate,
+   xfpustate, xfpustate_len);
 #else
error = EINVAL;
 #endif

Modified: stable/10/sys/i386/isa/npx.c
==
--- stable/10/sys/i386/isa/npx.cWed Nov  8 11:25:19 2017
(r325542)
+++ stable/10/sys/i386/isa/npx.cWed Nov  8 11:39:42 2017
(r325543)
@@ -1124,6 +1124,10 @@ npxsetregs(struct thread *td, union savefpu *addr, cha
if (!hw_float)
return (ENXIO);
 
+#ifdef CPU_ENABLE_SSE
+   if (cpu_fxsr)
+   addr->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
+#endif
pcb = td->td_pcb;
critical_enter();
if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r325099 - in stable/10/sys: kern sys

2017-10-29 Thread Konstantin Belousov
Author: kib
Date: Sun Oct 29 09:48:28 2017
New Revision: 325099
URL: https://svnweb.freebsd.org/changeset/base/325099

Log:
  MFC r324853:
  Remove the support for mknod(S_IFMT), which created dummy vnodes with
  VBAD type.

Modified:
  stable/10/sys/kern/vfs_syscalls.c
  stable/10/sys/sys/priv.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_syscalls.c
==
--- stable/10/sys/kern/vfs_syscalls.c   Sun Oct 29 09:38:42 2017
(r325098)
+++ stable/10/sys/kern/vfs_syscalls.c   Sun Oct 29 09:48:28 2017
(r325099)
@@ -1246,9 +1246,6 @@ kern_mknodat(struct thread *td, int fd, char *path, en
if (error == 0 && dev == VNOVAL)
error = EINVAL;
break;
-   case S_IFMT:
-   error = priv_check(td, PRIV_VFS_MKNOD_BAD);
-   break;
case S_IFWHT:
error = priv_check(td, PRIV_VFS_MKNOD_WHT);
break;
@@ -1286,9 +1283,6 @@ restart:
whiteout = 0;
 
switch (mode & S_IFMT) {
-   case S_IFMT:/* used by badsect to flag bad sectors */
-   vattr.va_type = VBAD;
-   break;
case S_IFCHR:
vattr.va_type = VCHR;
break;

Modified: stable/10/sys/sys/priv.h
==
--- stable/10/sys/sys/priv.hSun Oct 29 09:38:42 2017(r325098)
+++ stable/10/sys/sys/priv.hSun Oct 29 09:48:28 2017(r325099)
@@ -265,7 +265,7 @@
 #definePRIV_VFS_GETFH  327 /* Can retrieve file handles. */
 #definePRIV_VFS_GETQUOTA   328 /* getquota(). */
 #definePRIV_VFS_LINK   329 /* bsd.hardlink_check_uid */
-#definePRIV_VFS_MKNOD_BAD  330 /* Can mknod() to mark bad 
inodes. */
+#definePRIV_VFS_MKNOD_BAD  330 /* Was: mknod() can mark bad 
inodes. */
 #definePRIV_VFS_MKNOD_DEV  331 /* Can mknod() to create dev 
nodes. */
 #definePRIV_VFS_MKNOD_WHT  332 /* Can mknod() to create 
whiteout. */
 #definePRIV_VFS_MOUNT  333 /* Can mount(). */
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322755 - stable/10/sys/i386/i386

2017-08-21 Thread Konstantin Belousov
Author: kib
Date: Mon Aug 21 15:44:57 2017
New Revision: 322755
URL: https://svnweb.freebsd.org/changeset/base/322755

Log:
  MFC r322667,r322706:
  Improve i386 #UD low-level kdtrace hook.
  
  Approved by:  re (marius)

Modified:
  stable/10/sys/i386/i386/exception.s
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/i386/i386/exception.s
==
--- stable/10/sys/i386/i386/exception.s Mon Aug 21 15:39:48 2017
(r322754)
+++ stable/10/sys/i386/i386/exception.s Mon Aug 21 15:44:57 2017
(r322755)
@@ -185,21 +185,29 @@ calltrap:
 #ifdef KDTRACE_HOOKS
SUPERALIGN_TEXT
 IDTVEC(ill)
-   /* Check if there is no DTrace hook registered. */
-   cmpl$0,dtrace_invop_jump_addr
+   /*
+* Check if a DTrace hook is registered.  The default (data) segment
+* cannot be used for this since %ds is not known good until we
+* verify that the entry was from kernel mode.
+*/
+   cmpl$0,%ss:dtrace_invop_jump_addr
je  norm_ill
 
-   /* Check if this is a user fault. */
-   cmpl$GSEL_KPL, 4(%esp)  /* Check the code segment. */
-
-   /* If so, just handle it as a normal trap. */
+   /*
+* Check if this is a user fault.  If so, just handle it as a normal
+* trap.
+*/
+   cmpl$GSEL_KPL, 4(%esp)  /* Check the code segment */
jne norm_ill
+   testl   $PSL_VM, 8(%esp)/* and vm86 mode. */
+   jnz norm_ill
 
/*
 * This is a kernel instruction fault that might have been caused
 * by a DTrace provider.
 */
-   pushal  /* Push all registers onto the stack. */
+   pushal
+   cld
 
/*
 * Set our jump address for the jump back in the event that
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322617 - stable/10/usr.sbin/cpucontrol

2017-08-17 Thread Konstantin Belousov
Author: kib
Date: Thu Aug 17 11:36:39 2017
New Revision: 322617
URL: https://svnweb.freebsd.org/changeset/base/322617

Log:
  MFC r322493:
  Remove confusion in the line explaining syntax of the msr read.
  Specify words order in the display.
  
  Approved by:  re (marius)

Modified:
  stable/10/usr.sbin/cpucontrol/cpucontrol.8
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/cpucontrol/cpucontrol.8
==
--- stable/10/usr.sbin/cpucontrol/cpucontrol.8  Thu Aug 17 10:56:22 2017
(r322616)
+++ stable/10/usr.sbin/cpucontrol/cpucontrol.8  Thu Aug 17 11:36:39 2017
(r322617)
@@ -90,9 +90,10 @@ The following options are available:
 .It Fl d Ar datadir
 Where to look for microcode images.
 The option can be specified multiple times.
-.It Fl m Ar msr Ns Op = Ns Ar value
+.It Fl m Ar msr
 Show value of the specified MSR.
 MSR register number should be given as a hexadecimal number.
+The high word is printed first, then the low word is printed second.
 .It Fl m Ar msr Ns = Ns Ar value
 Store the
 .Ar value
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322399 - stable/10/usr.sbin/pmcstat

2017-08-11 Thread Konstantin Belousov
Author: kib
Date: Fri Aug 11 11:38:04 2017
New Revision: 322399
URL: https://svnweb.freebsd.org/changeset/base/322399

Log:
  MFC r322059:
  Fix off by one in calculation of the number of buckets for the pc
  addresses.
  
  Approved by:  re (marius)

Modified:
  stable/10/usr.sbin/pmcstat/pmcpl_gprof.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/pmcstat/pmcpl_gprof.c
==
--- stable/10/usr.sbin/pmcstat/pmcpl_gprof.cFri Aug 11 10:59:34 2017
(r322398)
+++ stable/10/usr.sbin/pmcstat/pmcpl_gprof.cFri Aug 11 11:38:04 2017
(r322399)
@@ -464,8 +464,8 @@ pmcpl_gmon_process(struct pmcstat_process *pp, struct 
image, pmcid);
pgf->pgf_pmcid = pmcid;
assert(image->pi_end > image->pi_start);
-   pgf->pgf_nbuckets = (image->pi_end - image->pi_start) /
-   FUNCTION_ALIGNMENT; /* see  */
+   pgf->pgf_nbuckets = howmany(image->pi_end - image->pi_start,
+   FUNCTION_ALIGNMENT);/* see  */
pgf->pgf_ndatabytes = sizeof(struct gmonhdr) +
pgf->pgf_nbuckets * hc_sz;
pgf->pgf_nsamples = 0;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322303 - in stable/10/sys: amd64/amd64 i386/i386

2017-08-09 Thread Konstantin Belousov
Author: kib
Date: Wed Aug  9 09:16:16 2017
New Revision: 322303
URL: https://svnweb.freebsd.org/changeset/base/322303

Log:
  MFC r321919:
  Do not call trapsignal() after handling usermode fault or interrupt,
  when a signal is not intended to be sent.

Modified:
  stable/10/sys/amd64/amd64/trap.c
  stable/10/sys/i386/i386/trap.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/trap.c
==
--- stable/10/sys/amd64/amd64/trap.cWed Aug  9 09:13:15 2017
(r322302)
+++ stable/10/sys/amd64/amd64/trap.cWed Aug  9 09:16:16 2017
(r322303)
@@ -396,7 +396,7 @@ trap(struct trapframe *frame)
goto userout;
} else if (panic_on_nmi)
panic("NMI indicates hardware failure");
-   break;
+   goto out;
 #endif /* DEV_ISA */
 
case T_OFLOW:   /* integer overflow fault */
@@ -434,7 +434,7 @@ trap(struct trapframe *frame)
if (dtrace_return_probe_ptr != NULL &&
dtrace_return_probe_ptr() == 0)
goto out;
-   break;
+   goto userout;
 #endif
}
} else {

Modified: stable/10/sys/i386/i386/trap.c
==
--- stable/10/sys/i386/i386/trap.c  Wed Aug  9 09:13:15 2017
(r322302)
+++ stable/10/sys/i386/i386/trap.c  Wed Aug  9 09:16:16 2017
(r322303)
@@ -469,7 +469,7 @@ trap(struct trapframe *frame)
goto userout;
} else if (panic_on_nmi)
panic("NMI indicates hardware failure");
-   break;
+   goto out;
 #endif /* POWERFAIL_NMI */
 #endif /* DEV_ISA */
 
@@ -519,7 +519,7 @@ trap(struct trapframe *frame)
if (dtrace_return_probe_ptr != NULL &&
dtrace_return_probe_ptr() == 0)
goto out;
-   break;
+   goto userout;
 #endif
}
} else {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322048 - stable/10/sys/ufs/ffs

2017-08-04 Thread Konstantin Belousov
Author: kib
Date: Fri Aug  4 08:27:34 2017
New Revision: 322048
URL: https://svnweb.freebsd.org/changeset/base/322048

Log:
  MFC r321349:
  Improve publication of the newly allocated snapdata.

Modified:
  stable/10/sys/ufs/ffs/ffs_snapshot.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/ufs/ffs/ffs_snapshot.c
==
--- stable/10/sys/ufs/ffs/ffs_snapshot.cFri Aug  4 08:26:19 2017
(r322047)
+++ stable/10/sys/ufs/ffs/ffs_snapshot.cFri Aug  4 08:27:34 2017
(r322048)
@@ -2643,8 +2643,8 @@ try_free_snapdata(struct vnode *devvp)
 static struct snapdata *
 ffs_snapdata_acquire(struct vnode *devvp)
 {
-   struct snapdata *nsn;
-   struct snapdata *sn;
+   struct snapdata *nsn, *sn;
+   int error;
 
/*
 * Allocate a free snapdata.  This is done before acquiring the
@@ -2652,23 +2652,37 @@ ffs_snapdata_acquire(struct vnode *devvp)
 * held.
 */
nsn = ffs_snapdata_alloc();
-   /*
-* If there snapshots already exist on this filesystem grab a
-* reference to the shared lock.  Otherwise this is the first
-* snapshot on this filesystem and we need to use our
-* pre-allocated snapdata.
-*/
-   VI_LOCK(devvp);
-   if (devvp->v_rdev->si_snapdata == NULL) {
-   devvp->v_rdev->si_snapdata = nsn;
-   nsn = NULL;
+
+   for (;;) {
+   VI_LOCK(devvp);
+   sn = devvp->v_rdev->si_snapdata;
+   if (sn == NULL) {
+   /*
+* This is the first snapshot on this
+* filesystem and we use our pre-allocated
+* snapdata.  Publish sn with the sn_lock
+* owned by us, to avoid the race.
+*/
+   error = lockmgr(>sn_lock, LK_EXCLUSIVE |
+   LK_NOWAIT, NULL);
+   if (error != 0)
+   panic("leaked sn, lockmgr error %d", error);
+   sn = devvp->v_rdev->si_snapdata = nsn;
+   VI_UNLOCK(devvp);
+   nsn = NULL;
+   break;
+   }
+
+   /*
+* There is a snapshots which already exists on this
+* filesystem, grab a reference to the common lock.
+*/
+   error = lockmgr(>sn_lock, LK_INTERLOCK |
+   LK_EXCLUSIVE | LK_SLEEPFAIL, VI_MTX(devvp));
+   if (error == 0)
+   break;
}
-   sn = devvp->v_rdev->si_snapdata;
-   /*
-* Acquire the snapshot lock.
-*/
-   lockmgr(>sn_lock,
-   LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, VI_MTX(devvp));
+
/*
 * Free any unused snapdata.
 */
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322047 - stable/10/sys/ufs/ffs

2017-08-04 Thread Konstantin Belousov
Author: kib
Date: Fri Aug  4 08:26:19 2017
New Revision: 322047
URL: https://svnweb.freebsd.org/changeset/base/322047

Log:
  MFC r321348:
  Unlock correct lock in ffs_snapblkfree().

Modified:
  stable/10/sys/ufs/ffs/ffs_snapshot.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/ufs/ffs/ffs_snapshot.c
==
--- stable/10/sys/ufs/ffs/ffs_snapshot.cFri Aug  4 08:25:03 2017
(r322046)
+++ stable/10/sys/ufs/ffs/ffs_snapshot.cFri Aug  4 08:26:19 2017
(r322047)
@@ -1944,7 +1944,7 @@ retry:
 */
if (error != 0 && wkhd != NULL)
softdep_freework(wkhd);
-   lockmgr(vp->v_vnlock, LK_RELEASE, NULL);
+   lockmgr(>sn_lock, LK_RELEASE, NULL);
return (error);
 }
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r322046 - stable/10/sys/ufs/ffs

2017-08-04 Thread Konstantin Belousov
Author: kib
Date: Fri Aug  4 08:25:03 2017
New Revision: 322046
URL: https://svnweb.freebsd.org/changeset/base/322046

Log:
  MFC r321347:
  Account for lock recursion when transfering snaplock to the vnode lock
  in ffs_snapremove().

Modified:
  stable/10/sys/ufs/ffs/ffs_snapshot.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/ufs/ffs/ffs_snapshot.c
==
--- stable/10/sys/ufs/ffs/ffs_snapshot.cFri Aug  4 08:20:26 2017
(r322045)
+++ stable/10/sys/ufs/ffs/ffs_snapshot.cFri Aug  4 08:25:03 2017
(r322046)
@@ -1607,7 +1607,7 @@ ffs_snapremove(vp)
struct buf *ibp;
struct fs *fs;
ufs2_daddr_t numblks, blkno, dblk;
-   int error, loc, last;
+   int error, i, last, loc;
struct snapdata *sn;
 
ip = VTOI(vp);
@@ -1627,10 +1627,14 @@ ffs_snapremove(vp)
ip->i_nextsnap.tqe_prev = 0;
VI_UNLOCK(devvp);
lockmgr(>v_lock, LK_EXCLUSIVE, NULL);
+   for (i = 0; i < sn->sn_lock.lk_recurse; i++)
+   lockmgr(>v_lock, LK_EXCLUSIVE, NULL);
KASSERT(vp->v_vnlock == >sn_lock,
("ffs_snapremove: lost lock mutation")); 
vp->v_vnlock = >v_lock;
VI_LOCK(devvp);
+   while (sn->sn_lock.lk_recurse > 0)
+   lockmgr(>sn_lock, LK_RELEASE, NULL);
lockmgr(>sn_lock, LK_RELEASE, NULL);
try_free_snapdata(devvp);
} else
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r321718 - stable/10/sys/vm

2017-07-30 Thread Konstantin Belousov
Author: kib
Date: Sun Jul 30 10:49:13 2017
New Revision: 321718
URL: https://svnweb.freebsd.org/changeset/base/321718

Log:
  Restore layout of struct vm_map_entry after r321717, same as was done
  in r320889 for stable/11.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  stable/10/sys/vm/vm_map.h

Modified: stable/10/sys/vm/vm_map.h
==
--- stable/10/sys/vm/vm_map.h   Sun Jul 30 10:36:20 2017(r321717)
+++ stable/10/sys/vm/vm_map.h   Sun Jul 30 10:49:13 2017(r321718)
@@ -103,6 +103,7 @@ struct vm_map_entry {
struct vm_map_entry *right; /* right child in binary search tree */
vm_offset_t start;  /* start address */
vm_offset_t end;/* end address */
+   vm_offset_t pad0;
vm_size_t adj_free; /* amount of adjacent free space */
vm_size_t max_free; /* max free space in subtree */
union vm_map_object object; /* object I point to */
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r321717 - in stable/10: lib/libc/sys sys/sys sys/vm

2017-07-30 Thread Konstantin Belousov
Author: kib
Date: Sun Jul 30 10:36:20 2017
New Revision: 321717
URL: https://svnweb.freebsd.org/changeset/base/321717

Log:
  Merge MAP_GUARD.
  
  MFC r316687 (by markj), r320314, r320317, r320338, r320339, r320344, r320430,
  r320560 (by alc), r320801, r320843, r321173, r321230.
  
  Tested by:pho
  Sponsored by: The FreeBSD Foundation

Modified:
  stable/10/lib/libc/sys/mmap.2
  stable/10/lib/libc/sys/munmap.2
  stable/10/sys/sys/mman.h
  stable/10/sys/sys/param.h
  stable/10/sys/vm/vm.h
  stable/10/sys/vm/vm_fault.c
  stable/10/sys/vm/vm_map.c
  stable/10/sys/vm/vm_map.h
  stable/10/sys/vm/vm_mmap.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/mmap.2
==
--- stable/10/lib/libc/sys/mmap.2   Sun Jul 30 08:02:06 2017
(r321716)
+++ stable/10/lib/libc/sys/mmap.2   Sun Jul 30 10:36:20 2017
(r321717)
@@ -28,7 +28,7 @@
 .\"@(#)mmap.2  8.4 (Berkeley) 5/11/95
 .\" $FreeBSD$
 .\"
-.Dd September 17, 2014
+.Dd June 22, 2017
 .Dt MMAP 2
 .Os
 .Sh NAME
@@ -173,9 +173,21 @@ In contrast, if
 .Dv MAP_EXCL
 is specified, the request will fail if a mapping
 already exists within the range.
-.It Dv MAP_HASSEMAPHORE
-Notify the kernel that the region may contain semaphores and that special
-handling may be necessary.
+.It Dv MAP_GUARD
+Instead of a mapping, create a guard of the specified size.
+Guards allow a process to create reservations in its address space,
+which can later be replaced by actual mappings.
+.Pp
+.Fa mmap
+will not create mappings in the address range of a guard unless
+the request specifies
+.Dv MAP_FIXED .
+Guards can be destroyed with
+.Xr munmap 2 .
+Any memory access by a thread to the guarded range results
+in the delivery of a
+.Dv SIGSEGV
+signal to that thread.
 .It Dv MAP_NOCORE
 Region is not included in a core file.
 .It Dv MAP_NOSYNC
@@ -278,6 +290,7 @@ must include at least
 .Dv PROT_READ
 and
 .Dv PROT_WRITE .
+.Pp
 This option creates
 a memory region that grows to at most
 .Fa len
@@ -288,6 +301,12 @@ stack top is the starting address returned by the call
 bytes.
 The bottom of the stack at maximum growth is the starting
 address returned by the call.
+.Pp
+Stacks created with
+.Dv MAP_STACK
+automatically grow.
+Guards prevent inadvertent use of the regions into which those
+stacks can grow without requiring mapping the whole stack in advance.
 .El
 .Pp
 The
@@ -375,6 +394,7 @@ were specified.
 .It Bq Er EINVAL
 None of
 .Dv MAP_ANON ,
+.Dv MAP_GUARD ,
 .Dv MAP_PRIVATE ,
 .Dv MAP_SHARED ,
 or
@@ -424,6 +444,25 @@ were specified, but the requested region is already us
 was specified, but
 .Dv MAP_FIXED
 was not.
+.It Bq Er EINVAL
+.Dv MAP_GUARD
+was specified, but the
+.Fa offset
+argument was not zero, the
+.Fa fd
+argument was not -1, or the
+.Fa prot
+argument was not
+.Dv PROT_NONE .
+.It Bq Er EINVAL
+.Dv MAP_GUARD
+was specified together with one of the flags
+.Dv MAP_ANON ,
+.Dv MAP_PREFAULT ,
+.Dv MAP_PREFAULT_READ ,
+.Dv MAP_PRIVATE ,
+.Dv MAP_SHARED ,
+.Dv MAP_STACK .
 .It Bq Er ENODEV
 .Dv MAP_ANON
 has not been specified and

Modified: stable/10/lib/libc/sys/munmap.2
==
--- stable/10/lib/libc/sys/munmap.2 Sun Jul 30 08:02:06 2017
(r321716)
+++ stable/10/lib/libc/sys/munmap.2 Sun Jul 30 10:36:20 2017
(r321717)
@@ -28,7 +28,7 @@
 .\"@(#)munmap.28.3 (Berkeley) 5/27/94
 .\" $FreeBSD$
 .\"
-.Dd May 27, 1994
+.Dd June 22, 2017
 .Dt MUNMAP 2
 .Os
 .Sh NAME
@@ -44,7 +44,7 @@
 The
 .Fn munmap
 system call
-deletes the mappings for the specified address range,
+deletes the mappings and guards for the specified address range,
 and causes further references to addresses within the range
 to generate invalid memory references.
 .Sh RETURN VALUES

Modified: stable/10/sys/sys/mman.h
==
--- stable/10/sys/sys/mman.hSun Jul 30 08:02:06 2017(r321716)
+++ stable/10/sys/sys/mman.hSun Jul 30 10:36:20 2017(r321717)
@@ -90,6 +90,7 @@
 /*
  * Extended flags
  */
+#defineMAP_GUARD0x2000 /* reserve but don't map address 
range */
 #defineMAP_EXCL 0x4000 /* for MAP_FIXED, fail if address 
is used */
 #defineMAP_NOCORE   0x0002 /* dont include these pages in a 
coredump */
 #defineMAP_PREFAULT_READ 0x0004 /* prefault mapping for reading */

Modified: stable/10/sys/sys/param.h
==
--- stable/10/sys/sys/param.h   Sun Jul 30 08:02:06 2017(r321716)
+++ stable/10/sys/sys/param.h   Sun Jul 30 10:36:20 2017(r321717)
@@ -58,7 +58,7 @@
  * in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1003515  /* Master, propagated to newvers */
+#define 

svn commit: r321677 - stable/10/sys/vm

2017-07-29 Thread Konstantin Belousov
Author: kib
Date: Sat Jul 29 08:24:51 2017
New Revision: 321677
URL: https://svnweb.freebsd.org/changeset/base/321677

Log:
  MFC r321371:
  Do not allocate struct kinfo_vmobject on stack.

Modified:
  stable/10/sys/vm/vm_object.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_object.c
==
--- stable/10/sys/vm/vm_object.cSat Jul 29 07:59:28 2017
(r321676)
+++ stable/10/sys/vm/vm_object.cSat Jul 29 08:24:51 2017
(r321677)
@@ -2279,7 +2279,7 @@ vm_object_vnode(vm_object_t object)
 static int
 sysctl_vm_object_list(SYSCTL_HANDLER_ARGS)
 {
-   struct kinfo_vmobject kvo;
+   struct kinfo_vmobject *kvo;
char *fullpath, *freepath;
struct vnode *vp;
struct vattr va;
@@ -2304,6 +2304,7 @@ sysctl_vm_object_list(SYSCTL_HANDLER_ARGS)
count * 11 / 10));
}
 
+   kvo = malloc(sizeof(*kvo), M_TEMP, M_WAITOK);
error = 0;
 
/*
@@ -2321,13 +2322,13 @@ sysctl_vm_object_list(SYSCTL_HANDLER_ARGS)
continue;
}
mtx_unlock(_object_list_mtx);
-   kvo.kvo_size = ptoa(obj->size);
-   kvo.kvo_resident = obj->resident_page_count;
-   kvo.kvo_ref_count = obj->ref_count;
-   kvo.kvo_shadow_count = obj->shadow_count;
-   kvo.kvo_memattr = obj->memattr;
-   kvo.kvo_active = 0;
-   kvo.kvo_inactive = 0;
+   kvo->kvo_size = ptoa(obj->size);
+   kvo->kvo_resident = obj->resident_page_count;
+   kvo->kvo_ref_count = obj->ref_count;
+   kvo->kvo_shadow_count = obj->shadow_count;
+   kvo->kvo_memattr = obj->memattr;
+   kvo->kvo_active = 0;
+   kvo->kvo_inactive = 0;
TAILQ_FOREACH(m, >memq, listq) {
/*
 * A page may belong to the object but be
@@ -2339,45 +2340,45 @@ sysctl_vm_object_list(SYSCTL_HANDLER_ARGS)
 * approximation of the system anyway.
 */
if (m->queue == PQ_ACTIVE)
-   kvo.kvo_active++;
+   kvo->kvo_active++;
else if (m->queue == PQ_INACTIVE)
-   kvo.kvo_inactive++;
+   kvo->kvo_inactive++;
}
 
-   kvo.kvo_vn_fileid = 0;
-   kvo.kvo_vn_fsid = 0;
+   kvo->kvo_vn_fileid = 0;
+   kvo->kvo_vn_fsid = 0;
freepath = NULL;
fullpath = "";
vp = NULL;
switch (obj->type) {
case OBJT_DEFAULT:
-   kvo.kvo_type = KVME_TYPE_DEFAULT;
+   kvo->kvo_type = KVME_TYPE_DEFAULT;
break;
case OBJT_VNODE:
-   kvo.kvo_type = KVME_TYPE_VNODE;
+   kvo->kvo_type = KVME_TYPE_VNODE;
vp = obj->handle;
vref(vp);
break;
case OBJT_SWAP:
-   kvo.kvo_type = KVME_TYPE_SWAP;
+   kvo->kvo_type = KVME_TYPE_SWAP;
break;
case OBJT_DEVICE:
-   kvo.kvo_type = KVME_TYPE_DEVICE;
+   kvo->kvo_type = KVME_TYPE_DEVICE;
break;
case OBJT_PHYS:
-   kvo.kvo_type = KVME_TYPE_PHYS;
+   kvo->kvo_type = KVME_TYPE_PHYS;
break;
case OBJT_DEAD:
-   kvo.kvo_type = KVME_TYPE_DEAD;
+   kvo->kvo_type = KVME_TYPE_DEAD;
break;
case OBJT_SG:
-   kvo.kvo_type = KVME_TYPE_SG;
+   kvo->kvo_type = KVME_TYPE_SG;
break;
case OBJT_MGTDEVICE:
-   kvo.kvo_type = KVME_TYPE_MGTDEVICE;
+   kvo->kvo_type = KVME_TYPE_MGTDEVICE;
break;
default:
-   kvo.kvo_type = KVME_TYPE_UNKNOWN;
+   kvo->kvo_type = KVME_TYPE_UNKNOWN;
break;
}
VM_OBJECT_RUNLOCK(obj);
@@ -2385,27 +2386,28 @@ sysctl_vm_object_list(SYSCTL_HANDLER_ARGS)
vn_fullpath(curthread, vp, , );
vn_lock(vp, LK_SHARED | LK_RETRY);
if (VOP_GETATTR(vp, , curthread->td_ucred) == 0) {
-   kvo.kvo_vn_fileid = va.va_fileid;
-   kvo.kvo_vn_fsid = va.va_fsid;
+   kvo->kvo_vn_fileid = va.va_fileid;
+

svn commit: r321074 - in stable/10/lib/libc: include stdio

2017-07-17 Thread Konstantin Belousov
Author: kib
Date: Mon Jul 17 14:09:34 2017
New Revision: 321074
URL: https://svnweb.freebsd.org/changeset/base/321074

Log:
  MFC r320472,r320508,r320509:
  Make stdio deferred cancel-safe.
  
  Requested by: eugen

Modified:
  stable/10/lib/libc/include/libc_private.h
  stable/10/lib/libc/stdio/fclose.c
  stable/10/lib/libc/stdio/fflush.c
  stable/10/lib/libc/stdio/fgetc.c
  stable/10/lib/libc/stdio/fgetln.c
  stable/10/lib/libc/stdio/fgets.c
  stable/10/lib/libc/stdio/fgetwc.c
  stable/10/lib/libc/stdio/fgetwln.c
  stable/10/lib/libc/stdio/fgetws.c
  stable/10/lib/libc/stdio/fputc.c
  stable/10/lib/libc/stdio/fputs.c
  stable/10/lib/libc/stdio/fputwc.c
  stable/10/lib/libc/stdio/fputws.c
  stable/10/lib/libc/stdio/fread.c
  stable/10/lib/libc/stdio/freopen.c
  stable/10/lib/libc/stdio/fscanf.c
  stable/10/lib/libc/stdio/fseek.c
  stable/10/lib/libc/stdio/fwrite.c
  stable/10/lib/libc/stdio/getc.c
  stable/10/lib/libc/stdio/getchar.c
  stable/10/lib/libc/stdio/getdelim.c
  stable/10/lib/libc/stdio/gets.c
  stable/10/lib/libc/stdio/local.h
  stable/10/lib/libc/stdio/perror.c
  stable/10/lib/libc/stdio/putc.c
  stable/10/lib/libc/stdio/putchar.c
  stable/10/lib/libc/stdio/puts.c
  stable/10/lib/libc/stdio/putw.c
  stable/10/lib/libc/stdio/refill.c
  stable/10/lib/libc/stdio/scanf.c
  stable/10/lib/libc/stdio/setvbuf.c
  stable/10/lib/libc/stdio/stdio.c
  stable/10/lib/libc/stdio/ungetc.c
  stable/10/lib/libc/stdio/ungetwc.c
  stable/10/lib/libc/stdio/vfprintf.c
  stable/10/lib/libc/stdio/vfscanf.c
  stable/10/lib/libc/stdio/vfwprintf.c
  stable/10/lib/libc/stdio/vfwscanf.c
  stable/10/lib/libc/stdio/vscanf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/include/libc_private.h
==
--- stable/10/lib/libc/include/libc_private.h   Mon Jul 17 09:26:42 2017
(r321073)
+++ stable/10/lib/libc/include/libc_private.h   Mon Jul 17 14:09:34 2017
(r321074)
@@ -405,4 +405,9 @@ void __libc_map_stacks_exec(void);
 void   _pthread_cancel_enter(int);
 void   _pthread_cancel_leave(int);
 
+struct _pthread_cleanup_info;
+void   ___pthread_cleanup_push_imp(void (*)(void *), void *,
+   struct _pthread_cleanup_info *);
+void   ___pthread_cleanup_pop_imp(int);
+
 #endif /* _LIBC_PRIVATE_H_ */

Modified: stable/10/lib/libc/stdio/fclose.c
==
--- stable/10/lib/libc/stdio/fclose.c   Mon Jul 17 09:26:42 2017
(r321073)
+++ stable/10/lib/libc/stdio/fclose.c   Mon Jul 17 14:09:34 2017
(r321074)
@@ -97,7 +97,7 @@ fdclose(FILE *fp, int *fdp)
return (EOF);
}
 
-   FLOCKFILE(fp);
+   FLOCKFILE_CANCELSAFE(fp);
r = 0;
if (fp->_close != __sclose) {
r = EOF;
@@ -115,7 +115,7 @@ fdclose(FILE *fp, int *fdp)
*fdp = fp->_file;
r = cleanfile(fp, false);
}
-   FUNLOCKFILE(fp);
+   FUNLOCKFILE_CANCELSAFE();
 
return (r);
 }
@@ -130,9 +130,9 @@ fclose(FILE *fp)
return (EOF);
}
 
-   FLOCKFILE(fp);
+   FLOCKFILE_CANCELSAFE(fp);
r = cleanfile(fp, true);
-   FUNLOCKFILE(fp);
+   FUNLOCKFILE_CANCELSAFE();
 
return (r);
 }

Modified: stable/10/lib/libc/stdio/fflush.c
==
--- stable/10/lib/libc/stdio/fflush.c   Mon Jul 17 09:26:42 2017
(r321073)
+++ stable/10/lib/libc/stdio/fflush.c   Mon Jul 17 14:09:34 2017
(r321074)
@@ -56,7 +56,7 @@ fflush(FILE *fp)
 
if (fp == NULL)
return (_fwalk(sflush_locked));
-   FLOCKFILE(fp);
+   FLOCKFILE_CANCELSAFE(fp);
 
/*
 * There is disagreement about the correct behaviour of fflush()
@@ -76,7 +76,7 @@ fflush(FILE *fp)
retval = 0;
else
retval = __sflush(fp);
-   FUNLOCKFILE(fp);
+   FUNLOCKFILE_CANCELSAFE();
return (retval);
 }
 
@@ -143,8 +143,8 @@ sflush_locked(FILE *fp)
 {
int ret;
 
-   FLOCKFILE(fp);
+   FLOCKFILE_CANCELSAFE(fp);
ret = __sflush(fp);
-   FUNLOCKFILE(fp);
+   FUNLOCKFILE_CANCELSAFE();
return (ret);
 }

Modified: stable/10/lib/libc/stdio/fgetc.c
==
--- stable/10/lib/libc/stdio/fgetc.cMon Jul 17 09:26:42 2017
(r321073)
+++ stable/10/lib/libc/stdio/fgetc.cMon Jul 17 14:09:34 2017
(r321074)
@@ -46,10 +46,10 @@ int
 fgetc(FILE *fp)
 {
int retval;
-   FLOCKFILE(fp);
+   FLOCKFILE_CANCELSAFE(fp);
/* Orientation set by __sgetc() when buffer is empty. */
/* ORIENT(fp, -1); */
retval = __sgetc(fp);
-   FUNLOCKFILE(fp);
+   FUNLOCKFILE_CANCELSAFE();
return (retval);
 }

Modified: stable/10/lib/libc/stdio/fgetln.c

svn commit: r321005 - stable/10/sys/i386/i386

2017-07-15 Thread Konstantin Belousov
Author: kib
Date: Sat Jul 15 06:38:01 2017
New Revision: 321005
URL: https://svnweb.freebsd.org/changeset/base/321005

Log:
  MFC r320804:
  Fix handling of one more possible exception on return to usermode.

Modified:
  stable/10/sys/i386/i386/trap.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/i386/i386/trap.c
==
--- stable/10/sys/i386/i386/trap.c  Sat Jul 15 06:33:39 2017
(r321004)
+++ stable/10/sys/i386/i386/trap.c  Sat Jul 15 06:38:01 2017
(r321005)
@@ -567,11 +567,7 @@ trap(struct trapframe *frame)
vm86_trap((struct vm86frame *)frame);
goto out;
}
-   if (type == T_STKFLT)
-   break;
-
/* FALL THROUGH */
-
case T_SEGNPFLT:/* segment not present fault */
if (curpcb->pcb_flags & PCB_VM86CALL)
break;
@@ -612,6 +608,9 @@ trap(struct trapframe *frame)
frame->tf_eip = (int)doreti_iret_fault;
goto out;
}
+   if (type == T_STKFLT)
+   break;
+
if (frame->tf_eip == (int)doreti_popl_ds) {
frame->tf_eip = (int)doreti_popl_ds_fault;
goto out;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320940 - stable/10/sys/sys

2017-07-13 Thread Konstantin Belousov
Author: kib
Date: Thu Jul 13 08:33:02 2017
New Revision: 320940
URL: https://svnweb.freebsd.org/changeset/base/320940

Log:
  MFC r320755,r320762,r320893:
  BIT_FLS(9).

Modified:
  stable/10/sys/sys/bitset.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/sys/bitset.h
==
--- stable/10/sys/sys/bitset.h  Thu Jul 13 08:29:01 2017(r320939)
+++ stable/10/sys/sys/bitset.h  Thu Jul 13 08:33:02 2017(r320940)
@@ -206,6 +206,21 @@
__bit;  \
 })
 
+#defineBIT_FLS(_s, p) __extension__ ({ 
\
+   __size_t __i;   \
+   int __bit;  \
+   \
+   __bit = 0;  \
+   for (__i = __bitset_words((_s)); __i > 0; __i--) {  \
+   if ((p)->__bits[__i - 1] != 0) {\
+   __bit = flsl((p)->__bits[__i - 1]); \
+   __bit += (__i - 1) * _BITSET_BITS;  \
+   break;  \
+   }   \
+   }   \
+   __bit;  \
+})
+
 #defineBIT_COUNT(_s, p) __extension__ ({   
\
__size_t __i;   \
int __count;\
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320888 - stable/10/libexec/rtld-elf

2017-07-10 Thread Konstantin Belousov
Author: kib
Date: Tue Jul 11 05:36:02 2017
New Revision: 320888
URL: https://svnweb.freebsd.org/changeset/base/320888

Log:
  MFC r320658:
  When reporting undefined symbol, note the version, if specified.

Modified:
  stable/10/libexec/rtld-elf/rtld.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld.c
==
--- stable/10/libexec/rtld-elf/rtld.c   Tue Jul 11 05:33:07 2017
(r320887)
+++ stable/10/libexec/rtld-elf/rtld.c   Tue Jul 11 05:36:02 2017
(r320888)
@@ -1547,6 +1547,7 @@ find_symdef(unsigned long symnum, const Obj_Entry *ref
 const Elf_Sym *ref;
 const Elf_Sym *def;
 const Obj_Entry *defobj;
+const Ver_Entry *ve;
 SymLook req;
 const char *name;
 int res;
@@ -1566,6 +1567,7 @@ find_symdef(unsigned long symnum, const Obj_Entry *ref
 name = refobj->strtab + ref->st_name;
 def = NULL;
 defobj = NULL;
+ve = NULL;
 
 /*
  * We don't have to do a full scale lookup if the symbol is local.
@@ -1582,7 +1584,7 @@ find_symdef(unsigned long symnum, const Obj_Entry *ref
}
symlook_init(, name);
req.flags = flags;
-   req.ventry = fetch_ventry(refobj, symnum);
+   ve = req.ventry = fetch_ventry(refobj, symnum);
req.lockstate = lockstate;
res = symlook_default(, refobj);
if (res == 0) {
@@ -1612,7 +1614,8 @@ find_symdef(unsigned long symnum, const Obj_Entry *ref
}
 } else {
if (refobj != _rtld)
-   _rtld_error("%s: Undefined symbol \"%s\"", refobj->path, name);
+   _rtld_error("%s: Undefined symbol \"%s%s%s\"", refobj->path, name,
+ ve != NULL ? "@" : "", ve != NULL ? ve->name : "");
 }
 return def;
 }
@@ -3283,7 +3286,8 @@ do_dlsym(void *handle, const char *name, void *retaddr
return (sym);
 }
 
-_rtld_error("Undefined symbol \"%s\"", name);
+_rtld_error("Undefined symbol \"%s%s%s\"", name, ve != NULL ? "@" : "",
+  ve != NULL ? ve->name : "");
 lock_release(rtld_bind_lock, );
 LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name);
 return NULL;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320864 - stable/10/sys/kern

2017-07-10 Thread Konstantin Belousov
Author: kib
Date: Mon Jul 10 06:08:44 2017
New Revision: 320864
URL: https://svnweb.freebsd.org/changeset/base/320864

Log:
  MFC r320619:
  Resolve confusion between different error code spaces.

Modified:
  stable/10/sys/kern/kern_exec.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_exec.c
==
--- stable/10/sys/kern/kern_exec.c  Mon Jul 10 05:59:06 2017
(r320863)
+++ stable/10/sys/kern/kern_exec.c  Mon Jul 10 06:08:44 2017
(r320864)
@@ -1043,9 +1043,9 @@ exec_unmap_first_page(imgp)
 }
 
 /*
- * Destroy old address space, and allocate a new stack
- * The new stack is only SGROWSIZ large because it is grown
- * automatically in trap.c.
+ * Destroy old address space, and allocate a new stack.
+ * The new stack is only sgrowsiz large because it is grown
+ * automatically on a page fault.
  */
 int
 exec_new_vmspace(imgp, sv)
@@ -1099,9 +1099,9 @@ exec_new_vmspace(imgp, sv)
VM_PROT_READ | VM_PROT_EXECUTE,
VM_PROT_READ | VM_PROT_EXECUTE,
MAP_INHERIT_SHARE | MAP_ACC_NO_CHARGE);
-   if (error) {
+   if (error != KERN_SUCCESS) {
vm_object_deallocate(obj);
-   return (error);
+   return (vm_mmap_to_errno(error));
}
}
 
@@ -1125,10 +1125,9 @@ exec_new_vmspace(imgp, sv)
stack_addr = sv->sv_usrstack - ssiz;
error = vm_map_stack(map, stack_addr, (vm_size_t)ssiz,
obj != NULL && imgp->stack_prot != 0 ? imgp->stack_prot :
-   sv->sv_stackprot,
-   VM_PROT_ALL, MAP_STACK_GROWS_DOWN);
-   if (error)
-   return (error);
+   sv->sv_stackprot, VM_PROT_ALL, MAP_STACK_GROWS_DOWN);
+   if (error != KERN_SUCCESS)
+   return (vm_mmap_to_errno(error));
 
 #ifdef __ia64__
/* Allocate a new register stack */
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320823 - stable/10/lib/libc/gen

2017-07-08 Thread Konstantin Belousov
Author: kib
Date: Sun Jul  9 03:57:24 2017
New Revision: 320823
URL: https://svnweb.freebsd.org/changeset/base/320823

Log:
  MFC r320570:
  Correct signatures of several pthreads stubs.

Modified:
  stable/10/lib/libc/gen/_pthread_stubs.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/_pthread_stubs.c
==
--- stable/10/lib/libc/gen/_pthread_stubs.c Sun Jul  9 03:54:10 2017
(r320822)
+++ stable/10/lib/libc/gen/_pthread_stubs.c Sun Jul  9 03:57:24 2017
(r320823)
@@ -271,10 +271,11 @@ STUB_FUNC2(pthread_kill, PJT_KILL, int, void *, int)
 STUB_FUNC2(pthread_setcancelstate, PJT_SETCANCELSTATE, int, int, void *)
 STUB_FUNC2(pthread_setcanceltype, PJT_SETCANCELTYPE, int, int, void *)
 STUB_FUNC(pthread_testcancel, PJT_TESTCANCEL, void)
-STUB_FUNC1(__pthread_cleanup_pop_imp, PJT_CLEANUP_POP_IMP, int, int)
-STUB_FUNC2(__pthread_cleanup_push_imp, PJT_CLEANUP_PUSH_IMP, void, void*, void 
*);
-STUB_FUNC1(_pthread_cancel_enter, PJT_CANCEL_ENTER, int, int)
-STUB_FUNC1(_pthread_cancel_leave, PJT_CANCEL_LEAVE, int, int)
+STUB_FUNC1(__pthread_cleanup_pop_imp, PJT_CLEANUP_POP_IMP, void, int)
+STUB_FUNC3(__pthread_cleanup_push_imp, PJT_CLEANUP_PUSH_IMP, void, void *,
+void *, void *);
+STUB_FUNC1(_pthread_cancel_enter, PJT_CANCEL_ENTER, void, int)
+STUB_FUNC1(_pthread_cancel_leave, PJT_CANCEL_LEAVE, void, int)
 
 static int
 stub_zero(void)
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320565 - stable/10/sys/vm

2017-07-01 Thread Konstantin Belousov
Author: kib
Date: Sun Jul  2 03:50:22 2017
New Revision: 320565
URL: https://svnweb.freebsd.org/changeset/base/320565

Log:
  MFC r320332:
  Style.

Modified:
  stable/10/sys/vm/vm_map.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_map.c
==
--- stable/10/sys/vm/vm_map.c   Sun Jul  2 03:47:56 2017(r320564)
+++ stable/10/sys/vm/vm_map.c   Sun Jul  2 03:50:22 2017(r320565)
@@ -2637,9 +2637,9 @@ vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset
 * If VM_MAP_WIRE_HOLESOK was specified, skip this check.
 */
next_entry:
-   if (((flags & VM_MAP_WIRE_HOLESOK) == 0) &&
-   (entry->end < end && (entry->next == >header ||
-   entry->next->start > entry->end))) {
+   if ((flags & VM_MAP_WIRE_HOLESOK) == 0 &&
+   entry->end < end && (entry->next == >header ||
+   entry->next->start > entry->end)) {
end = entry->end;
rv = KERN_INVALID_ADDRESS;
goto done;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320525 - stable/10/sys/amd64/ia32

2017-06-30 Thread Konstantin Belousov
Author: kib
Date: Sat Jul  1 03:38:12 2017
New Revision: 320525
URL: https://svnweb.freebsd.org/changeset/base/320525

Log:
  MFC r320308:
  Translate between abridged and full x87 tags for compat32 
ptrace(PT_GETFPREGS).

Modified:
  stable/10/sys/amd64/ia32/ia32_reg.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/ia32/ia32_reg.c
==
--- stable/10/sys/amd64/ia32/ia32_reg.c Sat Jul  1 03:33:26 2017
(r320524)
+++ stable/10/sys/amd64/ia32/ia32_reg.c Sat Jul  1 03:38:12 2017
(r320525)
@@ -156,7 +156,7 @@ fill_fpregs32(struct thread *td, struct fpreg32 *regs)
/* FPU control/status */
penv_87->en_cw = penv_xmm->en_cw;
penv_87->en_sw = penv_xmm->en_sw;
-   penv_87->en_tw = penv_xmm->en_tw;
+
/*
 * XXX for en_fip/fcs/foo/fos, check if the fxsave format
 * uses the old-style layout for 32 bit user apps.  If so,
@@ -170,9 +170,13 @@ fill_fpregs32(struct thread *td, struct fpreg32 *regs)
/* Entry into the kernel always sets TF_HASSEGS */
penv_87->en_fos = td->td_frame->tf_ds;
 
-   /* FPU registers */
-   for (i = 0; i < 8; ++i)
+   /* FPU registers and tags */
+   penv_87->en_tw = 0x;
+   for (i = 0; i < 8; ++i) {
sv_87->sv_ac[i] = sv_fpu->sv_fp[i].fp_acc;
+   if ((penv_xmm->en_tw & (1 << i)) != 0)
+   penv_87->en_tw &= ~(3 << i * 2);
+   }
 
return (0);
 }
@@ -189,15 +193,19 @@ set_fpregs32(struct thread *td, struct fpreg32 *regs)
/* FPU control/status */
penv_xmm->en_cw = penv_87->en_cw;
penv_xmm->en_sw = penv_87->en_sw;
-   penv_xmm->en_tw = penv_87->en_tw;
penv_xmm->en_rip = penv_87->en_fip;
/* penv_87->en_fcs and en_fos ignored, see above */
penv_xmm->en_opcode = penv_87->en_opcode;
penv_xmm->en_rdp = penv_87->en_foo;
 
-   /* FPU registers */
-   for (i = 0; i < 8; ++i)
+   /* FPU registers and tags */
+   penv_xmm->en_tw = 0;
+   for (i = 0; i < 8; ++i) {
sv_fpu->sv_fp[i].fp_acc = sv_87->sv_ac[i];
+   if ((penv_87->en_tw & (3 << i * 2)) != (3 << i * 2))
+   penv_xmm->en_tw |= 1 << i;
+   }
+
for (i = 8; i < 16; ++i)
bzero(_fpu->sv_fp[i].fp_acc, 
sizeof(sv_fpu->sv_fp[i].fp_acc));
fpuuserinited(td);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320437 - stable/10/sys/vm

2017-06-27 Thread Konstantin Belousov
Author: kib
Date: Wed Jun 28 05:21:00 2017
New Revision: 320437
URL: https://svnweb.freebsd.org/changeset/base/320437

Log:
  MFC r320202:
  Call pmap_copy() only for map entries which have the backing object
  instantiated.

Modified:
  stable/10/sys/vm/vm_map.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_map.c
==
--- stable/10/sys/vm/vm_map.c   Wed Jun 28 05:20:28 2017(r320436)
+++ stable/10/sys/vm/vm_map.c   Wed Jun 28 05:21:00 2017(r320437)
@@ -3185,6 +3185,10 @@ vm_map_copy_entry(
fake_entry->next = curthread->td_map_def_user;
curthread->td_map_def_user = fake_entry;
}
+
+   pmap_copy(dst_map->pmap, src_map->pmap,
+   dst_entry->start, dst_entry->end - dst_entry->start,
+   src_entry->start);
} else {
dst_entry->object.vm_object = NULL;
dst_entry->offset = 0;
@@ -3194,9 +3198,6 @@ vm_map_copy_entry(
*fork_charge += size;
}
}
-
-   pmap_copy(dst_map->pmap, src_map->pmap, dst_entry->start,
-   dst_entry->end - dst_entry->start, src_entry->start);
} else {
/*
 * We don't want to make writeable wired pages copy-on-write.
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320435 - stable/10/sys/vm

2017-06-27 Thread Konstantin Belousov
Author: kib
Date: Wed Jun 28 04:53:06 2017
New Revision: 320435
URL: https://svnweb.freebsd.org/changeset/base/320435

Log:
  MFC r320201:
  Assert that the protection of a new map entry is a subset of the max
  protection.

Modified:
  stable/10/sys/vm/vm_map.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_map.c
==
--- stable/10/sys/vm/vm_map.c   Wed Jun 28 04:25:20 2017(r320434)
+++ stable/10/sys/vm/vm_map.c   Wed Jun 28 04:53:06 2017(r320435)
@@ -1143,6 +1143,8 @@ vm_map_insert(vm_map_t map, vm_object_t object, vm_oof
("vm_map_insert: kmem or kernel object and COW"));
KASSERT(object == NULL || (cow & MAP_NOFAULT) == 0,
("vm_map_insert: paradoxical MAP_NOFAULT request"));
+   KASSERT((prot & ~max) == 0,
+   ("prot %#x is not subset of max_prot %#x", prot, max));
 
/*
 * Check that the start and end points are not bogus.
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320312 - stable/10/lib/libc/gen

2017-06-24 Thread Konstantin Belousov
Author: kib
Date: Sat Jun 24 14:44:59 2017
New Revision: 320312
URL: https://svnweb.freebsd.org/changeset/base/320312

Log:
  MFC r320052:
  Do not leak syslog_mutex on cancellation.

Modified:
  stable/10/lib/libc/gen/syslog.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/syslog.c
==
--- stable/10/lib/libc/gen/syslog.c Sat Jun 24 14:41:57 2017
(r320311)
+++ stable/10/lib/libc/gen/syslog.c Sat Jun 24 14:44:59 2017
(r320312)
@@ -129,8 +129,8 @@ syslog(int pri, const char *fmt, ...)
va_end(ap);
 }
 
-void
-vsyslog(int pri, const char *fmt, va_list ap)
+static void
+vsyslog1(int pri, const char *fmt, va_list ap)
 {
int cnt;
char ch, *p;
@@ -151,13 +151,9 @@ vsyslog(int pri, const char *fmt, va_list ap)
 
saved_errno = errno;
 
-   THREAD_LOCK();
-
/* Check priority against setlogmask values. */
-   if (!(LOG_MASK(LOG_PRI(pri)) & LogMask)) {
-   THREAD_UNLOCK();
+   if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
return;
-   }
 
/* Set default facility if none specified. */
if ((pri & LOG_FACMASK) == 0)
@@ -167,10 +163,8 @@ vsyslog(int pri, const char *fmt, va_list ap)
tbuf_cookie.base = tbuf;
tbuf_cookie.left = sizeof(tbuf);
fp = fwopen(_cookie, writehook);
-   if (fp == NULL) {
-   THREAD_UNLOCK();
+   if (fp == NULL)
return;
-   }
 
/* Build the message. */
(void)time();
@@ -200,7 +194,6 @@ vsyslog(int pri, const char *fmt, va_list ap)
fmt_fp = fwopen(_cookie, writehook);
if (fmt_fp == NULL) {
fclose(fp);
-   THREAD_UNLOCK();
return;
}
 
@@ -285,10 +278,8 @@ vsyslog(int pri, const char *fmt, va_list ap)
 */
disconnectlog();
connectlog();
-   if (send(LogFile, tbuf, cnt, 0) >= 0) {
-   THREAD_UNLOCK();
+   if (send(LogFile, tbuf, cnt, 0) >= 0)
return;
-   }
/*
 * if the resend failed, fall through to
 * possible scenario 2
@@ -303,15 +294,11 @@ vsyslog(int pri, const char *fmt, va_list ap)
if (status == CONNPRIV)
break;
_usleep(1);
-   if (send(LogFile, tbuf, cnt, 0) >= 0) {
-   THREAD_UNLOCK();
+   if (send(LogFile, tbuf, cnt, 0) >= 0)
return;
-   }
}
-   } else {
-   THREAD_UNLOCK();
+   } else
return;
-   }
 
/*
 * Output the message to the console; try not to block
@@ -333,10 +320,25 @@ vsyslog(int pri, const char *fmt, va_list ap)
(void)_writev(fd, iov, 2);
(void)_close(fd);
}
+}
 
+static void
+syslog_cancel_cleanup(void *arg __unused)
+{
+
THREAD_UNLOCK();
 }
 
+void
+vsyslog(int pri, const char *fmt, va_list ap)
+{
+
+   THREAD_LOCK();
+   pthread_cleanup_push(syslog_cancel_cleanup, NULL);
+   vsyslog1(pri, fmt, ap);
+   pthread_cleanup_pop(1);
+}
+
 /* Should be called with mutex acquired */
 static void
 disconnectlog(void)
@@ -423,9 +425,11 @@ openlog_unlocked(const char *ident, int logstat, int l
 void
 openlog(const char *ident, int logstat, int logfac)
 {
+
THREAD_LOCK();
+   pthread_cleanup_push(syslog_cancel_cleanup, NULL);
openlog_unlocked(ident, logstat, logfac);
-   THREAD_UNLOCK();
+   pthread_cleanup_pop(1);
 }
 
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320147 - stable/10/sys/kern

2017-06-20 Thread Konstantin Belousov
Author: kib
Date: Tue Jun 20 15:02:59 2017
New Revision: 320147
URL: https://svnweb.freebsd.org/changeset/base/320147

Log:
  MFC r319916:
  Remove stray return.

Modified:
  stable/10/sys/kern/subr_prf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/subr_prf.c
==
--- stable/10/sys/kern/subr_prf.c   Tue Jun 20 14:35:19 2017
(r320146)
+++ stable/10/sys/kern/subr_prf.c   Tue Jun 20 15:02:59 2017
(r320147)
@@ -374,7 +374,6 @@ log_console(struct uio *uio)
msgbuftrigger = 1;
free(uio, M_IOV);
free(consbuffer, M_TEMP);
-   return;
 }
 
 int
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r319653 - in stable/10: include sys/sys

2017-06-07 Thread Konstantin Belousov
Author: kib
Date: Wed Jun  7 11:43:36 2017
New Revision: 319653
URL: https://svnweb.freebsd.org/changeset/base/319653

Log:
  MFC r318780:
  Use __BSD_VISIBLE test instead checking for absense of _POSIX_SOURCE.

Modified:
  stable/10/include/termios.h
  stable/10/sys/sys/_termios.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/include/termios.h
==
--- stable/10/include/termios.h Wed Jun  7 11:42:43 2017(r319652)
+++ stable/10/include/termios.h Wed Jun  7 11:43:36 2017(r319653)
@@ -42,12 +42,12 @@ typedef __pid_t pid_t;
 #define_PID_T_DECLARED
 #endif
 
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineOXTABS  TAB3
 #defineMDMBUF  CCAR_OFLOW
 #endif 
 
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineCCEQ(val, c)((c) == (val) && (val) != _POSIX_VDISABLE)
 #endif
 
@@ -57,7 +57,7 @@ typedef   __pid_t pid_t;
 #defineTCSANOW 0   /* make change immediate */
 #defineTCSADRAIN   1   /* drain output, then change */
 #defineTCSAFLUSH   2   /* drain output, flush input */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineTCSASOFT0x10/* flag - don't alter h.w. 
state */
 #endif
 
@@ -95,7 +95,7 @@ __END_DECLS
 
 #endif /* !_TERMIOS_H_ */
 
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #include 
 #include 
 #endif

Modified: stable/10/sys/sys/_termios.h
==
--- stable/10/sys/sys/_termios.hWed Jun  7 11:42:43 2017
(r319652)
+++ stable/10/sys/sys/_termios.hWed Jun  7 11:43:36 2017
(r319653)
@@ -42,15 +42,15 @@
  */
 #defineVEOF0   /* ICANON */
 #defineVEOL1   /* ICANON */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineVEOL2   2   /* ICANON together with IEXTEN */
 #endif
 #defineVERASE  3   /* ICANON */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineVWERASE 4   /* ICANON together with IEXTEN */
 #endif
 #defineVKILL   5   /* ICANON */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineVREPRINT6   /* ICANON together with IEXTEN */
 #defineVERASE2 7   /* ICANON */
 #endif
@@ -58,18 +58,18 @@
 #defineVINTR   8   /* ISIG */
 #defineVQUIT   9   /* ISIG */
 #defineVSUSP   10  /* ISIG */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineVDSUSP  11  /* ISIG together with IEXTEN */
 #endif
 #defineVSTART  12  /* IXON, IXOFF */
 #defineVSTOP   13  /* IXON, IXOFF */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineVLNEXT  14  /* IEXTEN */
 #defineVDISCARD15  /* IEXTEN */
 #endif
 #defineVMIN16  /* !ICANON */
 #defineVTIME   17  /* !ICANON */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineVSTATUS 18  /* ICANON together with IEXTEN */
 /* 19 spare 2 */
 #endif
@@ -91,16 +91,16 @@
 #defineICRNL   0x0100  /* map CR to NL (ala CRMOD) */
 #defineIXON0x0200  /* enable output flow control */
 #defineIXOFF   0x0400  /* enable input flow control */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineIXANY   0x0800  /* any char will restart after 
stop */
 #defineIMAXBEL 0x2000  /* ring bell on input queue 
full */
-#endif  /*_POSIX_SOURCE */
+#endif
 
 /*
  * Output flags - software output processing
  */
 #defineOPOST   0x0001  /* enable following output 
processing */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineONLCR   0x0002  /* map NL to CR-NL (ala CRMOD) 
*/
 #defineTABDLY  0x0004  /* tab delay mask */
 #defineTAB00x  /* no tab delay and 
expansion */
@@ -109,12 +109,12 @@
 #defineOCRNL   0x0010  /* map CR to NL on output */
 #defineONOCR   0x0020  /* no CR output at column 0 */
 #defineONLRET  0x0040  /* NL performs CR function */
-#endif  /*_POSIX_SOURCE */
+#endif
 
 /*
  * Control flags - hardware control of terminal
  */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
 #defineCIGNORE 0x0001  /* ignore control flags */
 #endif
 #defineCSIZE   0x0300  /* character size mask */
@@ -128,7 +128,7 @@
 #definePARODD  0x2000  /* odd parity, else even */
 #defineHUPCL   0x4000  /* hang up on last close */
 #defineCLOCAL

svn commit: r319652 - stable/10/sys/sys

2017-06-07 Thread Konstantin Belousov
Author: kib
Date: Wed Jun  7 11:42:43 2017
New Revision: 319652
URL: https://svnweb.freebsd.org/changeset/base/319652

Log:
  MFC r318781:
  Add BIT_OR2(), BIT_AND2(), BIT_NAND2(), BIT_XOR() and BIT_XOR2().

Modified:
  stable/10/sys/sys/bitset.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/sys/bitset.h
==
--- stable/10/sys/sys/bitset.h  Wed Jun  7 11:39:52 2017(r319651)
+++ stable/10/sys/sys/bitset.h  Wed Jun  7 11:42:43 2017(r319652)
@@ -115,16 +115,46 @@
(d)->__bits[__i] |= (s)->__bits[__i];   \
 } while (0)
 
+#defineBIT_OR2(_s, d, s1, s2) do { 
\
+   __size_t __i;   \
+   for (__i = 0; __i < __bitset_words((_s)); __i++)\
+   (d)->__bits[__i] = (s1)->__bits[__i] | (s2)->__bits[__i];\
+} while (0)
+
 #defineBIT_AND(_s, d, s) do {  
\
__size_t __i;   \
for (__i = 0; __i < __bitset_words((_s)); __i++)\
(d)->__bits[__i] &= (s)->__bits[__i];   \
 } while (0)
 
+#defineBIT_AND2(_s, d, s1, s2) do {
\
+   __size_t __i;   \
+   for (__i = 0; __i < __bitset_words((_s)); __i++)\
+   (d)->__bits[__i] = (s1)->__bits[__i] & (s2)->__bits[__i];\
+} while (0)
+
 #defineBIT_NAND(_s, d, s) do { 
\
__size_t __i;   \
for (__i = 0; __i < __bitset_words((_s)); __i++)\
(d)->__bits[__i] &= ~(s)->__bits[__i];  \
+} while (0)
+
+#defineBIT_NAND2(_s, d, s1, s2) do {   
\
+   __size_t __i;   \
+   for (__i = 0; __i < __bitset_words((_s)); __i++)\
+   (d)->__bits[__i] = (s1)->__bits[__i] & ~(s2)->__bits[__i];\
+} while (0)
+
+#defineBIT_XOR(_s, d, s) do {  
\
+   __size_t __i;   \
+   for (__i = 0; __i < __bitset_words((_s)); __i++)\
+   (d)->__bits[__i] ^= (s)->__bits[__i];   \
+} while (0)
+
+#defineBIT_XOR2(_s, d, s1, s2) do {
\
+   __size_t __i;   \
+   for (__i = 0; __i < __bitset_words((_s)); __i++)\
+   (d)->__bits[__i] = (s1)->__bits[__i] ^ (s2)->__bits[__i];\
 } while (0)
 
 #defineBIT_CLR_ATOMIC(_s, n, p)
\
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r319419 - stable/10/lib/libc/tests/gen

2017-06-01 Thread Konstantin Belousov
Author: kib
Date: Thu Jun  1 13:22:04 2017
New Revision: 319419
URL: https://svnweb.freebsd.org/changeset/base/319419

Log:
  MFC r318450:
  Add tests for some cases in r318298.
  
  PR:   219154

Added:
  stable/10/lib/libc/tests/gen/realpath2_test.c
 - copied unchanged from r318450, head/lib/libc/tests/gen/realpath2_test.c
Modified:
  stable/10/lib/libc/tests/gen/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/tests/gen/Makefile
==
--- stable/10/lib/libc/tests/gen/Makefile   Thu Jun  1 13:20:47 2017
(r319418)
+++ stable/10/lib/libc/tests/gen/Makefile   Thu Jun  1 13:22:04 2017
(r319419)
@@ -11,6 +11,7 @@ ATF_TESTS_C+= ftw_test
 ATF_TESTS_C+=  popen_test
 ATF_TESTS_C+=  posix_spawn_test
 ATF_TESTS_C+=  wordexp_test
+ATF_TESTS_C+=  realpath2_test
 
 # TODO: t_closefrom, t_cpuset, t_fmtcheck, t_randomid,
 # TODO: t_siginfo (fixes require further inspection)

Copied: stable/10/lib/libc/tests/gen/realpath2_test.c (from r318450, 
head/lib/libc/tests/gen/realpath2_test.c)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/gen/realpath2_test.c   Thu Jun  1 13:22:04 
2017(r319419, copy of r318450, head/lib/libc/tests/gen/realpath2_test.c)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2017 Jan Kokemüller
+ * 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 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.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+ATF_TC(realpath_buffer_overflow);
+ATF_TC_HEAD(realpath_buffer_overflow, tc)
+{
+   atf_tc_set_md_var(tc, "descr",
+   "Test for out of bounds read from 'left' array "
+   "(compile realpath.c with '-fsanitize=address')");
+}
+
+ATF_TC_BODY(realpath_buffer_overflow, tc)
+{
+   char path[MAXPATHLEN] = { 0 };
+   char resb[MAXPATHLEN] = { 0 };
+   size_t i;
+
+   path[0] = 'a';
+   path[1] = '/';
+   for (i = 2; i < sizeof(path) - 1; ++i) {
+   path[i] = 'a';
+   }
+
+   ATF_REQUIRE(realpath(path, resb) == NULL);
+}
+
+ATF_TC(realpath_empty_symlink);
+ATF_TC_HEAD(realpath_empty_symlink, tc)
+{
+   atf_tc_set_md_var(tc, "descr",
+   "Test for correct behavior when encountering empty symlinks");
+}
+
+ATF_TC_BODY(realpath_empty_symlink, tc)
+{
+   char path[MAXPATHLEN] = { 0 };
+   char slnk[MAXPATHLEN] = { 0 };
+   char resb[MAXPATHLEN] = { 0 };
+   int fd;
+
+   (void)strlcat(slnk, "empty_symlink", sizeof(slnk));
+
+   ATF_REQUIRE(symlink("", slnk) == 0);
+
+   fd = open("aaa", O_RDONLY | O_CREAT, 0600);
+
+   ATF_REQUIRE(fd >= 0);
+   ATF_REQUIRE(close(fd) == 0);
+
+   (void)strlcat(path, "empty_symlink", sizeof(path));
+   (void)strlcat(path, "/aaa", sizeof(path));
+
+   ATF_REQUIRE_ERRNO(ENOENT, realpath(path, resb) == NULL);
+
+   ATF_REQUIRE(unlink("aaa") == 0);
+   ATF_REQUIRE(unlink(slnk) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+   ATF_TP_ADD_TC(tp, realpath_buffer_overflow);
+   ATF_TP_ADD_TC(tp, realpath_empty_symlink);
+
+   return atf_no_error();
+}
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

svn commit: r319311 - stable/10/lib/libc/sys

2017-05-31 Thread Konstantin Belousov
Author: kib
Date: Wed May 31 09:25:47 2017
New Revision: 319311
URL: https://svnweb.freebsd.org/changeset/base/319311

Log:
  MFC r319086:
  Mention that the basep argument to getdirentries(2) can be NULL.

Modified:
  stable/10/lib/libc/sys/getdirentries.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/getdirentries.2
==
--- stable/10/lib/libc/sys/getdirentries.2  Wed May 31 09:23:21 2017
(r319310)
+++ stable/10/lib/libc/sys/getdirentries.2  Wed May 31 09:25:47 2017
(r319311)
@@ -124,7 +124,10 @@ or
 A value of zero is returned when
 the end of the directory has been reached.
 .Pp
-The
+If the
+.Fa basep
+pointer value is non-NULL ,
+the
 .Fn getdirentries
 system call writes the position of the block read into the location pointed to 
by
 .Fa basep .
@@ -156,7 +159,7 @@ is not a valid file descriptor open for reading.
 .It Bq Er EFAULT
 Either
 .Fa buf
-or
+or non-NULL
 .Fa basep
 point outside the allocated address space.
 .It Bq Er EINVAL
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r319131 - stable/10/lib/libc/stdlib

2017-05-29 Thread Konstantin Belousov
Author: kib
Date: Mon May 29 13:00:39 2017
New Revision: 319131
URL: https://svnweb.freebsd.org/changeset/base/319131

Log:
  MFC r318303:
  Style.

Modified:
  stable/10/lib/libc/stdlib/realpath.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/stdlib/realpath.c
==
--- stable/10/lib/libc/stdlib/realpath.cMon May 29 12:59:24 2017
(r319130)
+++ stable/10/lib/libc/stdlib/realpath.cMon May 29 13:00:39 2017
(r319131)
@@ -89,7 +89,7 @@ realpath1(const char *path, char *resolv
 */
p = strchr(left, '/');
 
-   next_token_len = p ? p - left : left_len;
+   next_token_len = p != NULL ? p - left : left_len;
memcpy(next_token, left, next_token_len);
next_token[next_token_len] = '\0';
 
@@ -112,10 +112,9 @@ realpath1(const char *path, char *resolv
if (next_token[0] == '\0') {
/* Handle consequential slashes. */
continue;
-   }
-   else if (strcmp(next_token, ".") == 0)
+   } else if (strcmp(next_token, ".") == 0) {
continue;
-   else if (strcmp(next_token, "..") == 0) {
+   } else if (strcmp(next_token, "..") == 0) {
/*
 * Strip the last path component except when we have
 * single "/"
@@ -146,13 +145,12 @@ realpath1(const char *path, char *resolv
}
slen = readlink(resolved, symlink, sizeof(symlink));
if (slen <= 0 || slen >= sizeof(symlink)) {
-   if (slen < 0) {
-   /* keep errno from readlink(2) call */
-   } else if (slen == 0) {
+   if (slen < 0)
+   ; /* keep errno from readlink(2) call */
+   else if (slen == 0)
errno = ENOENT;
-   } else {
+   else
errno = ENAMETOOLONG;
-   }
return (NULL);
}
symlink[slen] = '\0';
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r319130 - stable/10/lib/libc/stdlib

2017-05-29 Thread Konstantin Belousov
Author: kib
Date: Mon May 29 12:59:24 2017
New Revision: 319130
URL: https://svnweb.freebsd.org/changeset/base/319130

Log:
  MFC r318299:
  Simplify cleanup on failure in realpath(3).

Modified:
  stable/10/lib/libc/stdlib/realpath.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/stdlib/realpath.c
==
--- stable/10/lib/libc/stdlib/realpath.cMon May 29 12:58:30 2017
(r319129)
+++ stable/10/lib/libc/stdlib/realpath.cMon May 29 12:59:24 2017
(r319130)
@@ -47,32 +47,16 @@ __FBSDID("$FreeBSD$");
  * components.  Returns (resolved) on success, or (NULL) on failure,
  * in which case the path which caused trouble is left in (resolved).
  */
-char *
-realpath(const char * __restrict path, char * __restrict resolved)
+static char *
+realpath1(const char *path, char *resolved)
 {
struct stat sb;
char *p, *q;
size_t left_len, resolved_len, next_token_len;
unsigned symlinks;
-   int m;
ssize_t slen;
char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
 
-   if (path == NULL) {
-   errno = EINVAL;
-   return (NULL);
-   }
-   if (path[0] == '\0') {
-   errno = ENOENT;
-   return (NULL);
-   }
-   if (resolved == NULL) {
-   resolved = malloc(PATH_MAX);
-   if (resolved == NULL)
-   return (NULL);
-   m = 1;
-   } else
-   m = 0;
symlinks = 0;
if (path[0] == '/') {
resolved[0] = '/';
@@ -83,20 +67,14 @@ realpath(const char * __restrict path, c
left_len = strlcpy(left, path + 1, sizeof(left));
} else {
if (getcwd(resolved, PATH_MAX) == NULL) {
-   if (m)
-   free(resolved);
-   else {
-   resolved[0] = '.';
-   resolved[1] = '\0';
-   }
+   resolved[0] = '.';
+   resolved[1] = '\0';
return (NULL);
}
resolved_len = strlen(resolved);
left_len = strlcpy(left, path, sizeof(left));
}
if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) {
-   if (m)
-   free(resolved);
errno = ENAMETOOLONG;
return (NULL);
}
@@ -125,8 +103,6 @@ realpath(const char * __restrict path, c
 
if (resolved[resolved_len - 1] != '/') {
if (resolved_len + 1 >= PATH_MAX) {
-   if (m)
-   free(resolved);
errno = ENAMETOOLONG;
return (NULL);
}
@@ -158,27 +134,18 @@ realpath(const char * __restrict path, c
 */
resolved_len = strlcat(resolved, next_token, PATH_MAX);
if (resolved_len >= PATH_MAX) {
-   if (m)
-   free(resolved);
errno = ENAMETOOLONG;
return (NULL);
}
-   if (lstat(resolved, ) != 0) {
-   if (m)
-   free(resolved);
+   if (lstat(resolved, ) != 0)
return (NULL);
-   }
if (S_ISLNK(sb.st_mode)) {
if (symlinks++ > MAXSYMLINKS) {
-   if (m)
-   free(resolved);
errno = ELOOP;
return (NULL);
}
slen = readlink(resolved, symlink, sizeof(symlink));
if (slen <= 0 || slen >= sizeof(symlink)) {
-   if (m)
-   free(resolved);
if (slen < 0) {
/* keep errno from readlink(2) call */
} else if (slen == 0) {
@@ -207,8 +174,6 @@ realpath(const char * __restrict path, c
if (p != NULL) {
if (symlink[slen - 1] != '/') {
if (slen + 1 >= sizeof(symlink)) {
-   if (m)
-   free(resolved);
errno = ENAMETOOLONG;
return (NULL);
}
@@ -218,16 +183,12 @@ realpath(const char * __restrict path, c
left_len = 

svn commit: r319129 - stable/10/lib/libc/stdlib

2017-05-29 Thread Konstantin Belousov
Author: kib
Date: Mon May 29 12:58:30 2017
New Revision: 319129
URL: https://svnweb.freebsd.org/changeset/base/319129

Log:
  MFC r318298:
  Fix several buffer overflows in realpath(3), and other minor issues.
  
  PR:   219154

Modified:
  stable/10/lib/libc/stdlib/realpath.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/stdlib/realpath.c
==
--- stable/10/lib/libc/stdlib/realpath.cMon May 29 12:55:26 2017
(r319128)
+++ stable/10/lib/libc/stdlib/realpath.cMon May 29 12:58:30 2017
(r319129)
@@ -51,10 +51,11 @@ char *
 realpath(const char * __restrict path, char * __restrict resolved)
 {
struct stat sb;
-   char *p, *q, *s;
-   size_t left_len, resolved_len;
+   char *p, *q;
+   size_t left_len, resolved_len, next_token_len;
unsigned symlinks;
-   int m, slen;
+   int m;
+   ssize_t slen;
char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
 
if (path == NULL) {
@@ -109,18 +110,19 @@ realpath(const char * __restrict path, c
 * and its length.
 */
p = strchr(left, '/');
-   s = p ? p : left + left_len;
-   if (s - left >= sizeof(next_token)) {
-   if (m)
-   free(resolved);
-   errno = ENAMETOOLONG;
-   return (NULL);
+
+   next_token_len = p ? p - left : left_len;
+   memcpy(next_token, left, next_token_len);
+   next_token[next_token_len] = '\0';
+
+   if (p != NULL) {
+   left_len -= next_token_len + 1;
+   memmove(left, p + 1, left_len + 1);
+   } else {
+   left[0] = '\0';
+   left_len = 0;
}
-   memcpy(next_token, left, s - left);
-   next_token[s - left] = '\0';
-   left_len -= s - left;
-   if (p != NULL)
-   memmove(left, s + 1, left_len + 1);
+
if (resolved[resolved_len - 1] != '/') {
if (resolved_len + 1 >= PATH_MAX) {
if (m)
@@ -173,19 +175,25 @@ realpath(const char * __restrict path, c
errno = ELOOP;
return (NULL);
}
-   slen = readlink(resolved, symlink, sizeof(symlink) - 1);
-   if (slen < 0) {
+   slen = readlink(resolved, symlink, sizeof(symlink));
+   if (slen <= 0 || slen >= sizeof(symlink)) {
if (m)
free(resolved);
+   if (slen < 0) {
+   /* keep errno from readlink(2) call */
+   } else if (slen == 0) {
+   errno = ENOENT;
+   } else {
+   errno = ENAMETOOLONG;
+   }
return (NULL);
}
symlink[slen] = '\0';
if (symlink[0] == '/') {
resolved[1] = 0;
resolved_len = 1;
-   } else if (resolved_len > 1) {
+   } else {
/* Strip the last path component. */
-   resolved[resolved_len - 1] = '\0';
q = strrchr(resolved, '/') + 1;
*q = '\0';
resolved_len = q - resolved;
@@ -209,7 +217,7 @@ realpath(const char * __restrict path, c
}
left_len = strlcat(symlink, left,
sizeof(symlink));
-   if (left_len >= sizeof(left)) {
+   if (left_len >= sizeof(symlink)) {
if (m)
free(resolved);
errno = ENAMETOOLONG;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r318529 - stable/10/sys/kern

2017-05-19 Thread Konstantin Belousov
Author: kib
Date: Fri May 19 10:16:51 2017
New Revision: 318529
URL: https://svnweb.freebsd.org/changeset/base/318529

Log:
  MFC r318243:
  Do not wake up sleeping thread in reschedule_signals() if the signal
  is blocked.  The spurious wakeup might result in spurious EINTR.
  
  PR:   219228

Modified:
  stable/10/sys/kern/kern_sig.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_sig.c
==
--- stable/10/sys/kern/kern_sig.c   Fri May 19 09:04:18 2017
(r318528)
+++ stable/10/sys/kern/kern_sig.c   Fri May 19 10:16:51 2017
(r318529)
@@ -2637,7 +2637,9 @@ reschedule_signals(struct proc *p, sigse
signotify(td);
if (!(flags & SIGPROCMASK_PS_LOCKED))
mtx_lock(>ps_mtx);
-   if (p->p_flag & P_TRACED || SIGISMEMBER(ps->ps_sigcatch, sig))
+   if (p->p_flag & P_TRACED ||
+   (SIGISMEMBER(ps->ps_sigcatch, sig) &&
+   !SIGISMEMBER(td->td_sigmask, sig)))
tdsigwakeup(td, sig, SIG_CATCH,
(SIGISMEMBER(ps->ps_sigintr, sig) ? EINTR :
 ERESTART));
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r318267 - stable/10/sys/ufs/ffs

2017-05-14 Thread Konstantin Belousov
Author: kib
Date: Sun May 14 12:00:00 2017
New Revision: 318267
URL: https://svnweb.freebsd.org/changeset/base/318267

Log:
  MFC r317908:
  Remove spl() calls from UFS code.

Modified:
  stable/10/sys/ufs/ffs/ffs_rawread.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/ufs/ffs/ffs_rawread.c
==
--- stable/10/sys/ufs/ffs/ffs_rawread.c Sun May 14 11:51:30 2017
(r318266)
+++ stable/10/sys/ufs/ffs/ffs_rawread.c Sun May 14 12:00:00 2017
(r318267)
@@ -274,7 +274,6 @@ ffs_rawread_main(struct vnode *vp,
struct buf *bp, *nbp, *tbp;
caddr_t sa, nsa, tsa;
u_int iolen;
-   int spl;
caddr_t udata;
long resid;
off_t offset;
@@ -339,10 +338,7 @@ ffs_rawread_main(struct vnode *vp,
}
}

-   spl = splbio();
bwait(bp, PRIBIO, "rawrd");
-   splx(spl);
-   
vunmapbuf(bp);

iolen = bp->b_bcount - bp->b_resid;
@@ -415,9 +411,7 @@ ffs_rawread_main(struct vnode *vp,
relpbuf(bp, );
}
if (nbp != NULL) {  /* Run down readahead buffer */
-   spl = splbio();
bwait(nbp, PRIBIO, "rawrd");
-   splx(spl);
vunmapbuf(nbp);
pbrelvp(nbp);
relpbuf(nbp, );
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317900 - stable/10/lib/libc/gen

2017-05-07 Thread Konstantin Belousov
Author: kib
Date: Sun May  7 08:02:28 2017
New Revision: 317900
URL: https://svnweb.freebsd.org/changeset/base/317900

Log:
  MFC r317611:
  Make semaphore names list mutex non-recursive.

Modified:
  stable/10/lib/libc/gen/sem_new.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/sem_new.c
==
--- stable/10/lib/libc/gen/sem_new.cSun May  7 08:01:29 2017
(r317899)
+++ stable/10/lib/libc/gen/sem_new.cSun May  7 08:02:28 2017
(r317900)
@@ -101,12 +101,8 @@ sem_child_postfork(void)
 static void
 sem_module_init(void)
 {
-   pthread_mutexattr_t ma;
 
-   _pthread_mutexattr_init();
-   _pthread_mutexattr_settype(,  PTHREAD_MUTEX_RECURSIVE);
-   _pthread_mutex_init(_llock, );
-   _pthread_mutexattr_destroy();
+   _pthread_mutex_init(_llock, NULL);
_pthread_atfork(sem_prefork, sem_postfork, sem_child_postfork);
 }
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317899 - stable/10/lib/libc/gen

2017-05-07 Thread Konstantin Belousov
Author: kib
Date: Sun May  7 08:01:29 2017
New Revision: 317899
URL: https://svnweb.freebsd.org/changeset/base/317899

Log:
  MFC r317610:
  Restructure normal (non-error) control flow in sem_close().

Modified:
  stable/10/lib/libc/gen/sem_new.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/sem_new.c
==
--- stable/10/lib/libc/gen/sem_new.cSun May  7 08:00:34 2017
(r317898)
+++ stable/10/lib/libc/gen/sem_new.cSun May  7 08:01:29 2017
(r317899)
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -259,6 +260,7 @@ int
 _sem_close(sem_t *sem)
 {
struct sem_nameinfo *ni;
+   bool last;
 
if (sem_check_validity(sem) != 0)
return (-1);
@@ -273,21 +275,17 @@ _sem_close(sem_t *sem)
_pthread_mutex_lock(_llock);
LIST_FOREACH(ni, _list, next) {
if (sem == ni->sem) {
-   if (--ni->open_count > 0) {
-   _pthread_mutex_unlock(_llock);
-   return (0);
+   last = --ni->open_count == 0;
+   if (last)
+   LIST_REMOVE(ni, next);
+   _pthread_mutex_unlock(_llock);
+   if (last) {
+   munmap(sem, sizeof(*sem));
+   free(ni);
}
-   break;
+   return (0);
}
}
-
-   if (ni != NULL) {
-   LIST_REMOVE(ni, next);
-   _pthread_mutex_unlock(_llock);
-   munmap(sem, sizeof(*sem));
-   free(ni);
-   return (0);
-   }
_pthread_mutex_unlock(_llock);
errno = EINVAL;
return (-1);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317898 - stable/10/lib/libc/gen

2017-05-07 Thread Konstantin Belousov
Author: kib
Date: Sun May  7 08:00:34 2017
New Revision: 317898
URL: https://svnweb.freebsd.org/changeset/base/317898

Log:
  MFC r317606:
  Style.

Modified:
  stable/10/lib/libc/gen/sem_new.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/sem_new.c
==
--- stable/10/lib/libc/gen/sem_new.cSun May  7 07:55:58 2017
(r317897)
+++ stable/10/lib/libc/gen/sem_new.cSun May  7 08:00:34 2017
(r317898)
@@ -74,24 +74,26 @@ struct sem_nameinfo {
 
 static pthread_once_t once = PTHREAD_ONCE_INIT;
 static pthread_mutex_t sem_llock;
-static LIST_HEAD(,sem_nameinfo) sem_list = LIST_HEAD_INITIALIZER(sem_list);
+static LIST_HEAD(, sem_nameinfo) sem_list = LIST_HEAD_INITIALIZER(sem_list);
 
 static void
-sem_prefork()
+sem_prefork(void)
 {

_pthread_mutex_lock(_llock);
 }
 
 static void
-sem_postfork()
+sem_postfork(void)
 {
+
_pthread_mutex_unlock(_llock);
 }
 
 static void
-sem_child_postfork()
+sem_child_postfork(void)
 {
+
_pthread_mutex_unlock(_llock);
 }
 
@@ -113,10 +115,8 @@ sem_check_validity(sem_t *sem)
 
if (sem->_magic == SEM_MAGIC)
return (0);
-   else {
-   errno = EINVAL;
-   return (-1);
-   }
+   errno = EINVAL;
+   return (-1);
 }
 
 int
@@ -140,13 +140,16 @@ sem_t *
 _sem_open(const char *name, int flags, ...)
 {
char path[PATH_MAX];
-
struct stat sb;
va_list ap;
-   struct sem_nameinfo *ni = NULL;
-   sem_t *sem = NULL;
-   int fd = -1, mode, len, errsave;
-   int value = 0;
+   struct sem_nameinfo *ni;
+   sem_t *sem, tmp;
+   int errsave, fd, len, mode, value;
+
+   ni = NULL;
+   sem = NULL;
+   fd = -1;
+   value = 0;
 
if (name[0] != '/') {
errno = EINVAL;
@@ -211,8 +214,6 @@ _sem_open(const char *name, int flags, .
goto error;
}
if (sb.st_size < sizeof(sem_t)) {
-   sem_t tmp;
-
tmp._magic = SEM_MAGIC;
tmp._kern._has_waiters = 0;
tmp._kern._count = value;
@@ -221,8 +222,8 @@ _sem_open(const char *name, int flags, .
goto error;
}
flock(fd, LOCK_UN);
-   sem = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ|PROT_WRITE,
-   MAP_SHARED|MAP_NOSYNC, fd, 0);
+   sem = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE,
+   MAP_SHARED | MAP_NOSYNC, fd, 0);
if (sem == MAP_FAILED) {
sem = NULL;
if (errno == ENOMEM)
@@ -276,12 +277,11 @@ _sem_close(sem_t *sem)
_pthread_mutex_unlock(_llock);
return (0);
}
-   else
-   break;
+   break;
}
}
 
-   if (ni) {
+   if (ni != NULL) {
LIST_REMOVE(ni, next);
_pthread_mutex_unlock(_llock);
munmap(sem, sizeof(*sem));
@@ -341,7 +341,8 @@ _sem_getvalue(sem_t * __restrict sem, in
 static __inline int
 usem_wake(struct _usem *sem)
 {
-   return _umtx_op(sem, UMTX_OP_SEM_WAKE, 0, NULL, NULL);
+
+   return (_umtx_op(sem, UMTX_OP_SEM_WAKE, 0, NULL, NULL));
 }
 
 static __inline int
@@ -422,7 +423,8 @@ _sem_timedwait(sem_t * __restrict sem,
 int
 _sem_wait(sem_t *sem)
 {
-   return _sem_timedwait(sem, NULL);
+
+   return (_sem_timedwait(sem, NULL));
 }
 
 /*
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317735 - stable/10/lib/libc/gen

2017-05-03 Thread Konstantin Belousov
Author: kib
Date: Wed May  3 09:54:37 2017
New Revision: 317735
URL: https://svnweb.freebsd.org/changeset/base/317735

Log:
  MFC r317436:
  getpagesize(3) cannot fail.

Modified:
  stable/10/lib/libc/gen/getpagesize.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/getpagesize.c
==
--- stable/10/lib/libc/gen/getpagesize.cWed May  3 09:52:11 2017
(r317734)
+++ stable/10/lib/libc/gen/getpagesize.cWed May  3 09:54:37 2017
(r317735)
@@ -69,7 +69,7 @@ getpagesize()
mib[1] = HW_PAGESIZE;
size = sizeof value;
if (sysctl(mib, nitems(mib), , , NULL, 0) == -1)
-   return (-1);
+   return (PAGE_SIZE);
 
return (value);
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317501 - stable/10/sys/dev/fb

2017-04-27 Thread Konstantin Belousov
Author: kib
Date: Thu Apr 27 12:15:15 2017
New Revision: 317501
URL: https://svnweb.freebsd.org/changeset/base/317501

Log:
  MFC r317196:
  Write-combine framebuffer writes through user-space mappings, if possible.

Modified:
  stable/10/sys/dev/fb/vesa.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/fb/vesa.c
==
--- stable/10/sys/dev/fb/vesa.c Thu Apr 27 12:12:33 2017(r317500)
+++ stable/10/sys/dev/fb/vesa.c Thu Apr 27 12:15:15 2017(r317501)
@@ -1636,6 +1636,9 @@ vesa_mmap(video_adapter_t *adp, vm_ooffs
if (offset > adp->va_window_size - PAGE_SIZE)
return (-1);
*paddr = adp->va_info.vi_buffer + offset;
+#ifdef VM_MEMATTR_WRITE_COMBINING
+   *memattr = VM_MEMATTR_WRITE_COMBINING;
+#endif
return (0);
}
return ((*prevvidsw->mmap)(adp, offset, paddr, prot, memattr));
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317408 - stable/10/sys/fs/nfsclient

2017-04-25 Thread Konstantin Belousov
Author: kib
Date: Tue Apr 25 13:17:34 2017
New Revision: 317408
URL: https://svnweb.freebsd.org/changeset/base/317408

Log:
  MFC r316698:
  Remove debugging printf.

Modified:
  stable/10/sys/fs/nfsclient/nfs_clvnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/nfsclient/nfs_clvnops.c
==
--- stable/10/sys/fs/nfsclient/nfs_clvnops.cTue Apr 25 13:07:06 2017
(r317407)
+++ stable/10/sys/fs/nfsclient/nfs_clvnops.cTue Apr 25 13:17:34 2017
(r317408)
@@ -2969,14 +2969,17 @@ done:
free(bvec, M_TEMP);
if (error == 0 && commit != 0 && waitfor == MNT_WAIT &&
(bo->bo_dirty.bv_cnt != 0 || bo->bo_numoutput != 0 ||
-np->n_directio_asyncwr != 0) && trycnt++ < 5) {
-   /* try, try again... */
-   passone = 1;
-   wcred = NULL;
-   bvec = NULL;
-   bvecsize = 0;
-printf("try%d\n", trycnt);
-   goto again;
+   np->n_directio_asyncwr != 0)) {
+   if (trycnt++ < 5) {
+   /* try, try again... */
+   passone = 1;
+   wcred = NULL;
+   bvec = NULL;
+   bvecsize = 0;
+   goto again;
+   }
+   vn_printf(vp, "ncl_flush failed");
+   error = called_from_renewthread != 0 ? EIO : EBUSY;
}
return (error);
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317250 - stable/10/sbin/fsck_ffs

2017-04-21 Thread Konstantin Belousov
Author: kib
Date: Fri Apr 21 10:16:34 2017
New Revision: 317250
URL: https://svnweb.freebsd.org/changeset/base/317250

Log:
  MFC r316852:
  In fsck_ffs pass1, prevent the inosused variable from wrapping.
  
  PR:   218592

Modified:
  stable/10/sbin/fsck_ffs/pass1.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/fsck_ffs/pass1.c
==
--- stable/10/sbin/fsck_ffs/pass1.c Fri Apr 21 10:13:07 2017
(r317249)
+++ stable/10/sbin/fsck_ffs/pass1.c Fri Apr 21 10:16:34 2017
(r317250)
@@ -133,9 +133,14 @@ pass1(void)
 */
if ((preen || inoopt) && usedsoftdep && !rebuildcg) {
cp = _inosused(cgp)[(inosused - 1) / CHAR_BIT];
-   for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
-   if (*cp == 0)
+   for ( ; inosused != 0; cp--) {
+   if (*cp == 0) {
+   if (inosused > CHAR_BIT)
+   inosused -= CHAR_BIT;
+   else
+   inosused = 0;
continue;
+   }
for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) {
if (*cp & i)
break;
@@ -143,8 +148,6 @@ pass1(void)
}
break;
}
-   if (inosused < 0)
-   inosused = 0;
}
/*
 * Allocate inoinfo structures for the allocated inodes.
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r317131 - stable/10/lib/libc/gen

2017-04-19 Thread Konstantin Belousov
Author: kib
Date: Wed Apr 19 10:57:57 2017
New Revision: 317131
URL: https://svnweb.freebsd.org/changeset/base/317131

Log:
  MFC r316739:
  Fix reporting of _SC_SEM_NSEMS_MAX and _SC_SEM_VALUE_MAX.

Modified:
  stable/10/lib/libc/gen/sysconf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/sysconf.c
==
--- stable/10/lib/libc/gen/sysconf.cWed Apr 19 10:54:08 2017
(r317130)
+++ stable/10/lib/libc/gen/sysconf.cWed Apr 19 10:57:57 2017
(r317131)
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include/* we just need the limits */
+#include 
 #include 
 #include 
 
@@ -298,13 +299,9 @@ do_NAME_MAX:
mib[1] = CTL_P1003_1B_RTSIG_MAX;
goto yesno;
case _SC_SEM_NSEMS_MAX:
-   mib[0] = CTL_P1003_1B;
-   mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX;
-   goto yesno;
+   return (-1);
case _SC_SEM_VALUE_MAX:
-   mib[0] = CTL_P1003_1B;
-   mib[1] = CTL_P1003_1B_SEM_VALUE_MAX;
-   goto yesno;
+   return (SEM_VALUE_MAX);
case _SC_SIGQUEUE_MAX:
mib[0] = CTL_P1003_1B;
mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r315972 - stable/10/sys/dev/cpuctl

2017-03-25 Thread Konstantin Belousov
Author: kib
Date: Sun Mar 26 01:10:59 2017
New Revision: 315972
URL: https://svnweb.freebsd.org/changeset/base/315972

Log:
  MFC r315588:
  Update the list of cpudev ioctls which require write access.

Modified:
  stable/10/sys/dev/cpuctl/cpuctl.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/cpuctl/cpuctl.c
==
--- stable/10/sys/dev/cpuctl/cpuctl.c   Sun Mar 26 00:59:15 2017
(r315971)
+++ stable/10/sys/dev/cpuctl/cpuctl.c   Sun Mar 26 01:10:59 2017
(r315972)
@@ -155,8 +155,9 @@ cpuctl_ioctl(struct cdev *dev, u_long cm
return (ENXIO);
}
/* Require write flag for "write" requests. */
-   if ((cmd == CPUCTL_WRMSR || cmd == CPUCTL_UPDATE) &&
-   ((flags & FWRITE) == 0))
+   if ((cmd == CPUCTL_MSRCBIT || cmd == CPUCTL_MSRSBIT ||
+   cmd == CPUCTL_UPDATE || cmd == CPUCTL_WRMSR) &&
+   (flags & FWRITE) == 0)
return (EPERM);
switch (cmd) {
case CPUCTL_RDMSR:
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r315894 - stable/10/sys/kern

2017-03-24 Thread Konstantin Belousov
Author: kib
Date: Fri Mar 24 07:22:32 2017
New Revision: 315894
URL: https://svnweb.freebsd.org/changeset/base/315894

Log:
  MFC r315453:
  When clearing altsigstack settings on exec, do it to the right thread.

Modified:
  stable/10/sys/kern/kern_sig.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_sig.c
==
--- stable/10/sys/kern/kern_sig.c   Fri Mar 24 07:14:46 2017
(r315893)
+++ stable/10/sys/kern/kern_sig.c   Fri Mar 24 07:22:32 2017
(r315894)
@@ -964,7 +964,6 @@ execsigs(struct proc *p)
 * and are now ignored by default).
 */
PROC_LOCK_ASSERT(p, MA_OWNED);
-   td = FIRST_THREAD_IN_PROC(p);
ps = p->p_sigacts;
mtx_lock(>ps_mtx);
while (SIGNOTEMPTY(ps->ps_sigcatch)) {
@@ -977,6 +976,8 @@ execsigs(struct proc *p)
 * Reset stack state to the user stack.
 * Clear set of signals caught on the signal stack.
 */
+   td = curthread;
+   MPASS(td->td_proc == p);
td->td_sigstk.ss_flags = SS_DISABLE;
td->td_sigstk.ss_size = 0;
td->td_sigstk.ss_sp = 0;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r315562 - in stable/10/sys: kern sys

2017-03-19 Thread Konstantin Belousov
Author: kib
Date: Sun Mar 19 15:56:06 2017
New Revision: 315562
URL: https://svnweb.freebsd.org/changeset/base/315562

Log:
  MFC r315155:
  Ktracing kevent(2) calls with unusual arguments might leads to an
  overly large allocation requests.
  
  PR:   217435

Modified:
  stable/10/sys/kern/kern_event.c
  stable/10/sys/kern/kern_ktrace.c
  stable/10/sys/sys/ktrace.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_event.c
==
--- stable/10/sys/kern/kern_event.c Sun Mar 19 15:53:17 2017
(r315561)
+++ stable/10/sys/kern/kern_event.c Sun Mar 19 15:56:06 2017
(r315562)
@@ -825,6 +825,15 @@ done2:
return (error);
 }
 
+static size_t
+kev_iovlen(int n, u_int kgio)
+{
+
+   if (n < 0 || n >= kgio / sizeof(struct kevent))
+   return (kgio);
+   return (n * sizeof(struct kevent));
+}
+
 #ifndef _SYS_SYSPROTO_H_
 struct kevent_args {
int fd;
@@ -848,6 +857,7 @@ sys_kevent(struct thread *td, struct kev
struct iovec ktriov;
struct uio *ktruioin = NULL;
struct uio *ktruioout = NULL;
+   u_int kgio;
 #endif
 
if (uap->timeout != NULL) {
@@ -860,13 +870,15 @@ sys_kevent(struct thread *td, struct kev
 
 #ifdef KTRACE
if (KTRPOINT(td, KTR_GENIO)) {
+   kgio = ktr_geniosize;
ktriov.iov_base = uap->changelist;
-   ktriov.iov_len = uap->nchanges * sizeof(struct kevent);
+   ktriov.iov_len = kev_iovlen(uap->nchanges, kgio);
ktruio = (struct uio){ .uio_iov = , .uio_iovcnt = 1,
.uio_segflg = UIO_USERSPACE, .uio_rw = UIO_READ,
.uio_td = td };
ktruioin = cloneuio();
ktriov.iov_base = uap->eventlist;
+   ktriov.iov_len = kev_iovlen(uap->nevents, kgio);
ktriov.iov_len = uap->nevents * sizeof(struct kevent);
ktruioout = cloneuio();
}
@@ -877,9 +889,9 @@ sys_kevent(struct thread *td, struct kev
 
 #ifdef KTRACE
if (ktruioin != NULL) {
-   ktruioin->uio_resid = uap->nchanges * sizeof(struct kevent);
+   ktruioin->uio_resid = kev_iovlen(uap->nchanges, kgio);
ktrgenio(uap->fd, UIO_WRITE, ktruioin, 0);
-   ktruioout->uio_resid = td->td_retval[0] * sizeof(struct kevent);
+   ktruioout->uio_resid = kev_iovlen(td->td_retval[0], kgio);
ktrgenio(uap->fd, UIO_READ, ktruioout, error);
}
 #endif

Modified: stable/10/sys/kern/kern_ktrace.c
==
--- stable/10/sys/kern/kern_ktrace.cSun Mar 19 15:53:17 2017
(r315561)
+++ stable/10/sys/kern/kern_ktrace.cSun Mar 19 15:56:06 2017
(r315562)
@@ -132,7 +132,7 @@ static SYSCTL_NODE(_kern, OID_AUTO, ktra
 static u_int ktr_requestpool = KTRACE_REQUEST_POOL;
 TUNABLE_INT("kern.ktrace.request_pool", _requestpool);
 
-static u_int ktr_geniosize = PAGE_SIZE;
+u_int ktr_geniosize = PAGE_SIZE;
 TUNABLE_INT("kern.ktrace.genio_size", _geniosize);
 SYSCTL_UINT(_kern_ktrace, OID_AUTO, genio_size, CTLFLAG_RW, _geniosize,
 0, "Maximum size of genio event payload");

Modified: stable/10/sys/sys/ktrace.h
==
--- stable/10/sys/sys/ktrace.h  Sun Mar 19 15:53:17 2017(r315561)
+++ stable/10/sys/sys/ktrace.h  Sun Mar 19 15:56:06 2017(r315562)
@@ -276,7 +276,7 @@ voidktrcapfail(enum ktr_cap_fail_type, 
ktrstruct("sockaddr", (s), ((struct sockaddr *)(s))->sa_len)
 #define ktrstat(s) \
ktrstruct("stat", (s), sizeof(struct stat))
-
+extern u_int ktr_geniosize;
 #else
 
 #include 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r315145 - stable/10/sys/sys

2017-03-12 Thread Konstantin Belousov
Author: kib
Date: Sun Mar 12 12:12:59 2017
New Revision: 315145
URL: https://svnweb.freebsd.org/changeset/base/315145

Log:
  MFC r314960:
  Fix typo in comment.

Modified:
  stable/10/sys/sys/signalvar.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/sys/signalvar.h
==
--- stable/10/sys/sys/signalvar.h   Sun Mar 12 12:11:11 2017
(r315144)
+++ stable/10/sys/sys/signalvar.h   Sun Mar 12 12:12:59 2017
(r315145)
@@ -233,7 +233,7 @@ typedef struct ksiginfo {
 #defineKSI_TRAP0x01/* Generated by trap. */
 #defineKSI_EXT 0x02/* Externally managed ksi. */
 #defineKSI_INS 0x04/* Directly insert ksi, not the copy */
-#defineKSI_SIGQ0x08/* Generated by sigqueue, might ret 
EGAIN. */
+#defineKSI_SIGQ0x08/* Generated by sigqueue, might ret 
EAGAIN. */
 #defineKSI_HEAD0x10/* Insert into head, not tail. */
 #defineKSI_COPYMASK(KSI_TRAP|KSI_SIGQ)
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314845 - in stable/10/sys: amd64/amd64 i386/i386

2017-03-07 Thread Konstantin Belousov
Author: kib
Date: Tue Mar  7 12:24:02 2017
New Revision: 314845
URL: https://svnweb.freebsd.org/changeset/base/314845

Log:
  MFC r314429:
  Initialize pcb_save for thread0.

Modified:
  stable/10/sys/amd64/amd64/machdep.c
  stable/10/sys/i386/i386/machdep.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/machdep.c
==
--- stable/10/sys/amd64/amd64/machdep.c Tue Mar  7 12:16:47 2017
(r314844)
+++ stable/10/sys/amd64/amd64/machdep.c Tue Mar  7 12:24:02 2017
(r314845)
@@ -2023,6 +2023,7 @@ hammer_time(u_int64_t modulep, u_int64_t
 * area.
 */
thread0.td_pcb = get_pcb_td();
+   thread0.td_pcb->pcb_save = get_pcb_user_save_td();
bzero(get_pcb_user_save_td(), cpu_max_ext_state_size);
if (use_xsave) {
xhdr = (struct xstate_hdr *)(get_pcb_user_save_td() +

Modified: stable/10/sys/i386/i386/machdep.c
==
--- stable/10/sys/i386/i386/machdep.c   Tue Mar  7 12:16:47 2017
(r314844)
+++ stable/10/sys/i386/i386/machdep.c   Tue Mar  7 12:24:02 2017
(r314845)
@@ -3420,6 +3420,7 @@ init386(int first)
 * area.
 */
thread0.td_pcb = get_pcb_td();
+   thread0.td_pcb->pcb_save = get_pcb_user_save_td();
bzero(get_pcb_user_save_td(), cpu_max_ext_state_size);
 #ifdef CPU_ENABLE_SSE
if (use_xsave) {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314689 - stable/10/sys/kern

2017-03-04 Thread Konstantin Belousov
Author: kib
Date: Sun Mar  5 00:37:23 2017
New Revision: 314689
URL: https://svnweb.freebsd.org/changeset/base/314689

Log:
  MFC r314562:
  Style.

Modified:
  stable/10/sys/kern/imgact_elf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/imgact_elf.c
==
--- stable/10/sys/kern/imgact_elf.c Sun Mar  5 00:34:12 2017
(r314688)
+++ stable/10/sys/kern/imgact_elf.c Sun Mar  5 00:37:23 2017
(r314689)
@@ -399,9 +399,8 @@ __elfN(map_partial)(vm_map_t map, vm_obj
error = copyout((caddr_t)sf_buf_kva(sf) + off, (caddr_t)start,
end - start);
vm_imgact_unmap_page(sf);
-   if (error) {
+   if (error != 0)
return (KERN_FAILURE);
-   }
}
 
return (KERN_SUCCESS);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314590 - stable/10/sys/vm

2017-03-03 Thread Konstantin Belousov
Author: kib
Date: Fri Mar  3 10:17:16 2017
New Revision: 314590
URL: https://svnweb.freebsd.org/changeset/base/314590

Log:
  MFC r314195:
  Properly handle possible underflow in vm_fault_prefault().

Modified:
  stable/10/sys/vm/vm_fault.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_fault.c
==
--- stable/10/sys/vm/vm_fault.c Fri Mar  3 10:02:56 2017(r314589)
+++ stable/10/sys/vm/vm_fault.c Fri Mar  3 10:17:16 2017(r314590)
@@ -1140,11 +1140,12 @@ vm_fault_prefault(const struct faultstat
}
entry = fs->entry;
 
-   starta = addra - backward * PAGE_SIZE;
-   if (starta < entry->start) {
+   if (addra < backward * PAGE_SIZE) {
starta = entry->start;
-   } else if (starta > addra) {
-   starta = 0;
+   } else {
+   starta = addra - backward * PAGE_SIZE;
+   if (starta < entry->start)
+   starta = entry->start;
}
 
/*
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314392 - stable/10/sys/sys

2017-02-28 Thread Konstantin Belousov
Author: kib
Date: Tue Feb 28 15:03:34 2017
New Revision: 314392
URL: https://svnweb.freebsd.org/changeset/base/314392

Log:
  MFC r313734:
  Add RLIM_SAVED_MAX and RLIM_SAVED_CUR symbols.

Modified:
  stable/10/sys/sys/resource.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/sys/resource.h
==
--- stable/10/sys/sys/resource.hTue Feb 28 14:48:52 2017
(r314391)
+++ stable/10/sys/sys/resource.hTue Feb 28 15:03:34 2017
(r314392)
@@ -107,8 +107,8 @@ struct __wrusage {
 #defineRLIM_NLIMITS13  /* number of resource limits */
 
 #defineRLIM_INFINITY   ((rlim_t)(((uint64_t)1 << 63) - 1))
-/* XXX Missing: RLIM_SAVED_MAX, RLIM_SAVED_CUR */
-
+#defineRLIM_SAVED_MAX  RLIM_INFINITY
+#defineRLIM_SAVED_CUR  RLIM_INFINITY
 
 /*
  * Resource limit string identifiers
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314202 - stable/10/sys/kern

2017-02-24 Thread Konstantin Belousov
Author: kib
Date: Fri Feb 24 11:34:00 2017
New Revision: 314202
URL: https://svnweb.freebsd.org/changeset/base/314202

Log:
  MFC r313496:
  Increase a chance of devfs_close() calling d_close cdevsw method.

Modified:
  stable/10/sys/kern/vfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_vnops.c
==
--- stable/10/sys/kern/vfs_vnops.c  Fri Feb 24 11:30:28 2017
(r314201)
+++ stable/10/sys/kern/vfs_vnops.c  Fri Feb 24 11:34:00 2017
(r314202)
@@ -412,12 +412,9 @@ vn_writechk(vp)
 /*
  * Vnode close call
  */
-int
-vn_close(vp, flags, file_cred, td)
-   register struct vnode *vp;
-   int flags;
-   struct ucred *file_cred;
-   struct thread *td;
+static int
+vn_close1(struct vnode *vp, int flags, struct ucred *file_cred,
+struct thread *td, bool keep_ref)
 {
struct mount *mp;
int error, lock_flags;
@@ -438,11 +435,22 @@ vn_close(vp, flags, file_cred, td)
__func__, vp, vp->v_writecount);
}
error = VOP_CLOSE(vp, flags, file_cred, td);
-   vput(vp);
+   if (keep_ref)
+   VOP_UNLOCK(vp, 0);
+   else
+   vput(vp);
vn_finished_write(mp);
return (error);
 }
 
+int
+vn_close(struct vnode *vp, int flags, struct ucred *file_cred,
+struct thread *td)
+{
+
+   return (vn_close1(vp, flags, file_cred, td, false));
+}
+
 /*
  * Heuristic to detect sequential operation.
  */
@@ -1624,16 +1632,15 @@ vn_closefile(fp, td)
struct vnode *vp;
struct flock lf;
int error;
+   bool ref;
 
vp = fp->f_vnode;
fp->f_ops = 
+   ref= (fp->f_flag & FHASLOCK) != 0 && fp->f_type == DTYPE_VNODE;
 
-   if (fp->f_type == DTYPE_VNODE && fp->f_flag & FHASLOCK)
-   vref(vp);
-
-   error = vn_close(vp, fp->f_flag, fp->f_cred, td);
+   error = vn_close1(vp, fp->f_flag, fp->f_cred, td, ref);
 
-   if (fp->f_type == DTYPE_VNODE && fp->f_flag & FHASLOCK) {
+   if (__predict_false(ref)) {
lf.l_whence = SEEK_SET;
lf.l_start = 0;
lf.l_len = 0;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314201 - stable/10/sys/fs/nfsclient

2017-02-24 Thread Konstantin Belousov
Author: kib
Date: Fri Feb 24 11:30:28 2017
New Revision: 314201
URL: https://svnweb.freebsd.org/changeset/base/314201

Log:
  MFC r313800:
  Do not access memory past the buffer end.
  Do not accept and silently truncate too long hostname.

Modified:
  stable/10/sys/fs/nfsclient/nfs_clvfsops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/nfsclient/nfs_clvfsops.c
==
--- stable/10/sys/fs/nfsclient/nfs_clvfsops.c   Fri Feb 24 11:25:32 2017
(r314200)
+++ stable/10/sys/fs/nfsclient/nfs_clvfsops.c   Fri Feb 24 11:30:28 2017
(r314201)
@@ -1149,8 +1149,13 @@ nfs_mount(struct mount *mp)
error = EINVAL;
goto out;
}
-   bcopy(args.hostname, hst, MNAMELEN);
-   hst[MNAMELEN - 1] = '\0';
+   if (len >= MNAMELEN) {
+   vfs_mount_error(mp, "Hostname too long");
+   error = EINVAL;
+   goto out;
+   }
+   bcopy(args.hostname, hst, len);
+   hst[len] = '\0';
}
 
if (vfs_getopt(mp->mnt_optnew, "principal", (void **), NULL) == 0)
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r314199 - stable/10/libexec/rtld-elf

2017-02-24 Thread Konstantin Belousov
Author: kib
Date: Fri Feb 24 11:07:49 2017
New Revision: 314199
URL: https://svnweb.freebsd.org/changeset/base/314199

Log:
  MFC r313494:
  Handle protected symbols in rtld.

Modified:
  stable/10/libexec/rtld-elf/rtld.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld.c
==
--- stable/10/libexec/rtld-elf/rtld.c   Fri Feb 24 10:20:13 2017
(r314198)
+++ stable/10/libexec/rtld-elf/rtld.c   Fri Feb 24 11:07:49 2017
(r314199)
@@ -3833,15 +3833,19 @@ symlook_default(SymLook *req, const Obj_
 donelist_init();
 symlook_init_from_req(, req);
 
-/* Look first in the referencing object if linked symbolically. */
-if (refobj->symbolic && !donelist_check(, refobj)) {
-   res = symlook_obj(, refobj);
-   if (res == 0) {
-   req->sym_out = req1.sym_out;
-   req->defobj_out = req1.defobj_out;
-   assert(req->defobj_out != NULL);
-   }
+/*
+ * Look first in the referencing object if linked symbolically,
+ * and similarly handle protected symbols.
+ */
+res = symlook_obj(, refobj);
+if (res == 0 && (refobj->symbolic ||
+  ELF_ST_VISIBILITY(req1.sym_out->st_other) == STV_PROTECTED)) {
+   req->sym_out = req1.sym_out;
+   req->defobj_out = req1.defobj_out;
+   assert(req->defobj_out != NULL);
 }
+if (refobj->symbolic || req->defobj_out != NULL)
+   donelist_check(, refobj);
 
 symlook_global(req, );
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313932 - stable/10/sys/fs/devfs

2017-02-18 Thread Konstantin Belousov
Author: kib
Date: Sun Feb 19 03:17:11 2017
New Revision: 313932
URL: https://svnweb.freebsd.org/changeset/base/313932

Log:
  MFC r313797:
  Minor style fixes.

Modified:
  stable/10/sys/fs/devfs/devfs_devs.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/devfs/devfs_devs.c
==
--- stable/10/sys/fs/devfs/devfs_devs.c Sun Feb 19 03:11:14 2017
(r313931)
+++ stable/10/sys/fs/devfs/devfs_devs.c Sun Feb 19 03:17:11 2017
(r313932)
@@ -208,7 +208,7 @@ devfs_newdirent(char *name, int namelen)
struct dirent d;
 
d.d_namlen = namelen;
-   i = sizeof (*de) + GENERIC_DIRSIZ(); 
+   i = sizeof(*de) + GENERIC_DIRSIZ();
de = malloc(i, M_DEVFS3, M_WAITOK | M_ZERO);
de->de_dirent = (struct dirent *)(de + 1);
de->de_dirent->d_namlen = namelen;
@@ -246,7 +246,8 @@ devfs_parent_dirent(struct devfs_dirent 
 }
 
 struct devfs_dirent *
-devfs_vmkdir(struct devfs_mount *dmp, char *name, int namelen, struct 
devfs_dirent *dotdot, u_int inode)
+devfs_vmkdir(struct devfs_mount *dmp, char *name, int namelen,
+struct devfs_dirent *dotdot, u_int inode)
 {
struct devfs_dirent *dd;
struct devfs_dirent *de;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313844 - stable/10/sys/sys

2017-02-16 Thread Konstantin Belousov
Author: kib
Date: Fri Feb 17 00:38:32 2017
New Revision: 313844
URL: https://svnweb.freebsd.org/changeset/base/313844

Log:
  MFC r313715:
  Order alphabetically.

Modified:
  stable/10/sys/sys/syscallsubr.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/sys/syscallsubr.h
==
--- stable/10/sys/sys/syscallsubr.h Fri Feb 17 00:36:12 2017
(r313843)
+++ stable/10/sys/sys/syscallsubr.h Fri Feb 17 00:38:32 2017
(r313844)
@@ -158,8 +158,8 @@ int kern_mknod(struct thread *td, char *
 intkern_mknodat(struct thread *td, int fd, char *path,
enum uio_seg pathseg, int mode, int dev);
 intkern_msgctl(struct thread *, int, int, struct msqid_ds *);
-intkern_msgsnd(struct thread *, int, const void *, size_t, int, long);
 intkern_msgrcv(struct thread *, int, void *, size_t, long, int, long *);
+intkern_msgsnd(struct thread *, int, const void *, size_t, int, long);
 int kern_nanosleep(struct thread *td, struct timespec *rqt,
struct timespec *rmt);
 intkern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313794 - stable/10/sys/compat/freebsd32

2017-02-15 Thread Konstantin Belousov
Author: kib
Date: Thu Feb 16 06:00:57 2017
New Revision: 313794
URL: https://svnweb.freebsd.org/changeset/base/313794

Log:
  MFC r313692:
  Style: wrap long line.

Modified:
  stable/10/sys/compat/freebsd32/freebsd32_misc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/compat/freebsd32/freebsd32_misc.c
==
--- stable/10/sys/compat/freebsd32/freebsd32_misc.c Thu Feb 16 05:57:58 
2017(r313793)
+++ stable/10/sys/compat/freebsd32/freebsd32_misc.c Thu Feb 16 06:00:57 
2017(r313794)
@@ -598,7 +598,8 @@ freebsd32_mmap(struct thread *td, struct
 
 #ifdef COMPAT_FREEBSD6
 int
-freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args 
*uap)
+freebsd6_freebsd32_mmap(struct thread *td,
+struct freebsd6_freebsd32_mmap_args *uap)
 {
struct freebsd32_mmap_args ap;
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313548 - stable/10/sys/i386/i386

2017-02-10 Thread Konstantin Belousov
Author: kib
Date: Fri Feb 10 14:38:28 2017
New Revision: 313548
URL: https://svnweb.freebsd.org/changeset/base/313548

Log:
  MFC r290101 (by hselasky):
  Build fix for i386/XBOX and pc98/GENERIC.
  
  Reported by:  ngie

Modified:
  stable/10/sys/i386/i386/pmap.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/i386/i386/pmap.c
==
--- stable/10/sys/i386/i386/pmap.c  Fri Feb 10 13:28:30 2017
(r313547)
+++ stable/10/sys/i386/i386/pmap.c  Fri Feb 10 14:38:28 2017
(r313548)
@@ -1257,8 +1257,10 @@ pmap_invalidate_cache_range(vm_offset_t 
sfence();
} else if ((cpu_feature & CPUID_CLFSH) != 0 &&
eva - sva < PMAP_CLFLUSH_THRESHOLD) {
+#ifdef DEV_APIC
if (pmap_kextract(sva) == lapic_paddr)
return;
+#endif
/*
 * Writes are ordered by CLFLUSH on Intel CPUs.
 */
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313464 - in stable/10/sys/i386: i386 isa

2017-02-08 Thread Konstantin Belousov
Author: kib
Date: Thu Feb  9 04:45:18 2017
New Revision: 313464
URL: https://svnweb.freebsd.org/changeset/base/313464

Log:
  MFC r313109:
  Use ANSI definitions for some i386 functions.

Modified:
  stable/10/sys/i386/i386/machdep.c
  stable/10/sys/i386/i386/vm_machdep.c
  stable/10/sys/i386/isa/npx.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/i386/i386/machdep.c
==
--- stable/10/sys/i386/i386/machdep.c   Thu Feb  9 04:42:21 2017
(r313463)
+++ stable/10/sys/i386/i386/machdep.c   Thu Feb  9 04:45:18 2017
(r313464)
@@ -3157,8 +3157,7 @@ init386(first)
 
 #else
 register_t
-init386(first)
-   int first;
+init386(int first)
 {
struct gate_descriptor *gdp;
int gsel_tss, metadata_missing, x, pa;

Modified: stable/10/sys/i386/i386/vm_machdep.c
==
--- stable/10/sys/i386/i386/vm_machdep.cThu Feb  9 04:42:21 2017
(r313463)
+++ stable/10/sys/i386/i386/vm_machdep.cThu Feb  9 04:45:18 2017
(r313464)
@@ -209,11 +209,7 @@ alloc_fpusave(int flags)
  * ready to run and return to user mode.
  */
 void
-cpu_fork(td1, p2, td2, flags)
-   register struct thread *td1;
-   register struct proc *p2;
-   struct thread *td2;
-   int flags;
+cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags)
 {
register struct proc *p1;
struct pcb *pcb2;

Modified: stable/10/sys/i386/isa/npx.c
==
--- stable/10/sys/i386/isa/npx.cThu Feb  9 04:42:21 2017
(r313463)
+++ stable/10/sys/i386/isa/npx.cThu Feb  9 04:45:18 2017
(r313464)
@@ -559,8 +559,7 @@ SYSINIT(npxinitstate, SI_SUB_DRIVERS, SI
  * Free coprocessor (if we have it).
  */
 void
-npxexit(td)
-   struct thread *td;
+npxexit(struct thread *td)
 {
 
critical_enter();
@@ -590,7 +589,7 @@ npxexit(td)
 }
 
 int
-npxformat()
+npxformat(void)
 {
 
if (!hw_float)
@@ -970,7 +969,7 @@ npxresume(union savefpu *addr)
 }
 
 void
-npxdrop()
+npxdrop(void)
 {
struct thread *td;
 
@@ -1203,8 +1202,7 @@ fpu_clean_state(void)
 #endif /* CPU_ENABLE_SSE */
 
 static void
-fpurstor(addr)
-   union savefpu *addr;
+fpurstor(union savefpu *addr)
 {
 
 #ifdef CPU_ENABLE_SSE
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313384 - stable/10/sys/vm

2017-02-07 Thread Konstantin Belousov
Author: kib
Date: Tue Feb  7 08:33:46 2017
New Revision: 313384
URL: https://svnweb.freebsd.org/changeset/base/313384

Log:
  MFC r313249:
  Style, use tab after #define.

Modified:
  stable/10/sys/vm/vm_object.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/vm/vm_object.h
==
--- stable/10/sys/vm/vm_object.hTue Feb  7 08:31:07 2017
(r313383)
+++ stable/10/sys/vm/vm_object.hTue Feb  7 08:33:46 2017
(r313384)
@@ -192,8 +192,8 @@ struct vm_object {
 #defineOBJ_DISCONNECTWNT 0x4000/* disconnect from vnode wanted 
*/
 #defineOBJ_TMPFS   0x8000  /* has tmpfs vnode allocated */
 
-#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
-#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
+#defineIDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
+#defineOFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> 
PAGE_SHIFT))
 
 #ifdef _KERNEL
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313256 - in stable/10/sys: amd64/amd64 i386/i386

2017-02-04 Thread Konstantin Belousov
Author: kib
Date: Sun Feb  5 00:42:15 2017
New Revision: 313256
URL: https://svnweb.freebsd.org/changeset/base/313256

Log:
  MFC r312954:
  Do not leave stale 4K TLB entries on pde (superpage) removal or
  protection change.

Modified:
  stable/10/sys/amd64/amd64/pmap.c
  stable/10/sys/i386/i386/pmap.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/pmap.c
==
--- stable/10/sys/amd64/amd64/pmap.cSun Feb  5 00:39:44 2017
(r313255)
+++ stable/10/sys/amd64/amd64/pmap.cSun Feb  5 00:42:15 2017
(r313256)
@@ -912,7 +912,12 @@ pmap_bootstrap(vm_paddr_t *firstaddr)
 
virtual_avail = va;
 
-   /* Initialize the PAT MSR. */
+   /*
+* Initialize the PAT MSR.
+* pmap_init_pat() clears and sets CR4_PGE, which, as a
+* side-effect, invalidates stale PG_G TLB entries that might
+* have been created in our pre-boot environment.
+*/
pmap_init_pat();
 
/* Initialize TLB Context Id. */
@@ -3372,6 +3377,7 @@ pmap_demote_pde_locked(pmap_t pmap, pd_e
vm_paddr_t mptepa;
vm_page_t mpte;
struct spglist free;
+   vm_offset_t sva;
int PG_PTE_CACHE;
 
PG_G = pmap_global_bit(pmap);
@@ -3410,9 +3416,9 @@ pmap_demote_pde_locked(pmap_t pmap, pd_e
DMAP_MAX_ADDRESS ? VM_ALLOC_INTERRUPT : VM_ALLOC_NORMAL) |
VM_ALLOC_NOOBJ | VM_ALLOC_WIRED)) == NULL) {
SLIST_INIT();
-   pmap_remove_pde(pmap, pde, trunc_2mpage(va), ,
-   lockp);
-   pmap_invalidate_page(pmap, trunc_2mpage(va));
+   sva = trunc_2mpage(va);
+   pmap_remove_pde(pmap, pde, sva, , lockp);
+   pmap_invalidate_range(pmap, sva, sva + NBPDR - 1);
pmap_free_zero_pages();
CTR2(KTR_PMAP, "pmap_demote_pde: failure for va %#lx"
" in pmap %p", va, pmap);
@@ -3555,11 +3561,23 @@ pmap_remove_pde(pmap_t pmap, pd_entry_t 
pmap->pm_stats.wired_count -= NBPDR / PAGE_SIZE;
 
/*
-* Machines that don't support invlpg, also don't support
-* PG_G.
-*/
-   if (oldpde & PG_G)
-   pmap_invalidate_page(kernel_pmap, sva);
+* When workaround_erratum383 is false, a promotion to a 2M
+* page mapping does not invalidate the 512 4K page mappings
+* from the TLB.  Consequently, at this point, the TLB may
+* hold both 4K and 2M page mappings.  Therefore, the entire
+* range of addresses must be invalidated here.  In contrast,
+* when workaround_erratum383 is true, a promotion does
+* invalidate the 512 4K page mappings, and so a single INVLPG
+* suffices to invalidate the 2M page mapping.
+*/
+   if ((oldpde & PG_G) != 0) {
+   if (workaround_erratum383)
+   pmap_invalidate_page(kernel_pmap, sva);
+   else
+   pmap_invalidate_range(kernel_pmap, sva,
+   sva + NBPDR - 1);
+   }
+
pmap_resident_count_dec(pmap, NBPDR / PAGE_SIZE);
if (oldpde & PG_MANAGED) {
CHANGE_PV_LIST_LOCK_TO_PHYS(lockp, oldpde & PG_PS_FRAME);
@@ -3914,9 +3932,14 @@ retry:
if (newpde != oldpde) {
if (!atomic_cmpset_long(pde, oldpde, newpde))
goto retry;
-   if (oldpde & PG_G)
-   pmap_invalidate_page(pmap, sva);
-   else
+   if (oldpde & PG_G) {
+   /* See pmap_remove_pde() for explanation. */
+   if (workaround_erratum383)
+   pmap_invalidate_page(kernel_pmap, sva);
+   else
+   pmap_invalidate_range(kernel_pmap, sva,
+   sva + NBPDR - 1);
+   } else
anychanged = TRUE;
}
return (anychanged);

Modified: stable/10/sys/i386/i386/pmap.c
==
--- stable/10/sys/i386/i386/pmap.c  Sun Feb  5 00:39:44 2017
(r313255)
+++ stable/10/sys/i386/i386/pmap.c  Sun Feb  5 00:42:15 2017
(r313256)
@@ -517,7 +517,14 @@ pmap_bootstrap(vm_paddr_t firstaddr)
for (i = 1; i < NKPT; i++)
PTD[i] = 0;
 
-   /* Initialize the PAT MSR if present. */
+   /*
+* Initialize the PAT MSR if present.
+* pmap_init_pat() clears and sets CR4_PGE, which, as a
+* side-effect, invalidates stale PG_G TLB entries that might
+* have been created in our pre-boot environment.  We assume
+* that PAT support implies PGE and in reverse, PGE presence
+* 

svn commit: r313150 - in stable/10/sys: amd64/amd64 amd64/include i386/i386 i386/include

2017-02-03 Thread Konstantin Belousov
Author: kib
Date: Fri Feb  3 12:20:44 2017
New Revision: 313150
URL: https://svnweb.freebsd.org/changeset/base/313150

Log:
  MFC r289894:
  CLFLUSH does not need barriers, the instruction is ordered WRT other writes.
  Use CLFLUSHOPT when available.
  
  MFC r312555:
  Use SFENCE for ordering CLFLUSHOPT.

Modified:
  stable/10/sys/amd64/amd64/initcpu.c
  stable/10/sys/amd64/amd64/pmap.c
  stable/10/sys/amd64/include/cpufunc.h
  stable/10/sys/i386/i386/initcpu.c
  stable/10/sys/i386/i386/pmap.c
  stable/10/sys/i386/include/cpufunc.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/initcpu.c
==
--- stable/10/sys/amd64/amd64/initcpu.c Fri Feb  3 12:13:55 2017
(r313149)
+++ stable/10/sys/amd64/amd64/initcpu.c Fri Feb  3 12:20:44 2017
(r313150)
@@ -253,12 +253,17 @@ initializecpucache(void)
 * CPUID_SS feature even though the native CPU supports it.
 */
TUNABLE_INT_FETCH("hw.clflush_disable", _clflush_disable);
-   if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1)
+   if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1) {
cpu_feature &= ~CPUID_CLFSH;
+   cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
+   }
+
/*
-* Allow to disable CLFLUSH feature manually by
-* hw.clflush_disable tunable.
+* The kernel's use of CLFLUSH{,OPT} can be disabled manually
+* by setting the hw.clflush_disable tunable.
 */
-   if (hw_clflush_disable == 1)
+   if (hw_clflush_disable == 1) {
cpu_feature &= ~CPUID_CLFSH;
+   cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
+   }
 }

Modified: stable/10/sys/amd64/amd64/pmap.c
==
--- stable/10/sys/amd64/amd64/pmap.cFri Feb  3 12:13:55 2017
(r313149)
+++ stable/10/sys/amd64/amd64/pmap.cFri Feb  3 12:20:44 2017
(r313150)
@@ -1789,9 +1789,8 @@ pmap_invalidate_cache_range(vm_offset_t 
 
if ((cpu_feature & CPUID_SS) != 0 && !force)
; /* If "Self Snoop" is supported and allowed, do nothing. */
-   else if ((cpu_feature & CPUID_CLFSH) != 0 &&
+   else if ((cpu_stdext_feature & CPUID_STDEXT_CLFLUSHOPT) != 0 &&
eva - sva < PMAP_CLFLUSH_THRESHOLD) {
-
/*
 * XXX: Some CPUs fault, hang, or trash the local APIC
 * registers if we use CLFLUSH on the local APIC
@@ -1802,16 +1801,29 @@ pmap_invalidate_cache_range(vm_offset_t 
return;
 
/*
-* Otherwise, do per-cache line flush.  Use the mfence
+* Otherwise, do per-cache line flush.  Use the sfence
 * instruction to insure that previous stores are
 * included in the write-back.  The processor
 * propagates flush to other processors in the cache
 * coherence domain.
 */
-   mfence();
+   sfence();
+   for (; sva < eva; sva += cpu_clflush_line_size)
+   clflushopt(sva);
+   sfence();
+   } else if ((cpu_feature & CPUID_CLFSH) != 0 &&
+   eva - sva < PMAP_CLFLUSH_THRESHOLD) {
+   if (pmap_kextract(sva) == lapic_paddr)
+   return;
+   /*
+* Writes are ordered by CLFLUSH on Intel CPUs.
+*/
+   if (cpu_vendor_id != CPU_VENDOR_INTEL)
+   mfence();
for (; sva < eva; sva += cpu_clflush_line_size)
clflush(sva);
-   mfence();
+   if (cpu_vendor_id != CPU_VENDOR_INTEL)
+   mfence();
} else {
 
/*
@@ -1835,19 +1847,31 @@ pmap_invalidate_cache_pages(vm_page_t *p
 {
vm_offset_t daddr, eva;
int i;
+   bool useclflushopt;
 
+   useclflushopt = (cpu_stdext_feature & CPUID_STDEXT_CLFLUSHOPT) != 0;
if (count >= PMAP_CLFLUSH_THRESHOLD / PAGE_SIZE ||
-   (cpu_feature & CPUID_CLFSH) == 0)
+   ((cpu_feature & CPUID_CLFSH) == 0 && !useclflushopt))
pmap_invalidate_cache();
else {
-   mfence();
+   if (useclflushopt)
+   sfence();
+   else if (cpu_vendor_id != CPU_VENDOR_INTEL)
+   mfence();
for (i = 0; i < count; i++) {
daddr = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(pages[i]));
eva = daddr + PAGE_SIZE;
-   for (; daddr < eva; daddr += cpu_clflush_line_size)
-   clflush(daddr);
+   for (; daddr < eva; daddr += cpu_clflush_line_size) {
+   if (useclflushopt)
+   

svn commit: r313095 - stable/10/sys/fs/tmpfs

2017-02-02 Thread Konstantin Belousov
Author: kib
Date: Thu Feb  2 13:39:11 2017
New Revision: 313095
URL: https://svnweb.freebsd.org/changeset/base/313095

Log:
  MFC r312432:
  Add a mount option for tmpfs(5) to not use namecache.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
  stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
  stable/10/sys/fs/tmpfs/tmpfs_vnops.c
  stable/10/sys/fs/tmpfs/tmpfs_vnops.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Feb  2 13:38:01 2017
(r313094)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Feb  2 13:39:11 2017
(r313095)
@@ -383,7 +383,9 @@ struct tmpfs_mount {
uma_zone_t  tm_node_pool;
 
/* Read-only status. */
-   int tm_ronly;
+   booltm_ronly;
+   /* Do not use namecache. */
+   booltm_nonc;
 };
 #defineTMPFS_LOCK(tm) mtx_lock(&(tm)->tm_allnode_lock)
 #defineTMPFS_UNLOCK(tm) mtx_unlock(&(tm)->tm_allnode_lock)
@@ -528,4 +530,11 @@ VP_TO_TMPFS_DIR(struct vnode *vp)
return (node);
 }
 
+static inline bool
+tmpfs_use_nc(struct vnode *vp)
+{
+
+   return (!(VFS_TO_TMPFS(vp->v_mount)->tm_nonc));
+}
+
 #endif /* _FS_TMPFS_TMPFS_H_ */

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Feb  2 13:38:01 2017
(r313094)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Feb  2 13:39:11 2017
(r313095)
@@ -591,7 +591,8 @@ loop:
TMPFS_NODE_UNLOCK(node);
 
/* Get a new vnode and associate it with our node. */
-   error = getnewvnode("tmpfs", mp, _vnodeop_entries, );
+   error = getnewvnode("tmpfs", mp, VFS_TO_TMPFS(mp)->tm_nonc ?
+   _vnodeop_nonc_entries : _vnodeop_entries, );
if (error != 0)
goto unlock;
MPASS(vp != NULL);

Modified: stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_vfsops.c   Thu Feb  2 13:38:01 2017
(r313094)
+++ stable/10/sys/fs/tmpfs/tmpfs_vfsops.c   Thu Feb  2 13:39:11 2017
(r313095)
@@ -78,7 +78,7 @@ static inttmpfs_statfs(struct mount *, 
 
 static const char *tmpfs_opts[] = {
"from", "size", "maxfilesize", "inodes", "uid", "gid", "mode", "export",
-   "union", NULL
+   "union", "nonc", NULL
 };
 
 static const char *tmpfs_updateopts[] = {
@@ -137,6 +137,7 @@ tmpfs_mount(struct mount *mp)
struct tmpfs_node *root;
struct thread *td = curthread;
int error;
+   bool nonc;
/* Size counters. */
u_quad_t pages;
off_t nodes_max, size_max, maxfilesize;
@@ -185,6 +186,7 @@ tmpfs_mount(struct mount *mp)
size_max = 0;
if (vfs_getopt_size(mp->mnt_optnew, "maxfilesize", ) != 0)
maxfilesize = 0;
+   nonc = vfs_getopt(mp->mnt_optnew, "nonc", NULL, NULL) == 0;
 
/* Do not allow mounts if we do not have enough memory to preserve
 * the minimum reserved pages. */
@@ -235,6 +237,7 @@ tmpfs_mount(struct mount *mp)
sizeof(struct tmpfs_node), tmpfs_node_ctor, tmpfs_node_dtor,
tmpfs_node_init, tmpfs_node_fini, UMA_ALIGN_PTR, 0);
tmp->tm_ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
+   tmp->tm_nonc = nonc;
 
/* Allocate the root node. */
error = tmpfs_alloc_node(mp, tmp, VDIR, root_uid, root_gid,

Modified: stable/10/sys/fs/tmpfs/tmpfs_vnops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_vnops.cThu Feb  2 13:38:01 2017
(r313094)
+++ stable/10/sys/fs/tmpfs/tmpfs_vnops.cThu Feb  2 13:39:11 2017
(r313095)
@@ -76,11 +76,8 @@ tmpfs_vn_get_ino_alloc(struct mount *mp,
 }
 
 static int
-tmpfs_lookup(struct vop_cachedlookup_args *v)
+tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
 {
-   struct vnode *dvp = v->a_dvp;
-   struct vnode **vpp = v->a_vpp;
-   struct componentname *cnp = v->a_cnp;
struct tmpfs_dirent *de;
struct tmpfs_node *dnode, *pnode;
struct tmpfs_mount *tm;
@@ -213,7 +210,7 @@ tmpfs_lookup(struct vop_cachedlookup_arg
 * request was for creation, as it does not improve timings on
 * emprical tests.
 */
-   if ((cnp->cn_flags & MAKEENTRY) != 0)
+   if ((cnp->cn_flags & MAKEENTRY) != 0 && tmpfs_use_nc(dvp))
cache_enter(dvp, *vpp, cnp);
 
 out:
@@ -227,6 +224,20 @@ out:
 }
 
 static int
+tmpfs_cached_lookup(struct vop_cachedlookup_args *v)
+{
+
+   return (tmpfs_lookup1(v->a_dvp, v->a_vpp, v->a_cnp));
+}
+
+static int
+tmpfs_lookup(struct vop_lookup_args *v)
+{
+
+   

svn commit: r313094 - stable/10/sys/fs/tmpfs

2017-02-02 Thread Konstantin Belousov
Author: kib
Date: Thu Feb  2 13:38:01 2017
New Revision: 313094
URL: https://svnweb.freebsd.org/changeset/base/313094

Log:
  MFC r312430:
  Implement VOP_VPTOCNP() for tmpfs.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs_vnops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_vnops.cThu Feb  2 13:37:00 2017
(r313093)
+++ stable/10/sys/fs/tmpfs/tmpfs_vnops.cThu Feb  2 13:38:01 2017
(r313094)
@@ -1402,6 +1402,132 @@ tmpfs_whiteout(struct vop_whiteout_args 
}
 }
 
+static int
+tmpfs_vptocnp_dir(struct tmpfs_node *tn, struct tmpfs_node *tnp,
+struct tmpfs_dirent **pde)
+{
+   struct tmpfs_dir_cursor dc;
+   struct tmpfs_dirent *de;
+
+   for (de = tmpfs_dir_first(tnp, ); de != NULL;
+de = tmpfs_dir_next(tnp, )) {
+   if (de->td_node == tn) {
+   *pde = de;
+   return (0);
+   }
+   }
+   return (ENOENT);
+}
+
+static int
+tmpfs_vptocnp_fill(struct vnode *vp, struct tmpfs_node *tn,
+struct tmpfs_node *tnp, char *buf, int *buflen, struct vnode **dvp)
+{
+   struct tmpfs_dirent *de;
+   int error, i;
+
+   error = vn_vget_ino_gen(vp, tmpfs_vn_get_ino_alloc, tnp, LK_SHARED,
+   dvp);
+   if (error != 0)
+   return (error);
+   error = tmpfs_vptocnp_dir(tn, tnp, );
+   if (error == 0) {
+   i = *buflen;
+   i -= de->td_namelen;
+   if (i < 0) {
+   error = ENOMEM;
+   } else {
+   bcopy(de->ud.td_name, buf + i, de->td_namelen);
+   *buflen = i;
+   }
+   }
+   if (error == 0) {
+   if (vp != *dvp)
+   VOP_UNLOCK(*dvp, 0);
+   } else {
+   if (vp != *dvp)
+   vput(*dvp);
+   else
+   vrele(vp);
+   }
+   return (error);
+}
+
+static int
+tmpfs_vptocnp(struct vop_vptocnp_args *ap)
+{
+   struct vnode *vp, **dvp;
+   struct tmpfs_node *tn, *tnp, *tnp1;
+   struct tmpfs_dirent *de;
+   struct tmpfs_mount *tm;
+   char *buf;
+   int *buflen;
+   int error;
+
+   vp = ap->a_vp;
+   dvp = ap->a_vpp;
+   buf = ap->a_buf;
+   buflen = ap->a_buflen;
+
+   tm = VFS_TO_TMPFS(vp->v_mount);
+   tn = VP_TO_TMPFS_NODE(vp);
+   if (tn->tn_type == VDIR) {
+   tnp = tn->tn_dir.tn_parent;
+   if (tnp == NULL)
+   return (ENOENT);
+   tmpfs_ref_node(tnp);
+   error = tmpfs_vptocnp_fill(vp, tn, tn->tn_dir.tn_parent, buf,
+   buflen, dvp);
+   tmpfs_free_node(tm, tnp);
+   return (error);
+   }
+restart:
+   TMPFS_LOCK(tm);
+   LIST_FOREACH_SAFE(tnp, >tm_nodes_used, tn_entries, tnp1) {
+   if (tnp->tn_type != VDIR)
+   continue;
+   TMPFS_NODE_LOCK(tnp);
+   tmpfs_ref_node_locked(tnp);
+
+   /*
+* tn_vnode cannot be instantiated while we hold the
+* node lock, so the directory cannot be changed while
+* we iterate over it.  Do this to avoid instantiating
+* vnode for directories which cannot point to our
+* node.
+*/
+   error = tnp->tn_vnode == NULL ? tmpfs_vptocnp_dir(tn, tnp,
+   ) : 0;
+
+   if (error == 0) {
+   TMPFS_NODE_UNLOCK(tnp);
+   TMPFS_UNLOCK(tm);
+   error = tmpfs_vptocnp_fill(vp, tn, tnp, buf, buflen,
+   dvp);
+   if (error == 0) {
+   tmpfs_free_node(tm, tnp);
+   return (0);
+   }
+   if ((vp->v_iflag & VI_DOOMED) != 0) {
+   tmpfs_free_node(tm, tnp);
+   return (ENOENT);
+   }
+   TMPFS_LOCK(tm);
+   TMPFS_NODE_LOCK(tnp);
+   }
+   if (tmpfs_free_node_locked(tm, tnp, false)) {
+   goto restart;
+   } else {
+   KASSERT(tnp->tn_refcount > 0,
+   ("node %p refcount zero", tnp));
+   tnp1 = LIST_NEXT(tnp, tn_entries);
+   TMPFS_NODE_UNLOCK(tnp);
+   }
+   }
+   TMPFS_UNLOCK(tm);
+   return (ENOENT);
+}
+
 /*
  * Vnode operations vector used for files stored in a tmpfs file system.
  */
@@ -1434,5 +1560,6 @@ struct vop_vector tmpfs_vnodeop_entries 
.vop_vptofh =   tmpfs_vptofh,
 

svn commit: r313093 - stable/10/sys/fs/tmpfs

2017-02-02 Thread Konstantin Belousov
Author: kib
Date: Thu Feb  2 13:37:00 2017
New Revision: 313093
URL: https://svnweb.freebsd.org/changeset/base/313093

Log:
  MFC r312429:
  VNON nodes cannot exist.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Feb  2 13:36:07 2017
(r313092)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Feb  2 13:37:00 2017
(r313093)
@@ -332,11 +332,6 @@ tmpfs_free_node_locked(struct tmpfs_moun
TMPFS_UNLOCK(tmp);
 
switch (node->tn_type) {
-   case VNON:
-   /* Do not do anything.  VNON is provided to let the
-* allocation routine clean itself easily by avoiding
-* duplicating code in it. */
-   /* FALLTHROUGH */
case VBLK:
/* FALLTHROUGH */
case VCHR:
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313092 - stable/10/sys/fs/tmpfs

2017-02-02 Thread Konstantin Belousov
Author: kib
Date: Thu Feb  2 13:36:07 2017
New Revision: 313092
URL: https://svnweb.freebsd.org/changeset/base/313092

Log:
  MFC r312428:
  Refcount tmpfs nodes and mount structures.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
  stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
  stable/10/sys/fs/tmpfs/tmpfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Feb  2 09:19:57 2017
(r313091)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Feb  2 13:36:07 2017
(r313092)
@@ -158,9 +158,11 @@ struct tmpfs_node {
 * Doubly-linked list entry which links all existing nodes for
 * a single file system.  This is provided to ease the removal
 * of all nodes during the unmount operation, and to support
-* the implementation of VOP_VNTOCNP().
+* the implementation of VOP_VNTOCNP().  tn_attached is false
+* when the node is removed from list and unlocked.
 */
LIST_ENTRY(tmpfs_node)  tn_entries; /* (m) */
+   booltn_attached;/* (m) */
 
/*
 * The node's type.  Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
@@ -231,6 +233,9 @@ struct tmpfs_node {
 */
int tn_vpstate; /* (i) */
 
+   /* Transient refcounter on this node. */
+   u_int   tn_refcount;/* (m) + (i) */
+
/* misc data field for different tn_type node */
union {
/* Valid when tn_type == VBLK || tn_type == VCHR. */
@@ -358,6 +363,9 @@ struct tmpfs_mount {
/* Number of nodes currently that are in use. */
ino_t   tm_nodes_inuse;
 
+   /* Refcounter on this struct tmpfs_mount. */
+   uint64_ttm_refcount;
+
/* maximum representable file size */
u_int64_t   tm_maxfilesize;
 
@@ -402,10 +410,14 @@ struct tmpfs_dir_cursor {
  * Prototypes for tmpfs_subr.c.
  */
 
+void   tmpfs_ref_node(struct tmpfs_node *node);
+void   tmpfs_ref_node_locked(struct tmpfs_node *node);
 inttmpfs_alloc_node(struct mount *mp, struct tmpfs_mount *, enum vtype,
uid_t uid, gid_t gid, mode_t mode, struct tmpfs_node *,
char *, dev_t, struct tmpfs_node **);
 void   tmpfs_free_node(struct tmpfs_mount *, struct tmpfs_node *);
+bool   tmpfs_free_node_locked(struct tmpfs_mount *, struct tmpfs_node *, bool);
+void   tmpfs_free_tmp(struct tmpfs_mount *);
 inttmpfs_alloc_dirent(struct tmpfs_mount *, struct tmpfs_node *,
const char *, u_int, struct tmpfs_dirent **);
 void   tmpfs_free_dirent(struct tmpfs_mount *, struct tmpfs_dirent *);

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Feb  2 09:19:57 2017
(r313091)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Feb  2 13:36:07 2017
(r313092)
@@ -131,6 +131,26 @@ tmpfs_pages_check_avail(struct tmpfs_mou
return (1);
 }
 
+void
+tmpfs_ref_node(struct tmpfs_node *node)
+{
+
+   TMPFS_NODE_LOCK(node);
+   tmpfs_ref_node_locked(node);
+   TMPFS_NODE_UNLOCK(node);
+}
+
+void
+tmpfs_ref_node_locked(struct tmpfs_node *node)
+{
+
+   TMPFS_NODE_ASSERT_LOCKED(node);
+   KASSERT(node->tn_refcount > 0, ("node %p zero refcount", node));
+   KASSERT(node->tn_refcount < UINT_MAX, ("node %p refcount %u", node,
+   node->tn_refcount));
+   node->tn_refcount++;
+}
+
 /*
  * Allocates a new node of type 'type' inside the 'tmp' mount point, with
  * its owner set to 'uid', its group to 'gid' and its mode set to 'mode',
@@ -205,6 +225,7 @@ tmpfs_alloc_node(struct mount *mp, struc
nnode->tn_gid = gid;
nnode->tn_mode = mode;
nnode->tn_id = alloc_unr(tmp->tm_ino_unr);
+   nnode->tn_refcount = 1;
 
/* Type-specific initialization. */
switch (nnode->tn_type) {
@@ -258,7 +279,9 @@ tmpfs_alloc_node(struct mount *mp, struc
 
TMPFS_LOCK(tmp);
LIST_INSERT_HEAD(>tm_nodes_used, nnode, tn_entries);
+   nnode->tn_attached = true;
tmp->tm_nodes_inuse++;
+   tmp->tm_refcount++;
TMPFS_UNLOCK(tmp);
 
*node = nnode;
@@ -272,18 +295,40 @@ tmpfs_alloc_node(struct mount *mp, struc
 void
 tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node)
 {
+
+   TMPFS_LOCK(tmp);
+   TMPFS_NODE_LOCK(node);
+   if (!tmpfs_free_node_locked(tmp, node, false)) {
+   TMPFS_NODE_UNLOCK(node);
+   TMPFS_UNLOCK(tmp);
+   }
+}
+
+bool
+tmpfs_free_node_locked(struct tmpfs_mount *tmp, struct tmpfs_node *node,
+bool detach)
+{
vm_object_t uobj;
 
+   TMPFS_MP_ASSERT_LOCKED(tmp);
+   TMPFS_NODE_ASSERT_LOCKED(node);
+   KASSERT(node->tn_refcount > 0, 

svn commit: r312946 - stable/10/sys/kern

2017-01-29 Thread Konstantin Belousov
Author: kib
Date: Sun Jan 29 10:36:43 2017
New Revision: 312946
URL: https://svnweb.freebsd.org/changeset/base/312946

Log:
  MFC r312647:
  Add comments explaining unobvious td_critnest adjustments in
  critical_exit().

Modified:
  stable/10/sys/kern/kern_switch.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_switch.c
==
--- stable/10/sys/kern/kern_switch.cSun Jan 29 10:33:42 2017
(r312945)
+++ stable/10/sys/kern/kern_switch.cSun Jan 29 10:36:43 2017
(r312946)
@@ -206,7 +206,22 @@ critical_exit(void)
 
if (td->td_critnest == 1) {
td->td_critnest = 0;
+
+   /*
+* Interrupt handlers execute critical_exit() on
+* leave, and td_owepreempt may be left set by an
+* interrupt handler only when td_critnest > 0.  If we
+* are decrementing td_critnest from 1 to 0, read
+* td_owepreempt after decrementing, to not miss the
+* preempt.  Disallow compiler to reorder operations.
+*/
+   __compiler_membar();
if (td->td_owepreempt && !kdb_active) {
+   /*
+* Microoptimization: we committed to switch,
+* disable preemption in interrupt handlers
+* while spinning for the thread lock.
+*/
td->td_critnest = 1;
thread_lock(td);
td->td_critnest--;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312811 - stable/10/share/man/man5

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 11:07:36 2017
New Revision: 312811
URL: https://svnweb.freebsd.org/changeset/base/312811

Log:
  MFC r312423:
  Refresh tmpfs(5) man page.
  
  MFC r312648:
  Editing and clarifications for tmpfs(5).

Modified:
  stable/10/share/man/man5/tmpfs.5
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/share/man/man5/tmpfs.5
==
--- stable/10/share/man/man5/tmpfs.5Thu Jan 26 11:06:39 2017
(r312810)
+++ stable/10/share/man/man5/tmpfs.5Thu Jan 26 11:07:36 2017
(r312811)
@@ -1,7 +1,12 @@
 .\"-
 .\" Copyright (c) 2007 Xin LI
+.\" Copyright (c) 2017 The FreeBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
+.\" Part of this documentation was written by
+.\" Konstantin Belousov <k...@freebsd.org> 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:
@@ -49,12 +54,12 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 23, 2012
+.Dd January 17, 2017
 .Dt TMPFS 5
 .Os
 .Sh NAME
 .Nm tmpfs
-.Nd "efficient memory file system"
+.Nd "in-memory file system"
 .Sh SYNOPSIS
 To compile this driver into the kernel,
 place the following line in your
@@ -72,17 +77,40 @@ tmpfs_load="YES"
 .Sh DESCRIPTION
 The
 .Nm
-driver will permit the
-.Fx
-kernel to access
+driver implements an in-memory, or
 .Tn tmpfs
-file systems.
+file system.
+The filesystem stores both file metadata and data in main memory.
+This allows very fast and low latency accesses to the data.
+The data is volatile.
+An umount or system reboot invalidates it.
+These properties make the filesystem's mounts suitable for fast
+scratch storage, like
+.Pa /tmp .
+.Pp
+If the system becomes low on memory and swap is configured (see
+.Xr swapon 8 ),
+the system can transfer file data to swap space, freeing memory
+for other needs.
+Metadata, including the directory content, is never swapped out by the
+current implementation.
+Keep this in mind when planning the mount limits, especially when expecting
+to place many small files on a tmpfs mount.
+.Pp
+When 
+.Xr mmap 2
+is used on a file from a tmpfs mount, the swap VM object managing the 
+file pages is used to implement mapping and avoid double-copying of
+the file data.
+This quirk causes process inspection tools, like
+.Xr procstat 1 ,
+to report anonymous memory mappings instead of file mappings.
 .Sh OPTIONS
 The following options are available when
 mounting
 .Nm
 file systems:
-.Bl -tag -width indent
+.Bl -tag -width "It Cm maxfilesize"
 .It Cm gid
 Specifies the group ID of the root inode of the file system.
 Defaults to the mount point's GID.
@@ -114,11 +142,15 @@ memory file system:
 .Pp
 .Dl "mount -t tmpfs tmpfs /tmp"
 .Sh SEE ALSO
+.Xr procstat 1 ,
 .Xr nmount 2 ,
+.Xr mmap 2 ,
 .Xr unmount 2 ,
 .Xr fstab 5 ,
 .Xr mdmfs 8 ,
-.Xr mount 8
+.Xr mount 8 ,
+.Xr swapinfo 8 ,
+.Xr swapon 8
 .Sh HISTORY
 The
 .Nm
@@ -130,7 +162,7 @@ The
 .Nm
 kernel implementation was written by
 .An Julio M. Merino Vidal Aq j...@netbsd.org
-as a Google SoC project.
+as a Google Summer of Code project.
 .Pp
 .An Rohit Jalan
 and others ported it from
@@ -140,5 +172,3 @@ to
 .Pp
 This manual page was written by
 .An Xin LI Aq delp...@freebsd.org .
-.Sh BUGS
-Some file system mount time options may not be well-supported.
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312809 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 11:04:27 2017
New Revision: 312809
URL: https://svnweb.freebsd.org/changeset/base/312809

Log:
  MFC r312425:
  Make tmpfs directory cursor available outside tmpfs_subr.c.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 11:03:19 2017
(r312808)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 11:04:27 2017
(r312809)
@@ -392,6 +392,11 @@ struct tmpfs_fid {
unsigned long   tf_gen;
 };
 
+struct tmpfs_dir_cursor {
+   struct tmpfs_dirent *tdc_current;
+   struct tmpfs_dirent *tdc_tree;
+};
+
 #ifdef _KERNEL
 /*
  * Prototypes for tmpfs_subr.c.
@@ -436,6 +441,10 @@ void   tmpfs_itimes(struct vnode *, const 
 void   tmpfs_set_status(struct tmpfs_node *node, int status);
 void   tmpfs_update(struct vnode *);
 inttmpfs_truncate(struct vnode *, off_t);
+struct tmpfs_dirent *tmpfs_dir_first(struct tmpfs_node *dnode,
+   struct tmpfs_dir_cursor *dc);
+struct tmpfs_dirent *tmpfs_dir_next(struct tmpfs_node *dnode,
+   struct tmpfs_dir_cursor *dc);
 
 /*
  * Convenience macros to simplify some logical expressions.

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 11:03:19 2017
(r312808)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 11:04:27 2017
(r312809)
@@ -61,11 +61,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
-struct tmpfs_dir_cursor {
-   struct tmpfs_dirent *tdc_current;
-   struct tmpfs_dirent *tdc_tree;
-};
-
 SYSCTL_NODE(_vfs, OID_AUTO, tmpfs, CTLFLAG_RW, 0, "tmpfs file system");
 
 static long tmpfs_pages_reserved = TMPFS_PAGES_MINRESERVED;
@@ -724,7 +719,7 @@ tmpfs_alloc_file(struct vnode *dvp, stru
return (0);
 }
 
-static struct tmpfs_dirent *
+struct tmpfs_dirent *
 tmpfs_dir_first(struct tmpfs_node *dnode, struct tmpfs_dir_cursor *dc)
 {
struct tmpfs_dirent *de;
@@ -738,7 +733,7 @@ tmpfs_dir_first(struct tmpfs_node *dnode
return (dc->tdc_current);
 }
 
-static struct tmpfs_dirent *
+struct tmpfs_dirent *
 tmpfs_dir_next(struct tmpfs_node *dnode, struct tmpfs_dir_cursor *dc)
 {
struct tmpfs_dirent *de;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312807 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 11:00:57 2017
New Revision: 312807
URL: https://svnweb.freebsd.org/changeset/base/312807

Log:
  MFC r312414:
  Rename tmpfs_mount member allnode_lock to include namespace prefix.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:58:12 2017
(r312806)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 11:00:57 2017
(r312807)
@@ -150,7 +150,7 @@ RB_HEAD(tmpfs_dir, tmpfs_dirent);
  * (vi) vnode lock in exclusive mode, or vnode lock in shared vnode and
  * tn_interlock
  * (i)  tn_interlock
- * (m)  tmpfs_mount allnode_lock
+ * (m)  tmpfs_mount tm_allnode_lock
  * (c)  stable after creation
  */
 struct tmpfs_node {
@@ -368,7 +368,7 @@ struct tmpfs_mount {
struct tmpfs_node_list  tm_nodes_used;
 
/* All node lock to protect the node list and tmp_pages_used. */
-   struct mtx allnode_lock;
+   struct mtx  tm_allnode_lock;
 
/* Zones used to store file system meta data, per tmpfs mount. */
uma_zone_t  tm_dirent_pool;
@@ -377,8 +377,9 @@ struct tmpfs_mount {
/* Read-only status. */
int tm_ronly;
 };
-#define TMPFS_LOCK(tm) mtx_lock(&(tm)->allnode_lock)
-#define TMPFS_UNLOCK(tm) mtx_unlock(&(tm)->allnode_lock)
+#defineTMPFS_LOCK(tm) mtx_lock(&(tm)->tm_allnode_lock)
+#defineTMPFS_UNLOCK(tm) mtx_unlock(&(tm)->tm_allnode_lock)
+#defineTMPFS_MP_ASSERT_LOCKED(tm) mtx_assert(&(tm)->tm_allnode_lock, 
MA_OWNED)
 
 /*
  * This structure maps a file identifier to a tmpfs node.  Used by the

Modified: stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_vfsops.c   Thu Jan 26 10:58:12 2017
(r312806)
+++ stable/10/sys/fs/tmpfs/tmpfs_vfsops.c   Thu Jan 26 11:00:57 2017
(r312807)
@@ -218,7 +218,7 @@ tmpfs_mount(struct mount *mp)
tmp = (struct tmpfs_mount *)malloc(sizeof(struct tmpfs_mount),
M_TMPFSMNT, M_WAITOK | M_ZERO);
 
-   mtx_init(>allnode_lock, "tmpfs allnode lock", NULL, MTX_DEF);
+   mtx_init(>tm_allnode_lock, "tmpfs allnode lock", NULL, MTX_DEF);
tmp->tm_nodes_max = nodes_max;
tmp->tm_nodes_inuse = 0;
tmp->tm_maxfilesize = maxfilesize > 0 ? maxfilesize : OFF_MAX;
@@ -226,7 +226,7 @@ tmpfs_mount(struct mount *mp)
 
tmp->tm_pages_max = pages;
tmp->tm_pages_used = 0;
-   tmp->tm_ino_unr = new_unrhdr(2, INT_MAX, >allnode_lock);
+   tmp->tm_ino_unr = new_unrhdr(2, INT_MAX, >tm_allnode_lock);
tmp->tm_dirent_pool = uma_zcreate("TMPFS dirent",
sizeof(struct tmpfs_dirent), NULL, NULL, NULL, NULL,
UMA_ALIGN_PTR, 0);
@@ -314,7 +314,7 @@ tmpfs_unmount(struct mount *mp, int mntf
uma_zdestroy(tmp->tm_node_pool);
delete_unrhdr(tmp->tm_ino_unr);
 
-   mtx_destroy(>allnode_lock);
+   mtx_destroy(>tm_allnode_lock);
MPASS(tmp->tm_pages_used == 0);
MPASS(tmp->tm_nodes_inuse == 0);
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312805 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 10:55:56 2017
New Revision: 312805
URL: https://svnweb.freebsd.org/changeset/base/312805

Log:
  MFC r312410:
  Rework some tmpfs lock assertions.
  
  MFC r312412:
  Protect macro argument.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
  stable/10/sys/fs/tmpfs/tmpfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:53:05 2017
(r312804)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:55:56 2017
(r312805)
@@ -307,21 +307,12 @@ LIST_HEAD(tmpfs_node_list, tmpfs_node);
 
 #ifdef INVARIANTS
 #define TMPFS_ASSERT_LOCKED(node) do { \
-   MPASS(node != NULL);\
-   MPASS(node->tn_vnode != NULL);  \
-   if (!VOP_ISLOCKED(node->tn_vnode) &&\
-   !mtx_owned(TMPFS_NODE_MTX(node)))   \
-   panic("tmpfs: node is not locked: %p", node);   \
-   } while (0)
-#define TMPFS_ASSERT_ELOCKED(node) do {
\
MPASS((node) != NULL);  \
MPASS((node)->tn_vnode != NULL);\
-   mtx_assert(TMPFS_NODE_MTX(node), MA_OWNED); \
-   ASSERT_VOP_LOCKED((node)->tn_vnode, "tmpfs");   \
+   ASSERT_VOP_LOCKED((node)->tn_vnode, "tmpfs assert");\
} while (0)
 #else
 #define TMPFS_ASSERT_LOCKED(node) (void)0
-#define TMPFS_ASSERT_ELOCKED(node) (void)0
 #endif
 
 #define TMPFS_VNODE_ALLOCATING 1

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 10:53:05 2017
(r312804)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 10:55:56 2017
(r312805)
@@ -669,7 +669,7 @@ tmpfs_alloc_file(struct vnode *dvp, stru
struct tmpfs_node *node;
struct tmpfs_node *parent;
 
-   MPASS(VOP_ISLOCKED(dvp));
+   ASSERT_VOP_ELOCKED(dvp, "tmpfs_alloc_file");
MPASS(cnp->cn_flags & HASBUF);
 
tmp = VFS_TO_TMPFS(dvp->v_mount);

Modified: stable/10/sys/fs/tmpfs/tmpfs_vnops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_vnops.cThu Jan 26 10:53:05 2017
(r312804)
+++ stable/10/sys/fs/tmpfs/tmpfs_vnops.cThu Jan 26 10:55:56 2017
(r312805)
@@ -1107,7 +1107,6 @@ tmpfs_rmdir(struct vop_rmdir_args *v)
 
/* No vnode should be allocated for this entry from this point */
TMPFS_NODE_LOCK(node);
-   TMPFS_ASSERT_ELOCKED(node);
node->tn_links--;
node->tn_dir.tn_parent = NULL;
node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED |
@@ -1116,7 +1115,6 @@ tmpfs_rmdir(struct vop_rmdir_args *v)
TMPFS_NODE_UNLOCK(node);
 
TMPFS_NODE_LOCK(dnode);
-   TMPFS_ASSERT_ELOCKED(dnode);
dnode->tn_links--;
dnode->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED |
TMPFS_NODE_MODIFIED;
@@ -1270,7 +1268,6 @@ tmpfs_reclaim(struct vop_reclaim_args *v
cache_purge(vp);
 
TMPFS_NODE_LOCK(node);
-   TMPFS_ASSERT_ELOCKED(node);
tmpfs_free_vp(vp);
 
/* If the node referenced by this vnode was deleted by the user,
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312803 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 10:49:45 2017
New Revision: 312803
URL: https://svnweb.freebsd.org/changeset/base/312803

Log:
  MFC r312409:
  Style fixes and comment updates.
  
  MFC r312435:
  Remove mistakenly merged field.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
  stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
  stable/10/sys/fs/tmpfs/tmpfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:47:05 2017
(r312802)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:49:45 2017
(r312803)
@@ -80,8 +80,10 @@ struct tmpfs_dirent {
uint32_ttd_hash;
u_int   td_namelen;
 
-   /* Pointer to the node this entry refers to.  In case this field
-* is NULL, the node is a whiteout. */
+   /*
+* Pointer to the node this entry refers to.  In case this field
+* is NULL, the node is a whiteout.
+*/
struct tmpfs_node * td_node;
 
union {
@@ -94,21 +96,24 @@ struct tmpfs_dirent {
} ud;
 };
 
-/* A directory in tmpfs holds a list of directory entries, which in
- * turn point to other files (which can be directories themselves).
+/*
+ * A directory in tmpfs holds a collection of directory entries, which
+ * in turn point to other files (which can be directories themselves).
  *
- * In tmpfs, this list is managed by a RB-Tree, whose head is defined by
- * the struct tmpfs_dir type.
+ * In tmpfs, this collection is managed by a RB-Tree, whose head is
+ * defined by the struct tmpfs_dir type.
  *
  * It is important to notice that directories do not have entries for . and
  * .. as other file systems do.  These can be generated when requested
  * based on information available by other means, such as the pointer to
  * the node itself in the former case or the pointer to the parent directory
  * in the latter case.  This is done to simplify tmpfs's code and, more
- * importantly, to remove redundancy. */
+ * importantly, to remove redundancy.
+ */
 RB_HEAD(tmpfs_dir, tmpfs_dirent);
 
-/* Each entry in a directory has a cookie that identifies it.  Cookies
+/*
+ * Each entry in a directory has a cookie that identifies it.  Cookies
  * supersede offsets within directories because, given how tmpfs stores
  * directories in memory, there is no such thing as an offset.
  *
@@ -139,51 +144,65 @@ RB_HEAD(tmpfs_dir, tmpfs_dirent);
  * a particular type.  The code must be careful to only access those
  * attributes that are actually allowed by the node's type.
  *
- *
  * Below is the key of locks used to protected the fields in the following
  * structures.
- *
+ * (v)  vnode lock in exclusive mode
+ * (vi) vnode lock in exclusive mode, or vnode lock in shared vnode and
+ * tn_interlock
+ * (i)  tn_interlock
+ * (m)  tmpfs_mount allnode_lock
+ * (c)  stable after creation
  */
 struct tmpfs_node {
-   /* Doubly-linked list entry which links all existing nodes for a
-* single file system.  This is provided to ease the removal of
-* all nodes during the unmount operation. */
-   LIST_ENTRY(tmpfs_node)  tn_entries;
+   /*
+* Doubly-linked list entry which links all existing nodes for
+* a single file system.  This is provided to ease the removal
+* of all nodes during the unmount operation, and to support
+* the implementation of VOP_VNTOCNP().
+*/
+   LIST_ENTRY(tmpfs_node)  tn_entries; /* (m) */
 
-   /* The node's type.  Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
+   /*
+* The node's type.  Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
 * 'VLNK', 'VREG' and 'VSOCK' is allowed.  The usage of vnode
 * types instead of a custom enumeration is to make things simpler
-* and faster, as we do not need to convert between two types. */
-   enum vtype  tn_type;
+* and faster, as we do not need to convert between two types.
+*/
+   enum vtype  tn_type;/* (c) */
 
/* Node identifier. */
-   ino_t   tn_id;
+   ino_t   tn_id;  /* (c) */
 
-   /* Node's internal status.  This is used by several file system
+   /*
+* Node's internal status.  This is used by several file system
 * operations to do modifications to the node in a delayed
-* fashion. */
-   int tn_status;
+* fashion.
+*/
+   int tn_status;  /* (vi) */
 #defineTMPFS_NODE_ACCESSED (1 << 1)
 #defineTMPFS_NODE_MODIFIED (1 << 2)
 #defineTMPFS_NODE_CHANGED  (1 << 3)
 
-   /* The node size.  It does not necessarily match the real amount
-* of memory consumed by it. 

svn commit: r312801 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 10:43:36 2017
New Revision: 312801
URL: https://svnweb.freebsd.org/changeset/base/312801

Log:
  MFC r312407:
  Remove unused union member, fifos on tmpfs are implemented in common code.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:41:56 2017
(r312800)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:43:36 2017
(r312801)
@@ -259,12 +259,6 @@ struct tmpfs_node {
vm_object_t tn_aobj;
 
}tn_reg;
-
-   /* Valid when tn_type = VFIFO */
-   struct tn_fifo {
-   fo_rdwr_t   *tn_fo_read;
-   fo_rdwr_t   *tn_fo_write;
-   }tn_fifo;
}tn_spec;
 };
 LIST_HEAD(tmpfs_node_list, tmpfs_node);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312799 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 10:35:04 2017
New Revision: 312799
URL: https://svnweb.freebsd.org/changeset/base/312799

Log:
  MFC r312124 (by mjg):
  tmpfs: manage tm_pages_used with atomics.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
  stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:29:23 2017
(r312798)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Thu Jan 26 10:35:04 2017
(r312799)
@@ -312,12 +312,12 @@ struct tmpfs_mount {
/* Maximum number of memory pages available for use by the file
 * system, set during mount time.  This variable must never be
 * used directly as it may be bigger than the current amount of
-* free memory; in the extreme case, it will hold the SIZE_MAX
+* free memory; in the extreme case, it will hold the ULONG_MAX
 * value. */
-   size_t  tm_pages_max;
+   u_long  tm_pages_max;
 
/* Number of pages in use by the file system. */
-   size_t  tm_pages_used;
+   u_long  tm_pages_used;
 
/* Pointer to the node representing the root directory of this
 * file system. */

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 10:29:23 2017
(r312798)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 10:35:04 2017
(r312799)
@@ -129,7 +129,7 @@ tmpfs_pages_check_avail(struct tmpfs_mou
if (tmpfs_mem_avail() < req_pages)
return (0);
 
-   if (tmp->tm_pages_max != SIZE_MAX &&
+   if (tmp->tm_pages_max != ULONG_MAX &&
tmp->tm_pages_max < req_pages + tmpfs_pages_used(tmp))
return (0);
 
@@ -327,9 +327,7 @@ tmpfs_free_node(struct tmpfs_mount *tmp,
case VREG:
uobj = node->tn_reg.tn_aobj;
if (uobj != NULL) {
-   TMPFS_LOCK(tmp);
-   tmp->tm_pages_used -= uobj->size;
-   TMPFS_UNLOCK(tmp);
+   atomic_subtract_long(>tm_pages_used, uobj->size);
KASSERT((uobj->flags & OBJ_TMPFS) == 0,
("leaked OBJ_TMPFS node %p vm_obj %p", node, uobj));
vm_object_deallocate(uobj);
@@ -1413,9 +1411,7 @@ retry:
uobj->size = newpages;
VM_OBJECT_WUNLOCK(uobj);
 
-   TMPFS_LOCK(tmp);
-   tmp->tm_pages_used += (newpages - oldpages);
-   TMPFS_UNLOCK(tmp);
+   atomic_add_long(>tm_pages_used, newpages - oldpages);
 
node->tn_size = newsize;
return (0);

Modified: stable/10/sys/fs/tmpfs/tmpfs_vfsops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_vfsops.c   Thu Jan 26 10:29:23 2017
(r312798)
+++ stable/10/sys/fs/tmpfs/tmpfs_vfsops.c   Thu Jan 26 10:35:04 2017
(r312799)
@@ -395,7 +395,7 @@ tmpfs_statfs(struct mount *mp, struct st
sbp->f_bsize = PAGE_SIZE;
 
used = tmpfs_pages_used(tmp);
-   if (tmp->tm_pages_max != SIZE_MAX)
+   if (tmp->tm_pages_max != ULONG_MAX)
 sbp->f_blocks = tmp->tm_pages_max;
else
 sbp->f_blocks = used + tmpfs_mem_avail();
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312798 - stable/10/sys/fs/tmpfs

2017-01-26 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 26 10:29:23 2017
New Revision: 312798
URL: https://svnweb.freebsd.org/changeset/base/312798

Log:
  MFC r311531 (by mjg):
  Perform a lockless check in tmpfs_itimes.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 10:19:53 2017
(r312797)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 26 10:29:23 2017
(r312798)
@@ -1745,19 +1745,22 @@ tmpfs_set_status(struct tmpfs_node *node
 }
 
 /* Sync timestamps */
-static void
-tmpfs_itimes_locked(struct tmpfs_node *node, const struct timespec *acc,
+void
+tmpfs_itimes(struct vnode *vp, const struct timespec *acc,
 const struct timespec *mod)
 {
+   struct tmpfs_node *node;
struct timespec now;
 
-   TMPFS_ASSERT_LOCKED(node);
+   ASSERT_VOP_LOCKED(vp, "tmpfs_itimes");
+   node = VP_TO_TMPFS_NODE(vp);
 
if ((node->tn_status & (TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
TMPFS_NODE_CHANGED)) == 0)
return;
 
vfs_timestamp();
+   TMPFS_NODE_LOCK(node);
if (node->tn_status & TMPFS_NODE_ACCESSED) {
if (acc == NULL)
 acc = 
@@ -1772,19 +1775,6 @@ tmpfs_itimes_locked(struct tmpfs_node *n
node->tn_ctime = now;
node->tn_status &= ~(TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
TMPFS_NODE_CHANGED);
-}
-
-void
-tmpfs_itimes(struct vnode *vp, const struct timespec *acc,
-const struct timespec *mod)
-{
-   struct tmpfs_node *node;
-
-   ASSERT_VOP_LOCKED(vp, "tmpfs_itimes");
-   node = VP_TO_TMPFS_NODE(vp);
-
-   TMPFS_NODE_LOCK(node);
-   tmpfs_itimes_locked(node, acc, mod);
TMPFS_NODE_UNLOCK(node);
 
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312701 - stable/10/libexec/rtld-elf

2017-01-24 Thread Konstantin Belousov
Author: kib
Date: Tue Jan 24 17:30:13 2017
New Revision: 312701
URL: https://svnweb.freebsd.org/changeset/base/312701

Log:
  MFC r311886:
  Fix acquisition of nested write compat rtld locks.
  
  PR:   215826

Modified:
  stable/10/libexec/rtld-elf/rtld_lock.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld_lock.c
==
--- stable/10/libexec/rtld-elf/rtld_lock.c  Tue Jan 24 16:47:06 2017
(r312700)
+++ stable/10/libexec/rtld-elf/rtld_lock.c  Tue Jan 24 17:30:13 2017
(r312701)
@@ -64,7 +64,7 @@ typedef struct Struct_Lock {
 } Lock;
 
 static sigset_t fullsigmask, oldsigmask;
-static int thread_flag;
+static int thread_flag, wnested;
 
 static void *
 def_lock_create(void)
@@ -117,29 +117,34 @@ def_rlock_acquire(void *lock)
 static void
 def_wlock_acquire(void *lock)
 {
-Lock *l = (Lock *)lock;
-sigset_t tmp_oldsigmask;
+   Lock *l;
+   sigset_t tmp_oldsigmask;
 
-for ( ; ; ) {
-   sigprocmask(SIG_BLOCK, , _oldsigmask);
-   if (atomic_cmpset_acq_int(>lock, 0, WAFLAG))
-   break;
-   sigprocmask(SIG_SETMASK, _oldsigmask, NULL);
-}
-oldsigmask = tmp_oldsigmask;
+   l = (Lock *)lock;
+   for (;;) {
+   sigprocmask(SIG_BLOCK, , _oldsigmask);
+   if (atomic_cmpset_acq_int(>lock, 0, WAFLAG))
+   break;
+   sigprocmask(SIG_SETMASK, _oldsigmask, NULL);
+   }
+   if (atomic_fetchadd_int(, 1) == 0)
+   oldsigmask = tmp_oldsigmask;
 }
 
 static void
 def_lock_release(void *lock)
 {
-Lock *l = (Lock *)lock;
+   Lock *l;
 
-if ((l->lock & WAFLAG) == 0)
-   atomic_add_rel_int(>lock, -RC_INCR);
-else {
-   atomic_add_rel_int(>lock, -WAFLAG);
-   sigprocmask(SIG_SETMASK, , NULL);
-}
+   l = (Lock *)lock;
+   if ((l->lock & WAFLAG) == 0)
+   atomic_add_rel_int(>lock, -RC_INCR);
+   else {
+   assert(wnested > 0);
+   atomic_add_rel_int(>lock, -WAFLAG);
+   if (atomic_fetchadd_int(, -1) == 1)
+   sigprocmask(SIG_SETMASK, , NULL);
+   }
 }
 
 static int
@@ -373,12 +378,12 @@ _rtld_atfork_pre(int *locks)
return;
 
/*
-* Warning: this does not work with the rtld compat locks
-* above, since the thread signal mask is corrupted (set to
-* all signals blocked) if two locks are taken in write mode.
-* The caller of the _rtld_atfork_pre() must provide the
-* working implementation of the locks, and libthr locks are
-* fine.
+* Warning: this did not worked well with the rtld compat
+* locks above, when the thread signal mask was corrupted (set
+* to all signals blocked) if two locks were taken
+* simultaneously in the write mode.  The caller of the
+* _rtld_atfork_pre() must provide the working implementation
+* of the locks anyway, and libthr locks are fine.
 */
wlock_acquire(rtld_phdr_lock, [0]);
wlock_acquire(rtld_bind_lock, [1]);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312590 - in stable/10/lib/libc: include stdlib

2017-01-21 Thread Konstantin Belousov
Author: kib
Date: Sat Jan 21 12:30:07 2017
New Revision: 312590
URL: https://svnweb.freebsd.org/changeset/base/312590

Log:
  MFC r311651:
  Export __cxa_thread_atexit_impl as an alias for __cxa_thread_atexit.

Added:
  stable/10/lib/libc/stdlib/cxa_thread_atexit_impl.c
 - copied unchanged from r311651, 
head/lib/libc/stdlib/cxa_thread_atexit_impl.c
Modified:
  stable/10/lib/libc/include/libc_private.h
  stable/10/lib/libc/stdlib/Makefile.inc
  stable/10/lib/libc/stdlib/Symbol.map
  stable/10/lib/libc/stdlib/cxa_thread_atexit.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/include/libc_private.h
==
--- stable/10/lib/libc/include/libc_private.h   Sat Jan 21 11:47:30 2017
(r312589)
+++ stable/10/lib/libc/include/libc_private.h   Sat Jan 21 12:30:07 2017
(r312590)
@@ -268,6 +268,8 @@ void _malloc_thread_cleanup(void);
  * thread is exiting, so its thread-local dtors should be called.
  */
 void __cxa_thread_call_dtors(void);
+int __cxa_thread_atexit_hidden(void (*dtor_func)(void *), void *obj,
+void *dso_symbol) __hidden;
 
 /*
  * These functions are used by the threading libraries in order to protect

Modified: stable/10/lib/libc/stdlib/Makefile.inc
==
--- stable/10/lib/libc/stdlib/Makefile.inc  Sat Jan 21 11:47:30 2017
(r312589)
+++ stable/10/lib/libc/stdlib/Makefile.inc  Sat Jan 21 12:30:07 2017
(r312590)
@@ -5,7 +5,9 @@
 .PATH: ${.CURDIR}/${LIBC_ARCH}/stdlib ${.CURDIR}/stdlib
 
 MISRCS+=_Exit.c a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
-   bsearch.c cxa_thread_atexit.c div.c exit.c getenv.c getopt.c 
getopt_long.c \
+   bsearch.c \
+   cxa_thread_atexit.c cxa_thread_atexit_impl.c \
+   div.c exit.c getenv.c getopt.c getopt_long.c \
getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c \
insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \
merge.c ptsname.c qsort.c qsort_r.c quick_exit.c radixsort.c rand.c \

Modified: stable/10/lib/libc/stdlib/Symbol.map
==
--- stable/10/lib/libc/stdlib/Symbol.mapSat Jan 21 11:47:30 2017
(r312589)
+++ stable/10/lib/libc/stdlib/Symbol.mapSat Jan 21 12:30:07 2017
(r312590)
@@ -106,6 +106,7 @@ FBSD_1.3 {
 
 FBSD_1.5 {
__cxa_thread_atexit;
+   __cxa_thread_atexit_impl;
 };
 
 FBSDprivate_1.0 {

Modified: stable/10/lib/libc/stdlib/cxa_thread_atexit.c
==
--- stable/10/lib/libc/stdlib/cxa_thread_atexit.c   Sat Jan 21 11:47:30 
2017(r312589)
+++ stable/10/lib/libc/stdlib/cxa_thread_atexit.c   Sat Jan 21 12:30:07 
2017(r312590)
@@ -1,7 +1,10 @@
 /*-
- * Copyright (c) 2016 Mahdi Mokhtari <mokh...@gmail.com>
+ * Copyright (c) 2017 The FreeBSD Foundation
  * All rights reserved.
  *
+ * Portions of this software were 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:
@@ -27,114 +30,11 @@
 #include 
 __FBSDID("$FreeBSD$");
 
-#include 
-#include "namespace.h"
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include "un-namespace.h"
 #include "libc_private.h"
 
-/*
- * C++11 introduces the thread_local scope (like __thread with some
- * additions).  As a key-feature it should support non-trivial
- * destructors, registered with __cxa_thread_atexit() to be executed
- * at the thread termination.
- *
- * The implemention keeps a _Thread_local list of destructors per each
- * thread, and calls __cxa_thread_call_dtors() on each thread's exit
- * to do cleanup.  For a thread calling exit(3), in particular, for
- * the initial thread returning from main(), we call
- * __cxa_thread_call_dtors() inside exit().
- *
- * It could be possible that a dynamically loaded library, use
- * thread_local variable but is dlclose()'d before thread exit.  The
- * destructor of this variable will then try to access the address,
- * for calling it but it's unloaded, so it'll crash.  We're using
- * __elf_phdr_match_addr() to detect and prevent such cases and so
- * prevent the crash.
- */
-
-#define CXA_DTORS_ITERATIONS 4
-
-struct cxa_thread_dtor {
-   void *obj;
-   void (*func)(void *);
-   void *dso;
-   LIST_ENTRY(cxa_thread_dtor) entry;
-};
-static _Thread_local LIST_HEAD(dtor_list, cxa_thread_dtor) dtors =
-LIST_HEAD_INITIALIZER(dtors);
-
 int
 __cxa_thread_atexit(void (*dtor_func)(void *), void *obj, void *dso_symbol)
 {
-   struct cxa_thread_dtor *new_dtor;
-
-   new_dtor = malloc(sizeof(*new_dtor));
-  

svn commit: r312402 - stable/10/libexec/rtld-elf

2017-01-18 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 19 06:48:03 2017
New Revision: 312402
URL: https://svnweb.freebsd.org/changeset/base/312402

Log:
  MFC r311984:
  For the main binary, postpone enforcing relro read-only protection
  until copy relocations are done.

Modified:
  stable/10/libexec/rtld-elf/rtld.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld.c
==
--- stable/10/libexec/rtld-elf/rtld.c   Thu Jan 19 06:44:27 2017
(r312401)
+++ stable/10/libexec/rtld-elf/rtld.c   Thu Jan 19 06:48:03 2017
(r312402)
@@ -104,6 +104,7 @@ static int load_needed_objects(Obj_Entry
 static int load_preload_objects(void);
 static Obj_Entry *load_object(const char *, int fd, const Obj_Entry *, int);
 static void map_stacks_exec(RtldLockState *);
+static int obj_enforce_relro(Obj_Entry *);
 static Obj_Entry *obj_from_addr(const void *);
 static void objlist_call_fini(Objlist *, Obj_Entry *, RtldLockState *);
 static void objlist_call_init(Objlist *, RtldLockState *);
@@ -609,6 +610,10 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_
 if (do_copy_relocations(obj_main) == -1)
rtld_die();
 
+dbg("enforcing main obj relro");
+if (obj_enforce_relro(obj_main) == -1)
+   rtld_die();
+
 if (getenv(LD_ "DUMP_REL_POST") != NULL) {
dump_relocations(obj_main);
exit (0);
@@ -2691,14 +2696,8 @@ relocate_object(Obj_Entry *obj, bool bin
reloc_non_plt(obj, rtldobj, flags | SYMLOOK_IFUNC, lockstate))
return (-1);
 
-   if (obj->relro_size > 0) {
-   if (mprotect(obj->relro_page, obj->relro_size,
-   PROT_READ) == -1) {
-   _rtld_error("%s: Cannot enforce relro protection: %s",
-   obj->path, rtld_strerror(errno));
-   return (-1);
-   }
-   }
+   if (!obj->mainprog && obj_enforce_relro(obj) == -1)
+   return (-1);
 
/*
 * Set up the magic number and version in the Obj_Entry.  These
@@ -4986,6 +4985,19 @@ _rtld_is_dlopened(void *arg)
return (res);
 }
 
+int
+obj_enforce_relro(Obj_Entry *obj)
+{
+
+   if (obj->relro_size > 0 && mprotect(obj->relro_page, obj->relro_size,
+   PROT_READ) == -1) {
+   _rtld_error("%s: Cannot enforce relro protection: %s",
+   obj->path, rtld_strerror(errno));
+   return (-1);
+   }
+   return (0);
+}
+
 static void
 map_stacks_exec(RtldLockState *lockstate)
 {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312340 - stable/10/libexec/rtld-elf

2017-01-17 Thread Konstantin Belousov
Author: kib
Date: Tue Jan 17 10:34:31 2017
New Revision: 312340
URL: https://svnweb.freebsd.org/changeset/base/312340

Log:
  MFC r311879:
  Use ANSI C definitions, update comment.

Modified:
  stable/10/libexec/rtld-elf/rtld_lock.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld_lock.c
==
--- stable/10/libexec/rtld-elf/rtld_lock.c  Tue Jan 17 10:32:27 2017
(r312339)
+++ stable/10/libexec/rtld-elf/rtld_lock.c  Tue Jan 17 10:34:31 2017
(r312340)
@@ -38,8 +38,8 @@
  * In this algorithm the lock is a single word.  Its low-order bit is
  * set when a writer holds the lock.  The remaining high-order bits
  * contain a count of readers desiring the lock.  The algorithm requires
- * atomic "compare_and_store" and "add" operations, which we implement
- * using assembly language sequences in "rtld_start.S".
+ * atomic "compare_and_store" and "add" operations, which we take
+ * from machine/atomic.h.
  */
 
 #include 
@@ -67,7 +67,7 @@ static sigset_t fullsigmask, oldsigmask;
 static int thread_flag;
 
 static void *
-def_lock_create()
+def_lock_create(void)
 {
 void *base;
 char *p;
@@ -269,7 +269,7 @@ lock_restart_for_upgrade(RtldLockState *
 }
 
 void
-lockdflt_init()
+lockdflt_init(void)
 {
 int i;
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312286 - stable/10/sys/fs/pseudofs

2017-01-16 Thread Konstantin Belousov
Author: kib
Date: Mon Jan 16 12:17:35 2017
New Revision: 312286
URL: https://svnweb.freebsd.org/changeset/base/312286

Log:
  MFC r311815:
  Forcibly remove the cached items from pseudofs vncache on module unload.

Modified:
  stable/10/sys/fs/pseudofs/pseudofs_vncache.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/pseudofs/pseudofs_vncache.c
==
--- stable/10/sys/fs/pseudofs/pseudofs_vncache.cMon Jan 16 12:13:49 
2017(r312285)
+++ stable/10/sys/fs/pseudofs/pseudofs_vncache.cMon Jan 16 12:17:35 
2017(r312286)
@@ -51,6 +51,7 @@ static struct mtx pfs_vncache_mutex;
 static struct pfs_vdata *pfs_vncache;
 static eventhandler_tag pfs_exit_tag;
 static void pfs_exit(void *arg, struct proc *p);
+static void pfs_purge_locked(struct pfs_node *pn, bool force);
 
 static SYSCTL_NODE(_vfs_pfs, OID_AUTO, vncache, CTLFLAG_RW, 0,
 "pseudofs vnode cache");
@@ -97,6 +98,9 @@ pfs_vncache_unload(void)
 {
 
EVENTHANDLER_DEREGISTER(process_exit, pfs_exit_tag);
+   mtx_lock(_vncache_mutex);
+   pfs_purge_locked(NULL, true);
+   mtx_unlock(_vncache_mutex);
KASSERT(pfs_vncache_entries == 0,
("%d vncache entries remaining", pfs_vncache_entries));
mtx_destroy(_vncache_mutex);
@@ -272,7 +276,7 @@ pfs_vncache_free(struct vnode *vp)
  * used to implement the cache.
  */
 static void
-pfs_purge_locked(struct pfs_node *pn)
+pfs_purge_locked(struct pfs_node *pn, bool force)
 {
struct pfs_vdata *pvd;
struct vnode *vnp;
@@ -280,7 +284,8 @@ pfs_purge_locked(struct pfs_node *pn)
mtx_assert(_vncache_mutex, MA_OWNED);
pvd = pfs_vncache;
while (pvd != NULL) {
-   if (pvd->pvd_dead || (pn != NULL && pvd->pvd_pn == pn)) {
+   if (force || pvd->pvd_dead ||
+   (pn != NULL && pvd->pvd_pn == pn)) {
vnp = pvd->pvd_vnode;
vhold(vnp);
mtx_unlock(_vncache_mutex);
@@ -301,7 +306,7 @@ pfs_purge(struct pfs_node *pn)
 {
 
mtx_lock(_vncache_mutex);
-   pfs_purge_locked(pn);
+   pfs_purge_locked(pn, false);
mtx_unlock(_vncache_mutex);
 }
 
@@ -321,6 +326,6 @@ pfs_exit(void *arg, struct proc *p)
if (pvd->pvd_pid == p->p_pid)
dead = pvd->pvd_dead = 1;
if (dead)
-   pfs_purge_locked(NULL);
+   pfs_purge_locked(NULL, false);
mtx_unlock(_vncache_mutex);
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312285 - stable/10/lib/libprocstat

2017-01-16 Thread Konstantin Belousov
Author: kib
Date: Mon Jan 16 12:13:49 2017
New Revision: 312285
URL: https://svnweb.freebsd.org/changeset/base/312285

Log:
  MFC r311781:
  Use standard Versions.def for libprocstat.

Deleted:
  stable/10/lib/libprocstat/Versions.def
Modified:
  stable/10/lib/libprocstat/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libprocstat/Makefile
==
--- stable/10/lib/libprocstat/Makefile  Mon Jan 16 12:05:00 2017
(r312284)
+++ stable/10/lib/libprocstat/Makefile  Mon Jan 16 12:13:49 2017
(r312285)
@@ -12,7 +12,7 @@ SRCS= cd9660.c\
smbfs.c \
udf.c
 
-VERSION_DEF=   ${.CURDIR}/Versions.def
+VERSION_DEF=   ${SRCTOP}/lib/libc/Versions.def
 SYMBOL_MAPS=   ${.CURDIR}/Symbol.map
 
 INCS=  libprocstat.h
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312284 - stable/10/lib/libprocstat

2017-01-16 Thread Konstantin Belousov
Author: kib
Date: Mon Jan 16 12:05:00 2017
New Revision: 312284
URL: https://svnweb.freebsd.org/changeset/base/312284

Log:
  MFC r311780:
  Use tab for indent.

Modified:
  stable/10/lib/libprocstat/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libprocstat/Makefile
==
--- stable/10/lib/libprocstat/Makefile  Mon Jan 16 11:40:53 2017
(r312283)
+++ stable/10/lib/libprocstat/Makefile  Mon Jan 16 12:05:00 2017
(r312284)
@@ -8,7 +8,7 @@ SRCS=   cd9660.c\
common_kvm.c\
core.c  \
libprocstat.c   \
-msdosfs.c  \
+   msdosfs.c   \
smbfs.c \
udf.c
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312171 - stable/10/sys/sys

2017-01-14 Thread Konstantin Belousov
Author: kib
Date: Sat Jan 14 11:27:11 2017
New Revision: 312171
URL: https://svnweb.freebsd.org/changeset/base/312171

Log:
  MFC r311646:
  Define _POSIX_PRIORITY_SCHEDULING as 0, to account for the kernel option.

Modified:
  stable/10/sys/sys/unistd.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/sys/unistd.h
==
--- stable/10/sys/sys/unistd.h  Sat Jan 14 11:16:10 2017(r312170)
+++ stable/10/sys/sys/unistd.h  Sat Jan 14 11:27:11 2017(r312171)
@@ -65,7 +65,7 @@
 #define_POSIX_MONOTONIC_CLOCK  200112L
 #define_POSIX_NO_TRUNC 1
 #define_POSIX_PRIORITIZED_IO   (-1)
-#define_POSIX_PRIORITY_SCHEDULING  200112L
+#define_POSIX_PRIORITY_SCHEDULING  0
 #define_POSIX_RAW_SOCKETS  200112L
 #define_POSIX_REALTIME_SIGNALS 200112L
 #define_POSIX_SEMAPHORES   200112L
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312069 - stable/10/sys/fs/tmpfs

2017-01-13 Thread Konstantin Belousov
Author: kib
Date: Fri Jan 13 12:47:44 2017
New Revision: 312069
URL: https://svnweb.freebsd.org/changeset/base/312069

Log:
  MFC r311525:
  Lock tmpfs node tn_status updates done under the shared vnode lock.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs.h
  stable/10/sys/fs/tmpfs/tmpfs_fifoops.c
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
  stable/10/sys/fs/tmpfs/tmpfs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs.h
==
--- stable/10/sys/fs/tmpfs/tmpfs.h  Fri Jan 13 12:45:54 2017
(r312068)
+++ stable/10/sys/fs/tmpfs/tmpfs.h  Fri Jan 13 12:47:44 2017
(r312069)
@@ -199,7 +199,9 @@ struct tmpfs_node {
 * allocated for it or it has been reclaimed). */
struct vnode *  tn_vnode;
 
-   /* interlock to protect tn_vpstate */
+   /* Interlock to protect tn_vpstate, and tn_status under shared
+* vnode lock.
+*/
struct mtx  tn_interlock;
 
/* Identify if current node has vnode assiocate with
@@ -420,6 +422,7 @@ int tmpfs_chtimes(struct vnode *, struct
 void   tmpfs_itimes(struct vnode *, const struct timespec *,
const struct timespec *);
 
+void   tmpfs_set_status(struct tmpfs_node *node, int status);
 void   tmpfs_update(struct vnode *);
 inttmpfs_truncate(struct vnode *, off_t);
 

Modified: stable/10/sys/fs/tmpfs/tmpfs_fifoops.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_fifoops.c  Fri Jan 13 12:45:54 2017
(r312068)
+++ stable/10/sys/fs/tmpfs/tmpfs_fifoops.c  Fri Jan 13 12:47:44 2017
(r312069)
@@ -52,11 +52,11 @@ static int
 tmpfs_fifo_close(struct vop_close_args *v)
 {
struct tmpfs_node *node;
-   node = VP_TO_TMPFS_NODE(v->a_vp);
-   node->tn_status |= TMPFS_NODE_ACCESSED;
 
+   node = VP_TO_TMPFS_NODE(v->a_vp);
+   tmpfs_set_status(node, TMPFS_NODE_ACCESSED);
tmpfs_update(v->a_vp);
-   return fifo_specops.vop_close(v);
+   return (fifo_specops.vop_close(v));
 }
 
 /*

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Fri Jan 13 12:45:54 2017
(r312068)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Fri Jan 13 12:47:44 2017
(r312069)
@@ -1092,9 +1092,9 @@ tmpfs_dir_getdotdent(struct tmpfs_node *
else
error = uiomove(, dent.d_reclen, uio);
 
-   node->tn_status |= TMPFS_NODE_ACCESSED;
+   tmpfs_set_status(node, TMPFS_NODE_ACCESSED);
 
-   return error;
+   return (error);
 }
 
 /*
@@ -1137,9 +1137,9 @@ tmpfs_dir_getdotdotdent(struct tmpfs_nod
else
error = uiomove(, dent.d_reclen, uio);
 
-   node->tn_status |= TMPFS_NODE_ACCESSED;
+   tmpfs_set_status(node, TMPFS_NODE_ACCESSED);
 
-   return error;
+   return (error);
 }
 
 /*
@@ -1282,7 +1282,7 @@ tmpfs_dir_getdents(struct tmpfs_node *no
node->tn_dir.tn_readdir_lastn = off;
node->tn_dir.tn_readdir_lastp = de;
 
-   node->tn_status |= TMPFS_NODE_ACCESSED;
+   tmpfs_set_status(node, TMPFS_NODE_ACCESSED);
return error;
 }
 
@@ -1733,15 +1733,25 @@ tmpfs_chtimes(struct vnode *vp, struct v
return (0);
 }
 
-/* Sync timestamps */
 void
-tmpfs_itimes(struct vnode *vp, const struct timespec *acc,
+tmpfs_set_status(struct tmpfs_node *node, int status)
+{
+
+   if ((node->tn_status & status) == status)
+   return;
+   TMPFS_NODE_LOCK(node);
+   node->tn_status |= status;
+   TMPFS_NODE_UNLOCK(node);
+}
+
+/* Sync timestamps */
+static void
+tmpfs_itimes_locked(struct tmpfs_node *node, const struct timespec *acc,
 const struct timespec *mod)
 {
-   struct tmpfs_node *node;
struct timespec now;
 
-   node = VP_TO_TMPFS_NODE(vp);
+   TMPFS_ASSERT_LOCKED(node);
 
if ((node->tn_status & (TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
TMPFS_NODE_CHANGED)) == 0)
@@ -1758,11 +1768,25 @@ tmpfs_itimes(struct vnode *vp, const str
mod = 
node->tn_mtime = *mod;
}
-   if (node->tn_status & TMPFS_NODE_CHANGED) {
+   if (node->tn_status & TMPFS_NODE_CHANGED)
node->tn_ctime = now;
-   }
-   node->tn_status &=
-   ~(TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED | TMPFS_NODE_CHANGED);
+   node->tn_status &= ~(TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
+   TMPFS_NODE_CHANGED);
+}
+
+void
+tmpfs_itimes(struct vnode *vp, const struct timespec *acc,
+const struct timespec *mod)
+{
+   struct tmpfs_node *node;
+
+   ASSERT_VOP_LOCKED(vp, "tmpfs_itimes");
+   node = VP_TO_TMPFS_NODE(vp);
+
+   TMPFS_NODE_LOCK(node);
+   tmpfs_itimes_locked(node, acc, mod);
+   TMPFS_NODE_UNLOCK(node);
+
 }
 
 void
@@ -1794,14 

svn commit: r312068 - stable/10/sys/fs/tmpfs

2017-01-13 Thread Konstantin Belousov
Author: kib
Date: Fri Jan 13 12:45:54 2017
New Revision: 312068
URL: https://svnweb.freebsd.org/changeset/base/312068

Log:
  MFC r311524:
  Use vnode lock assertion expression, assert exclusive ownership.

Modified:
  stable/10/sys/fs/tmpfs/tmpfs_subr.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/tmpfs/tmpfs_subr.c
==
--- stable/10/sys/fs/tmpfs/tmpfs_subr.c Fri Jan 13 12:44:52 2017
(r312067)
+++ stable/10/sys/fs/tmpfs/tmpfs_subr.c Fri Jan 13 12:45:54 2017
(r312068)
@@ -1458,7 +1458,7 @@ tmpfs_chflags(struct vnode *vp, u_long f
int error;
struct tmpfs_node *node;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chflags");
 
node = VP_TO_TMPFS_NODE(vp);
 
@@ -1498,9 +1498,9 @@ tmpfs_chflags(struct vnode *vp, u_long f
node->tn_flags = flags;
node->tn_status |= TMPFS_NODE_CHANGED;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chflags2");
 
-   return 0;
+   return (0);
 }
 
 /*
@@ -1514,7 +1514,7 @@ tmpfs_chmod(struct vnode *vp, mode_t mod
int error;
struct tmpfs_node *node;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chmod");
 
node = VP_TO_TMPFS_NODE(vp);
 
@@ -1554,9 +1554,9 @@ tmpfs_chmod(struct vnode *vp, mode_t mod
 
node->tn_status |= TMPFS_NODE_CHANGED;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chmod2");
 
-   return 0;
+   return (0);
 }
 
 /*
@@ -1575,7 +1575,7 @@ tmpfs_chown(struct vnode *vp, uid_t uid,
uid_t ouid;
gid_t ogid;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chown");
 
node = VP_TO_TMPFS_NODE(vp);
 
@@ -1625,9 +1625,9 @@ tmpfs_chown(struct vnode *vp, uid_t uid,
node->tn_mode &= ~(S_ISUID | S_ISGID);
}
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chown2");
 
-   return 0;
+   return (0);
 }
 
 /*
@@ -1642,7 +1642,7 @@ tmpfs_chsize(struct vnode *vp, u_quad_t 
int error;
struct tmpfs_node *node;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chsize");
 
node = VP_TO_TMPFS_NODE(vp);
 
@@ -1680,9 +1680,9 @@ tmpfs_chsize(struct vnode *vp, u_quad_t 
/* tmpfs_truncate will raise the NOTE_EXTEND and NOTE_ATTRIB kevents
 * for us, as will update tn_status; no need to do that here. */
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chsize2");
 
-   return error;
+   return (error);
 }
 
 /*
@@ -1697,7 +1697,7 @@ tmpfs_chtimes(struct vnode *vp, struct v
int error;
struct tmpfs_node *node;
 
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chtimes");
 
node = VP_TO_TMPFS_NODE(vp);
 
@@ -1728,9 +1728,9 @@ tmpfs_chtimes(struct vnode *vp, struct v
if (vap->va_birthtime.tv_nsec != VNOVAL &&
vap->va_birthtime.tv_nsec != VNOVAL)
node->tn_birthtime = vap->va_birthtime;
-   MPASS(VOP_ISLOCKED(vp));
+   ASSERT_VOP_ELOCKED(vp, "chtimes2");
 
-   return 0;
+   return (0);
 }
 
 /* Sync timestamps */
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r311959 - in stable/10/sys: compat/freebsd32 kern

2017-01-11 Thread Konstantin Belousov
Author: kib
Date: Thu Jan 12 01:20:51 2017
New Revision: 311959
URL: https://svnweb.freebsd.org/changeset/base/311959

Log:
  MFC r311447:
  Some style fixes for getfstat(2)-related code.

Modified:
  stable/10/sys/compat/freebsd32/freebsd32_misc.c
  stable/10/sys/kern/vfs_syscalls.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/compat/freebsd32/freebsd32_misc.c
==
--- stable/10/sys/compat/freebsd32/freebsd32_misc.c Thu Jan 12 01:13:05 
2017(r311958)
+++ stable/10/sys/compat/freebsd32/freebsd32_misc.c Thu Jan 12 01:20:51 
2017(r311959)
@@ -244,7 +244,8 @@ copy_statfs(struct statfs *in, struct st
 
 #ifdef COMPAT_FREEBSD4
 int
-freebsd4_freebsd32_getfsstat(struct thread *td, struct 
freebsd4_freebsd32_getfsstat_args *uap)
+freebsd4_freebsd32_getfsstat(struct thread *td,
+struct freebsd4_freebsd32_getfsstat_args *uap)
 {
struct statfs *buf, *sp;
struct statfs32 stat32;

Modified: stable/10/sys/kern/vfs_syscalls.c
==
--- stable/10/sys/kern/vfs_syscalls.c   Thu Jan 12 01:13:05 2017
(r311958)
+++ stable/10/sys/kern/vfs_syscalls.c   Thu Jan 12 01:20:51 2017
(r311959)
@@ -464,7 +464,7 @@ kern_getfsstat(struct thread *td, struct
nmp = TAILQ_NEXT(mp, mnt_list);
continue;
}
-   if (sfsp && count < maxcount) {
+   if (sfsp != NULL && count < maxcount) {
sp = >mnt_stat;
/*
 * Set these in case the underlying filesystem
@@ -509,7 +509,7 @@ kern_getfsstat(struct thread *td, struct
vfs_unbusy(mp);
}
mtx_unlock(_mtx);
-   if (sfsp && count > maxcount)
+   if (sfsp != NULL && count > maxcount)
td->td_retval[0] = maxcount;
else
td->td_retval[0] = count;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r311779 - stable/10/sys/kern

2017-01-09 Thread Konstantin Belousov
Author: kib
Date: Mon Jan  9 10:31:39 2017
New Revision: 311779
URL: https://svnweb.freebsd.org/changeset/base/311779

Log:
  MFC r33:
  There is no need to use temporary statfs buffer for fsid obliteration
  and prison enforcement.  Do it on the caller buffer directly.

Modified:
  stable/10/sys/kern/vfs_syscalls.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_syscalls.c
==
--- stable/10/sys/kern/vfs_syscalls.c   Mon Jan  9 10:30:24 2017
(r311778)
+++ stable/10/sys/kern/vfs_syscalls.c   Mon Jan  9 10:31:39 2017
(r311779)
@@ -259,7 +259,7 @@ statfs_scale_blocks(struct statfs *sf, l
 static int
 kern_do_statfs(struct thread *td, struct mount *mp, struct statfs *buf)
 {
-   struct statfs *sp, sb;
+   struct statfs *sp;
int error;
 
if (mp == NULL)
@@ -283,13 +283,11 @@ kern_do_statfs(struct thread *td, struct
error = VFS_STATFS(mp, sp);
if (error != 0)
goto out;
+   *buf = *sp;
if (priv_check(td, PRIV_VFS_GENERATION)) {
-   bcopy(sp, , sizeof(sb));
-   sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
-   prison_enforce_statfs(td->td_ucred, mp, );
-   sp = 
+   buf->f_fsid.val[0] = buf->f_fsid.val[1] = 0;
+   prison_enforce_statfs(td->td_ucred, mp, buf);
}
-   *buf = *sp;
 out:
vfs_unbusy(mp);
return (error);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r311778 - stable/10/sys/kern

2017-01-09 Thread Konstantin Belousov
Author: kib
Date: Mon Jan  9 10:30:24 2017
New Revision: 311778
URL: https://svnweb.freebsd.org/changeset/base/311778

Log:
  MFC r31:
  Style.

Modified:
  stable/10/sys/kern/vfs_syscalls.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_syscalls.c
==
--- stable/10/sys/kern/vfs_syscalls.c   Mon Jan  9 10:29:13 2017
(r311777)
+++ stable/10/sys/kern/vfs_syscalls.c   Mon Jan  9 10:30:24 2017
(r311778)
@@ -387,7 +387,7 @@ kern_fstatfs(struct thread *td, int fd, 
AUDIT_ARG_VNODE1(vp);
 #endif
mp = vp->v_mount;
-   if (mp)
+   if (mp != NULL)
vfs_ref(mp);
VOP_UNLOCK(vp, 0);
fdrop(fp, td);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r311777 - stable/10/sys/kern

2017-01-09 Thread Konstantin Belousov
Author: kib
Date: Mon Jan  9 10:29:13 2017
New Revision: 311777
URL: https://svnweb.freebsd.org/changeset/base/311777

Log:
  MFC r311108:
  Move common code from kern_statfs() and kern_fstatfs() into a new helper.

Modified:
  stable/10/sys/kern/vfs_syscalls.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_syscalls.c
==
--- stable/10/sys/kern/vfs_syscalls.c   Mon Jan  9 10:26:02 2017
(r311776)
+++ stable/10/sys/kern/vfs_syscalls.c   Mon Jan  9 10:29:13 2017
(r311777)
@@ -256,6 +256,45 @@ statfs_scale_blocks(struct statfs *sf, l
sf->f_bavail >>= shift;
 }
 
+static int
+kern_do_statfs(struct thread *td, struct mount *mp, struct statfs *buf)
+{
+   struct statfs *sp, sb;
+   int error;
+
+   if (mp == NULL)
+   return (EBADF);
+   error = vfs_busy(mp, 0);
+   vfs_rel(mp);
+   if (error != 0)
+   return (error);
+#ifdef MAC
+   error = mac_mount_check_stat(td->td_ucred, mp);
+   if (error != 0)
+   goto out;
+#endif
+   /*
+* Set these in case the underlying filesystem fails to do so.
+*/
+   sp = >mnt_stat;
+   sp->f_version = STATFS_VERSION;
+   sp->f_namemax = NAME_MAX;
+   sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
+   error = VFS_STATFS(mp, sp);
+   if (error != 0)
+   goto out;
+   if (priv_check(td, PRIV_VFS_GENERATION)) {
+   bcopy(sp, , sizeof(sb));
+   sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
+   prison_enforce_statfs(td->td_ucred, mp, );
+   sp = 
+   }
+   *buf = *sp;
+out:
+   vfs_unbusy(mp);
+   return (error);
+}
+
 /*
  * Get filesystem statistics.
  */
@@ -287,7 +326,6 @@ kern_statfs(struct thread *td, char *pat
 struct statfs *buf)
 {
struct mount *mp;
-   struct statfs *sp, sb;
struct nameidata nd;
int error;
 
@@ -300,35 +338,7 @@ kern_statfs(struct thread *td, char *pat
vfs_ref(mp);
NDFREE(, NDF_ONLY_PNBUF);
vput(nd.ni_vp);
-   error = vfs_busy(mp, 0);
-   vfs_rel(mp);
-   if (error != 0)
-   return (error);
-#ifdef MAC
-   error = mac_mount_check_stat(td->td_ucred, mp);
-   if (error != 0)
-   goto out;
-#endif
-   /*
-* Set these in case the underlying filesystem fails to do so.
-*/
-   sp = >mnt_stat;
-   sp->f_version = STATFS_VERSION;
-   sp->f_namemax = NAME_MAX;
-   sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
-   error = VFS_STATFS(mp, sp);
-   if (error != 0)
-   goto out;
-   if (priv_check(td, PRIV_VFS_GENERATION)) {
-   bcopy(sp, , sizeof(sb));
-   sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
-   prison_enforce_statfs(td->td_ucred, mp, );
-   sp = 
-   }
-   *buf = *sp;
-out:
-   vfs_unbusy(mp);
-   return (error);
+   return (kern_do_statfs(td, mp, buf));
 }
 
 /*
@@ -362,7 +372,6 @@ kern_fstatfs(struct thread *td, int fd, 
 {
struct file *fp;
struct mount *mp;
-   struct statfs *sp, sb;
struct vnode *vp;
cap_rights_t rights;
int error;
@@ -382,40 +391,7 @@ kern_fstatfs(struct thread *td, int fd, 
vfs_ref(mp);
VOP_UNLOCK(vp, 0);
fdrop(fp, td);
-   if (mp == NULL) {
-   error = EBADF;
-   goto out;
-   }
-   error = vfs_busy(mp, 0);
-   vfs_rel(mp);
-   if (error != 0)
-   return (error);
-#ifdef MAC
-   error = mac_mount_check_stat(td->td_ucred, mp);
-   if (error != 0)
-   goto out;
-#endif
-   /*
-* Set these in case the underlying filesystem fails to do so.
-*/
-   sp = >mnt_stat;
-   sp->f_version = STATFS_VERSION;
-   sp->f_namemax = NAME_MAX;
-   sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
-   error = VFS_STATFS(mp, sp);
-   if (error != 0)
-   goto out;
-   if (priv_check(td, PRIV_VFS_GENERATION)) {
-   bcopy(sp, , sizeof(sb));
-   sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
-   prison_enforce_statfs(td->td_ucred, mp, );
-   sp = 
-   }
-   *buf = *sp;
-out:
-   if (mp)
-   vfs_unbusy(mp);
-   return (error);
+   return (kern_do_statfs(td, mp, buf));
 }
 
 /*
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r311773 - stable/10/sys/kern

2017-01-09 Thread Konstantin Belousov
Author: kib
Date: Mon Jan  9 10:18:34 2017
New Revision: 311773
URL: https://svnweb.freebsd.org/changeset/base/311773

Log:
  MFC r310615:
  Change knlist_destroy() to assertion.

Modified:
  stable/10/sys/kern/kern_event.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_event.c
==
--- stable/10/sys/kern/kern_event.c Mon Jan  9 10:13:53 2017
(r311772)
+++ stable/10/sys/kern/kern_event.c Mon Jan  9 10:18:34 2017
(r311773)
@@ -2177,17 +2177,8 @@ void
 knlist_destroy(struct knlist *knl)
 {
 
-#ifdef INVARIANTS
-   /*
-* if we run across this error, we need to find the offending
-* driver and have it call knlist_clear or knlist_delete.
-*/
-   if (!SLIST_EMPTY(>kl_list))
-   printf("WARNING: destroying knlist w/ knotes on it!\n");
-#endif
-
-   knl->kl_lockarg = knl->kl_lock = knl->kl_unlock = NULL;
-   SLIST_INIT(>kl_list);
+   KASSERT(KNLIST_EMPTY(knl),
+   ("destroying knlist %p with knotes on it", knl));
 }
 
 /*
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


  1   2   3   4   >