svn commit: r352832 - head/sys/powerpc/booke

2019-09-27 Thread Justin Hibbits
Author: jhibbits
Date: Sat Sep 28 03:33:07 2019
New Revision: 352832
URL: https://svnweb.freebsd.org/changeset/base/352832

Log:
  powerpc/booke64: Align initial stack setting to match that of aim64's
  
  Clang9/LLD9 appears to get quite confused with the instruction stream used
  to obtain the tmpstack pointer, almost as though it thinks this is a C
  function, so tries to optimize it.  Since the AIM64 method doesn't use the
  TOC to obtain the tmpstack, just follow that model, and lld won't get
  confused.
  
  Reported by:  bdragon
  MFC after:2 weeks

Modified:
  head/sys/powerpc/booke/locore.S

Modified: head/sys/powerpc/booke/locore.S
==
--- head/sys/powerpc/booke/locore.S Sat Sep 28 02:49:46 2019
(r352831)
+++ head/sys/powerpc/booke/locore.S Sat Sep 28 03:33:07 2019
(r352832)
@@ -298,16 +298,18 @@ done_mapping:
ld  %r1,0(%r2)
add %r2,%r1,%r2
mtspr   SPR_SPRG8, %r2
+   nop
 
/* Get load offset */
ld  %r31,-0x8000(%r2) /* First TOC entry is TOC base */
subf%r31,%r31,%r2   /* Subtract from real TOC base to get base */
 
/* Set up the stack pointer */
-   addis   %r1,%r2,TOC_REF(tmpstack)@ha
-   ld  %r1,TOC_REF(tmpstack)@l(%r1)
-   addi%r1,%r1,TMPSTACKSZ-96
-   add %r1,%r1,%r31
+   bl  1f
+   .llong  tmpstack + TMPSTACKSZ - 96 - .
+1: mflr%r3
+   ld  %r1,0(%r3)
+   add %r1,%r1,%r3
bl  1f
.llong _DYNAMIC-.
 1: mflr%r3
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352831 - head/sys/contrib/ncsw/Peripherals/BM

2019-09-27 Thread Justin Hibbits
Author: jhibbits
Date: Sat Sep 28 02:49:46 2019
New Revision: 352831
URL: https://svnweb.freebsd.org/changeset/base/352831

Log:
  dpaa(4): Fix memcpy size for threshold copy in NCSW contrib
  
  On 64-bit platforms uintptr_t makes the copy twice as large as it should be.
  This code isn't actually used in FreeBSD, since it's for guest mode only,
  not hypervisor mode, but fixing it for completeness sake.
  
  Reported by:  bdragon (clang9 build)

Modified:
  head/sys/contrib/ncsw/Peripherals/BM/bm.c

Modified: head/sys/contrib/ncsw/Peripherals/BM/bm.c
==
--- head/sys/contrib/ncsw/Peripherals/BM/bm.c   Sat Sep 28 02:15:23 2019
(r352830)
+++ head/sys/contrib/ncsw/Peripherals/BM/bm.c   Sat Sep 28 02:49:46 2019
(r352831)
@@ -258,7 +258,7 @@ t_Error BmSetPoolThresholds(t_Handle h_Bm, uint8_t bpi
 
 memset(, 0, sizeof(t_BmIpcMsg));
 ipcPoolThresh.bpid  = bpid;
-memcpy(ipcPoolThresh.thresholds, thresholds, sizeof(uintptr_t) * 
MAX_DEPLETION_THRESHOLDS);
+memcpy(ipcPoolThresh.thresholds, thresholds, sizeof(uint32_t) * 
MAX_DEPLETION_THRESHOLDS);
 msg.msgId   = BM_SET_POOL_THRESH;
 memcpy(msg.msgBody, , sizeof(t_BmIpcPoolThreshParams));
 if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352829 - head/sys/kern

2019-09-27 Thread Mark Johnston
Author: markj
Date: Sat Sep 28 01:42:59 2019
New Revision: 352829
URL: https://svnweb.freebsd.org/changeset/base/352829

Log:
  Fix some problems with the SPARSE_MAPPING option in the kernel linker.
  
  - Ensure that the end of the mapping passed to vm_page_wire() is
page-aligned.  vm_page_wire() expects this.
  - Wire pages before reading data into them.
  - Apply protections specified in the segment descriptor using
vm_map_protect() once relocation processing is done.
  - On amd64, ensure that we load KLDs above KERNBASE, since they
are compiled with the "kernel" memory model by default.
  
  Reviewed by:  kib
  MFC after:2 weeks
  Sponsored by: Netflix
  Differential Revision:https://reviews.freebsd.org/D21756

Modified:
  head/sys/kern/link_elf.c

Modified: head/sys/kern/link_elf.c
==
--- head/sys/kern/link_elf.cSat Sep 28 01:31:33 2019(r352828)
+++ head/sys/kern/link_elf.cSat Sep 28 01:42:59 2019(r352829)
@@ -40,6 +40,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#ifdef SPARSE_MAPPING
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -419,7 +422,7 @@ link_elf_init(void* arg)
ef->address = 0;
 #endif
 #ifdef SPARSE_MAPPING
-   ef->object = 0;
+   ef->object = NULL;
 #endif
ef->dynamic = dp;
 
@@ -772,7 +775,7 @@ link_elf_link_preload(linker_class_t cls,
ef->modptr = modptr;
ef->address = *(caddr_t *)baseptr;
 #ifdef SPARSE_MAPPING
-   ef->object = 0;
+   ef->object = NULL;
 #endif
dp = (vm_offset_t)ef->address + *(vm_offset_t *)dynptr;
ef->dynamic = (Elf_Dyn *)dp;
@@ -826,7 +829,7 @@ link_elf_load_file(linker_class_t cls, const char* fil
struct nameidata nd;
struct thread* td = curthread;  /* XXX */
Elf_Ehdr *hdr;
-   caddr_t firstpage;
+   caddr_t firstpage, segbase;
int nbytes, i;
Elf_Phdr *phdr;
Elf_Phdr *phlimit;
@@ -993,47 +996,61 @@ link_elf_load_file(linker_class_t cls, const char* fil
error = ENOMEM;
goto out;
}
-   ef->address = (caddr_t) vm_map_min(kernel_map);
+#ifdef __amd64__
+   mapbase = (caddr_t)KERNBASE;
+#else
+   mapbase = (caddr_t)vm_map_min(kernel_map);
+#endif
+   /*
+* Mapping protections are downgraded after relocation processing.
+*/
error = vm_map_find(kernel_map, ef->object, 0,
-   (vm_offset_t *) >address, mapsize, 0, VMFS_OPTIMAL_SPACE,
+   (vm_offset_t *), mapsize, 0, VMFS_OPTIMAL_SPACE,
VM_PROT_ALL, VM_PROT_ALL, 0);
if (error != 0) {
vm_object_deallocate(ef->object);
-   ef->object = 0;
+   ef->object = NULL;
goto out;
}
 #else
-   ef->address = malloc(mapsize, M_LINKER, M_EXEC | M_WAITOK);
+   mapbase = malloc(mapsize, M_LINKER, M_EXEC | M_WAITOK);
 #endif
-   mapbase = ef->address;
+   ef->address = mapbase;
 
/*
 * Read the text and data sections and zero the bss.
 */
for (i = 0; i < nsegs; i++) {
-   caddr_t segbase = mapbase + segs[i]->p_vaddr - base_vaddr;
-   error = vn_rdwr(UIO_READ, nd.ni_vp,
-   segbase, segs[i]->p_filesz, segs[i]->p_offset,
-   UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
-   , td);
-   if (error != 0)
-   goto out;
-   bzero(segbase + segs[i]->p_filesz,
-   segs[i]->p_memsz - segs[i]->p_filesz);
+   segbase = mapbase + segs[i]->p_vaddr - base_vaddr;
 
 #ifdef SPARSE_MAPPING
/*
-* Wire down the pages
+* Consecutive segments may have different mapping permissions,
+* so be strict and verify that their mappings do not overlap.
 */
+   if (((vm_offset_t)segbase & PAGE_MASK) != 0) {
+   error = EINVAL;
+   goto out;
+   }
+
error = vm_map_wire(kernel_map,
-   (vm_offset_t) segbase,
-   (vm_offset_t) segbase + segs[i]->p_memsz,
-   VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES);
+   (vm_offset_t)segbase,
+   (vm_offset_t)segbase + round_page(segs[i]->p_memsz),
+   VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
if (error != KERN_SUCCESS) {
error = ENOMEM;
goto out;
}
 #endif
+
+   error = vn_rdwr(UIO_READ, nd.ni_vp,
+   segbase, segs[i]->p_filesz, segs[i]->p_offset,
+   UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
+   , td);
+   if (error != 0)
+   goto out;
+   bzero(segbase + 

Re: svn commit: r352795 - head/lib/libc/sys

2019-09-27 Thread Mateusz Guzik
On 9/27/19, Warner Losh  wrote:
> On Fri, Sep 27, 2019 at 2:38 PM Mateusz Guzik  wrote:
>
>> On 9/27/19, Konstantin Belousov  wrote:
>> > On Fri, Sep 27, 2019 at 08:32:20PM +0200, Mateusz Guzik wrote:
>> >> On 9/27/19, Warner Losh  wrote:
>> >> >   Document varadic args as int, since you can't have short varadic
>> args
>> >> > (they are
>> >> >   promoted to ints).
>> >> >
>> >> >   - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
>> >> >   - `openat` takes variadic args
>> >> >   - variadic args cannot be 16-bit, and indeed the code uses int
>> >> >   - the manpage currently kinda implies the argument is 16-bit by
>> >> > saying
>> >> > `mode_t`
>> >> >
>> >> But opengroup says it is mode_t. Perhaps it is mode_t which needs
>> >> to be changed?
>> >
>> > Yes, users must pass mode_t, and the man page is written for users.
>> > Implementation needs to be aware of the implicit promotion and handle
>> > it accordingly.
>> >
>> > In theory, mode_t might be wider than int.
>> >
>>
>> So I think the change should be reverted. Whatever workaround is being
>> in place in rust should remain for the current codebase.
>>
>
> Rust needs to understand that it's not C. It's mistake was assuming it was
> just like C and this is a case where the languages differ because C is so
> quirky.
>
>
>> If anyone is to fixed the problem they should bump mode_t to uint32_t,
>> to match Linux. This is ABI breakage, I don't know how that's handled.
>>
>
> That's not going to happen. And there's no need. It would cause more
> heartache than it's worth.
>
>

In isolation, sure. Someone(tm) should do a type comprehensive type
check against Linux. There are probably many cases where something
has a different size, but software hardcodes what happens to work on
Linux (instead of using the type documented by opengroup or whatever
else is applicable).

>> I have no interest in handling any of this, but the change committed
>> is definitely wrong.
>>
>
> I tend to agree, but the manual was/is incomplete. The arg *IS* promoted to
> an int, per normal C rules, so that part is right and there's no
> type-checking against truncation or the wrong type being used as would be
> the case if it weren't varadic (so don't pass a long here).
>

But the fact there is any need for promotion in the first place is only
an implementation wart.

> However, type purity aside, that's not how things are implemented. Open is
> expecting an int (as is openat):
>
> int
> open(const char *path, int flags, ...)
> {
> va_list ap;
> int mode;
>
> if ((flags & O_CREAT) != 0) {
> va_start(ap, flags);
> mode = va_arg(ap, int);
> va_end(ap);
> } else {
> mode = 0;
> }
> return (((int (*)(int, const char *, int, ...))
> __libc_interposing[INTERPOS_openat])(fd, path, flags, mode));
> }
>
> so the change, from that perspective, actually documents the interface (so
> isn't definitely wrong, and my guarded 'tend to agree'). So if you did
> change the type of mode_t, the above code might be wrong afterwards (hence
> my can of worms comment). And then we're passing it again through a varadic
> function pointer...
>
> So while POSIX says one thing, we implement something else. Should we
> document POSIX or what we implement? Or do we fix our implementation to
> match the docs? For all programs that don't pass in a 'long' or a pointer,
> the difference is zero, however.
>
> To be honest, though, quibbling over how it should be implemented aside, I
> think we should actually do the following:
>
> diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
> index a771461e2e49..aa912b797f74 100644
> --- a/lib/libc/sys/open.2
> +++ b/lib/libc/sys/open.2
> @@ -61,7 +61,7 @@ In this case
>  and
>  .Fn openat
>  require an additional argument
> -.Fa "int mode" ,
> +.Fa "mode_t mode" ,
>  and the file is created with mode
>  .Fa mode
>  as described in
> @@ -615,3 +615,8 @@ permits searches.
>  The present implementation of the
>  .Fa openat
>  checks the current permissions of directory instead.
> +.Pp
> +The
> +.Fa mode
> +argument is varadic and may result in different calling conventions
> +than might otherwise be expected.
>
> Is what I was thinking of committing instead. It's in the BUGS section, and
> is useful to know if you are debugging code that has this in the call path
> (since values may be on the stack instead of in registers, depending on the
> calling convention for the underlying architecture).
>

I think this is fine. I mostly object to telling people to pass int instead of
mode_t.

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


svn commit: r352826 - in head/sys: arm64/arm64 arm64/include riscv/include riscv/riscv

2019-09-27 Thread Mark Johnston
Author: markj
Date: Fri Sep 27 23:37:01 2019
New Revision: 352826
URL: https://svnweb.freebsd.org/changeset/base/352826

Log:
  Implement pmap_page_is_mapped() correctly on arm64 and riscv.
  
  We must also check for large mappings.  pmap_page_is_mapped() is
  mostly used in assertions, so the problem was not very noticeable.
  
  Reviewed by:  alc
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D21824

Modified:
  head/sys/arm64/arm64/pmap.c
  head/sys/arm64/include/pmap.h
  head/sys/riscv/include/pmap.h
  head/sys/riscv/riscv/pmap.c

Modified: head/sys/arm64/arm64/pmap.c
==
--- head/sys/arm64/arm64/pmap.c Fri Sep 27 22:18:50 2019(r352825)
+++ head/sys/arm64/arm64/pmap.c Fri Sep 27 23:37:01 2019(r352826)
@@ -4241,6 +4241,27 @@ restart:
 }
 
 /*
+ * Returns true if the given page is mapped individually or as part of
+ * a 2mpage.  Otherwise, returns false.
+ */
+bool
+pmap_page_is_mapped(vm_page_t m)
+{
+   struct rwlock *lock;
+   bool rv;
+
+   if ((m->oflags & VPO_UNMANAGED) != 0)
+   return (false);
+   lock = VM_PAGE_TO_PV_LIST_LOCK(m);
+   rw_rlock(lock);
+   rv = !TAILQ_EMPTY(>md.pv_list) ||
+   ((m->flags & PG_FICTITIOUS) == 0 &&
+   !TAILQ_EMPTY(_to_pvh(VM_PAGE_TO_PHYS(m))->pv_list));
+   rw_runlock(lock);
+   return (rv);
+}
+
+/*
  * Destroy all managed, non-wired mappings in the given user-space
  * pmap.  This pmap cannot be active on any processor besides the
  * caller.

Modified: head/sys/arm64/include/pmap.h
==
--- head/sys/arm64/include/pmap.h   Fri Sep 27 22:18:50 2019
(r352825)
+++ head/sys/arm64/include/pmap.h   Fri Sep 27 23:37:01 2019
(r352826)
@@ -150,6 +150,7 @@ vm_paddr_t pmap_kextract(vm_offset_t va);
 void   pmap_kremove(vm_offset_t);
 void   pmap_kremove_device(vm_offset_t, vm_size_t);
 void   *pmap_mapdev_attr(vm_offset_t pa, vm_size_t size, vm_memattr_t ma);
+bool   pmap_page_is_mapped(vm_page_t m);
 bool   pmap_ps_enabled(pmap_t pmap);
 
 void   *pmap_mapdev(vm_offset_t, vm_size_t);
@@ -166,8 +167,6 @@ boolpmap_get_tables(pmap_t, vm_offset_t, pd_entry_t 
*
 intpmap_fault(pmap_t, uint64_t, uint64_t);
 
 struct pcb *pmap_switch(struct thread *, struct thread *);
-
-#definepmap_page_is_mapped(m)  (!TAILQ_EMPTY(&(m)->md.pv_list))
 
 static inline int
 pmap_vmspace_copy(pmap_t dst_pmap __unused, pmap_t src_pmap __unused)

Modified: head/sys/riscv/include/pmap.h
==
--- head/sys/riscv/include/pmap.h   Fri Sep 27 22:18:50 2019
(r352825)
+++ head/sys/riscv/include/pmap.h   Fri Sep 27 23:37:01 2019
(r352826)
@@ -146,6 +146,7 @@ voidpmap_kenter_device(vm_offset_t, vm_size_t, 
vm_pad
 vm_paddr_t pmap_kextract(vm_offset_t va);
 void   pmap_kremove(vm_offset_t);
 void   pmap_kremove_device(vm_offset_t, vm_size_t);
+bool   pmap_page_is_mapped(vm_page_t m);
 bool   pmap_ps_enabled(pmap_t);
 
 void   *pmap_mapdev(vm_offset_t, vm_size_t);
@@ -158,8 +159,6 @@ voidpmap_unmap_io_transient(vm_page_t *, 
vm_offset_t 
 
 bool   pmap_get_tables(pmap_t, vm_offset_t, pd_entry_t **, pd_entry_t **,
 pt_entry_t **);
-
-#definepmap_page_is_mapped(m)  (!TAILQ_EMPTY(&(m)->md.pv_list))
 
 int pmap_fault_fixup(pmap_t, vm_offset_t, vm_prot_t);
 

Modified: head/sys/riscv/riscv/pmap.c
==
--- head/sys/riscv/riscv/pmap.c Fri Sep 27 22:18:50 2019(r352825)
+++ head/sys/riscv/riscv/pmap.c Fri Sep 27 23:37:01 2019(r352826)
@@ -3541,6 +3541,27 @@ restart:
return (count);
 }
 
+/*
+ * Returns true if the given page is mapped individually or as part of
+ * a 2mpage.  Otherwise, returns false.
+ */
+bool
+pmap_page_is_mapped(vm_page_t m)
+{
+   struct rwlock *lock;
+   bool rv;
+
+   if ((m->oflags & VPO_UNMANAGED) != 0)
+   return (false);
+   lock = VM_PAGE_TO_PV_LIST_LOCK(m);
+   rw_rlock(lock);
+   rv = !TAILQ_EMPTY(>md.pv_list) ||
+   ((m->flags & PG_FICTITIOUS) == 0 &&
+   !TAILQ_EMPTY(_to_pvh(VM_PAGE_TO_PHYS(m))->pv_list));
+   rw_runlock(lock);
+   return (rv);
+}
+
 static void
 pmap_remove_pages_pv(pmap_t pmap, vm_page_t m, pv_entry_t pv,
 struct spglist *free, bool superpage)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r352795 - head/lib/libc/sys

2019-09-27 Thread Warner Losh
On Fri, Sep 27, 2019 at 2:38 PM Mateusz Guzik  wrote:

> On 9/27/19, Konstantin Belousov  wrote:
> > On Fri, Sep 27, 2019 at 08:32:20PM +0200, Mateusz Guzik wrote:
> >> On 9/27/19, Warner Losh  wrote:
> >> >   Document varadic args as int, since you can't have short varadic
> args
> >> > (they are
> >> >   promoted to ints).
> >> >
> >> >   - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
> >> >   - `openat` takes variadic args
> >> >   - variadic args cannot be 16-bit, and indeed the code uses int
> >> >   - the manpage currently kinda implies the argument is 16-bit by
> >> > saying
> >> > `mode_t`
> >> >
> >> But opengroup says it is mode_t. Perhaps it is mode_t which needs
> >> to be changed?
> >
> > Yes, users must pass mode_t, and the man page is written for users.
> > Implementation needs to be aware of the implicit promotion and handle
> > it accordingly.
> >
> > In theory, mode_t might be wider than int.
> >
>
> So I think the change should be reverted. Whatever workaround is being
> in place in rust should remain for the current codebase.
>

Rust needs to understand that it's not C. It's mistake was assuming it was
just like C and this is a case where the languages differ because C is so
quirky.


> If anyone is to fixed the problem they should bump mode_t to uint32_t,
> to match Linux. This is ABI breakage, I don't know how that's handled.
>

That's not going to happen. And there's no need. It would cause more
heartache than it's worth.


> I have no interest in handling any of this, but the change committed
> is definitely wrong.
>

I tend to agree, but the manual was/is incomplete. The arg *IS* promoted to
an int, per normal C rules, so that part is right and there's no
type-checking against truncation or the wrong type being used as would be
the case if it weren't varadic (so don't pass a long here).

However, type purity aside, that's not how things are implemented. Open is
expecting an int (as is openat):

int
open(const char *path, int flags, ...)
{
va_list ap;
int mode;

if ((flags & O_CREAT) != 0) {
va_start(ap, flags);
mode = va_arg(ap, int);
va_end(ap);
} else {
mode = 0;
}
return (((int (*)(int, const char *, int, ...))
__libc_interposing[INTERPOS_openat])(fd, path, flags, mode));
}

so the change, from that perspective, actually documents the interface (so
isn't definitely wrong, and my guarded 'tend to agree'). So if you did
change the type of mode_t, the above code might be wrong afterwards (hence
my can of worms comment). And then we're passing it again through a varadic
function pointer...

So while POSIX says one thing, we implement something else. Should we
document POSIX or what we implement? Or do we fix our implementation to
match the docs? For all programs that don't pass in a 'long' or a pointer,
the difference is zero, however.

To be honest, though, quibbling over how it should be implemented aside, I
think we should actually do the following:

diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index a771461e2e49..aa912b797f74 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -61,7 +61,7 @@ In this case
 and
 .Fn openat
 require an additional argument
-.Fa "int mode" ,
+.Fa "mode_t mode" ,
 and the file is created with mode
 .Fa mode
 as described in
@@ -615,3 +615,8 @@ permits searches.
 The present implementation of the
 .Fa openat
 checks the current permissions of directory instead.
+.Pp
+The
+.Fa mode
+argument is varadic and may result in different calling conventions
+than might otherwise be expected.

Is what I was thinking of committing instead. It's in the BUGS section, and
is useful to know if you are debugging code that has this in the call path
(since values may be on the stack instead of in registers, depending on the
calling convention for the underlying architecture).

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


svn commit: r352823 - in head/sys: amd64/vmm/amd amd64/vmm/intel dev/qlnx/qlnxe

2019-09-27 Thread Mark Johnston
Author: markj
Date: Fri Sep 27 21:04:33 2019
New Revision: 352823
URL: https://svnweb.freebsd.org/changeset/base/352823

Log:
  Correct the scope of several global variables.
  
  They are accessed from multiple compilation units.  No functional change
  intended.
  
  MFC after:1 week
  Sponsored by: Netflix

Modified:
  head/sys/amd64/vmm/amd/amdvi_hw.c
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/dev/qlnx/qlnxe/qlnx_os.c

Modified: head/sys/amd64/vmm/amd/amdvi_hw.c
==
--- head/sys/amd64/vmm/amd/amdvi_hw.c   Fri Sep 27 20:56:49 2019
(r352822)
+++ head/sys/amd64/vmm/amd/amdvi_hw.c   Fri Sep 27 21:04:33 2019
(r352823)
@@ -96,7 +96,7 @@ SYSCTL_INT(_hw_vmm_amdvi, OID_AUTO, host_ptp, CTLFLAG_
 TUNABLE_INT("hw.vmm.amdvi.host_ptp", _host_ptp);
 
 /* Page table level used <= supported by h/w[v1=7]. */
-static int amdvi_ptp_level = 4;
+int amdvi_ptp_level = 4;
 SYSCTL_INT(_hw_vmm_amdvi, OID_AUTO, ptp_level, CTLFLAG_RDTUN,
 _ptp_level, 0, NULL);
 TUNABLE_INT("hw.vmm.amdvi.ptp_level", _ptp_level);

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Fri Sep 27 20:56:49 2019
(r352822)
+++ head/sys/amd64/vmm/intel/vmx.c  Fri Sep 27 21:04:33 2019
(r352823)
@@ -189,10 +189,10 @@ static u_int vpid_alloc_failed;
 SYSCTL_UINT(_hw_vmm_vmx, OID_AUTO, vpid_alloc_failed, CTLFLAG_RD,
_alloc_failed, 0, NULL);
 
-static int guest_l1d_flush;
+int guest_l1d_flush;
 SYSCTL_INT(_hw_vmm_vmx, OID_AUTO, l1d_flush, CTLFLAG_RD,
 _l1d_flush, 0, NULL);
-static int guest_l1d_flush_sw;
+int guest_l1d_flush_sw;
 SYSCTL_INT(_hw_vmm_vmx, OID_AUTO, l1d_flush_sw, CTLFLAG_RD,
 _l1d_flush_sw, 0, NULL);
 

Modified: head/sys/dev/qlnx/qlnxe/qlnx_os.c
==
--- head/sys/dev/qlnx/qlnxe/qlnx_os.c   Fri Sep 27 20:56:49 2019
(r352822)
+++ head/sys/dev/qlnx/qlnxe/qlnx_os.c   Fri Sep 27 21:04:33 2019
(r352823)
@@ -232,10 +232,9 @@ MODULE_DEPEND(if_qlnxev, ether, 1, 1, 1);
 
 MALLOC_DEFINE(M_QLNXBUF, "qlnxbuf", "Buffers for qlnx driver");
 
-
-static char qlnx_dev_str[128];
-static char qlnx_ver_str[VER_SIZE];
-static char qlnx_name_str[NAME_SIZE];
+char qlnx_dev_str[128];
+char qlnx_ver_str[VER_SIZE];
+char qlnx_name_str[NAME_SIZE];
 
 /*
  * Some PCI Configuration Space Related Defines
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352821 - head/tools/tools/nanobsd

2019-09-27 Thread Warner Losh
Author: imp
Date: Fri Sep 27 20:56:44 2019
New Revision: 352821
URL: https://svnweb.freebsd.org/changeset/base/352821

Log:
  Push and pop xtrace correctly for run_early_customize
  
  run_early_customize is run as a shell list, not as a subshell, so that the 
side
  effects of setting variables can affect later stages of the build (for better 
or
  worse, it's been like this since it was introduced). It therefore has the side
  effect of turning off xtrace always, which limits the usefulness of sh -x
  nanobsd.sh. Remember the old setting and only turn off tracing after the 
command
  if tracing was off before. All the other places where we do similar things we 
use
  a subshell, so we don't need to do this.

Modified:
  head/tools/tools/nanobsd/defaults.sh

Modified: head/tools/tools/nanobsd/defaults.sh
==
--- head/tools/tools/nanobsd/defaults.shFri Sep 27 20:56:31 2019
(r352820)
+++ head/tools/tools/nanobsd/defaults.shFri Sep 27 20:56:44 2019
(r352821)
@@ -445,7 +445,11 @@ run_early_customize ( ) {
pprint 2 "early customize \"$c\""
pprint 3 "log: ${NANO_LOG}/_.early_cust.$c"
pprint 4 "`type $c`"
-   { set -x ; $c ; set +x ; } >${NANO_LOG}/_.early_cust.$c 2>&1
+   { t=$(set -o | awk '$1 == "xtrace" && $2 == "off" { print "set 
+x"}');
+ set -x ;
+ $c ;
+ eval $t
+   } >${NANO_LOG}/_.early_cust.$c 2>&1
done
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352822 - head/tools/tools/nanobsd

2019-09-27 Thread Warner Losh
Author: imp
Date: Fri Sep 27 20:56:49 2019
New Revision: 352822
URL: https://svnweb.freebsd.org/changeset/base/352822

Log:
  Use set -o xtrace in preference to set -x for consistency with
  the rest of nanobsd.sh.

Modified:
  head/tools/tools/nanobsd/defaults.sh

Modified: head/tools/tools/nanobsd/defaults.sh
==
--- head/tools/tools/nanobsd/defaults.shFri Sep 27 20:56:44 2019
(r352821)
+++ head/tools/tools/nanobsd/defaults.shFri Sep 27 20:56:49 2019
(r352822)
@@ -445,8 +445,8 @@ run_early_customize ( ) {
pprint 2 "early customize \"$c\""
pprint 3 "log: ${NANO_LOG}/_.early_cust.$c"
pprint 4 "`type $c`"
-   { t=$(set -o | awk '$1 == "xtrace" && $2 == "off" { print "set 
+x"}');
- set -x ;
+   { t=$(set -o | awk '$1 == "xtrace" && $2 == "off" { print "set 
+o xtrace"}');
+ set -o xtrace ;
  $c ;
  eval $t
} >${NANO_LOG}/_.early_cust.$c 2>&1
@@ -466,7 +466,7 @@ run_customize ( ) (
pprint 2 "customize \"$c\""
pprint 3 "log: ${NANO_LOG}/_.cust.$c"
pprint 4 "`type $c`"
-   ( set -x ; $c ) > ${NANO_LOG}/_.cust.$c 2>&1
+   ( set -o xtrace ; $c ) > ${NANO_LOG}/_.cust.$c 2>&1
done
 )
 
@@ -481,7 +481,7 @@ run_late_customize ( ) (
pprint 2 "late customize \"$c\""
pprint 3 "log: ${NANO_LOG}/_.late_cust.$c"
pprint 4 "`type $c`"
-   ( set -x ; $c ) > ${NANO_LOG}/_.late_cust.$c 2>&1
+   ( set -o xtrace ; $c ) > ${NANO_LOG}/_.late_cust.$c 2>&1
done
 )
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352820 - head/tools/tools/nanobsd

2019-09-27 Thread Warner Losh
Author: imp
Date: Fri Sep 27 20:56:31 2019
New Revision: 352820
URL: https://svnweb.freebsd.org/changeset/base/352820

Log:
  Remove workaround for building on FreeBSD hosts prior to FreeBSD 10.
  
  rm -x was introduced in the FreeBSD 10 time frame. 4 years ago I added a
  function to cope with building nanobsd images on hosts as old FreeBSD 7 that
  lacked rm -x. The workaround is no longer needed as FreeBSD 9 hasn't been
  supported for almost 3 years. Eliminate the wrapper and use rm -x directly
  again.

Modified:
  head/tools/tools/nanobsd/defaults.sh

Modified: head/tools/tools/nanobsd/defaults.sh
==
--- head/tools/tools/nanobsd/defaults.shFri Sep 27 20:53:31 2019
(r352819)
+++ head/tools/tools/nanobsd/defaults.shFri Sep 27 20:56:31 2019
(r352820)
@@ -241,16 +241,6 @@ nano_global_make_env ( ) (
[ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}"
 )
 
-# rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build
-# hosts for now. This will go away when support in the base goes away.
-rm ( ) {
-echo "NANO RM $*"
-   case $(uname -r) in
-   7*|8*|9*) command rm $* ;;
-   *) command rm -x $* ;;
-   esac
-}
-
 #
 # Create empty files in the target tree, and record the fact.  All paths
 # are relative to NANO_WORLDDIR.
@@ -274,7 +264,7 @@ tgt_dir2symlink ( ) (
symlink=$2
 
cd "${NANO_WORLDDIR}"
-   rm -rf "$dir"
+   rm -xrf "$dir"
ln -s "$symlink" "$dir"
if [ -n "$NANO_METALOG" ]; then
echo "./${dir} type=link mode=0777 link=${symlink}" >> 
${NANO_METALOG}
@@ -294,9 +284,9 @@ CR0 ( ) {
 clean_build ( ) (
pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
 
-   if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
+   if ! rm -xrf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
chflags -R noschg ${MAKEOBJDIRPREFIX}/
-   rm -r ${MAKEOBJDIRPREFIX}/
+   rm -xr ${MAKEOBJDIRPREFIX}/
fi
 )
 
@@ -348,17 +338,17 @@ build_kernel ( ) (
 clean_world ( ) (
if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
pprint 2 "Clean and create object directory (${NANO_OBJ})"
-   if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
+   if ! rm -xrf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
chflags -R noschg ${NANO_OBJ}
-   rm -r ${NANO_OBJ}/
+   rm -xr ${NANO_OBJ}/
fi
mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}"
printenv > ${NANO_LOG}/_.env
else
pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
-   if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then
+   if ! rm -xrf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then
chflags -R noschg "${NANO_WORLDDIR}"
-   rm -rf "${NANO_WORLDDIR}/"
+   rm -xrf "${NANO_WORLDDIR}/"
fi
mkdir -p "${NANO_WORLDDIR}"
fi
@@ -531,7 +521,7 @@ setup_nanobsd ( ) (
cd usr/local/etc
find . -print | cpio -dumpl ../../../etc/local
cd ..
-   rm -rf etc
+   rm -xrf etc
)
fi
 
@@ -780,7 +770,7 @@ cust_pkgng ( ) (
mount -t nullfs -o noatime -o ro ${NANO_PACKAGE_DIR} 
${NANO_WORLDDIR}/_.p
mount -t devfs devfs ${NANO_WORLDDIR}/dev
 
-   trap "umount ${NANO_WORLDDIR}/dev; umount ${NANO_WORLDDIR}/_.p ; rm -rf 
${NANO_WORLDDIR}/_.p" 1 2 15 EXIT
+   trap "umount ${NANO_WORLDDIR}/dev; umount ${NANO_WORLDDIR}/_.p ; rm 
-xrf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT
 
# Install pkg-* package
CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}"
@@ -807,7 +797,7 @@ cust_pkgng ( ) (
trap - 1 2 15 EXIT
umount ${NANO_WORLDDIR}/dev
umount ${NANO_WORLDDIR}/_.p
-   rm -rf ${NANO_WORLDDIR}/_.p
+   rm -xrf ${NANO_WORLDDIR}/_.p
 )
 
 ###
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352819 - head/usr.bin/top

2019-09-27 Thread Dimitry Andric
Author: dim
Date: Fri Sep 27 20:53:31 2019
New Revision: 352819
URL: https://svnweb.freebsd.org/changeset/base/352819

Log:
  Allow entering fractional delays in top(1) interactive mode.
  
  This uses the same logic as with the -s option, first validating the
  entered value, then storing the result in a struct timeval.
  
  MFC after:3 days
  X-MFC-With:   r352818

Modified:
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/top.c
==
--- head/usr.bin/top/top.c  Fri Sep 27 20:20:21 2019(r352818)
+++ head/usr.bin/top/top.c  Fri Sep 27 20:53:31 2019(r352819)
@@ -886,12 +886,22 @@ restart:
 
case CMD_delay: /* new seconds delay */
new_message(MT_standout, "Seconds to delay: ");
-   if ((i = readline(tempbuf1, 8, true)) > 0)
+   if ((i = readline(tempbuf1, 8, false)) > 0)
{
-   delay.tv_sec = i;
-   delay.tv_usec = 0;
+   double delay_d = strtod(tempbuf1, );
+   if (nptr == tempbuf1 || delay_d <= 0)
+   {
+   new_message(MT_standout, " Invalid 
delay");
+   putchar('\r');
+   no_command = true;
+   }
+   else
+   {
+   delay.tv_sec = delay_d;
+   delay.tv_usec = (delay_d - 
delay.tv_sec) * 1e6;
+   clear_message();
+   }
}
-   clear_message();
break;
 
case CMD_displays:  /* change display count */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r352795 - head/lib/libc/sys

2019-09-27 Thread Mateusz Guzik
On 9/27/19, Konstantin Belousov  wrote:
> On Fri, Sep 27, 2019 at 08:32:20PM +0200, Mateusz Guzik wrote:
>> On 9/27/19, Warner Losh  wrote:
>> >   Document varadic args as int, since you can't have short varadic args
>> > (they are
>> >   promoted to ints).
>> >
>> >   - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
>> >   - `openat` takes variadic args
>> >   - variadic args cannot be 16-bit, and indeed the code uses int
>> >   - the manpage currently kinda implies the argument is 16-bit by
>> > saying
>> > `mode_t`
>> >
>> But opengroup says it is mode_t. Perhaps it is mode_t which needs
>> to be changed?
>
> Yes, users must pass mode_t, and the man page is written for users.
> Implementation needs to be aware of the implicit promotion and handle
> it accordingly.
>
> In theory, mode_t might be wider than int.
>

So I think the change should be reverted. Whatever workaround is being
in place in rust should remain for the current codebase.

If anyone is to fixed the problem they should bump mode_t to uint32_t,
to match Linux. This is ABI breakage, I don't know how that's handled.

I have no interest in handling any of this, but the change committed
is definitely wrong.

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


Re: svn commit: r352795 - head/lib/libc/sys

2019-09-27 Thread Bruce Evans

On Fri, 27 Sep 2019, Konstantin Belousov wrote:


On Fri, Sep 27, 2019 at 08:32:20PM +0200, Mateusz Guzik wrote:

On 9/27/19, Warner Losh  wrote:

Author: imp
Date: Fri Sep 27 16:11:47 2019
New Revision: 352795
URL: https://svnweb.freebsd.org/changeset/base/352795

Log:
  Document varadic args as int, since you can't have short varadic args
(they are
  promoted to ints).

  - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
  - `openat` takes variadic args
  - variadic args cannot be 16-bit, and indeed the code uses int
  - the manpage currently kinda implies the argument is 16-bit by saying
`mode_t`

  Prompted by Rust things: https://github.com/tailhook/openat/issues/21
  Submitted by: Greg V at unrelenting
  Differential Revision: https://reviews.freebsd.org/D21816

Modified:
  head/lib/libc/sys/mq_open.2
  head/lib/libc/sys/open.2

Modified: head/lib/libc/sys/mq_open.2
==
--- head/lib/libc/sys/mq_open.2 Fri Sep 27 15:28:30 2019(r352794)
+++ head/lib/libc/sys/mq_open.2 Fri Sep 27 16:11:47 2019(r352795)
@@ -133,7 +133,7 @@ Create a message queue.
 It requires two additional arguments:
 .Fa mode ,
 which is of type
-.Vt mode_t ,
+.Vt int ,
 and
 .Fa attr ,
 which is a pointer to an

Modified: head/lib/libc/sys/open.2
==
--- head/lib/libc/sys/open.2Fri Sep 27 15:28:30 2019(r352794)
+++ head/lib/libc/sys/open.2Fri Sep 27 16:11:47 2019(r352795)
@@ -61,7 +61,7 @@ In this case
 and
 .Fn openat
 require an additional argument
-.Fa "mode_t mode" ,
+.Fa "int mode" ,
 and the file is created with mode
 .Fa mode
 as described in


But opengroup says it is mode_t. Perhaps it is mode_t which needs
to be changed?


POSIX needed to be changed before it became standard in 1988, but it is
too late now.  Types shorter than int shouldn't be used in APIs since
they cause ABI and API problems.  Especially in 1988 when non-prototyped
functions were common.  Non-prototyped functions use the default promotions
much like variadic functions.  open() is variadic, so its mode_t arg is
always promoted, but 'int chmod(const char *path, mode_t mode)' is just
wrong since in 1988 prototypes were not required and the prototype
matching the K API was 'int chmod(const char *path,
__default_promotion_of(mode_t) mode)'.


Yes, users must pass mode_t, and the man page is written for users.
Implementation needs to be aware of the implicit promotion and handle
it accordingly.

In theory, mode_t might be wider than int.


Indeed.  mode_t can also be the same size as int, but unsigned.  This
happens naturally if int is 16 bits, which POSIX allowed before 2001.
In V7, mode_t was really a 16-bit u_int, but it was type-punned to int.

When mode_t is u_int or wider than int, then the promotion is null, and
variadic and K do it consistently (but the arg type before the call
must be precisely mode_t, not int).

The POSIX list recently discussed a related problem with variadic pid_t
args for fcntl().  For F_SETOWN, the original arg type should be pid_t
as for mode_t for open().  Howver, F_GETOWN only returns int, so pids
larger than INT_MAX cannot work and making pid_t different from int is
just foot shooting.

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


svn commit: r352818 - head/usr.bin/top

2019-09-27 Thread Dimitry Andric
Author: dim
Date: Fri Sep 27 20:20:21 2019
New Revision: 352818
URL: https://svnweb.freebsd.org/changeset/base/352818

Log:
  Make fractional delays for top(1) work for interactive mode.
  
  In r334906, the -s option was changed to allow fractional times, but
  this only functioned correctly for batch mode.  In interactive mode, any
  delay below 1.0 would get floored to zero.  This would put top(1) into a
  tight loop, which could be difficult to interrupt.
  
  Fix this by storing the -s option value (after validation) into a struct
  timeval, and using that struct consistently for delaying with select(2).
  
  Next up is to allow interactive entry of a fractional delay value.
  
  MFC after:3 days

Modified:
  head/usr.bin/top/top.1
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/top.1
==
--- head/usr.bin/top/top.1  Fri Sep 27 20:09:43 2019(r352817)
+++ head/usr.bin/top/top.1  Fri Sep 27 20:20:21 2019(r352818)
@@ -147,7 +147,7 @@ no information is available about the percentage of ti
 .It Fl s Ar time
 Set the delay between screen updates to
 .Ar time
-seconds.
+seconds, which may be fractional.
 The default delay between updates is 1 second.
 .It Fl o Ar field
 Sort the process display area on the specified field.

Modified: head/usr.bin/top/top.c
==
--- head/usr.bin/top/top.c  Fri Sep 27 20:09:43 2019(r352817)
+++ head/usr.bin/top/top.c  Fri Sep 27 20:20:21 2019(r352818)
@@ -233,7 +233,7 @@ main(int argc, const char *argv[])
 static char tempbuf2[50];
sigset_t old_sigmask, new_sigmask;
 int topn = Infinity;
-double delay = 2;
+struct timeval delay = { 2, 0 };
 int displays = 0;  /* indicates unspecified */
 int sel_ret = 0;
 time_t curr_time;
@@ -377,21 +377,27 @@ main(int argc, const char *argv[])
break;
  }
 
- case 's':
-   delay = strtod(optarg, );
-   if (nptr == optarg) {
-   warnx("warning: invalid delay");
-   delay = 2;
-   warnings++;
-   }
-   if (delay < 0) {
-   warnx("warning: seconds delay should be 
positive -- using default");
-   delay = 2;
-   warnings++;
-   }
+ case 's':
+ {
+ double delay_d = strtod(optarg, );
+ if (nptr == optarg)
+ {
+ warnx("warning: invalid delay");
+ warnings++;
+ }
+ else if (delay_d <= 0)
+ {
+ warnx("warning: seconds delay should be positive -- using 
default");
+ warnings++;
+ }
+ else
+ {
+ delay.tv_sec = delay_d;
+ delay.tv_usec = (delay_d - delay.tv_sec) * 1e6;
+ }
+ break;
+ }
 
-   break;
-
  case 'q': /* be quick about it */
errno = 0;
i = setpriority(PRIO_PROCESS, 0, PRIO_MIN);
@@ -704,7 +710,8 @@ restart:
no_command = true;
if (!interactive)
{
-   usleep(delay * 1e6);
+   timeout = delay;
+   select(0, NULL, NULL, NULL, );
if (leaveflag) {
end_screen();
exit(0);
@@ -718,8 +725,7 @@ restart:
/* set up arguments for select with timeout */
FD_ZERO();
FD_SET(0, );/* for standard input */
-   timeout.tv_sec  = delay;
-   timeout.tv_usec = 0;
+   timeout = delay;
 
if (leaveflag) {
end_screen();
@@ -880,12 +886,10 @@ restart:
 
case CMD_delay: /* new seconds delay */
new_message(MT_standout, "Seconds to delay: ");
-   if ((i = readline(tempbuf1, 8, true)) > -1)
+   if ((i = readline(tempbuf1, 8, true)) > 0)
{
-   if ((delay = i) == 0)
-   {
-   delay = 1;
-   }
+   delay.tv_sec = i;
+   delay.tv_usec = 0;
}
clear_message();
break;
___
svn-src-head@freebsd.org 

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

2019-09-27 Thread Andrew Gallatin
Author: gallatin
Date: Fri Sep 27 20:08:19 2019
New Revision: 352816
URL: https://svnweb.freebsd.org/changeset/base/352816

Log:
  kTLS: Fix a bug where we would not encrypt anon data inplace.
  
  Software Kernel TLS needs to allocate a new destination crypto
  buffer when encrypting data from the page cache, so as to avoid
  overwriting shared clear-text file data with encrypted data
  specific to a single socket. When the data is anonymous, eg, not
  tied to a file, then we can encrypt in place and avoid allocating
  a new page. This fixes a bug where the existing code always
  assumes the data is private, and never encrypts in place. This
  results in unneeded page allocations and potentially more memory
  bandwidth consumption when doing socket writes.
  
  When the code was written at Netflix, ktls_encrypt() looked at
  private sendfile flags to determine if the pages being encrypted
  where part of the page cache (coming from sendfile) or
  anonymous (coming from sosend). This was broken internally at
  Netflix when the sendfile flags were made private, and the
  M_WRITABLE() check was added. Unfortunately, M_WRITABLE() will
  always be false for M_NOMAP mbufs, since one cannot just mtod()
  them.
  
  This change introduces a new flags field to the mbuf_ext_pgs
  struct by stealing a byte from the tls hdr. Note that the current
  header is still 2 bytes larger than the largest header we
  support: AES-CBC with explicit IV. We set MBUF_PEXT_FLAG_ANON
  when creating an unmapped mbuf in m_uiotombuf_nomap() (which is
  the path that socket writes take), and we check for that flag in
  ktls_encrypt() when looking for anon pages.
  
  Reviewed by:  jhb
  Sponsored by: Netflix
  Differential Revision:https://reviews.freebsd.org/D21796

Modified:
  head/sys/kern/kern_mbuf.c
  head/sys/kern/uipc_ktls.c
  head/sys/kern/uipc_mbuf.c
  head/sys/sys/mbuf.h

Modified: head/sys/kern/kern_mbuf.c
==
--- head/sys/kern/kern_mbuf.c   Fri Sep 27 19:26:52 2019(r352815)
+++ head/sys/kern/kern_mbuf.c   Fri Sep 27 20:08:19 2019(r352816)
@@ -1171,6 +1171,7 @@ mb_alloc_ext_pgs(int how, bool pkthdr, m_ext_free_t ex
ext_pgs->nrdy = 0;
ext_pgs->first_pg_off = 0;
ext_pgs->last_pg_len = 0;
+   ext_pgs->flags = 0;
ext_pgs->hdr_len = 0;
ext_pgs->trail_len = 0;
ext_pgs->tls = NULL;

Modified: head/sys/kern/uipc_ktls.c
==
--- head/sys/kern/uipc_ktls.c   Fri Sep 27 19:26:52 2019(r352815)
+++ head/sys/kern/uipc_ktls.c   Fri Sep 27 20:08:19 2019(r352816)
@@ -1363,7 +1363,7 @@ ktls_encrypt(struct mbuf_ext_pgs *pgs)
 * (from sendfile), anonymous wired pages are
 * allocated and assigned to the destination iovec.
 */
-   is_anon = M_WRITABLE(m);
+   is_anon = (pgs->flags & MBUF_PEXT_FLAG_ANON) != 0;
 
off = pgs->first_pg_off;
for (i = 0; i < pgs->npgs; i++, off = 0) {
@@ -1416,6 +1416,9 @@ retry_page:
 
/* Use the basic free routine. */
m->m_ext.ext_free = mb_free_mext_pgs;
+
+   /* Pages are now writable. */
+   pgs->flags |= MBUF_PEXT_FLAG_ANON;
}
 
/*

Modified: head/sys/kern/uipc_mbuf.c
==
--- head/sys/kern/uipc_mbuf.c   Fri Sep 27 19:26:52 2019(r352815)
+++ head/sys/kern/uipc_mbuf.c   Fri Sep 27 20:08:19 2019(r352816)
@@ -1664,6 +1664,7 @@ m_uiotombuf_nomap(struct uio *uio, int how, int len, i
prev->m_next = mb;
prev = mb;
pgs = mb->m_ext.ext_pgs;
+   pgs->flags = MBUF_PEXT_FLAG_ANON;
needed = length = MIN(maxseg, total);
for (i = 0; needed > 0; i++, needed -= PAGE_SIZE) {
 retry_page:

Modified: head/sys/sys/mbuf.h
==
--- head/sys/sys/mbuf.h Fri Sep 27 19:26:52 2019(r352815)
+++ head/sys/sys/mbuf.h Fri Sep 27 20:08:19 2019(r352816)
@@ -312,7 +312,7 @@ struct socket;
  * - 21 (AES-CBC with explicit IV)
  * - 13 (AES-GCM with 8 byte explicit IV)
  */
-#defineMBUF_PEXT_HDR_LEN   24
+#defineMBUF_PEXT_HDR_LEN   23
 
 /*
  * TLS records for TLS 1.0-1.2 can have the following maximum trailer
@@ -333,6 +333,8 @@ struct socket;
 #defineMBUF_PEXT_MAX_BYTES 
\
 (MBUF_PEXT_MAX_PGS * PAGE_SIZE + MBUF_PEXT_HDR_LEN + MBUF_PEXT_TRAIL_LEN)
 
+#define MBUF_PEXT_FLAG_ANON1   /* Data can be encrypted in place. */
+
 /*
  * This struct is 256 bytes in size and is arranged so that the most
  * common case (accessing the first 4 

svn commit: r352815 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 19:26:52 2019
New Revision: 352815
URL: https://svnweb.freebsd.org/changeset/base/352815

Log:
  controlelf: update man page
  
  Some minor corrections, clarifications or rewording.

Modified:
  head/tools/tools/controlelf/controlelf.1

Modified: head/tools/tools/controlelf/controlelf.1
==
--- head/tools/tools/controlelf/controlelf.1Fri Sep 27 19:17:40 2019
(r352814)
+++ head/tools/tools/controlelf/controlelf.1Fri Sep 27 19:26:52 2019
(r352815)
@@ -26,12 +26,12 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 21, 2019
+.Dd September 27, 2019
 .Dt CONTROLELF 1
 .Os
 .Sh NAME
 .Nm controlelf
-.Nd change an ELF binary's control features
+.Nd change an ELF binary's feature control note
 .Sh SYNOPSIS
 .Nm
 .Op Fl h | Fl -help
@@ -41,33 +41,33 @@
 .Sh DESCRIPTION
 The
 .Nm
-utility modifies an ELF binary to change it's control features.
+utility modifies feature flags in the feature control note in an ELF binary.
 .Pp
 The options are as follows:
 .Bl -tag -width indent
 .It Fl h | Fl -help
 Print a usage message and exit.
 .It Fl l
-Writes the list of all known ELF types to standard output.
+List known ELF feature flags.
 .It Fl e Ar featurelist
 Edit features from the given comma separated list
 .Ar featurelist .
 .Ar featurelist
-starts with one of the three modes:
+starts with one of the three operations:
 .Dq Li +
 to turn on the features,
 .Dq Li -
 to turn off the features,
 .Dq Li =
 to only turn on the given features.
-Followed by a comma separated features.
+A comma separated list of feature names follows the operation.
 .El
 .Pp
 If
-.Fl e ,
-option wasn't specified,
+.Fl e
+is not specified
 .Nm
-will display the current control features for the files named by the arguments
+displays the status of each feature in the ELF note in each
 .Ar .
 .Sh EXIT STATUS
 Exit status is 0 on success, and 1 if the command
@@ -83,10 +83,12 @@ controlelf file
 controlelf -e +aslr file
 .Ed
 .Sh HISTORY
-The
 .Nm
-manual page first appeared in
+first appeared in
 .Fx 13.0 .
 .Sh AUTHORS
-This manual page was written by
-.An Bora Ozarslan Mt borako.ozars...@gmail.com .
+.Nm
+was written by
+.An Bora Ozarslan Mt borako.ozars...@gmail.com
+under sponsorship from the
+.Fx Foundation.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352814 - in head/sys: kern net opencrypto sys

2019-09-27 Thread Andrew Gallatin
Author: gallatin
Date: Fri Sep 27 19:17:40 2019
New Revision: 352814
URL: https://svnweb.freebsd.org/changeset/base/352814

Log:
  kTLS support for TLS 1.3
  
  TLS 1.3 requires a few changes because 1.3 pretends to be 1.2
  with a record type of application data. The "real" record type is
  then included at the end of the user-supplied plaintext
  data. This required adding a field to the mbuf_ext_pgs struct to
  save the record type, and passing the real record type to the
  sw_encrypt() ktls backend functions.
  
  Reviewed by:  jhb, hselasky
  Sponsored by: Netflix
  Differential Revision:D21801

Modified:
  head/sys/kern/uipc_ktls.c
  head/sys/net/iflib.c
  head/sys/opencrypto/ktls_ocf.c
  head/sys/sys/ktls.h
  head/sys/sys/mbuf.h

Modified: head/sys/kern/uipc_ktls.c
==
--- head/sys/kern/uipc_ktls.c   Fri Sep 27 19:14:03 2019(r352813)
+++ head/sys/kern/uipc_ktls.c   Fri Sep 27 19:17:40 2019(r352814)
@@ -389,14 +389,14 @@ ktls_create_session(struct socket *so, struct tls_enab
if (en->tls_vmajor != TLS_MAJOR_VER_ONE)
return (EINVAL);
if (en->tls_vminor < TLS_MINOR_VER_ZERO ||
-   en->tls_vminor > TLS_MINOR_VER_TWO)
+   en->tls_vminor > TLS_MINOR_VER_THREE)
return (EINVAL);
 
if (en->auth_key_len < 0 || en->auth_key_len > TLS_MAX_PARAM_SIZE)
return (EINVAL);
if (en->cipher_key_len < 0 || en->cipher_key_len > TLS_MAX_PARAM_SIZE)
return (EINVAL);
-   if (en->iv_len < 0 || en->iv_len > TLS_MAX_PARAM_SIZE)
+   if (en->iv_len < 0 || en->iv_len > sizeof(tls->params.iv))
return (EINVAL);
 
/* All supported algorithms require a cipher key. */
@@ -425,7 +425,10 @@ ktls_create_session(struct socket *so, struct tls_enab
}
if (en->auth_key_len != 0)
return (EINVAL);
-   if (en->iv_len != TLS_AEAD_GCM_LEN)
+   if ((en->tls_vminor == TLS_MINOR_VER_TWO &&
+   en->iv_len != TLS_AEAD_GCM_LEN) ||
+   (en->tls_vminor == TLS_MINOR_VER_THREE &&
+   en->iv_len != TLS_1_3_GCM_IV_LEN))
return (EINVAL);
break;
case CRYPTO_AES_CBC:
@@ -477,8 +480,22 @@ ktls_create_session(struct socket *so, struct tls_enab
tls->params.tls_hlen = sizeof(struct tls_record_layer);
switch (en->cipher_algorithm) {
case CRYPTO_AES_NIST_GCM_16:
-   tls->params.tls_hlen += 8;
+   /*
+* TLS 1.2 uses a 4 byte implicit IV with an explicit 8 byte
+* nonce.  TLS 1.3 uses a 12 byte implicit IV.
+*/
+   if (en->tls_vminor < TLS_MINOR_VER_THREE)
+   tls->params.tls_hlen += sizeof(uint64_t);
tls->params.tls_tlen = AES_GMAC_HASH_LEN;
+
+   /*
+* TLS 1.3 includes optional padding which we
+* do not support, and also puts the "real" record
+* type at the end of the encrypted data.
+*/
+   if (en->tls_vminor == TLS_MINOR_VER_THREE)
+   tls->params.tls_tlen += sizeof(uint8_t);
+
tls->params.tls_bs = 1;
break;
case CRYPTO_AES_CBC:
@@ -539,7 +556,6 @@ ktls_create_session(struct socket *so, struct tls_enab
 * of the IV are generated in ktls_frame() and ktls_seq().
 */
if (en->iv_len != 0) {
-   MPASS(en->iv_len <= sizeof(tls->params.iv));
tls->params.iv_len = en->iv_len;
error = copyin(en->iv, tls->params.iv, en->iv_len);
if (error)
@@ -1188,8 +1204,21 @@ ktls_frame(struct mbuf *top, struct ktls_session *tls,
/* Populate the TLS header. */
tlshdr = (void *)pgs->hdr;
tlshdr->tls_vmajor = tls->params.tls_vmajor;
-   tlshdr->tls_vminor = tls->params.tls_vminor;
-   tlshdr->tls_type = record_type;
+
+   /*
+* TLS 1.3 masquarades as TLS 1.2 with a record type
+* of TLS_RLTYPE_APP.
+*/
+   if (tls->params.tls_vminor == TLS_MINOR_VER_THREE &&
+   tls->params.tls_vmajor == TLS_MAJOR_VER_ONE) {
+   tlshdr->tls_vminor = TLS_MINOR_VER_TWO;
+   tlshdr->tls_type = TLS_RLTYPE_APP;
+   /* save the real record type for later */
+   pgs->record_type = record_type;
+   } else {
+   tlshdr->tls_vminor = tls->params.tls_vminor;
+   tlshdr->tls_type = record_type;
+   }
tlshdr->tls_length = htons(m->m_len - sizeof(*tlshdr));
 
/*
@@ -1365,7 +1394,8 @@ retry_page:
 

svn commit: r352813 - head/sys/kern

2019-09-27 Thread Mateusz Guzik
Author: mjg
Date: Fri Sep 27 19:14:03 2019
New Revision: 352813
URL: https://svnweb.freebsd.org/changeset/base/352813

Log:
  cache: decrease ncnegfactor to 5
  
  The current mechanism is bogus in several ways:
  - the limit is a percentage of total entries added, which means negative
  entries get evicted all the time even if there are plenty of resources
  - evicting code is almost not concurrent, which makes it unable to
  remove entries fast enough when doing something as simple as -j 104
  buildworld
  - there is no support for performing mass removal if necessary
  
  Vast majority of negative entries never get any hits. Only evicting
  them when the filesystem demands it results in a significant growth of
  the namecache with almost no improvement in the hit ratio.
  
  Sample result about afer 90 minutes of poudriere -j 104:
  
 currentno evict   % of the original
  numneg 219737 2013157916
  numneghits 266711906  263544562  98 [1]
  
  [1] this may look funny but there is a certain dose of variation to the
  build
  
  The number was chosen as something which mostly eliminates spurious
  evictions during lighter workloads but still keeps the total at bay.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==
--- head/sys/kern/vfs_cache.c   Fri Sep 27 19:13:22 2019(r352812)
+++ head/sys/kern/vfs_cache.c   Fri Sep 27 19:14:03 2019(r352813)
@@ -200,7 +200,7 @@ static __read_mostly LIST_HEAD(nchashhead, namecache) 
 static u_long __read_mostlynchash; /* size of hash table */
 SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, , 0,
 "Size of namecache hash table");
-static u_long __read_mostlyncnegfactor = 12; /* ratio of negative entries 
*/
+static u_long __read_mostlyncnegfactor = 5; /* ratio of negative entries */
 SYSCTL_ULONG(_vfs, OID_AUTO, ncnegfactor, CTLFLAG_RW, , 0,
 "Ratio of negative namecache entries");
 static u_long __exclusive_cache_line   numneg; /* number of negative entries 
allocated */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352812 - head/sys/kern

2019-09-27 Thread Mateusz Guzik
Author: mjg
Date: Fri Sep 27 19:13:22 2019
New Revision: 352812
URL: https://svnweb.freebsd.org/changeset/base/352812

Log:
  cache: stop requeuing negative entries on the hot list
  
  Turns out it does not improve hit ratio, but it does come with a cost
  induces stemming from dirtying hit entries.
  
  Sample result: hit counts of evicted entries after 2 buildworlds
  
  before:
  
 value  - Distribution - count
-1 | 0
 0 |@180865
 1 |@@@  49150
 2 |@@@  19067
 4 |@9825
 8 |@7340
16 |@5952
32 |@5243
64 |@4446
   128 | 3556
   256 | 3035
   512 | 1705
  1024 | 1078
  2048 | 365
  4096 | 95
  8192 | 34
 16384 | 26
 32768 | 23
 65536 | 8
131072 | 6
262144 | 0
  
  after:
 value  - Distribution - count
-1 | 0
 0 |@184004
 1 |@@   47577
 2 |@@@  19446
 4 |@10093
 8 |@7470
16 |@5544
32 |@5475
64 |@5011
   128 | 3451
   256 | 3002
   512 | 1729
  1024 | 1086
  2048 | 363
  4096 | 86
  8192 | 26
 16384 | 25
 32768 | 24
 65536 | 7
131072 | 5
262144 | 0
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==
--- head/sys/kern/vfs_cache.c   Fri Sep 27 19:12:43 2019(r352811)
+++ head/sys/kern/vfs_cache.c   Fri Sep 27 19:13:22 2019(r352812)
@@ -92,10 +92,10 @@ SDT_PROBE_DEFINE1(vfs, namecache, purge_negative, done
 SDT_PROBE_DEFINE1(vfs, namecache, purgevfs, done, "struct mount *");
 SDT_PROBE_DEFINE3(vfs, namecache, zap, done, "struct vnode *", "char *",
 "struct vnode *");
-SDT_PROBE_DEFINE3(vfs, namecache, zap_negative, done, "struct vnode *",
-"char *", "int");
-SDT_PROBE_DEFINE3(vfs, namecache, shrink_negative, done, "struct vnode *",
-"char *", "int");
+SDT_PROBE_DEFINE2(vfs, namecache, zap_negative, done, "struct vnode *",
+"char *");
+SDT_PROBE_DEFINE2(vfs, namecache, shrink_negative, done, "struct vnode *",
+"char *");
 
 /*
  * This structure describes the elements in the cache of recent
@@ -109,7 +109,6 @@ struct  namecache {
struct  vnode *nc_dvp;  /* vnode of parent of name */
union {
struct  vnode *nu_vp;   /* vnode the name refers to */
-   u_int   nu_neghits; /* negative entry hits */
} n_un;
u_char  nc_flag;/* flag bits */
u_char  nc_nlen;/* length of name */
@@ -132,7 +131,6 @@ struct  namecache_ts {
 };
 
 #definenc_vp   n_un.nu_vp
-#definenc_neghits  n_un.nu_neghits
 
 /*
  * Flags in namecache.nc_flag
@@ -220,9 +218,6 @@ SYSCTL_UINT(_vfs, OID_AUTO, ncsizefactor, CTLFLAG_RW, 
 static u_int __read_mostly 

svn commit: r352811 - head/sys/kern

2019-09-27 Thread Mateusz Guzik
Author: mjg
Date: Fri Sep 27 19:12:43 2019
New Revision: 352811
URL: https://svnweb.freebsd.org/changeset/base/352811

Log:
  cache: make negative list shrinking a little bit concurrent
  
  Continue protecting demotion from the hotlist and selection of the
  target list with the ncneg_shrink_lock lock, but drop it before
  relocking to zap the node.
  
  While here count how many times we skipped shrinking due to the lock
  being already taken.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==
--- head/sys/kern/vfs_cache.c   Fri Sep 27 19:12:20 2019(r352810)
+++ head/sys/kern/vfs_cache.c   Fri Sep 27 19:12:43 2019(r352811)
@@ -380,8 +380,6 @@ STATNODE_COUNTER(numfullpathfail2,
 "Number of fullpath search errors (VOP_VPTOCNP failures)");
 STATNODE_COUNTER(numfullpathfail4, "Number of fullpath search errors 
(ENOMEM)");
 STATNODE_COUNTER(numfullpathfound, "Number of successful fullpath calls");
-static long numneg_evicted; STATNODE_ULONG(numneg_evicted,
-"Number of negative entries evicted when adding a new entry");
 STATNODE_COUNTER(zap_and_exit_bucket_relock_success,
 "Number of successful removals after relocking");
 static long zap_and_exit_bucket_fail; STATNODE_ULONG(zap_and_exit_bucket_fail,
@@ -392,6 +390,10 @@ static long cache_lock_vnodes_cel_3_failures;
 STATNODE_ULONG(cache_lock_vnodes_cel_3_failures,
 "Number of times 3-way vnode locking failed");
 STATNODE_ULONG(numhotneg, "Number of hot negative entries");
+STATNODE_COUNTER(numneg_evicted,
+"Number of negative entries evicted when adding a new entry");
+STATNODE_COUNTER(shrinking_skipped,
+"Number of times shrinking was already in progress");
 
 static void cache_zap_locked(struct namecache *ncp, bool neg_locked);
 static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode 
*rdir,
@@ -809,8 +811,10 @@ cache_negative_zap_one(void)
struct rwlock *blp;
 
if (mtx_owner(_shrink_lock) != NULL ||
-   !mtx_trylock(_shrink_lock))
+   !mtx_trylock(_shrink_lock)) {
+   counter_u64_add(shrinking_skipped, 1);
return;
+   }
 
mtx_lock(_hot.nl_lock);
ncp = TAILQ_FIRST(_hot.nl_list);
@@ -831,8 +835,9 @@ cache_negative_zap_one(void)
shrink_list_turn = 0;
if (ncp == NULL && shrink_list_turn == 0)
cache_negative_shrink_select(shrink_list_turn, , );
+   mtx_unlock(_shrink_lock);
if (ncp == NULL)
-   goto out;
+   return;
 
MPASS(ncp->nc_flag & NCF_NEGATIVE);
dvlp = VP2VNODELOCK(ncp->nc_dvp);
@@ -845,19 +850,15 @@ cache_negative_zap_one(void)
if (ncp != ncp2 || dvlp != VP2VNODELOCK(ncp2->nc_dvp) ||
blp != NCP2BUCKETLOCK(ncp2) || !(ncp2->nc_flag & NCF_NEGATIVE)) {
ncp = NULL;
-   goto out_unlock_all;
+   } else {
+   SDT_PROBE3(vfs, namecache, shrink_negative, done, ncp->nc_dvp,
+   ncp->nc_name, ncp->nc_neghits);
+   cache_zap_locked(ncp, true);
+   counter_u64_add(numneg_evicted, 1);
}
-   SDT_PROBE3(vfs, namecache, shrink_negative, done, ncp->nc_dvp,
-   ncp->nc_name, ncp->nc_neghits);
-
-   cache_zap_locked(ncp, true);
-   numneg_evicted++;
-out_unlock_all:
mtx_unlock(>nl_lock);
rw_wunlock(blp);
mtx_unlock(dvlp);
-out:
-   mtx_unlock(_shrink_lock);
cache_free(ncp);
 }
 
@@ -2016,6 +2017,8 @@ nchinit(void *dummy __unused)
numfullpathfail4 = counter_u64_alloc(M_WAITOK);
numfullpathfound = counter_u64_alloc(M_WAITOK);
zap_and_exit_bucket_relock_success = counter_u64_alloc(M_WAITOK);
+   numneg_evicted = counter_u64_alloc(M_WAITOK);
+   shrinking_skipped = counter_u64_alloc(M_WAITOK);
 }
 SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_SECOND, nchinit, NULL);
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352810 - head/sys/kern

2019-09-27 Thread Mateusz Guzik
Author: mjg
Date: Fri Sep 27 19:12:20 2019
New Revision: 352810
URL: https://svnweb.freebsd.org/changeset/base/352810

Log:
  cache: stop recalculating upper limit each time a new entry is added
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==
--- head/sys/kern/vfs_cache.c   Fri Sep 27 19:07:11 2019(r352809)
+++ head/sys/kern/vfs_cache.c   Fri Sep 27 19:12:20 2019(r352810)
@@ -214,7 +214,7 @@ SYSCTL_ULONG(_debug, OID_AUTO, numcache, CTLFLAG_RD, &
 static u_long __exclusive_cache_line   numcachehv;/* number of cache entries 
with vnodes held */
 SYSCTL_ULONG(_debug, OID_AUTO, numcachehv, CTLFLAG_RD, , 0,
 "Number of namecache entries with vnodes held");
-u_int __read_mostlyncsizefactor = 2;
+u_int ncsizefactor = 2;
 SYSCTL_UINT(_vfs, OID_AUTO, ncsizefactor, CTLFLAG_RW, , 0,
 "Size factor for namecache");
 static u_int __read_mostly ncpurgeminvnodes;
@@ -223,6 +223,7 @@ SYSCTL_UINT(_vfs, OID_AUTO, ncpurgeminvnodes, CTLFLAG_
 static u_int __read_mostly ncneghitsrequeue = 8;
 SYSCTL_UINT(_vfs, OID_AUTO, ncneghitsrequeue, CTLFLAG_RW, , 0,
 "Number of hits to requeue a negative entry in the LRU list");
+static u_int __read_mostly ncsize; /* the size as computed on creation or 
resizing */
 
 struct nchstatsnchstats;   /* cache effectiveness 
statistics */
 
@@ -1713,7 +1714,7 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, 
 * Avoid blowout in namecache entries.
 */
lnumcache = atomic_fetchadd_long(, 1) + 1;
-   if (__predict_false(lnumcache >= desiredvnodes * ncsizefactor)) {
+   if (__predict_false(lnumcache >= ncsize)) {
atomic_add_long(, -1);
return;
}
@@ -1969,6 +1970,7 @@ nchinit(void *dummy __unused)
NULL, NULL, NULL, NULL, UMA_ALIGNOF(struct namecache_ts),
UMA_ZONE_ZINIT);
 
+   ncsize = desiredvnodes * ncsizefactor;
nchashtbl = hashinit(desiredvnodes * 2, M_VFSCACHE, );
ncbuckethash = cache_roundup_2(mp_ncpus * mp_ncpus) - 1;
if (ncbuckethash < 7) /* arbitrarily chosen to avoid having one lock */
@@ -2024,8 +2026,10 @@ cache_changesize(int newmaxvnodes)
u_long new_nchash, old_nchash;
struct namecache *ncp;
uint32_t hash;
+   int newncsize;
int i;
 
+   newncsize = newmaxvnodes * ncsizefactor;
newmaxvnodes = cache_roundup_2(newmaxvnodes * 2);
if (newmaxvnodes < numbucketlocks)
newmaxvnodes = numbucketlocks;
@@ -2055,6 +2059,7 @@ cache_changesize(int newmaxvnodes)
LIST_INSERT_HEAD(NCHHASH(hash), ncp, nc_hash);
}
}
+   ncsize = newncsize;
cache_unlock_all_buckets();
cache_unlock_all_vnodes();
free(old_nchashtbl, M_VFSCACHE);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352809 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 19:07:11 2019
New Revision: 352809
URL: https://svnweb.freebsd.org/changeset/base/352809

Log:
  controlelf: exit with error if file endianness does not match host
  
  We need to add support for cross-endian operation, but until that's done
  just exit with an error rather than misbehaving.

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 18:49:13 2019
(r352808)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 19:07:11 2019
(r352809)
@@ -30,6 +30,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -70,6 +71,12 @@ static struct option long_opts[] = {
{ NULL, 0,  NULL,   0 }
 };
 
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define SUPPORTED_ENDIAN ELFDATA2LSB
+#else
+#define SUPPORTED_ENDIAN ELFDATA2MSB
+#endif
+   
 int
 main(int argc, char **argv)
 {
@@ -140,6 +147,15 @@ main(int argc, char **argv)
 
if (gelf_getehdr(elf, ) == NULL) {
warnx("gelf_getehdr: %s", elf_errmsg(-1));
+   retval = 1;
+   goto fail;
+   }
+   /*
+* XXX need to support cross-endian operation, but for now
+* exit on error rather than misbehaving.
+*/
+   if (ehdr.e_ident[EI_DATA] != SUPPORTED_ENDIAN) {
+   warnx("file endianness must match host");
retval = 1;
goto fail;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352808 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 18:49:13 2019
New Revision: 352808
URL: https://svnweb.freebsd.org/changeset/base/352808

Log:
  controlelf: simplify feature string parsing
  
  Also add error handling on failure to seek/write updated value.

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 18:43:36 2019
(r352807)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 18:49:13 2019
(r352808)
@@ -56,7 +56,7 @@ static void usage(void);
 
 struct ControlFeatures {
const char *alias;
-   unsigned long featureVal;
+   unsigned long value;
const char *desc;
 };
 
@@ -189,30 +189,19 @@ usage(void)
 static bool
 convert_to_feature_val(char *feature_str, u_int32_t *feature_val)
 {
-   char *feature_input, *feature;
+   char *feature;
int i, len;
u_int32_t input;
-   bool add, set;
+   char operation;
 
-   add = set = false;
input = 0;
-
-   if (feature_str[0] == '+')
-   add = true;
-   else if (feature_str[0] == '=')
-   set = true;
-   else if (feature_str[0] != '-') {
-   warnx("'%c' not an operator - use '+', '-', '='",
-   feature_str[0]);
-   return (false);
-   }
-
-   feature_input = feature_str + 1;
+   operation = *feature_str;
+   feature_str++;
len = nitems(featurelist);
-   while ((feature = strsep(_input, ",")) != NULL) {
+   while ((feature = strsep(_str, ",")) != NULL) {
for (i = 0; i < len; ++i) {
if (strcmp(featurelist[i].alias, feature) == 0) {
-   input |= featurelist[i].featureVal;
+   input |= featurelist[i].value;
break;
}
}
@@ -222,12 +211,16 @@ convert_to_feature_val(char *feature_str, u_int32_t *f
}
}
 
-   if (add) {
+   if (operation == '+') {
*feature_val |= input;
-   } else if (set) {
+   } else if (operation == '=') {
*feature_val = input;
+   } else if (operation == '-') {
+   *feature_val &= ~input;
} else {
-   *feature_val -= (*feature_val) & input;
+   warnx("'%c' not an operator - use '+', '-', '='",
+   feature_str[0]);
+   return (false);
}
return (true);
 }
@@ -246,8 +239,12 @@ edit_file_features(Elf *elf, int phcount, int fd, char
if (!convert_to_feature_val(val, ))
return (false);
 
-   lseek(fd, off, SEEK_SET);
-   write(fd, , sizeof(u_int32_t));
+   if (lseek(fd, off, SEEK_SET) == -1 ||
+   write(fd, , sizeof(features)) <
+   (ssize_t)sizeof(features)) {
+   warnx("error writing feature value");
+   return (false);
+   }
return (true);
 }
 
@@ -277,7 +274,7 @@ print_file_features(Elf *elf, int phcount, int fd, cha
printf("%s\t\t'%s' is ", featurelist[i].alias,
featurelist[i].desc);
 
-   if ((featurelist[i].featureVal & features) == 0)
+   if ((featurelist[i].value & features) == 0)
printf("un");
 
printf("set.\n");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r352795 - head/lib/libc/sys

2019-09-27 Thread Konstantin Belousov
On Fri, Sep 27, 2019 at 08:32:20PM +0200, Mateusz Guzik wrote:
> On 9/27/19, Warner Losh  wrote:
> > Author: imp
> > Date: Fri Sep 27 16:11:47 2019
> > New Revision: 352795
> > URL: https://svnweb.freebsd.org/changeset/base/352795
> >
> > Log:
> >   Document varadic args as int, since you can't have short varadic args
> > (they are
> >   promoted to ints).
> >
> >   - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
> >   - `openat` takes variadic args
> >   - variadic args cannot be 16-bit, and indeed the code uses int
> >   - the manpage currently kinda implies the argument is 16-bit by saying
> > `mode_t`
> >
> >   Prompted by Rust things: https://github.com/tailhook/openat/issues/21
> >   Submitted by: Greg V at unrelenting
> >   Differential Revision: https://reviews.freebsd.org/D21816
> >
> > Modified:
> >   head/lib/libc/sys/mq_open.2
> >   head/lib/libc/sys/open.2
> >
> > Modified: head/lib/libc/sys/mq_open.2
> > ==
> > --- head/lib/libc/sys/mq_open.2 Fri Sep 27 15:28:30 2019
> > (r352794)
> > +++ head/lib/libc/sys/mq_open.2 Fri Sep 27 16:11:47 2019
> > (r352795)
> > @@ -133,7 +133,7 @@ Create a message queue.
> >  It requires two additional arguments:
> >  .Fa mode ,
> >  which is of type
> > -.Vt mode_t ,
> > +.Vt int ,
> >  and
> >  .Fa attr ,
> >  which is a pointer to an
> >
> > Modified: head/lib/libc/sys/open.2
> > ==
> > --- head/lib/libc/sys/open.2Fri Sep 27 15:28:30 2019
> > (r352794)
> > +++ head/lib/libc/sys/open.2Fri Sep 27 16:11:47 2019
> > (r352795)
> > @@ -61,7 +61,7 @@ In this case
> >  and
> >  .Fn openat
> >  require an additional argument
> > -.Fa "mode_t mode" ,
> > +.Fa "int mode" ,
> >  and the file is created with mode
> >  .Fa mode
> >  as described in
> >
> 
> But opengroup says it is mode_t. Perhaps it is mode_t which needs
> to be changed?

Yes, users must pass mode_t, and the man page is written for users.
Implementation needs to be aware of the implicit promotion and handle
it accordingly.

In theory, mode_t might be wider than int.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352807 - in head/sys: amd64/amd64 amd64/vmm arm/arm arm64/arm64 i386/i386 kern mips/mips powerpc/powerpc riscv/riscv sparc64/sparc64 sys vm

2019-09-27 Thread Konstantin Belousov
Author: kib
Date: Fri Sep 27 18:43:36 2019
New Revision: 352807
URL: https://svnweb.freebsd.org/changeset/base/352807

Log:
  Improve MD page fault handlers.
  
  Centralize calculation of signal and ucode delivered on unhandled page
  fault in new function vm_fault_trap().  MD trap_pfault() now almost
  always uses the signal numbers and error codes calculated in
  consistent MI way.
  
  This introduces the protection fault compatibility sysctls to all
  non-x86 architectures which did not have that bug, but apparently they
  were already much more wrong in selecting delivered signals on
  protection violations.
  
  Change the delivered signal for accesses to mapped area after the
  backing object was truncated.  According to POSIX description for
  mmap(2):
 The system shall always zero-fill any partial page at the end of an
 object. Further, the system shall never write out any modified
 portions of the last page of an object which are beyond its
 end. References within the address range starting at pa and
 continuing for len bytes to whole pages following the end of an
 object shall result in delivery of a SIGBUS signal.
  
 An implementation may generate SIGBUS signals when a reference
 would cause an error in the mapped object, such as out-of-space
 condition.
  Adjust according to the description, keeping the existing
  compatibility code for SIGSEGV/SIGBUS on protection failures.
  
  For situations where kernel cannot handle page fault due to resource
  limit enforcement, SIGBUS with a new error code BUS_OBJERR is
  delivered.  Also, provide a new error code SEGV_PKUERR for SIGSEGV on
  amd64 due to protection key access violation.
  
  vm_fault_hold() is renamed to vm_fault().  Fixed some nits in
  trap_pfault()s like mis-interpreting Mach errors as errnos.  Removed
  unneeded truncations of the fault addresses reported by hardware.
  
  PR:   211924
  Reviewed by:  alc
  Discussed with:   jilles, markj
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D21566

Modified:
  head/sys/amd64/amd64/trap.c
  head/sys/amd64/vmm/vmm.c
  head/sys/arm/arm/trap-v4.c
  head/sys/arm/arm/trap-v6.c
  head/sys/arm64/arm64/trap.c
  head/sys/i386/i386/trap.c
  head/sys/kern/sys_process.c
  head/sys/mips/mips/trap.c
  head/sys/powerpc/powerpc/trap.c
  head/sys/riscv/riscv/trap.c
  head/sys/sparc64/sparc64/trap.c
  head/sys/sys/signal.h
  head/sys/vm/vm_extern.h
  head/sys/vm/vm_fault.c
  head/sys/vm/vm_map.c
  head/sys/vm/vm_param.h

Modified: head/sys/amd64/amd64/trap.c
==
--- head/sys/amd64/amd64/trap.c Fri Sep 27 18:39:05 2019(r352806)
+++ head/sys/amd64/amd64/trap.c Fri Sep 27 18:43:36 2019(r352807)
@@ -111,7 +111,7 @@ void __noinline trap(struct trapframe *frame);
 void trap_check(struct trapframe *frame);
 void dblfault_handler(struct trapframe *frame);
 
-static int trap_pfault(struct trapframe *, int);
+static int trap_pfault(struct trapframe *, bool, int *, int *);
 static void trap_fatal(struct trapframe *, vm_offset_t);
 #ifdef KDTRACE_HOOKS
 static bool trap_user_dtrace(struct trapframe *,
@@ -155,10 +155,6 @@ static const char *const trap_msg[] = {
[T_DTRACE_RET] ="DTrace pid return trap",
 };
 
-static int prot_fault_translation;
-SYSCTL_INT(_machdep, OID_AUTO, prot_fault_translation, CTLFLAG_RWTUN,
-_fault_translation, 0,
-"Select signal to deliver on protection fault");
 static int uprintf_signal;
 SYSCTL_INT(_machdep, OID_AUTO, uprintf_signal, CTLFLAG_RWTUN,
 _signal, 0,
@@ -192,14 +188,11 @@ trap(struct trapframe *frame)
struct thread *td;
struct proc *p;
register_t addr, dr6;
-   int signo, ucode;
+   int pf, signo, ucode;
u_int type;
 
td = curthread;
p = td->td_proc;
-   signo = 0;
-   ucode = 0;
-   addr = 0;
dr6 = 0;
 
VM_CNT_INC(v_trap);
@@ -345,47 +338,18 @@ trap(struct trapframe *frame)
 
case T_PAGEFLT: /* page fault */
/*
-* Emulator can take care about this trap?
+* Can emulator handle this trap?
 */
if (*p->p_sysent->sv_trap != NULL &&
(*p->p_sysent->sv_trap)(td) == 0)
return;
 
-   addr = frame->tf_addr;
-   signo = trap_pfault(frame, TRUE);
-   if (signo == -1)
+   pf = trap_pfault(frame, true, , );
+   if (pf == -1)
return;
-   if (signo == 0)
+   if (pf == 0)
goto userret;
-   if (signo == SIGSEGV) {
-   ucode = 

svn commit: r352806 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 18:39:05 2019
New Revision: 352806
URL: https://svnweb.freebsd.org/changeset/base/352806

Log:
  controlelf: tidy up option parsing
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 17:28:25 2019
(r352805)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 18:39:05 2019
(r352806)
@@ -65,7 +65,7 @@ static struct ControlFeatures featurelist[] = {
{ "protmax",NT_FREEBSD_FCTL_PROTMAX_DISABLE,"Disable implicit 
PROT_MAX" },
 };
 
-static struct option controlelf_longopts[] = {
+static struct option long_opts[] = {
{ "help",   no_argument,NULL,   'h' },
{ NULL, 0,  NULL,   0 }
 };
@@ -76,38 +76,36 @@ main(int argc, char **argv)
GElf_Ehdr ehdr;
Elf *elf;
Elf_Kind kind;
-   int ch, fd, listed, editfeatures, retval;
+   int ch, fd, editfeatures, retval;
char *features;
+   bool lflag;
 
-   listed = 0;
+   lflag = 0;
editfeatures = 0;
retval = 0;
 
if (elf_version(EV_CURRENT) == EV_NONE)
errx(EXIT_FAILURE, "elf_version error");
 
-   while ((ch = getopt_long(argc, argv, "hle:", controlelf_longopts,
-   NULL)) != -1) {
+   while ((ch = getopt_long(argc, argv, "hle:", long_opts, NULL)) != -1) {
switch (ch) {
case 'l':
print_features();
-   listed = 1;
+   lflag = true;
break;
case 'e':
features = optarg;
editfeatures = 1;
break;
case 'h':
-   usage();
-   break;
default:
usage();
}
}
argc -= optind;
argv += optind;
-   if (!argc) {
-   if (listed)
+   if (argc == 0) {
+   if (lflag)
exit(0);
else {
warnx("no file(s) specified");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r352795 - head/lib/libc/sys

2019-09-27 Thread Mateusz Guzik
On 9/27/19, Warner Losh  wrote:
> Author: imp
> Date: Fri Sep 27 16:11:47 2019
> New Revision: 352795
> URL: https://svnweb.freebsd.org/changeset/base/352795
>
> Log:
>   Document varadic args as int, since you can't have short varadic args
> (they are
>   promoted to ints).
>
>   - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
>   - `openat` takes variadic args
>   - variadic args cannot be 16-bit, and indeed the code uses int
>   - the manpage currently kinda implies the argument is 16-bit by saying
> `mode_t`
>
>   Prompted by Rust things: https://github.com/tailhook/openat/issues/21
>   Submitted by: Greg V at unrelenting
>   Differential Revision: https://reviews.freebsd.org/D21816
>
> Modified:
>   head/lib/libc/sys/mq_open.2
>   head/lib/libc/sys/open.2
>
> Modified: head/lib/libc/sys/mq_open.2
> ==
> --- head/lib/libc/sys/mq_open.2   Fri Sep 27 15:28:30 2019
> (r352794)
> +++ head/lib/libc/sys/mq_open.2   Fri Sep 27 16:11:47 2019
> (r352795)
> @@ -133,7 +133,7 @@ Create a message queue.
>  It requires two additional arguments:
>  .Fa mode ,
>  which is of type
> -.Vt mode_t ,
> +.Vt int ,
>  and
>  .Fa attr ,
>  which is a pointer to an
>
> Modified: head/lib/libc/sys/open.2
> ==
> --- head/lib/libc/sys/open.2  Fri Sep 27 15:28:30 2019(r352794)
> +++ head/lib/libc/sys/open.2  Fri Sep 27 16:11:47 2019(r352795)
> @@ -61,7 +61,7 @@ In this case
>  and
>  .Fn openat
>  require an additional argument
> -.Fa "mode_t mode" ,
> +.Fa "int mode" ,
>  and the file is created with mode
>  .Fa mode
>  as described in
>

But opengroup says it is mode_t. Perhaps it is mode_t which needs
to be changed?

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


svn commit: r352805 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 17:28:25 2019
New Revision: 352805
URL: https://svnweb.freebsd.org/changeset/base/352805

Log:
  controlelf: add protmax control
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 17:11:21 2019
(r352804)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 17:28:25 2019
(r352805)
@@ -62,6 +62,7 @@ struct ControlFeatures {
 
 static struct ControlFeatures featurelist[] = {
{ "aslr",   NT_FREEBSD_FCTL_ASLR_DISABLE,   "Disable ASLR" },
+   { "protmax",NT_FREEBSD_FCTL_PROTMAX_DISABLE,"Disable implicit 
PROT_MAX" },
 };
 
 static struct option controlelf_longopts[] = {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352804 - head/usr.bin/top

2019-09-27 Thread Dimitry Andric
Author: dim
Date: Fri Sep 27 17:11:21 2019
New Revision: 352804
URL: https://svnweb.freebsd.org/changeset/base/352804

Log:
  Correct the final argument name in the top(1) manpage.
  
  The description talks about 'number', while the final argument was
  'count'.  Since 'count' is already used for the count of displays,
  change the final argument name to 'number'.
  
  MFC after:3 days

Modified:
  head/usr.bin/top/top.1

Modified: head/usr.bin/top/top.1
==
--- head/usr.bin/top/top.1  Fri Sep 27 16:57:32 2019(r352803)
+++ head/usr.bin/top/top.1  Fri Sep 27 17:11:21 2019(r352804)
@@ -15,7 +15,7 @@
 .Op Fl s Ar time
 .Op Fl o Ar field
 .Op Fl p Ar pid
-.Op Ar count
+.Op Ar number
 .Sh DESCRIPTION
 .Nm
 displays the top
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352803 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 16:57:32 2019
New Revision: 352803
URL: https://svnweb.freebsd.org/changeset/base/352803

Log:
  controlelf: some style(9) cleanup
  
  Submitted by: clang-format

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 16:46:08 2019
(r352802)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 16:57:32 2019
(r352803)
@@ -14,7 +14,7 @@
  * 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
@@ -47,11 +47,11 @@
 
 __FBSDID("$FreeBSD$");
 
-static bool convert_to_feature_val(char*, u_int32_t*);
-static bool edit_file_features(Elf *, int, int, char*);
+static bool convert_to_feature_val(char *, u_int32_t *);
+static bool edit_file_features(Elf *, int, int, char *);
 static bool get_file_features(Elf *, int, int, u_int32_t *, u_int64_t *);
 static void print_features(void);
-static bool print_file_features(Elf *, int, int, char*);
+static bool print_file_features(Elf *, int, int, char *);
 static void usage(void);
 
 struct ControlFeatures {
@@ -61,12 +61,12 @@ struct ControlFeatures {
 };
 
 static struct ControlFeatures featurelist[] = {
-   { "aslr",   NT_FREEBSD_FCTL_ASLR_DISABLE,   
"Disable ASLR" }
+   { "aslr",   NT_FREEBSD_FCTL_ASLR_DISABLE,   "Disable ASLR" },
 };
 
 static struct option controlelf_longopts[] = {
-   { "help",   no_argument,NULL,   'h' },
-   { NULL, 0,  NULL,   0   }
+   { "help",   no_argument,NULL,   'h' },
+   { NULL, 0,  NULL,   0 }
 };
 
 int
@@ -117,8 +117,8 @@ main(int argc, char **argv)
while (argc) {
elf = NULL;
 
-   if ((fd = open(argv[0], editfeatures ? O_RDWR :
-   O_RDONLY, 0)) < 0) {
+   if ((fd = open(argv[0],
+   editfeatures ? O_RDWR : O_RDONLY, 0)) < 0) {
warn("error opening file %s", argv[0]);
retval = 1;
goto fail;
@@ -134,8 +134,7 @@ main(int argc, char **argv)
if (kind == ELF_K_AR)
warnx("file '%s' is an archive", argv[0]);
else
-   warnx("file '%s' is not an ELF file",
-   argv[0]);
+   warnx("file '%s' is not an ELF file", argv[0]);
retval = 1;
goto fail;
}
@@ -147,11 +146,13 @@ main(int argc, char **argv)
}
 
if (!editfeatures) {
-   if (!print_file_features(elf, ehdr.e_phnum, fd, 
argv[0])) {
+   if (!print_file_features(elf, ehdr.e_phnum, fd,
+   argv[0])) {
retval = 1;
goto fail;
}
-   } else if (!edit_file_features(elf, ehdr.e_phnum, fd, 
features)) {
+   } else if (!edit_file_features(elf, ehdr.e_phnum, fd,
+   features)) {
retval = 1;
goto fail;
}
@@ -169,7 +170,8 @@ fail:
return (retval);
 }
 
-#defineUSAGE_MESSAGE   "\
+#define USAGE_MESSAGE \
+   "\
 Usage: %s [options] file...\n\
   Set or display the control features for an ELF object.\n\n\
   Supported options are:\n\
@@ -186,7 +188,7 @@ usage(void)
 }
 
 static bool
-convert_to_feature_val(char* feature_str, u_int32_t* feature_val)
+convert_to_feature_val(char *feature_str, u_int32_t *feature_val)
 {
char *feature_input, *feature;
int i, len;
@@ -262,7 +264,8 @@ print_features(void)
 }
 
 static bool
-print_file_features(Elf *elf, int phcount, int fd, char *filename) {
+print_file_features(Elf *elf, int phcount, int fd, char *filename)
+{
u_int32_t features;
unsigned long i;
 
@@ -284,7 +287,8 @@ print_file_features(Elf *elf, int phcount, int fd, cha
 }
 
 static bool
-get_file_features(Elf *elf, int phcount, int fd, u_int32_t *features, 
u_int64_t *off)
+get_file_features(Elf *elf, int phcount, int fd, u_int32_t *features,
+u_int64_t *off)
 {
GElf_Phdr phdr;
Elf_Note note;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, 

svn commit: r352802 - head/sys/vm

2019-09-27 Thread Mark Johnston
Author: markj
Date: Fri Sep 27 16:46:08 2019
New Revision: 352802
URL: https://svnweb.freebsd.org/changeset/base/352802

Log:
  Fix a race in vm_page_swapqueue().
  
  vm_page_swapqueue() atomically transitions a page between queues.  To do
  so, it must hold the page queue lock for the old queue.  However, once
  the queue index has been updated, the queue lock no longer protects the
  page's queue state.  Thus, we must speculatively remove the page from
  the old queue before committing the queue state update, and roll back if
  the update fails.
  
  Reported and tested by:   pho
  Reviewed by:  kib
  Sponsored by: Intel, Netflix
  Differential Revision:https://reviews.freebsd.org/D21791

Modified:
  head/sys/vm/vm_page.c

Modified: head/sys/vm/vm_page.c
==
--- head/sys/vm/vm_page.c   Fri Sep 27 16:44:29 2019(r352801)
+++ head/sys/vm/vm_page.c   Fri Sep 27 16:46:08 2019(r352802)
@@ -3462,27 +3462,58 @@ void
 vm_page_swapqueue(vm_page_t m, uint8_t oldq, uint8_t newq)
 {
struct vm_pagequeue *pq;
+   vm_page_t next;
+   bool queued;
 
KASSERT(oldq < PQ_COUNT && newq < PQ_COUNT && oldq != newq,
("vm_page_swapqueue: invalid queues (%d, %d)", oldq, newq));
-   KASSERT((m->oflags & VPO_UNMANAGED) == 0,
-   ("vm_page_swapqueue: page %p is unmanaged", m));
vm_page_assert_locked(m);
 
-   /*
-* Atomically update the queue field and set PGA_REQUEUE while
-* ensuring that PGA_DEQUEUE has not been set.
-*/
pq = _pagequeue_domain(m)->vmd_pagequeues[oldq];
vm_pagequeue_lock(pq);
-   if (!vm_page_pqstate_cmpset(m, oldq, newq, PGA_DEQUEUE, PGA_REQUEUE)) {
+
+   /*
+* The physical queue state might change at any point before the page
+* queue lock is acquired, so we must verify that we hold the correct
+* lock before proceeding.
+*/
+   if (__predict_false(m->queue != oldq)) {
vm_pagequeue_unlock(pq);
return;
}
-   if ((m->aflags & PGA_ENQUEUED) != 0) {
-   vm_pagequeue_remove(pq, m);
+
+   /*
+* Once the queue index of the page changes, there is nothing
+* synchronizing with further updates to the physical queue state.
+* Therefore we must remove the page from the queue now in anticipation
+* of a successful commit, and be prepared to roll back.
+*/
+   if (__predict_true((m->aflags & PGA_ENQUEUED) != 0)) {
+   next = TAILQ_NEXT(m, plinks.q);
+   TAILQ_REMOVE(>pq_pl, m, plinks.q);
vm_page_aflag_clear(m, PGA_ENQUEUED);
+   queued = true;
+   } else {
+   queued = false;
}
+
+   /*
+* Atomically update the queue field and set PGA_REQUEUE while
+* ensuring that PGA_DEQUEUE has not been set.
+*/
+   if (__predict_false(!vm_page_pqstate_cmpset(m, oldq, newq, PGA_DEQUEUE,
+   PGA_REQUEUE))) {
+   if (queued) {
+   vm_page_aflag_set(m, PGA_ENQUEUED);
+   if (next != NULL)
+   TAILQ_INSERT_BEFORE(next, m, plinks.q);
+   else
+   TAILQ_INSERT_TAIL(>pq_pl, m, plinks.q);
+   }
+   vm_pagequeue_unlock(pq);
+   return;
+   }
+   vm_pagequeue_cnt_dec(pq);
vm_pagequeue_unlock(pq);
vm_page_pqbatch_submit(m, newq);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352801 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 16:44:29 2019
New Revision: 352801
URL: https://svnweb.freebsd.org/changeset/base/352801

Log:
  controlelf: install standard BSD 2 clause license
  
  Reported by:  kaktus
  Sponsored by: The FreeBSD Foundation

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 16:41:34 2019
(r352800)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 16:44:29 2019
(r352801)
@@ -1,5 +1,5 @@
 /*-
- * SPDX-License-Identifier: BSD-3-Clause
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
  * Copyright (c) 2019 The FreeBSD Foundation.
  *
@@ -10,22 +10,22 @@
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer
- *in this position and unchanged.
+ *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 ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * 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 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352800 - head/sys/vm

2019-09-27 Thread Mark Johnston
Author: markj
Date: Fri Sep 27 16:41:34 2019
New Revision: 352800
URL: https://svnweb.freebsd.org/changeset/base/352800

Log:
  Fix object locking in vm_object_unwire() after r352174.
  
  Now, vm_page_busy_sleep() expects the page's object to be locked.
  vm_object_unwire() does some unusual lazy locking of the object chain
  and keeps objects locked until a busy page is encountered or the loop
  terminates.  When a busy page is encountered, rather than unlocking all
  but the "bottom-level" object, we must instead skip the object to which
  "tm" belongs.
  
  Reported and tested by:   pho
  Reviewed by:  kib
  Discussed with:   jeff
  Sponsored by: Intel, Netflix
  Differential Revision:https://reviews.freebsd.org/D21790

Modified:
  head/sys/vm/vm_object.c

Modified: head/sys/vm/vm_object.c
==
--- head/sys/vm/vm_object.c Fri Sep 27 16:35:08 2019(r352799)
+++ head/sys/vm/vm_object.c Fri Sep 27 16:41:34 2019(r352800)
@@ -2169,10 +2169,11 @@ again:
m = TAILQ_NEXT(m, listq);
}
if (vm_page_xbusied(tm)) {
-   for (tobject = object; locked_depth > 1;
+   for (tobject = object; locked_depth >= 1;
locked_depth--) {
t1object = tobject->backing_object;
-   VM_OBJECT_RUNLOCK(tobject);
+   if (tm->object != tobject)
+   VM_OBJECT_RUNLOCK(tobject);
tobject = t1object;
}
vm_page_busy_sleep(tm, "unwbo", true);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r352757 - in head: lib/libc/sys lib/libregex/tests stand/lua tests/sys/kern

2019-09-27 Thread Rodney W. Grimes
> Author: kevans
> Date: Thu Sep 26 16:19:22 2019
> New Revision: 352757
> URL: https://svnweb.freebsd.org/changeset/base/352757
> 
> Log:
>   Further normalize copyright notices
>   
>   - s/C/c/ where I've been inconsistent about it
>   - +SPDX tags
>   - Remove "All rights reserved" where possible
>   
>   Requested by:   rgrimes (all rights reserved)

Thank you Kyle!

> Modified:
>   head/lib/libc/sys/shm_open.c
>   head/lib/libregex/tests/libregex_test.sh
>   head/stand/lua/config.lua
>   head/stand/lua/menu.lua
>   head/stand/lua/password.lua

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


svn commit: r352799 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 16:35:08 2019
New Revision: 352799
URL: https://svnweb.freebsd.org/changeset/base/352799

Log:
  controlelf: clean up warnings
  
  - use explicit ELF note name when not found
  - no trailing . on warnings
  - no \n
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/tools/tools/controlelf/controlelf.c

Modified: head/tools/tools/controlelf/controlelf.c
==
--- head/tools/tools/controlelf/controlelf.cFri Sep 27 16:32:44 2019
(r352798)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 16:35:08 2019
(r352799)
@@ -132,9 +132,9 @@ main(int argc, char **argv)
 
if ((kind = elf_kind(elf)) != ELF_K_ELF) {
if (kind == ELF_K_AR)
-   warnx("file '%s' is an archive.", argv[0]);
+   warnx("file '%s' is an archive", argv[0]);
else
-   warnx("file '%s' is not an ELF file.",
+   warnx("file '%s' is not an ELF file",
argv[0]);
retval = 1;
goto fail;
@@ -201,7 +201,7 @@ convert_to_feature_val(char* feature_str, u_int32_t* f
else if (feature_str[0] == '=')
set = true;
else if (feature_str[0] != '-') {
-   warnx("'%c' is not an operator. Use instead '+', '-', '='.",
+   warnx("'%c' not an operator - use '+', '-', '='",
feature_str[0]);
return (false);
}
@@ -216,7 +216,7 @@ convert_to_feature_val(char* feature_str, u_int32_t* f
}
}
if (i == len) {
-   warnx("%s is not a valid feature.", feature);
+   warnx("%s is not a valid feature", feature);
return (false);
}
}
@@ -238,7 +238,7 @@ edit_file_features(Elf *elf, int phcount, int fd, char
u_int64_t off;
 
if (!get_file_features(elf, phcount, fd, , )) {
-   warnx("No control features note on the file.\n");
+   warnx("NT_FREEBSD_FEATURE_CTL note not found");
return (false);
}
 
@@ -327,7 +327,7 @@ get_file_features(Elf *elf, int phcount, int fd, u_int
namesz = roundup2(note.n_namesz, 4);
name = malloc(namesz);
if (name == NULL) {
-   warn("malloc() failed.\n");
+   warn("malloc() failed.");
return (false);
}
descsz = roundup2(note.n_descsz, 4);
@@ -339,7 +339,7 @@ get_file_features(Elf *elf, int phcount, int fd, u_int
note.n_type != NT_FREEBSD_FEATURE_CTL) {
/* Not the right note. Skip the description */
if (lseek(fd, descsz, SEEK_CUR) < 0) {
-   warn("lseek() failed.\n");
+   warn("lseek() failed.");
free(name);
return (false);
}
@@ -360,7 +360,7 @@ get_file_features(Elf *elf, int phcount, int fd, u_int
 *  descriptor. This should respect descsz.
 */
if (note.n_descsz > sizeof(u_int32_t))
-   warnx("Feature note is bigger than expected.");
+   warnx("Feature note is bigger than expected");
read(fd, features, sizeof(u_int32_t));
if (off != NULL)
*off = phdr.p_offset + read_total;
@@ -369,6 +369,6 @@ get_file_features(Elf *elf, int phcount, int fd, u_int
}
}
 
-   warnx("Couldn't find a note header with control feature note.");
+   warnx("NT_FREEBSD_FEATURE_CTL note not found");
return (false);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352798 - in head/sys: dev/nvdimm modules/nvdimm

2019-09-27 Thread Conrad Meyer
Author: cem
Date: Fri Sep 27 16:32:44 2019
New Revision: 352798
URL: https://svnweb.freebsd.org/changeset/base/352798

Log:
  nvdimm(4): Extract ACPI root bus driver
  
  No functional change intended.
  
  The intent is to add a "legacy" e820 pmem newbus bus for nvdimm device in a
  subsequent revision, and it's a little more clear if the parent buses get
  independent source files.
  
  Quite a lot of ACPI-specific logic is left in nvdimm.c; disentangling that
  is a much larger change (and probably not especially useful).
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D21813

Added:
  head/sys/dev/nvdimm/nvdimm_acpi.c
 - copied, changed from r352792, head/sys/dev/nvdimm/nvdimm.c
Modified:
  head/sys/dev/nvdimm/nvdimm.c
  head/sys/dev/nvdimm/nvdimm_var.h
  head/sys/modules/nvdimm/Makefile

Modified: head/sys/dev/nvdimm/nvdimm.c
==
--- head/sys/dev/nvdimm/nvdimm.cFri Sep 27 16:27:52 2019
(r352797)
+++ head/sys/dev/nvdimm/nvdimm.cFri Sep 27 16:32:44 2019
(r352798)
@@ -43,10 +43,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+
 #include 
 #include 
 #include 
 #include 
+
 #include 
 
 #define _COMPONENT ACPI_OEM
@@ -59,7 +61,6 @@ static struct uuid intel_nvdimm_dsm_uuid =
 #define INTEL_NVDIMM_DSM_GET_LABEL_DATA 5
 
 static devclass_t nvdimm_devclass;
-static devclass_t nvdimm_root_devclass;
 MALLOC_DEFINE(M_NVDIMM, "nvdimm", "NVDIMM driver memory");
 
 static int
@@ -325,8 +326,7 @@ nvdimm_attach(device_t dev)
 
nv = device_get_softc(dev);
handle = nvdimm_root_get_acpi_handle(dev);
-   if (handle == NULL)
-   return (EINVAL);
+   MPASS(handle != NULL);
nv->nv_dev = dev;
nv->nv_handle = nvdimm_root_get_device_handle(dev);
 
@@ -380,204 +380,6 @@ nvdimm_resume(device_t dev)
return (0);
 }
 
-static ACPI_STATUS
-find_dimm(ACPI_HANDLE handle, UINT32 nesting_level, void *context,
-void **return_value)
-{
-   ACPI_DEVICE_INFO *device_info;
-   ACPI_STATUS status;
-
-   status = AcpiGetObjectInfo(handle, _info);
-   if (ACPI_FAILURE(status))
-   return_ACPI_STATUS(AE_ERROR);
-   if (device_info->Address == (uintptr_t)context) {
-   *(ACPI_HANDLE *)return_value = handle;
-   return_ACPI_STATUS(AE_CTRL_TERMINATE);
-   }
-   return_ACPI_STATUS(AE_OK);
-}
-
-static ACPI_HANDLE
-get_dimm_acpi_handle(ACPI_HANDLE root_handle, nfit_handle_t adr)
-{
-   ACPI_HANDLE res;
-   ACPI_STATUS status;
-
-   res = NULL;
-   status = AcpiWalkNamespace(ACPI_TYPE_DEVICE, root_handle, 1, find_dimm,
-   NULL, (void *)(uintptr_t)adr, );
-   if (ACPI_FAILURE(status))
-   res = NULL;
-   return (res);
-}
-
-static int
-nvdimm_root_create_devs(device_t dev, ACPI_TABLE_NFIT *nfitbl)
-{
-   ACPI_HANDLE root_handle, dimm_handle;
-   device_t child;
-   nfit_handle_t *dimm_ids, *dimm;
-   uintptr_t *ivars;
-   int num_dimm_ids;
-
-   root_handle = acpi_get_handle(dev);
-   acpi_nfit_get_dimm_ids(nfitbl, _ids, _dimm_ids);
-   for (dimm = dimm_ids; dimm < dimm_ids + num_dimm_ids; dimm++) {
-   dimm_handle = get_dimm_acpi_handle(root_handle, *dimm);
-   child = BUS_ADD_CHILD(dev, 100, "nvdimm", -1);
-   if (child == NULL) {
-   device_printf(dev, "failed to create nvdimm\n");
-   return (ENXIO);
-   }
-   ivars = mallocarray(NVDIMM_ROOT_IVAR_MAX, sizeof(uintptr_t),
-   M_NVDIMM, M_ZERO | M_WAITOK);
-   device_set_ivars(child, ivars);
-   nvdimm_root_set_acpi_handle(child, dimm_handle);
-   nvdimm_root_set_device_handle(child, *dimm);
-   }
-   free(dimm_ids, M_NVDIMM);
-   return (0);
-}
-
-static int
-nvdimm_root_create_spas(struct nvdimm_root_dev *dev, ACPI_TABLE_NFIT *nfitbl)
-{
-   ACPI_NFIT_SYSTEM_ADDRESS **spas, **spa;
-   struct SPA_mapping *spa_mapping;
-   enum SPA_mapping_type spa_type;
-   int error, num_spas;
-
-   error = 0;
-   acpi_nfit_get_spa_ranges(nfitbl, , _spas);
-   for (spa = spas; spa < spas + num_spas; spa++) {
-   spa_type = nvdimm_spa_type_from_uuid(
-   (struct uuid *)(*spa)->RangeGuid);
-   if (spa_type == SPA_TYPE_UNKNOWN)
-   continue;
-   spa_mapping = malloc(sizeof(struct SPA_mapping), M_NVDIMM,
-   M_WAITOK | M_ZERO);
-   error = nvdimm_spa_init(spa_mapping, *spa, spa_type);
-   if (error != 0) {
-   nvdimm_spa_fini(spa_mapping);
-   free(spa, M_NVDIMM);
-   break;
-   }
-   nvdimm_create_namespaces(spa_mapping, nfitbl);
-  

svn commit: r352797 - head/tools/tools/controlelf

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 16:27:52 2019
New Revision: 352797
URL: https://svnweb.freebsd.org/changeset/base/352797

Log:
  Add tool to modify ELF binary feature control bits
  
  This will allow feature control bits (e.g. for ASLR, PROT_MAX) to be
  inspected or modified.
  
  Some clean-up and additional work is likely still required, but we can
  iterate on this in the tree.
  
  Submitted by: Bora Özarslan 
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D19290

Added:
  head/tools/tools/controlelf/
  head/tools/tools/controlelf/Makefile   (contents, props changed)
  head/tools/tools/controlelf/controlelf.1   (contents, props changed)
  head/tools/tools/controlelf/controlelf.c   (contents, props changed)

Added: head/tools/tools/controlelf/Makefile
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/tools/controlelf/MakefileFri Sep 27 16:27:52 2019
(r352797)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+ELFTCDIR=  ${SRCTOP}/contrib/elftoolchain
+
+PROG=  controlelf
+SRCS=  controlelf.c
+
+LIBADD=elftc elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+WARNS?=6
+
+.include 

Added: head/tools/tools/controlelf/controlelf.1
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/tools/controlelf/controlelf.1Fri Sep 27 16:27:52 2019
(r352797)
@@ -0,0 +1,92 @@
+.\" Copyright 2019 The FreeBSD Foundation.
+.\"
+.\" This software was developed by Bora Ozarslan under sponsorship from
+.\" the FreeBSD Foundation.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
+.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 21, 2019
+.Dt CONTROLELF 1
+.Os
+.Sh NAME
+.Nm controlelf
+.Nd change an ELF binary's control features
+.Sh SYNOPSIS
+.Nm
+.Op Fl h | Fl -help
+.Op Fl l
+.Op Fl e Ar featurelist
+.Ar
+.Sh DESCRIPTION
+The
+.Nm
+utility modifies an ELF binary to change it's control features.
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl h | Fl -help
+Print a usage message and exit.
+.It Fl l
+Writes the list of all known ELF types to standard output.
+.It Fl e Ar featurelist
+Edit features from the given comma separated list
+.Ar featurelist .
+.Ar featurelist
+starts with one of the three modes:
+.Dq Li +
+to turn on the features,
+.Dq Li -
+to turn off the features,
+.Dq Li =
+to only turn on the given features.
+Followed by a comma separated features.
+.El
+.Pp
+If
+.Fl e ,
+option wasn't specified,
+.Nm
+will display the current control features for the files named by the arguments
+.Ar .
+.Sh EXIT STATUS
+Exit status is 0 on success, and 1 if the command
+fails if a file does not exist, is too short,
+or fails to find or edit features note.
+.Sh EXAMPLES
+The following is an example of a typical usage
+of the
+.Nm
+command:
+.Bd -literal -offset indent
+controlelf file
+controlelf -e +aslr file
+.Ed
+.Sh HISTORY
+The
+.Nm
+manual page first appeared in
+.Fx 13.0 .
+.Sh AUTHORS
+This manual page was written by
+.An Bora Ozarslan Mt borako.ozars...@gmail.com .

Added: head/tools/tools/controlelf/controlelf.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/tools/controlelf/controlelf.cFri Sep 27 16:27:52 2019
(r352797)
@@ -0,0 +1,374 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation.
+ *
+ * This software was developed by Bora Ozarslan under sponsorship from
+ * the 

svn commit: r352796 - head/sys/kern

2019-09-27 Thread Andrew Turner
Author: andrew
Date: Fri Sep 27 16:22:28 2019
New Revision: 352796
URL: https://svnweb.freebsd.org/changeset/base/352796

Log:
  Check the vfs option length is valid before accessing through
  
  When a VFS option passed to nmount is present but NULL the kernel will
  place an empty option in its internal list. This will have a NULL
  pointer and a length of 0. When we come to read one of these the kernel
  will try to load from the last address of virtual memory. This is
  normally invalid so will fault resulting in a kernel panic.
  
  Fix this by checking if the length is valid before dereferencing.
  
  MFC after:3 days
  Sponsored by: DARPA, AFRL

Modified:
  head/sys/kern/vfs_mount.c

Modified: head/sys/kern/vfs_mount.c
==
--- head/sys/kern/vfs_mount.c   Fri Sep 27 16:11:47 2019(r352795)
+++ head/sys/kern/vfs_mount.c   Fri Sep 27 16:22:28 2019(r352796)
@@ -646,7 +646,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, stru
 */
fstypelen = 0;
error = vfs_getopt(optlist, "fstype", (void **), );
-   if (error || fstype[fstypelen - 1] != '\0') {
+   if (error || fstypelen <= 0 || fstype[fstypelen - 1] != '\0') {
error = EINVAL;
if (errmsg != NULL)
strncpy(errmsg, "Invalid fstype", errmsg_len);
@@ -654,7 +654,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, stru
}
fspathlen = 0;
error = vfs_getopt(optlist, "fspath", (void **), );
-   if (error || fspath[fspathlen - 1] != '\0') {
+   if (error || fspathlen <= 0 || fspath[fspathlen - 1] != '\0') {
error = EINVAL;
if (errmsg != NULL)
strncpy(errmsg, "Invalid fspath", errmsg_len);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2019-09-27 Thread Warner Losh
Author: imp
Date: Fri Sep 27 16:11:47 2019
New Revision: 352795
URL: https://svnweb.freebsd.org/changeset/base/352795

Log:
  Document varadic args as int, since you can't have short varadic args (they 
are
  promoted to ints).
  
  - `mode_t` is `uint16_t` (`sys/sys/_types.h`)
  - `openat` takes variadic args
  - variadic args cannot be 16-bit, and indeed the code uses int
  - the manpage currently kinda implies the argument is 16-bit by saying 
`mode_t`
  
  Prompted by Rust things: https://github.com/tailhook/openat/issues/21
  Submitted by: Greg V at unrelenting
  Differential Revision: https://reviews.freebsd.org/D21816

Modified:
  head/lib/libc/sys/mq_open.2
  head/lib/libc/sys/open.2

Modified: head/lib/libc/sys/mq_open.2
==
--- head/lib/libc/sys/mq_open.2 Fri Sep 27 15:28:30 2019(r352794)
+++ head/lib/libc/sys/mq_open.2 Fri Sep 27 16:11:47 2019(r352795)
@@ -133,7 +133,7 @@ Create a message queue.
 It requires two additional arguments:
 .Fa mode ,
 which is of type
-.Vt mode_t ,
+.Vt int ,
 and
 .Fa attr ,
 which is a pointer to an

Modified: head/lib/libc/sys/open.2
==
--- head/lib/libc/sys/open.2Fri Sep 27 15:28:30 2019(r352794)
+++ head/lib/libc/sys/open.2Fri Sep 27 16:11:47 2019(r352795)
@@ -61,7 +61,7 @@ In this case
 and
 .Fn openat
 require an additional argument
-.Fa "mode_t mode" ,
+.Fa "int mode" ,
 and the file is created with mode
 .Fa mode
 as described in
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352792 - head/contrib/compiler-rt/lib/sanitizer_common

2019-09-27 Thread Ed Maste
Author: emaste
Date: Fri Sep 27 13:14:36 2019
New Revision: 352792
URL: https://svnweb.freebsd.org/changeset/base/352792

Log:
  compiler-rt: correct RISC-V struct_kernel_stat64_sz
  
  The value of struct_kernel_stat64_sz introduced by review D5021 for
  RISC-V was incorrect.
  
  Also add a __riscv_xlen == 64 conditional as the 32-bit ABI is not yet
  finalized.
  
  Submitted by: Luís Marques
  Differential Revision:https://reviews.freebsd.org/D21684

Modified:
  
head/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Modified: 
head/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
==
--- 
head/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h 
Fri Sep 27 10:19:28 2019(r352791)
+++ 
head/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h 
Fri Sep 27 13:14:36 2019(r352792)
@@ -79,10 +79,9 @@ namespace __sanitizer {
 #elif defined(__powerpc64__)
   const unsigned struct_kernel_stat_sz = 144;
   const unsigned struct_kernel_stat64_sz = 104;
-#elif defined(__riscv)
-  /* RISCVTODO: check that these values are correct */
+#elif defined(__riscv) && __riscv_xlen == 64
   const unsigned struct_kernel_stat_sz = 128;
-  const unsigned struct_kernel_stat64_sz = 128;
+  const unsigned struct_kernel_stat64_sz = 104;
 #elif defined(__mips__)
   const unsigned struct_kernel_stat_sz =
  SANITIZER_ANDROID ? FIRST_32_SECOND_64(104, 128) :
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352791 - head/share/misc

2019-09-27 Thread Pawel Biernacki
Author: kaktus
Date: Fri Sep 27 10:19:28 2019
New Revision: 352791
URL: https://svnweb.freebsd.org/changeset/base/352791

Log:
  Add myself (kaktus) as a src commiter.
  
  Reviewed by:  kib (mentor)
  Approved by:  kib (mentor), mjg (mentor)
  Differential Revision:https://reviews.freebsd.org/D21811

Modified:
  head/share/misc/committers-src.dot

Modified: head/share/misc/committers-src.dot
==
--- head/share/misc/committers-src.dot  Fri Sep 27 10:04:58 2019
(r352790)
+++ head/share/misc/committers-src.dot  Fri Sep 27 10:19:28 2019
(r352791)
@@ -227,6 +227,7 @@ jtl [label="Jonathan T. Looney\n...@freebsd.org\n2015/
 julian [label="Julian Elischer\njul...@freebsd.org\n1993/04/19"]
 jwd [label="John De Boskey\n...@freebsd.org\n2000/05/19"]
 kaiw [label="Kai Wang\nk...@freebsd.org\n2007/09/26"]
+kaktus [label="Pawel Biernacki\nkak...@freebsd.org\n2019/09/26"]
 kan [label="Alexander Kabaev\n...@freebsd.org\n2002/07/21"]
 karels [label="Mike Karels\nkar...@freebsd.org\n2016/06/09"]
 ken [label="Ken Merry\n...@freebsd.org\n1998/09/08"]
@@ -675,6 +676,7 @@ kib -> gjb
 kib -> jah
 kib -> jlh
 kib -> jpaetzel
+kib -> kaktus
 kib -> lulf
 kib -> melifaro
 kib -> mmel
@@ -719,6 +721,8 @@ mdf -> gleb
 mdodd -> jake
 
 mike -> das
+
+mjg -> kaktus
 
 mlaier -> benjsc
 mlaier -> dhartmei
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r352707 - in head/sys: conf kern net sys

2019-09-27 Thread Warner Losh
On Fri, Sep 27, 2019, 2:00 AM Niclas Zeising  wrote:

> On 2019-09-27 01:27, Warner Losh wrote:
> > I talked to Gleb and this will move to opt_global.h. this will fix all
> > these problems.
> >
> > Warner
> >
>
> [ trimming CC list ]
> So, in conclusion, the changes made to any out of tree kmods to handle
> this should be reverted?
>

Yes. It was a momentary blip.

Warner


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


Re: svn commit: r352707 - in head/sys: conf kern net sys

2019-09-27 Thread Niclas Zeising

On 2019-09-27 01:27, Warner Losh wrote:
I talked to Gleb and this will move to opt_global.h. this will fix all 
these problems.


Warner



[ trimming CC list ]
So, in conclusion, the changes made to any out of tree kmods to handle 
this should be reverted?

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