svn commit: r349965 - head/sys/powerpc/aim

2019-07-12 Thread Justin Hibbits
Author: jhibbits
Date: Sat Jul 13 03:39:46 2019
New Revision: 349965
URL: https://svnweb.freebsd.org/changeset/base/349965

Log:
  powerpc64/pmap: No need for moea64_pvo_remove_from_page_locked() wrapper
  
  The only consumer of moea64_pvo_remove_from_page_locked() already has the
  page in hand, so there is no need to search for the page while holding the
  lock.  Drop the wrapper, and rename _moea64_pvo_remove_from_page_locked().
  
  Reported by:  alc

Modified:
  head/sys/powerpc/aim/mmu_oea64.c

Modified: head/sys/powerpc/aim/mmu_oea64.c
==
--- head/sys/powerpc/aim/mmu_oea64.cSat Jul 13 03:22:28 2019
(r349964)
+++ head/sys/powerpc/aim/mmu_oea64.cSat Jul 13 03:39:46 2019
(r349965)
@@ -235,7 +235,7 @@ static int  moea64_pvo_enter(mmu_t mmu, struct pvo_entr
 static voidmoea64_pvo_remove_from_pmap(mmu_t mmu, struct pvo_entry *pvo);
 static voidmoea64_pvo_remove_from_page(mmu_t mmu, struct pvo_entry *pvo);
 static voidmoea64_pvo_remove_from_page_locked(mmu_t mmu,
-   struct pvo_entry *pvo);
+   struct pvo_entry *pvo, vm_page_t m);
 static struct  pvo_entry *moea64_pvo_find_va(pmap_t, vm_offset_t);
 
 /*
@@ -2452,7 +2452,7 @@ moea64_remove_all(mmu_t mmu, vm_page_t m)
wasdead = (pvo->pvo_vaddr & PVO_DEAD);
if (!wasdead)
moea64_pvo_remove_from_pmap(mmu, pvo);
-   moea64_pvo_remove_from_page_locked(mmu, pvo);
+   moea64_pvo_remove_from_page_locked(mmu, pvo, m);
if (!wasdead)
LIST_INSERT_HEAD(, pvo, pvo_vlink);
PMAP_UNLOCK(pmap);
@@ -2626,7 +2626,7 @@ moea64_pvo_remove_from_pmap(mmu_t mmu, struct pvo_entr
 }
 
 static inline void
-_moea64_pvo_remove_from_page_locked(mmu_t mmu, struct pvo_entry *pvo,
+moea64_pvo_remove_from_page_locked(mmu_t mmu, struct pvo_entry *pvo,
 vm_page_t m)
 {
 
@@ -2655,17 +2655,6 @@ _moea64_pvo_remove_from_page_locked(mmu_t mmu, struct 
 }
 
 static void
-moea64_pvo_remove_from_page_locked(mmu_t mmu, struct pvo_entry *pvo)
-{
-   vm_page_t pg = NULL;
-
-   if (pvo->pvo_vaddr & PVO_MANAGED)
-   pg = PHYS_TO_VM_PAGE(pvo->pvo_pte.pa & LPTE_RPGN);
-
-   _moea64_pvo_remove_from_page_locked(mmu, pvo, pg);
-}
-
-static void
 moea64_pvo_remove_from_page(mmu_t mmu, struct pvo_entry *pvo)
 {
vm_page_t pg = NULL;
@@ -2674,7 +2663,7 @@ moea64_pvo_remove_from_page(mmu_t mmu, struct pvo_entr
pg = PHYS_TO_VM_PAGE(pvo->pvo_pte.pa & LPTE_RPGN);
 
PV_LOCK(pvo->pvo_pte.pa & LPTE_RPGN);
-   _moea64_pvo_remove_from_page_locked(mmu, pvo, pg);
+   moea64_pvo_remove_from_page_locked(mmu, pvo, pg);
PV_UNLOCK(pvo->pvo_pte.pa & LPTE_RPGN);
 }
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349964 - head/sbin/camcontrol

2019-07-12 Thread Warner Losh
Author: imp
Date: Sat Jul 13 03:22:28 2019
New Revision: 349964
URL: https://svnweb.freebsd.org/changeset/base/349964

Log:
  Add device type NVME and device type MMCSD to get_device_type
  
  For completeness, add nvme and mmc/sd devices to the list of device
  types we know.

Modified:
  head/sbin/camcontrol/camcontrol.c
  head/sbin/camcontrol/camcontrol.h

Modified: head/sbin/camcontrol/camcontrol.c
==
--- head/sbin/camcontrol/camcontrol.c   Sat Jul 13 03:02:11 2019
(r349963)
+++ head/sbin/camcontrol/camcontrol.c   Sat Jul 13 03:22:28 2019
(r349964)
@@ -5366,6 +5366,14 @@ get_device_type(struct cam_device *dev, int retry_coun
*devtype = CC_DT_ATA;
goto bailout;
break; /*NOTREACHED*/
+   case PROTO_NVME:
+   *devtype = CC_DT_NVME;
+   goto bailout;
+   break; /*NOTREACHED*/
+   case PROTO_MMCSD:
+   *devtype = CC_DT_MMCSD;
+   goto bailout;
+   break; /*NOTREACHED*/
default:
*devtype = CC_DT_UNKNOWN;
goto bailout;

Modified: head/sbin/camcontrol/camcontrol.h
==
--- head/sbin/camcontrol/camcontrol.h   Sat Jul 13 03:02:11 2019
(r349963)
+++ head/sbin/camcontrol/camcontrol.h   Sat Jul 13 03:22:28 2019
(r349964)
@@ -44,6 +44,8 @@ typedef enum {
CC_DT_SCSI,
CC_DT_ATA_BEHIND_SCSI,
CC_DT_ATA,
+   CC_DT_NVME,
+   CC_DT_MMCSD,
CC_DT_UNKNOWN
 } camcontrol_devtype;
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349963 - head/sys/powerpc/aim

2019-07-12 Thread Justin Hibbits
Author: jhibbits
Date: Sat Jul 13 03:02:11 2019
New Revision: 349963
URL: https://svnweb.freebsd.org/changeset/base/349963

Log:
  powerpc64/pmap: Reduce scope of PV_LOCK in remove path
  
  Summary:
  Since the 'page pv' lock is one of the most highly contended locks, we
  need to try to do as much work outside of the lock as we can.  The
  moea64_pvo_remove_from_page() path is a low hanging fruit, where we can
  do some heavy work (PHYS_TO_VM_PAGE()) outside of the lock if needed.
  In one path, moea64_remove_all(), the PV lock is already held and can't
  be swizzled, so we provide two ways to perform the locked operation, one
  that can call PHYS_TO_VM_PAGE outside the lock, and one that calls with
  the lock already held.
  
  Reviewed By: luporl
  Differential Revision: https://reviews.freebsd.org/D20694

Modified:
  head/sys/powerpc/aim/mmu_oea64.c

Modified: head/sys/powerpc/aim/mmu_oea64.c
==
--- head/sys/powerpc/aim/mmu_oea64.cSat Jul 13 00:51:11 2019
(r349962)
+++ head/sys/powerpc/aim/mmu_oea64.cSat Jul 13 03:02:11 2019
(r349963)
@@ -234,6 +234,8 @@ static int  moea64_pvo_enter(mmu_t mmu, struct pvo_entr
struct pvo_head *pvo_head);
 static voidmoea64_pvo_remove_from_pmap(mmu_t mmu, struct pvo_entry *pvo);
 static voidmoea64_pvo_remove_from_page(mmu_t mmu, struct pvo_entry *pvo);
+static voidmoea64_pvo_remove_from_page_locked(mmu_t mmu,
+   struct pvo_entry *pvo);
 static struct  pvo_entry *moea64_pvo_find_va(pmap_t, vm_offset_t);
 
 /*
@@ -1454,9 +1456,7 @@ moea64_enter(mmu_t mmu, pmap_t pmap, vm_offset_t va, v
 
/* Free any dead pages */
if (oldpvo != NULL) {
-   PV_LOCK(oldpvo->pvo_pte.pa & LPTE_RPGN);
moea64_pvo_remove_from_page(mmu, oldpvo);
-   PV_UNLOCK(oldpvo->pvo_pte.pa & LPTE_RPGN);
free_pvo_entry(oldpvo);
}
 
@@ -1877,9 +1877,7 @@ moea64_kenter_attr(mmu_t mmu, vm_offset_t va, vm_paddr
 
/* Free any dead pages */
if (oldpvo != NULL) {
-   PV_LOCK(oldpvo->pvo_pte.pa & LPTE_RPGN);
moea64_pvo_remove_from_page(mmu, oldpvo);
-   PV_UNLOCK(oldpvo->pvo_pte.pa & LPTE_RPGN);
free_pvo_entry(oldpvo);
}
 
@@ -2386,9 +2384,7 @@ moea64_remove_pages(mmu_t mmu, pmap_t pm)
PMAP_UNLOCK(pm);
 
RB_FOREACH_SAFE(pvo, pvo_tree, , tpvo) {
-   PV_LOCK(pvo->pvo_pte.pa & LPTE_RPGN);
moea64_pvo_remove_from_page(mmu, pvo);
-   PV_UNLOCK(pvo->pvo_pte.pa & LPTE_RPGN);
RB_REMOVE(pvo_tree, , pvo);
free_pvo_entry(pvo);
}
@@ -2429,9 +2425,7 @@ moea64_remove(mmu_t mmu, pmap_t pm, vm_offset_t sva, v
PMAP_UNLOCK(pm);
 
RB_FOREACH_SAFE(pvo, pvo_tree, , tpvo) {
-   PV_LOCK(pvo->pvo_pte.pa & LPTE_RPGN);
moea64_pvo_remove_from_page(mmu, pvo);
-   PV_UNLOCK(pvo->pvo_pte.pa & LPTE_RPGN);
RB_REMOVE(pvo_tree, , pvo);
free_pvo_entry(pvo);
}
@@ -2458,7 +2452,7 @@ moea64_remove_all(mmu_t mmu, vm_page_t m)
wasdead = (pvo->pvo_vaddr & PVO_DEAD);
if (!wasdead)
moea64_pvo_remove_from_pmap(mmu, pvo);
-   moea64_pvo_remove_from_page(mmu, pvo);
+   moea64_pvo_remove_from_page_locked(mmu, pvo);
if (!wasdead)
LIST_INSERT_HEAD(, pvo, pvo_vlink);
PMAP_UNLOCK(pmap);
@@ -2631,10 +2625,10 @@ moea64_pvo_remove_from_pmap(mmu_t mmu, struct pvo_entr
}
 }
 
-static void
-moea64_pvo_remove_from_page(mmu_t mmu, struct pvo_entry *pvo)
+static inline void
+_moea64_pvo_remove_from_page_locked(mmu_t mmu, struct pvo_entry *pvo,
+vm_page_t m)
 {
-   struct  vm_page *pg;
 
KASSERT(pvo->pvo_vaddr & PVO_DEAD, ("Trying to delink live page"));
 
@@ -2648,18 +2642,40 @@ moea64_pvo_remove_from_page(mmu_t mmu, struct pvo_entr
 */
PV_LOCKASSERT(pvo->pvo_pte.pa & LPTE_RPGN);
if (pvo->pvo_vaddr & PVO_MANAGED) {
-   pg = PHYS_TO_VM_PAGE(pvo->pvo_pte.pa & LPTE_RPGN);
-
-   if (pg != NULL) {
+   if (m != NULL) {
LIST_REMOVE(pvo, pvo_vlink);
-   if (LIST_EMPTY(vm_page_to_pvoh(pg)))
-   vm_page_aflag_clear(pg,
+   if (LIST_EMPTY(vm_page_to_pvoh(m)))
+   vm_page_aflag_clear(m,
PGA_WRITEABLE | PGA_EXECUTABLE);
}
}
 
moea64_pvo_entries--;
moea64_pvo_remove_calls++;
+}
+
+static void
+moea64_pvo_remove_from_page_locked(mmu_t mmu, struct pvo_entry *pvo)
+{
+   vm_page_t pg = NULL;
+
+   if (pvo->pvo_vaddr & PVO_MANAGED)

svn commit: r349962 - in stable: 11/sys/amd64/vmm 12/sys/amd64/vmm

2019-07-12 Thread John Baldwin
Author: jhb
Date: Sat Jul 13 00:51:11 2019
New Revision: 349962
URL: https://svnweb.freebsd.org/changeset/base/349962

Log:
  MFC 347238: vmm(4): Pass through RDSEED feature bit to guests

Modified:
  stable/11/sys/amd64/vmm/x86.c
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/sys/amd64/vmm/x86.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/11/sys/amd64/vmm/x86.c
==
--- stable/11/sys/amd64/vmm/x86.c   Sat Jul 13 00:23:20 2019
(r349961)
+++ stable/11/sys/amd64/vmm/x86.c   Sat Jul 13 00:51:11 2019
(r349962)
@@ -430,6 +430,7 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
CPUID_STDEXT_AVX2 | CPUID_STDEXT_BMI2 |
CPUID_STDEXT_ERMS | CPUID_STDEXT_RTM |
CPUID_STDEXT_AVX512F |
+   CPUID_STDEXT_RDSEED |
CPUID_STDEXT_AVX512PF |
CPUID_STDEXT_AVX512ER |
CPUID_STDEXT_AVX512CD | CPUID_STDEXT_SHA);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349962 - in stable: 11/sys/amd64/vmm 12/sys/amd64/vmm

2019-07-12 Thread John Baldwin
Author: jhb
Date: Sat Jul 13 00:51:11 2019
New Revision: 349962
URL: https://svnweb.freebsd.org/changeset/base/349962

Log:
  MFC 347238: vmm(4): Pass through RDSEED feature bit to guests

Modified:
  stable/12/sys/amd64/vmm/x86.c
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/amd64/vmm/x86.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/sys/amd64/vmm/x86.c
==
--- stable/12/sys/amd64/vmm/x86.c   Sat Jul 13 00:23:20 2019
(r349961)
+++ stable/12/sys/amd64/vmm/x86.c   Sat Jul 13 00:51:11 2019
(r349962)
@@ -432,6 +432,7 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
CPUID_STDEXT_AVX2 | CPUID_STDEXT_BMI2 |
CPUID_STDEXT_ERMS | CPUID_STDEXT_RTM |
CPUID_STDEXT_AVX512F |
+   CPUID_STDEXT_RDSEED |
CPUID_STDEXT_AVX512PF |
CPUID_STDEXT_AVX512ER |
CPUID_STDEXT_AVX512CD | CPUID_STDEXT_SHA);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349961 - stable/12/usr.sbin/bhyve

2019-07-12 Thread John Baldwin
Author: jhb
Date: Sat Jul 13 00:23:20 2019
New Revision: 349961
URL: https://svnweb.freebsd.org/changeset/base/349961

Log:
  MFC 343068:
  Use capsicum_helpers(3) that allow us to simplify the code and its functions
  will return success when the kernel is built without support of
  the capability mode.
  
  It is important to note, that I'm taking a more conservative approach
  with these changes and it will be done in small steps.

Modified:
  stable/12/usr.sbin/bhyve/bhyverun.c
  stable/12/usr.sbin/bhyve/block_if.c
  stable/12/usr.sbin/bhyve/consport.c
  stable/12/usr.sbin/bhyve/dbgport.c
  stable/12/usr.sbin/bhyve/gdb.c
  stable/12/usr.sbin/bhyve/mevent.c
  stable/12/usr.sbin/bhyve/pci_e82545.c
  stable/12/usr.sbin/bhyve/pci_passthru.c
  stable/12/usr.sbin/bhyve/pci_virtio_console.c
  stable/12/usr.sbin/bhyve/pci_virtio_net.c
  stable/12/usr.sbin/bhyve/pci_virtio_rnd.c
  stable/12/usr.sbin/bhyve/rfb.c
  stable/12/usr.sbin/bhyve/uart_emul.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/bhyverun.c
==
--- stable/12/usr.sbin/bhyve/bhyverun.c Sat Jul 13 00:19:57 2019
(r349960)
+++ stable/12/usr.sbin/bhyve/bhyverun.c Sat Jul 13 00:23:20 2019
(r349961)
@@ -54,7 +54,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -949,15 +948,13 @@ do_open(const char *vmname)
 
 #ifndef WITHOUT_CAPSICUM
cap_rights_init(, CAP_IOCTL, CAP_MMAP_RW);
-   if (cap_rights_limit(vm_get_device_fd(ctx), ) == -1 &&
-   errno != ENOSYS)
+   if (caph_rights_limit(vm_get_device_fd(ctx), ) == -1) 
errx(EX_OSERR, "Unable to apply rights for sandbox");
vm_get_ioctls();
cmds = vm_get_ioctls(NULL);
if (cmds == NULL)
errx(EX_OSERR, "out of memory");
-   if (cap_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1 &&
-   errno != ENOSYS)
+   if (caph_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1)
errx(EX_OSERR, "Unable to apply rights for sandbox");
free((cap_ioctl_t *)cmds);
 #endif

Modified: stable/12/usr.sbin/bhyve/block_if.c
==
--- stable/12/usr.sbin/bhyve/block_if.c Sat Jul 13 00:19:57 2019
(r349960)
+++ stable/12/usr.sbin/bhyve/block_if.c Sat Jul 13 00:23:20 2019
(r349961)
@@ -42,6 +42,9 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #include 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -473,7 +476,7 @@ blockif_open(const char *optstr, const char *ident)
if (ro)
cap_rights_clear(, CAP_FSYNC, CAP_WRITE);
 
-   if (cap_rights_limit(fd, ) == -1 && errno != ENOSYS)
+   if (caph_rights_limit(fd, ) == -1)
errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
@@ -504,7 +507,7 @@ blockif_open(const char *optstr, const char *ident)
psectsz = sbuf.st_blksize;
 
 #ifndef WITHOUT_CAPSICUM
-   if (cap_ioctls_limit(fd, cmds, nitems(cmds)) == -1 && errno != ENOSYS)
+   if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1)
errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/consport.c
==
--- stable/12/usr.sbin/bhyve/consport.c Sat Jul 13 00:19:57 2019
(r349960)
+++ stable/12/usr.sbin/bhyve/consport.c Sat Jul 13 00:23:20 2019
(r349961)
@@ -37,6 +37,9 @@ __FBSDID("$FreeBSD$");
 #endif
 #include 
 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -138,11 +141,9 @@ console_handler(struct vmctx *ctx, int vcpu, int in, i
 #ifndef WITHOUT_CAPSICUM
cap_rights_init(, CAP_EVENT, CAP_IOCTL, CAP_READ,
CAP_WRITE);
-   if (cap_rights_limit(STDIN_FILENO, ) == -1 &&
-   errno != ENOSYS)
+   if (caph_rights_limit(STDIN_FILENO, ) == -1)
errx(EX_OSERR, "Unable to apply rights for sandbox");
-   if (cap_ioctls_limit(STDIN_FILENO, cmds, nitems(cmds)) == -1 &&
-   errno != ENOSYS)
+   if (caph_ioctls_limit(STDIN_FILENO, cmds, nitems(cmds)) == -1)
errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
ttyopen();

Modified: stable/12/usr.sbin/bhyve/dbgport.c
==
--- stable/12/usr.sbin/bhyve/dbgport.c  Sat Jul 13 00:19:57 2019
(r349960)
+++ stable/12/usr.sbin/bhyve/dbgport.c  Sat Jul 13 00:23:20 2019
(r349961)
@@ -40,6 +40,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -167,7 +170,7 @@ init_dbgport(int sport)
 
 #ifndef 

svn commit: r349960 - head/sys/powerpc/aim

2019-07-12 Thread Justin Hibbits
Author: jhibbits
Date: Sat Jul 13 00:19:57 2019
New Revision: 349960
URL: https://svnweb.freebsd.org/changeset/base/349960

Log:
  Set pcpu curpmap for powerpc64
  
  Summary:
  If an illegal instruction is encountered on a process running on a
  powerpc64 kernel it would attempt to sync the cache before retrying the
  instruction "just in case".  However, since curpmap is not set, when
  moea64_sync_icache() attempts to lock the pmap, it's locking on a NULL 
pointer,
  triggering a panic.  Fix this by adding a (assumed unnecessary) fallback to
  curthread's pmap in moea64_sync_icache().
  
  Reported by:  alfredo.junior_eldorado.org.br
  Reviewed by:  luporl, alfredo.junior_eldorado.org.br
  Differential Revision: https://reviews.freebsd.org/D20911

Modified:
  head/sys/powerpc/aim/mmu_oea64.c

Modified: head/sys/powerpc/aim/mmu_oea64.c
==
--- head/sys/powerpc/aim/mmu_oea64.cSat Jul 13 00:12:35 2019
(r349959)
+++ head/sys/powerpc/aim/mmu_oea64.cSat Jul 13 00:19:57 2019
(r349960)
@@ -2838,6 +2838,9 @@ moea64_sync_icache(mmu_t mmu, pmap_t pm, vm_offset_t v
vm_paddr_t pa;
vm_size_t len;
 
+   if (__predict_false(pm == NULL))
+   pm = >td_proc->p_vmspace->vm_pmap;
+
PMAP_LOCK(pm);
while (sz > 0) {
lim = round_page(va+1);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349959 - stable/11/usr.sbin/bhyve

2019-07-12 Thread John Baldwin
Author: jhb
Date: Sat Jul 13 00:12:35 2019
New Revision: 349959
URL: https://svnweb.freebsd.org/changeset/base/349959

Log:
  Add Capsicumification of the virtio_console device model.
  
  This is a direct commit to stable/11.  This change was missed when
  merging virtio_console to 11 because the capsicum change and
  virtio_console changes were merged in the opposite order of the
  changes in head.

Modified:
  stable/11/usr.sbin/bhyve/pci_virtio_console.c

Modified: stable/11/usr.sbin/bhyve/pci_virtio_console.c
==
--- stable/11/usr.sbin/bhyve/pci_virtio_console.c   Fri Jul 12 22:31:12 
2019(r349958)
+++ stable/11/usr.sbin/bhyve/pci_virtio_console.c   Sat Jul 13 00:12:35 
2019(r349959)
@@ -34,12 +34,16 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#endif
 #include 
 #include 
 #include 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -50,6 +54,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #include "bhyverun.h"
 #include "pci_emul.h"
@@ -270,6 +275,9 @@ pci_vtcon_sock_add(struct pci_vtcon_softc *sc, const c
struct pci_vtcon_sock *sock;
struct sockaddr_un sun;
int s = -1, fd = -1, error = 0;
+#ifndef WITHOUT_CAPSICUM
+   cap_rights_t rights;
+#endif
 
sock = calloc(1, sizeof(struct pci_vtcon_sock));
if (sock == NULL) {
@@ -308,6 +316,11 @@ pci_vtcon_sock_add(struct pci_vtcon_softc *sc, const c
goto out;
}
 
+#ifndef WITHOUT_CAPSICUM
+   cap_rights_init(, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
+   if (cap_rights_limit(s, ) == -1 && errno != ENOSYS)
+   errx(EX_OSERR, "Unable to apply rights for sandbox");
+#endif
 
sock->vss_port = pci_vtcon_port_add(sc, name, pci_vtcon_sock_tx, sock);
if (sock->vss_port == NULL) {
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349958 - in stable: 11/sys/amd64/vmm 11/sys/amd64/vmm/amd 11/sys/x86/x86 11/usr.sbin/bhyve 12/sys/amd64/vmm 12/sys/amd64/vmm/amd 12/sys/x86/x86 12/usr.sbin/bhyve

2019-07-12 Thread John Baldwin
Author: jhb
Date: Fri Jul 12 22:31:12 2019
New Revision: 349958
URL: https://svnweb.freebsd.org/changeset/base/349958

Log:
  MFC 339911,339936,343075,343166,348592: Various AMD CPU-specific fixes.
  
  339911:
  Emulate machine check related MSR_EXTFEATURES to allow guest OSes to
  boot on AMD FX Series.
  
  339936:
  Merge cases with upper block.
  This is a cosmetic change only to simplify code.
  
  343075:
  vmm(4): Take steps towards multicore bhyve AMD support
  
  vmm's CPUID emulation presented Intel topology information to the guest, but
  disabled AMD topology information and in some cases passed through garbage.
  I.e., CPUID leaves 0x8000_001[de] were passed through to the guest, but
  guest CPUs can migrate between host threads, so the information presented
  was not consistent.  This could easily be observed with 'cpucontrol -i 0xfoo
  /dev/cpuctl0'.
  
  Slightly improve this situation by enabling the AMD topology feature flag
  and presenting at least the CPUID fields used by FreeBSD itself to probe
  topology on more modern AMD64 hardware (Family 15h+).  Older stuff is
  probably less interesting.  I have not been able to empirically confirm it
  is sufficient, but it should not regress anything either.
  
  343166:
  vmm(4): Mask Spectre feature bits on AMD hosts
  
  For parity with Intel hosts, which already mask out the CPUID feature
  bits that indicate the presence of the SPEC_CTRL MSR, do the same on
  AMD.
  
  Eventually we may want to have a better support story for guests, but
  for now, limit the damage of incorrectly indicating an MSR we do not yet
  support.
  
  Eventually, we may want a generic CPUID override system for
  administrators, or for minimum supported feature set in heterogenous
  environments with failover.  That is a much larger scope effort than
  this bug fix.
  
  348592:
  Emulate the AMD MSR_LS_CFG MSR used for various Ryzen errata.
  
  Writes are ignored and reads always return zero.
  
  PR:   224476, 235010

Modified:
  stable/11/sys/amd64/vmm/amd/svm_msr.c
  stable/11/sys/amd64/vmm/x86.c
  stable/11/sys/amd64/vmm/x86.h
  stable/11/sys/x86/x86/mp_x86.c
  stable/11/usr.sbin/bhyve/xmsr.c
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/sys/amd64/vmm/amd/svm_msr.c
  stable/12/sys/amd64/vmm/x86.c
  stable/12/sys/amd64/vmm/x86.h
  stable/12/sys/x86/x86/mp_x86.c
  stable/12/usr.sbin/bhyve/xmsr.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/11/sys/amd64/vmm/amd/svm_msr.c
==
--- stable/11/sys/amd64/vmm/amd/svm_msr.c   Fri Jul 12 21:19:47 2019
(r349957)
+++ stable/11/sys/amd64/vmm/amd/svm_msr.c   Fri Jul 12 22:31:12 2019
(r349958)
@@ -122,9 +122,8 @@ svm_rdmsr(struct svm_softc *sc, int vcpu, u_int num, u
case MSR_MTRR16kBase ... MSR_MTRR16kBase + 1:
case MSR_MTRR64kBase:
case MSR_SYSCFG:
-   *result = 0;
-   break;
case MSR_AMDK8_IPM:
+   case MSR_EXTFEATURES:
*result = 0;
break;
default:
@@ -162,6 +161,8 @@ svm_wrmsr(struct svm_softc *sc, int vcpu, u_int num, u
/*
 * Ignore writes to microcode update register.
 */
+   break;
+   case MSR_EXTFEATURES:
break;
default:
error = EINVAL;

Modified: stable/11/sys/amd64/vmm/x86.c
==
--- stable/11/sys/amd64/vmm/x86.c   Fri Jul 12 21:19:47 2019
(r349957)
+++ stable/11/sys/amd64/vmm/x86.c   Fri Jul 12 22:31:12 2019
(r349958)
@@ -135,17 +135,30 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
cpuid_count(*eax, *ecx, regs);
if (vmm_is_amd()) {
/*
-* XXX this might appear silly because AMD
-* cpus don't have threads.
-*
-* However this matches the logical cpus as
-* advertised by leaf 0x1 and will work even
-* if threads is set incorrectly on an AMD host.
+* As on Intel (_0007:0, EDX), mask out
+* unsupported or unsafe AMD extended features
+* (8000_0008 EBX).
 */
+   regs[1] &= (AMDFEID_CLZERO | AMDFEID_IRPERF |
+   AMDFEID_XSAVEERPTR);
+
vm_get_topology(vm, , , ,
);
-   logical_cpus = threads * cores;
-   regs[2] = logical_cpus - 1;
+

svn commit: r349958 - in stable: 11/sys/amd64/vmm 11/sys/amd64/vmm/amd 11/sys/x86/x86 11/usr.sbin/bhyve 12/sys/amd64/vmm 12/sys/amd64/vmm/amd 12/sys/x86/x86 12/usr.sbin/bhyve

2019-07-12 Thread John Baldwin
Author: jhb
Date: Fri Jul 12 22:31:12 2019
New Revision: 349958
URL: https://svnweb.freebsd.org/changeset/base/349958

Log:
  MFC 339911,339936,343075,343166,348592: Various AMD CPU-specific fixes.
  
  339911:
  Emulate machine check related MSR_EXTFEATURES to allow guest OSes to
  boot on AMD FX Series.
  
  339936:
  Merge cases with upper block.
  This is a cosmetic change only to simplify code.
  
  343075:
  vmm(4): Take steps towards multicore bhyve AMD support
  
  vmm's CPUID emulation presented Intel topology information to the guest, but
  disabled AMD topology information and in some cases passed through garbage.
  I.e., CPUID leaves 0x8000_001[de] were passed through to the guest, but
  guest CPUs can migrate between host threads, so the information presented
  was not consistent.  This could easily be observed with 'cpucontrol -i 0xfoo
  /dev/cpuctl0'.
  
  Slightly improve this situation by enabling the AMD topology feature flag
  and presenting at least the CPUID fields used by FreeBSD itself to probe
  topology on more modern AMD64 hardware (Family 15h+).  Older stuff is
  probably less interesting.  I have not been able to empirically confirm it
  is sufficient, but it should not regress anything either.
  
  343166:
  vmm(4): Mask Spectre feature bits on AMD hosts
  
  For parity with Intel hosts, which already mask out the CPUID feature
  bits that indicate the presence of the SPEC_CTRL MSR, do the same on
  AMD.
  
  Eventually we may want to have a better support story for guests, but
  for now, limit the damage of incorrectly indicating an MSR we do not yet
  support.
  
  Eventually, we may want a generic CPUID override system for
  administrators, or for minimum supported feature set in heterogenous
  environments with failover.  That is a much larger scope effort than
  this bug fix.
  
  348592:
  Emulate the AMD MSR_LS_CFG MSR used for various Ryzen errata.
  
  Writes are ignored and reads always return zero.
  
  PR:   224476, 235010

Modified:
  stable/12/sys/amd64/vmm/amd/svm_msr.c
  stable/12/sys/amd64/vmm/x86.c
  stable/12/sys/amd64/vmm/x86.h
  stable/12/sys/x86/x86/mp_x86.c
  stable/12/usr.sbin/bhyve/xmsr.c
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/amd64/vmm/amd/svm_msr.c
  stable/11/sys/amd64/vmm/x86.c
  stable/11/sys/amd64/vmm/x86.h
  stable/11/sys/x86/x86/mp_x86.c
  stable/11/usr.sbin/bhyve/xmsr.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/sys/amd64/vmm/amd/svm_msr.c
==
--- stable/12/sys/amd64/vmm/amd/svm_msr.c   Fri Jul 12 21:19:47 2019
(r349957)
+++ stable/12/sys/amd64/vmm/amd/svm_msr.c   Fri Jul 12 22:31:12 2019
(r349958)
@@ -122,9 +122,8 @@ svm_rdmsr(struct svm_softc *sc, int vcpu, u_int num, u
case MSR_MTRR16kBase ... MSR_MTRR16kBase + 1:
case MSR_MTRR64kBase:
case MSR_SYSCFG:
-   *result = 0;
-   break;
case MSR_AMDK8_IPM:
+   case MSR_EXTFEATURES:
*result = 0;
break;
default:
@@ -162,6 +161,8 @@ svm_wrmsr(struct svm_softc *sc, int vcpu, u_int num, u
/*
 * Ignore writes to microcode update register.
 */
+   break;
+   case MSR_EXTFEATURES:
break;
default:
error = EINVAL;

Modified: stable/12/sys/amd64/vmm/x86.c
==
--- stable/12/sys/amd64/vmm/x86.c   Fri Jul 12 21:19:47 2019
(r349957)
+++ stable/12/sys/amd64/vmm/x86.c   Fri Jul 12 22:31:12 2019
(r349958)
@@ -137,17 +137,30 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
cpuid_count(*eax, *ecx, regs);
if (vmm_is_amd()) {
/*
-* XXX this might appear silly because AMD
-* cpus don't have threads.
-*
-* However this matches the logical cpus as
-* advertised by leaf 0x1 and will work even
-* if threads is set incorrectly on an AMD host.
+* As on Intel (_0007:0, EDX), mask out
+* unsupported or unsafe AMD extended features
+* (8000_0008 EBX).
 */
+   regs[1] &= (AMDFEID_CLZERO | AMDFEID_IRPERF |
+   AMDFEID_XSAVEERPTR);
+
vm_get_topology(vm, , , ,
);
-   logical_cpus = threads * cores;
-   regs[2] = logical_cpus - 1;
+

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

2019-07-12 Thread Tijl Coosemans
Author: tijl
Date: Fri Jul 12 21:19:47 2019
New Revision: 349957
URL: https://svnweb.freebsd.org/changeset/base/349957

Log:
  Fix layout.  -C needs to be styled as a flag here, not as a new list item.
  
  MFC after:2 weeks

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

Modified: head/usr.bin/top/top.1
==
--- head/usr.bin/top/top.1  Fri Jul 12 20:59:10 2019(r349956)
+++ head/usr.bin/top/top.1  Fri Jul 12 21:19:47 2019(r349957)
@@ -51,7 +51,7 @@ By default top displays the weighted CPU percentage in
 .Xr ps 1
 displays as CPU).
 Each time
-.It Fl C
+.Fl C
 flag is passed it toggles between \*(lqraw cpu\*(rq mode
 and \*(lqweighted cpu\*(rq mode, showing the \*(lqCPU\*(rq or
 the \*(lqWCPU\*(rq column respectively.
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349956 - head/sys/dev/cxgbe/common

2019-07-12 Thread Navdeep Parhar
Author: np
Date: Fri Jul 12 20:59:10 2019
New Revision: 349956
URL: https://svnweb.freebsd.org/changeset/base/349956

Log:
  cxgbe(4): Completely ignore all top level interrupts that are not enabled.
  
  The driver used to log any non-zero cause and when running with a single
  line interrupt it would spam the console/logs with reports of interrupts
  that are of no interest to anyone.
  
  MFC after:1 week
  Sponsored by: Chelsio Communications

Modified:
  head/sys/dev/cxgbe/common/t4_hw.c

Modified: head/sys/dev/cxgbe/common/t4_hw.c
==
--- head/sys/dev/cxgbe/common/t4_hw.c   Fri Jul 12 20:05:30 2019
(r349955)
+++ head/sys/dev/cxgbe/common/t4_hw.c   Fri Jul 12 20:59:10 2019
(r349956)
@@ -4023,17 +4023,16 @@ t4_handle_intr(struct adapter *adap, const struct intr
bool rc;
const struct intr_action *action;
 
-   /* read and display cause. */
-   cause = t4_read_reg(adap, ii->cause_reg);
-   if (verbose || cause != 0)
-   t4_show_intr_info(adap, ii, cause);
/*
-* The top level interrupt cause is a bit special and we need to ignore
-* the bits that are not in the enable.  Note that we did display them
-* above in t4_show_intr_info but will not clear them.
+* Read and display cause.  Note that the top level PL_INT_CAUSE is a
+* bit special and we need to completely ignore the bits that are not in
+* PL_INT_ENABLE.
 */
+   cause = t4_read_reg(adap, ii->cause_reg);
if (ii->cause_reg == A_PL_INT_CAUSE)
cause &= t4_read_reg(adap, ii->enable_reg);
+   if (verbose || cause != 0)
+   t4_show_intr_info(adap, ii, cause);
fatal = cause & ii->fatal;
if (fatal != 0 && ii->flags & NONFATAL_IF_DISABLED)
fatal &= t4_read_reg(adap, ii->enable_reg);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349955 - in stable: 11/sys/amd64/amd64 11/sys/x86/include 12/sys/amd64/amd64 12/sys/x86/include

2019-07-12 Thread John Baldwin
Author: jhb
Date: Fri Jul 12 20:05:30 2019
New Revision: 349955
URL: https://svnweb.freebsd.org/changeset/base/349955

Log:
  MFC 348210: Add a constant for the LS config MSR on AMD CPUs.

Modified:
  stable/12/sys/amd64/amd64/initcpu.c
  stable/12/sys/x86/include/specialreg.h
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/amd64/amd64/initcpu.c
  stable/11/sys/x86/include/specialreg.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/sys/amd64/amd64/initcpu.c
==
--- stable/12/sys/amd64/amd64/initcpu.c Fri Jul 12 19:43:59 2019
(r349954)
+++ stable/12/sys/amd64/amd64/initcpu.c Fri Jul 12 20:05:30 2019
(r349955)
@@ -124,9 +124,9 @@ init_amd(void)
 */
if (CPUID_TO_FAMILY(cpu_id) == 0x16 && CPUID_TO_MODEL(cpu_id) <= 0xf) {
if ((cpu_feature2 & CPUID2_HV) == 0) {
-   msr = rdmsr(0xc0011020);
+   msr = rdmsr(MSR_LS_CFG);
msr |= (uint64_t)1 << 15;
-   wrmsr(0xc0011020, msr);
+   wrmsr(MSR_LS_CFG, msr);
}
}
 
@@ -139,9 +139,9 @@ init_amd(void)
wrmsr(0xc0011029, msr);
 
/* 1033 */
-   msr = rdmsr(0xc0011020);
+   msr = rdmsr(MSR_LS_CFG);
msr |= 0x10;
-   wrmsr(0xc0011020, msr);
+   wrmsr(MSR_LS_CFG, msr);
 
/* 1049 */
msr = rdmsr(0xc0011028);
@@ -149,9 +149,9 @@ init_amd(void)
wrmsr(0xc0011028, msr);
 
/* 1095 */
-   msr = rdmsr(0xc0011020);
+   msr = rdmsr(MSR_LS_CFG);
msr |= 0x200;
-   wrmsr(0xc0011020, msr);
+   wrmsr(MSR_LS_CFG, msr);
}
 
/*

Modified: stable/12/sys/x86/include/specialreg.h
==
--- stable/12/sys/x86/include/specialreg.h  Fri Jul 12 19:43:59 2019
(r349954)
+++ stable/12/sys/x86/include/specialreg.h  Fri Jul 12 20:05:30 2019
(r349955)
@@ -1029,6 +1029,7 @@
 #defineMSR_VM_HSAVE_PA 0xc0010117  /* SVM: host save area address 
*/
 #defineMSR_AMD_CPUID07 0xc0011002  /* CPUID 07 %ebx override */
 #defineMSR_EXTFEATURES 0xc0011005  /* Extended CPUID Features 
override */
+#defineMSR_LS_CFG  0xc0011020
 #defineMSR_IC_CFG  0xc0011021  /* Instruction Cache 
Configuration */
 
 /* MSR_VM_CR related */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349955 - in stable: 11/sys/amd64/amd64 11/sys/x86/include 12/sys/amd64/amd64 12/sys/x86/include

2019-07-12 Thread John Baldwin
Author: jhb
Date: Fri Jul 12 20:05:30 2019
New Revision: 349955
URL: https://svnweb.freebsd.org/changeset/base/349955

Log:
  MFC 348210: Add a constant for the LS config MSR on AMD CPUs.

Modified:
  stable/11/sys/amd64/amd64/initcpu.c
  stable/11/sys/x86/include/specialreg.h
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/sys/amd64/amd64/initcpu.c
  stable/12/sys/x86/include/specialreg.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/11/sys/amd64/amd64/initcpu.c
==
--- stable/11/sys/amd64/amd64/initcpu.c Fri Jul 12 19:43:59 2019
(r349954)
+++ stable/11/sys/amd64/amd64/initcpu.c Fri Jul 12 20:05:30 2019
(r349955)
@@ -122,9 +122,9 @@ init_amd(void)
 */
if (CPUID_TO_FAMILY(cpu_id) == 0x16 && CPUID_TO_MODEL(cpu_id) <= 0xf) {
if ((cpu_feature2 & CPUID2_HV) == 0) {
-   msr = rdmsr(0xc0011020);
+   msr = rdmsr(MSR_LS_CFG);
msr |= (uint64_t)1 << 15;
-   wrmsr(0xc0011020, msr);
+   wrmsr(MSR_LS_CFG, msr);
}
}
 
@@ -137,9 +137,9 @@ init_amd(void)
wrmsr(0xc0011029, msr);
 
/* 1033 */
-   msr = rdmsr(0xc0011020);
+   msr = rdmsr(MSR_LS_CFG);
msr |= 0x10;
-   wrmsr(0xc0011020, msr);
+   wrmsr(MSR_LS_CFG, msr);
 
/* 1049 */
msr = rdmsr(0xc0011028);
@@ -147,9 +147,9 @@ init_amd(void)
wrmsr(0xc0011028, msr);
 
/* 1095 */
-   msr = rdmsr(0xc0011020);
+   msr = rdmsr(MSR_LS_CFG);
msr |= 0x200;
-   wrmsr(0xc0011020, msr);
+   wrmsr(MSR_LS_CFG, msr);
}
 
/*

Modified: stable/11/sys/x86/include/specialreg.h
==
--- stable/11/sys/x86/include/specialreg.h  Fri Jul 12 19:43:59 2019
(r349954)
+++ stable/11/sys/x86/include/specialreg.h  Fri Jul 12 20:05:30 2019
(r349955)
@@ -908,6 +908,7 @@
 #defineMSR_VM_HSAVE_PA 0xc0010117  /* SVM: host save area address 
*/
 #defineMSR_AMD_CPUID07 0xc0011002  /* CPUID 07 %ebx override */
 #defineMSR_EXTFEATURES 0xc0011005  /* Extended CPUID Features 
override */
+#defineMSR_LS_CFG  0xc0011020
 #defineMSR_IC_CFG  0xc0011021  /* Instruction Cache 
Configuration */
 
 /* MSR_VM_CR related */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349954 - in stable: 11/contrib/llvm/include/llvm/Analysis 11/contrib/llvm/lib/Analysis 11/contrib/llvm/lib/Transforms/Scalar 12/contrib/llvm/include/llvm/Analysis 12/contrib/llvm/lib/A...

2019-07-12 Thread Dimitry Andric
Author: dim
Date: Fri Jul 12 19:43:59 2019
New Revision: 349954
URL: https://svnweb.freebsd.org/changeset/base/349954

Log:
  MFC r349583:
  
  Pull in r360968 from upstream llvm trunk (by Philip Reames):
  
Clarify comments on helpers used by LFTR [NFC]
  
I'm slowly wrapping my head around this code, and am making comment
improvements where I can.
  
  Pull in r360972 from upstream llvm trunk (by Philip Reames):
  
[LFTR] Factor out a helper function for readability purpose [NFC]
  
  Pull in r360976 from upstream llvm trunk (by Philip Reames):
  
[IndVars] Don't reimplement Loop::isLoopInvariant [NFC]
  
Using dominance vs a set membership check is indistinguishable from a
compile time perspective, and the two queries return equivelent
results.  Simplify code by using the existing function.
  
  Pull in r360978 from upstream llvm trunk (by Philip Reames):
  
[LFTR] Strengthen assertions in genLoopLimit [NFCI]
  
  Pull in r362292 from upstream llvm trunk (by Nikita Popov):
  
[IndVarSimplify] Fixup nowrap flags during LFTR (PR31181)
  
Fix for https://bugs.llvm.org/show_bug.cgi?id=31181 and partial fix
for LFTR poison handling issues in general.
  
When LFTR moves a condition from pre-inc to post-inc, it may now
depend on value that is poison due to nowrap flags. To avoid this, we
clear any nowrap flag that SCEV cannot prove for the post-inc addrec.
  
Additionally, LFTR may switch to a different IV that is dynamically
dead and as such may be arbitrarily poison. This patch will correct
nowrap flags in some but not all cases where this happens. This is
related to the adoption of IR nowrap flags for the pre-inc addrec.
(See some of the switch_to_different_iv tests, where flags are not
dropped or insufficiently dropped.)
  
Finally, there are likely similar issues with the handling of GEP
inbounds, but we don't have a test case for this yet.
  
Differential Revision: https://reviews.llvm.org/D60935
  
  Pull in r362971 from upstream llvm trunk (by Philip Reames):
  
Prepare for multi-exit LFTR [NFC]
  
This change does the plumbing to wire an ExitingBB parameter through
the LFTR implementation, and reorganizes the code to work in terms of
a set of individual loop exits. Most of it is fairly obvious, but
there's one key complexity which makes it worthy of consideration.
The actual multi-exit LFTR patch is in D62625 for context.
  
Specifically, it turns out the existing code uses the backedge taken
count from before a IV is widened. Oddly, we can end up with a
different (more expensive, but semantically equivelent) BE count for
the loop when requerying after widening.  For the nestedIV example
from elim-extend, we end up with the following BE counts:
BEFORE: (-2 + (-1 * %innercount) + %limit)
AFTER: (-1 + (sext i32 (-1 + %limit) to i64) + (-1 * (sext i32 %innercount 
to i64)))
  
This is the only test in tree which seems sensitive to this
difference. The actual result of using the wider BETC on this example
is that we actually produce slightly better code. :)
  
In review, we decided to accept that test change.  This patch is
structured to preserve the old behavior, but a separate change will
immediate follow with the behavior change.  (I wanted it separate for
problem attribution purposes.)
  
Differential Revision: https://reviews.llvm.org/D62880
  
  Pull in r362975 from upstream llvm trunk (by Philip Reames):
  
[LFTR] Use recomputed BE count
  
This was discussed as part of D62880.  The basic thought is that
computing BE taken count after widening should produce (on average)
an equally good backedge taken count as the one before widening.
Since there's only one test in the suite which is impacted by this
change, and it's essentially equivelent codegen, that seems to be a
reasonable assertion.  This change was separated from r362971 so that
if this turns out to be problematic, the triggering piece is obvious
and easily revertable.
  
For the nestedIV example from elim-extend.ll, we end up with the
following BE counts:
BEFORE: (-2 + (-1 * %innercount) + %limit)
AFTER: (-1 + (sext i32 (-1 + %limit) to i64) + (-1 * (sext i32 %innercount 
to i64)))
  
Note that before is an i32 type, and the after is an i64.  Truncating
the i64 produces the i32.
  
  Pull in r362980 from upstream llvm trunk (by Philip Reames):
  
Factor out a helper function for readability and reuse in a future
patch [NFC]
  
  Pull in r363613 from upstream llvm trunk (by Philip Reames):
  
Fix a bug w/inbounds invalidation in LFTR (recommit)
  
Recommit r363289 with a bug fix for crash identified in pr42279.
Issue was that a loop exit test does not have to be an icmp, leading
to a null dereference crash when new logic was exercised for that
case.  Test case previously 

svn commit: r349954 - in stable: 11/contrib/llvm/include/llvm/Analysis 11/contrib/llvm/lib/Analysis 11/contrib/llvm/lib/Transforms/Scalar 12/contrib/llvm/include/llvm/Analysis 12/contrib/llvm/lib/A...

2019-07-12 Thread Dimitry Andric
Author: dim
Date: Fri Jul 12 19:43:59 2019
New Revision: 349954
URL: https://svnweb.freebsd.org/changeset/base/349954

Log:
  MFC r349583:
  
  Pull in r360968 from upstream llvm trunk (by Philip Reames):
  
Clarify comments on helpers used by LFTR [NFC]
  
I'm slowly wrapping my head around this code, and am making comment
improvements where I can.
  
  Pull in r360972 from upstream llvm trunk (by Philip Reames):
  
[LFTR] Factor out a helper function for readability purpose [NFC]
  
  Pull in r360976 from upstream llvm trunk (by Philip Reames):
  
[IndVars] Don't reimplement Loop::isLoopInvariant [NFC]
  
Using dominance vs a set membership check is indistinguishable from a
compile time perspective, and the two queries return equivelent
results.  Simplify code by using the existing function.
  
  Pull in r360978 from upstream llvm trunk (by Philip Reames):
  
[LFTR] Strengthen assertions in genLoopLimit [NFCI]
  
  Pull in r362292 from upstream llvm trunk (by Nikita Popov):
  
[IndVarSimplify] Fixup nowrap flags during LFTR (PR31181)
  
Fix for https://bugs.llvm.org/show_bug.cgi?id=31181 and partial fix
for LFTR poison handling issues in general.
  
When LFTR moves a condition from pre-inc to post-inc, it may now
depend on value that is poison due to nowrap flags. To avoid this, we
clear any nowrap flag that SCEV cannot prove for the post-inc addrec.
  
Additionally, LFTR may switch to a different IV that is dynamically
dead and as such may be arbitrarily poison. This patch will correct
nowrap flags in some but not all cases where this happens. This is
related to the adoption of IR nowrap flags for the pre-inc addrec.
(See some of the switch_to_different_iv tests, where flags are not
dropped or insufficiently dropped.)
  
Finally, there are likely similar issues with the handling of GEP
inbounds, but we don't have a test case for this yet.
  
Differential Revision: https://reviews.llvm.org/D60935
  
  Pull in r362971 from upstream llvm trunk (by Philip Reames):
  
Prepare for multi-exit LFTR [NFC]
  
This change does the plumbing to wire an ExitingBB parameter through
the LFTR implementation, and reorganizes the code to work in terms of
a set of individual loop exits. Most of it is fairly obvious, but
there's one key complexity which makes it worthy of consideration.
The actual multi-exit LFTR patch is in D62625 for context.
  
Specifically, it turns out the existing code uses the backedge taken
count from before a IV is widened. Oddly, we can end up with a
different (more expensive, but semantically equivelent) BE count for
the loop when requerying after widening.  For the nestedIV example
from elim-extend, we end up with the following BE counts:
BEFORE: (-2 + (-1 * %innercount) + %limit)
AFTER: (-1 + (sext i32 (-1 + %limit) to i64) + (-1 * (sext i32 %innercount 
to i64)))
  
This is the only test in tree which seems sensitive to this
difference. The actual result of using the wider BETC on this example
is that we actually produce slightly better code. :)
  
In review, we decided to accept that test change.  This patch is
structured to preserve the old behavior, but a separate change will
immediate follow with the behavior change.  (I wanted it separate for
problem attribution purposes.)
  
Differential Revision: https://reviews.llvm.org/D62880
  
  Pull in r362975 from upstream llvm trunk (by Philip Reames):
  
[LFTR] Use recomputed BE count
  
This was discussed as part of D62880.  The basic thought is that
computing BE taken count after widening should produce (on average)
an equally good backedge taken count as the one before widening.
Since there's only one test in the suite which is impacted by this
change, and it's essentially equivelent codegen, that seems to be a
reasonable assertion.  This change was separated from r362971 so that
if this turns out to be problematic, the triggering piece is obvious
and easily revertable.
  
For the nestedIV example from elim-extend.ll, we end up with the
following BE counts:
BEFORE: (-2 + (-1 * %innercount) + %limit)
AFTER: (-1 + (sext i32 (-1 + %limit) to i64) + (-1 * (sext i32 %innercount 
to i64)))
  
Note that before is an i32 type, and the after is an i64.  Truncating
the i64 produces the i32.
  
  Pull in r362980 from upstream llvm trunk (by Philip Reames):
  
Factor out a helper function for readability and reuse in a future
patch [NFC]
  
  Pull in r363613 from upstream llvm trunk (by Philip Reames):
  
Fix a bug w/inbounds invalidation in LFTR (recommit)
  
Recommit r363289 with a bug fix for crash identified in pr42279.
Issue was that a loop exit test does not have to be an icmp, leading
to a null dereference crash when new logic was exercised for that
case.  Test case previously 

Re: svn commit: r349953 - head/sys/amd64/vmm

2019-07-12 Thread Scott Long
Thanks, sorry about that, I had compiled and tested this a dozen times before 
committing, not
sure how this crept in.

Scott

> On Jul 12, 2019, at 1:14 PM, Konstantin Belousov  wrote:
> 
> Author: kib
> Date: Fri Jul 12 19:14:52 2019
> New Revision: 349953
> URL: https://svnweb.freebsd.org/changeset/base/349953
> 
> Log:
>  Fix syntax.
> 
>  Nod from:jhb
>  Sponsored by:The FreeBSD Foundation
> 
> Modified:
>  head/sys/amd64/vmm/vmm_dev.c
> 
> Modified: head/sys/amd64/vmm/vmm_dev.c
> ==
> --- head/sys/amd64/vmm/vmm_dev.c  Fri Jul 12 18:50:46 2019
> (r349952)
> +++ head/sys/amd64/vmm/vmm_dev.c  Fri Jul 12 19:14:52 2019
> (r349953)
> @@ -291,7 +291,7 @@ alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg
>*/
>   if (VM_MEMSEG_NAME(mseg)) {
>   sysmem = false;
> - name = malloc(sizeof(mseg->name) M_VMMDEV, M_WAITOK);
> + name = malloc(sizeof(mseg->name), M_VMMDEV, M_WAITOK);
>   error = copystr(mseg->name, name, sizeof(mseg->name), NULL);
>   if (error)
>   goto done;
> 

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


svn commit: r349953 - head/sys/amd64/vmm

2019-07-12 Thread Konstantin Belousov
Author: kib
Date: Fri Jul 12 19:14:52 2019
New Revision: 349953
URL: https://svnweb.freebsd.org/changeset/base/349953

Log:
  Fix syntax.
  
  Nod from: jhb
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/amd64/vmm/vmm_dev.c

Modified: head/sys/amd64/vmm/vmm_dev.c
==
--- head/sys/amd64/vmm/vmm_dev.cFri Jul 12 18:50:46 2019
(r349952)
+++ head/sys/amd64/vmm/vmm_dev.cFri Jul 12 19:14:52 2019
(r349953)
@@ -291,7 +291,7 @@ alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg
 */
if (VM_MEMSEG_NAME(mseg)) {
sysmem = false;
-   name = malloc(sizeof(mseg->name) M_VMMDEV, M_WAITOK);
+   name = malloc(sizeof(mseg->name), M_VMMDEV, M_WAITOK);
error = copystr(mseg->name, name, sizeof(mseg->name), NULL);
if (error)
goto done;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349952 - head/usr.sbin/bhyve

2019-07-12 Thread Sean Chittenden
Author: seanc (ports committer)
Date: Fri Jul 12 18:50:46 2019
New Revision: 349952
URL: https://svnweb.freebsd.org/changeset/base/349952

Log:
  usr.sbin/bhyve: close backend file descriptor during tap init error
  
  Coverity CID: 1402953
  Reviewed by:  scottl, markj, aleksandr.fedorov -at- itglobal.com
  Approved by:  vmaffione, jhb
  Differential Revision:https://reviews.freebsd.org/D20913

Modified:
  head/usr.sbin/bhyve/net_backends.c

Modified: head/usr.sbin/bhyve/net_backends.c
==
--- head/usr.sbin/bhyve/net_backends.c  Fri Jul 12 18:43:24 2019
(r349951)
+++ head/usr.sbin/bhyve/net_backends.c  Fri Jul 12 18:50:46 2019
(r349952)
@@ -175,7 +175,6 @@ tap_init(struct net_backend *be, const char *devname,
 {
struct tap_priv *priv = (struct tap_priv *)be->opaque;
char tbuf[80];
-   int fd;
int opt = 1;
 #ifndef WITHOUT_CAPSICUM
cap_rights_t rights;
@@ -189,8 +188,8 @@ tap_init(struct net_backend *be, const char *devname,
strcpy(tbuf, "/dev/");
strlcat(tbuf, devname, sizeof(tbuf));
 
-   fd = open(tbuf, O_RDWR);
-   if (fd == -1) {
+   be->fd = open(tbuf, O_RDWR);
+   if (be->fd == -1) {
WPRINTF(("open of tap device %s failed\n", tbuf));
goto error;
}
@@ -199,24 +198,22 @@ tap_init(struct net_backend *be, const char *devname,
 * Set non-blocking and register for read
 * notifications with the event loop
 */
-   if (ioctl(fd, FIONBIO, ) < 0) {
+   if (ioctl(be->fd, FIONBIO, ) < 0) {
WPRINTF(("tap device O_NONBLOCK failed\n"));
goto error;
}
 
 #ifndef WITHOUT_CAPSICUM
cap_rights_init(, CAP_EVENT, CAP_READ, CAP_WRITE);
-   if (caph_rights_limit(fd, ) == -1)
+   if (caph_rights_limit(be->fd, ) == -1)
errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
-   priv->mevp = mevent_add(fd, EVF_READ, cb, param);
+   priv->mevp = mevent_add(be->fd, EVF_READ, cb, param);
if (priv->mevp == NULL) {
WPRINTF(("Could not register event\n"));
goto error;
}
-
-   be->fd = fd;
 
return (0);
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349951 - in head: share/man/man9 sys/amd64/amd64 sys/arm/arm sys/arm64/arm64 sys/i386/i386 sys/kern sys/mips/mips sys/powerpc/powerpc sys/riscv/riscv sys/sparc64/sparc64

2019-07-12 Thread Konstantin Belousov
Author: kib
Date: Fri Jul 12 18:43:24 2019
New Revision: 349951
URL: https://svnweb.freebsd.org/changeset/base/349951

Log:
  Provide protection against starvation of the ll/sc loops when accessing 
userpace.
  
  Casueword(9) on ll/sc architectures must be prepared for userspace
  constantly modifying the same cache line as containing the CAS word,
  and not loop infinitely.  Otherwise, rogue userspace livelocks the
  kernel.
  
  To fix the issue, change casueword(9) interface to return new value 1
  indicating that either comparision or store failed, instead of relying
  on the oldval == *oldvalp comparison.  The primitive no longer retries
  the operation if it failed spuriously.  Modify callers of
  casueword(9), all in kern_umtx.c, to handle retries, and react to
  stops and requests to terminate between retries.
  
  On x86, despite cmpxchg should not return spurious failures, we can
  take advantage of the new interface and just return PSL.ZF.
  
  Reviewed by:  andrew (arm64, previous version), markj
  Tested by:pho
  Reported by:  https://xenbits.xen.org/xsa/advisory-295.txt
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D20772

Modified:
  head/share/man/man9/casuword.9
  head/sys/amd64/amd64/support.S
  head/sys/arm/arm/fusu.S
  head/sys/arm64/arm64/support.S
  head/sys/i386/i386/copyout.c
  head/sys/kern/kern_umtx.c
  head/sys/mips/mips/support.S
  head/sys/powerpc/powerpc/copyinout.c
  head/sys/riscv/riscv/support.S
  head/sys/sparc64/sparc64/support.S
  head/sys/sparc64/sparc64/vm_machdep.c

Modified: head/share/man/man9/casuword.9
==
--- head/share/man/man9/casuword.9  Fri Jul 12 18:39:41 2019
(r349950)
+++ head/share/man/man9/casuword.9  Fri Jul 12 18:43:24 2019
(r349951)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2014 The FreeBSD Foundation
+.\" Copyright (c) 2014, 2019 The FreeBSD Foundation
 .\" All rights reserved.
 .\"
 .\" Part of this documentation was written by
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 21, 2014
+.Dd April 19, 2019
 .Dt CASU 9
 .Os
 .Sh NAME
@@ -106,7 +106,9 @@ The
 .Fn casueword
 and
 .Fn casueword32
-functions return 0 on success and -1 on failure.
+functions return 0 on success, -1 on failure to access memory,
+and 1 when comparison or store failed.
+The store can fail on load-linked/store-conditional architectures.
 .Sh SEE ALSO
 .Xr atomic 9 ,
 .Xr fetch 9 ,

Modified: head/sys/amd64/amd64/support.S
==
--- head/sys/amd64/amd64/support.S  Fri Jul 12 18:39:41 2019
(r349950)
+++ head/sys/amd64/amd64/support.S  Fri Jul 12 18:43:24 2019
(r349951)
@@ -811,6 +811,7 @@ ENTRY(casueword32_nosmap)
lock
 #endif
cmpxchgl %ecx,(%rdi)/* new = %ecx */
+   setne   %cl
 
/*
 * The old value is in %eax.  If the store succeeded it will be the
@@ -828,6 +829,7 @@ ENTRY(casueword32_nosmap)
 */
movl%esi,(%rdx) /* oldp = %rdx */
POP_FRAME_POINTER
+   movzbl  %cl, %eax
ret
 END(casueword32_nosmap)
 
@@ -847,6 +849,7 @@ ENTRY(casueword32_smap)
 #endif
cmpxchgl %ecx,(%rdi)/* new = %ecx */
clac
+   setne   %cl
 
/*
 * The old value is in %eax.  If the store succeeded it will be the
@@ -864,6 +867,7 @@ ENTRY(casueword32_smap)
 */
movl%esi,(%rdx) /* oldp = %rdx */
POP_FRAME_POINTER
+   movzbl  %cl, %eax
ret
 END(casueword32_smap)
 
@@ -886,6 +890,7 @@ ENTRY(casueword_nosmap)
lock
 #endif
cmpxchgq %rcx,(%rdi)/* new = %rcx */
+   setne   %cl
 
/*
 * The old value is in %rax.  If the store succeeded it will be the
@@ -897,6 +902,7 @@ ENTRY(casueword_nosmap)
movq%rax,PCB_ONFAULT(%r8)
movq%rsi,(%rdx)
POP_FRAME_POINTER
+   movzbl  %cl, %eax
ret
 END(casueword_nosmap)
 
@@ -916,6 +922,7 @@ ENTRY(casueword_smap)
 #endif
cmpxchgq %rcx,(%rdi)/* new = %rcx */
clac
+   setne   %cl
 
/*
 * The old value is in %rax.  If the store succeeded it will be the
@@ -927,6 +934,7 @@ ENTRY(casueword_smap)
movq%rax,PCB_ONFAULT(%r8)
movq%rsi,(%rdx)
POP_FRAME_POINTER
+   movzbl  %cl, %eax
ret
 END(casueword_smap)
 

Modified: head/sys/arm/arm/fusu.S
==
--- head/sys/arm/arm/fusu.S Fri Jul 12 18:39:41 2019(r349950)
+++ head/sys/arm/arm/fusu.S Fri Jul 12 18:43:24 2019(r349951)
@@ -63,7 +63,7 @@ EENTRY_NP(casueword32)
ldr r4, =(VM_MAXUSER_ADDRESS-3)
cmp r0, r4
mvncs   r0, #0
-   

svn commit: r349950 - head/share/man/man9

2019-07-12 Thread Konstantin Belousov
Author: kib
Date: Fri Jul 12 18:39:41 2019
New Revision: 349950
URL: https://svnweb.freebsd.org/changeset/base/349950

Log:
  Style: avoid long lines by using .Fo instead of .Fn.
  
  Sponsored by: The FreeBSD Foundation
  MFC after:3 days

Modified:
  head/share/man/man9/casuword.9

Modified: head/share/man/man9/casuword.9
==
--- head/share/man/man9/casuword.9  Fri Jul 12 18:38:18 2019
(r349949)
+++ head/share/man/man9/casuword.9  Fri Jul 12 18:39:41 2019
(r349950)
@@ -41,13 +41,31 @@
 .In sys/types.h
 .In sys/systm.h
 .Ft int
-.Fn casueword "volatile u_long *base" "u_long oldval" "u_long *oldvalp" 
"u_long newval"
+.Fo casueword
+.Fa "volatile u_long *base"
+.Fa "u_long oldval"
+.Fa "u_long *oldvalp"
+.Fa "u_long newval"
+.Fc
 .Ft int
-.Fn casueword32 "volatile uint32_t *base" "uint32_t oldval" "uint32_t 
*oldvalp" "uint32_t newval"
+.Fo casueword32
+.Fa "volatile uint32_t *base"
+.Fa "uint32_t oldval"
+.Fa "uint32_t *oldvalp"
+.Fa "uint32_t newval"
+.Fc
 .Ft u_long
-.Fn casuword "volatile u_long *base" "u_long oldval" "u_long newval"
+.Fo casuword
+.Fa "volatile u_long *base"
+.Fa "u_long oldval"
+.Fa "u_long newval"
+.Fc
 .Ft uint32_t
-.Fn casuword32 "volatile uint32_t *base" "uint32_t oldval" "uint32_t newval"
+.Fo casuword32
+.Fa "volatile uint32_t *base"
+.Fa "uint32_t oldval"
+.Fa "uint32_t newval"
+.Fc
 .Sh DESCRIPTION
 The
 .Nm
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349949 - head/usr.sbin/bhyveload

2019-07-12 Thread Sean Chittenden
Author: seanc (ports committer)
Date: Fri Jul 12 18:38:18 2019
New Revision: 349949
URL: https://svnweb.freebsd.org/changeset/base/349949

Log:
  usr.sbin/bhyveload: don't leak an fd if a device can't be opened
  
  Coverity CID: 1194167
  Approved by:  markj, jhb
  Differential Revision:https://reviews.freebsd.org/D20935

Modified:
  head/usr.sbin/bhyveload/bhyveload.c

Modified: head/usr.sbin/bhyveload/bhyveload.c
==
--- head/usr.sbin/bhyveload/bhyveload.c Fri Jul 12 18:37:56 2019
(r349948)
+++ head/usr.sbin/bhyveload/bhyveload.c Fri Jul 12 18:38:18 2019
(r349949)
@@ -664,21 +664,19 @@ altcons_open(char *path)
 static int
 disk_open(char *path)
 {
-   int err, fd;
+   int fd;
 
if (ndisks >= NDISKS)
return (ERANGE);
 
-   err = 0;
fd = open(path, O_RDONLY);
+   if (fd < 0)
+   return (errno);
 
-   if (fd > 0) {
-   disk_fd[ndisks] = fd;
-   ndisks++;
-   } else 
-   err = errno;
+   disk_fd[ndisks] = fd;
+   ndisks++;
 
-   return (err);
+   return (0);
 }
 
 static void
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349948 - in head/sys/amd64: include vmm

2019-07-12 Thread Scott Long
Author: scottl
Date: Fri Jul 12 18:37:56 2019
New Revision: 349948
URL: https://svnweb.freebsd.org/changeset/base/349948

Log:
  Tie the name limit of a VM to SPECNAMELEN from devfs instead of a
  hard-coded value. Don't allocate space for it from the kernel stack.
  Account for prefix, suffix, and separator space in the name. This
  takes the effective length up to 229 bytes on 13-current, and 37 bytes
  on 12-stable. 37 bytes is enough to hold a full GUID string.
  
  PR:   234134
  MFC after:1 week
  Differential Revision:http://reviews.freebsd.org/D20924

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/include/vmm_dev.h
  head/sys/amd64/vmm/vmm_dev.c

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hFri Jul 12 18:33:58 2019
(r349947)
+++ head/sys/amd64/include/vmm.hFri Jul 12 18:37:56 2019
(r349948)
@@ -114,9 +114,30 @@ enum x2apic_state {
 #defineVM_INTINFO_HWEXCEPTION  (3 << 8)
 #defineVM_INTINFO_SWINTR   (4 << 8)
 
-#ifdef _KERNEL
+/*
+ * The VM name has to fit into the pathname length constraints of devfs,
+ * governed primarily by SPECNAMELEN.  The length is the total number of
+ * characters in the full path, relative to the mount point and not 
+ * including any leading '/' characters.
+ * A prefix and a suffix are added to the name specified by the user.
+ * The prefix is usually "vmm/" or "vmm.io/", but can be a few characters
+ * longer for future use.
+ * The suffix is a string that identifies a bootrom image or some similar
+ * image that is attached to the VM. A separator character gets added to
+ * the suffix automatically when generating the full path, so it must be
+ * accounted for, reducing the effective length by 1.
+ * The effective length of a VM name is 229 bytes for FreeBSD 13 and 37
+ * bytes for FreeBSD 12.  A minimum length is set for safety and supports
+ * a SPECNAMELEN as small as 32 on old systems.
+ */
+#define VM_MAX_PREFIXLEN 10
+#define VM_MAX_SUFFIXLEN 15
+#define VM_MIN_NAMELEN   6
+#define VM_MAX_NAMELEN \
+(SPECNAMELEN - VM_MAX_PREFIXLEN - VM_MAX_SUFFIXLEN - 1)
 
-#defineVM_MAX_NAMELEN  32
+#ifdef _KERNEL
+CTASSERT(VM_MAX_NAMELEN >= VM_MIN_NAMELEN);
 
 struct vm;
 struct vm_exception;

Modified: head/sys/amd64/include/vmm_dev.h
==
--- head/sys/amd64/include/vmm_dev.hFri Jul 12 18:33:58 2019
(r349947)
+++ head/sys/amd64/include/vmm_dev.hFri Jul 12 18:37:56 2019
(r349948)
@@ -51,7 +51,7 @@ struct vm_memmap {
 struct vm_memseg {
int segid;
size_t  len;
-   charname[SPECNAMELEN + 1];
+   charname[VM_MAX_SUFFIXLEN + 1];
 };
 
 struct vm_register {

Modified: head/sys/amd64/vmm/vmm_dev.c
==
--- head/sys/amd64/vmm/vmm_dev.cFri Jul 12 18:33:58 2019
(r349947)
+++ head/sys/amd64/vmm/vmm_dev.cFri Jul 12 18:37:56 2019
(r349948)
@@ -245,7 +245,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flag
return (error);
 }
 
-CTASSERT(sizeof(((struct vm_memseg *)0)->name) >= SPECNAMELEN + 1);
+CTASSERT(sizeof(((struct vm_memseg *)0)->name) >= VM_MAX_SUFFIXLEN + 1);
 
 static int
 get_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg)
@@ -265,7 +265,8 @@ get_memseg(struct vmmdev_softc *sc, struct vm_memseg *
}
KASSERT(dsc != NULL, ("%s: devmem segment %d not found",
__func__, mseg->segid));
-   error = copystr(dsc->name, mseg->name, SPECNAMELEN + 1, NULL);
+   error = copystr(dsc->name, mseg->name, sizeof(mseg->name),
+   NULL);
} else {
bzero(mseg->name, sizeof(mseg->name));
}
@@ -284,10 +285,14 @@ alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg
name = NULL;
sysmem = true;
 
+   /*
+* The allocation is lengthened by 1 to hold a terminating NUL.  It'll
+* by stripped off when devfs processes the full string.
+*/
if (VM_MEMSEG_NAME(mseg)) {
sysmem = false;
-   name = malloc(SPECNAMELEN + 1, M_VMMDEV, M_WAITOK);
-   error = copystr(mseg->name, name, SPECNAMELEN + 1, 0);
+   name = malloc(sizeof(mseg->name) M_VMMDEV, M_WAITOK);
+   error = copystr(mseg->name, name, sizeof(mseg->name), NULL);
if (error)
goto done;
}
@@ -894,26 +899,29 @@ vmmdev_destroy(void *arg)
 static int
 sysctl_vmm_destroy(SYSCTL_HANDLER_ARGS)
 {
-   int error;
-   char buf[VM_MAX_NAMELEN];
struct devmem_softc *dsc;
struct vmmdev_softc *sc;
struct cdev *cdev;
+   char *buf;
+   int error, buflen;
 

svn commit: r349947 - head/usr.sbin/bhyve

2019-07-12 Thread Sean Chittenden
Author: seanc (ports committer)
Date: Fri Jul 12 18:33:58 2019
New Revision: 349947
URL: https://svnweb.freebsd.org/changeset/base/349947

Log:
  usr.sbin/bhyve: only unassign a pt device after obtaining bus/slot/func
  
  Coverity CID: 1194302, 1194303, 1194304
  Approved by:  jhb, markj
  Differential Revision:https://reviews.freebsd.org/D20933

Modified:
  head/usr.sbin/bhyve/pci_passthru.c

Modified: head/usr.sbin/bhyve/pci_passthru.c
==
--- head/usr.sbin/bhyve/pci_passthru.c  Fri Jul 12 18:20:56 2019
(r349946)
+++ head/usr.sbin/bhyve/pci_passthru.c  Fri Jul 12 18:33:58 2019
(r349947)
@@ -668,14 +668,14 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
memflags = vm_get_memflags(ctx);
if (!(memflags & VM_MEM_F_WIRED)) {
warnx("passthru requires guest memory to be wired");
-   goto done;
+   return (error);
}
 
if (pcifd < 0) {
pcifd = open(_PATH_DEVPCI, O_RDWR, 0);
if (pcifd < 0) {
warn("failed to open %s", _PATH_DEVPCI);
-   goto done;
+   return (error);
}
}
 
@@ -690,7 +690,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
iofd = open(_PATH_DEVIO, O_RDWR, 0);
if (iofd < 0) {
warn("failed to open %s", _PATH_DEVIO);
-   goto done;
+   return (error);
}
}
 
@@ -705,7 +705,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
memfd = open(_PATH_MEM, O_RDWR, 0);
if (memfd < 0) {
warn("failed to open %s", _PATH_MEM);
-   goto done;
+   return (error);
}
}
 
@@ -719,7 +719,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
if (opts == NULL ||
sscanf(opts, "%d/%d/%d", , , ) != 3) {
warnx("invalid passthru options");
-   goto done;
+   return (error);
}
 
if (vm_assign_pptdev(ctx, bus, slot, func) != 0) {
@@ -734,10 +734,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
sc->psc_pi = pi;
 
/* initialize config space */
-   if ((error = cfginit(ctx, pi, bus, slot, func)) != 0)
-   goto done;
-   
-   error = 0;  /* success */
+   error = cfginit(ctx, pi, bus, slot, func);
 done:
if (error) {
free(sc);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349946 - head/usr.sbin/bhyve

2019-07-12 Thread Sean Chittenden
Author: seanc (ports committer)
Date: Fri Jul 12 18:20:56 2019
New Revision: 349946
URL: https://svnweb.freebsd.org/changeset/base/349946

Log:
  usr.sbin/bhyve: free resources when erroring out of pci_vtcon_sock_add()
  
  Coverity CID: 1362880
  Approved by:  markj, jhb
  Differential Revision:https://reviews.freebsd.org/D20916

Modified:
  head/usr.sbin/bhyve/pci_virtio_console.c

Modified: head/usr.sbin/bhyve/pci_virtio_console.c
==
--- head/usr.sbin/bhyve/pci_virtio_console.cFri Jul 12 18:17:35 2019
(r349945)
+++ head/usr.sbin/bhyve/pci_virtio_console.cFri Jul 12 18:20:56 2019
(r349946)
@@ -356,8 +356,11 @@ out:
if (fd != -1)
close(fd);
 
-   if (error != 0 && s != -1)
-   close(s);
+   if (error != 0) {
+   if (s != -1)
+   close(s);
+   free(sock);
+   }
 
return (error);
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349945 - head/usr.sbin/bhyve

2019-07-12 Thread Sean Chittenden
Author: seanc (ports committer)
Date: Fri Jul 12 18:17:35 2019
New Revision: 349945
URL: https://svnweb.freebsd.org/changeset/base/349945

Log:
  usr.sbin/bhyve: prevent use-after-free in virtio scsi request handling
  
  Coverity CID: 1393377
  Approved by:  araujo, jhb
  Differential Revision:https://reviews.freebsd.org/D20915

Modified:
  head/usr.sbin/bhyve/pci_virtio_scsi.c

Modified: head/usr.sbin/bhyve/pci_virtio_scsi.c
==
--- head/usr.sbin/bhyve/pci_virtio_scsi.c   Fri Jul 12 18:13:58 2019
(r349944)
+++ head/usr.sbin/bhyve/pci_virtio_scsi.c   Fri Jul 12 18:17:35 2019
(r349945)
@@ -465,7 +465,7 @@ pci_vtscsi_request_handle(struct pci_vtscsi_queue *q, 
int data_niov_in, data_niov_out;
void *ext_data_ptr = NULL;
uint32_t ext_data_len = 0, ext_sg_entries = 0;
-   int err;
+   int err, nxferred;
 
seek_iov(iov_in, niov_in, data_iov_in, _niov_in,
VTSCSI_IN_HEADER_LEN(sc));
@@ -544,10 +544,11 @@ pci_vtscsi_request_handle(struct pci_vtscsi_queue *q, 
}
 
buf_to_iov(cmd_wr, VTSCSI_OUT_HEADER_LEN(sc), iov_out, niov_out, 0);
+   nxferred = VTSCSI_OUT_HEADER_LEN(sc) + io->scsiio.ext_data_filled;
free(cmd_rd);
free(cmd_wr);
ctl_scsi_free_io(io);
-   return (VTSCSI_OUT_HEADER_LEN(sc) + io->scsiio.ext_data_filled);
+   return (nxferred);
 }
 
 static void
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349944 - head/usr.sbin/bhyve

2019-07-12 Thread Sean Chittenden
Author: seanc (ports committer)
Date: Fri Jul 12 18:13:58 2019
New Revision: 349944
URL: https://svnweb.freebsd.org/changeset/base/349944

Log:
  usr.sbin/bhyve: don't leak a FD if the device is not a tty
  
  Coverity CID: 1194193
  Approved by:  markj, jhb
  Differential Revision:https://reviews.freebsd.org/D20934

Modified:
  head/usr.sbin/bhyve/uart_emul.c

Modified: head/usr.sbin/bhyve/uart_emul.c
==
--- head/usr.sbin/bhyve/uart_emul.c Fri Jul 12 15:24:25 2019
(r349943)
+++ head/usr.sbin/bhyve/uart_emul.c Fri Jul 12 18:13:58 2019
(r349944)
@@ -678,8 +678,13 @@ uart_tty_backend(struct uart_softc *sc, const char *op
int fd;
 
fd = open(opts, O_RDWR | O_NONBLOCK);
-   if (fd < 0 || !isatty(fd))
+   if (fd < 0)
return (-1);
+
+   if (!isatty(fd)) {
+   close(fd);
+   return (-1);
+   }
 
sc->tty.rfd = sc->tty.wfd = fd;
sc->tty.opened = true;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


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

2019-07-12 Thread Mark Johnston
Author: markj
Date: Fri Jul 12 15:24:25 2019
New Revision: 349943
URL: https://svnweb.freebsd.org/changeset/base/349943

Log:
  Apply some light cleanup to uses of pmap_pte_dirty().
  
  - Check for ATTR_SW_MANAGED before anything else.
  - Use pmap_pte_dirty() in pmap_remove_pages().
  
  No functional change intended.
  
  Reviewed by:  alc
  MFC after:1 week
  Sponsored by: The FreeBSD Foundation

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

Modified: head/sys/arm64/arm64/pmap.c
==
--- head/sys/arm64/arm64/pmap.c Fri Jul 12 11:45:42 2019(r349942)
+++ head/sys/arm64/arm64/pmap.c Fri Jul 12 15:24:25 2019(r349943)
@@ -2812,9 +2812,8 @@ pmap_protect_l2(pmap_t pmap, pt_entry_t *l2, vm_offset
 * update the dirty field of each of the superpage's constituent 4KB
 * pages.
 */
-   if ((nbits & ATTR_AP(ATTR_AP_RO)) != 0 &&
-   (old_l2 & ATTR_SW_MANAGED) != 0 &&
-   pmap_pte_dirty(old_l2)) {
+   if ((old_l2 & ATTR_SW_MANAGED) != 0 &&
+   (nbits & ATTR_AP(ATTR_AP_RO)) != 0 && pmap_pte_dirty(old_l2)) {
m = PHYS_TO_VM_PAGE(old_l2 & ~ATTR_MASK);
for (mt = m; mt < [L2_SIZE / PAGE_SIZE]; mt++)
vm_page_dirty(mt);
@@ -2920,8 +2919,8 @@ pmap_protect(pmap_t pmap, vm_offset_t sva, vm_offset_t
 * When a dirty read/write mapping is write protected,
 * update the page's dirty field.
 */
-   if ((nbits & ATTR_AP(ATTR_AP_RO)) != 0 &&
-   (l3 & ATTR_SW_MANAGED) != 0 &&
+   if ((l3 & ATTR_SW_MANAGED) != 0 &&
+   (nbits & ATTR_AP(ATTR_AP_RO)) != 0 &&
pmap_pte_dirty(l3))
vm_page_dirty(PHYS_TO_VM_PAGE(l3 & ~ATTR_MASK));
 
@@ -3344,8 +3343,8 @@ validate:
/* same PA, different attributes */
pmap_load_store(l3, new_l3);
pmap_invalidate_page(pmap, va);
-   if (pmap_pte_dirty(orig_l3) &&
-   (orig_l3 & ATTR_SW_MANAGED) != 0)
+   if ((orig_l3 & ATTR_SW_MANAGED) != 0 &&
+   pmap_pte_dirty(orig_l3))
vm_page_dirty(m);
} else {
/*
@@ -4293,8 +4292,7 @@ pmap_remove_pages(pmap_t pmap)
/*
 * Update the vm_page_t clean/reference bits.
 */
-   if ((tpte & ATTR_AP_RW_BIT) ==
-   ATTR_AP(ATTR_AP_RW)) {
+   if (pmap_pte_dirty(tpte)) {
switch (lvl) {
case 1:
for (mt = m; mt < [L2_SIZE / 
PAGE_SIZE]; mt++)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349942 - head/sys/netinet/tcp_stacks

2019-07-12 Thread Randall Stewart
Author: rrs
Date: Fri Jul 12 11:45:42 2019
New Revision: 349942
URL: https://svnweb.freebsd.org/changeset/base/349942

Log:
  add back the comment around the pending DSACK fixes.

Modified:
  head/sys/netinet/tcp_stacks/rack.c

Modified: head/sys/netinet/tcp_stacks/rack.c
==
--- head/sys/netinet/tcp_stacks/rack.c  Fri Jul 12 09:59:21 2019
(r349941)
+++ head/sys/netinet/tcp_stacks/rack.c  Fri Jul 12 11:45:42 2019
(r349942)
@@ -8537,10 +8537,10 @@ out:
 * retransmit.  In persist state, just set snd_max.
 */
if (error == 0) {
-   if (TCPS_HAVEESTABLISHED(tp->t_state) &&
+/* if (TCPS_HAVEESTABLISHED(tp->t_state) &&
(tp->t_flags & TF_SACK_PERMIT) &&
tp->rcv_numsacks > 0)
-   tcp_clean_dsack_blocks(tp);
+   tcp_clean_dsack_blocks(tp);*/
if (len == 0)
counter_u64_add(rack_out_size[TCP_MSS_ACCT_SNDACK], 1);
else if (len == 1) {
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r349907 - head/sys/netinet/tcp_stacks

2019-07-12 Thread Randall Stewart via svn-src-all
opps.. that was a error on my part I will fix it :)


> On Jul 11, 2019, at 4:37 AM, Enji Cooper  wrote:
> 
> 
>> On Jul 10, 2019, at 9:38 PM, Randall Stewart  wrote:
>> 
>> Author: rrs
>> Date: Thu Jul 11 04:38:33 2019
>> New Revision: 349907
>> URL: https://svnweb.freebsd.org/changeset/base/349907
>> 
>> Log:
>>  Update copyright per JBH's suggestions.. thanks.
>> 
>> Modified:
>>  head/sys/netinet/tcp_stacks/rack.c
>> 
>> Modified: head/sys/netinet/tcp_stacks/rack.c
>> ==
>> --- head/sys/netinet/tcp_stacks/rack.c   Thu Jul 11 03:29:25 2019
>> (r349906)
>> +++ head/sys/netinet/tcp_stacks/rack.c   Thu Jul 11 04:38:33 2019
>> (r349907)
>> @@ -1,5 +1,5 @@
>> /*-
>> - * Copyright (c) 2016
>> + * Copyright (c) 2016-2019
>>  *   Netflix Inc.  All rights reserved.
>>  *
>>  * Redistribution and use in source and binary forms, with or without
>> @@ -8537,10 +8537,10 @@ out:
>>   * retransmit.  In persist state, just set snd_max.
>>   */
>>  if (error == 0) {
>> -/*  if (TCPS_HAVEESTABLISHED(tp->t_state) &&
>> +if (TCPS_HAVEESTABLISHED(tp->t_state) &&
>>  (tp->t_flags & TF_SACK_PERMIT) &&
>>  tp->rcv_numsacks > 0)
>> -tcp_clean_dsack_blocks(tp);*/
>> +tcp_clean_dsack_blocks(tp);
> 
>   Removing this commented out code unfortunately broke the build: 
> https://ci.freebsd.org/job/FreeBSD-head-amd64-LINT/12934/console .
> Thanks,
> -Enji
> 

--
Randall Stewart
r...@netflix.com



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


svn commit: r349941 - head/sys/netpfil/ipfw

2019-07-12 Thread Andrey V. Elsukov
Author: ae
Date: Fri Jul 12 09:59:21 2019
New Revision: 349941
URL: https://svnweb.freebsd.org/changeset/base/349941

Log:
  Do not modify cmd pointer if it is already last opcode in the rule.
  
  MFC after:1 week

Modified:
  head/sys/netpfil/ipfw/ip_fw_eaction.c

Modified: head/sys/netpfil/ipfw/ip_fw_eaction.c
==
--- head/sys/netpfil/ipfw/ip_fw_eaction.c   Fri Jul 12 09:48:42 2019
(r349940)
+++ head/sys/netpfil/ipfw/ip_fw_eaction.c   Fri Jul 12 09:59:21 2019
(r349941)
@@ -387,7 +387,7 @@ ipfw_reset_eaction(struct ip_fw_chain *ch, struct ip_f
while (l > 0) {
cmdlen = F_LEN(cmd);
l -= cmdlen;
-   if (cmd->opcode == O_EXTERNAL_ACTION)
+   if (cmd->opcode == O_EXTERNAL_ACTION || l <= 0)
break;
cmd += cmdlen;
}
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349940 - head/sys/netpfil/ipfw

2019-07-12 Thread Andrey V. Elsukov
Author: ae
Date: Fri Jul 12 09:48:42 2019
New Revision: 349940
URL: https://svnweb.freebsd.org/changeset/base/349940

Log:
  Correctly truncate the rule in case when it has several action opcodes.
  
  It is possible, that opcode at the ACTION_PTR() location is not real
  action, but action modificator like "log", "tag" etc. In this case we
  need to check for each opcode in the loop to find O_EXTERNAL_ACTION.
  
  Obtained from:Yandex LLC
  MFC after:1 week
  Sponsored by: Yandex LLC

Modified:
  head/sys/netpfil/ipfw/ip_fw_eaction.c

Modified: head/sys/netpfil/ipfw/ip_fw_eaction.c
==
--- head/sys/netpfil/ipfw/ip_fw_eaction.c   Fri Jul 12 09:02:12 2019
(r349939)
+++ head/sys/netpfil/ipfw/ip_fw_eaction.c   Fri Jul 12 09:48:42 2019
(r349940)
@@ -377,35 +377,51 @@ ipfw_reset_eaction(struct ip_fw_chain *ch, struct ip_f
 uint16_t eaction_id, uint16_t default_id, uint16_t instance_id)
 {
ipfw_insn *cmd, *icmd;
+   int l, cmdlen;
 
IPFW_UH_WLOCK_ASSERT(ch);
IPFW_WLOCK_ASSERT(ch);
 
cmd = ACTION_PTR(rule);
+   l = rule->cmd_len - rule->act_ofs;
+   while (l > 0) {
+   cmdlen = F_LEN(cmd);
+   l -= cmdlen;
+   if (cmd->opcode == O_EXTERNAL_ACTION)
+   break;
+   cmd += cmdlen;
+   }
+   /*
+* Return if there is not O_EXTERNAL_ACTION or its id is
+* different.
+*/
if (cmd->opcode != O_EXTERNAL_ACTION ||
cmd->arg1 != eaction_id)
return (0);
-
-   if (instance_id != 0 && rule->act_ofs < rule->cmd_len - 1) {
+   /*
+* If instance_id is specified, we need to truncate the
+* rule length. Check if there is O_EXTERNAL_INSTANCE opcode.
+*/
+   if (instance_id != 0 && l > 0) {
+   MPASS(cmdlen == 1);
icmd = cmd + 1;
if (icmd->opcode != O_EXTERNAL_INSTANCE ||
icmd->arg1 != instance_id)
return (0);
-   /* FALLTHROUGH */
+   /*
+* Since named_object related to this instance will be
+* destroyed, truncate the chain of opcodes to remove
+* the rest of cmd chain just after O_EXTERNAL_ACTION
+* opcode.
+*/
+   EACTION_DEBUG("truncate rule %d: len %u -> %u",
+   rule->rulenum, rule->cmd_len, rule->cmd_len - l);
+   rule->cmd_len -= l;
+   MPASS(((uint32_t *)icmd -
+   (uint32_t *)rule->cmd) == rule->cmd_len);
}
 
cmd->arg1 = default_id; /* Set to default id */
-   /*
-* Since named_object related to this instance will be
-* also destroyed, truncate the chain of opcodes to
-* remove the rest of cmd chain just after O_EXTERNAL_ACTION
-* opcode.
-*/
-   if (rule->act_ofs < rule->cmd_len - 1) {
-   EACTION_DEBUG("truncate rule %d: len %u -> %u",
-   rule->rulenum, rule->cmd_len, rule->act_ofs + 1);
-   rule->cmd_len = rule->act_ofs + 1;
-   }
/*
 * Return 1 when reset successfully happened.
 */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r349939 - head/sys/dev/usb/serial

2019-07-12 Thread Poul-Henning Kamp
Author: phk
Date: Fri Jul 12 09:02:12 2019
New Revision: 349939
URL: https://svnweb.freebsd.org/changeset/base/349939

Log:
  Support multiple serial ports per device.
  
  Enable this for the NovAtel OEMv2 GPS receiver.
  
  Not fixed:  The receiver shows up as "" in the device
  tree, because that is literally what the descriptor-string is.
  
  Reviewed by:  hselasky@

Modified:
  head/sys/dev/usb/serial/ugensa.c

Modified: head/sys/dev/usb/serial/ugensa.c
==
--- head/sys/dev/usb/serial/ugensa.cFri Jul 12 06:19:25 2019
(r349938)
+++ head/sys/dev/usb/serial/ugensa.cFri Jul 12 09:02:12 2019
(r349939)
@@ -70,6 +70,7 @@
 #defineUGENSA_CONFIG_INDEX 0
 #defineUGENSA_IFACE_INDEX  0
 #defineUGENSA_IFACE_MAX8   /* exclusivly */
+#defineUGENSA_PORT_MAX 8   /* exclusivly */
 
 enum {
UGENSA_BULK_DT_WR,
@@ -84,11 +85,11 @@ struct ugensa_sub_softc {
 
 struct ugensa_softc {
struct ucom_super_softc sc_super_ucom;
-   struct ucom_softc sc_ucom[UGENSA_IFACE_MAX];
-   struct ugensa_sub_softc sc_sub[UGENSA_IFACE_MAX];
+   struct ucom_softc sc_ucom[UGENSA_PORT_MAX];
+   struct ugensa_sub_softc sc_sub[UGENSA_PORT_MAX];
 
struct mtx sc_mtx;
-   uint8_t sc_niface;
+   uint8_t sc_nports;
 };
 
 /* prototypes */
@@ -154,12 +155,13 @@ static driver_t ugensa_driver = {
.size = sizeof(struct ugensa_softc),
 };
 
+/* Driver-info is max number of serial ports per interface */
 static const STRUCT_USB_HOST_ID ugensa_devs[] = {
-   {USB_VPI(USB_VENDOR_AIRPRIME, USB_PRODUCT_AIRPRIME_PC5220, 0)},
-   {USB_VPI(USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CDMA_MODEM1, 0)},
-   {USB_VPI(USB_VENDOR_KYOCERA2, USB_PRODUCT_KYOCERA2_CDMA_MSM_K, 0)},
-   {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_49GPLUS, 0)},
-   {USB_VPI(USB_VENDOR_NOVATEL2, USB_PRODUCT_NOVATEL2_FLEXPACKGPS, 0)},
+   {USB_VPI(USB_VENDOR_AIRPRIME, USB_PRODUCT_AIRPRIME_PC5220, 1)},
+   {USB_VPI(USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CDMA_MODEM1, 1)},
+   {USB_VPI(USB_VENDOR_KYOCERA2, USB_PRODUCT_KYOCERA2_CDMA_MSM_K, 1)},
+   {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_49GPLUS, 1)},
+   {USB_VPI(USB_VENDOR_NOVATEL2, USB_PRODUCT_NOVATEL2_FLEXPACKGPS, 3)},
 };
 
 DRIVER_MODULE(ugensa, uhub, ugensa_driver, ugensa_devclass, NULL, 0);
@@ -192,65 +194,68 @@ ugensa_attach(device_t dev)
struct ugensa_softc *sc = device_get_softc(dev);
struct ugensa_sub_softc *ssc;
struct usb_interface *iface;
+   struct usb_config xfer_config[UGENSA_N_TRANSFER];
int32_t error;
uint8_t iface_index;
-   int x, cnt;
+   int x, maxports;
 
+   maxports = USB_GET_DRIVER_INFO(uaa);
device_set_usb_desc(dev);
mtx_init(>sc_mtx, "ugensa", NULL, MTX_DEF);
ucom_ref(>sc_super_ucom);
 
-   /* Figure out how many interfaces this device has got */
-   for (cnt = 0; cnt < UGENSA_IFACE_MAX; cnt++) {
-   if ((usbd_get_endpoint(uaa->device, cnt, ugensa_xfer_config + 
0) == NULL) ||
-   (usbd_get_endpoint(uaa->device, cnt, ugensa_xfer_config + 
1) == NULL)) {
-   /* we have reached the end */
-   break;
-   }
-   }
+   for (iface_index = UGENSA_IFACE_INDEX; iface_index < UGENSA_IFACE_MAX; 
iface_index++) {
 
-   if (cnt == 0) {
-   device_printf(dev, "No interfaces\n");
-   goto detach;
-   }
-   for (x = 0; x < cnt; x++) {
-   iface = usbd_get_iface(uaa->device, x);
-   if (iface->idesc->bInterfaceClass != UICLASS_VENDOR)
+   iface = usbd_get_iface(uaa->device, iface_index);
+   if (iface == NULL || iface->idesc->bInterfaceClass != 
UICLASS_VENDOR)
/* Not a serial port, most likely a SD reader */
continue;
 
-   ssc = sc->sc_sub + sc->sc_niface;
-   ssc->sc_ucom_ptr = sc->sc_ucom + sc->sc_niface;
+   /* Loop over all endpoints pairwise */
+   for (x = 0; x < maxports && sc->sc_nports < UGENSA_PORT_MAX; 
x++) {
 
-   iface_index = (UGENSA_IFACE_INDEX + x);
-   error = usbd_transfer_setup(uaa->device,
-   _index, ssc->sc_xfer, ugensa_xfer_config,
-   UGENSA_N_TRANSFER, ssc, >sc_mtx);
+   ssc = sc->sc_sub + sc->sc_nports;
+   ssc->sc_ucom_ptr = sc->sc_ucom + sc->sc_nports;
 
-   if (error) {
-   device_printf(dev, "allocating USB "
-   "transfers failed\n");
-   goto detach;
-   }
-   /* clear stall at first run */
-   mtx_lock(>sc_mtx);
-   usbd_xfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
-   

svn commit: r349938 - head/usr.sbin/ppp

2019-07-12 Thread Warner Losh
Author: imp
Date: Fri Jul 12 06:19:25 2019
New Revision: 349938
URL: https://svnweb.freebsd.org/changeset/base/349938

Log:
  Retire the -DRELEASE_CRUNCH define.
  
  The RELEASE_CRUNCH ifdefs save about 100 bytes of text space. The
  complexity is not worth it as they eliminate error messages.
  
  Left the RELEASE_CRUNCH ifdef to eliminate a lot of stuff in place.
  That saves an interesting amount of space and change some behaviors,
  so absent a more detailed analysis, maintain the status quo.

Modified:
  head/usr.sbin/ppp/Makefile
  head/usr.sbin/ppp/bundle.c
  head/usr.sbin/ppp/physical.c

Modified: head/usr.sbin/ppp/Makefile
==
--- head/usr.sbin/ppp/Makefile  Fri Jul 12 05:53:13 2019(r349937)
+++ head/usr.sbin/ppp/Makefile  Fri Jul 12 06:19:25 2019(r349938)
@@ -12,7 +12,6 @@ SRCS= acf.c arp.c async.c auth.c bundle.c cbcp.c ccp.c
tcpmss.c throughput.c timer.c tty.c tun.c udp.c vjcomp.c
 WARNS?=3
 .if defined(RELEASE_CRUNCH)
-CFLAGS+=-DRELEASE_CRUNCH
 PPP_NO_DES=
 PPP_NO_KLDLOAD=
 PPP_NO_NAT=

Modified: head/usr.sbin/ppp/bundle.c
==
--- head/usr.sbin/ppp/bundle.c  Fri Jul 12 05:53:13 2019(r349937)
+++ head/usr.sbin/ppp/bundle.c  Fri Jul 12 06:19:25 2019(r349938)
@@ -678,12 +678,9 @@ bundle_LockTun(struct bundle *bundle)
   if (lockfile != NULL) {
 fprintf(lockfile, "%d\n", (int)getpid());
 fclose(lockfile);
-  }
-#ifndef RELEASE_CRUNCH
-  else
+  } else
 log_Printf(LogERROR, "Warning: Can't create %s: %s\n",
pidfile, strerror(errno));
-#endif
 }
 
 static void

Modified: head/usr.sbin/ppp/physical.c
==
--- head/usr.sbin/ppp/physical.cFri Jul 12 05:53:13 2019
(r349937)
+++ head/usr.sbin/ppp/physical.cFri Jul 12 06:19:25 2019
(r349938)
@@ -364,13 +364,9 @@ physical_Close(struct physical *p)
 
   if (*p->name.full == '/') {
 snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, p->name.base);
-#ifndef RELEASE_CRUNCH
 if (ID0unlink(fn) == -1)
   log_Printf(LogALERT, "%s: Can't remove %s: %s\n",
  p->link.name, fn, strerror(errno));
-#else
-ID0unlink(fn);
-#endif
   }
   physical_Unlock(p);
   if (p->handler && p->handler->destroy)
@@ -978,12 +974,9 @@ physical_Found(struct physical *p)
 if (lockfile != NULL) {
   fprintf(lockfile, "%s%d\n", TUN_NAME, p->dl->bundle->unit);
   fclose(lockfile);
-}
-#ifndef RELEASE_CRUNCH
-else
+} else
   log_Printf(LogALERT, "%s: Can't create %s: %s\n",
  p->link.name, fn, strerror(errno));
-#endif
   }
 
   throughput_start(>link.stats.total, "physical throughput",
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"