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

2020-10-13 Thread Tycho Nightingale
Author: tychon
Date: Tue Oct 13 18:28:48 2020
New Revision: 366678
URL: https://svnweb.freebsd.org/changeset/base/366678

Log:
  eliminate possible race in parallel TLB shootdown IPI
  
  On the target side TLB shootdown IPI handler, prevent the compiler
  from performing a forward store optimization which may mask a
  subsequent update to the scoreboard by the initiator.
  
  Reported by:  Max Laier, Anton Rang
  Discussed with:   kib
  Sponsored by: Dell EMC Isilon

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

Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Tue Oct 13 18:04:19 2020
(r366677)
+++ head/sys/amd64/amd64/mp_machdep.c   Tue Oct 13 18:28:48 2020
(r366678)
@@ -1094,7 +1094,7 @@ invlop_handler(void)
for (;;) {
for (initiator_cpu_id = 0; initiator_cpu_id <= mp_maxid;
initiator_cpu_id++) {
-   if (scoreboard[initiator_cpu_id] == 0)
+   if (atomic_load_int([initiator_cpu_id]) == 0)
break;
}
if (initiator_cpu_id > mp_maxid)
___
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: r362540 - head/sys/net

2020-06-23 Thread Tycho Nightingale
Author: tychon
Date: Tue Jun 23 13:57:53 2020
New Revision: 362540
URL: https://svnweb.freebsd.org/changeset/base/362540

Log:
  To avoid a startup script race change net.bpf.optimize_writers from
  CTLFLAG_RW to CTLFLAG_RWTUN to allow it to be modified by a loader
  tunable.
  
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/net/bpf.c

Modified: head/sys/net/bpf.c
==
--- head/sys/net/bpf.c  Tue Jun 23 11:40:11 2020(r362539)
+++ head/sys/net/bpf.c  Tue Jun 23 13:57:53 2020(r362540)
@@ -227,7 +227,7 @@ static SYSCTL_NODE(_net_bpf, OID_AUTO, stats, CTLFLAG_
 
 VNET_DEFINE_STATIC(int, bpf_optimize_writers) = 0;
 #defineV_bpf_optimize_writers VNET(bpf_optimize_writers)
-SYSCTL_INT(_net_bpf, OID_AUTO, optimize_writers, CTLFLAG_VNET | CTLFLAG_RW,
+SYSCTL_INT(_net_bpf, OID_AUTO, optimize_writers, CTLFLAG_VNET | CTLFLAG_RWTUN,
 _NAME(bpf_optimize_writers), 0,
 "Do not send packets until BPF program is set");
 
___
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: r346645 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src sys

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr 24 20:30:45 2019
New Revision: 346645
URL: https://svnweb.freebsd.org/changeset/base/346645

Log:
  LinuxKPI should use bus_dma(9) to be compatible with an IOMMU
  
  Reviewed by:  hselasky, kib
  Tested by:greg@unrelenting.technology
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19845

Modified:
  head/sys/compat/linuxkpi/common/include/linux/device.h
  head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
  head/sys/compat/linuxkpi/common/include/linux/dmapool.h
  head/sys/compat/linuxkpi/common/include/linux/pci.h
  head/sys/compat/linuxkpi/common/include/linux/scatterlist.h
  head/sys/compat/linuxkpi/common/src/linux_pci.c
  head/sys/sys/param.h

Modified: head/sys/compat/linuxkpi/common/include/linux/device.h
==
--- head/sys/compat/linuxkpi/common/include/linux/device.h  Wed Apr 24 
19:56:02 2019(r346644)
+++ head/sys/compat/linuxkpi/common/include/linux/device.h  Wed Apr 24 
20:30:45 2019(r346645)
@@ -105,7 +105,7 @@ struct device {
struct class*class;
void(*release)(struct device *dev);
struct kobject  kobj;
-   uint64_t*dma_mask;
+   void*dma_priv;
void*driver_data;
unsigned intirq;
 #defineLINUX_IRQ_INVALID   65535

Modified: head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
==
--- head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h Wed Apr 24 
19:56:02 2019(r346644)
+++ head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h Wed Apr 24 
20:30:45 2019(r346645)
@@ -90,6 +90,16 @@ struct dma_map_ops {
 
 #defineDMA_BIT_MASK(n) ((2ULL << ((n) - 1)) - 1ULL)
 
+int linux_dma_tag_init(struct device *dev, u64 mask);
+void *linux_dma_alloc_coherent(struct device *dev, size_t size,
+dma_addr_t *dma_handle, gfp_t flag);
+dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len);
+void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size);
+int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
+int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
+void linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
+int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
+
 static inline int
 dma_supported(struct device *dev, u64 mask)
 {
@@ -102,11 +112,10 @@ static inline int
 dma_set_mask(struct device *dev, u64 dma_mask)
 {
 
-   if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+   if (!dev->dma_priv || !dma_supported(dev, dma_mask))
return -EIO;
 
-   *dev->dma_mask = dma_mask;
-   return (0);
+   return (linux_dma_tag_init(dev, dma_mask));
 }
 
 static inline int
@@ -134,24 +143,7 @@ static inline void *
 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
 gfp_t flag)
 {
-   vm_paddr_t high;
-   size_t align;
-   void *mem;
-
-   if (dev != NULL && dev->dma_mask)
-   high = *dev->dma_mask;
-   else if (flag & GFP_DMA32)
-   high = BUS_SPACE_MAXADDR_32BIT;
-   else
-   high = BUS_SPACE_MAXADDR;
-   align = PAGE_SIZE << get_order(size);
-   mem = (void *)kmem_alloc_contig(size, flag, 0, high, align, 0,
-   VM_MEMATTR_DEFAULT);
-   if (mem)
-   *dma_handle = vtophys(mem);
-   else
-   *dma_handle = 0;
-   return (mem);
+   return (linux_dma_alloc_coherent(dev, size, dma_handle, flag));
 }
 
 static inline void *
@@ -164,25 +156,27 @@ dma_zalloc_coherent(struct device *dev, size_t size, d
 
 static inline void
 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
-dma_addr_t dma_handle)
+dma_addr_t dma_addr)
 {
 
+   linux_dma_unmap(dev, dma_addr, size);
kmem_free((vm_offset_t)cpu_addr, size);
 }
 
-/* XXX This only works with no iommu. */
 static inline dma_addr_t
 dma_map_single_attrs(struct device *dev, void *ptr, size_t size,
 enum dma_data_direction dir, struct dma_attrs *attrs)
 {
 
-   return vtophys(ptr);
+   return (linux_dma_map_phys(dev, vtophys(ptr), size));
 }
 
 static inline void
-dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, size_t size,
+dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, size_t size,
 enum dma_data_direction dir, struct dma_attrs *attrs)
 {
+
+   linux_dma_unmap(dev, dma_addr, size);
 }
 
 static inline dma_addr_t
@@ -190,26 +184,23 @@ dma_map_page_attrs(struct device *dev, struct page *pa
 size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
 
-   return (VM_PAGE_TO_PHYS(page) + offset);
+   return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
 }
 
 static 

svn commit: r346386 - in head/sys: dev/bge dev/pci dev/twa x86/iommu

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 19 13:43:33 2019
New Revision: 346386
URL: https://svnweb.freebsd.org/changeset/base/346386

Log:
  remove the 4GB boundary requirement on PCI DMA segments
  
  Reviewed by:  kib
  Discussed with:   jhb
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19867

Modified:
  head/sys/dev/bge/if_bgereg.h
  head/sys/dev/pci/pci.c
  head/sys/dev/pci/pcivar.h
  head/sys/dev/twa/tw_osl.h
  head/sys/dev/twa/tw_osl_freebsd.c
  head/sys/x86/iommu/intel_ctx.c

Modified: head/sys/dev/bge/if_bgereg.h
==
--- head/sys/dev/bge/if_bgereg.hFri Apr 19 13:23:41 2019
(r346385)
+++ head/sys/dev/bge/if_bgereg.hFri Apr 19 13:43:33 2019
(r346386)
@@ -3067,3 +3067,11 @@ struct bge_softc {
 #defineBGE_LOCK_ASSERT(_sc)mtx_assert(&(_sc)->bge_mtx, MA_OWNED)
 #defineBGE_UNLOCK(_sc) mtx_unlock(&(_sc)->bge_mtx)
 #defineBGE_LOCK_DESTROY(_sc)   mtx_destroy(&(_sc)->bge_mtx)
+
+#ifdef BUS_SPACE_MAXADDR
+#if (BUS_SPACE_MAXADDR > 0x)
+#defineBGE_DMA_BOUNDARY(0x1)
+#else
+#defineBGE_DMA_BOUNDARY0
+#endif
+#endif

Modified: head/sys/dev/pci/pci.c
==
--- head/sys/dev/pci/pci.c  Fri Apr 19 13:23:41 2019(r346385)
+++ head/sys/dev/pci/pci.c  Fri Apr 19 13:43:33 2019(r346386)
@@ -4343,9 +4343,6 @@ pci_attach_common(device_t dev)
 {
struct pci_softc *sc;
int busno, domain;
-#ifdef PCI_DMA_BOUNDARY
-   int error, tag_valid;
-#endif
 #ifdef PCI_RES_BUS
int rid;
 #endif
@@ -4365,23 +4362,7 @@ pci_attach_common(device_t dev)
if (bootverbose)
device_printf(dev, "domain=%d, physical bus=%d\n",
domain, busno);
-#ifdef PCI_DMA_BOUNDARY
-   tag_valid = 0;
-   if (device_get_devclass(device_get_parent(device_get_parent(dev))) !=
-   devclass_find("pci")) {
-   error = bus_dma_tag_create(bus_get_dma_tag(dev), 1,
-   PCI_DMA_BOUNDARY, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
-   NULL, NULL, BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED,
-   BUS_SPACE_MAXSIZE, 0, NULL, NULL, >sc_dma_tag);
-   if (error)
-   device_printf(dev, "Failed to create DMA tag: %d\n",
-   error);
-   else
-   tag_valid = 1;
-   }
-   if (!tag_valid)
-#endif
-   sc->sc_dma_tag = bus_get_dma_tag(dev);
+   sc->sc_dma_tag = bus_get_dma_tag(dev);
return (0);
 }
 

Modified: head/sys/dev/pci/pcivar.h
==
--- head/sys/dev/pci/pcivar.h   Fri Apr 19 13:23:41 2019(r346385)
+++ head/sys/dev/pci/pcivar.h   Fri Apr 19 13:43:33 2019(r346386)
@@ -693,14 +693,6 @@ intpcie_link_reset(device_t port, int 
pcie_location);
 
 void   pci_print_faulted_dev(void);
 
-#ifdef BUS_SPACE_MAXADDR
-#if (BUS_SPACE_MAXADDR > 0x)
-#definePCI_DMA_BOUNDARY0x1
-#else
-#definePCI_DMA_BOUNDARY0
-#endif
-#endif
-
 #endif /* _SYS_BUS_H_ */
 
 /*

Modified: head/sys/dev/twa/tw_osl.h
==
--- head/sys/dev/twa/tw_osl.h   Fri Apr 19 13:23:41 2019(r346385)
+++ head/sys/dev/twa/tw_osl.h   Fri Apr 19 13:43:33 2019(r346386)
@@ -57,6 +57,12 @@
 #define TW_OSLI_MAX_NUM_IOS(TW_OSLI_MAX_NUM_REQUESTS - 2)
 #define TW_OSLI_MAX_NUM_AENS   0x100
 
+#ifdef PAE
+#defineTW_OSLI_DMA_BOUNDARY(1u << 31)
+#else
+#defineTW_OSLI_DMA_BOUNDARY((bus_size_t)((uint64_t)1 << 
32))
+#endif
+
 /* Possible values of req->state. */
 #define TW_OSLI_REQ_STATE_INIT 0x0 /* being initialized */
 #define TW_OSLI_REQ_STATE_BUSY 0x1 /* submitted to CL */

Modified: head/sys/dev/twa/tw_osl_freebsd.c
==
--- head/sys/dev/twa/tw_osl_freebsd.c   Fri Apr 19 13:23:41 2019
(r346385)
+++ head/sys/dev/twa/tw_osl_freebsd.c   Fri Apr 19 13:43:33 2019
(r346386)
@@ -551,7 +551,7 @@ tw_osli_alloc_mem(struct twa_softc *sc)
/* Create the parent dma tag. */
if (bus_dma_tag_create(bus_get_dma_tag(sc->bus_dev), /* parent */
sc->alignment,  /* alignment */
-   0,  /* boundary */
+   TW_OSLI_DMA_BOUNDARY,   /* boundary */
BUS_SPACE_MAXADDR,  /* lowaddr */
BUS_SPACE_MAXADDR,  /* highaddr */
NULL, NULL, /* filter, filterarg */


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

2019-09-03 Thread Tycho Nightingale


> On Apr 12, 2019, at 12:43 PM, Enji Cooper  wrote:
> 
> 
>> On Apr 12, 2019, at 5:46 AM, Tycho Nightingale  wrote:
>> 
>> Author: tychon
>> Date: Fri Apr 12 12:46:25 2019
>> New Revision: 346150
>> URL: https://svnweb.freebsd.org/changeset/base/346150
>> 
>> Log:
>> for a cache-only zone the destructor tries to destroy a non-existent keg
>> 
>> Reviewed by: markj
>> Sponsored by:Dell EMC Isilon
>> Differential Revision:   https://reviews.freebsd.org/D19835
> 
> 
> Hi Tycho!
>   Is the goal of this change to prevent a panic (with an INVARIANTS 
> kernel)?
> Thank you!
> -Enji

Hi,

The goal of this change is to fix a regression introduced in r343026.  It does 
cause a panic independent of INVARIANTS.  Fortunately there isn’t currently any 
in-tree code which triggers the panic.  It does however show up when running 
with the patch under review in D19845.

Tycho


___
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: r346150 - head/sys/vm

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 12 12:46:25 2019
New Revision: 346150
URL: https://svnweb.freebsd.org/changeset/base/346150

Log:
  for a cache-only zone the destructor tries to destroy a non-existent keg
  
  Reviewed by:  markj
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19835

Modified:
  head/sys/vm/uma_core.c

Modified: head/sys/vm/uma_core.c
==
--- head/sys/vm/uma_core.c  Fri Apr 12 10:13:17 2019(r346149)
+++ head/sys/vm/uma_core.c  Fri Apr 12 12:46:25 2019(r346150)
@@ -1916,10 +1916,10 @@ zone_dtor(void *arg, int size, void *udata)
 */
zone_drain_wait(zone, M_WAITOK);
/*
-* We only destroy kegs from non secondary zones.
+* We only destroy kegs from non secondary/non cache zones.
 */
-   if ((keg = zone->uz_keg) != NULL &&
-   (zone->uz_flags & UMA_ZONE_SECONDARY) == 0)  {
+   if ((zone->uz_flags & (UMA_ZONE_SECONDARY | UMA_ZFLAG_CACHE)) == 0) {
+   keg = zone->uz_keg;
rw_wlock(_rwlock);
LIST_REMOVE(keg, uk_link);
rw_wunlock(_rwlock);


___
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: r346050 - head/tools/tools/ioat

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  9 10:33:18 2019
New Revision: 346050
URL: https://svnweb.freebsd.org/changeset/base/346050

Log:
  ioatcontrol(8) crc-copy flag bug and misc usage tweak
  
  Reviewed by:  cem
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19855

Modified:
  head/tools/tools/ioat/ioatcontrol.c

Modified: head/tools/tools/ioat/ioatcontrol.c
==
--- head/tools/tools/ioat/ioatcontrol.c Tue Apr  9 10:17:24 2019
(r346049)
+++ head/tools/tools/ioat/ioatcontrol.c Tue Apr  9 10:33:18 2019
(r346050)
@@ -49,7 +49,7 @@ static void
 usage(void)
 {
 
-   printf("Usage: %s [-c period] [-EfmVz] channel-number num-txns 
[ "
+   printf("Usage: %s [-c period] [-EefmVxXz] channel-number num-txns 
[ "
"[ [duration]]]\n", getprogname());
printf("   %s -r [-c period] [-vVwz] channel-number address 
[]\n\n",
getprogname());
@@ -154,9 +154,11 @@ main(int argc, char **argv)
break;
case 'x':
xflag = true;
+   modeflags++;
break;
case 'X':
Xflag = true;
+   modeflags++;
break;
case 'z':
t.zero_stats = true;
@@ -172,7 +174,7 @@ main(int argc, char **argv)
usage();
 
if (modeflags > 1) {
-   printf("Invalid: Cannot use >1 mode flag (-E, -f, -m, or 
-r)\n");
+   printf("Invalid: Cannot use >1 mode flag (-E, -e, -f, -m, -r, 
-x or -X)\n");
usage();
}
 
@@ -191,7 +193,7 @@ main(int argc, char **argv)
t.testkind = IOAT_TEST_MEMCPY;
else if (xflag)
t.testkind = IOAT_TEST_DMA_CRC;
-   else if (xflag)
+   else if (Xflag)
t.testkind = IOAT_TEST_DMA_CRC_COPY;
 
t.channel_index = atoi(argv[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: r345813 - head/sys/dev/ioat

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  2 19:08:06 2019
New Revision: 345813
URL: https://svnweb.freebsd.org/changeset/base/345813

Log:
  ioat(4) should use bus_dma(9) for the operation source and destination
  addresses
  
  Reviewed by:  cem
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19725

Modified:
  head/sys/dev/ioat/ioat.c
  head/sys/dev/ioat/ioat_internal.h

Modified: head/sys/dev/ioat/ioat.c
==
--- head/sys/dev/ioat/ioat.cTue Apr  2 19:06:25 2019(r345812)
+++ head/sys/dev/ioat/ioat.cTue Apr  2 19:08:06 2019(r345813)
@@ -320,10 +320,26 @@ err:
return (error);
 }
 
+static inline int
+ioat_bus_dmamap_destroy(struct ioat_softc *ioat, const char *func,
+bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+   int error;
+
+   error = bus_dmamap_destroy(dmat, map);
+   if (error != 0) {
+   ioat_log_message(0,
+   "%s: bus_dmamap_destroy failed %d\n", func, error);
+   }
+
+   return (error);
+}
+
 static int
 ioat_detach(device_t device)
 {
struct ioat_softc *ioat;
+   int i, error;
 
ioat = DEVICE2SOFTC(device);
 
@@ -359,6 +375,47 @@ ioat_detach(device_t device)
bus_release_resource(device, SYS_RES_MEMORY,
ioat->pci_resource_id, ioat->pci_resource);
 
+   if (ioat->data_tag != NULL) {
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].src_dmamap);
+   if (error != 0)
+   return (error);
+   }
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].dst_dmamap);
+   if (error != 0)
+   return (error);
+   }
+
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].src2_dmamap);
+   if (error != 0)
+   return (error);
+   }
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].dst2_dmamap);
+   if (error != 0)
+   return (error);
+   }
+
+   bus_dma_tag_destroy(ioat->data_tag);
+   }
+
+   if (ioat->data_crc_tag != NULL) {
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_crc_tag, ioat->ring[i].crc_dmamap);
+   if (error != 0)
+   return (error);
+   }
+
+   bus_dma_tag_destroy(ioat->data_crc_tag);
+   }
+
if (ioat->ring != NULL)
ioat_free_ring(ioat, 1 << ioat->ring_size_order, ioat->ring);
 
@@ -523,6 +580,25 @@ ioat3_attach(device_t device)
 
ioat->hw_desc_ring = hw_desc;
 
+   error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
+   1, 0, BUS_SPACE_MAXADDR_40BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+   ioat->max_xfer_size, 1, ioat->max_xfer_size, 0, NULL, NULL,
+   >data_crc_tag);
+   if (error != 0) {
+   ioat_log_message(0, "%s: bus_dma_tag_create failed %d\n",
+   __func__, error);
+   return (error);
+   }
+
+   error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
+   1, 0, BUS_SPACE_MAXADDR_48BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+   ioat->max_xfer_size, 1, ioat->max_xfer_size, 0, NULL, NULL,
+   >data_tag);
+   if (error != 0) {
+   ioat_log_message(0, "%s: bus_dma_tag_create failed %d\n",
+   __func__, error);
+   return (error);
+   }
ioat->ring = malloc(num_descriptors * sizeof(*ring), M_IOAT,
M_ZERO | M_WAITOK);
 
@@ -530,6 +606,46 @@ ioat3_attach(device_t device)
for (i = 0; i < num_descriptors; i++) {
memset([i].bus_dmadesc, 0, sizeof(ring[i].bus_dmadesc));
ring[i].id = i;
+   error = bus_dmamap_create(ioat->data_tag, 0,
+[i].src_dmamap);
+   if (error != 0) {
+   ioat_log_message(0,
+   "%s: bus_dmamap_create failed %d\n", __func__,
+   error);
+   return (error);
+   }
+   error = bus_dmamap_create(ioat->data_tag, 0,
+  

svn commit: r345812 - in head: sys/dev/ioat tools/tools/ioat

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  2 19:06:25 2019
New Revision: 345812
URL: https://svnweb.freebsd.org/changeset/base/345812

Log:
  ioatcontrol(8) could exercise 8k-aligned copy with page-break, crc and
  crc-copy modes.
  
  Reviewed by:  cem
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19780

Modified:
  head/sys/dev/ioat/ioat_test.c
  head/sys/dev/ioat/ioat_test.h
  head/tools/tools/ioat/ioatcontrol.8
  head/tools/tools/ioat/ioatcontrol.c

Modified: head/sys/dev/ioat/ioat_test.c
==
--- head/sys/dev/ioat/ioat_test.c   Tue Apr  2 18:50:49 2019
(r345811)
+++ head/sys/dev/ioat/ioat_test.c   Tue Apr  2 19:06:25 2019
(r345812)
@@ -65,6 +65,7 @@ struct test_transaction {
void*buf[IOAT_MAX_BUFS];
uint32_tlength;
uint32_tdepth;
+   uint32_tcrc[IOAT_MAX_BUFS];
struct ioat_test*test;
TAILQ_ENTRY(test_transaction)   entry;
 };
@@ -312,6 +313,28 @@ ioat_test_submit_1_tx(struct ioat_test *test, bus_dmae
 
desc = ioat_copy_8k_aligned(dma, dest, dst2, src, src2,
cb, tx, flags);
+   } else if (test->testkind == IOAT_TEST_DMA_8K_PB) {
+   bus_addr_t src2, dst2;
+
+   src2 = vtophys((vm_offset_t)tx->buf[2*i+1] + PAGE_SIZE);
+   dst2 = vtophys((vm_offset_t)tx->buf[2*i] + PAGE_SIZE);
+
+   desc = ioat_copy_8k_aligned(dma, dest, dst2, src, src2,
+   cb, tx, flags);
+   } else if (test->testkind == IOAT_TEST_DMA_CRC) {
+   bus_addr_t crc;
+
+   tx->crc[i] = 0;
+   crc = vtophys((vm_offset_t)>crc[i]);
+   desc = ioat_crc(dma, src, tx->length,
+   NULL, crc, cb, tx, flags | DMA_CRC_STORE);
+   } else if (test->testkind == IOAT_TEST_DMA_CRC_COPY) {
+   bus_addr_t crc;
+
+   tx->crc[i] = 0;
+   crc = vtophys((vm_offset_t)>crc[i]);
+   desc = ioat_copy_crc(dma, dest, src, tx->length,
+   NULL, crc, cb, tx, flags | DMA_CRC_STORE);
}
if (desc == NULL)
break;
@@ -346,7 +369,8 @@ ioat_dma_test(void *arg)
test = arg;
memset(__DEVOLATILE(void *, test->status), 0, sizeof(test->status));
 
-   if (test->testkind == IOAT_TEST_DMA_8K &&
+   if ((test->testkind == IOAT_TEST_DMA_8K ||
+   test->testkind == IOAT_TEST_DMA_8K_PB) &&
test->buffer_size != 2 * PAGE_SIZE) {
ioat_test_log(0, "Asked for 8k test and buffer size isn't 
8k\n");
test->status[IOAT_TEST_INVALID_INPUT]++;

Modified: head/sys/dev/ioat/ioat_test.h
==
--- head/sys/dev/ioat/ioat_test.h   Tue Apr  2 18:50:49 2019
(r345811)
+++ head/sys/dev/ioat/ioat_test.h   Tue Apr  2 19:06:25 2019
(r345812)
@@ -44,6 +44,9 @@ enum ioat_test_kind {
IOAT_TEST_RAW_DMA,
IOAT_TEST_DMA_8K,
IOAT_TEST_MEMCPY,
+   IOAT_TEST_DMA_8K_PB,
+   IOAT_TEST_DMA_CRC,
+   IOAT_TEST_DMA_CRC_COPY,
IOAT_NUM_TESTKINDS
 };
 

Modified: head/tools/tools/ioat/ioatcontrol.8
==
--- head/tools/tools/ioat/ioatcontrol.8 Tue Apr  2 18:50:49 2019
(r345811)
+++ head/tools/tools/ioat/ioatcontrol.8 Tue Apr  2 19:06:25 2019
(r345812)
@@ -35,9 +35,12 @@
 .Nm
 .Op Fl c Ar period
 .Op Fl E
+.Op Fl e
 .Op Fl f
 .Op Fl m
 .Op Fl V
+.Op Fl x
+.Op Fl X
 .Op Fl z
 .Ar channel_number
 .Ar num_txns
@@ -65,6 +68,8 @@ The arguments are as follows:
 Configure the channel's interrupt coalescing period, in microseconds
 (defaults to 0).
 .It Fl E
+Test contiguous 8k copy.
+.It Fl e
 Test non-contiguous 8k copy.
 .It Fl f
 Test block fill (by default,
@@ -74,6 +79,10 @@ tests copy)
 Test memcpy instead of DMA.
 .It Fl V
 Verify copies/fills for accuracy
+.It Fl x
+Test DMA CRC.
+.It Fl X
+Test DMA copy with CRC.
 .It Fl z
 Zero device statistics before running test.
 .El

Modified: head/tools/tools/ioat/ioatcontrol.c
==
--- head/tools/tools/ioat/ioatcontrol.c Tue Apr  2 18:50:49 2019
(r345811)
+++ head/tools/tools/ioat/ioatcontrol.c Tue Apr  2 19:06:25 2019
(r345812)
@@ -54,13 +54,16 @@ usage(void)
printf("   %s -r [-c period] [-vVwz] channel-number address 
[]\n\n",
getprogname());
printf("   -c period - Enable interrupt coalescing (us) 
(default: 0)\n");
-   printf("   -E- Test 

svn commit: r345811 - head/sys/x86/iommu

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  2 18:50:49 2019
New Revision: 345811
URL: https://svnweb.freebsd.org/changeset/base/345811

Log:
  DMAR driver assumes all physical addresses are backed by a fully
  initialized struct vm_page.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19753

Modified:
  head/sys/x86/iommu/busdma_dmar.c

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cTue Apr  2 18:50:33 2019
(r345810)
+++ head/sys/x86/iommu/busdma_dmar.cTue Apr  2 18:50:49 2019
(r345811)
@@ -665,9 +665,9 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
 {
struct bus_dma_tag_dmar *tag;
struct bus_dmamap_dmar *map;
-   vm_page_t *ma;
-   vm_paddr_t pstart, pend;
-   int error, i, ma_cnt, offset;
+   vm_page_t *ma, fma;
+   vm_paddr_t pstart, pend, paddr;
+   int error, i, ma_cnt, mflags, offset;
 
tag = (struct bus_dma_tag_dmar *)dmat;
map = (struct bus_dmamap_dmar *)map1;
@@ -675,14 +675,36 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
pend = round_page(buf + buflen);
offset = buf & PAGE_MASK;
ma_cnt = OFF_TO_IDX(pend - pstart);
-   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, map->cansleep ?
-   M_WAITOK : M_NOWAIT);
+   mflags = map->cansleep ? M_WAITOK : M_NOWAIT;
+   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, mflags);
if (ma == NULL)
return (ENOMEM);
-   for (i = 0; i < ma_cnt; i++)
-   ma[i] = PHYS_TO_VM_PAGE(pstart + i * PAGE_SIZE);
+   fma = NULL;
+   for (i = 0; i < ma_cnt; i++) {
+   paddr = pstart + i * PAGE_SIZE;
+   ma[i] = PHYS_TO_VM_PAGE(paddr);
+   if (ma[i] == NULL || VM_PAGE_TO_PHYS(ma[i]) != paddr) {
+   /*
+* If PHYS_TO_VM_PAGE() returned NULL or the
+* vm_page was not initialized we'll use a
+* fake page.
+*/
+   if (fma == NULL) {
+   fma = malloc(sizeof(struct vm_page) * ma_cnt,
+   M_DEVBUF, mflags);
+   if (fma == NULL) {
+   free(ma, M_DEVBUF);
+   return (ENOMEM);
+   }
+   }
+   vm_page_initfake([i], pstart + i * PAGE_SIZE,
+   VM_MEMATTR_DEFAULT);
+   ma[i] = [i];
+   }
+   }
error = dmar_bus_dmamap_load_something(tag, map, ma, offset, buflen,
flags, segs, segp);
+   free(fma, M_DEVBUF);
free(ma, M_DEVBUF);
return (error);
 }
@@ -696,7 +718,7 @@ dmar_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dm
struct bus_dmamap_dmar *map;
vm_page_t *ma, fma;
vm_paddr_t pstart, pend, paddr;
-   int error, i, ma_cnt, offset;
+   int error, i, ma_cnt, mflags, offset;
 
tag = (struct bus_dma_tag_dmar *)dmat;
map = (struct bus_dmamap_dmar *)map1;
@@ -704,41 +726,33 @@ dmar_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dm
pend = round_page((vm_offset_t)buf + buflen);
offset = (vm_offset_t)buf & PAGE_MASK;
ma_cnt = OFF_TO_IDX(pend - pstart);
-   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, map->cansleep ?
-   M_WAITOK : M_NOWAIT);
+   mflags = map->cansleep ? M_WAITOK : M_NOWAIT;
+   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, mflags);
if (ma == NULL)
return (ENOMEM);
-   if (dumping) {
-   /*
-* If dumping, do not attempt to call
-* PHYS_TO_VM_PAGE() at all.  It may return non-NULL
-* but the vm_page returned might be not initialized,
-* e.g. for the kernel itself.
-*/
-   KASSERT(pmap == kernel_pmap, ("non-kernel address write"));
-   fma = malloc(sizeof(struct vm_page) * ma_cnt, M_DEVBUF,
-   M_ZERO | (map->cansleep ? M_WAITOK : M_NOWAIT));
-   if (fma == NULL) {
-   free(ma, M_DEVBUF);
-   return (ENOMEM);
-   }
-   for (i = 0; i < ma_cnt; i++, pstart += PAGE_SIZE) {
+   fma = NULL;
+   for (i = 0; i < ma_cnt; i++, pstart += PAGE_SIZE) {
+   if (pmap == kernel_pmap)
paddr = pmap_kextract(pstart);
+   else
+   paddr = pmap_extract(pmap, pstart);
+   ma[i] = PHYS_TO_VM_PAGE(paddr);
+   if (ma[i] == NULL || VM_PAGE_TO_PHYS(ma[i]) != paddr) {
+   /*
+* If 

svn commit: r345777 - head/sys/dev/pci

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Mon Apr  1 19:08:05 2019
New Revision: 345777
URL: https://svnweb.freebsd.org/changeset/base/345777

Log:
  Devices behind downstream bridges should still get DMAR protection.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19717

Modified:
  head/sys/dev/pci/pci.c

Modified: head/sys/dev/pci/pci.c
==
--- head/sys/dev/pci/pci.c  Mon Apr  1 18:54:15 2019(r345776)
+++ head/sys/dev/pci/pci.c  Mon Apr  1 19:08:05 2019(r345777)
@@ -31,6 +31,7 @@
 #include 
 __FBSDID("$FreeBSD$");
 
+#include "opt_acpi.h"
 #include "opt_bus.h"
 
 #include 
@@ -5693,13 +5694,34 @@ pci_get_resource_list (device_t dev, device_t child)
return (>resources);
 }
 
+#ifdef ACPI_DMAR
+bus_dma_tag_t dmar_get_dma_tag(device_t dev, device_t child);
 bus_dma_tag_t
 pci_get_dma_tag(device_t bus, device_t dev)
 {
+   bus_dma_tag_t tag;
+   struct pci_softc *sc;
+
+   if (device_get_parent(dev) == bus) {
+   /* try dmar and return if it works */
+   tag = dmar_get_dma_tag(bus, dev);
+   } else
+   tag = NULL;
+   if (tag == NULL) {
+   sc = device_get_softc(bus);
+   tag = sc->sc_dma_tag;
+   }
+   return (tag);
+}
+#else
+bus_dma_tag_t
+pci_get_dma_tag(device_t bus, device_t dev)
+{
struct pci_softc *sc = device_get_softc(bus);
 
return (sc->sc_dma_tag);
 }
+#endif
 
 uint32_t
 pci_read_config_method(device_t dev, device_t child, int reg, int width)


___
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: r345601 - head/sys/x86/iommu

2019-09-03 Thread Tycho Nightingale
Author: tychon
Date: Wed Mar 27 20:15:51 2019
New Revision: 345601
URL: https://svnweb.freebsd.org/changeset/base/345601

Log:
  Use the BUS_DMA_NOWRITE flag to expose and create the read-only VT-d
  IOMMU mappings.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19729

Modified:
  head/sys/x86/iommu/busdma_dmar.c

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cWed Mar 27 19:59:36 2019
(r345600)
+++ head/sys/x86/iommu/busdma_dmar.cWed Mar 27 20:15:51 2019
(r345601)
@@ -527,7 +527,8 @@ dmar_bus_dmamap_load_something1(struct bus_dma_tag_dma
gas_flags |= DMAR_GM_CANSPLIT;
 
error = dmar_gas_map(domain, >common, size, offset,
-   DMAR_MAP_ENTRY_READ | DMAR_MAP_ENTRY_WRITE,
+   DMAR_MAP_ENTRY_READ |
+   ((flags & BUS_DMA_NOWRITE) == 0 ? DMAR_MAP_ENTRY_WRITE : 0),
gas_flags, ma + idx, );
if (error != 0)
break;


___
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: r348687 - head/sys/x86/iommu

2019-06-05 Thread Tycho Nightingale
Author: tychon
Date: Wed Jun  5 13:08:21 2019
New Revision: 348687
URL: https://svnweb.freebsd.org/changeset/base/348687

Log:
  another occurrence where a very large dma mapping can cause integer overflow
  
  Submitted by: rlibby
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/x86/iommu/busdma_dmar.c

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cWed Jun  5 12:53:36 2019
(r348686)
+++ head/sys/x86/iommu/busdma_dmar.cWed Jun  5 13:08:21 2019
(r348687)
@@ -702,7 +702,7 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
return (ENOMEM);
}
}
-   vm_page_initfake([i], pstart + i * PAGE_SIZE,
+   vm_page_initfake([i], pstart + ptoa(i),
VM_MEMATTR_DEFAULT);
ma[i] = [i];
}
___
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: r348571 - in head/sys: arm64/arm64 x86/iommu x86/x86

2019-06-03 Thread Tycho Nightingale
Author: tychon
Date: Mon Jun  3 19:19:35 2019
New Revision: 348571
URL: https://svnweb.freebsd.org/changeset/base/348571

Log:
  very large dma mappings can cause integer overflow
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D20505

Modified:
  head/sys/arm64/arm64/busdma_bounce.c
  head/sys/x86/iommu/busdma_dmar.c
  head/sys/x86/x86/busdma_bounce.c

Modified: head/sys/arm64/arm64/busdma_bounce.c
==
--- head/sys/arm64/arm64/busdma_bounce.cMon Jun  3 19:15:06 2019
(r348570)
+++ head/sys/arm64/arm64/busdma_bounce.cMon Jun  3 19:19:35 2019
(r348571)
@@ -660,7 +660,7 @@ _bus_dmamap_reserve_pages(bus_dma_tag_t dmat, bus_dmam
 /*
  * Add a single contiguous physical range to the segment list.
  */
-static int
+static bus_size_t
 _bus_dmamap_addseg(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t curaddr,
 bus_size_t sgsize, bus_dma_segment_t *segs, int *segp)
 {

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cMon Jun  3 19:15:06 2019
(r348570)
+++ head/sys/x86/iommu/busdma_dmar.cMon Jun  3 19:19:35 2019
(r348571)
@@ -686,7 +686,7 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
return (ENOMEM);
fma = NULL;
for (i = 0; i < ma_cnt; i++) {
-   paddr = pstart + i * PAGE_SIZE;
+   paddr = pstart + ptoa(i);
ma[i] = PHYS_TO_VM_PAGE(paddr);
if (ma[i] == NULL || VM_PAGE_TO_PHYS(ma[i]) != paddr) {
/*

Modified: head/sys/x86/x86/busdma_bounce.c
==
--- head/sys/x86/x86/busdma_bounce.cMon Jun  3 19:15:06 2019
(r348570)
+++ head/sys/x86/x86/busdma_bounce.cMon Jun  3 19:19:35 2019
(r348571)
@@ -667,7 +667,7 @@ _bus_dmamap_reserve_pages(bus_dma_tag_t dmat, bus_dmam
 /*
  * Add a single contiguous physical range to the segment list.
  */
-static int
+static bus_size_t
 _bus_dmamap_addseg(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t curaddr,
 bus_size_t sgsize, bus_dma_segment_t *segs, int *segp)
 {
___
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: r347903 - head/sys/dev/bge

2019-05-17 Thread Tycho Nightingale
Author: tychon
Date: Fri May 17 13:08:12 2019
New Revision: 347903
URL: https://svnweb.freebsd.org/changeset/base/347903

Log:
  Remove unused define.
  
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/dev/bge/if_bgereg.h

Modified: head/sys/dev/bge/if_bgereg.h
==
--- head/sys/dev/bge/if_bgereg.hFri May 17 08:25:31 2019
(r347902)
+++ head/sys/dev/bge/if_bgereg.hFri May 17 13:08:12 2019
(r347903)
@@ -3073,11 +3073,3 @@ struct bge_softc {
 #defineBGE_LOCK_ASSERT(_sc)mtx_assert(&(_sc)->bge_mtx, MA_OWNED)
 #defineBGE_UNLOCK(_sc) mtx_unlock(&(_sc)->bge_mtx)
 #defineBGE_LOCK_DESTROY(_sc)   mtx_destroy(&(_sc)->bge_mtx)
-
-#ifdef BUS_SPACE_MAXADDR
-#if (BUS_SPACE_MAXADDR > 0x)
-#defineBGE_DMA_BOUNDARY(0x1)
-#else
-#defineBGE_DMA_BOUNDARY0
-#endif
-#endif
___
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: r347890 - in head/sys/dev: aac bge

2019-05-16 Thread Tycho Nightingale


> On May 16, 2019, at 5:23 PM, Hans Petter Selasky  wrote:
> 
> On 2019-05-16 22:41, Tycho Nightingale wrote:
>> Author: tychon
>> Date: Thu May 16 20:41:28 2019
>> New Revision: 347890
>> URL: https://svnweb.freebsd.org/changeset/base/347890
>> Log:
>>   reinstate 4GB DMA boundary workarounds for bge and aac
>>  Reviewed by:kib
>>   Sponsored by:  Dell EMC Isilon
>>   Differential Revision: https://reviews.freebsd.org/D20277
>> Modified:
>>   head/sys/dev/aac/aac_pci.c
>>   head/sys/dev/bge/if_bge.c
>>   head/sys/dev/bge/if_bgereg.h
>> Modified: head/sys/dev/aac/aac_pci.c
>> ==
>> --- head/sys/dev/aac/aac_pci.c   Thu May 16 19:32:11 2019
>> (r347889)
>> +++ head/sys/dev/aac/aac_pci.c   Thu May 16 20:41:28 2019
>> (r347890)
>> @@ -443,7 +443,8 @@ aac_pci_attach(device_t dev)
>>   * Note that some of these controllers are 64-bit capable.
>>   */
>>  if (bus_dma_tag_create(bus_get_dma_tag(dev),/* parent */
>> -   PAGE_SIZE, 0,/* algnmnt, boundary */
>> +   PAGE_SIZE,   /* algnmnt */
>> +   ((bus_size_t)((uint64_t)1 << 32)), /* boundary*/
>> BUS_SPACE_MAXADDR,   /* lowaddr */
>> BUS_SPACE_MAXADDR,   /* highaddr */
>> NULL, NULL,  /* filter, filterarg */
>> Modified: head/sys/dev/bge/if_bge.c
>> ==
>> --- head/sys/dev/bge/if_bge.cThu May 16 19:32:11 2019
>> (r347889)
>> +++ head/sys/dev/bge/if_bge.cThu May 16 20:41:28 2019
>> (r347890)
>> @@ -2927,10 +2927,14 @@ bge_dma_ring_alloc(struct bge_softc *sc, bus_size_t 
>> al
>>  bus_addr_t *paddr, const char *msg)
>>  {
>>  struct bge_dmamap_arg ctx;
>> +bus_addr_t lowaddr;
>> +bus_size_t ring_end;
>>  int error;
>>  +   lowaddr = BUS_SPACE_MAXADDR;
>> +again:
>>  error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
>> -alignment, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
>> +alignment, 0, lowaddr, BUS_SPACE_MAXADDR, NULL,
>>  NULL, maxsize, 1, maxsize, 0, NULL, NULL, tag);
>>  if (error != 0) {
>>  device_printf(sc->bge_dev,
>> @@ -2955,6 +2959,25 @@ bge_dma_ring_alloc(struct bge_softc *sc, bus_size_t al
>>  return (ENOMEM);
>>  }
>>  *paddr = ctx.bge_busaddr;
>> +ring_end = *paddr + maxsize;
>> +if ((sc->bge_flags & BGE_FLAG_4G_BNDRY_BUG) != 0 &&
>> +BGE_ADDR_HI(*paddr) != BGE_ADDR_HI(ring_end)) {
>> +/*
>> + * 4GB boundary crossed.  Limit maximum allowable DMA
>> + * address space to 32bit and try again.
>> + */
>> +bus_dmamap_unload(*tag, *map);
>> +bus_dmamem_free(*tag, *ring, *map);
>> +bus_dma_tag_destroy(*tag);
>> +if (bootverbose)
>> +device_printf(sc->bge_dev, "4GB boundary crossed, "
>> +"limit DMA address space to 32bit for %s\n", msg);
>> +*ring = NULL;
>> +*tag = NULL;
>> +*map = NULL;
>> +lowaddr = BUS_SPACE_MAXADDR_32BIT;
>> +goto again;
>> +}
>>  return (0);
>>  }
>>  @@ -2962,7 +2985,7 @@ static int
>>  bge_dma_alloc(struct bge_softc *sc)
>>  {
>>  bus_addr_t lowaddr;
>> -bus_size_t rxmaxsegsz, sbsz, txsegsz, txmaxsegsz;
>> +bus_size_t boundary, sbsz, rxmaxsegsz, txsegsz, txmaxsegsz;
>>  int i, error;
>>  lowaddr = BUS_SPACE_MAXADDR;
>> @@ -3049,7 +3072,9 @@ bge_dma_alloc(struct bge_softc *sc)
>>  }
>>  /* Create parent tag for buffers. */
>> +boundary = 0;
>>  if ((sc->bge_flags & BGE_FLAG_4G_BNDRY_BUG) != 0) {
>> +boundary = BGE_DMA_BNDRY;
>>  /*
>>   * XXX
>>   * watchdog timeout issue was observed on BCM5704 which
>> @@ -3060,10 +3085,10 @@ bge_dma_alloc(struct bge_softc *sc)
>>  if (sc->bge_pcixcap != 0)
>>  lowaddr = BUS_SPACE_MAXADDR_32BIT;
>>  }
>> -  

svn commit: r347896 - head/sys/dev/bge

2019-05-16 Thread Tycho Nightingale
Author: tychon
Date: Thu May 16 22:27:38 2019
New Revision: 347896
URL: https://svnweb.freebsd.org/changeset/base/347896

Log:
  Fix integer overflow in r346386.
  
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/dev/bge/if_bgereg.h

Modified: head/sys/dev/bge/if_bgereg.h
==
--- head/sys/dev/bge/if_bgereg.hThu May 16 22:20:54 2019
(r347895)
+++ head/sys/dev/bge/if_bgereg.hThu May 16 22:27:38 2019
(r347896)
@@ -2866,7 +2866,7 @@ struct bge_gib {
 #defineBGE_DMA_MAXADDR 0xFF
 #endif
 
-#if (BUS_SPACE_MAXADDR > 0x)
+#if (BUS_SPACE_MAXSIZE > 0x)
 #defineBGE_DMA_BNDRY   0x1
 #else
 #defineBGE_DMA_BNDRY   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: r347890 - in head/sys/dev: aac bge

2019-05-16 Thread Tycho Nightingale
Author: tychon
Date: Thu May 16 20:41:28 2019
New Revision: 347890
URL: https://svnweb.freebsd.org/changeset/base/347890

Log:
  reinstate 4GB DMA boundary workarounds for bge and aac
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D20277

Modified:
  head/sys/dev/aac/aac_pci.c
  head/sys/dev/bge/if_bge.c
  head/sys/dev/bge/if_bgereg.h

Modified: head/sys/dev/aac/aac_pci.c
==
--- head/sys/dev/aac/aac_pci.c  Thu May 16 19:32:11 2019(r347889)
+++ head/sys/dev/aac/aac_pci.c  Thu May 16 20:41:28 2019(r347890)
@@ -443,7 +443,8 @@ aac_pci_attach(device_t dev)
 * Note that some of these controllers are 64-bit capable.
 */
if (bus_dma_tag_create(bus_get_dma_tag(dev),/* parent */
-  PAGE_SIZE, 0,/* algnmnt, boundary */
+  PAGE_SIZE,   /* algnmnt */
+  ((bus_size_t)((uint64_t)1 << 32)), /* boundary*/
   BUS_SPACE_MAXADDR,   /* lowaddr */
   BUS_SPACE_MAXADDR,   /* highaddr */
   NULL, NULL,  /* filter, filterarg */

Modified: head/sys/dev/bge/if_bge.c
==
--- head/sys/dev/bge/if_bge.c   Thu May 16 19:32:11 2019(r347889)
+++ head/sys/dev/bge/if_bge.c   Thu May 16 20:41:28 2019(r347890)
@@ -2927,10 +2927,14 @@ bge_dma_ring_alloc(struct bge_softc *sc, bus_size_t al
 bus_addr_t *paddr, const char *msg)
 {
struct bge_dmamap_arg ctx;
+   bus_addr_t lowaddr;
+   bus_size_t ring_end;
int error;
 
+   lowaddr = BUS_SPACE_MAXADDR;
+again:
error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
-   alignment, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
+   alignment, 0, lowaddr, BUS_SPACE_MAXADDR, NULL,
NULL, maxsize, 1, maxsize, 0, NULL, NULL, tag);
if (error != 0) {
device_printf(sc->bge_dev,
@@ -2955,6 +2959,25 @@ bge_dma_ring_alloc(struct bge_softc *sc, bus_size_t al
return (ENOMEM);
}
*paddr = ctx.bge_busaddr;
+   ring_end = *paddr + maxsize;
+   if ((sc->bge_flags & BGE_FLAG_4G_BNDRY_BUG) != 0 &&
+   BGE_ADDR_HI(*paddr) != BGE_ADDR_HI(ring_end)) {
+   /*
+* 4GB boundary crossed.  Limit maximum allowable DMA
+* address space to 32bit and try again.
+*/
+   bus_dmamap_unload(*tag, *map);
+   bus_dmamem_free(*tag, *ring, *map);
+   bus_dma_tag_destroy(*tag);
+   if (bootverbose)
+   device_printf(sc->bge_dev, "4GB boundary crossed, "
+   "limit DMA address space to 32bit for %s\n", msg);
+   *ring = NULL;
+   *tag = NULL;
+   *map = NULL;
+   lowaddr = BUS_SPACE_MAXADDR_32BIT;
+   goto again;
+   }
return (0);
 }
 
@@ -2962,7 +2985,7 @@ static int
 bge_dma_alloc(struct bge_softc *sc)
 {
bus_addr_t lowaddr;
-   bus_size_t rxmaxsegsz, sbsz, txsegsz, txmaxsegsz;
+   bus_size_t boundary, sbsz, rxmaxsegsz, txsegsz, txmaxsegsz;
int i, error;
 
lowaddr = BUS_SPACE_MAXADDR;
@@ -3049,7 +3072,9 @@ bge_dma_alloc(struct bge_softc *sc)
}
 
/* Create parent tag for buffers. */
+   boundary = 0;
if ((sc->bge_flags & BGE_FLAG_4G_BNDRY_BUG) != 0) {
+   boundary = BGE_DMA_BNDRY;
/*
 * XXX
 * watchdog timeout issue was observed on BCM5704 which
@@ -3060,10 +3085,10 @@ bge_dma_alloc(struct bge_softc *sc)
if (sc->bge_pcixcap != 0)
lowaddr = BUS_SPACE_MAXADDR_32BIT;
}
-   error = bus_dma_tag_create(bus_get_dma_tag(sc->bge_dev), 1, 0, lowaddr,
-   BUS_SPACE_MAXADDR, NULL, NULL, BUS_SPACE_MAXSIZE_32BIT, 0,
-   BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL,
-   >bge_cdata.bge_buffer_tag);
+   error = bus_dma_tag_create(bus_get_dma_tag(sc->bge_dev),
+   1, boundary, lowaddr, BUS_SPACE_MAXADDR, NULL,
+   NULL, BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT,
+   0, NULL, NULL, >bge_cdata.bge_buffer_tag);
if (error != 0) {
device_printf(sc->bge_dev,
"could not allocate buffer dma tag\n");

Modified: head/sys/dev/bge/if_bgereg.h
==
--- head/sys/dev/bge/if_bgereg.hThu May 16 19:32:11 2019
(r347889)
+++ head/sys/dev/bge/if_bgereg.hThu May 16 20:41:28 2019
(r347890)
@@ -2866,6 +2866,12 @@ struct bge_gib {
 #defineBGE_DMA_MAXADDR 

svn commit: r347836 - in head: sys/arm64/arm64 sys/arm64/include sys/compat/linuxkpi/common/src sys/sys sys/x86/include sys/x86/iommu sys/x86/x86 usr.sbin/camdd

2019-05-16 Thread Tycho Nightingale
Author: tychon
Date: Thu May 16 17:41:16 2019
New Revision: 347836
URL: https://svnweb.freebsd.org/changeset/base/347836

Log:
  Allow loading the same DMA address multiple times without any prior
  unload for the LinuxKPI.
  
  Reviewed by:  kib, zeising
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D20181

Modified:
  head/sys/arm64/arm64/busdma_bounce.c
  head/sys/arm64/include/bus_dma.h
  head/sys/arm64/include/bus_dma_impl.h
  head/sys/compat/linuxkpi/common/src/linux_pci.c
  head/sys/sys/bus_dma.h
  head/sys/x86/include/bus_dma.h
  head/sys/x86/include/busdma_impl.h
  head/sys/x86/iommu/busdma_dmar.c
  head/sys/x86/x86/busdma_bounce.c
  head/usr.sbin/camdd/camdd.c

Modified: head/sys/arm64/arm64/busdma_bounce.c
==
--- head/sys/arm64/arm64/busdma_bounce.cThu May 16 17:38:59 2019
(r347835)
+++ head/sys/arm64/arm64/busdma_bounce.cThu May 16 17:41:16 2019
(r347836)
@@ -152,6 +152,8 @@ static bus_addr_t add_bounce_page(bus_dma_tag_t dmat, 
 vm_offset_t vaddr, bus_addr_t addr, bus_size_t size);
 static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage);
 int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr);
+static bool _bus_dmamap_pagesneeded(bus_dma_tag_t dmat, vm_paddr_t buf,
+bus_size_t buflen, int *pagesneeded);
 static void _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map,
 pmap_t pmap, void *buf, bus_size_t buflen, int flags);
 static void _bus_dmamap_count_phys(bus_dma_tag_t dmat, bus_dmamap_t map,
@@ -271,6 +273,15 @@ out:
return (error);
 }
 
+static bool
+bounce_bus_dma_id_mapped(bus_dma_tag_t dmat, vm_paddr_t buf, bus_size_t buflen)
+{
+
+   if ((dmat->bounce_flags & BF_COULD_BOUNCE) == 0)
+   return (true);
+   return (!_bus_dmamap_pagesneeded(dmat, buf, buflen, NULL));
+}
+
 static bus_dmamap_t
 alloc_dmamap(bus_dma_tag_t dmat, int flags)
 {
@@ -539,29 +550,45 @@ bounce_bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr
dmat->bounce_flags);
 }
 
+static bool
+_bus_dmamap_pagesneeded(bus_dma_tag_t dmat, vm_paddr_t buf, bus_size_t buflen,
+int *pagesneeded)
+{
+   bus_addr_t curaddr;
+   bus_size_t sgsize;
+   int count;
+
+   /*
+* Count the number of bounce pages needed in order to
+* complete this transfer
+*/
+   count = 0;
+   curaddr = buf;
+   while (buflen != 0) {
+   sgsize = MIN(buflen, dmat->common.maxsegsz);
+   if (bus_dma_run_filter(>common, curaddr)) {
+   sgsize = MIN(sgsize,
+   PAGE_SIZE - (curaddr & PAGE_MASK));
+   if (pagesneeded == NULL)
+   return (true);
+   count++;
+   }
+   curaddr += sgsize;
+   buflen -= sgsize;
+   }
+
+   if (pagesneeded != NULL)
+   *pagesneeded = count;
+   return (count != 0);
+}
+
 static void
 _bus_dmamap_count_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
 bus_size_t buflen, int flags)
 {
-   bus_addr_t curaddr;
-   bus_size_t sgsize;
 
if ((map->flags & DMAMAP_COULD_BOUNCE) != 0 && map->pagesneeded == 0) {
-   /*
-* Count the number of bounce pages
-* needed in order to complete this transfer
-*/
-   curaddr = buf;
-   while (buflen != 0) {
-   sgsize = MIN(buflen, dmat->common.maxsegsz);
-   if (bus_dma_run_filter(>common, curaddr)) {
-   sgsize = MIN(sgsize,
-   PAGE_SIZE - (curaddr & PAGE_MASK));
-   map->pagesneeded++;
-   }
-   curaddr += sgsize;
-   buflen -= sgsize;
-   }
+   _bus_dmamap_pagesneeded(dmat, buf, buflen, >pagesneeded);
CTR1(KTR_BUSDMA, "pagesneeded= %d\n", map->pagesneeded);
}
 }
@@ -1316,6 +1343,7 @@ busdma_swi(void)
 struct bus_dma_impl bus_dma_bounce_impl = {
.tag_create = bounce_bus_dma_tag_create,
.tag_destroy = bounce_bus_dma_tag_destroy,
+   .id_mapped = bounce_bus_dma_id_mapped,
.map_create = bounce_bus_dmamap_create,
.map_destroy = bounce_bus_dmamap_destroy,
.mem_alloc = bounce_bus_dmamem_alloc,

Modified: head/sys/arm64/include/bus_dma.h
==
--- head/sys/arm64/include/bus_dma.hThu May 16 17:38:59 2019
(r347835)
+++ head/sys/arm64/include/bus_dma.hThu May 16 17:41:16 2019
(r347836)
@@ -9,6 +9,18 @@
 #include 
 
 /*
+ * Is DMA address 1:1 mapping of physical address
+ */
+static inline bool
+bus_dma_id_mapped(bus_dma_tag_t dmat, vm_paddr_t buf, 

Re: svn commit: r346645 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src sys

2019-05-07 Thread Tycho Nightingale

Hi,

> On May 7, 2019, at 9:13 PM, Conrad Meyer  wrote:
> 
> Hi Tycho,
> 
> On Wed, Apr 24, 2019 at 1:31 PM Tycho Nightingale  wrote:
>> 
>> Author: tychon
>> Date: Wed Apr 24 20:30:45 2019
>> New Revision: 346645
>> URL: https://svnweb.freebsd.org/changeset/base/346645
>> 
>> Log:
>>  LinuxKPI should use bus_dma(9) to be compatible with an IOMMU
>> 
>>  Reviewed by:  hselasky, kib
>>  Tested by:greg@unrelenting.technology
>>  Sponsored by: Dell EMC Isilon
>>  Differential Revision:https://reviews.freebsd.org/D19845
>> ...
>> Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
>> ==
>> --- head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 24 19:56:02 
>> 2019(r346644)
>> +++ head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 24 20:30:45 
>> 2019(r346645)
>> ...
>> +linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len)
>> +{
>> ...
>> +   nseg = -1;
>> +   mtx_lock(>dma_lock);
>> +   if (_bus_dmamap_load_phys(priv->dmat, obj->dmamap, phys, len,
>> +   BUS_DMA_NOWAIT, , ) != 0) {
>> +   bus_dmamap_destroy(priv->dmat, obj->dmamap);
>> +   mtx_unlock(>dma_lock);
>> +   uma_zfree(linux_dma_obj_zone, obj);
>> +   return (0);
>> +   }
>> +   mtx_unlock(>dma_lock);
>> +
>> +   KASSERT(++nseg == 1, ("More than one segment (nseg=%d)", nseg));
> 
> This construct is a bit odd.  Coverity produces the (perhaps spurious)
> warning (CID 1401319) that the KASSERT (which can be compiled out in
> !INVARIANTS builds) has a side effect (++nseg).  While true, nseg is
> never used afterwards, so perhaps we can use the equivalent expression
> with no side effect instead?  I.e., something like:
> 
> KASSERT(nseg == 0, ("More than one segment (nseg=%d)", nseg + 1));
> 
> Does that make sense?  It is a false positive of sorts, but performing
> side effects in compiled-out assert is a pretty strong antipattern so
> I'd just as soon "fix" the warning.

The construct is indeed a little odd and mimics how other callers of 
_bus_dmamap_load_phys() handle the bizarre way nseg is treated.  There isn’t 
any reason for it and in hindsight I prefer your version — especially if it 
eliminates this Coverity issue.

Tycho
___
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: r347168 - in head/sys: dev/nvdimm x86/iommu

2019-05-05 Thread Tycho Nightingale
Author: tychon
Date: Mon May  6 00:57:05 2019
New Revision: 347168
URL: https://svnweb.freebsd.org/changeset/base/347168

Log:
  zero inputs to vm_page_initfake() for predictable results
  
  Reviewed by:  kib
  Submitted by: Anton Rang 
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D20162

Modified:
  head/sys/dev/nvdimm/nvdimm_spa.c
  head/sys/x86/iommu/busdma_dmar.c

Modified: head/sys/dev/nvdimm/nvdimm_spa.c
==
--- head/sys/dev/nvdimm/nvdimm_spa.cSun May  5 20:23:43 2019
(r347167)
+++ head/sys/dev/nvdimm/nvdimm_spa.cMon May  6 00:57:05 2019
(r347168)
@@ -177,6 +177,7 @@ nvdimm_spa_uio(struct nvdimm_spa_dev *dev, struct uio 
error = 0;
if (dev->spa_kva == NULL) {
mattr = nvdimm_spa_memattr(dev);
+   bzero(, sizeof(m));
vm_page_initfake(, 0, mattr);
ma = 
while (uio->uio_resid > 0) {
@@ -276,7 +277,7 @@ nvdimm_spa_g_all_unmapped(struct nvdimm_spa_dev *dev, 
 
mattr = nvdimm_spa_memattr(dev);
for (i = 0; i < nitems(ma); i++) {
-   maa[i].flags = 0;
+   bzero([i], sizeof(maa[i]));
vm_page_initfake([i], dev->spa_phys_base +
trunc_page(bp->bio_offset) + PAGE_SIZE * i, mattr);
ma[i] = [i];

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cSun May  5 20:23:43 2019
(r347167)
+++ head/sys/x86/iommu/busdma_dmar.cMon May  6 00:57:05 2019
(r347168)
@@ -689,7 +689,7 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
 */
if (fma == NULL) {
fma = malloc(sizeof(struct vm_page) * ma_cnt,
-   M_DEVBUF, mflags);
+   M_DEVBUF, M_ZERO | mflags);
if (fma == NULL) {
free(ma, M_DEVBUF);
return (ENOMEM);
@@ -743,7 +743,7 @@ dmar_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dm
 */
if (fma == NULL) {
fma = malloc(sizeof(struct vm_page) * ma_cnt,
-   M_DEVBUF, mflags);
+   M_DEVBUF, M_ZERO | mflags);
if (fma == NULL) {
free(ma, M_DEVBUF);
return (ENOMEM);
___
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: r346958 - head/sys/compat/linuxkpi/common/src

2019-04-30 Thread Tycho Nightingale

> On Apr 30, 2019, at 11:24 AM, Warner Losh  wrote:
> 
> 
> On Tue, Apr 30, 2019 at 9:17 AM Hans Petter Selasky  > wrote:
> On 4/30/19 3:10 PM, Niclas Zeising wrote:
> > On 2019-04-30 12:41, Hans Petter Selasky wrote:
> >> Author: hselasky
> >> Date: Tue Apr 30 10:41:20 2019
> >> New Revision: 346958
> >> URL: https://svnweb.freebsd.org/changeset/base/346958 
> >> 
> >>
> >> Log:
> >>Reduce the number of mutexes after r346645 in the LinuxKPI.
> >>Make function macro wrappers for locking and unlocking to ease 
> >> readability.
> >>No functional change.
> >>Discussed with:kib@, tychon@ and zeising@
> > 
> > I was not part of any discussion regarding this.  If this is related to 
> > https://reviews.freebsd.org/D20097  I 
> > explicitly asked you on gitter to 
> > hold of for a bit, while we try to figure out why we are seeing 
> > regressions in graphics with the latest dmar changes.
> > 
> > Can you please revert this since it colludes the dmar graphics issue, 
> > and it makes the suggested patch not apply cleanly, which makes it 
> > harder to get people to help test.
> > Thank you!
> > Regards
> 
> In response to your request I've collected fixes for all the known 
> LinuxKPI+DMA issues at:
> https://reviews.freebsd.org/D20097 
> 
> It is based on top of the latest -current.
> 
> Hopefully this will solve the problem. Do you have any idea of when we might 
> see resolution of this issue? I'd like to see it fixed by Friday either with 
> fixes or a revert. Do you think that's a reasonable time frame? If not, what 
> do you think a reasonable time frame will be? I know we have a number of 
> unknowns to factor in, so my queries are  based on our best guesses.

Friday seems reasonable.

The issues that have been exposed are that several callers of the Linux API are 
not compliant with the documented API.  For example according to the 
documentation, dma_map_sg() may coalesce entries and our current implementation 
does that.  This broke some graphics drivers. To support these drivers, going 
back to the non-coalesced version is the only path forward as the callee bugs 
redefine this API de facto; this is included in D20097.

Also included in D20097 is a fix to ensure sg_dma_len() is equal to sg->length 
— again to address assumptions in drivers.

Finally, apparently some drivers load the same DMA address multiple times 
without any prior unload.  Those drivers need to work too; D20097 contains a 
fix.

Thanks hps@ for helping out!

Tycho
___
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: r346386 - in head/sys: dev/bge dev/pci dev/twa x86/iommu

2019-04-25 Thread Tycho Nightingale

As Ryan suggests r232260 should be recommitted to get acc(4) fixed.

However, given the age of the devices involved and the lack of support by the 
standard, I’d say the threshold isn’t met to reinstate the boundary globally 
preemptively.

To get the insurance, which may not even be necessary, you start to contort 
working drivers.  For example the insurance can cause legitimate mappings to 
fail to load.  Since bus_dma(9) has no interface to return the “active” 
boundary and only returns the EFBIG when boundary constraint causes a mapping 
to fail to load this causes a rather cryptic failure when a driver.  E.g. with 
the insurance a a tiny 8 byte region will fail to load into a single segment on 
ioat(4) if it happens to cross an invisible 4GB boundary instituted by the 
parent.  You need create a tag which allows multiple segments.  How many 
segments?  Well it depends on how many artificial boundaries; it starts to get 
ugly.  Seems better to support the handful of those devices which need 
hand-holding at the tag level for those devices.

Tycho

> On Apr 25, 2019, at 7:31 PM, Scott Long  wrote:
> 
> Yeah, it might be turning into an old wives tale at this point.  I clearly 
> remember
> it being discussed at the PCI-SIG in late 2003 when PCIe 1.0 was in its final
> draft stages.  However, that was a long time ago, and it’s possible that even
> if it’s a limitation in some version or another of the spec, that most 
> hardware
> and firmware just silently account for it.  At the time (and even now) it 
> didn’t
> seem like an onerous limitation to place on drivers, especially with it being
> quite easy to implement in FreeBSD.  So I’m on the fence; it might be a bit of
> trivia that’s not relevant, and maybe wasn’t ever relevant, but it’s also 
> cheap
> insurance.
> 
> Scott
> 
> 
>> On Apr 25, 2019, at 4:24 PM, Ryan Stone  wrote:
>> 
>> +scottl@, who I believe explained this to us in the first place.
>> 
>> As I recall, it had something to do with 64-bit DMA being expressed as
>> segment base + 32-bit offset.  DMA engines that blindly try to cross a
>> 32-bit boundary end up back at the start of the segment and read/write
>> the wrong memory location.
>> 
>> On Thu, Apr 25, 2019 at 4:37 PM John Baldwin  wrote:
>>> 
>>> I had looked for the aac change, but wasn't able to find it, perhaps 
>>> because I
>>> looked at tags created in aac.c rather than aac_pci.c.  I agree aac will 
>>> need to
>>> be re-patched.  I'm not really certain how many other devices are actually 
>>> broken.
>>> They would all be due to a firmware bug, nothing inherent in PCI.
>>> 
>>> I believe twa(4) and bge(4) issues predated aac(4) FWIW.
>>> 
>>> Unfortunately, the main bit of discussion about moving the limit into the 
>>> PCI bus
>>> itself seems to be an IRC discussion on 2/28/12 that resulted in revision 
>>> r232267
>>> as a quick MFC'able fix, but I don't have a log of that conversation. :(  I
>>> couldn't find anything in e-mail either that was definitive for why this 
>>> might have
>>> been inherent in PCI-e vs a few firmware writers having similar bugs.
>>> 
>>> On 4/25/19 12:20 PM, Ryan Stone wrote:
>>>> Following up, this is what will have to be re-instated in the aac driver:
>>>> 
>>>> http://svn.freebsd.org/changeset/base/232260
>>>> 
>>>> However, my biggest concern is that we have no idea how many new
>>>> devices with the broken behaviour might have been introduced since we
>>>> fixed the problem in general.  How does Linux handle the issue?
>>>> 
>>>> On Thu, Apr 25, 2019 at 3:17 PM Ryan Stone  wrote:
>>>>> 
>>>>> This change makes me *very* uncomfortable.  It was originally brought
>>>>> in due to issues with Adaptec RAID cards using the aac(9) driver.  The
>>>>> symptoms of the bug included silent corruption of data as it was
>>>>> written to disk.  Are we sure that this change is a good idea, given
>>>>> how catastrophic it is when a device gets this wrong?
>>>>> 
>>>>> On Fri, Apr 19, 2019 at 9:43 AM Tycho Nightingale  
>>>>> wrote:
>>>>>> 
>>>>>> Author: tychon
>>>>>> Date: Fri Apr 19 13:43:33 2019
>>>>>> New Revision: 346386
>>>>>> URL: https://svnweb.freebsd.org/changeset/base/346386
>>>>>> 
>>>>>> Log:
>>>>>> remove the 4GB boundary requirement on PCI DMA segments
>>>>>> 
>>>>>>

Re: svn commit: r346687 - head/sys/compat/linuxkpi/common/src

2019-04-25 Thread Tycho Nightingale



> On Apr 25, 2019, at 2:50 PM, John Baldwin  wrote:
> 
> On 4/25/19 11:43 AM, Konstantin Belousov wrote:
>> On Thu, Apr 25, 2019 at 06:13:56PM +, Tycho Nightingale wrote:
>>> Author: tychon
>>> Date: Thu Apr 25 18:13:55 2019
>>> New Revision: 346687
>>> URL: https://svnweb.freebsd.org/changeset/base/346687
>>> 
>>> Log:
>>>  LinuxKPI buildfix for ppc64 after r346645.
>>> 
>>>  Proposed by:   hselasky
>>>  Sponsored by:  Dell EMC Isilon
>>> 
>>> Modified:
>>>  head/sys/compat/linuxkpi/common/src/linux_pci.c
>>> 
>>> Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
>>> ==
>>> --- head/sys/compat/linuxkpi/common/src/linux_pci.c Thu Apr 25 17:28:36 
>>> 2019(r346686)
>>> +++ head/sys/compat/linuxkpi/common/src/linux_pci.c Thu Apr 25 18:13:55 
>>> 2019(r346687)
>>> @@ -137,9 +137,9 @@ linux_dma_tag_init(struct device *dev, u64 dma_mask)
>>> dma_mask,   /* lowaddr */
>>> BUS_SPACE_MAXADDR,  /* highaddr */
>>> NULL, NULL, /* filtfunc, filtfuncarg */
>>> -   BUS_SPACE_MAXADDR,  /* maxsize */
>>> +   BUS_SPACE_MAXSIZE,  /* maxsize */
>>> 1,  /* nsegments */
>>> -   BUS_SPACE_MAXADDR,  /* maxsegsz */
>>> +   BUS_SPACE_MAXSIZE,  /* maxsegsz */
>>> 0,  /* flags */
>>> NULL, NULL, /* lockfunc, lockfuncarg */
>>> >dmat);
>> 
>> It seems that amd64 BUS_SPACE_MAXSIZE is 4G, I do not know why.
>> Either we should fix that, or the following fix is more appropriate.
>> i386 and ppc both have PAE-like configs where maxaddr is 64bit but
>> maxsize is 32bit.
> 
> I think we should fix amd64's maxsize.

That sounds reasonable.  Perhaps this was a conservative choice along with the 
4GB DMA boundary which I removed recently.

After some testing I can make this change.

Tycho
___
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: r346687 - head/sys/compat/linuxkpi/common/src

2019-04-25 Thread Tycho Nightingale
Author: tychon
Date: Thu Apr 25 18:13:55 2019
New Revision: 346687
URL: https://svnweb.freebsd.org/changeset/base/346687

Log:
  LinuxKPI buildfix for ppc64 after r346645.
  
  Proposed by:  hselasky
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/compat/linuxkpi/common/src/linux_pci.c

Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
==
--- head/sys/compat/linuxkpi/common/src/linux_pci.c Thu Apr 25 17:28:36 
2019(r346686)
+++ head/sys/compat/linuxkpi/common/src/linux_pci.c Thu Apr 25 18:13:55 
2019(r346687)
@@ -137,9 +137,9 @@ linux_dma_tag_init(struct device *dev, u64 dma_mask)
dma_mask,   /* lowaddr */
BUS_SPACE_MAXADDR,  /* highaddr */
NULL, NULL, /* filtfunc, filtfuncarg */
-   BUS_SPACE_MAXADDR,  /* maxsize */
+   BUS_SPACE_MAXSIZE,  /* maxsize */
1,  /* nsegments */
-   BUS_SPACE_MAXADDR,  /* maxsegsz */
+   BUS_SPACE_MAXSIZE,  /* maxsegsz */
0,  /* flags */
NULL, NULL, /* lockfunc, lockfuncarg */
>dmat);
___
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: r346645 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src sys

2019-04-25 Thread Tycho Nightingale


> On Apr 25, 2019, at 5:13 AM, Hans Petter Selasky  wrote:
> 
> On 4/25/19 8:09 AM, Li-Wen Hsu wrote:
>> On Thu, Apr 25, 2019 at 5:31 AM Tycho Nightingale  wrote:
>>> 
>>> Author: tychon
>>> Date: Wed Apr 24 20:30:45 2019
>>> New Revision: 346645
>>> URL: https://svnweb.freebsd.org/changeset/base/346645
>> ...
>>> Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
>>> ==
>>> --- head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 24 19:56:02 
>>> 2019(r346644)
>>> +++ head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 24 20:30:45 
>>> 2019(r346645)
>> ...
>>> +PCTRIE_DEFINE(LINUX_DMA, linux_dma_obj, dma_addr, linux_dma_trie_alloc,
>>> +linux_dma_trie_free);
>> Here we got errors in build on 32-bit platforms use gcc:
> 
> Should be fixed by r346664.

Sorry about that.  Thanks for fixing it!

Tycho
___
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: r346645 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src sys

2019-04-24 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr 24 20:30:45 2019
New Revision: 346645
URL: https://svnweb.freebsd.org/changeset/base/346645

Log:
  LinuxKPI should use bus_dma(9) to be compatible with an IOMMU
  
  Reviewed by:  hselasky, kib
  Tested by:greg@unrelenting.technology
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19845

Modified:
  head/sys/compat/linuxkpi/common/include/linux/device.h
  head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
  head/sys/compat/linuxkpi/common/include/linux/dmapool.h
  head/sys/compat/linuxkpi/common/include/linux/pci.h
  head/sys/compat/linuxkpi/common/include/linux/scatterlist.h
  head/sys/compat/linuxkpi/common/src/linux_pci.c
  head/sys/sys/param.h

Modified: head/sys/compat/linuxkpi/common/include/linux/device.h
==
--- head/sys/compat/linuxkpi/common/include/linux/device.h  Wed Apr 24 
19:56:02 2019(r346644)
+++ head/sys/compat/linuxkpi/common/include/linux/device.h  Wed Apr 24 
20:30:45 2019(r346645)
@@ -105,7 +105,7 @@ struct device {
struct class*class;
void(*release)(struct device *dev);
struct kobject  kobj;
-   uint64_t*dma_mask;
+   void*dma_priv;
void*driver_data;
unsigned intirq;
 #defineLINUX_IRQ_INVALID   65535

Modified: head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
==
--- head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h Wed Apr 24 
19:56:02 2019(r346644)
+++ head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h Wed Apr 24 
20:30:45 2019(r346645)
@@ -90,6 +90,16 @@ struct dma_map_ops {
 
 #defineDMA_BIT_MASK(n) ((2ULL << ((n) - 1)) - 1ULL)
 
+int linux_dma_tag_init(struct device *dev, u64 mask);
+void *linux_dma_alloc_coherent(struct device *dev, size_t size,
+dma_addr_t *dma_handle, gfp_t flag);
+dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len);
+void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size);
+int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
+int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
+void linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
+int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
+
 static inline int
 dma_supported(struct device *dev, u64 mask)
 {
@@ -102,11 +112,10 @@ static inline int
 dma_set_mask(struct device *dev, u64 dma_mask)
 {
 
-   if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+   if (!dev->dma_priv || !dma_supported(dev, dma_mask))
return -EIO;
 
-   *dev->dma_mask = dma_mask;
-   return (0);
+   return (linux_dma_tag_init(dev, dma_mask));
 }
 
 static inline int
@@ -134,24 +143,7 @@ static inline void *
 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
 gfp_t flag)
 {
-   vm_paddr_t high;
-   size_t align;
-   void *mem;
-
-   if (dev != NULL && dev->dma_mask)
-   high = *dev->dma_mask;
-   else if (flag & GFP_DMA32)
-   high = BUS_SPACE_MAXADDR_32BIT;
-   else
-   high = BUS_SPACE_MAXADDR;
-   align = PAGE_SIZE << get_order(size);
-   mem = (void *)kmem_alloc_contig(size, flag, 0, high, align, 0,
-   VM_MEMATTR_DEFAULT);
-   if (mem)
-   *dma_handle = vtophys(mem);
-   else
-   *dma_handle = 0;
-   return (mem);
+   return (linux_dma_alloc_coherent(dev, size, dma_handle, flag));
 }
 
 static inline void *
@@ -164,25 +156,27 @@ dma_zalloc_coherent(struct device *dev, size_t size, d
 
 static inline void
 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
-dma_addr_t dma_handle)
+dma_addr_t dma_addr)
 {
 
+   linux_dma_unmap(dev, dma_addr, size);
kmem_free((vm_offset_t)cpu_addr, size);
 }
 
-/* XXX This only works with no iommu. */
 static inline dma_addr_t
 dma_map_single_attrs(struct device *dev, void *ptr, size_t size,
 enum dma_data_direction dir, struct dma_attrs *attrs)
 {
 
-   return vtophys(ptr);
+   return (linux_dma_map_phys(dev, vtophys(ptr), size));
 }
 
 static inline void
-dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, size_t size,
+dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, size_t size,
 enum dma_data_direction dir, struct dma_attrs *attrs)
 {
+
+   linux_dma_unmap(dev, dma_addr, size);
 }
 
 static inline dma_addr_t
@@ -190,26 +184,23 @@ dma_map_page_attrs(struct device *dev, struct page *pa
 size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
 
-   return (VM_PAGE_TO_PHYS(page) + offset);
+   return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
 }
 
 static 

svn commit: r346386 - in head/sys: dev/bge dev/pci dev/twa x86/iommu

2019-04-19 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 19 13:43:33 2019
New Revision: 346386
URL: https://svnweb.freebsd.org/changeset/base/346386

Log:
  remove the 4GB boundary requirement on PCI DMA segments
  
  Reviewed by:  kib
  Discussed with:   jhb
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19867

Modified:
  head/sys/dev/bge/if_bgereg.h
  head/sys/dev/pci/pci.c
  head/sys/dev/pci/pcivar.h
  head/sys/dev/twa/tw_osl.h
  head/sys/dev/twa/tw_osl_freebsd.c
  head/sys/x86/iommu/intel_ctx.c

Modified: head/sys/dev/bge/if_bgereg.h
==
--- head/sys/dev/bge/if_bgereg.hFri Apr 19 13:23:41 2019
(r346385)
+++ head/sys/dev/bge/if_bgereg.hFri Apr 19 13:43:33 2019
(r346386)
@@ -3067,3 +3067,11 @@ struct bge_softc {
 #defineBGE_LOCK_ASSERT(_sc)mtx_assert(&(_sc)->bge_mtx, MA_OWNED)
 #defineBGE_UNLOCK(_sc) mtx_unlock(&(_sc)->bge_mtx)
 #defineBGE_LOCK_DESTROY(_sc)   mtx_destroy(&(_sc)->bge_mtx)
+
+#ifdef BUS_SPACE_MAXADDR
+#if (BUS_SPACE_MAXADDR > 0x)
+#defineBGE_DMA_BOUNDARY(0x1)
+#else
+#defineBGE_DMA_BOUNDARY0
+#endif
+#endif

Modified: head/sys/dev/pci/pci.c
==
--- head/sys/dev/pci/pci.c  Fri Apr 19 13:23:41 2019(r346385)
+++ head/sys/dev/pci/pci.c  Fri Apr 19 13:43:33 2019(r346386)
@@ -4343,9 +4343,6 @@ pci_attach_common(device_t dev)
 {
struct pci_softc *sc;
int busno, domain;
-#ifdef PCI_DMA_BOUNDARY
-   int error, tag_valid;
-#endif
 #ifdef PCI_RES_BUS
int rid;
 #endif
@@ -4365,23 +4362,7 @@ pci_attach_common(device_t dev)
if (bootverbose)
device_printf(dev, "domain=%d, physical bus=%d\n",
domain, busno);
-#ifdef PCI_DMA_BOUNDARY
-   tag_valid = 0;
-   if (device_get_devclass(device_get_parent(device_get_parent(dev))) !=
-   devclass_find("pci")) {
-   error = bus_dma_tag_create(bus_get_dma_tag(dev), 1,
-   PCI_DMA_BOUNDARY, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
-   NULL, NULL, BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED,
-   BUS_SPACE_MAXSIZE, 0, NULL, NULL, >sc_dma_tag);
-   if (error)
-   device_printf(dev, "Failed to create DMA tag: %d\n",
-   error);
-   else
-   tag_valid = 1;
-   }
-   if (!tag_valid)
-#endif
-   sc->sc_dma_tag = bus_get_dma_tag(dev);
+   sc->sc_dma_tag = bus_get_dma_tag(dev);
return (0);
 }
 

Modified: head/sys/dev/pci/pcivar.h
==
--- head/sys/dev/pci/pcivar.h   Fri Apr 19 13:23:41 2019(r346385)
+++ head/sys/dev/pci/pcivar.h   Fri Apr 19 13:43:33 2019(r346386)
@@ -693,14 +693,6 @@ intpcie_link_reset(device_t port, int 
pcie_location);
 
 void   pci_print_faulted_dev(void);
 
-#ifdef BUS_SPACE_MAXADDR
-#if (BUS_SPACE_MAXADDR > 0x)
-#definePCI_DMA_BOUNDARY0x1
-#else
-#definePCI_DMA_BOUNDARY0
-#endif
-#endif
-
 #endif /* _SYS_BUS_H_ */
 
 /*

Modified: head/sys/dev/twa/tw_osl.h
==
--- head/sys/dev/twa/tw_osl.h   Fri Apr 19 13:23:41 2019(r346385)
+++ head/sys/dev/twa/tw_osl.h   Fri Apr 19 13:43:33 2019(r346386)
@@ -57,6 +57,12 @@
 #define TW_OSLI_MAX_NUM_IOS(TW_OSLI_MAX_NUM_REQUESTS - 2)
 #define TW_OSLI_MAX_NUM_AENS   0x100
 
+#ifdef PAE
+#defineTW_OSLI_DMA_BOUNDARY(1u << 31)
+#else
+#defineTW_OSLI_DMA_BOUNDARY((bus_size_t)((uint64_t)1 << 
32))
+#endif
+
 /* Possible values of req->state. */
 #define TW_OSLI_REQ_STATE_INIT 0x0 /* being initialized */
 #define TW_OSLI_REQ_STATE_BUSY 0x1 /* submitted to CL */

Modified: head/sys/dev/twa/tw_osl_freebsd.c
==
--- head/sys/dev/twa/tw_osl_freebsd.c   Fri Apr 19 13:23:41 2019
(r346385)
+++ head/sys/dev/twa/tw_osl_freebsd.c   Fri Apr 19 13:43:33 2019
(r346386)
@@ -551,7 +551,7 @@ tw_osli_alloc_mem(struct twa_softc *sc)
/* Create the parent dma tag. */
if (bus_dma_tag_create(bus_get_dma_tag(sc->bus_dev), /* parent */
sc->alignment,  /* alignment */
-   0,  /* boundary */
+   TW_OSLI_DMA_BOUNDARY,   /* boundary */
BUS_SPACE_MAXADDR,  /* lowaddr */
BUS_SPACE_MAXADDR,  /* highaddr */
NULL, NULL, /* filter, filterarg */


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

2019-04-12 Thread Tycho Nightingale


> On Apr 12, 2019, at 12:43 PM, Enji Cooper  wrote:
> 
> 
>> On Apr 12, 2019, at 5:46 AM, Tycho Nightingale  wrote:
>> 
>> Author: tychon
>> Date: Fri Apr 12 12:46:25 2019
>> New Revision: 346150
>> URL: https://svnweb.freebsd.org/changeset/base/346150
>> 
>> Log:
>> for a cache-only zone the destructor tries to destroy a non-existent keg
>> 
>> Reviewed by: markj
>> Sponsored by:Dell EMC Isilon
>> Differential Revision:   https://reviews.freebsd.org/D19835
> 
> 
> Hi Tycho!
>   Is the goal of this change to prevent a panic (with an INVARIANTS 
> kernel)?
> Thank you!
> -Enji

Hi,

The goal of this change is to fix a regression introduced in r343026.  It does 
cause a panic independent of INVARIANTS.  Fortunately there isn’t currently any 
in-tree code which triggers the panic.  It does however show up when running 
with the patch under review in D19845.

Tycho
___
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: r346150 - head/sys/vm

2019-04-12 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 12 12:46:25 2019
New Revision: 346150
URL: https://svnweb.freebsd.org/changeset/base/346150

Log:
  for a cache-only zone the destructor tries to destroy a non-existent keg
  
  Reviewed by:  markj
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19835

Modified:
  head/sys/vm/uma_core.c

Modified: head/sys/vm/uma_core.c
==
--- head/sys/vm/uma_core.c  Fri Apr 12 10:13:17 2019(r346149)
+++ head/sys/vm/uma_core.c  Fri Apr 12 12:46:25 2019(r346150)
@@ -1916,10 +1916,10 @@ zone_dtor(void *arg, int size, void *udata)
 */
zone_drain_wait(zone, M_WAITOK);
/*
-* We only destroy kegs from non secondary zones.
+* We only destroy kegs from non secondary/non cache zones.
 */
-   if ((keg = zone->uz_keg) != NULL &&
-   (zone->uz_flags & UMA_ZONE_SECONDARY) == 0)  {
+   if ((zone->uz_flags & (UMA_ZONE_SECONDARY | UMA_ZFLAG_CACHE)) == 0) {
+   keg = zone->uz_keg;
rw_wlock(_rwlock);
LIST_REMOVE(keg, uk_link);
rw_wunlock(_rwlock);
___
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: r346050 - head/tools/tools/ioat

2019-04-09 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  9 10:33:18 2019
New Revision: 346050
URL: https://svnweb.freebsd.org/changeset/base/346050

Log:
  ioatcontrol(8) crc-copy flag bug and misc usage tweak
  
  Reviewed by:  cem
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19855

Modified:
  head/tools/tools/ioat/ioatcontrol.c

Modified: head/tools/tools/ioat/ioatcontrol.c
==
--- head/tools/tools/ioat/ioatcontrol.c Tue Apr  9 10:17:24 2019
(r346049)
+++ head/tools/tools/ioat/ioatcontrol.c Tue Apr  9 10:33:18 2019
(r346050)
@@ -49,7 +49,7 @@ static void
 usage(void)
 {
 
-   printf("Usage: %s [-c period] [-EfmVz] channel-number num-txns 
[ "
+   printf("Usage: %s [-c period] [-EefmVxXz] channel-number num-txns 
[ "
"[ [duration]]]\n", getprogname());
printf("   %s -r [-c period] [-vVwz] channel-number address 
[]\n\n",
getprogname());
@@ -154,9 +154,11 @@ main(int argc, char **argv)
break;
case 'x':
xflag = true;
+   modeflags++;
break;
case 'X':
Xflag = true;
+   modeflags++;
break;
case 'z':
t.zero_stats = true;
@@ -172,7 +174,7 @@ main(int argc, char **argv)
usage();
 
if (modeflags > 1) {
-   printf("Invalid: Cannot use >1 mode flag (-E, -f, -m, or 
-r)\n");
+   printf("Invalid: Cannot use >1 mode flag (-E, -e, -f, -m, -r, 
-x or -X)\n");
usage();
}
 
@@ -191,7 +193,7 @@ main(int argc, char **argv)
t.testkind = IOAT_TEST_MEMCPY;
else if (xflag)
t.testkind = IOAT_TEST_DMA_CRC;
-   else if (xflag)
+   else if (Xflag)
t.testkind = IOAT_TEST_DMA_CRC_COPY;
 
t.channel_index = atoi(argv[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: r345813 - head/sys/dev/ioat

2019-04-02 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  2 19:08:06 2019
New Revision: 345813
URL: https://svnweb.freebsd.org/changeset/base/345813

Log:
  ioat(4) should use bus_dma(9) for the operation source and destination
  addresses
  
  Reviewed by:  cem
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19725

Modified:
  head/sys/dev/ioat/ioat.c
  head/sys/dev/ioat/ioat_internal.h

Modified: head/sys/dev/ioat/ioat.c
==
--- head/sys/dev/ioat/ioat.cTue Apr  2 19:06:25 2019(r345812)
+++ head/sys/dev/ioat/ioat.cTue Apr  2 19:08:06 2019(r345813)
@@ -320,10 +320,26 @@ err:
return (error);
 }
 
+static inline int
+ioat_bus_dmamap_destroy(struct ioat_softc *ioat, const char *func,
+bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+   int error;
+
+   error = bus_dmamap_destroy(dmat, map);
+   if (error != 0) {
+   ioat_log_message(0,
+   "%s: bus_dmamap_destroy failed %d\n", func, error);
+   }
+
+   return (error);
+}
+
 static int
 ioat_detach(device_t device)
 {
struct ioat_softc *ioat;
+   int i, error;
 
ioat = DEVICE2SOFTC(device);
 
@@ -359,6 +375,47 @@ ioat_detach(device_t device)
bus_release_resource(device, SYS_RES_MEMORY,
ioat->pci_resource_id, ioat->pci_resource);
 
+   if (ioat->data_tag != NULL) {
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].src_dmamap);
+   if (error != 0)
+   return (error);
+   }
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].dst_dmamap);
+   if (error != 0)
+   return (error);
+   }
+
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].src2_dmamap);
+   if (error != 0)
+   return (error);
+   }
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_tag, ioat->ring[i].dst2_dmamap);
+   if (error != 0)
+   return (error);
+   }
+
+   bus_dma_tag_destroy(ioat->data_tag);
+   }
+
+   if (ioat->data_crc_tag != NULL) {
+   for (i = 0; i < 1 << ioat->ring_size_order; i++) {
+   error = ioat_bus_dmamap_destroy(ioat, __func__,
+   ioat->data_crc_tag, ioat->ring[i].crc_dmamap);
+   if (error != 0)
+   return (error);
+   }
+
+   bus_dma_tag_destroy(ioat->data_crc_tag);
+   }
+
if (ioat->ring != NULL)
ioat_free_ring(ioat, 1 << ioat->ring_size_order, ioat->ring);
 
@@ -523,6 +580,25 @@ ioat3_attach(device_t device)
 
ioat->hw_desc_ring = hw_desc;
 
+   error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
+   1, 0, BUS_SPACE_MAXADDR_40BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+   ioat->max_xfer_size, 1, ioat->max_xfer_size, 0, NULL, NULL,
+   >data_crc_tag);
+   if (error != 0) {
+   ioat_log_message(0, "%s: bus_dma_tag_create failed %d\n",
+   __func__, error);
+   return (error);
+   }
+
+   error = bus_dma_tag_create(bus_get_dma_tag(ioat->device),
+   1, 0, BUS_SPACE_MAXADDR_48BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+   ioat->max_xfer_size, 1, ioat->max_xfer_size, 0, NULL, NULL,
+   >data_tag);
+   if (error != 0) {
+   ioat_log_message(0, "%s: bus_dma_tag_create failed %d\n",
+   __func__, error);
+   return (error);
+   }
ioat->ring = malloc(num_descriptors * sizeof(*ring), M_IOAT,
M_ZERO | M_WAITOK);
 
@@ -530,6 +606,46 @@ ioat3_attach(device_t device)
for (i = 0; i < num_descriptors; i++) {
memset([i].bus_dmadesc, 0, sizeof(ring[i].bus_dmadesc));
ring[i].id = i;
+   error = bus_dmamap_create(ioat->data_tag, 0,
+[i].src_dmamap);
+   if (error != 0) {
+   ioat_log_message(0,
+   "%s: bus_dmamap_create failed %d\n", __func__,
+   error);
+   return (error);
+   }
+   error = bus_dmamap_create(ioat->data_tag, 0,
+  

svn commit: r345812 - in head: sys/dev/ioat tools/tools/ioat

2019-04-02 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  2 19:06:25 2019
New Revision: 345812
URL: https://svnweb.freebsd.org/changeset/base/345812

Log:
  ioatcontrol(8) could exercise 8k-aligned copy with page-break, crc and
  crc-copy modes.
  
  Reviewed by:  cem
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19780

Modified:
  head/sys/dev/ioat/ioat_test.c
  head/sys/dev/ioat/ioat_test.h
  head/tools/tools/ioat/ioatcontrol.8
  head/tools/tools/ioat/ioatcontrol.c

Modified: head/sys/dev/ioat/ioat_test.c
==
--- head/sys/dev/ioat/ioat_test.c   Tue Apr  2 18:50:49 2019
(r345811)
+++ head/sys/dev/ioat/ioat_test.c   Tue Apr  2 19:06:25 2019
(r345812)
@@ -65,6 +65,7 @@ struct test_transaction {
void*buf[IOAT_MAX_BUFS];
uint32_tlength;
uint32_tdepth;
+   uint32_tcrc[IOAT_MAX_BUFS];
struct ioat_test*test;
TAILQ_ENTRY(test_transaction)   entry;
 };
@@ -312,6 +313,28 @@ ioat_test_submit_1_tx(struct ioat_test *test, bus_dmae
 
desc = ioat_copy_8k_aligned(dma, dest, dst2, src, src2,
cb, tx, flags);
+   } else if (test->testkind == IOAT_TEST_DMA_8K_PB) {
+   bus_addr_t src2, dst2;
+
+   src2 = vtophys((vm_offset_t)tx->buf[2*i+1] + PAGE_SIZE);
+   dst2 = vtophys((vm_offset_t)tx->buf[2*i] + PAGE_SIZE);
+
+   desc = ioat_copy_8k_aligned(dma, dest, dst2, src, src2,
+   cb, tx, flags);
+   } else if (test->testkind == IOAT_TEST_DMA_CRC) {
+   bus_addr_t crc;
+
+   tx->crc[i] = 0;
+   crc = vtophys((vm_offset_t)>crc[i]);
+   desc = ioat_crc(dma, src, tx->length,
+   NULL, crc, cb, tx, flags | DMA_CRC_STORE);
+   } else if (test->testkind == IOAT_TEST_DMA_CRC_COPY) {
+   bus_addr_t crc;
+
+   tx->crc[i] = 0;
+   crc = vtophys((vm_offset_t)>crc[i]);
+   desc = ioat_copy_crc(dma, dest, src, tx->length,
+   NULL, crc, cb, tx, flags | DMA_CRC_STORE);
}
if (desc == NULL)
break;
@@ -346,7 +369,8 @@ ioat_dma_test(void *arg)
test = arg;
memset(__DEVOLATILE(void *, test->status), 0, sizeof(test->status));
 
-   if (test->testkind == IOAT_TEST_DMA_8K &&
+   if ((test->testkind == IOAT_TEST_DMA_8K ||
+   test->testkind == IOAT_TEST_DMA_8K_PB) &&
test->buffer_size != 2 * PAGE_SIZE) {
ioat_test_log(0, "Asked for 8k test and buffer size isn't 
8k\n");
test->status[IOAT_TEST_INVALID_INPUT]++;

Modified: head/sys/dev/ioat/ioat_test.h
==
--- head/sys/dev/ioat/ioat_test.h   Tue Apr  2 18:50:49 2019
(r345811)
+++ head/sys/dev/ioat/ioat_test.h   Tue Apr  2 19:06:25 2019
(r345812)
@@ -44,6 +44,9 @@ enum ioat_test_kind {
IOAT_TEST_RAW_DMA,
IOAT_TEST_DMA_8K,
IOAT_TEST_MEMCPY,
+   IOAT_TEST_DMA_8K_PB,
+   IOAT_TEST_DMA_CRC,
+   IOAT_TEST_DMA_CRC_COPY,
IOAT_NUM_TESTKINDS
 };
 

Modified: head/tools/tools/ioat/ioatcontrol.8
==
--- head/tools/tools/ioat/ioatcontrol.8 Tue Apr  2 18:50:49 2019
(r345811)
+++ head/tools/tools/ioat/ioatcontrol.8 Tue Apr  2 19:06:25 2019
(r345812)
@@ -35,9 +35,12 @@
 .Nm
 .Op Fl c Ar period
 .Op Fl E
+.Op Fl e
 .Op Fl f
 .Op Fl m
 .Op Fl V
+.Op Fl x
+.Op Fl X
 .Op Fl z
 .Ar channel_number
 .Ar num_txns
@@ -65,6 +68,8 @@ The arguments are as follows:
 Configure the channel's interrupt coalescing period, in microseconds
 (defaults to 0).
 .It Fl E
+Test contiguous 8k copy.
+.It Fl e
 Test non-contiguous 8k copy.
 .It Fl f
 Test block fill (by default,
@@ -74,6 +79,10 @@ tests copy)
 Test memcpy instead of DMA.
 .It Fl V
 Verify copies/fills for accuracy
+.It Fl x
+Test DMA CRC.
+.It Fl X
+Test DMA copy with CRC.
 .It Fl z
 Zero device statistics before running test.
 .El

Modified: head/tools/tools/ioat/ioatcontrol.c
==
--- head/tools/tools/ioat/ioatcontrol.c Tue Apr  2 18:50:49 2019
(r345811)
+++ head/tools/tools/ioat/ioatcontrol.c Tue Apr  2 19:06:25 2019
(r345812)
@@ -54,13 +54,16 @@ usage(void)
printf("   %s -r [-c period] [-vVwz] channel-number address 
[]\n\n",
getprogname());
printf("   -c period - Enable interrupt coalescing (us) 
(default: 0)\n");
-   printf("   -E- Test 

svn commit: r345811 - head/sys/x86/iommu

2019-04-02 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr  2 18:50:49 2019
New Revision: 345811
URL: https://svnweb.freebsd.org/changeset/base/345811

Log:
  DMAR driver assumes all physical addresses are backed by a fully
  initialized struct vm_page.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19753

Modified:
  head/sys/x86/iommu/busdma_dmar.c

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cTue Apr  2 18:50:33 2019
(r345810)
+++ head/sys/x86/iommu/busdma_dmar.cTue Apr  2 18:50:49 2019
(r345811)
@@ -665,9 +665,9 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
 {
struct bus_dma_tag_dmar *tag;
struct bus_dmamap_dmar *map;
-   vm_page_t *ma;
-   vm_paddr_t pstart, pend;
-   int error, i, ma_cnt, offset;
+   vm_page_t *ma, fma;
+   vm_paddr_t pstart, pend, paddr;
+   int error, i, ma_cnt, mflags, offset;
 
tag = (struct bus_dma_tag_dmar *)dmat;
map = (struct bus_dmamap_dmar *)map1;
@@ -675,14 +675,36 @@ dmar_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmam
pend = round_page(buf + buflen);
offset = buf & PAGE_MASK;
ma_cnt = OFF_TO_IDX(pend - pstart);
-   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, map->cansleep ?
-   M_WAITOK : M_NOWAIT);
+   mflags = map->cansleep ? M_WAITOK : M_NOWAIT;
+   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, mflags);
if (ma == NULL)
return (ENOMEM);
-   for (i = 0; i < ma_cnt; i++)
-   ma[i] = PHYS_TO_VM_PAGE(pstart + i * PAGE_SIZE);
+   fma = NULL;
+   for (i = 0; i < ma_cnt; i++) {
+   paddr = pstart + i * PAGE_SIZE;
+   ma[i] = PHYS_TO_VM_PAGE(paddr);
+   if (ma[i] == NULL || VM_PAGE_TO_PHYS(ma[i]) != paddr) {
+   /*
+* If PHYS_TO_VM_PAGE() returned NULL or the
+* vm_page was not initialized we'll use a
+* fake page.
+*/
+   if (fma == NULL) {
+   fma = malloc(sizeof(struct vm_page) * ma_cnt,
+   M_DEVBUF, mflags);
+   if (fma == NULL) {
+   free(ma, M_DEVBUF);
+   return (ENOMEM);
+   }
+   }
+   vm_page_initfake([i], pstart + i * PAGE_SIZE,
+   VM_MEMATTR_DEFAULT);
+   ma[i] = [i];
+   }
+   }
error = dmar_bus_dmamap_load_something(tag, map, ma, offset, buflen,
flags, segs, segp);
+   free(fma, M_DEVBUF);
free(ma, M_DEVBUF);
return (error);
 }
@@ -696,7 +718,7 @@ dmar_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dm
struct bus_dmamap_dmar *map;
vm_page_t *ma, fma;
vm_paddr_t pstart, pend, paddr;
-   int error, i, ma_cnt, offset;
+   int error, i, ma_cnt, mflags, offset;
 
tag = (struct bus_dma_tag_dmar *)dmat;
map = (struct bus_dmamap_dmar *)map1;
@@ -704,41 +726,33 @@ dmar_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dm
pend = round_page((vm_offset_t)buf + buflen);
offset = (vm_offset_t)buf & PAGE_MASK;
ma_cnt = OFF_TO_IDX(pend - pstart);
-   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, map->cansleep ?
-   M_WAITOK : M_NOWAIT);
+   mflags = map->cansleep ? M_WAITOK : M_NOWAIT;
+   ma = malloc(sizeof(vm_page_t) * ma_cnt, M_DEVBUF, mflags);
if (ma == NULL)
return (ENOMEM);
-   if (dumping) {
-   /*
-* If dumping, do not attempt to call
-* PHYS_TO_VM_PAGE() at all.  It may return non-NULL
-* but the vm_page returned might be not initialized,
-* e.g. for the kernel itself.
-*/
-   KASSERT(pmap == kernel_pmap, ("non-kernel address write"));
-   fma = malloc(sizeof(struct vm_page) * ma_cnt, M_DEVBUF,
-   M_ZERO | (map->cansleep ? M_WAITOK : M_NOWAIT));
-   if (fma == NULL) {
-   free(ma, M_DEVBUF);
-   return (ENOMEM);
-   }
-   for (i = 0; i < ma_cnt; i++, pstart += PAGE_SIZE) {
+   fma = NULL;
+   for (i = 0; i < ma_cnt; i++, pstart += PAGE_SIZE) {
+   if (pmap == kernel_pmap)
paddr = pmap_kextract(pstart);
+   else
+   paddr = pmap_extract(pmap, pstart);
+   ma[i] = PHYS_TO_VM_PAGE(paddr);
+   if (ma[i] == NULL || VM_PAGE_TO_PHYS(ma[i]) != paddr) {
+   /*
+* If 

svn commit: r345777 - head/sys/dev/pci

2019-04-01 Thread Tycho Nightingale
Author: tychon
Date: Mon Apr  1 19:08:05 2019
New Revision: 345777
URL: https://svnweb.freebsd.org/changeset/base/345777

Log:
  Devices behind downstream bridges should still get DMAR protection.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19717

Modified:
  head/sys/dev/pci/pci.c

Modified: head/sys/dev/pci/pci.c
==
--- head/sys/dev/pci/pci.c  Mon Apr  1 18:54:15 2019(r345776)
+++ head/sys/dev/pci/pci.c  Mon Apr  1 19:08:05 2019(r345777)
@@ -31,6 +31,7 @@
 #include 
 __FBSDID("$FreeBSD$");
 
+#include "opt_acpi.h"
 #include "opt_bus.h"
 
 #include 
@@ -5693,13 +5694,34 @@ pci_get_resource_list (device_t dev, device_t child)
return (>resources);
 }
 
+#ifdef ACPI_DMAR
+bus_dma_tag_t dmar_get_dma_tag(device_t dev, device_t child);
 bus_dma_tag_t
 pci_get_dma_tag(device_t bus, device_t dev)
 {
+   bus_dma_tag_t tag;
+   struct pci_softc *sc;
+
+   if (device_get_parent(dev) == bus) {
+   /* try dmar and return if it works */
+   tag = dmar_get_dma_tag(bus, dev);
+   } else
+   tag = NULL;
+   if (tag == NULL) {
+   sc = device_get_softc(bus);
+   tag = sc->sc_dma_tag;
+   }
+   return (tag);
+}
+#else
+bus_dma_tag_t
+pci_get_dma_tag(device_t bus, device_t dev)
+{
struct pci_softc *sc = device_get_softc(bus);
 
return (sc->sc_dma_tag);
 }
+#endif
 
 uint32_t
 pci_read_config_method(device_t dev, device_t child, int reg, int width)
___
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: r345601 - head/sys/x86/iommu

2019-03-27 Thread Tycho Nightingale
Author: tychon
Date: Wed Mar 27 20:15:51 2019
New Revision: 345601
URL: https://svnweb.freebsd.org/changeset/base/345601

Log:
  Use the BUS_DMA_NOWRITE flag to expose and create the read-only VT-d
  IOMMU mappings.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19729

Modified:
  head/sys/x86/iommu/busdma_dmar.c

Modified: head/sys/x86/iommu/busdma_dmar.c
==
--- head/sys/x86/iommu/busdma_dmar.cWed Mar 27 19:59:36 2019
(r345600)
+++ head/sys/x86/iommu/busdma_dmar.cWed Mar 27 20:15:51 2019
(r345601)
@@ -527,7 +527,8 @@ dmar_bus_dmamap_load_something1(struct bus_dma_tag_dma
gas_flags |= DMAR_GM_CANSPLIT;
 
error = dmar_gas_map(domain, >common, size, offset,
-   DMAR_MAP_ENTRY_READ | DMAR_MAP_ENTRY_WRITE,
+   DMAR_MAP_ENTRY_READ |
+   ((flags & BUS_DMA_NOWRITE) == 0 ? DMAR_MAP_ENTRY_WRITE : 0),
gas_flags, ma + idx, );
if (error != 0)
break;
___
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: r343912 - head/sys/dev/pms/freebsd/driver/common

2019-02-08 Thread Tycho Nightingale
Author: tychon
Date: Fri Feb  8 16:05:38 2019
New Revision: 343912
URL: https://svnweb.freebsd.org/changeset/base/343912

Log:
  pms(4) should use bus_get_dma_tag() to get parent tag.
  
  Reviewed by:  imp
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/dev/pms/freebsd/driver/common/lxutil.c

Modified: head/sys/dev/pms/freebsd/driver/common/lxutil.c
==
--- head/sys/dev/pms/freebsd/driver/common/lxutil.c Fri Feb  8 14:56:28 
2019(r343911)
+++ head/sys/dev/pms/freebsd/driver/common/lxutil.c Fri Feb  8 16:05:38 
2019(r343912)
@@ -63,7 +63,7 @@ STATIC agBOOLEAN agtiapi_typhAlloc( ag_card_info_t *th
   struct agtiapi_softc *pmsc = thisCardInst->pCard;
   int wait = 0;
 
-  if( bus_dma_tag_create( agNULL,  // parent
+  if( bus_dma_tag_create( bus_get_dma_tag(pmsc->my_dev), // parent
   32,  // alignment
   0,   // boundary
   BUS_SPACE_MAXADDR,   // lowaddr
___
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: r334856 - head/sys/amd64/amd64

2018-06-08 Thread Tycho Nightingale
Author: tychon
Date: Fri Jun  8 20:35:58 2018
New Revision: 334856
URL: https://svnweb.freebsd.org/changeset/base/334856

Log:
  Don't bother looking for non-executable pages when a process is
  excluded from PTI.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D15708

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

Modified: head/sys/amd64/amd64/trap.c
==
--- head/sys/amd64/amd64/trap.c Fri Jun  8 20:31:59 2018(r334855)
+++ head/sys/amd64/amd64/trap.c Fri Jun  8 20:35:58 2018(r334856)
@@ -770,7 +770,8 @@ trap_pfault(struct trapframe *frame, int usermode)
 * If nx protection of the usermode portion of kernel page
 * tables caused trap, panic.
 */
-   if (pti && usermode && pg_nx != 0 && (frame->tf_err & (PGEX_P | PGEX_W |
+   if (PCPU_GET(curpmap)->pm_ucr3 != PMAP_NO_CR3 && usermode &&
+   pg_nx != 0 && (frame->tf_err & (PGEX_P | PGEX_W |
PGEX_U | PGEX_I)) == (PGEX_P | PGEX_U | PGEX_I) &&
(curpcb->pcb_saved_ucr3 & ~CR3_PCID_MASK)==
(PCPU_GET(curpmap)->pm_cr3 & ~CR3_PCID_MASK))
___
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: r333059 - in head/sys/amd64: amd64 include

2018-04-27 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 27 12:44:20 2018
New Revision: 333059
URL: https://svnweb.freebsd.org/changeset/base/333059

Log:
  Expand the checks for UCR3 == PMAP_NO_CR3 to enable processes to be
  excluded from PTI.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D15100

Modified:
  head/sys/amd64/amd64/cpu_switch.S
  head/sys/amd64/amd64/exception.S
  head/sys/amd64/amd64/genassym.c
  head/sys/amd64/amd64/machdep.c
  head/sys/amd64/amd64/mp_machdep.c
  head/sys/amd64/amd64/pmap.c
  head/sys/amd64/amd64/trap.c
  head/sys/amd64/include/asmacros.h
  head/sys/amd64/include/pcpu.h

Modified: head/sys/amd64/amd64/cpu_switch.S
==
--- head/sys/amd64/amd64/cpu_switch.S   Fri Apr 27 12:03:27 2018
(r333058)
+++ head/sys/amd64/amd64/cpu_switch.S   Fri Apr 27 12:44:20 2018
(r333059)
@@ -215,10 +215,13 @@ done_tss:
movq%r8,PCPU(RSP0)
movq%r8,PCPU(CURPCB)
/* Update the TSS_RSP0 pointer for the next interrupt */
-   cmpb$0,pti(%rip)
-   jne 1f
-   movq%r8,TSS_RSP0(%rdx)
-1: movq%r12,PCPU(CURTHREAD)/* into next thread */
+   cmpq$~0,PCPU(UCR3)
+   je  1f
+   movqPCPU(PTI_RSP0),%rax
+   movq%rax,TSS_RSP0(%rdx)
+   jmp 2f
+1: movq%r8,TSS_RSP0(%rdx)
+2: movq%r12,PCPU(CURTHREAD)/* into next thread */
 
/* Test if debug registers should be restored. */
testl   $PCB_DBREGS,PCB_FLAGS(%r8)
@@ -295,12 +298,7 @@ do_tss:movq%rdx,PCPU(TSSP)
shrq$8,%rcx
movl%ecx,8(%rax)
movb$0x89,5(%rax)   /* unset busy */
-   cmpb$0,pti(%rip)
-   je  1f
-   movqPCPU(PRVSPACE),%rax
-   addq$PC_PTI_STACK+PC_PTI_STACK_SZ*8,%rax
-   movq%rax,TSS_RSP0(%rdx)
-1: movl$TSSSEL,%eax
+   movl$TSSSEL,%eax
ltr %ax
jmp done_tss
 

Modified: head/sys/amd64/amd64/exception.S
==
--- head/sys/amd64/amd64/exception.SFri Apr 27 12:03:27 2018
(r333058)
+++ head/sys/amd64/amd64/exception.SFri Apr 27 12:44:20 2018
(r333059)
@@ -298,11 +298,15 @@ IDTVEC(page_pti)
jz  Xpage
swapgs
pushq   %rax
-   pushq   %rdx
movq%cr3,%rax
movq%rax,PCPU(SAVED_UCR3)
+   cmpq$~0,PCPU(UCR3)
+   jne 1f
+   popq%rax
+   jmp 2f
+1: pushq   %rdx
PTI_UUENTRY has_err=1
-   subq$TF_ERR,%rsp
+2: subq$TF_ERR,%rsp
movq%rdi,TF_RDI(%rsp)
movq%rax,TF_RAX(%rsp)
movq%rdx,TF_RDX(%rsp)
@@ -347,9 +351,11 @@ page_cr2:
 */
.macro PROTF_ENTRY name,trapno
 \name\()_pti_doreti:
+   swapgs
+   cmpq$~0,PCPU(UCR3)
+   je  1f
pushq   %rax
pushq   %rdx
-   swapgs
movqPCPU(KCR3),%rax
movq%rax,%cr3
movqPCPU(RSP0),%rax
@@ -362,7 +368,7 @@ page_cr2:
movq%rax,%rsp
popq%rdx
popq%rax
-   swapgs
+1: swapgs
jmp X\name
 IDTVEC(\name\()_pti)
cmpq$doreti_iret,PTI_RIP-2*8(%rsp)
@@ -438,6 +444,8 @@ prot_addrf:
 IDTVEC(fast_syscall_pti)
swapgs
movq%rax,PCPU(SCRATCH_RAX)
+   cmpq$~0,PCPU(UCR3)
+   je  fast_syscall_common
movqPCPU(KCR3),%rax
movq%rax,%cr3
jmp fast_syscall_common
@@ -503,7 +511,7 @@ fast_syscall_common:
movqTF_RFLAGS(%rsp),%r11/* original %rflags */
movqTF_RIP(%rsp),%rcx   /* original %rip */
movqTF_RSP(%rsp),%rsp   /* user stack pointer */
-   cmpb$0,pti
+   cmpq$~0,PCPU(UCR3)
je  2f
movqPCPU(UCR3),%r9
movq%r9,%cr3
@@ -1011,11 +1019,11 @@ ld_regs:
jz  2f  /* keep running with kernel GS.base */
cli
callhandle_ibrs_exit_rs
-   cmpb$0,pti
+   cmpq$~0,PCPU(UCR3)
je  1f
pushq   %rdx
-   movqPCPU(PRVSPACE),%rdx
-   addq$PC_PTI_STACK+PC_PTI_STACK_SZ*8-PTI_SIZE,%rdx
+   movqPCPU(PTI_RSP0),%rdx
+   subq$PTI_SIZE,%rdx
movq%rax,PTI_RAX(%rdx)
popq%rax
movq%rax,PTI_RDX(%rdx)

Modified: head/sys/amd64/amd64/genassym.c
==
--- head/sys/amd64/amd64/genassym.c Fri Apr 27 12:03:27 2018
(r333058)
+++ head/sys/amd64/amd64/genassym.c Fri Apr 27 12:44:20 2018
(r333059)
@@ -227,6 +227,7 @@ ASSYM(PC_UCR3, offsetof(struct pcpu, pc_ucr3));
 ASSYM(PC_SAVED_UCR3, offsetof(struct pcpu, pc_saved_ucr3));
 ASSYM(PC_PTI_STACK, offsetof(struct pcpu, pc_pti_stack));
 ASSYM(PC_PTI_STACK_SZ, 

Re: svn commit: r332994 - head/sys/amd64/amd64

2018-04-25 Thread Tycho Nightingale


> On Apr 25, 2018, at 10:30 AM, Oliver Pinter <oliver.pin...@hardenedbsd.org> 
> wrote:
> 
> On Wednesday, April 25, 2018, Tycho Nightingale <tyc...@freebsd.org 
> <mailto:tyc...@freebsd.org>> wrote:
> Author: tychon
> Date: Wed Apr 25 14:21:13 2018
> New Revision: 332994
> URL: https://svnweb.freebsd.org/changeset/base/332994 
> <https://svnweb.freebsd.org/changeset/base/332994>
> 
> Log:
>   If a trap is encountered upon executing iretq from within doreti() the
>   hardware will ensure the stack pointer is aligned to a 16-byte
>   boundary before saving the fault state on the stack.
> 
>   In the PTI case, handle this potential alignment adjustment by copying
>   both frames independently while unwinding the stack in between.
> 
>   Reviewed by:  kib
>   Sponsored by: Dell EMC Isilon
>   Differential Revision:https://reviews.freebsd.org/D15183 
> <https://reviews.freebsd.org/D15183>
> 
> Is there any plan to MFC this commit? 

Yes, it seems reasonable to do that after 2 weeks.

Tycho
___
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: r332994 - head/sys/amd64/amd64

2018-04-25 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr 25 14:21:13 2018
New Revision: 332994
URL: https://svnweb.freebsd.org/changeset/base/332994

Log:
  If a trap is encountered upon executing iretq from within doreti() the
  hardware will ensure the stack pointer is aligned to a 16-byte
  boundary before saving the fault state on the stack.
  
  In the PTI case, handle this potential alignment adjustment by copying
  both frames independently while unwinding the stack in between.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D15183

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

Modified: head/sys/amd64/amd64/exception.S
==
--- head/sys/amd64/amd64/exception.SWed Apr 25 13:23:58 2018
(r332993)
+++ head/sys/amd64/amd64/exception.SWed Apr 25 14:21:13 2018
(r332994)
@@ -341,6 +341,9 @@ page_cr2:
 * On the stack, we have the hardware interrupt frame to return
 * to usermode (faulted) and another frame with error code, for
 * fault.  For PTI, copy both frames to the main thread stack.
+* Handle the potential 16-byte alignment adjustment incurred
+* during the second fault by copying both frames independently
+* while unwinding the stack in between.
 */
.macro PROTF_ENTRY name,trapno
 \name\()_pti_doreti:
@@ -351,7 +354,11 @@ page_cr2:
movq%rax,%cr3
movqPCPU(RSP0),%rax
subq$2*PTI_SIZE-3*8,%rax /* no err, %rax, %rdx in faulted frame */
-   MOVE_STACKS (PTI_SIZE / 4 - 3)
+   MOVE_STACKS (PTI_SIZE / 8)
+   addq$PTI_SIZE,%rax
+   movqPTI_RSP(%rsp),%rsp
+   MOVE_STACKS (PTI_SIZE / 8 - 3)
+   subq$PTI_SIZE,%rax
movq%rax,%rsp
popq%rdx
popq%rax
___
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: r332479 - in head/sys/amd64: include vmm vmm/intel

2018-04-13 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 13 17:23:05 2018
New Revision: 332479
URL: https://svnweb.freebsd.org/changeset/base/332479

Log:
  Add SDT probes to vmexit on Intel.
  
  Submitted by: domagoj.stolfa_gmail.com
  Reviewed by:  grehan, tychon
  Sponsored by: DARPA/AFRL
  Differential Revision:https://reviews.freebsd.org/D14656

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/amd64/vmm/vmm.c

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hFri Apr 13 16:54:49 2018
(r332478)
+++ head/sys/amd64/include/vmm.hFri Apr 13 17:23:05 2018
(r332479)
@@ -31,7 +31,12 @@
 #ifndef _VMM_H_
 #define_VMM_H_
 
+#include 
 #include 
+
+#ifdef _KERNEL
+SDT_PROVIDER_DECLARE(vmm);
+#endif
 
 enum vm_suspend_how {
VM_SUSPEND_NONE,

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Fri Apr 13 16:54:49 2018
(r332478)
+++ head/sys/amd64/vmm/intel/vmx.c  Fri Apr 13 17:23:05 2018
(r332479)
@@ -188,6 +188,82 @@ SYSCTL_UINT(_hw_vmm_vmx, OID_AUTO, vpid_alloc_failed, 
_alloc_failed, 0, NULL);
 
 /*
+ * The definitions of SDT probes for VMX.
+ */
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, entry,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, taskswitch,
+"struct vmx *", "int", "struct vm_exit *", "struct vm_task_switch *");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, craccess,
+"struct vmx *", "int", "struct vm_exit *", "uint64_t");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, rdmsr,
+"struct vmx *", "int", "struct vm_exit *", "uint32_t");
+
+SDT_PROBE_DEFINE5(vmm, vmx, exit, wrmsr,
+"struct vmx *", "int", "struct vm_exit *", "uint32_t", "uint64_t");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, halt,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, mtrap,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, pause,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, intrwindow,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, interrupt,
+"struct vmx *", "int", "struct vm_exit *", "uint32_t");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, nmiwindow,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, inout,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, cpuid,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE5(vmm, vmx, exit, exception,
+"struct vmx *", "int", "struct vm_exit *", "uint32_t", "int");
+
+SDT_PROBE_DEFINE5(vmm, vmx, exit, nestedfault,
+"struct vmx *", "int", "struct vm_exit *", "uint64_t", "uint64_t");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, mmiofault,
+"struct vmx *", "int", "struct vm_exit *", "uint64_t");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, eoi,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, apicaccess,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, apicwrite,
+"struct vmx *", "int", "struct vm_exit *", "struct vlapic *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, xsetbv,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, monitor,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE3(vmm, vmx, exit, mwait,
+"struct vmx *", "int", "struct vm_exit *");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, unknown,
+"struct vmx *", "int", "struct vm_exit *", "uint32_t");
+
+SDT_PROBE_DEFINE4(vmm, vmx, exit, return,
+"struct vmx *", "int", "struct vm_exit *", "int");
+
+/*
  * Use the last page below 4GB as the APIC access address. This address is
  * occupied by the boot firmware so it is guaranteed that it will not conflict
  * with a page in system memory.
@@ -2118,6 +2194,7 @@ vmx_exit_process(struct vmx *vmx, int vcpu, struct vm_
vmexit->exitcode = VM_EXITCODE_BOGUS;
 
vmm_stat_incr(vmx->vm, vcpu, VMEXIT_COUNT, 1);
+   SDT_PROBE3(vmm, vmx, exit, entry, vmx, vcpu, vmexit);
 
/*
 * VM-entry failures during or after loading guest state.
@@ -2220,6 +2297,7 @@ vmx_exit_process(struct vmx *vmx, int vcpu, struct vm_
}
}
vmexit->exitcode = VM_EXITCODE_TASK_SWITCH;
+   SDT_PROBE4(vmm, vmx, exit, taskswitch, vmx, vcpu, vmexit, ts);
VCPU_CTR4(vmx->vm, vcpu, "task switch reason %d, tss 0x%04x, "
"%s errcode 0x%016lx", ts->reason, ts->tsssel,
ts->ext ? "external" : "internal",
@@ -2227,6 +2305,7 @@ vmx_exit_process(struct vmx *vmx, int vcpu, struct vm_
break;
case EXIT_REASON_CR_ACCESS:
vmm_stat_incr(vmx->vm, vcpu, VMEXIT_CR_ACCESS, 

svn commit: r330713 - in stable/10/sys/amd64/vmm: amd intel

2018-03-09 Thread Tycho Nightingale
Author: tychon
Date: Sat Mar 10 00:44:33 2018
New Revision: 330713
URL: https://svnweb.freebsd.org/changeset/base/330713

Log:
  MFC r328011,329162
  
  r328011:
  
  Provide some mitigation against CVE-2017-5715 by clearing registers
  upon returning from the guest which aren't immediately clobbered by
  the host.  This eradicates any remaining guest contents limiting their
  usefulness in an exploit gadget.
  
  r329162:
  
  Provide further mitigation against CVE-2017-5715 by flushing the
  return stack buffer (RSB) upon returning from the guest.

Modified:
  stable/10/sys/amd64/vmm/amd/svm_support.S
  stable/10/sys/amd64/vmm/intel/vmcs.c
  stable/10/sys/amd64/vmm/intel/vmx.h
  stable/10/sys/amd64/vmm/intel/vmx_support.S
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/vmm/amd/svm_support.S
==
--- stable/10/sys/amd64/vmm/amd/svm_support.S   Sat Mar 10 00:10:47 2018
(r330712)
+++ stable/10/sys/amd64/vmm/amd/svm_support.S   Sat Mar 10 00:44:33 2018
(r330713)
@@ -113,6 +113,23 @@ ENTRY(svm_launch)
movq %rdi, SCTX_RDI(%rax)
movq %rsi, SCTX_RSI(%rax)
 
+   /*
+* To prevent malicious branch target predictions from
+* affecting the host, overwrite all entries in the RSB upon
+* exiting a guest.
+*/
+   mov $16, %ecx   /* 16 iterations, two calls per loop */
+   mov %rsp, %rax
+0: call 2f /* create an RSB entry. */
+1: pause
+   call 1b /* capture rogue speculation. */
+2: call 2f /* create an RSB entry. */
+1: pause
+   call 1b /* capture rogue speculation. */
+2: sub $1, %ecx
+   jnz 0b
+   mov %rax, %rsp
+
/* Restore host state */
pop %r15
pop %r14
@@ -124,8 +141,20 @@ ENTRY(svm_launch)
pop %rdx
mov %edx, %eax
shr $32, %rdx
-   mov $MSR_GSBASE, %ecx
+   mov $MSR_GSBASE, %rcx
wrmsr
+
+   /*
+* Clobber the remaining registers with guest contents so they
+* can't be misused.
+*/
+   xor %rbp, %rbp
+   xor %rdi, %rdi
+   xor %rsi, %rsi
+   xor %r8, %r8
+   xor %r9, %r9
+   xor %r10, %r10
+   xor %r11, %r11
 
VLEAVE
ret

Modified: stable/10/sys/amd64/vmm/intel/vmcs.c
==
--- stable/10/sys/amd64/vmm/intel/vmcs.cSat Mar 10 00:10:47 2018
(r330712)
+++ stable/10/sys/amd64/vmm/intel/vmcs.cSat Mar 10 00:44:33 2018
(r330713)
@@ -32,6 +32,7 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#include 
 #include 
 #include 
 
@@ -50,6 +51,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #endif
 
+SYSCTL_DECL(_hw_vmm_vmx);
+
+static int no_flush_rsb;
+SYSCTL_INT(_hw_vmm_vmx, OID_AUTO, no_flush_rsb, CTLFLAG_RW,
+_flush_rsb, 0, "Do not flush RSB upon vmexit");
+
 static uint64_t
 vmcs_fix_regval(uint32_t encoding, uint64_t val)
 {
@@ -401,8 +408,15 @@ vmcs_init(struct vmcs *vmcs)
goto done;
 
/* instruction pointer */
-   if ((error = vmwrite(VMCS_HOST_RIP, (u_long)vmx_exit_guest)) != 0)
-   goto done;
+   if (no_flush_rsb) {
+   if ((error = vmwrite(VMCS_HOST_RIP,
+   (u_long)vmx_exit_guest)) != 0)
+   goto done;
+   } else {
+   if ((error = vmwrite(VMCS_HOST_RIP,
+   (u_long)vmx_exit_guest_flush_rsb)) != 0)
+   goto done;
+   }
 
/* link pointer */
if ((error = vmwrite(VMCS_LINK_POINTER, ~0)) != 0)

Modified: stable/10/sys/amd64/vmm/intel/vmx.h
==
--- stable/10/sys/amd64/vmm/intel/vmx.h Sat Mar 10 00:10:47 2018
(r330712)
+++ stable/10/sys/amd64/vmm/intel/vmx.h Sat Mar 10 00:44:33 2018
(r330713)
@@ -138,5 +138,6 @@ u_long  vmx_fix_cr4(u_long cr4);
 intvmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset);
 
 extern charvmx_exit_guest[];
+extern charvmx_exit_guest_flush_rsb[];
 
 #endif

Modified: stable/10/sys/amd64/vmm/intel/vmx_support.S
==
--- stable/10/sys/amd64/vmm/intel/vmx_support.S Sat Mar 10 00:10:47 2018
(r330712)
+++ stable/10/sys/amd64/vmm/intel/vmx_support.S Sat Mar 10 00:44:33 2018
(r330713)
@@ -42,6 +42,29 @@
 #define VLEAVE  pop %rbp
 
 /*
+ * Save the guest context.
+ */
+#defineVMX_GUEST_SAVE  
\
+   movq%rdi,VMXCTX_GUEST_RDI(%rsp);\
+   movq%rsi,VMXCTX_GUEST_RSI(%rsp);\
+   movq%rdx,VMXCTX_GUEST_RDX(%rsp);\
+   movq%rcx,VMXCTX_GUEST_RCX(%rsp);\
+   movq

svn commit: r330704 - in stable/11/sys/amd64/vmm: amd intel

2018-03-09 Thread Tycho Nightingale
Author: tychon
Date: Fri Mar  9 19:39:08 2018
New Revision: 330704
URL: https://svnweb.freebsd.org/changeset/base/330704

Log:
  MFC r328011,329162
  
  r328011:
  
  Provide some mitigation against CVE-2017-5715 by clearing registers
  upon returning from the guest which aren't immediately clobbered by
  the host.  This eradicates any remaining guest contents limiting their
  usefulness in an exploit gadget.
  
  r329162:
  
  Provide further mitigation against CVE-2017-5715 by flushing the
  return stack buffer (RSB) upon returning from the guest.

Modified:
  stable/11/sys/amd64/vmm/amd/svm_support.S
  stable/11/sys/amd64/vmm/intel/vmcs.c
  stable/11/sys/amd64/vmm/intel/vmx.h
  stable/11/sys/amd64/vmm/intel/vmx_support.S
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/amd64/vmm/amd/svm_support.S
==
--- stable/11/sys/amd64/vmm/amd/svm_support.S   Fri Mar  9 19:04:06 2018
(r330703)
+++ stable/11/sys/amd64/vmm/amd/svm_support.S   Fri Mar  9 19:39:08 2018
(r330704)
@@ -113,6 +113,23 @@ ENTRY(svm_launch)
movq %rdi, SCTX_RDI(%rax)
movq %rsi, SCTX_RSI(%rax)
 
+   /*
+* To prevent malicious branch target predictions from
+* affecting the host, overwrite all entries in the RSB upon
+* exiting a guest.
+*/
+   mov $16, %ecx   /* 16 iterations, two calls per loop */
+   mov %rsp, %rax
+0: call 2f /* create an RSB entry. */
+1: pause
+   call 1b /* capture rogue speculation. */
+2: call 2f /* create an RSB entry. */
+1: pause
+   call 1b /* capture rogue speculation. */
+2: sub $1, %ecx
+   jnz 0b
+   mov %rax, %rsp
+
/* Restore host state */
pop %r15
pop %r14
@@ -124,8 +141,20 @@ ENTRY(svm_launch)
pop %rdx
mov %edx, %eax
shr $32, %rdx
-   mov $MSR_GSBASE, %ecx
+   mov $MSR_GSBASE, %rcx
wrmsr
+
+   /*
+* Clobber the remaining registers with guest contents so they
+* can't be misused.
+*/
+   xor %rbp, %rbp
+   xor %rdi, %rdi
+   xor %rsi, %rsi
+   xor %r8, %r8
+   xor %r9, %r9
+   xor %r10, %r10
+   xor %r11, %r11
 
VLEAVE
ret

Modified: stable/11/sys/amd64/vmm/intel/vmcs.c
==
--- stable/11/sys/amd64/vmm/intel/vmcs.cFri Mar  9 19:04:06 2018
(r330703)
+++ stable/11/sys/amd64/vmm/intel/vmcs.cFri Mar  9 19:39:08 2018
(r330704)
@@ -32,6 +32,7 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#include 
 #include 
 #include 
 
@@ -50,6 +51,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #endif
 
+SYSCTL_DECL(_hw_vmm_vmx);
+
+static int no_flush_rsb;
+SYSCTL_INT(_hw_vmm_vmx, OID_AUTO, no_flush_rsb, CTLFLAG_RW,
+_flush_rsb, 0, "Do not flush RSB upon vmexit");
+
 static uint64_t
 vmcs_fix_regval(uint32_t encoding, uint64_t val)
 {
@@ -401,8 +408,15 @@ vmcs_init(struct vmcs *vmcs)
goto done;
 
/* instruction pointer */
-   if ((error = vmwrite(VMCS_HOST_RIP, (u_long)vmx_exit_guest)) != 0)
-   goto done;
+   if (no_flush_rsb) {
+   if ((error = vmwrite(VMCS_HOST_RIP,
+   (u_long)vmx_exit_guest)) != 0)
+   goto done;
+   } else {
+   if ((error = vmwrite(VMCS_HOST_RIP,
+   (u_long)vmx_exit_guest_flush_rsb)) != 0)
+   goto done;
+   }
 
/* link pointer */
if ((error = vmwrite(VMCS_LINK_POINTER, ~0)) != 0)

Modified: stable/11/sys/amd64/vmm/intel/vmx.h
==
--- stable/11/sys/amd64/vmm/intel/vmx.h Fri Mar  9 19:04:06 2018
(r330703)
+++ stable/11/sys/amd64/vmm/intel/vmx.h Fri Mar  9 19:39:08 2018
(r330704)
@@ -148,5 +148,6 @@ u_long  vmx_fix_cr4(u_long cr4);
 intvmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset);
 
 extern charvmx_exit_guest[];
+extern charvmx_exit_guest_flush_rsb[];
 
 #endif

Modified: stable/11/sys/amd64/vmm/intel/vmx_support.S
==
--- stable/11/sys/amd64/vmm/intel/vmx_support.S Fri Mar  9 19:04:06 2018
(r330703)
+++ stable/11/sys/amd64/vmm/intel/vmx_support.S Fri Mar  9 19:39:08 2018
(r330704)
@@ -42,6 +42,29 @@
 #define VLEAVE  pop %rbp
 
 /*
+ * Save the guest context.
+ */
+#defineVMX_GUEST_SAVE  
\
+   movq%rdi,VMXCTX_GUEST_RDI(%rsp);\
+   movq%rsi,VMXCTX_GUEST_RSI(%rsp);\
+   movq%rdx,VMXCTX_GUEST_RDX(%rsp);\
+   movq%rcx,VMXCTX_GUEST_RCX(%rsp);\
+   movq

Re: svn commit: r328011 - in head/sys/amd64/vmm: amd intel

2018-03-09 Thread Tycho Nightingale

> On Mar 9, 2018, at 9:26 AM, Ed Maste <ema...@freebsd.org> wrote:
> 
> On 8 March 2018 at 21:57, Kubilay Kocak <ko...@freebsd.org> wrote:
>> On 9/03/2018 8:57 am, Ed Maste wrote:
>>> On 15 January 2018 at 13:37, Tycho Nightingale <tyc...@freebsd.org> wrote:
>>>> Author: tychon
>>>> Date: Mon Jan 15 18:37:03 2018
>>>> New Revision: 328011
>>>> URL: https://svnweb.freebsd.org/changeset/base/328011
>>>> 
>>>> Log:
>>>>  Provide some mitigation against CVE-2017-5715 by clearing registers
>>>>  upon returning from the guest which aren't immediately clobbered by
>>>>  the host.  This eradicates any remaining guest contents limiting their
>>>>  usefulness in an exploit gadget.
>>> 
>>> Will you MFC this to stable/11?
>> 
>> Mitigations and related MFC's and SA's, etc for vulnerabilities, are
>> presumably all being coordinated and handled by secteam, with associated
>> (explicit) messaging when fixes don't apply to particular
>> branches/versions, no?
> 
> Embargoed patches to address specific security vulnerabilities are
> handled by secteam, and are committed to all branches simultaneously.
> 
> For cases like this, where it's a mitigation or other improvement that
> is already committed to CURRENT, it's best if the domain expert /
> original committer handles the merge. That said, I'm happy to take
> care of the merge if desired.

No worries, I will merge this and r329162 too.

Tycho

___
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: r330615 - in head/sys/amd64: include vmm/intel

2018-03-07 Thread Tycho Nightingale
Author: tychon
Date: Wed Mar  7 18:03:22 2018
New Revision: 330615
URL: https://svnweb.freebsd.org/changeset/base/330615

Log:
  Fix a lock recursion introduced in r327065.
  
  Reported by:  kmacy
  Reviewed by:  grehan, jhb
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D14548

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/intel/vmx.c

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hWed Mar  7 17:37:36 2018
(r330614)
+++ head/sys/amd64/include/vmm.hWed Mar  7 18:03:22 2018
(r330615)
@@ -636,6 +636,7 @@ struct vm_exit {
} spinup_ap;
struct {
uint64_trflags;
+   uint64_tintr_status;
} hlt;
struct {
int vector;

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Wed Mar  7 17:37:36 2018
(r330614)
+++ head/sys/amd64/vmm/intel/vmx.c  Wed Mar  7 18:03:22 2018
(r330615)
@@ -2282,6 +2282,11 @@ vmx_exit_process(struct vmx *vmx, int vcpu, struct vm_
vmm_stat_incr(vmx->vm, vcpu, VMEXIT_HLT, 1);
vmexit->exitcode = VM_EXITCODE_HLT;
vmexit->u.hlt.rflags = vmcs_read(VMCS_GUEST_RFLAGS);
+   if (virtual_interrupt_delivery)
+   vmexit->u.hlt.intr_status =
+   vmcs_read(VMCS_GUEST_INTR_STATUS);
+   else
+   vmexit->u.hlt.intr_status = 0;
break;
case EXIT_REASON_MTF:
vmm_stat_incr(vmx->vm, vcpu, VMEXIT_MTRAP, 1);
@@ -3267,12 +3272,13 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr)
 * interrupt by reevaluating virtual interrupts
 * following Section 29.2.1 in the Intel SDM Volume 3.
 */
-   uint64_t val;
+   struct vm_exit *vmexit;
uint8_t rvi, ppr;
 
-   vmx_getreg(vlapic_vtx->vmx, vlapic->vcpuid,
-   VMCS_IDENT(VMCS_GUEST_INTR_STATUS), );
-   rvi = val & APIC_TPR_INT;
+   vmexit = vm_exitinfo(vlapic->vm, vlapic->vcpuid);
+   KASSERT(vmexit->exitcode == VM_EXITCODE_HLT,
+   ("vmx_pending_intr: exitcode not 'HLT'"));
+   rvi = vmexit->u.hlt.intr_status & APIC_TPR_INT;
lapic = vlapic->apic_page;
ppr = lapic->ppr & APIC_TPR_INT;
if (rvi > ppr) {
___
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: r329162 - in head/sys/amd64/vmm: amd intel

2018-02-12 Thread Tycho Nightingale

Hi,

> On Feb 12, 2018, at 10:37 AM, Shawn Webb <shawn.w...@hardenedbsd.org> wrote:
> 
> On Mon, Feb 12, 2018 at 02:45:27PM +, Tycho Nightingale wrote:
>> Author: tychon
>> Date: Mon Feb 12 14:45:27 2018
>> New Revision: 329162
>> URL: https://svnweb.freebsd.org/changeset/base/329162
>> 
>> Log:
>>  Provide further mitigation against CVE-2017-5715 by flushing the
>>  return stack buffer (RSB) upon returning from the guest.
>> 
>>  This was inspired by this linux commit:
>>  
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/arch/x86/kvm?id=117cc7a908c83697b0b737d15ae1eb5943afe35b
>> 
>>  Reviewed by:grehan
>>  Sponsored by:   Dell EMC Isilon
>>  Differential Revision:  https://reviews.freebsd.org/D14272
>> 
>> Modified:
>>  head/sys/amd64/vmm/amd/svm_support.S
>>  head/sys/amd64/vmm/intel/vmcs.c
>>  head/sys/amd64/vmm/intel/vmx.h
>>  head/sys/amd64/vmm/intel/vmx_support.S
>> 
>> Modified: head/sys/amd64/vmm/amd/svm_support.S
>> ==
>> --- head/sys/amd64/vmm/amd/svm_support.S Mon Feb 12 14:44:21 2018
>> (r329161)
>> +++ head/sys/amd64/vmm/amd/svm_support.S Mon Feb 12 14:45:27 2018
>> (r329162)
>> @@ -113,6 +113,23 @@ ENTRY(svm_launch)
>>  movq %rdi, SCTX_RDI(%rax)
>>  movq %rsi, SCTX_RSI(%rax)
>> 
>> +/*
>> + * To prevent malicious branch target predictions from
>> + * affecting the host, overwrite all entries in the RSB upon
>> + * exiting a guest.
>> + */
>> +mov $16, %ecx   /* 16 iterations, two calls per loop */
>> +mov %rsp, %rax
>> +0:  call 2f /* create an RSB entry. */
>> +1:  pause
>> +call 1b /* capture rogue speculation. */
>> +2:  call 2f /* create an RSB entry. */
>> +1:  pause
>> +call 1b /* capture rogue speculation. */
>> +2:  sub $1, %ecx
>> +jnz 0b
>> +mov %rax, %rsp
>> +
>>  /* Restore host state */
>>  pop %r15
>>  pop %r14
>> 
> 
> For amd systems, isn't use of lfence required for performance
> reasons[1]? Or am I conflating two things?
> 
> 1: https://reviews.llvm.org/D41723

For what AMD calls V2 (the window of a speculative execution between indirect 
branch predictions and resolution of the correct target) there are a few 
mitigations cited in their white paper:


https://developer.amd.com/wp-content/resources/Managing-Speculation-on-AMD-Processors.pdf

depending on the specific code you are trying to “fix”.  In my interpretation 
lfence is a component of several of the possible mitigations when one wants to 
“fix” a specific indirect branch but does not ensure that subsequent branches 
will not be speculated around.  In this case we are trying to guard against the 
more generic case of "entering more privileged code” i.e. returning from the 
guest to hypervisor aka host and protect all subsequent indirect branches 
without needing to apply an lfence to them individually.  To do that, I’ve 
implemented mitigation V2-3 where the return address predictor is filled with 
benign entries.

Does that help?

Tycho
___
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: r329162 - in head/sys/amd64/vmm: amd intel

2018-02-12 Thread Tycho Nightingale
Author: tychon
Date: Mon Feb 12 14:45:27 2018
New Revision: 329162
URL: https://svnweb.freebsd.org/changeset/base/329162

Log:
  Provide further mitigation against CVE-2017-5715 by flushing the
  return stack buffer (RSB) upon returning from the guest.
  
  This was inspired by this linux commit:
  
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/arch/x86/kvm?id=117cc7a908c83697b0b737d15ae1eb5943afe35b
  
  Reviewed by:  grehan
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D14272

Modified:
  head/sys/amd64/vmm/amd/svm_support.S
  head/sys/amd64/vmm/intel/vmcs.c
  head/sys/amd64/vmm/intel/vmx.h
  head/sys/amd64/vmm/intel/vmx_support.S

Modified: head/sys/amd64/vmm/amd/svm_support.S
==
--- head/sys/amd64/vmm/amd/svm_support.SMon Feb 12 14:44:21 2018
(r329161)
+++ head/sys/amd64/vmm/amd/svm_support.SMon Feb 12 14:45:27 2018
(r329162)
@@ -113,6 +113,23 @@ ENTRY(svm_launch)
movq %rdi, SCTX_RDI(%rax)
movq %rsi, SCTX_RSI(%rax)
 
+   /*
+* To prevent malicious branch target predictions from
+* affecting the host, overwrite all entries in the RSB upon
+* exiting a guest.
+*/
+   mov $16, %ecx   /* 16 iterations, two calls per loop */
+   mov %rsp, %rax
+0: call 2f /* create an RSB entry. */
+1: pause
+   call 1b /* capture rogue speculation. */
+2: call 2f /* create an RSB entry. */
+1: pause
+   call 1b /* capture rogue speculation. */
+2: sub $1, %ecx
+   jnz 0b
+   mov %rax, %rsp
+
/* Restore host state */
pop %r15
pop %r14

Modified: head/sys/amd64/vmm/intel/vmcs.c
==
--- head/sys/amd64/vmm/intel/vmcs.c Mon Feb 12 14:44:21 2018
(r329161)
+++ head/sys/amd64/vmm/intel/vmcs.c Mon Feb 12 14:45:27 2018
(r329162)
@@ -34,6 +34,7 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#include 
 #include 
 #include 
 
@@ -52,6 +53,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #endif
 
+SYSCTL_DECL(_hw_vmm_vmx);
+
+static int no_flush_rsb;
+SYSCTL_INT(_hw_vmm_vmx, OID_AUTO, no_flush_rsb, CTLFLAG_RW,
+_flush_rsb, 0, "Do not flush RSB upon vmexit");
+
 static uint64_t
 vmcs_fix_regval(uint32_t encoding, uint64_t val)
 {
@@ -403,8 +410,15 @@ vmcs_init(struct vmcs *vmcs)
goto done;
 
/* instruction pointer */
-   if ((error = vmwrite(VMCS_HOST_RIP, (u_long)vmx_exit_guest)) != 0)
-   goto done;
+   if (no_flush_rsb) {
+   if ((error = vmwrite(VMCS_HOST_RIP,
+   (u_long)vmx_exit_guest)) != 0)
+   goto done;
+   } else {
+   if ((error = vmwrite(VMCS_HOST_RIP,
+   (u_long)vmx_exit_guest_flush_rsb)) != 0)
+   goto done;
+   }
 
/* link pointer */
if ((error = vmwrite(VMCS_LINK_POINTER, ~0)) != 0)

Modified: head/sys/amd64/vmm/intel/vmx.h
==
--- head/sys/amd64/vmm/intel/vmx.h  Mon Feb 12 14:44:21 2018
(r329161)
+++ head/sys/amd64/vmm/intel/vmx.h  Mon Feb 12 14:45:27 2018
(r329162)
@@ -150,5 +150,6 @@ u_long  vmx_fix_cr4(u_long cr4);
 intvmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset);
 
 extern charvmx_exit_guest[];
+extern charvmx_exit_guest_flush_rsb[];
 
 #endif

Modified: head/sys/amd64/vmm/intel/vmx_support.S
==
--- head/sys/amd64/vmm/intel/vmx_support.S  Mon Feb 12 14:44:21 2018
(r329161)
+++ head/sys/amd64/vmm/intel/vmx_support.S  Mon Feb 12 14:45:27 2018
(r329162)
@@ -42,6 +42,29 @@
 #define VLEAVE  pop %rbp
 
 /*
+ * Save the guest context.
+ */
+#defineVMX_GUEST_SAVE  
\
+   movq%rdi,VMXCTX_GUEST_RDI(%rsp);\
+   movq%rsi,VMXCTX_GUEST_RSI(%rsp);\
+   movq%rdx,VMXCTX_GUEST_RDX(%rsp);\
+   movq%rcx,VMXCTX_GUEST_RCX(%rsp);\
+   movq%r8,VMXCTX_GUEST_R8(%rsp);  \
+   movq%r9,VMXCTX_GUEST_R9(%rsp);  \
+   movq%rax,VMXCTX_GUEST_RAX(%rsp);\
+   movq%rbx,VMXCTX_GUEST_RBX(%rsp);\
+   movq%rbp,VMXCTX_GUEST_RBP(%rsp);\
+   movq%r10,VMXCTX_GUEST_R10(%rsp);\
+   movq%r11,VMXCTX_GUEST_R11(%rsp);\
+   movq%r12,VMXCTX_GUEST_R12(%rsp);\
+   movq

svn commit: r328011 - in head/sys/amd64/vmm: amd intel

2018-01-15 Thread Tycho Nightingale
Author: tychon
Date: Mon Jan 15 18:37:03 2018
New Revision: 328011
URL: https://svnweb.freebsd.org/changeset/base/328011

Log:
  Provide some mitigation against CVE-2017-5715 by clearing registers
  upon returning from the guest which aren't immediately clobbered by
  the host.  This eradicates any remaining guest contents limiting their
  usefulness in an exploit gadget.
  
  This was inspired by this linux commit:
  
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5b6c02f38315b720c593c6079364855d276886aa
  
  Reviewed by:  grehan, rgrimes
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D13573

Modified:
  head/sys/amd64/vmm/amd/svm_support.S
  head/sys/amd64/vmm/intel/vmx_support.S

Modified: head/sys/amd64/vmm/amd/svm_support.S
==
--- head/sys/amd64/vmm/amd/svm_support.SMon Jan 15 18:20:15 2018
(r328010)
+++ head/sys/amd64/vmm/amd/svm_support.SMon Jan 15 18:37:03 2018
(r328011)
@@ -124,8 +124,20 @@ ENTRY(svm_launch)
pop %rdx
mov %edx, %eax
shr $32, %rdx
-   mov $MSR_GSBASE, %ecx
+   mov $MSR_GSBASE, %rcx
wrmsr
+
+   /*
+* Clobber the remaining registers with guest contents so they
+* can't be misused.
+*/
+   xor %rbp, %rbp
+   xor %rdi, %rdi
+   xor %rsi, %rsi
+   xor %r8, %r8
+   xor %r9, %r9
+   xor %r10, %r10
+   xor %r11, %r11
 
VLEAVE
ret

Modified: head/sys/amd64/vmm/intel/vmx_support.S
==
--- head/sys/amd64/vmm/intel/vmx_support.S  Mon Jan 15 18:20:15 2018
(r328010)
+++ head/sys/amd64/vmm/intel/vmx_support.S  Mon Jan 15 18:37:03 2018
(r328011)
@@ -72,6 +72,20 @@
movqVMXCTX_GUEST_RDI(%rdi),%rdi; /* restore rdi the last */
 
 /*
+ * Clobber the remaining registers with guest contents so they can't
+ * be misused.
+ */
+#defineVMX_GUEST_CLOBBER   
\
+   xor %rax, %rax; \
+   xor %rcx, %rcx; \
+   xor %rdx, %rdx; \
+   xor %rsi, %rsi; \
+   xor %r8, %r8;   \
+   xor %r9, %r9;   \
+   xor %r10, %r10; \
+   xor %r11, %r11;
+
+/*
  * Save and restore the host context.
  *
  * Assumes that %rdi holds a pointer to the 'vmxctx'.
@@ -231,6 +245,8 @@ vmx_exit_guest:
LK btrl %r10d, PM_ACTIVE(%r11)
 
VMX_HOST_RESTORE
+
+   VMX_GUEST_CLOBBER
 
/*
 * This will return to the caller of 'vmx_enter_guest()' with a return
___
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: r327065 - head/sys/amd64/vmm/intel

2017-12-21 Thread Tycho Nightingale
Author: tychon
Date: Thu Dec 21 18:30:11 2017
New Revision: 327065
URL: https://svnweb.freebsd.org/changeset/base/327065

Log:
  Recognize a pending virtual interrupt while emulating the halt instruction.
  
  Reviewed by:  grehan, rgrimes
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D13573

Modified:
  head/sys/amd64/vmm/intel/vmx.c

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Thu Dec 21 16:25:33 2017
(r327064)
+++ head/sys/amd64/vmm/intel/vmx.c  Thu Dec 21 18:30:11 2017
(r327065)
@@ -3174,9 +3174,29 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr)
pir_desc = vlapic_vtx->pir_desc;
 
pending = atomic_load_acq_long(_desc->pending);
-   if (!pending)
-   return (0); /* common case */
+   if (!pending) {
+   /*
+* While a virtual interrupt may have already been
+* processed the actual delivery maybe pending the
+* interruptibility of the guest.  Recognize a pending
+* interrupt by reevaluating virtual interrupts
+* following Section 29.2.1 in the Intel SDM Volume 3.
+*/
+   uint64_t val;
+   uint8_t rvi, ppr;
 
+   vmx_getreg(vlapic_vtx->vmx, vlapic->vcpuid,
+   VMCS_IDENT(VMCS_GUEST_INTR_STATUS), );
+   rvi = val & APIC_TPR_INT;
+   lapic = vlapic->apic_page;
+   ppr = lapic->ppr & APIC_TPR_INT;
+   if (rvi > ppr) {
+   return (1);
+   }
+
+   return (0);
+   }
+
/*
 * If there is an interrupt pending then it will be recognized only
 * if its priority is greater than the processor priority.
@@ -3185,7 +3205,7 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr)
 * interrupt will be recognized.
 */
lapic = vlapic->apic_page;
-   ppr = lapic->ppr & 0xf0;
+   ppr = lapic->ppr & APIC_TPR_INT;
if (ppr == 0)
return (1);
 
@@ -3195,7 +3215,7 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr)
for (i = 3; i >= 0; i--) {
pirval = pir_desc->pir[i];
if (pirval != 0) {
-   vpr = (i * 64 + flsl(pirval) - 1) & 0xf0;
+   vpr = (i * 64 + flsl(pirval) - 1) & APIC_TPR_INT;
return (vpr > ppr);
}
}
___
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: r316304 - head/lib/libprocstat

2017-03-30 Thread Tycho Nightingale
Author: tychon
Date: Thu Mar 30 20:42:16 2017
New Revision: 316304
URL: https://svnweb.freebsd.org/changeset/base/316304

Log:
  Reorder includes to placate MIPS build.
  
  Reported by:  markj
  Sponsored by: Dell EMC Isilon

Modified:
  head/lib/libprocstat/libprocstat.c

Modified: head/lib/libprocstat/libprocstat.c
==
--- head/lib/libprocstat/libprocstat.c  Thu Mar 30 20:18:34 2017
(r316303)
+++ head/lib/libprocstat/libprocstat.c  Thu Mar 30 20:42:16 2017
(r316304)
@@ -63,10 +63,10 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #define_KERNEL
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
___
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: r316286 - in head: lib/libprocstat sys/kern sys/sys usr.bin/gcore usr.bin/procstat

2017-03-30 Thread Tycho Nightingale

Additionally:

Differential Revision:  https://reviews.freebsd.org/D9995

Tycho

> On Mar 30, 2017, at 2:21 PM, Tycho Nightingale <tyc...@freebsd.org> wrote:
> 
> Author: tychon
> Date: Thu Mar 30 18:21:36 2017
> New Revision: 316286
> URL: https://svnweb.freebsd.org/changeset/base/316286
> 
> Log:
>  Add support for capturing 'struct ptrace_lwpinfo' for signals
>  resulting in a process dumping core in the corefile.
> 
>  Also extend procstat to view select members of 'struct ptrace_lwpinfo'
>  from the contents of the note.
> 
>  Sponsored by:Dell EMC Isilon
> 
> Added:
>  head/usr.bin/procstat/procstat_ptlwpinfo.c   (contents, props changed)
> Modified:
>  head/lib/libprocstat/Symbol.map
>  head/lib/libprocstat/core.c
>  head/lib/libprocstat/core.h
>  head/lib/libprocstat/libprocstat.c
>  head/lib/libprocstat/libprocstat.h
>  head/sys/kern/imgact_elf.c
>  head/sys/kern/kern_sig.c
>  head/sys/kern/sys_process.c
>  head/sys/sys/elf_common.h
>  head/sys/sys/proc.h
>  head/usr.bin/gcore/elfcore.c
>  head/usr.bin/procstat/Makefile
>  head/usr.bin/procstat/procstat.1
>  head/usr.bin/procstat/procstat.c
>  head/usr.bin/procstat/procstat.h
> 
> Modified: head/lib/libprocstat/Symbol.map
> ==
> --- head/lib/libprocstat/Symbol.map   Thu Mar 30 18:20:04 2017
> (r316285)
> +++ head/lib/libprocstat/Symbol.map   Thu Mar 30 18:21:36 2017
> (r316286)
> @@ -36,3 +36,8 @@ FBSD_1.3 {
>   procstat_getvmmap;
>   procstat_open_core;
> };
> +
> +FBSD_1.5 {
> + procstat_freeptlwpinfo;
> + procstat_getptlwpinfo;
> +};
> 
> Modified: head/lib/libprocstat/core.c
> ==
> --- head/lib/libprocstat/core.c   Thu Mar 30 18:20:04 2017
> (r316285)
> +++ head/lib/libprocstat/core.c   Thu Mar 30 18:21:36 2017
> (r316286)
> @@ -1,5 +1,6 @@
> /*-
>  * Copyright (c) 2013 Mikolaj Golub <troc...@freebsd.org>
> + * Copyright (c) 2017 Dell EMC
>  * All rights reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
> @@ -30,6 +31,7 @@ __FBSDID("$FreeBSD$");
> #include 
> #include 
> #include 
> +#include 
> #include 
> 
> #include 
> @@ -56,6 +58,24 @@ struct procstat_core
>   GElf_Phdr   pc_phdr;
> };
> 
> +static struct psc_type_info {
> + unsigned intn_type;
> + int structsize;
> +} psc_type_info[PSC_TYPE_MAX] = {
> + { .n_type  = NT_PROCSTAT_PROC, .structsize = sizeof(struct kinfo_proc) 
> },
> + { .n_type = NT_PROCSTAT_FILES, .structsize = sizeof(struct kinfo_file) 
> },
> + { .n_type = NT_PROCSTAT_VMMAP, .structsize = sizeof(struct 
> kinfo_vmentry) },
> + { .n_type = NT_PROCSTAT_GROUPS, .structsize = sizeof(gid_t) },
> + { .n_type = NT_PROCSTAT_UMASK, .structsize = sizeof(u_short) },
> + { .n_type = NT_PROCSTAT_RLIMIT, .structsize = sizeof(struct rlimit) * 
> RLIM_NLIMITS },
> + { .n_type = NT_PROCSTAT_OSREL, .structsize = sizeof(int) },
> + { .n_type = NT_PROCSTAT_PSSTRINGS, .structsize = sizeof(vm_offset_t) },
> + { .n_type = NT_PROCSTAT_PSSTRINGS, .structsize = sizeof(vm_offset_t) },
> + { .n_type = NT_PROCSTAT_PSSTRINGS, .structsize = sizeof(vm_offset_t) },
> + { .n_type = NT_PROCSTAT_AUXV, .structsize = sizeof(Elf_Auxinfo) },
> + { .n_type = NT_PTLWPINFO, .structsize = sizeof(struct ptrace_lwpinfo) },
> +};
> +
> static bool   core_offset(struct procstat_core *core, off_t offset);
> static bool   core_read(struct procstat_core *core, void *buf, size_t len);
> static ssize_tcore_read_mem(struct procstat_core *core, void *buf,
> @@ -154,59 +174,20 @@ procstat_core_get(struct procstat_core *
>   off_t offset, eoffset;
>   vm_offset_t psstrings;
>   void *freebuf;
> - size_t len;
> - u_int32_t n_type;
> - int cstructsize, structsize;
> + size_t len, curlen;
> + int cstructsize;
>   char nbuf[8];
> 
>   assert(core->pc_magic == PROCSTAT_CORE_MAGIC);
> 
> - switch(type) {
> - case PSC_TYPE_PROC:
> - n_type = NT_PROCSTAT_PROC;
> - structsize = sizeof(struct kinfo_proc);
> - break;
> - case PSC_TYPE_FILES:
> - n_type = NT_PROCSTAT_FILES;
> - structsize = sizeof(struct kinfo_file);
> - break;
> - case PSC_TYPE_VMMAP:
> - n_type = NT_PROCSTAT_VMMAP;
> - structsize = sizeof(struct kinfo_vmentry);
> - break;
> - case PSC_TYPE_GROUPS:
> -  

svn commit: r316286 - in head: lib/libprocstat sys/kern sys/sys usr.bin/gcore usr.bin/procstat

2017-03-30 Thread Tycho Nightingale
Author: tychon
Date: Thu Mar 30 18:21:36 2017
New Revision: 316286
URL: https://svnweb.freebsd.org/changeset/base/316286

Log:
  Add support for capturing 'struct ptrace_lwpinfo' for signals
  resulting in a process dumping core in the corefile.
  
  Also extend procstat to view select members of 'struct ptrace_lwpinfo'
  from the contents of the note.
  
  Sponsored by: Dell EMC Isilon

Added:
  head/usr.bin/procstat/procstat_ptlwpinfo.c   (contents, props changed)
Modified:
  head/lib/libprocstat/Symbol.map
  head/lib/libprocstat/core.c
  head/lib/libprocstat/core.h
  head/lib/libprocstat/libprocstat.c
  head/lib/libprocstat/libprocstat.h
  head/sys/kern/imgact_elf.c
  head/sys/kern/kern_sig.c
  head/sys/kern/sys_process.c
  head/sys/sys/elf_common.h
  head/sys/sys/proc.h
  head/usr.bin/gcore/elfcore.c
  head/usr.bin/procstat/Makefile
  head/usr.bin/procstat/procstat.1
  head/usr.bin/procstat/procstat.c
  head/usr.bin/procstat/procstat.h

Modified: head/lib/libprocstat/Symbol.map
==
--- head/lib/libprocstat/Symbol.map Thu Mar 30 18:20:04 2017
(r316285)
+++ head/lib/libprocstat/Symbol.map Thu Mar 30 18:21:36 2017
(r316286)
@@ -36,3 +36,8 @@ FBSD_1.3 {
procstat_getvmmap;
procstat_open_core;
 };
+
+FBSD_1.5 {
+   procstat_freeptlwpinfo;
+   procstat_getptlwpinfo;
+};

Modified: head/lib/libprocstat/core.c
==
--- head/lib/libprocstat/core.c Thu Mar 30 18:20:04 2017(r316285)
+++ head/lib/libprocstat/core.c Thu Mar 30 18:21:36 2017(r316286)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2013 Mikolaj Golub 
+ * Copyright (c) 2017 Dell EMC
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,6 +31,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -56,6 +58,24 @@ struct procstat_core
GElf_Phdr   pc_phdr;
 };
 
+static struct psc_type_info {
+   unsigned intn_type;
+   int structsize;
+} psc_type_info[PSC_TYPE_MAX] = {
+   { .n_type  = NT_PROCSTAT_PROC, .structsize = sizeof(struct kinfo_proc) 
},
+   { .n_type = NT_PROCSTAT_FILES, .structsize = sizeof(struct kinfo_file) 
},
+   { .n_type = NT_PROCSTAT_VMMAP, .structsize = sizeof(struct 
kinfo_vmentry) },
+   { .n_type = NT_PROCSTAT_GROUPS, .structsize = sizeof(gid_t) },
+   { .n_type = NT_PROCSTAT_UMASK, .structsize = sizeof(u_short) },
+   { .n_type = NT_PROCSTAT_RLIMIT, .structsize = sizeof(struct rlimit) * 
RLIM_NLIMITS },
+   { .n_type = NT_PROCSTAT_OSREL, .structsize = sizeof(int) },
+   { .n_type = NT_PROCSTAT_PSSTRINGS, .structsize = sizeof(vm_offset_t) },
+   { .n_type = NT_PROCSTAT_PSSTRINGS, .structsize = sizeof(vm_offset_t) },
+   { .n_type = NT_PROCSTAT_PSSTRINGS, .structsize = sizeof(vm_offset_t) },
+   { .n_type = NT_PROCSTAT_AUXV, .structsize = sizeof(Elf_Auxinfo) },
+   { .n_type = NT_PTLWPINFO, .structsize = sizeof(struct ptrace_lwpinfo) },
+};
+
 static boolcore_offset(struct procstat_core *core, off_t offset);
 static boolcore_read(struct procstat_core *core, void *buf, size_t len);
 static ssize_t core_read_mem(struct procstat_core *core, void *buf,
@@ -154,59 +174,20 @@ procstat_core_get(struct procstat_core *
off_t offset, eoffset;
vm_offset_t psstrings;
void *freebuf;
-   size_t len;
-   u_int32_t n_type;
-   int cstructsize, structsize;
+   size_t len, curlen;
+   int cstructsize;
char nbuf[8];
 
assert(core->pc_magic == PROCSTAT_CORE_MAGIC);
 
-   switch(type) {
-   case PSC_TYPE_PROC:
-   n_type = NT_PROCSTAT_PROC;
-   structsize = sizeof(struct kinfo_proc);
-   break;
-   case PSC_TYPE_FILES:
-   n_type = NT_PROCSTAT_FILES;
-   structsize = sizeof(struct kinfo_file);
-   break;
-   case PSC_TYPE_VMMAP:
-   n_type = NT_PROCSTAT_VMMAP;
-   structsize = sizeof(struct kinfo_vmentry);
-   break;
-   case PSC_TYPE_GROUPS:
-   n_type = NT_PROCSTAT_GROUPS;
-   structsize = sizeof(gid_t);
-   break;
-   case PSC_TYPE_UMASK:
-   n_type = NT_PROCSTAT_UMASK;
-   structsize = sizeof(u_short);
-   break;
-   case PSC_TYPE_RLIMIT:
-   n_type = NT_PROCSTAT_RLIMIT;
-   structsize = sizeof(struct rlimit) * RLIM_NLIMITS;
-   break;
-   case PSC_TYPE_OSREL:
-   n_type = NT_PROCSTAT_OSREL;
-   structsize = sizeof(int);
-   break;
-   case PSC_TYPE_PSSTRINGS:
-   case PSC_TYPE_ARGV:
-   case PSC_TYPE_ENVV:
-   n_type = NT_PROCSTAT_PSSTRINGS;
-   structsize = 

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

2015-06-26 Thread Tycho Nightingale
Author: tychon
Date: Fri Jun 26 18:00:29 2015
New Revision: 284877
URL: https://svnweb.freebsd.org/changeset/base/284877

Log:
  verify_gla() needs to account for non-zero segment base addresses.
  
  Reviewed by:  neel

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

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Fri Jun 26 17:13:23 2015
(r284876)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Fri Jun 26 18:00:29 2015
(r284877)
@@ -2321,10 +2321,13 @@ decode_moffset(struct vie *vie)
  * page table fault matches with our instruction decoding.
  */
 static int
-verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie)
+verify_gla(struct vm *vm, int cpuid, uint64_t gla, struct vie *vie,
+enum vm_cpu_mode cpu_mode)
 {
int error;
-   uint64_t base, idx, gla2;
+   uint64_t base, segbase, idx, gla2;
+   enum vm_reg_name seg;
+   struct seg_desc desc;
 
/* Skip 'gla' verification */
if (gla == VIE_INVALID_GLA)
@@ -2357,14 +2360,48 @@ verify_gla(struct vm *vm, int cpuid, uin
}
}
 
-   /* XXX assuming that the base address of the segment is 0 */
-   gla2 = base + vie-scale * idx + vie-displacement;
+   /*
+* From Specifying a Segment Selector, Intel SDM, Vol 1
+*
+* In 64-bit mode, segmentation is generally (but not
+* completely) disabled.  The exceptions are the FS and GS
+* segments.
+*
+* In legacy IA-32 mode, when the ESP or EBP register is used
+* as the base, the SS segment is the default segment.  For
+* other data references, except when relative to stack or
+* string destination the DS segment is the default.  These
+* can be overridden to allow other segments to be accessed.
+*/
+   if (vie-segment_override)
+   seg = vie-segment_register;
+   else if (vie-base_register == VM_REG_GUEST_RSP ||
+   vie-base_register == VM_REG_GUEST_RBP)
+   seg = VM_REG_GUEST_SS;
+   else
+   seg = VM_REG_GUEST_DS;
+   if (cpu_mode == CPU_MODE_64BIT  seg != VM_REG_GUEST_FS 
+   seg != VM_REG_GUEST_GS) {
+   segbase = 0;
+   } else {
+   error = vm_get_seg_desc(vm, cpuid, seg, desc);
+   if (error) {
+   printf(verify_gla: error %d getting segment
+   descriptor %d, error,
+  vie-segment_register);
+   return (-1);
+   }
+   segbase = desc.base;
+   }
+
+   gla2 = segbase + base + vie-scale * idx + vie-displacement;
gla2 = size2mask[vie-addrsize];
if (gla != gla2) {
-   printf(verify_gla mismatch: 
+   printf(verify_gla mismatch: segbase(0x%0lx)
   base(0x%0lx), scale(%d), index(0x%0lx), 
   disp(0x%0lx), gla(0x%0lx), gla2(0x%0lx)\n,
-  base, vie-scale, idx, vie-displacement, gla, gla2);
+  segbase, base, vie-scale, idx, vie-displacement,
+  gla, gla2);
return (-1);
}
 
@@ -2398,7 +2435,7 @@ vmm_decode_instruction(struct vm *vm, in
return (-1);
 
if ((vie-op.op_flags  VIE_OP_F_NO_GLA_VERIFICATION) == 0) {
-   if (verify_gla(vm, cpuid, gla, vie))
+   if (verify_gla(vm, cpuid, gla, vie, cpu_mode))
return (-1);
}
 
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r284174 - head/sys/amd64/vmm/intel

2015-06-08 Thread Tycho Nightingale
Author: tychon
Date: Tue Jun  9 00:14:47 2015
New Revision: 284174
URL: https://svnweb.freebsd.org/changeset/base/284174

Log:
  Support guest writes to the TSC by enabling the use TSC offsetting
  execution control and writing the difference between the host TSC and
  the guest TSC into the TSC offset in the VMCS upon encountering a
  write.
  
  Reviewed by:  neel

Modified:
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/amd64/vmm/intel/vmx.h
  head/sys/amd64/vmm/intel/vmx_msr.c

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Mon Jun  8 23:37:17 2015
(r284173)
+++ head/sys/amd64/vmm/intel/vmx.c  Tue Jun  9 00:14:47 2015
(r284174)
@@ -856,10 +856,11 @@ vmx_vminit(struct vm *vm, pmap_t pmap)
 * VM exit and entry respectively. It is also restored from the
 * host VMCS area on a VM exit.
 *
-* The TSC MSR is exposed read-only. Writes are disallowed as that
-* will impact the host TSC.
-* XXX Writes would be implemented with a wrmsr trap, and
-* then modifying the TSC offset in the VMCS.
+* The TSC MSR is exposed read-only. Writes are disallowed as
+* that will impact the host TSC.  If the guest does a write
+* the use TSC offsetting execution control is enabled and the
+* difference between the host TSC and the guest TSC is written
+* into the TSC offset in the VMCS.
 */
if (guest_msr_rw(vmx, MSR_GSBASE) ||
guest_msr_rw(vmx, MSR_FSBASE) ||
@@ -1130,6 +1131,22 @@ vmx_clear_nmi_window_exiting(struct vmx 
VCPU_CTR0(vmx-vm, vcpu, Disabling NMI window exiting);
 }
 
+int
+vmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset)
+{
+   int error;
+
+   if ((vmx-cap[vcpu].proc_ctls  PROCBASED_TSC_OFFSET) == 0) {
+   vmx-cap[vcpu].proc_ctls |= PROCBASED_TSC_OFFSET;
+   vmcs_write(VMCS_PRI_PROC_BASED_CTLS, vmx-cap[vcpu].proc_ctls);
+   VCPU_CTR0(vmx-vm, vcpu, Enabling TSC offsetting);
+   }
+
+   error = vmwrite(VMCS_TSC_OFFSET, offset);
+
+   return (error);
+}
+
 #defineNMI_BLOCKING(VMCS_INTERRUPTIBILITY_NMI_BLOCKING |   
\
 VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING)
 #defineHWINTR_BLOCKING (VMCS_INTERRUPTIBILITY_STI_BLOCKING |   
\

Modified: head/sys/amd64/vmm/intel/vmx.h
==
--- head/sys/amd64/vmm/intel/vmx.h  Mon Jun  8 23:37:17 2015
(r284173)
+++ head/sys/amd64/vmm/intel/vmx.h  Tue Jun  9 00:14:47 2015
(r284174)
@@ -135,6 +135,8 @@ voidvmx_call_isr(uintptr_t entry);
 u_long vmx_fix_cr0(u_long cr0);
 u_long vmx_fix_cr4(u_long cr4);
 
+intvmx_set_tsc_offset(struct vmx *vmx, int vcpu, uint64_t offset);
+
 extern charvmx_exit_guest[];
 
 #endif

Modified: head/sys/amd64/vmm/intel/vmx_msr.c
==
--- head/sys/amd64/vmm/intel/vmx_msr.c  Mon Jun  8 23:37:17 2015
(r284173)
+++ head/sys/amd64/vmm/intel/vmx_msr.c  Tue Jun  9 00:14:47 2015
(r284174)
@@ -474,6 +474,9 @@ vmx_wrmsr(struct vmx *vmx, int vcpuid, u
else
vm_inject_gp(vmx-vm, vcpuid);
break;
+   case MSR_TSC:
+   error = vmx_set_tsc_offset(vmx, vcpuid, val - rdtsc());
+   break;
default:
error = EINVAL;
break;
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2015-05-21 Thread Tycho Nightingale
Author: tychon
Date: Thu May 21 20:11:52 2015
New Revision: 283264
URL: https://svnweb.freebsd.org/changeset/base/283264

Log:
  The 'hostbridge' device exists to allow guests to infer msi/msix
  capablity by advertising pcie capability.
  
  Since the 'hostbridge' device isn't a true pci-to-pci bridge, and
  doesn't actaully use the bridge configuration space layout, change
  the header-type from type 1 to type 0 to avoid confusion.
  
  Reviewed by:  neel

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

Modified: head/usr.sbin/bhyve/pci_hostbridge.c
==
--- head/usr.sbin/bhyve/pci_hostbridge.cThu May 21 20:09:36 2015
(r283263)
+++ head/usr.sbin/bhyve/pci_hostbridge.cThu May 21 20:11:52 2015
(r283264)
@@ -38,7 +38,7 @@ pci_hostbridge_init(struct vmctx *ctx, s
/* config space */
pci_set_cfgdata16(pi, PCIR_VENDOR, 0x1275); /* NetApp */
pci_set_cfgdata16(pi, PCIR_DEVICE, 0x1275); /* NetApp */
-   pci_set_cfgdata8(pi, PCIR_HDRTYPE, PCIM_HDRTYPE_BRIDGE);
+   pci_set_cfgdata8(pi, PCIR_HDRTYPE, PCIM_HDRTYPE_NORMAL);
pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_BRIDGE);
pci_set_cfgdata8(pi, PCIR_SUBCLASS, PCIS_BRIDGE_HOST);
 
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2015-04-25 Thread Tycho Nightingale
Author: tychon
Date: Sat Apr 25 19:02:06 2015
New Revision: 281987
URL: https://svnweb.freebsd.org/changeset/base/281987

Log:
  STOS/STOSB/STOSW/STOSD/STOSQ instruction emulation.
  
  Reviewed by:  neel

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

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Sat Apr 25 18:17:08 2015
(r281986)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Sat Apr 25 19:02:06 2015
(r281987)
@@ -72,6 +72,7 @@ enum {
VIE_OP_TYPE_POP,
VIE_OP_TYPE_MOVS,
VIE_OP_TYPE_GROUP1,
+   VIE_OP_TYPE_STOS,
VIE_OP_TYPE_LAST
 };
 
@@ -146,6 +147,16 @@ static const struct vie_op one_byte_opco
.op_type = VIE_OP_TYPE_MOVS,
.op_flags = VIE_OP_F_NO_MODRM | VIE_OP_F_NO_GLA_VERIFICATION
},
+   [0xAA] = {
+   .op_byte = 0xAA,
+   .op_type = VIE_OP_TYPE_STOS,
+   .op_flags = VIE_OP_F_NO_MODRM | VIE_OP_F_NO_GLA_VERIFICATION
+   },
+   [0xAB] = {
+   .op_byte = 0xAB,
+   .op_type = VIE_OP_TYPE_STOS,
+   .op_flags = VIE_OP_F_NO_MODRM | VIE_OP_F_NO_GLA_VERIFICATION
+   },
[0xC6] = {
/* XXX Group 11 extended opcode - not just MOV */
.op_byte = 0xC6,
@@ -803,6 +814,68 @@ done:
 }
 
 static int
+emulate_stos(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+struct vm_guest_paging *paging, mem_region_read_t memread,
+mem_region_write_t memwrite, void *arg)
+{
+   int error, opsize, repeat;
+   uint64_t val;
+   uint64_t rcx, rdi, rflags;
+
+   opsize = (vie-op.op_byte == 0xAA) ? 1 : vie-opsize;
+   repeat = vie-repz_present | vie-repnz_present;
+
+   if (repeat) {
+   error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RCX, rcx);
+   KASSERT(!error, (%s: error %d getting rcx, __func__, error));
+
+   /*
+* The count register is %rcx, %ecx or %cx depending on the
+* address size of the instruction.
+*/
+   if ((rcx  vie_size2mask(vie-addrsize)) == 0)
+   return (0);
+   }
+
+   error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RAX, val);
+   KASSERT(!error, (%s: error %d getting rax, __func__, error));
+
+   error = memwrite(vm, vcpuid, gpa, val, opsize, arg);
+   if (error)
+   return (error);
+
+   error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RDI, rdi);
+   KASSERT(error == 0, (%s: error %d getting rdi, __func__, error));
+
+   error = vie_read_register(vm, vcpuid, VM_REG_GUEST_RFLAGS, rflags);
+   KASSERT(error == 0, (%s: error %d getting rflags, __func__, error));
+
+   if (rflags  PSL_D)
+   rdi -= opsize;
+   else
+   rdi += opsize;
+
+   error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RDI, rdi,
+   vie-addrsize);
+   KASSERT(error == 0, (%s: error %d updating rdi, __func__, error));
+
+   if (repeat) {
+   rcx = rcx - 1;
+   error = vie_update_register(vm, vcpuid, VM_REG_GUEST_RCX,
+   rcx, vie-addrsize);
+   KASSERT(!error, (%s: error %d updating rcx, __func__, error));
+
+   /*
+* Repeat the instruction if the count register is not zero.
+*/
+   if ((rcx  vie_size2mask(vie-addrsize)) != 0)
+   vm_restart_instruction(vm, vcpuid);
+   }
+
+   return (0);
+}
+
+static int
 emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
 {
@@ -1302,6 +1375,10 @@ vmm_emulate_instruction(void *vm, int vc
error = emulate_movs(vm, vcpuid, gpa, vie, paging, memread,
memwrite, memarg);
break;
+   case VIE_OP_TYPE_STOS:
+   error = emulate_stos(vm, vcpuid, gpa, vie, paging, memread,
+   memwrite, memarg);
+   break;
case VIE_OP_TYPE_AND:
error = emulate_and(vm, vcpuid, gpa, vie,
memread, memwrite, memarg);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2015-04-15 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr 15 18:49:03 2015
New Revision: 281561
URL: https://svnweb.freebsd.org/changeset/base/281561

Log:
  Prior to aborting due to an ioport error, it is always interesting to
  see what the guest's %rip is.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/bhyverun.c
==
--- head/usr.sbin/bhyve/bhyverun.c  Wed Apr 15 16:52:34 2015
(r281560)
+++ head/usr.sbin/bhyve/bhyverun.c  Wed Apr 15 18:49:03 2015
(r281561)
@@ -325,8 +325,10 @@ vmexit_inout(struct vmctx *ctx, struct v
 
error = emulate_inout(ctx, vcpu, vme, strictio);
if (error) {
-   fprintf(stderr, Unhandled %s%c 0x%04x\n, in ? in : out,
-   bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port);
+   fprintf(stderr, Unhandled %s%c 0x%04x at 0x%lx\n,
+   in ? in : out,
+   bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'),
+   port, vmexit-rip);
return (VMEXIT_ABORT);
} else {
return (VMEXIT_CONTINUE);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2015-04-06 Thread Tycho Nightingale
Author: tychon
Date: Mon Apr  6 12:22:41 2015
New Revision: 281145
URL: https://svnweb.freebsd.org/changeset/base/281145

Log:
  Enhance the support for Group 1 Extended opcodes:
  
* Implemement the 0x81 and 0x83 CMP instructions.
* Implemement the 0x83 AND instruction.
* Implemement the 0x81 OR instruction.
  
  Reviewed by:  neel

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

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Mon Apr  6 09:52:16 2015
(r281144)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Mon Apr  6 12:22:41 2015
(r281145)
@@ -71,6 +71,7 @@ enum {
VIE_OP_TYPE_CMP,
VIE_OP_TYPE_POP,
VIE_OP_TYPE_MOVS,
+   VIE_OP_TYPE_GROUP1,
VIE_OP_TYPE_LAST
 };
 
@@ -161,15 +162,15 @@ static const struct vie_op one_byte_opco
.op_type = VIE_OP_TYPE_AND,
},
[0x81] = {
-   /* XXX Group 1 extended opcode - not just AND */
+   /* XXX Group 1 extended opcode */
.op_byte = 0x81,
-   .op_type = VIE_OP_TYPE_AND,
+   .op_type = VIE_OP_TYPE_GROUP1,
.op_flags = VIE_OP_F_IMM,
},
[0x83] = {
-   /* XXX Group 1 extended opcode - not just OR */
+   /* XXX Group 1 extended opcode */
.op_byte = 0x83,
-   .op_type = VIE_OP_TYPE_OR,
+   .op_type = VIE_OP_TYPE_GROUP1,
.op_flags = VIE_OP_F_IMM8,
},
[0x8F] = {
@@ -839,16 +840,18 @@ emulate_and(void *vm, int vcpuid, uint64
error = vie_update_register(vm, vcpuid, reg, result, size);
break;
case 0x81:
+   case 0x83:
/*
-* AND/OR mem (ModRM:r/m) with immediate and store the
+* AND mem (ModRM:r/m) with immediate and store the
 * result in mem.
 *
-* AND: i = 4
-* OR:  i = 1
-* 81 /iop r/m16, imm16
-* 81 /iop r/m32, imm32
-* REX.W + 81 /iop r/m64, imm32 sign-extended to 64
+* 81 /4and r/m16, imm16
+* 81 /4and r/m32, imm32
+* REX.W + 81 /4and r/m64, imm32 sign-extended to 64
 *
+* 83 /4and r/m16, imm8 sign-extended to 16
+* 83 /4and r/m32, imm8 sign-extended to 32
+* REX.W + 83/4 and r/m64, imm8 sign-extended to 64
 */
 
/* get the first operand */
@@ -857,26 +860,11 @@ emulate_and(void *vm, int vcpuid, uint64
break;
 
 /*
- * perform the operation with the pre-fetched immediate
- * operand and write the result
- */
-   switch (vie-reg  7) {
-   case 0x4:
-   /* modrm:reg == b100, AND */
-   result = val1  vie-immediate;
-   break;
-   case 0x1:
-   /* modrm:reg == b001, OR */
-   result = val1 | vie-immediate;
-   break;
-   default:
-   error = EINVAL;
-   break;
-   }
-   if (error)
-   break;
-
-   error = memwrite(vm, vcpuid, gpa, result, size, arg);
+* perform the operation with the pre-fetched immediate
+* operand and write the result
+*/
+result = val1  vie-immediate;
+error = memwrite(vm, vcpuid, gpa, result, size, arg);
break;
default:
break;
@@ -913,20 +901,20 @@ emulate_or(void *vm, int vcpuid, uint64_
error = EINVAL;
 
switch (vie-op.op_byte) {
+   case 0x81:
case 0x83:
/*
 * OR mem (ModRM:r/m) with immediate and store the
 * result in mem.
 *
-* 83 /1OR r/m16, imm8 sign-extended to 16
-* 83 /1OR r/m32, imm8 sign-extended to 32
-* REX.W + 83/1 OR r/m64, imm8 sign-extended to 64
+* 81 /1or r/m16, imm16
+* 81 /1or r/m32, imm32
+* REX.W + 81 /1or r/m64, imm32 sign-extended to 64
 *
-* Currently, only the OR operation of the 0x83 opcode
-* is implemented (ModRM:reg = b001).
+* 83 /1or r/m16, imm8 sign-extended to 16
+* 83 /1or r/m32, imm8 sign-extended to 32
+

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

2015-04-01 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr  1 20:36:07 2015
New Revision: 280968
URL: https://svnweb.freebsd.org/changeset/base/280968

Log:
  Prior to aborting due to an instruction emulation error, it is always
  interesting to see what the guest's %rip and instruction bytes are.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/bhyverun.c
==
--- head/usr.sbin/bhyve/bhyverun.c  Wed Apr  1 20:14:00 2015
(r280967)
+++ head/usr.sbin/bhyve/bhyverun.c  Wed Apr  1 20:36:07 2015
(r280968)
@@ -495,22 +495,27 @@ vmexit_mtrap(struct vmctx *ctx, struct v
 static int
 vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
 {
-   int err;
+   int err, i;
+   struct vie *vie;
+
stats.vmexit_inst_emul++;
 
+   vie = vmexit-u.inst_emul.vie;
err = emulate_mem(ctx, *pvcpu, vmexit-u.inst_emul.gpa,
-   vmexit-u.inst_emul.vie, vmexit-u.inst_emul.paging);
+   vie, vmexit-u.inst_emul.paging);
 
if (err) {
-   if (err == EINVAL) {
-   fprintf(stderr,
-   Failed to emulate instruction at 0x%lx\n, 
-   vmexit-rip);
-   } else if (err == ESRCH) {
+   if (err == ESRCH) {
fprintf(stderr, Unhandled memory access to 0x%lx\n,
vmexit-u.inst_emul.gpa);
}
 
+   fprintf(stderr, Failed to emulate instruction [);
+   for (i = 0; i  vie-num_valid; i++) {
+   fprintf(stderr, 0x%02x%s, vie-inst[i],
+   i != (vie-num_valid - 1) ?   : );
+   }
+   fprintf(stderr, ] at 0x%lx\n, vmexit-rip);
return (VMEXIT_ABORT);
}
 
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r280929 - in head: lib/libvmmapi sys/amd64/include sys/amd64/vmm

2015-03-31 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr  1 00:15:31 2015
New Revision: 280929
URL: https://svnweb.freebsd.org/changeset/base/280929

Log:
  Fix MOVS instruction memory to MMIO emulation.  Currently updates to
  %rdi, %rsi, etc are inadvertently bypassed along with the check to
  see if the instruction needs to be repeated per the 'rep' prefix.
  
  Add MOVS instruction support for the 'MMIO to MMIO' case.
  
  Reviewed by:  neel

Modified:
  head/lib/libvmmapi/vmmapi.c
  head/lib/libvmmapi/vmmapi.h
  head/sys/amd64/include/vmm_instruction_emul.h
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_dev.c
  head/sys/amd64/vmm/vmm_instruction_emul.c

Modified: head/lib/libvmmapi/vmmapi.c
==
--- head/lib/libvmmapi/vmmapi.c Wed Apr  1 00:00:17 2015(r280928)
+++ head/lib/libvmmapi/vmmapi.c Wed Apr  1 00:15:31 2015(r280929)
@@ -979,6 +979,18 @@ gla2gpa(struct vmctx *ctx, int vcpu, str
return (error);
 }
 
+int
+vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
+uint64_t gla, int prot, uint64_t *gpa)
+{
+   int error, fault;
+
+   error = gla2gpa(ctx, vcpu, paging, gla, prot, fault, gpa);
+   if (fault)
+   error = fault;
+   return (error);
+}
+
 #ifndef min
 #definemin(a,b)(((a)  (b)) ? (a) : (b))
 #endif

Modified: head/lib/libvmmapi/vmmapi.h
==
--- head/lib/libvmmapi/vmmapi.h Wed Apr  1 00:00:17 2015(r280928)
+++ head/lib/libvmmapi/vmmapi.h Wed Apr  1 00:15:31 2015(r280929)
@@ -63,6 +63,8 @@ int   vm_get_memory_seg(struct vmctx *ctx,
 intvm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
 void   *vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
 intvm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num);
+intvm_gla2gpa(struct vmctx *, int vcpuid, struct vm_guest_paging *paging,
+  uint64_t gla, int prot, uint64_t *gpa);
 uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
 void   vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
 void   vm_set_memflags(struct vmctx *ctx, int flags);

Modified: head/sys/amd64/include/vmm_instruction_emul.h
==
--- head/sys/amd64/include/vmm_instruction_emul.h   Wed Apr  1 00:00:17 
2015(r280928)
+++ head/sys/amd64/include/vmm_instruction_emul.h   Wed Apr  1 00:15:31 
2015(r280929)
@@ -90,7 +90,7 @@ int vmm_fetch_instruction(struct vm *vm,
  * Returns 1 if an exception was injected into the guest.
  * Returns -1 otherwise.
  */
-int vmm_gla2gpa(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
+int vm_gla2gpa(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
 uint64_t gla, int prot, uint64_t *gpa);
 
 void vie_init(struct vie *vie, const char *inst_bytes, int inst_length);

Modified: head/sys/amd64/vmm/vmm.c
==
--- head/sys/amd64/vmm/vmm.cWed Apr  1 00:00:17 2015(r280928)
+++ head/sys/amd64/vmm/vmm.cWed Apr  1 00:15:31 2015(r280929)
@@ -2332,7 +2332,7 @@ vm_copy_setup(struct vm *vm, int vcpuid,
remaining = len;
while (remaining  0) {
KASSERT(nused  num_copyinfo, (insufficient vm_copyinfo));
-   error = vmm_gla2gpa(vm, vcpuid, paging, gla, prot, gpa);
+   error = vm_gla2gpa(vm, vcpuid, paging, gla, prot, gpa);
if (error)
return (error);
off = gpa  PAGE_MASK;

Modified: head/sys/amd64/vmm/vmm_dev.c
==
--- head/sys/amd64/vmm/vmm_dev.cWed Apr  1 00:00:17 2015
(r280928)
+++ head/sys/amd64/vmm/vmm_dev.cWed Apr  1 00:15:31 2015
(r280929)
@@ -440,10 +440,10 @@ vmmdev_ioctl(struct cdev *cdev, u_long c
CTASSERT(PROT_WRITE == VM_PROT_WRITE);
CTASSERT(PROT_EXEC == VM_PROT_EXECUTE);
gg = (struct vm_gla2gpa *)data;
-   error = vmm_gla2gpa(sc-vm, gg-vcpuid, gg-paging, gg-gla,
+   error = vm_gla2gpa(sc-vm, gg-vcpuid, gg-paging, gg-gla,
gg-prot, gg-gpa);
KASSERT(error == 0 || error == 1 || error == -1,
-   (%s: vmm_gla2gpa unknown error %d, __func__, error));
+   (%s: vm_gla2gpa unknown error %d, __func__, error));
if (error = 0) {
/*
 * error = 0: the translation was successful

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Wed Apr  1 00:00:17 2015
(r280928)
+++ 

svn commit: r280447 - in head/sys/amd64: include vmm vmm/amd vmm/intel

2015-03-24 Thread Tycho Nightingale
Author: tychon
Date: Tue Mar 24 17:12:36 2015
New Revision: 280447
URL: https://svnweb.freebsd.org/changeset/base/280447

Log:
  When fetching an instruction in non-64bit mode, consider the value of the
  code segment base address.
  
  Also if an instruction doesn't support a mod R/M (modRM) byte, don't
  be concerned if the CPU is in real mode.
  
  Reviewed by:  neel

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/amd/svm.c
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_instruction_emul.c

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hTue Mar 24 16:53:16 2015
(r280446)
+++ head/sys/amd64/include/vmm.hTue Mar 24 17:12:36 2015
(r280447)
@@ -551,6 +551,7 @@ struct vm_exit {
struct {
uint64_tgpa;
uint64_tgla;
+   uint64_tcs_base;
int cs_d;   /* CS.D */
struct vm_guest_paging paging;
struct vie  vie;

Modified: head/sys/amd64/vmm/amd/svm.c
==
--- head/sys/amd64/vmm/amd/svm.cTue Mar 24 16:53:16 2015
(r280446)
+++ head/sys/amd64/vmm/amd/svm.cTue Mar 24 17:12:36 2015
(r280447)
@@ -799,8 +799,13 @@ svm_handle_inst_emul(struct vmcb *vmcb, 
KASSERT(error == 0, (%s: vmcb_seg(CS) error %d, __func__, error));
 
switch(paging-cpu_mode) {
+   case CPU_MODE_REAL:
+   vmexit-u.inst_emul.cs_base = seg.base;
+   vmexit-u.inst_emul.cs_d = 0;
case CPU_MODE_PROTECTED:
case CPU_MODE_COMPATIBILITY:
+   vmexit-u.inst_emul.cs_base = seg.base;
+
/*
 * Section 4.8.1 of APM2, Default Operand Size or D bit.
 */
@@ -808,6 +813,7 @@ svm_handle_inst_emul(struct vmcb *vmcb, 
1 : 0;
break;
default:
+   vmexit-u.inst_emul.cs_base = 0;
vmexit-u.inst_emul.cs_d = 0;
break;  
}

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Tue Mar 24 16:53:16 2015
(r280446)
+++ head/sys/amd64/vmm/intel/vmx.c  Tue Mar 24 17:12:36 2015
(r280447)
@@ -1784,12 +1784,18 @@ vmexit_inst_emul(struct vm_exit *vmexit,
vmexit-u.inst_emul.gla = gla;
vmx_paging_info(paging);
switch (paging-cpu_mode) {
+   case CPU_MODE_REAL:
+   vmexit-u.inst_emul.cs_base = vmcs_read(VMCS_GUEST_CS_BASE);
+   vmexit-u.inst_emul.cs_d = 0;
+   break;
case CPU_MODE_PROTECTED:
case CPU_MODE_COMPATIBILITY:
+   vmexit-u.inst_emul.cs_base = vmcs_read(VMCS_GUEST_CS_BASE);
csar = vmcs_read(VMCS_GUEST_CS_ACCESS_RIGHTS);
vmexit-u.inst_emul.cs_d = SEG_DESC_DEF32(csar);
break;
default:
+   vmexit-u.inst_emul.cs_base = 0;
vmexit-u.inst_emul.cs_d = 0;
break;
}

Modified: head/sys/amd64/vmm/vmm.c
==
--- head/sys/amd64/vmm/vmm.cTue Mar 24 16:53:16 2015(r280446)
+++ head/sys/amd64/vmm/vmm.cTue Mar 24 17:12:36 2015(r280447)
@@ -1251,7 +1251,7 @@ vm_handle_inst_emul(struct vm *vm, int v
struct vie *vie;
struct vcpu *vcpu;
struct vm_exit *vme;
-   uint64_t gla, gpa;
+   uint64_t gla, gpa, cs_base;
struct vm_guest_paging *paging;
mem_region_read_t mread;
mem_region_write_t mwrite;
@@ -1263,6 +1263,7 @@ vm_handle_inst_emul(struct vm *vm, int v
 
gla = vme-u.inst_emul.gla;
gpa = vme-u.inst_emul.gpa;
+   cs_base = vme-u.inst_emul.cs_base;
cs_d = vme-u.inst_emul.cs_d;
vie = vme-u.inst_emul.vie;
paging = vme-u.inst_emul.paging;
@@ -1277,8 +1278,8 @@ vm_handle_inst_emul(struct vm *vm, int v
 * maximum size instruction.
 */
length = vme-inst_length ? vme-inst_length : VIE_INST_SIZE;
-   error = vmm_fetch_instruction(vm, vcpuid, paging, vme-rip,
-   length, vie);
+   error = vmm_fetch_instruction(vm, vcpuid, paging, vme-rip +
+   cs_base, length, vie);
} else {
/*
 * The instruction bytes have already been copied into 'vie'

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Tue Mar 24 16:53:16 2015
(r280446)
+++ 

svn commit: r279683 - head/sys/amd64/vmm/io

2015-03-05 Thread Tycho Nightingale
Author: tychon
Date: Fri Mar  6 02:05:45 2015
New Revision: 279683
URL: https://svnweb.freebsd.org/changeset/base/279683

Log:
  When ICW1 is issued the edge sense circuit is reset which means that
  following an initialization a low-to-high transistion is necesary to
  generate an interrupt.
  
  Reviewed by:  neel

Modified:
  head/sys/amd64/vmm/io/vatpic.c

Modified: head/sys/amd64/vmm/io/vatpic.c
==
--- head/sys/amd64/vmm/io/vatpic.c  Fri Mar  6 00:24:21 2015
(r279682)
+++ head/sys/amd64/vmm/io/vatpic.c  Fri Mar  6 02:05:45 2015
(r279683)
@@ -275,6 +275,7 @@ vatpic_icw1(struct vatpic *vatpic, struc
atpic-ready = false;
 
atpic-icw_num = 1;
+   atpic-request = 0;
atpic-mask = 0;
atpic-lowprio = 7;
atpic-rd_cmd_reg = 0;
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-11-09 Thread Tycho Nightingale
Author: tychon
Date: Sun Nov  9 21:08:52 2014
New Revision: 274330
URL: https://svnweb.freebsd.org/changeset/base/274330

Log:
  To allow a request to be submitted from within the callback routine of
  a completing one increase the total by 1 but don't advertise it.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/block_if.c
==
--- head/usr.sbin/bhyve/block_if.c  Sun Nov  9 20:43:50 2014
(r274329)
+++ head/usr.sbin/bhyve/block_if.c  Sun Nov  9 21:08:52 2014
(r274330)
@@ -54,7 +54,7 @@ __FBSDID($FreeBSD$);
 
 #define BLOCKIF_SIG0xb109b109
 
-#define BLOCKIF_MAXREQ 32
+#define BLOCKIF_MAXREQ 33
 
 enum blockop {
BOP_READ,
@@ -600,7 +600,7 @@ blockif_queuesz(struct blockif_ctxt *bc)
 {
 
assert(bc-bc_magic == BLOCKIF_SIG);
-   return (BLOCKIF_MAXREQ);
+   return (BLOCKIF_MAXREQ - 1);
 }
 
 int
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-11-03 Thread Tycho Nightingale
Author: tychon
Date: Mon Nov  3 12:55:31 2014
New Revision: 274045
URL: https://svnweb.freebsd.org/changeset/base/274045

Log:
  If the start bit, PxCMD.ST, is cleared and nothing is in-flight then
  PxCI, PxSACT, PxCMD.CCS and PxCMD.CR should be 0.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Mon Nov  3 12:38:41 2014
(r274044)
+++ head/usr.sbin/bhyve/pci_ahci.c  Mon Nov  3 12:55:31 2014
(r274045)
@@ -367,11 +367,15 @@ ahci_check_stopped(struct ahci_port *p)
 {
/*
 * If we are no longer processing the command list and nothing
-* is in-flight, clear the running bit.
+* is in-flight, clear the running bit, the current command
+* slot, the command issue and active bits.
 */
if (!(p-cmd  AHCI_P_CMD_ST)) {
-   if (p-pending == 0)
+   if (p-pending == 0) {
p-cmd = ~(AHCI_P_CMD_CR | AHCI_P_CMD_CCS_MASK);
+   p-ci = 0;
+   p-sact = 0;
+   }
}
 }
 
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-11-03 Thread Tycho Nightingale
Author: tychon
Date: Tue Nov  4 01:06:33 2014
New Revision: 274076
URL: https://svnweb.freebsd.org/changeset/base/274076

Log:
  Improve the ability to cancel an in-flight request by using an
  interrupt, via SIGCONT, to force the read or write system call to
  return prematurely.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/block_if.c
==
--- head/usr.sbin/bhyve/block_if.c  Tue Nov  4 00:56:25 2014
(r274075)
+++ head/usr.sbin/bhyve/block_if.c  Tue Nov  4 01:06:33 2014
(r274076)
@@ -43,9 +43,13 @@ __FBSDID($FreeBSD$);
 #include string.h
 #include pthread.h
 #include pthread_np.h
+#include signal.h
 #include unistd.h
 
+#include machine/atomic.h
+
 #include bhyverun.h
+#include mevent.h
 #include block_if.h
 
 #define BLOCKIF_SIG0xb109b109
@@ -60,7 +64,9 @@ enum blockop {
 
 enum blockstat {
BST_FREE,
-   BST_INUSE
+   BST_PEND,
+   BST_BUSY,
+   BST_DONE
 };
 
 struct blockif_elem {
@@ -68,6 +74,7 @@ struct blockif_elem {
struct blockif_req  *be_req;
enum blockop be_op;
enum blockstat   be_status;
+   pthread_tbe_tid;
 };
 
 struct blockif_ctxt {
@@ -81,13 +88,25 @@ struct blockif_ctxt {
 pthread_cond_t bc_cond;
int bc_closing;
 
-   /* Request elements and free/inuse queues */
+   /* Request elements and free/pending/busy queues */
TAILQ_HEAD(, blockif_elem) bc_freeq;   
-   TAILQ_HEAD(, blockif_elem) bc_inuseq;   
+   TAILQ_HEAD(, blockif_elem) bc_pendq;
+   TAILQ_HEAD(, blockif_elem) bc_busyq;
u_int   bc_req_count;
struct blockif_elem bc_reqs[BLOCKIF_MAXREQ];
 };
 
+static pthread_once_t blockif_once = PTHREAD_ONCE_INIT;
+
+struct blockif_sig_elem {
+   pthread_mutex_t bse_mtx;
+   pthread_cond_t  bse_cond;
+   int bse_pending;
+   struct blockif_sig_elem *bse_next;
+};
+
+static struct blockif_sig_elem *blockif_bse_head;
+
 static int
 blockif_enqueue(struct blockif_ctxt *bc, struct blockif_req *breq,
enum blockop op)
@@ -101,10 +120,10 @@ blockif_enqueue(struct blockif_ctxt *bc,
assert(be-be_status == BST_FREE);
 
TAILQ_REMOVE(bc-bc_freeq, be, be_link);
-   be-be_status = BST_INUSE;
+   be-be_status = BST_PEND;
be-be_req = breq;
be-be_op = op;
-   TAILQ_INSERT_TAIL(bc-bc_inuseq, be, be_link);
+   TAILQ_INSERT_TAIL(bc-bc_pendq, be, be_link);
 
bc-bc_req_count++;
 
@@ -112,26 +131,38 @@ blockif_enqueue(struct blockif_ctxt *bc,
 }
 
 static int
-blockif_dequeue(struct blockif_ctxt *bc, struct blockif_elem *el)
+blockif_dequeue(struct blockif_ctxt *bc, struct blockif_elem **bep)
 {
struct blockif_elem *be;
 
if (bc-bc_req_count == 0)
return (ENOENT);
 
-   be = TAILQ_FIRST(bc-bc_inuseq);
+   be = TAILQ_FIRST(bc-bc_pendq);
assert(be != NULL);
-   assert(be-be_status == BST_INUSE);
-   *el = *be;
+   assert(be-be_status == BST_PEND);
+   TAILQ_REMOVE(bc-bc_pendq, be, be_link);
+   be-be_status = BST_BUSY;
+   be-be_tid = bc-bc_btid;
+   TAILQ_INSERT_TAIL(bc-bc_busyq, be, be_link);
+
+   *bep = be;
 
-   TAILQ_REMOVE(bc-bc_inuseq, be, be_link);
+   return (0);
+}
+
+static void
+blockif_complete(struct blockif_ctxt *bc, struct blockif_elem *be)
+{
+   assert(be-be_status == BST_DONE);
+
+   TAILQ_REMOVE(bc-bc_busyq, be, be_link);
+   be-be_tid = 0;
be-be_status = BST_FREE;
be-be_req = NULL;
TAILQ_INSERT_TAIL(bc-bc_freeq, be, be_link);
-   
-   bc-bc_req_count--;
 
-   return (0);
+   bc-bc_req_count--;
 }
 
 static void
@@ -163,6 +194,8 @@ blockif_proc(struct blockif_ctxt *bc, st
break;
}
 
+   be-be_status = BST_DONE;
+
(*br-br_callback)(br, err);
 }
 
@@ -170,16 +203,17 @@ static void *
 blockif_thr(void *arg)
 {
struct blockif_ctxt *bc;
-   struct blockif_elem req;
+   struct blockif_elem *be;
 
bc = arg;
 
for (;;) {
pthread_mutex_lock(bc-bc_mtx);
-   while (!blockif_dequeue(bc, req)) {
+   while (!blockif_dequeue(bc, be)) {
pthread_mutex_unlock(bc-bc_mtx);
-   blockif_proc(bc, req);
+   blockif_proc(bc, be);
pthread_mutex_lock(bc-bc_mtx);
+   blockif_complete(bc, be);
}
pthread_cond_wait(bc-bc_cond, bc-bc_mtx);
pthread_mutex_unlock(bc-bc_mtx);
@@ -195,6 +229,38 @@ blockif_thr(void *arg)
return (NULL);
 }
 
+static void
+blockif_sigcont_handler(int signal, enum ev_type type, void *arg)
+{
+   

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

2014-10-17 Thread Tycho Nightingale
Author: tychon
Date: Fri Oct 17 11:37:50 2014
New Revision: 273212
URL: https://svnweb.freebsd.org/changeset/base/273212

Log:
  Support stopping and restarting the AHCI command list via toggling
  PxCMD.ST from '1' to '0' and back.  This allows the driver a chance to
  recover if for instance a timeout occurred due to activity on the
  host.
  
  Reviewed by:  grehan

Modified:
  head/usr.sbin/bhyve/block_if.c
  head/usr.sbin/bhyve/pci_ahci.c

Modified: head/usr.sbin/bhyve/block_if.c
==
--- head/usr.sbin/bhyve/block_if.c  Fri Oct 17 09:33:09 2014
(r273211)
+++ head/usr.sbin/bhyve/block_if.c  Fri Oct 17 11:37:50 2014
(r273212)
@@ -55,8 +55,7 @@ __FBSDID($FreeBSD$);
 enum blockop {
BOP_READ,
BOP_WRITE,
-   BOP_FLUSH,
-   BOP_CANCEL
+   BOP_FLUSH
 };
 
 enum blockstat {
@@ -159,9 +158,6 @@ blockif_proc(struct blockif_ctxt *bc, st
break;
case BOP_FLUSH:
break;
-   case BOP_CANCEL:
-   err = EINTR;
-   break;
default:
err = EINVAL;
break;
@@ -356,9 +352,28 @@ blockif_flush(struct blockif_ctxt *bc, s
 int
 blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq)
 {
+   struct blockif_elem *be;
 
assert(bc-bc_magic == BLOCKIF_SIG);
-   return (blockif_request(bc, breq, BOP_CANCEL));
+
+   pthread_mutex_lock(bc-bc_mtx);
+   TAILQ_FOREACH(be, bc-bc_inuseq, be_link) {
+   if (be-be_req == breq)
+   break;
+   }
+   if (be == NULL) {
+   pthread_mutex_unlock(bc-bc_mtx);
+   return (EINVAL);
+   }
+
+   TAILQ_REMOVE(bc-bc_inuseq, be, be_link);
+   be-be_status = BST_FREE;
+   be-be_req = NULL;
+   TAILQ_INSERT_TAIL(bc-bc_freeq, be, be_link);
+   bc-bc_req_count--;
+   pthread_mutex_unlock(bc-bc_mtx);
+
+   return (0);
 }
 
 int

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Fri Oct 17 09:33:09 2014
(r273211)
+++ head/usr.sbin/bhyve/pci_ahci.c  Fri Oct 17 11:37:50 2014
(r273212)
@@ -48,6 +48,7 @@ __FBSDID($FreeBSD$);
 #include unistd.h
 #include assert.h
 #include pthread.h
+#include pthread_np.h
 #include inttypes.h
 
 #include bhyverun.h
@@ -115,7 +116,8 @@ static FILE *dbg;
 struct ahci_ioreq {
struct blockif_req io_req;
struct ahci_port *io_pr;
-   STAILQ_ENTRY(ahci_ioreq) io_list;
+   STAILQ_ENTRY(ahci_ioreq) io_flist;
+   TAILQ_ENTRY(ahci_ioreq) io_blist;
uint8_t *cfis;
uint32_t len;
uint32_t done;
@@ -160,6 +162,7 @@ struct ahci_port {
struct ahci_ioreq *ioreq;
int ioqsz;
STAILQ_HEAD(ahci_fhead, ahci_ioreq) iofhd;
+   TAILQ_HEAD(ahci_bhead, ahci_ioreq) iobhd;
 };
 
 struct ahci_cmd_hdr {
@@ -360,6 +363,68 @@ ahci_write_reset_fis_d2h(struct ahci_por
 }
 
 static void
+ahci_check_stopped(struct ahci_port *p)
+{
+   /*
+* If we are no longer processing the command list and nothing
+* is in-flight, clear the running bit.
+*/
+   if (!(p-cmd  AHCI_P_CMD_ST)) {
+   if (p-pending == 0)
+   p-cmd = ~(AHCI_P_CMD_CR | AHCI_P_CMD_CCS_MASK);
+   }
+}
+
+static void
+ahci_port_stop(struct ahci_port *p)
+{
+   struct ahci_ioreq *aior;
+   uint8_t *cfis;
+   int slot;
+   int ncq;
+   int error;
+
+   assert(pthread_mutex_isowned_np(p-pr_sc-mtx));
+
+   TAILQ_FOREACH(aior, p-iobhd, io_blist) {
+   /*
+* Try to cancel the outstanding blockif request.
+*/
+   error = blockif_cancel(p-bctx, aior-io_req);
+   if (error != 0)
+   continue;
+
+   slot = aior-slot;
+   cfis = aior-cfis;
+   if (cfis[2] == ATA_WRITE_FPDMA_QUEUED ||
+   cfis[2] == ATA_READ_FPDMA_QUEUED)
+   ncq = 1;
+
+   if (ncq)
+   p-sact = ~(1  slot);
+   else
+   p-ci = ~(1  slot);
+
+   /*
+* This command is now done.
+*/
+   p-pending = ~(1  slot);
+
+   /*
+* Delete the blockif request from the busy list
+*/
+   TAILQ_REMOVE(p-iobhd, aior, io_blist);
+
+   /*
+* Move the blockif request back to the free list
+*/
+   STAILQ_INSERT_TAIL(p-iofhd, aior, io_flist);
+   }
+
+   ahci_check_stopped(p);
+}
+
+static void
 ahci_port_reset(struct ahci_port *pr)
 {
pr-sctl = 0;
@@ -492,7 +557,7 @@ ahci_handle_dma(struct ahci_port *p, int
 */
aior = STAILQ_FIRST(p-iofhd);
assert(aior != 

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

2014-08-22 Thread Tycho Nightingale
Author: tychon
Date: Fri Aug 22 13:01:22 2014
New Revision: 270326
URL: http://svnweb.freebsd.org/changeset/base/270326

Log:
  Fix a recursive lock acquisition in vi_reset_dev().
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/virtio.c
==
--- head/usr.sbin/bhyve/virtio.cFri Aug 22 11:50:34 2014
(r270325)
+++ head/usr.sbin/bhyve/virtio.cFri Aug 22 13:01:22 2014
(r270326)
@@ -33,6 +33,7 @@ __FBSDID($FreeBSD$);
 #include stdio.h
 #include stdint.h
 #include pthread.h
+#include pthread_np.h
 
 #include bhyverun.h
 #include pci_emul.h
@@ -89,6 +90,9 @@ vi_reset_dev(struct virtio_softc *vs)
struct vqueue_info *vq;
int i, nvq;
 
+   if (vs-vs_mtx)
+   assert(pthread_mutex_isowned_np(vs-vs_mtx));
+
nvq = vs-vs_vc-vc_nvq;
for (vq = vs-vs_queues, i = 0; i  nvq; vq++, i++) {
vq-vq_flags = 0;
@@ -99,11 +103,9 @@ vi_reset_dev(struct virtio_softc *vs)
vs-vs_negotiated_caps = 0;
vs-vs_curq = 0;
/* vs-vs_status = 0; -- redundant */
-   VS_LOCK(vs);
if (vs-vs_isr)
pci_lintr_deassert(vs-vs_pi);
vs-vs_isr = 0;
-   VS_UNLOCK(vs);
vs-vs_msix_cfg_idx = VIRTIO_MSI_NO_VECTOR;
 }
 
@@ -137,7 +139,9 @@ vi_intr_init(struct virtio_softc *vs, in
 
if (use_msix) {
vs-vs_flags |= VIRTIO_USE_MSIX;
+   VS_LOCK(vs);
vi_reset_dev(vs); /* set all vectors to NO_VECTOR */
+   VS_UNLOCK(vs);
nvec = vs-vs_vc-vc_nvq + 1;
if (pci_emul_add_msixcap(vs-vs_pi, nvec, barnum))
return (1);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-07-30 Thread Tycho Nightingale
Author: tychon
Date: Wed Jul 30 18:47:31 2014
New Revision: 269317
URL: http://svnweb.freebsd.org/changeset/base/269317

Log:
  Commands which encounter a fatal error shouldn't be marked as completed.
  Furthermore, provide an indication of the current command so it can be
  determined which one actually failed.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Wed Jul 30 18:21:06 2014
(r269316)
+++ head/usr.sbin/bhyve/pci_ahci.c  Wed Jul 30 18:47:31 2014
(r269317)
@@ -336,8 +336,9 @@ ahci_write_fis_d2h(struct ahci_port *p, 
fis[13] = cfis[13];
if (fis[2]  ATA_S_ERROR)
p-is |= AHCI_P_IX_TFE;
+   else
+   p-ci = ~(1  slot);
p-tfd = tfd;
-   p-ci = ~(1  slot);
ahci_write_fis(p, FIS_TYPE_REGD2H, fis);
 }
 
@@ -651,8 +652,8 @@ handle_identify(struct ahci_port *p, int
write_prdt(p, slot, cfis, (void *)buf, sizeof(buf));
p-tfd = ATA_S_DSC | ATA_S_READY;
p-is |= AHCI_P_IX_DP;
+   p-ci = ~(1  slot);
}
-   p-ci = ~(1  slot);
ahci_generate_intr(p-pr_sc);
 }
 
@@ -694,8 +695,8 @@ handle_atapi_identify(struct ahci_port *
write_prdt(p, slot, cfis, (void *)buf, sizeof(buf));
p-tfd = ATA_S_DSC | ATA_S_READY;
p-is |= AHCI_P_IX_DHR;
+   p-ci = ~(1  slot);
}
-   p-ci = ~(1  slot);
ahci_generate_intr(p-pr_sc);
 }
 
@@ -1298,7 +1299,6 @@ ahci_handle_cmd(struct ahci_port *p, int
if (!p-atapi) {
p-tfd = (ATA_E_ABORT  8) | ATA_S_READY | ATA_S_ERROR;
p-is |= AHCI_P_IX_TFE;
-   p-ci = ~(1  slot);
ahci_generate_intr(p-pr_sc);
} else
handle_packet_cmd(p, slot, cfis);
@@ -1307,7 +1307,6 @@ ahci_handle_cmd(struct ahci_port *p, int
WPRINTF(Unsupported cmd:%02x\n, cfis[2]);
p-tfd = (ATA_E_ABORT  8) | ATA_S_READY | ATA_S_ERROR;
p-is |= AHCI_P_IX_TFE;
-   p-ci = ~(1  slot);
ahci_generate_intr(p-pr_sc);
break;
}
@@ -1375,8 +1374,11 @@ ahci_handle_port(struct ahci_port *p)
 * are already in-flight.
 */
for (i = 0; (i  32)  p-ci; i++) {
-   if ((p-ci  (1  i))  !(p-pending  (1  i)))
+   if ((p-ci  (1  i))  !(p-pending  (1  i))) {
+   p-cmd = ~AHCI_P_CMD_CCS_MASK;
+   p-cmd |= i  AHCI_P_CMD_CCS_SHIFT;
ahci_handle_slot(p, i);
+   }
}
 }
 
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-06-26 Thread Tycho Nightingale
Author: tychon
Date: Thu Jun 26 17:15:41 2014
New Revision: 267921
URL: http://svnweb.freebsd.org/changeset/base/267921

Log:
  Add support for emulating the move instruction: mov r/m8, imm8.
  
  Reviewed by:  neel

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

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Thu Jun 26 17:10:07 2014
(r267920)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Thu Jun 26 17:15:41 2014
(r267921)
@@ -104,6 +104,12 @@ static const struct vie_op one_byte_opco
.op_byte = 0x8B,
.op_type = VIE_OP_TYPE_MOV,
},
+   [0xC6] = {
+   /* XXX Group 11 extended opcode - not just MOV */
+   .op_byte = 0xC6,
+   .op_type = VIE_OP_TYPE_MOV,
+   .op_flags = VIE_OP_F_IMM8,
+   },
[0xC7] = {
.op_byte = 0xC7,
.op_type = VIE_OP_TYPE_MOV,
@@ -310,6 +316,15 @@ emulate_mov(void *vm, int vcpuid, uint64
error = vie_update_register(vm, vcpuid, reg, val, size);
}
break;
+   case 0xC6:
+   /*
+* MOV from imm8 to mem (ModRM:r/m)
+* C6/0 mov r/m8, imm8
+* REX + C6/0   mov r/m8, imm8
+*/
+   size = 1;
+   error = memwrite(vm, vcpuid, gpa, vie-immediate, size, arg);
+   break;
case 0xC7:
/*
 * MOV from imm32 to mem (ModRM:r/m)
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r267558 - head/sys/amd64/vmm/intel

2014-06-16 Thread Tycho Nightingale
Author: tychon
Date: Mon Jun 16 22:59:18 2014
New Revision: 267558
URL: http://svnweb.freebsd.org/changeset/base/267558

Log:
  Bring an overly enthusiastic KASSERT inline with the Intel SDM.
  
  Reviewed by:  neel

Modified:
  head/sys/amd64/vmm/intel/vmx.c

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Mon Jun 16 21:37:16 2014
(r267557)
+++ head/sys/amd64/vmm/intel/vmx.c  Mon Jun 16 22:59:18 2014
(r267558)
@@ -1258,12 +1258,28 @@ vmx_inject_interrupts(struct vmx *vmx, i
/* Ask the local apic for a vector to inject */
if (!vlapic_pending_intr(vlapic, vector))
return;
+
+   /*
+* From the Intel SDM, Volume 3, Section Maskable
+* Hardware Interrupts:
+* - maskable interrupt vectors [16,255] can be delivered
+*   through the local APIC.
+   */
+   KASSERT(vector = 16  vector = 255,
+   (invalid vector %d from local APIC, vector));
} else {
/* Ask the legacy pic for a vector to inject */
vatpic_pending_intr(vmx-vm, vector);
-   }
 
-   KASSERT(vector = 32  vector = 255, (invalid vector %d, vector));
+   /*
+* From the Intel SDM, Volume 3, Section Maskable
+* Hardware Interrupts:
+* - maskable interrupt vectors [0,255] can be delivered
+*   through the INTR pin.
+*/
+   KASSERT(vector = 0  vector = 255,
+   (invalid vector %d from INTR, vector));
+   }
 
/* Check RFLAGS.IF and the interruptibility state of the guest */
rflags = vmcs_read(VMCS_GUEST_RFLAGS);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-06-10 Thread Tycho Nightingale
Author: tychon
Date: Tue Jun 10 18:46:00 2014
New Revision: 267338
URL: http://svnweb.freebsd.org/changeset/base/267338

Log:
  Replace enum forward declarations with complete definitions.
  
  Reviewed by:  neel

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

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hTue Jun 10 18:29:45 2014
(r267337)
+++ head/sys/amd64/include/vmm.hTue Jun 10 18:46:00 2014
(r267338)
@@ -37,6 +37,53 @@ enum vm_suspend_how {
VM_SUSPEND_LAST
 };
 
+/*
+ * Identifiers for architecturally defined registers.
+ */
+enum vm_reg_name {
+   VM_REG_GUEST_RAX,
+   VM_REG_GUEST_RBX,
+   VM_REG_GUEST_RCX,
+   VM_REG_GUEST_RDX,
+   VM_REG_GUEST_RSI,
+   VM_REG_GUEST_RDI,
+   VM_REG_GUEST_RBP,
+   VM_REG_GUEST_R8,
+   VM_REG_GUEST_R9,
+   VM_REG_GUEST_R10,
+   VM_REG_GUEST_R11,
+   VM_REG_GUEST_R12,
+   VM_REG_GUEST_R13,
+   VM_REG_GUEST_R14,
+   VM_REG_GUEST_R15,
+   VM_REG_GUEST_CR0,
+   VM_REG_GUEST_CR3,
+   VM_REG_GUEST_CR4,
+   VM_REG_GUEST_DR7,
+   VM_REG_GUEST_RSP,
+   VM_REG_GUEST_RIP,
+   VM_REG_GUEST_RFLAGS,
+   VM_REG_GUEST_ES,
+   VM_REG_GUEST_CS,
+   VM_REG_GUEST_SS,
+   VM_REG_GUEST_DS,
+   VM_REG_GUEST_FS,
+   VM_REG_GUEST_GS,
+   VM_REG_GUEST_LDTR,
+   VM_REG_GUEST_TR,
+   VM_REG_GUEST_IDTR,
+   VM_REG_GUEST_GDTR,
+   VM_REG_GUEST_EFER,
+   VM_REG_GUEST_CR2,
+   VM_REG_LAST
+};
+
+enum x2apic_state {
+   X2APIC_DISABLED,
+   X2APIC_ENABLED,
+   X2APIC_STATE_LAST
+};
+
 #ifdef _KERNEL
 
 #defineVM_MAX_NAMELEN  32
@@ -54,9 +101,6 @@ struct vmspace;
 struct vm_object;
 struct pmap;
 
-enum vm_reg_name;
-enum x2apic_state;
-
 typedef int(*vmm_init_func_t)(int ipinum);
 typedef int(*vmm_cleanup_func_t)(void);
 typedef void   (*vmm_resume_func_t)(void);
@@ -250,47 +294,6 @@ enum vm_reg_name vm_segment_name(int seg
 #defineVM_MAXCPU   16  /* maximum virtual cpus 
*/
 
 /*
- * Identifiers for architecturally defined registers.
- */
-enum vm_reg_name {
-   VM_REG_GUEST_RAX,
-   VM_REG_GUEST_RBX,
-   VM_REG_GUEST_RCX,
-   VM_REG_GUEST_RDX,
-   VM_REG_GUEST_RSI,
-   VM_REG_GUEST_RDI,
-   VM_REG_GUEST_RBP,
-   VM_REG_GUEST_R8,
-   VM_REG_GUEST_R9,
-   VM_REG_GUEST_R10,
-   VM_REG_GUEST_R11,
-   VM_REG_GUEST_R12,
-   VM_REG_GUEST_R13,
-   VM_REG_GUEST_R14,
-   VM_REG_GUEST_R15,
-   VM_REG_GUEST_CR0,
-   VM_REG_GUEST_CR3,
-   VM_REG_GUEST_CR4,
-   VM_REG_GUEST_DR7,
-   VM_REG_GUEST_RSP,
-   VM_REG_GUEST_RIP,
-   VM_REG_GUEST_RFLAGS,
-   VM_REG_GUEST_ES,
-   VM_REG_GUEST_CS,
-   VM_REG_GUEST_SS,
-   VM_REG_GUEST_DS,
-   VM_REG_GUEST_FS,
-   VM_REG_GUEST_GS,
-   VM_REG_GUEST_LDTR,
-   VM_REG_GUEST_TR,
-   VM_REG_GUEST_IDTR,
-   VM_REG_GUEST_GDTR,
-   VM_REG_GUEST_EFER,
-   VM_REG_GUEST_CR2,
-   VM_REG_LAST
-};
-
-/*
  * Identifiers for optional vmm capabilities
  */
 enum vm_cap_type {
@@ -302,12 +305,6 @@ enum vm_cap_type {
VM_CAP_MAX
 };
 
-enum x2apic_state {
-   X2APIC_DISABLED,
-   X2APIC_ENABLED,
-   X2APIC_STATE_LAST
-};
-
 enum vm_intr_trigger {
EDGE_TRIGGER,
LEVEL_TRIGGER
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-06-09 Thread Tycho Nightingale
Author: tychon
Date: Mon Jun  9 19:55:50 2014
New Revision: 267294
URL: http://svnweb.freebsd.org/changeset/base/267294

Log:
  r267169 should apply to 64-bit BARs as well.
  
  Reviewed by:  neel

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

Modified: head/usr.sbin/bhyve/pci_emul.c
==
--- head/usr.sbin/bhyve/pci_emul.c  Mon Jun  9 19:36:08 2014
(r267293)
+++ head/usr.sbin/bhyve/pci_emul.c  Mon Jun  9 19:55:50 2014
(r267294)
@@ -376,7 +376,7 @@ pci_emul_mem_handler(struct vmctx *ctx, 
offset = addr - pdi-pi_bar[bidx].addr;
 
if (dir == MEM_F_WRITE) {
-   if (pdi-pi_bar[bidx].type == PCIBAR_MEM32  size == 8) {
+   if (size == 8) {
(*pe-pe_barwrite)(ctx, vcpu, pdi, bidx, offset,
   4, *val  0x);
(*pe-pe_barwrite)(ctx, vcpu, pdi, bidx, offset + 4,
@@ -386,7 +386,7 @@ pci_emul_mem_handler(struct vmctx *ctx, 
   size, *val);
}
} else {
-   if (pdi-pi_bar[bidx].type == PCIBAR_MEM32  size == 8) {
+   if (size == 8) {
*val = (*pe-pe_barread)(ctx, vcpu, pdi, bidx,
 offset, 4);
*val |= (*pe-pe_barread)(ctx, vcpu, pdi, bidx,
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-06-06 Thread Tycho Nightingale
Author: tychon
Date: Fri Jun  6 16:18:37 2014
New Revision: 267169
URL: http://svnweb.freebsd.org/changeset/base/267169

Log:
  Some devices (e.g. Intel AHCI and NICs) support quad-word access to
  register pairs where two 32-bit registers make up a larger logical
  size.  Support those access by splitting the quad-word into two
  double-words.
  
  Reviewed by:  grehan

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

Modified: head/usr.sbin/bhyve/pci_emul.c
==
--- head/usr.sbin/bhyve/pci_emul.c  Fri Jun  6 15:17:19 2014
(r267168)
+++ head/usr.sbin/bhyve/pci_emul.c  Fri Jun  6 16:18:37 2014
(r267169)
@@ -375,10 +375,27 @@ pci_emul_mem_handler(struct vmctx *ctx, 
 
offset = addr - pdi-pi_bar[bidx].addr;
 
-   if (dir == MEM_F_WRITE)
-   (*pe-pe_barwrite)(ctx, vcpu, pdi, bidx, offset, size, *val);
-   else
-   *val = (*pe-pe_barread)(ctx, vcpu, pdi, bidx, offset, size);
+   if (dir == MEM_F_WRITE) {
+   if (pdi-pi_bar[bidx].type == PCIBAR_MEM32  size == 8) {
+   (*pe-pe_barwrite)(ctx, vcpu, pdi, bidx, offset,
+  4, *val  0x);
+   (*pe-pe_barwrite)(ctx, vcpu, pdi, bidx, offset + 4,
+  4, *val  32);
+   } else {
+   (*pe-pe_barwrite)(ctx, vcpu, pdi, bidx, offset,
+  size, *val);
+   }
+   } else {
+   if (pdi-pi_bar[bidx].type == PCIBAR_MEM32  size == 8) {
+   *val = (*pe-pe_barread)(ctx, vcpu, pdi, bidx,
+offset, 4);
+   *val |= (*pe-pe_barread)(ctx, vcpu, pdi, bidx,
+ offset + 4, 4)  32;
+   } else {
+   *val = (*pe-pe_barread)(ctx, vcpu, pdi, bidx,
+offset, size);
+   }
+   }
 
return (0);
 }
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r267178 - in head/sys/amd64/vmm: intel io

2014-06-06 Thread Tycho Nightingale
Author: tychon
Date: Fri Jun  6 18:23:49 2014
New Revision: 267178
URL: http://svnweb.freebsd.org/changeset/base/267178

Log:
  Support guest accesses to %cr8.
  
  Reviewed by:  neel

Modified:
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/amd64/vmm/io/vlapic.c
  head/sys/amd64/vmm/io/vlapic.h

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Fri Jun  6 18:02:32 2014
(r267177)
+++ head/sys/amd64/vmm/intel/vmx.c  Fri Jun  6 18:23:49 2014
(r267178)
@@ -83,7 +83,9 @@ __FBSDID($FreeBSD$);
(PROCBASED_SECONDARY_CONTROLS   |   \
 PROCBASED_IO_EXITING   |   \
 PROCBASED_MSR_BITMAPS  |   \
-PROCBASED_CTLS_WINDOW_SETTING)
+PROCBASED_CTLS_WINDOW_SETTING  |   \
+PROCBASED_CR8_LOAD_EXITING |   \
+PROCBASED_CR8_STORE_EXITING)
 #definePROCBASED_CTLS_ZERO_SETTING \
(PROCBASED_CR3_LOAD_EXITING |   \
PROCBASED_CR3_STORE_EXITING |   \
@@ -714,6 +716,13 @@ vmx_init(int ipinum)
procbased_ctls2 = ~PROCBASED2_VIRTUALIZE_X2APIC_MODE;
 
/*
+* No need to emulate accesses to %CR8 if virtual
+* interrupt delivery is enabled.
+*/
+   procbased_ctls = ~PROCBASED_CR8_LOAD_EXITING;
+   procbased_ctls = ~PROCBASED_CR8_STORE_EXITING;
+
+   /*
 * Check for Posted Interrupts only if Virtual Interrupt
 * Delivery is enabled.
 */
@@ -1426,97 +1435,130 @@ vmx_emulate_xsetbv(struct vmx *vmx, int 
return (HANDLED);
 }
 
-static int
-vmx_emulate_cr_access(struct vmx *vmx, int vcpu, uint64_t exitqual)
+static uint64_t
+vmx_get_guest_reg(struct vmx *vmx, int vcpu, int ident)
 {
-   int cr, vmcs_guest_cr, vmcs_shadow_cr;
-   uint64_t crval, regval, ones_mask, zeros_mask;
const struct vmxctx *vmxctx;
 
-   /* We only handle mov to %cr0 or %cr4 at this time */
-   if ((exitqual  0xf0) != 0x00)
-   return (UNHANDLED);
+   vmxctx = vmx-ctx[vcpu];
 
-   cr = exitqual  0xf;
-   if (cr != 0  cr != 4)
-   return (UNHANDLED);
+   switch (ident) {
+   case 0:
+   return (vmxctx-guest_rax);
+   case 1:
+   return (vmxctx-guest_rcx);
+   case 2:
+   return (vmxctx-guest_rdx);
+   case 3:
+   return (vmxctx-guest_rbx);
+   case 4:
+   return (vmcs_read(VMCS_GUEST_RSP));
+   case 5:
+   return (vmxctx-guest_rbp);
+   case 6:
+   return (vmxctx-guest_rsi);
+   case 7:
+   return (vmxctx-guest_rdi);
+   case 8:
+   return (vmxctx-guest_r8);
+   case 9:
+   return (vmxctx-guest_r9);
+   case 10:
+   return (vmxctx-guest_r10);
+   case 11:
+   return (vmxctx-guest_r11);
+   case 12:
+   return (vmxctx-guest_r12);
+   case 13:
+   return (vmxctx-guest_r13);
+   case 14:
+   return (vmxctx-guest_r14);
+   case 15:
+   return (vmxctx-guest_r15);
+   default:
+   panic(invalid vmx register %d, ident);
+   }
+}
+
+static void
+vmx_set_guest_reg(struct vmx *vmx, int vcpu, int ident, uint64_t regval)
+{
+   struct vmxctx *vmxctx;
 
-   regval = 0; /* silence gcc */
vmxctx = vmx-ctx[vcpu];
 
-   /*
-* We must use vmcs_write() directly here because vmcs_setreg() will
-* call vmclear(vmcs) as a side-effect which we certainly don't want.
-*/
-   switch ((exitqual  8)  0xf) {
+   switch (ident) {
case 0:
-   regval = vmxctx-guest_rax;
+   vmxctx-guest_rax = regval;
break;
case 1:
-   regval = vmxctx-guest_rcx;
+   vmxctx-guest_rcx = regval;
break;
case 2:
-   regval = vmxctx-guest_rdx;
+   vmxctx-guest_rdx = regval;
break;
case 3:
-   regval = vmxctx-guest_rbx;
+   vmxctx-guest_rbx = regval;
break;
case 4:
-   regval = vmcs_read(VMCS_GUEST_RSP);
+   vmcs_write(VMCS_GUEST_RSP, regval);
break;
case 5:
-   regval = vmxctx-guest_rbp;
+   vmxctx-guest_rbp = regval;
break;
case 6:
-   regval = vmxctx-guest_rsi;
+   vmxctx-guest_rsi = regval;
break;
case 7:
-   regval = vmxctx-guest_rdi;
+   vmxctx-guest_rdi = regval;
break;
case 8:
-   regval = vmxctx-guest_r8;
+   

svn commit: r266910 - head/sys/amd64/vmm/intel

2014-05-30 Thread Tycho Nightingale
Author: tychon
Date: Fri May 30 23:37:31 2014
New Revision: 266910
URL: http://svnweb.freebsd.org/changeset/base/266910

Log:
  If VMX isn't enabled so long as the lock bit isn't set yet in MSR
  IA32_FEATURE_CONTROL it still can be.
  
  Approved by:  grehan (co-mentor)

Modified:
  head/sys/amd64/vmm/intel/vmx.c

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Fri May 30 23:28:53 2014
(r266909)
+++ head/sys/amd64/vmm/intel/vmx.c  Fri May 30 23:37:31 2014
(r266910)
@@ -512,6 +512,15 @@ static void
 vmx_enable(void *arg __unused)
 {
int error;
+   uint64_t feature_control;
+
+   feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL);
+   if ((feature_control  IA32_FEATURE_CONTROL_LOCK) == 0 ||
+   (feature_control  IA32_FEATURE_CONTROL_VMX_EN) == 0) {
+   wrmsr(MSR_IA32_FEATURE_CONTROL,
+   feature_control | IA32_FEATURE_CONTROL_VMX_EN |
+   IA32_FEATURE_CONTROL_LOCK);
+   }
 
load_cr4(rcr4() | CR4_VMXE);
 
@@ -547,7 +556,7 @@ vmx_init(int ipinum)
 * are set (bits 0 and 2 respectively).
 */
feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL);
-   if ((feature_control  IA32_FEATURE_CONTROL_LOCK) == 0 ||
+   if ((feature_control  IA32_FEATURE_CONTROL_LOCK) == 1 
(feature_control  IA32_FEATURE_CONTROL_VMX_EN) == 0) {
printf(vmx_init: VMX operation disabled by BIOS\n);
return (ENXIO);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-04-25 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 25 13:38:18 2014
New Revision: 264916
URL: http://svnweb.freebsd.org/changeset/base/264916

Log:
  Provide a very basic stub for the 8042 PS/2 keyboard controller.
  
  Reviewed by:  jhb
  Approved by:  neel (co-mentor)

Added:
  head/usr.sbin/bhyve/atkbdc.c   (contents, props changed)
Modified:
  head/usr.sbin/bhyve/Makefile
  head/usr.sbin/bhyve/bhyverun.c

Modified: head/usr.sbin/bhyve/Makefile
==
--- head/usr.sbin/bhyve/MakefileFri Apr 25 11:36:11 2014
(r264915)
+++ head/usr.sbin/bhyve/MakefileFri Apr 25 13:38:18 2014
(r264916)
@@ -9,6 +9,7 @@ DEBUG_FLAGS= -g -O0 
 MAN=   bhyve.8
 
 SRCS=  \
+   atkbdc.c\
acpi.c  \
bhyverun.c  \
block_if.c  \

Added: head/usr.sbin/bhyve/atkbdc.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/bhyve/atkbdc.cFri Apr 25 13:38:18 2014
(r264916)
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 2014 Tycho Nightingale 
tycho.nighting...@pluribusnetworks.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/types.h
+
+#include machine/vmm.h
+
+#include stdio.h
+
+#include inout.h
+#include pci_lpc.h
+
+#defineKBD_DATA_PORT   0x60
+
+#defineKBD_STS_CTL_PORT0x64
+#define KDB_SYS_FLAG   0x4
+
+#defineKBDC_RESET  0xfe
+
+static int
+atkbdc_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
+uint32_t *eax, void *arg)
+{
+   if (bytes != 1)
+   return (INOUT_ERROR);
+
+   *eax = 0;
+
+   return (INOUT_OK);
+}
+
+static int
+atkbdc_sts_ctl_handler(struct vmctx *ctx, int vcpu, int in, int port,
+int bytes, uint32_t *eax, void *arg)
+{
+   int retval;
+
+   if (bytes != 1)
+   return (INOUT_ERROR);
+
+   retval = INOUT_OK;
+   if (in) {
+   *eax = KDB_SYS_FLAG;/* system passed POST */
+   } else {
+   switch (*eax) {
+   case KBDC_RESET:/* Pulse reset line. */
+   retval = INOUT_RESET;
+   break;
+   }
+   }
+
+   return (retval);
+}
+
+INOUT_PORT(atkdbc, KBD_DATA_PORT, IOPORT_F_INOUT, atkbdc_data_handler);
+SYSRES_IO(KBD_DATA_PORT, 1);
+INOUT_PORT(atkbdc, KBD_STS_CTL_PORT,  IOPORT_F_INOUT,
+atkbdc_sts_ctl_handler);
+SYSRES_IO(KBD_STS_CTL_PORT, 1);

Modified: head/usr.sbin/bhyve/bhyverun.c
==
--- head/usr.sbin/bhyve/bhyverun.c  Fri Apr 25 11:36:11 2014
(r264915)
+++ head/usr.sbin/bhyve/bhyverun.c  Fri Apr 25 13:38:18 2014
(r264916)
@@ -281,10 +281,6 @@ vmexit_inout(struct vmctx *ctx, struct v
if (vme-u.inout.string || vme-u.inout.rep)
return (VMEXIT_ABORT);
 
-   /* Special case of guest reset */
-   if (out  port == 0x64  (uint8_t)eax == 0xFE)
-   return (vmexit_catch_reset());
-
 /* Extra-special case of host notifications */
 if (out  port == GUEST_NIO_PORT)
 return (vmexit_handle_notify(ctx, vme, pvcpu, eax));
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r264768 - in head: sys/amd64/vmm usr.sbin/bhyve

2014-04-22 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr 22 16:13:56 2014
New Revision: 264768
URL: http://svnweb.freebsd.org/changeset/base/264768

Log:
  Factor out common ioport handler code for better hygiene -- pointed
  out by neel@.
  
  Approved by:  neel (co-mentor)

Modified:
  head/sys/amd64/vmm/vmm_ioport.c
  head/usr.sbin/bhyve/inout.c

Modified: head/sys/amd64/vmm/vmm_ioport.c
==
--- head/sys/amd64/vmm/vmm_ioport.c Tue Apr 22 16:04:31 2014
(r264767)
+++ head/sys/amd64/vmm/vmm_ioport.c Tue Apr 22 16:13:56 2014
(r264768)
@@ -69,18 +69,19 @@ emulate_ioport(struct vm *vm, int vcpuid
if (handler == NULL)
return (-1);
 
+   switch (vmexit-u.inout.bytes) {
+   case 1:
+   mask = 0xff;
+   break;
+   case 2:
+   mask = 0x;
+   break;
+   default:
+   mask = 0x;
+   break;
+   }
+
if (!vmexit-u.inout.in) {
-   switch (vmexit-u.inout.bytes) {
-   case 1:
-   mask = 0xff;
-   break;
-   case 2:
-   mask = 0x;
-   break;
-   default:
-   mask = 0x;
-   break;
-   }
val = vmexit-u.inout.eax  mask;
}
 
@@ -88,17 +89,6 @@ emulate_ioport(struct vm *vm, int vcpuid
vmexit-u.inout.port, vmexit-u.inout.bytes, val);
 
if (!error  vmexit-u.inout.in) {
-   switch (vmexit-u.inout.bytes) {
-   case 1:
-   mask = 0xff;
-   break;
-   case 2:
-   mask = 0x;
-   break;
-   default:
-   mask = 0x;
-   break;
-   }
vmexit-u.inout.eax = ~mask;
vmexit-u.inout.eax |= val  mask;
}

Modified: head/usr.sbin/bhyve/inout.c
==
--- head/usr.sbin/bhyve/inout.c Tue Apr 22 16:04:31 2014(r264767)
+++ head/usr.sbin/bhyve/inout.c Tue Apr 22 16:13:56 2014(r264768)
@@ -107,18 +107,19 @@ emulate_inout(struct vmctx *ctx, int vcp
if (strict  handler == default_inout)
return (-1);
 
+   switch (bytes) {
+   case 1:
+   mask = 0xff;
+   break;
+   case 2:
+   mask = 0x;
+   break;
+   default:
+   mask = 0x;
+   break;
+   }
+
if (!in) {
-   switch (bytes) {
-   case 1:
-   mask = 0xff;
-   break;
-   case 2:
-   mask = 0x;
-   break;
-   default:
-   mask = 0x;
-   break;
-   }
val = *eax  mask;
}
 
@@ -131,17 +132,6 @@ emulate_inout(struct vmctx *ctx, int vcp
error = -1;
 
if (!error  in) {
-   switch (bytes) {
-   case 1:
-   mask = 0xff;
-   break;
-   case 2:
-   mask = 0x;
-   break;
-   default:
-   mask = 0x;
-   break;
-   }
*eax = ~mask;
*eax |= val  mask;
}
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r264648 - in head: sys/amd64/vmm sys/amd64/vmm/io usr.sbin/bhyve

2014-04-18 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 18 15:22:56 2014
New Revision: 264648
URL: http://svnweb.freebsd.org/changeset/base/264648

Log:
  Respect the destination operand size of the 'Input from Port' instruction.
  
  Approved by:  grehan (co-mentor)

Modified:
  head/sys/amd64/vmm/io/vatpic.c
  head/sys/amd64/vmm/io/vatpic.h
  head/sys/amd64/vmm/io/vatpit.c
  head/sys/amd64/vmm/io/vatpit.h
  head/sys/amd64/vmm/vmm_ioport.c
  head/sys/amd64/vmm/vmm_ioport.h
  head/usr.sbin/bhyve/inout.c

Modified: head/sys/amd64/vmm/io/vatpic.c
==
--- head/sys/amd64/vmm/io/vatpic.c  Fri Apr 18 14:59:39 2014
(r264647)
+++ head/sys/amd64/vmm/io/vatpic.c  Fri Apr 18 15:22:56 2014
(r264648)
@@ -517,7 +517,8 @@ vatpic_intr_accepted(struct vm *vm, int 
 }
 
 static int
-vatpic_read(struct vatpic *vatpic, struct atpic *atpic, struct vm_exit *vmexit)
+vatpic_read(struct vatpic *vatpic, struct atpic *atpic, bool in, int port,
+   int bytes, uint32_t *eax)
 {
VATPIC_LOCK(vatpic);
 
@@ -526,16 +527,16 @@ vatpic_read(struct vatpic *vatpic, struc
VATPIC_UNLOCK(vatpic);
return (-1);
} else {
-   if (vmexit-u.inout.port  ICU_IMR_OFFSET) {
+   if (port  ICU_IMR_OFFSET) {
/* read interrrupt mask register */
-   vmexit-u.inout.eax = atpic-mask;
+   *eax = atpic-mask;
} else {
if (atpic-rd_cmd_reg == OCW3_RIS) {
/* read interrupt service register */
-   vmexit-u.inout.eax = atpic-service;
+   *eax = atpic-service;
} else {
/* read interrupt request register */
-   vmexit-u.inout.eax = atpic-request;
+   *eax = atpic-request;
}
}
}
@@ -547,17 +548,17 @@ vatpic_read(struct vatpic *vatpic, struc
 }
 
 static int
-vatpic_write(struct vatpic *vatpic, struct atpic *atpic,
-struct vm_exit *vmexit)
+vatpic_write(struct vatpic *vatpic, struct atpic *atpic, bool in, int port,
+int bytes, uint32_t *eax)
 {
int error;
uint8_t val;
 
-   val = vmexit-u.inout.eax;
+   val = *eax;
 
VATPIC_LOCK(vatpic);
 
-   if (vmexit-u.inout.port  ICU_IMR_OFFSET) {
+   if (port  ICU_IMR_OFFSET) {
if (atpic-ready) {
error = vatpic_ocw1(vatpic, atpic, val);
} else {
@@ -594,7 +595,8 @@ vatpic_write(struct vatpic *vatpic, stru
 }
 
 int
-vatpic_master_handler(void *vm, int vcpuid, struct vm_exit *vmexit)
+vatpic_master_handler(void *vm, int vcpuid, bool in, int port, int bytes,
+uint32_t *eax)
 {
struct vatpic *vatpic;
struct atpic *atpic;
@@ -602,18 +604,19 @@ vatpic_master_handler(void *vm, int vcpu
vatpic = vm_atpic(vm);
atpic = vatpic-atpic[0];
 
-   if (vmexit-u.inout.bytes != 1)
+   if (bytes != 1)
return (-1);
  
-   if (vmexit-u.inout.in) {
-   return (vatpic_read(vatpic, atpic, vmexit));
+   if (in) {
+   return (vatpic_read(vatpic, atpic, in, port, bytes, eax));
}
  
-   return (vatpic_write(vatpic, atpic, vmexit));
+   return (vatpic_write(vatpic, atpic, in, port, bytes, eax));
 }
 
 int
-vatpic_slave_handler(void *vm, int vcpuid, struct vm_exit *vmexit)
+vatpic_slave_handler(void *vm, int vcpuid, bool in, int port, int bytes,
+uint32_t *eax)
 {
struct vatpic *vatpic;
struct atpic *atpic;
@@ -621,35 +624,36 @@ vatpic_slave_handler(void *vm, int vcpui
vatpic = vm_atpic(vm);
atpic = vatpic-atpic[1];
 
-   if (vmexit-u.inout.bytes != 1)
+   if (bytes != 1)
return (-1);
 
-   if (vmexit-u.inout.in) {
-   return (vatpic_read(vatpic, atpic, vmexit));
+   if (in) {
+   return (vatpic_read(vatpic, atpic, in, port, bytes, eax));
}
 
-   return (vatpic_write(vatpic, atpic, vmexit));
+   return (vatpic_write(vatpic, atpic, in, port, bytes, eax));
 }
 
 int
-vatpic_elc_handler(void *vm, int vcpuid, struct vm_exit *vmexit)
+vatpic_elc_handler(void *vm, int vcpuid, bool in, int port, int bytes,
+uint32_t *eax)
 {
struct vatpic *vatpic;
bool is_master;
 
vatpic = vm_atpic(vm);
-   is_master = (vmexit-u.inout.port == IO_ELCR1);
+   is_master = (port == IO_ELCR1);
 
-   if (vmexit-u.inout.bytes != 1)
+   if (bytes != 1)
return (-1);
 
VATPIC_LOCK(vatpic);
 
-   if (vmexit-u.inout.in) {
+   if (in) {
if (is_master)
-   vmexit-u.inout.eax = vatpic-elc[0];
+   *eax = vatpic-elc[0];
else
-   

svn commit: r264631 - in head: sys/amd64/vmm sys/amd64/vmm/io usr.sbin/bhyve

2014-04-17 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 18 00:02:06 2014
New Revision: 264631
URL: http://svnweb.freebsd.org/changeset/base/264631

Log:
  Add support for reading the PIT Counter 2 output signal via the NMI
  Status and Control register at port 0x61.
  
  Be more conservative about catching up callouts that were supposed
  to fire in the past by skipping an interrupt if it was
  scheduled too far in the past.
  
  Restore the PIT ACPI DSDT entries and add an entry for NMISC too.
  
  Approved by:  neel (co-mentor)

Modified:
  head/sys/amd64/vmm/io/vatpit.c
  head/sys/amd64/vmm/io/vatpit.h
  head/sys/amd64/vmm/vmm_ioport.c
  head/usr.sbin/bhyve/pci_lpc.c

Modified: head/sys/amd64/vmm/io/vatpit.c
==
--- head/sys/amd64/vmm/io/vatpit.c  Thu Apr 17 23:31:50 2014
(r264630)
+++ head/sys/amd64/vmm/io/vatpit.c  Fri Apr 18 00:02:06 2014
(r264631)
@@ -56,6 +56,8 @@ static MALLOC_DEFINE(M_VATPIT, atpit, 
 #defineTIMER_MODE_MASK 0x0f
 #defineTIMER_SEL_READBACK  0xc0
 
+#defineTMR2_OUT_STS0x20
+
 #definePIT_8254_FREQ   1193182
 #defineTIMER_DIV(freq, hz) (((freq) + (hz) / 2) / (hz))
 
@@ -88,22 +90,29 @@ struct vatpit {
struct channel  channel[3];
 };
 
-#defineVATPIT_CTR0(vatpit, fmt)
\
-   VM_CTR0((vatpit)-vm, fmt)
-
-#defineVATPIT_CTR1(vatpit, fmt, a1)
\
-   VM_CTR1((vatpit)-vm, fmt, a1)
+static void pit_timer_start_cntr0(struct vatpit *vatpit);
 
-#defineVATPIT_CTR2(vatpit, fmt, a1, a2)
\
-   VM_CTR2((vatpit)-vm, fmt, a1, a2)
+static int
+vatpit_get_out(struct vatpit *vatpit, int channel)
+{
+   struct channel *c;
+   sbintime_t delta_ticks;
+   int out;
 
-#defineVATPIT_CTR3(vatpit, fmt, a1, a2, a3)
\
-   VM_CTR3((vatpit)-vm, fmt, a1, a2, a3)
+   c = vatpit-channel[channel];
 
-#defineVATPIT_CTR4(vatpit, fmt, a1, a2, a3, a4)
\
-   VM_CTR4((vatpit)-vm, fmt, a1, a2, a3, a4)
+   switch (c-mode) {
+   case TIMER_INTTC:
+   delta_ticks = (sbinuptime() - c-now_sbt) / vatpit-freq_sbt;
+   out = ((c-initial - delta_ticks) = 0);
+   break;
+   default:
+   out = 0;
+   break;
+   }
 
-static void pit_timer_start_cntr0(struct vatpit *vatpit);
+   return (out);
+}
 
 static void
 vatpit_callout_handler(void *a)
@@ -117,7 +126,7 @@ vatpit_callout_handler(void *a)
c = vatpit-channel[arg-channel_num];
callout = c-callout;
 
-   VATPIT_CTR1(vatpit, atpit t%d fired, arg-channel_num);
+   VM_CTR1(vatpit-vm, atpit t%d fired, arg-channel_num);
 
VATPIT_LOCK(vatpit);
 
@@ -145,7 +154,7 @@ static void
 pit_timer_start_cntr0(struct vatpit *vatpit)
 {
struct channel *c;
-   sbintime_t delta, precision;
+   sbintime_t now, delta, precision;
 
c = vatpit-channel[0];
if (c-initial != 0) {
@@ -153,6 +162,15 @@ pit_timer_start_cntr0(struct vatpit *vat
precision = delta  tc_precexp;
c-callout_sbt = c-callout_sbt + delta;
 
+   /*
+* Reset 'callout_sbt' if the time that the callout
+* was supposed to fire is more than 'c-initial'
+* ticks in the past.
+*/
+   now = sbinuptime();
+   if (c-callout_sbt  now)
+   c-callout_sbt = now + delta;
+
callout_reset_sbt(c-callout, c-callout_sbt,
precision, vatpit_callout_handler, c-callout_arg,
C_ABSOLUTE);
@@ -252,8 +270,8 @@ vatpit_handler(void *vm, int vcpuid, str
port = vmexit-u.inout.port;
 
if (port == TIMER_MODE) {
-   if (vmexit-u.inout.in != 0) {
-   VATPIT_CTR0(vatpit, vatpit attempt to read mode);
+   if (vmexit-u.inout.in) {
+   VM_CTR0(vatpit-vm, vatpit attempt to read mode);
return (-1);
}
 
@@ -310,6 +328,26 @@ vatpit_handler(void *vm, int vcpuid, str
return (0);
 }
 
+int
+vatpit_nmisc_handler(void *vm, int vcpuid, struct vm_exit *vmexit)
+{
+   struct vatpit *vatpit;
+
+   vatpit = vm_atpit(vm);
+
+   if (vmexit-u.inout.in) {
+   VATPIT_LOCK(vatpit);
+   if (vatpit_get_out(vatpit, 2))
+   vmexit-u.inout.eax = TMR2_OUT_STS;
+   else
+   vmexit-u.inout.eax = 0;
+
+   VATPIT_UNLOCK(vatpit);
+   }
+
+   return (0);
+}
+
 struct vatpit *
 vatpit_init(struct vm *vm)
 {

Modified: head/sys/amd64/vmm/io/vatpit.h

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

2014-04-15 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr 15 15:11:10 2014
New Revision: 264501
URL: http://svnweb.freebsd.org/changeset/base/264501

Log:
  Add support for emulating the byte move and sign extend instructions:
  movsx r/m8, r32 and movsx r/m8, r64.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Tue Apr 15 14:55:56 2014
(r264500)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Tue Apr 15 15:11:10 2014
(r264501)
@@ -53,6 +53,7 @@ __FBSDID($FreeBSD$);
 enum {
VIE_OP_TYPE_NONE = 0,
VIE_OP_TYPE_MOV,
+   VIE_OP_TYPE_MOVSX,
VIE_OP_TYPE_MOVZX,
VIE_OP_TYPE_AND,
VIE_OP_TYPE_OR,
@@ -69,6 +70,10 @@ static const struct vie_op two_byte_opco
.op_byte = 0xB6,
.op_type = VIE_OP_TYPE_MOVZX,
},
+   [0xBE] = {
+   .op_byte = 0xBE,
+   .op_type = VIE_OP_TYPE_MOVSX,
+   },
 };
 
 static const struct vie_op one_byte_opcodes[256] = {
@@ -333,9 +338,9 @@ emulate_mov(void *vm, int vcpuid, uint64
  * - address size override is not supported
  */
 static int
-emulate_movzx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
- mem_region_read_t memread, mem_region_write_t memwrite,
- void *arg)
+emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+mem_region_read_t memread, mem_region_write_t memwrite,
+void *arg)
 {
int error, size;
enum vm_reg_name reg;
@@ -368,6 +373,32 @@ emulate_movzx(void *vm, int vcpuid, uint
/* write the result */
error = vie_update_register(vm, vcpuid, reg, val, size);
break;
+   case 0xBE:
+   /*
+* MOV and sign extend byte from mem (ModRM:r/m) to
+* reg (ModRM:reg).
+*
+* 0F BE/r  movsx r/m8, r32
+* REX.W + 0F BE/r  movsx r/m8, r64
+*/
+
+   /* get the first operand */
+   error = memread(vm, vcpuid, gpa, val, 1, arg);
+   if (error)
+   break;
+
+   /* get the second operand */
+   reg = gpr_map[vie-reg];
+
+   if (vie-rex_w)
+   size = 8;
+
+   /* sign extend byte */
+   val = (int8_t)val;
+
+   /* write the result */
+   error = vie_update_register(vm, vcpuid, reg, val, size);
+   break;
default:
break;
}
@@ -508,9 +539,10 @@ vmm_emulate_instruction(void *vm, int vc
error = emulate_mov(vm, vcpuid, gpa, vie,
memread, memwrite, memarg);
break;
+   case VIE_OP_TYPE_MOVSX:
case VIE_OP_TYPE_MOVZX:
-   error = emulate_movzx(vm, vcpuid, gpa, vie,
- memread, memwrite, memarg);
+   error = emulate_movx(vm, vcpuid, gpa, vie,
+memread, memwrite, memarg);
break;
case VIE_OP_TYPE_AND:
error = emulate_and(vm, vcpuid, gpa, vie,
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-04-15 Thread Tycho Nightingale
Author: tychon
Date: Tue Apr 15 17:06:26 2014
New Revision: 264509
URL: http://svnweb.freebsd.org/changeset/base/264509

Log:
  Local APIC access via 32-bit naturally-aligned loads is merely
  suggested in the SDM.  Since some OSes have implemented otherwise
  don't be too rigorous in enforcing it.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/sys/amd64/vmm/vmm_lapic.c
==
--- head/sys/amd64/vmm/vmm_lapic.c  Tue Apr 15 16:31:23 2014
(r264508)
+++ head/sys/amd64/vmm/vmm_lapic.c  Tue Apr 15 17:06:26 2014
(r264509)
@@ -230,10 +230,12 @@ lapic_mmio_read(void *vm, int cpu, uint6
off = gpa - DEFAULT_APIC_BASE;
 
/*
-* Memory mapped local apic accesses must be 4 bytes wide and
-* aligned on a 16-byte boundary.
+* Memory mapped local apic accesses should be aligned on a
+* 16-byte boundary.  They are also suggested to be 4 bytes
+* wide, alas not all OSes follow suggestions.
 */
-   if (size != 4 || off  0xf)
+   off = ~3;
+   if (off  0xf)
return (EINVAL);
 
vlapic = vm_lapic(vm, cpu);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r264468 - in head: lib/libvmmapi sys/amd64/vmm/io usr.sbin/bhyve

2014-04-14 Thread Tycho Nightingale
Author: tychon
Date: Mon Apr 14 19:00:20 2014
New Revision: 264468
URL: http://svnweb.freebsd.org/changeset/base/264468

Log:
  Add support for emulating the slave PIC.
  
  Reviewed by:  grehan, jhb
  Approved by:  grehan (co-mentor)

Modified:
  head/lib/libvmmapi/vmmapi.h
  head/sys/amd64/vmm/io/vatpic.c
  head/usr.sbin/bhyve/pm.c

Modified: head/lib/libvmmapi/vmmapi.h
==
--- head/lib/libvmmapi/vmmapi.h Mon Apr 14 18:38:14 2014(r264467)
+++ head/lib/libvmmapi/vmmapi.h Mon Apr 14 19:00:20 2014(r264468)
@@ -72,9 +72,9 @@ int   vm_ioapic_assert_irq(struct vmctx *c
 intvm_ioapic_deassert_irq(struct vmctx *ctx, int irq);
 intvm_ioapic_pulse_irq(struct vmctx *ctx, int irq);
 intvm_ioapic_pincount(struct vmctx *ctx, int *pincount);
+intvm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
 intvm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
 intvm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
-intvm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
 intvm_inject_nmi(struct vmctx *ctx, int vcpu);
 intvm_capability_name2type(const char *capname);
 const char *vm_capability_type2name(int type);

Modified: head/sys/amd64/vmm/io/vatpic.c
==
--- head/sys/amd64/vmm/io/vatpic.c  Mon Apr 14 18:38:14 2014
(r264467)
+++ head/sys/amd64/vmm/io/vatpic.c  Mon Apr 14 19:00:20 2014
(r264468)
@@ -67,6 +67,7 @@ struct atpic {
boolaeoi;
boolpoll;
boolrotate;
+   boolsfn;/* special fully-nested mode */
 
int irq_base;
uint8_t request;/* Interrupt Request Register (IIR) */
@@ -75,6 +76,8 @@ struct atpic {
 
int acnt[8];/* sum of pin asserts and deasserts */
int priority;   /* current pin priority */
+
+   boolintr_raised;
 };
 
 struct vatpic {
@@ -82,8 +85,6 @@ struct vatpic {
struct mtx  mtx;
struct atpicatpic[2];
uint8_t elc[2];
-
-   boolintr_raised;
 };
 
 #defineVATPIC_CTR0(vatpic, fmt)
\
@@ -101,6 +102,7 @@ struct vatpic {
 #defineVATPIC_CTR4(vatpic, fmt, a1, a2, a3, a4)
\
VM_CTR4((vatpic)-vm, fmt, a1, a2, a3, a4)
 
+static void vatpic_set_pinstate(struct vatpic *vatpic, int pin, bool newstate);
 
 static __inline int
 vatpic_get_highest_isrpin(struct atpic *atpic)
@@ -122,13 +124,23 @@ vatpic_get_highest_isrpin(struct atpic *
 static __inline int
 vatpic_get_highest_irrpin(struct atpic *atpic)
 {
+   int serviced;
int bit, pin;
int i, j;
 
+   /*
+* In 'Special Fully-Nested Mode' when an interrupt request from
+* a slave is in service, the slave is not locked out from the
+* master's priority logic.
+*/
+   serviced = atpic-service;
+   if (atpic-sfn)
+   serviced = ~(1  2);
+
for (i = 0; i = 7; i++) {
pin = ((i + 7 - atpic-priority)  0x7);
bit = (1  pin);
-   if (atpic-service  bit)
+   if (serviced  bit)
break;
}
 
@@ -150,14 +162,35 @@ vatpic_notify_intr(struct vatpic *vatpic
 
KASSERT(VATPIC_LOCKED(vatpic), (vatpic_notify_intr not locked));
 
-   if (vatpic-intr_raised == true)
-   return;
+   /*
+* First check the slave.
+*/
+   atpic = vatpic-atpic[1];
+   if (!atpic-intr_raised 
+   (pin = vatpic_get_highest_irrpin(atpic)) != -1) {
+   VATPIC_CTR4(vatpic, atpic slave notify pin = %d 
+   (imr 0x%x irr 0x%x isr 0x%x), pin,
+   atpic-mask, atpic-request, atpic-service);
 
-   /* XXX master only */
-   atpic = vatpic-atpic[0];
+   /*
+* Cascade the request from the slave to the master.
+*/
+   atpic-intr_raised = true;
+   vatpic_set_pinstate(vatpic, 2, true);
+   vatpic_set_pinstate(vatpic, 2, false);
+   } else {
+   VATPIC_CTR3(vatpic, atpic slave no eligible interrupts 
+   (imr 0x%x irr 0x%x isr 0x%x),
+   atpic-mask, atpic-request, atpic-service);
+   }
 
-   if ((pin = vatpic_get_highest_irrpin(atpic)) != -1) {
-   VATPIC_CTR4(vatpic, atpic notify pin = %d 
+   /*
+* Then check the master.
+*/
+   atpic = vatpic-atpic[0];
+   if (!atpic-intr_raised 
+   (pin = vatpic_get_highest_irrpin(atpic)) != -1) {
+   VATPIC_CTR4(vatpic, atpic master notify pin = %d 
(imr 0x%x irr 0x%x isr 0x%x), pin,
  

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

2014-04-11 Thread Tycho Nightingale
Author: tychon
Date: Fri Apr 11 18:19:21 2014
New Revision: 264347
URL: http://svnweb.freebsd.org/changeset/base/264347

Log:
  Account for the plus 1 encoding of the CPUID Function 4 reported
  core per package and cache sharing values.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/sys/amd64/vmm/x86.c
==
--- head/sys/amd64/vmm/x86.cFri Apr 11 16:55:25 2014(r264346)
+++ head/sys/amd64/vmm/x86.cFri Apr 11 18:19:21 2014(r264347)
@@ -219,9 +219,18 @@ x86_emulate_cpuid(struct vm *vm, int vcp
 
/*
 * Do not expose topology.
+*
+* The maximum number of processor cores in
+* this physical processor package and the
+* maximum number of threads sharing this
+* cache are encoded with plus 1 encoding.
+* Adding one to the value in this register
+* field to obtains the actual value.
+*
+* Therefore 0 for both indicates 1 core per
+* package and no cache sharing.
 */
regs[0] = 0x8000;
-   regs[0] |= 0x04008000;
break;
 
case CPUID__0007:
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-04-09 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr  9 14:50:55 2014
New Revision: 264302
URL: http://svnweb.freebsd.org/changeset/base/264302

Log:
  Constrain the amount of data returned to what is actually available
  not the size of the buffer.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Wed Apr  9 13:35:52 2014
(r264301)
+++ head/usr.sbin/bhyve/pci_ahci.c  Wed Apr  9 14:50:55 2014
(r264302)
@@ -543,12 +543,14 @@ write_prdt(struct ahci_port *p, int slot
for (i = 0; i  hdr-prdtl  len; i++) {
uint8_t *ptr;
uint32_t dbcsz;
+   int sublen;
 
dbcsz = (prdt-dbc  DBCMASK) + 1;
ptr = paddr_guest2host(ahci_ctx(p-pr_sc), prdt-dba, dbcsz);
-   memcpy(ptr, from, dbcsz);
-   len -= dbcsz;
-   from += dbcsz;
+   sublen = len  dbcsz ? len : dbcsz;
+   memcpy(ptr, from, sublen);
+   len -= sublen;
+   from += sublen;
prdt++;
}
hdr-prdbc = size - len;
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r263744 - in head: sys/amd64/include sys/amd64/vmm sys/amd64/vmm/io sys/modules/vmm usr.sbin/bhyve

2014-03-25 Thread Tycho Nightingale
Author: tychon
Date: Tue Mar 25 19:20:34 2014
New Revision: 263744
URL: http://svnweb.freebsd.org/changeset/base/263744

Log:
  Move the atpit device model from userspace into vmm.ko for better
  precision and lower latency.
  
  Approved by:  grehan (co-mentor)

Added:
  head/sys/amd64/vmm/io/vatpit.c   (contents, props changed)
  head/sys/amd64/vmm/io/vatpit.h   (contents, props changed)
Deleted:
  head/usr.sbin/bhyve/pit_8254.c
  head/usr.sbin/bhyve/pit_8254.h
Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_ioport.c
  head/sys/modules/vmm/Makefile
  head/usr.sbin/bhyve/Makefile

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hTue Mar 25 19:17:22 2014
(r263743)
+++ head/sys/amd64/include/vmm.hTue Mar 25 19:20:34 2014
(r263744)
@@ -191,6 +191,7 @@ struct vmspace *vm_get_vmspace(struct vm
 int vm_assign_pptdev(struct vm *vm, int bus, int slot, int func);
 int vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func);
 struct vatpic *vm_atpic(struct vm *vm);
+struct vatpit *vm_atpit(struct vm *vm);
 
 /*
  * Inject exception 'vme' into the guest vcpu. This function returns 0 on

Added: head/sys/amd64/vmm/io/vatpit.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/amd64/vmm/io/vatpit.c  Tue Mar 25 19:20:34 2014
(r263744)
@@ -0,0 +1,370 @@
+/*-
+ * Copyright (c) 2014 Tycho Nightingale 
tycho.nighting...@pluribusnetworks.com
+ * Copyright (c) 2011 NetApp, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``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 NETAPP, INC 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 sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/param.h
+#include sys/types.h
+#include sys/queue.h
+#include sys/cpuset.h
+#include sys/kernel.h
+#include sys/lock.h
+#include sys/malloc.h
+#include sys/mutex.h
+#include sys/systm.h
+
+#include machine/vmm.h
+
+#include vmm_ktr.h
+#include vatpic.h
+#include vioapic.h
+#include vatpit.h
+
+static MALLOC_DEFINE(M_VATPIT, atpit, bhyve virtual atpit (8254));
+
+#defineVATPIT_LOCK(vatpit) mtx_lock_spin(((vatpit)-mtx))
+#defineVATPIT_UNLOCK(vatpit)   
mtx_unlock_spin(((vatpit)-mtx))
+#defineVATPIT_LOCKED(vatpit)   mtx_owned(((vatpit)-mtx))
+
+#defineTIMER_SEL_MASK  0xc0
+#defineTIMER_RW_MASK   0x30
+#defineTIMER_MODE_MASK 0x0f
+#defineTIMER_SEL_READBACK  0xc0
+
+#definePIT_8254_FREQ   1193182
+#defineTIMER_DIV(freq, hz) (((freq) + (hz) / 2) / (hz))
+
+struct vatpit_callout_arg {
+   struct vatpit   *vatpit;
+   int channel_num;
+};
+
+
+struct channel {
+   int mode;
+   uint16_tinitial;/* initial counter value */
+   sbintime_t  now_sbt;/* uptime when counter was loaded */
+   uint8_t cr[2];
+   uint8_t ol[2];
+   int crbyte;
+   int olbyte;
+   int frbyte;
+   struct callout  callout;
+   sbintime_t  callout_sbt;/* target time */
+   struct vatpit_callout_arg callout_arg;
+};
+
+struct vatpit {
+   struct vm   *vm;
+   struct mtx  mtx;
+
+   sbintime_t  freq_sbt;
+
+   struct channel  channel[3];
+};
+
+#defineVATPIT_CTR0(vatpit, fmt)
\
+   VM_CTR0((vatpit)-vm, fmt)
+
+#defineVATPIT_CTR1(vatpit, fmt, a1)
\
+   VM_CTR1((vatpit)-vm, fmt, a1)
+
+#define

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

2014-03-18 Thread Tycho Nightingale
Author: tychon
Date: Tue Mar 18 23:25:35 2014
New Revision: 263322
URL: http://svnweb.freebsd.org/changeset/base/263322

Log:
  Don't reissue in-flight commands.
  
  Approved by:  neel (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Tue Mar 18 22:22:47 2014
(r263321)
+++ head/usr.sbin/bhyve/pci_ahci.c  Tue Mar 18 23:25:35 2014
(r263322)
@@ -134,6 +134,7 @@ struct ahci_port {
uint8_t xfermode;
uint8_t sense_key;
uint8_t asc;
+   uint32_t pending;
 
uint32_t clb;
uint32_t clbu;
@@ -471,6 +472,10 @@ ahci_handle_dma(struct ahci_port *p, int
if (iovcnt  BLOCKIF_IOV_MAX) {
aior-prdtl = iovcnt - BLOCKIF_IOV_MAX;
iovcnt = BLOCKIF_IOV_MAX;
+   /*
+* Mark this command in-flight.
+*/
+   p-pending |= 1  slot;
} else
aior-prdtl = 0;
breq-br_iovcnt = iovcnt;
@@ -494,7 +499,7 @@ ahci_handle_dma(struct ahci_port *p, int
err = blockif_write(p-bctx, breq);
assert(err == 0);
 
-   if (!aior-prdtl  ncq)
+   if (ncq)
p-ci = ~(1  slot);
 }
 
@@ -1327,8 +1332,12 @@ ahci_handle_port(struct ahci_port *p)
if (!(p-cmd  AHCI_P_CMD_ST))
return;
 
+   /*
+* Search for any new commands to issue ignoring those that
+* are already in-flight.
+*/
for (i = 0; (i  32)  p-ci; i++) {
-   if (p-ci  (1  i))
+   if ((p-ci  (1  i))  !(p-pending  (1  i)))
ahci_handle_slot(p, i);
}
 }
@@ -1389,6 +1398,11 @@ ata_ioreq_cb(struct blockif_req *br, int
p-serr |= (1  slot);
}
 
+   /*
+* This command is now complete.
+*/
+   p-pending = ~(1  slot);
+
if (ncq) {
p-sact = ~(1  slot);
ahci_write_fis_sdb(p, slot, tfd);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-03-16 Thread Tycho Nightingale
Author: tychon
Date: Sun Mar 16 12:31:28 2014
New Revision: 263236
URL: http://svnweb.freebsd.org/changeset/base/263236

Log:
  Support the bootloader's single 16-bit 'outw' access to the Divisor
  Latch MSB and LSB registers.
  
  Approved by:  neel (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_lpc.c
==
--- head/usr.sbin/bhyve/pci_lpc.c   Sun Mar 16 11:06:05 2014
(r263235)
+++ head/usr.sbin/bhyve/pci_lpc.c   Sun Mar 16 12:31:28 2014
(r263236)
@@ -125,15 +125,27 @@ lpc_uart_io_handler(struct vmctx *ctx, i
int offset;
struct lpc_uart_softc *sc = arg;
 
-   if (bytes != 1)
-   return (-1);
-
offset = port - sc-iobase;
 
-   if (in)
-   *eax = uart_read(sc-uart_softc, offset); 
-   else
-   uart_write(sc-uart_softc, offset, *eax);
+   switch (bytes) {
+   case 1:
+   if (in)
+   *eax = uart_read(sc-uart_softc, offset);
+   else
+   uart_write(sc-uart_softc, offset, *eax);
+   break;
+   case 2:
+   if (in) {
+   *eax = uart_read(sc-uart_softc, offset);
+   *eax |= uart_read(sc-uart_softc, offset + 1)  8;
+   } else {
+   uart_write(sc-uart_softc, offset, *eax);
+   uart_write(sc-uart_softc, offset + 1, *eax  8);
+   }
+   break;
+   default:
+   return (-1);
+   }
 
return (0);
 }
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-03-16 Thread Tycho Nightingale
Author: tychon
Date: Sun Mar 16 12:33:40 2014
New Revision: 263238
URL: http://svnweb.freebsd.org/changeset/base/263238

Log:
  Though there currently isn't a way to insert new media into an ATAPI
  drive, at least pretend to support Asynchronous Notification (AN) to
  avoid a guest needlessly polling for it.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Sun Mar 16 12:32:16 2014
(r263237)
+++ head/usr.sbin/bhyve/pci_ahci.c  Sun Mar 16 12:33:40 2014
(r263238)
@@ -95,6 +95,13 @@ enum sata_fis_type {
 #defineMODEPAGE_CD_CAPABILITIES0x2A
 
 /*
+ * ATA commands
+ */
+#defineATA_SF_ENAB_SATA_SF 0x10
+#defineATA_SATA_SF_AN  0x05
+#defineATA_SF_DIS_SATA_SF  0x90
+
+/*
  * Debug printf
  */
 #ifdef AHCI_DEBUG
@@ -1169,6 +1176,17 @@ ahci_handle_cmd(struct ahci_port *p, int
case ATA_SETFEATURES:
{
switch (cfis[3]) {
+   case ATA_SF_ENAB_SATA_SF:
+   switch (cfis[12]) {
+   case ATA_SATA_SF_AN:
+   p-tfd = ATA_S_DSC | ATA_S_READY;
+   break;
+   default:
+   p-tfd = ATA_S_ERROR | ATA_S_READY;
+   p-tfd |= (ATA_ERROR_ABORT  8);
+   break;
+   }
+   break;
case ATA_SF_ENAB_WCACHE:
case ATA_SF_DIS_WCACHE:
case ATA_SF_ENAB_RCACHE:
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r263211 - in head/sys/amd64: include vmm vmm/intel vmm/io

2014-03-15 Thread Tycho Nightingale
Author: tychon
Date: Sat Mar 15 23:09:34 2014
New Revision: 263211
URL: http://svnweb.freebsd.org/changeset/base/263211

Log:
  Fix a race wherein the source of an interrupt vector is wrongly
  attributed if an ExtINT arrives during interrupt injection.
  
  Also, fix a spurious interrupt if the PIC tries to raise an interrupt
  before the outstanding one is accepted.
  
  Finally, improve the PIC interrupt latency when another interrupt is
  raised immediately after the outstanding one is accepted by creating a
  vmexit rather than waiting for one to occur by happenstance.
  
  Approved by:  neel (co-mentor)

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/amd64/vmm/io/vatpic.c
  head/sys/amd64/vmm/io/vatpic.h
  head/sys/amd64/vmm/io/vlapic.c
  head/sys/amd64/vmm/io/vlapic_priv.h
  head/sys/amd64/vmm/vmm.c

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hSat Mar 15 21:58:07 2014
(r263210)
+++ head/sys/amd64/include/vmm.hSat Mar 15 23:09:34 2014
(r263211)
@@ -117,6 +117,9 @@ int vm_run(struct vm *vm, struct vm_run 
 int vm_inject_nmi(struct vm *vm, int vcpu);
 int vm_nmi_pending(struct vm *vm, int vcpuid);
 void vm_nmi_clear(struct vm *vm, int vcpuid);
+int vm_inject_extint(struct vm *vm, int vcpu);
+int vm_extint_pending(struct vm *vm, int vcpuid);
+void vm_extint_clear(struct vm *vm, int vcpuid);
 uint64_t *vm_guest_msrs(struct vm *vm, int cpu);
 struct vlapic *vm_lapic(struct vm *vm, int cpu);
 struct vioapic *vm_ioapic(struct vm *vm);

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Sat Mar 15 21:58:07 2014
(r263210)
+++ head/sys/amd64/vmm/intel/vmx.c  Sat Mar 15 23:09:34 2014
(r263211)
@@ -57,6 +57,7 @@ __FBSDID($FreeBSD$);
 #include vmm_msr.h
 #include vmm_ktr.h
 #include vmm_stat.h
+#include vatpic.h
 #include vlapic.h
 #include vlapic_priv.h
 
@@ -1144,7 +1145,7 @@ static void
 vmx_inject_interrupts(struct vmx *vmx, int vcpu, struct vlapic *vlapic)
 {
struct vm_exception exc;
-   int vector, need_nmi_exiting;
+   int vector, need_nmi_exiting, extint_pending;
uint64_t rflags;
uint32_t gi, info;
 
@@ -1196,7 +1197,9 @@ vmx_inject_interrupts(struct vmx *vmx, i
vmx_set_nmi_window_exiting(vmx, vcpu);
}
 
-   if (virtual_interrupt_delivery) {
+   extint_pending = vm_extint_pending(vmx-vm, vcpu);
+
+   if (!extint_pending  virtual_interrupt_delivery) {
vmx_inject_pir(vlapic);
return;
}
@@ -1212,9 +1215,14 @@ vmx_inject_interrupts(struct vmx *vmx, i
return;
}
 
-   /* Ask the local apic for a vector to inject */
-   if (!vlapic_pending_intr(vlapic, vector))
-   return;
+   if (!extint_pending) {
+   /* Ask the local apic for a vector to inject */
+   if (!vlapic_pending_intr(vlapic, vector))
+   return;
+   } else {
+   /* Ask the legacy pic for a vector to inject */
+   vatpic_pending_intr(vmx-vm, vector);
+   }
 
KASSERT(vector = 32  vector = 255, (invalid vector %d, vector));
 
@@ -1252,8 +1260,22 @@ vmx_inject_interrupts(struct vmx *vmx, i
info |= vector;
vmcs_write(VMCS_ENTRY_INTR_INFO, info);
 
-   /* Update the Local APIC ISR */
-   vlapic_intr_accepted(vlapic, vector);
+   if (!extint_pending) {
+   /* Update the Local APIC ISR */
+   vlapic_intr_accepted(vlapic, vector);
+   } else {
+   vm_extint_clear(vmx-vm, vcpu);
+   vatpic_intr_accepted(vmx-vm, vector);
+
+   /*
+* After we accepted the current ExtINT the PIC may
+* have posted another one.  If that is the case, set
+* the Interrupt Window Exiting execution control so
+* we can inject that one too.
+*/
+   if (vm_extint_pending(vmx-vm, vcpu))
+   vmx_set_int_window_exiting(vmx, vcpu);
+   }
 
VCPU_CTR1(vmx-vm, vcpu, Injecting hwintr at vector %d, vector);
 

Modified: head/sys/amd64/vmm/io/vatpic.c
==
--- head/sys/amd64/vmm/io/vatpic.c  Sat Mar 15 21:58:07 2014
(r263210)
+++ head/sys/amd64/vmm/io/vatpic.c  Sat Mar 15 23:09:34 2014
(r263211)
@@ -82,6 +82,8 @@ struct vatpic {
struct mtx  mtx;
struct atpicatpic[2];
uint8_t elc[2];
+
+   boolintr_raised;
 };
 
 #defineVATPIC_CTR0(vatpic, fmt)
\
@@ -148,6 +150,9 @@ vatpic_notify_intr(struct vatpic *vatpic
 

svn commit: r263035 - in head: lib/libvmmapi sys/amd64/include sys/amd64/vmm sys/amd64/vmm/intel sys/amd64/vmm/io sys/modules/vmm usr.sbin/bhyve

2014-03-11 Thread Tycho Nightingale
 @@ enum {
_IOW('v', IOCNUM_IOAPIC_PULSE_IRQ, struct vm_ioapic_irq)
 #defineVM_IOAPIC_PINCOUNT  \
_IOR('v', IOCNUM_IOAPIC_PINCOUNT, int)
+#defineVM_ISA_ASSERT_IRQ   \
+   _IOW('v', IOCNUM_ISA_ASSERT_IRQ, struct vm_isa_irq)
+#defineVM_ISA_DEASSERT_IRQ \
+   _IOW('v', IOCNUM_ISA_DEASSERT_IRQ, struct vm_isa_irq)
+#defineVM_ISA_PULSE_IRQ\
+   _IOW('v', IOCNUM_ISA_PULSE_IRQ, struct vm_isa_irq)
 #defineVM_SET_CAPABILITY \
_IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability)
 #defineVM_GET_CAPABILITY \

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Tue Mar 11 16:53:03 2014
(r263034)
+++ head/sys/amd64/vmm/intel/vmx.c  Tue Mar 11 16:56:00 2014
(r263035)
@@ -52,6 +52,7 @@ __FBSDID($FreeBSD$);
 #include machine/vmm.h
 #include machine/vmm_dev.h
 #include vmm_host.h
+#include vmm_ioport.h
 #include vmm_ipi.h
 #include vmm_msr.h
 #include vmm_ktr.h
@@ -1861,6 +1862,11 @@ vmx_exit_process(struct vmx *vmx, int vc
vmexit-u.inout.rep = (qual  0x20) ? 1 : 0;
vmexit-u.inout.port = (uint16_t)(qual  16);
vmexit-u.inout.eax = (uint32_t)(vmxctx-guest_rax);
+   error = emulate_ioport(vmx-vm, vcpu, vmexit);
+   if (error == 0)  {
+   handled = 1;
+   vmxctx-guest_rax = vmexit-u.inout.eax;
+   }
break;
case EXIT_REASON_CPUID:
vmm_stat_incr(vmx-vm, vcpu, VMEXIT_CPUID, 1);

Added: head/sys/amd64/vmm/io/vatpic.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/amd64/vmm/io/vatpic.c  Tue Mar 11 16:56:00 2014
(r263035)
@@ -0,0 +1,595 @@
+/*-
+ * Copyright (c) 2014 Tycho Nightingale 
tycho.nighting...@pluribusnetworks.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/param.h
+#include sys/types.h
+#include sys/queue.h
+#include sys/cpuset.h
+#include sys/kernel.h
+#include sys/lock.h
+#include sys/malloc.h
+#include sys/mutex.h
+#include sys/systm.h
+
+#include x86/apicreg.h
+#include dev/ic/i8259.h
+
+#include machine/vmm.h
+
+#include vmm_ktr.h
+#include vmm_lapic.h
+#include vioapic.h
+#include vatpic.h
+
+static MALLOC_DEFINE(M_VATPIC, atpic, bhyve virtual atpic (8259));
+
+#defineVATPIC_LOCK(vatpic) mtx_lock_spin(((vatpic)-mtx))
+#defineVATPIC_UNLOCK(vatpic)   
mtx_unlock_spin(((vatpic)-mtx))
+#defineVATPIC_LOCKED(vatpic)   mtx_owned(((vatpic)-mtx))
+
+enum irqstate {
+   IRQSTATE_ASSERT,
+   IRQSTATE_DEASSERT,
+   IRQSTATE_PULSE
+};
+
+struct atpic {
+   boolready;
+   int icw_num;
+   int rd_cmd_reg;
+
+   boolaeoi;
+   boolpoll;
+   boolrotate;
+
+   int irq_base;
+   uint8_t request;/* Interrupt Request Register (IIR) */
+   uint8_t service;/* Interrupt Service (ISR) */
+   uint8_t mask;   /* Interrupt Mask Register (IMR) */
+
+   int acnt[8];/* sum of pin asserts and deasserts */
+   int priority;   /* current pin priority */
+};
+
+struct vatpic {
+   struct vm   *vm;
+   struct mtx  mtx;
+   struct atpicatpic[2];
+   uint8_t elc[2];
+};
+
+#defineVATPIC_CTR0(vatpic, fmt

svn commit: r263054 - head/sys/amd64/vmm/io

2014-03-11 Thread Tycho Nightingale
Author: tychon
Date: Tue Mar 11 22:12:12 2014
New Revision: 263054
URL: http://svnweb.freebsd.org/changeset/base/263054

Log:
  Don't try to return a vector to a caller that only cares if a vector
  is pending or not.
  
  Approved by:  neel (co-mentor)

Modified:
  head/sys/amd64/vmm/io/vlapic.c

Modified: head/sys/amd64/vmm/io/vlapic.c
==
--- head/sys/amd64/vmm/io/vlapic.c  Tue Mar 11 22:11:45 2014
(r263053)
+++ head/sys/amd64/vmm/io/vlapic.c  Tue Mar 11 22:12:12 2014
(r263054)
@@ -1053,8 +1053,12 @@ vlapic_pending_intr(struct vlapic *vlapi
int  idx, i, bitpos, vector;
uint32_t*irrptr, val;
 
-   if (vlapic-extint_pending)
-   return (vatpic_pending_intr(vlapic-vm, vecptr));
+   if (vlapic-extint_pending) {
+   if (vecptr == NULL)
+   return (1);
+   else
+   return (vatpic_pending_intr(vlapic-vm, vecptr));
+   }
 
if (vlapic-ops.pending_intr)
return ((*vlapic-ops.pending_intr)(vlapic, vecptr));
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-03-04 Thread Tycho Nightingale
 @@
 
 struct vmctx;
 extern int guest_ncpus;
+extern char *guest_uuid_str;
 extern char *vmname;
 
 void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);

Added: head/usr.sbin/bhyve/smbiostbl.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/bhyve/smbiostbl.c Tue Mar  4 17:12:06 2014
(r262744)
@@ -0,0 +1,832 @@
+/*-
+ * Copyright (c) 2014 Tycho Nightingale 
tycho.nighting...@pluribusnetworks.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/param.h
+
+#include assert.h
+#include errno.h
+#include md5.h
+#include stdio.h
+#include string.h
+#include unistd.h
+#include uuid.h
+
+#include machine/vmm.h
+#include vmmapi.h
+
+#include bhyverun.h
+#include smbiostbl.h
+
+#defineMB  (1024*1024)
+#defineGB  (1024ULL*1024*1024)
+
+#define SMBIOS_BASE0xF1000
+
+/* BHYVE_ACPI_BASE - SMBIOS_BASE) */
+#defineSMBIOS_MAX_LENGTH   (0xF2400 - 0xF1000)
+
+#defineSMBIOS_TYPE_BIOS0
+#defineSMBIOS_TYPE_SYSTEM  1
+#defineSMBIOS_TYPE_CHASSIS 3
+#defineSMBIOS_TYPE_PROCESSOR   4
+#defineSMBIOS_TYPE_MEMARRAY16
+#defineSMBIOS_TYPE_MEMDEVICE   17
+#defineSMBIOS_TYPE_MEMARRAYMAP 19
+#defineSMBIOS_TYPE_BOOT32
+#defineSMBIOS_TYPE_EOT 127
+
+struct smbios_structure {
+   uint8_t type;
+   uint8_t length;
+   uint16_thandle;
+} __packed;
+
+typedef int (*initializer_func_t)(struct smbios_structure *template_entry,
+const char **template_strings, char *curaddr, char **endaddr,
+uint16_t *n, uint16_t *size);
+
+struct smbios_template_entry {
+   struct smbios_structure *entry;
+   const char  **strings;
+   initializer_func_t  initializer;
+};
+
+/*
+ * SMBIOS Structure Table Entry Point
+ */
+#defineSMBIOS_ENTRY_EANCHOR_SM_
+#defineSMBIOS_ENTRY_EANCHORLEN 4
+#defineSMBIOS_ENTRY_IANCHOR_DMI_
+#defineSMBIOS_ENTRY_IANCHORLEN 5
+
+struct smbios_entry_point {
+   chareanchor[4]; /* anchor tag */
+   uint8_t echecksum;  /* checksum of entry point structure */
+   uint8_t eplen;  /* length in bytes of entry point */
+   uint8_t major;  /* major version of the SMBIOS spec */
+   uint8_t minor;  /* minor version of the SMBIOS spec */
+   uint16_tmaxssize;   /* maximum size in bytes of a struct */
+   uint8_t revision;   /* entry point structure revision */
+   uint8_t format[5];  /* entry point rev-specific data */
+   charianchor[5]; /* intermediate anchor tag */
+   uint8_t ichecksum;  /* intermediate checksum */
+   uint16_tstlen;  /* len in bytes of structure table */
+   uint32_tstaddr; /* physical addr of structure table */
+   uint16_tstnum;  /* number of structure table entries */
+   uint8_t bcdrev; /* BCD value representing DMI ver */
+} __packed;
+
+/*
+ * BIOS Information
+ */
+#defineSMBIOS_FL_ISA   0x0010  /* ISA is supported */
+#defineSMBIOS_FL_PCI   0x0080  /* PCI is supported */
+#defineSMBIOS_FL_SHADOW0x1000  /* BIOS shadowing is 
allowed */
+#defineSMBIOS_FL_CDBOOT0x8000  /* Boot from CD is 
supported */
+#define

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

2014-02-20 Thread Tycho Nightingale
Author: tychon
Date: Fri Feb 21 01:15:26 2014
New Revision: 262274
URL: http://svnweb.freebsd.org/changeset/base/262274

Log:
  Avoid clobbering the counter mode when issuing a latch command.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/pit_8254.c
==
--- head/usr.sbin/bhyve/pit_8254.c  Thu Feb 20 23:43:49 2014
(r262273)
+++ head/usr.sbin/bhyve/pit_8254.c  Fri Feb 21 01:15:26 2014
(r262274)
@@ -216,11 +216,12 @@ pit_8254_handler(struct vmctx *ctx, int 

c = counter[sel  6];
c-ctx = ctx;
-   c-mode = mode;
if (rw == TIMER_LATCH)
pit_update_counter(c, 1);
-   else
+   else {
+   c-mode = mode;
c-olbyte = 0;  /* reset latch after reprogramming */
+   }

return (0);
}
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-02-11 Thread Tycho Nightingale
Author: tychon
Date: Wed Feb 12 00:32:14 2014
New Revision: 261785
URL: http://svnweb.freebsd.org/changeset/base/261785

Log:
  Provide an indication a PIO Setup Device to Host FIS occurred while 
executing
  the IDENTIFY DEVICE and IDENTIFY PACKET DEVICE commands.
  
  Also, provide an indication a D2H Register FIS occurred during a SET 
FEATURES
  command.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Tue Feb 11 23:11:11 2014
(r261784)
+++ head/usr.sbin/bhyve/pci_ahci.c  Wed Feb 12 00:32:14 2014
(r261785)
@@ -254,6 +254,16 @@ ahci_write_fis(struct ahci_port *p, enum
 }
 
 static void
+ahci_write_fis_piosetup(struct ahci_port *p)
+{
+   uint8_t fis[20];
+
+   memset(fis, 0, sizeof(fis));
+   fis[0] = FIS_TYPE_PIOSETUP;
+   ahci_write_fis(p, FIS_TYPE_PIOSETUP, fis);
+}
+
+static void
 ahci_write_fis_sdb(struct ahci_port *p, int slot, uint32_t tfd)
 {
uint8_t fis[8];
@@ -587,6 +597,7 @@ handle_identify(struct ahci_port *p, int
buf[101] = (sectors  16);
buf[102] = (sectors  32);
buf[103] = (sectors  48);
+   ahci_write_fis_piosetup(p);
write_prdt(p, slot, cfis, (void *)buf, sizeof(buf));
p-tfd = ATA_S_DSC | ATA_S_READY;
p-is |= AHCI_P_IX_DP;
@@ -629,6 +640,7 @@ handle_atapi_identify(struct ahci_port *
buf[85] = (1  4);
buf[87] = (1  14);
buf[88] = (1  14 | 0x7f);
+   ahci_write_fis_piosetup(p);
write_prdt(p, slot, cfis, (void *)buf, sizeof(buf));
p-tfd = ATA_S_DSC | ATA_S_READY;
p-is |= AHCI_P_IX_DHR;
@@ -1182,9 +1194,7 @@ ahci_handle_cmd(struct ahci_port *p, int
p-tfd |= (ATA_ERROR_ABORT  8);
break;
}
-   p-is |= AHCI_P_IX_DP;
-   p-ci = ~(1  slot);
-   ahci_generate_intr(p-pr_sc);
+   ahci_write_fis_d2h(p, slot, cfis, p-tfd);
break;
}
case ATA_SET_MULTI:
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-02-04 Thread Tycho Nightingale
Author: tychon
Date: Wed Feb  5 02:01:08 2014
New Revision: 261503
URL: http://svnweb.freebsd.org/changeset/base/261503

Log:
  Add support for emulating the byte move and zero extend instructions:
  mov r/m8, r32 and mov r/m8, r64.
  
  Approved by:  neel (co-mentor)

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

Modified: head/sys/amd64/vmm/vmm_instruction_emul.c
==
--- head/sys/amd64/vmm/vmm_instruction_emul.c   Wed Feb  5 02:00:31 2014
(r261502)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Wed Feb  5 02:01:08 2014
(r261503)
@@ -58,8 +58,10 @@ enum cpu_mode {
 enum {
VIE_OP_TYPE_NONE = 0,
VIE_OP_TYPE_MOV,
+   VIE_OP_TYPE_MOVZX,
VIE_OP_TYPE_AND,
VIE_OP_TYPE_OR,
+   VIE_OP_TYPE_TWO_BYTE,
VIE_OP_TYPE_LAST
 };
 
@@ -67,7 +69,18 @@ enum {
 #defineVIE_OP_F_IMM(1  0)/* immediate operand 
present */
 #defineVIE_OP_F_IMM8   (1  1)/* 8-bit immediate 
operand */
 
+static const struct vie_op two_byte_opcodes[256] = {
+   [0xB6] = {
+   .op_byte = 0xB6,
+   .op_type = VIE_OP_TYPE_MOVZX,
+   },
+};
+
 static const struct vie_op one_byte_opcodes[256] = {
+   [0x0F] = {
+   .op_byte = 0x0F,
+   .op_type = VIE_OP_TYPE_TWO_BYTE
+   },
[0x88] = {
.op_byte = 0x88,
.op_type = VIE_OP_TYPE_MOV,
@@ -313,6 +326,59 @@ emulate_mov(void *vm, int vcpuid, uint64
return (error);
 }
 
+/*
+ * The following simplifying assumptions are made during emulation:
+ *
+ * - guest is in 64-bit mode
+ *   - default address size is 64-bits
+ *   - default operand size is 32-bits
+ *
+ * - operand size override is not supported
+ *
+ * - address size override is not supported
+ */
+static int
+emulate_movzx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+ mem_region_read_t memread, mem_region_write_t memwrite,
+ void *arg)
+{
+   int error, size;
+   enum vm_reg_name reg;
+   uint64_t val;
+
+   size = 4;
+   error = EINVAL;
+
+   switch (vie-op.op_byte) {
+   case 0xB6:
+   /*
+* MOV and zero extend byte from mem (ModRM:r/m) to
+* reg (ModRM:reg).
+*
+* 0F B6/r  movzx r/m8, r32
+* REX.W + 0F B6/r  movzx r/m8, r64
+*/
+
+   /* get the first operand */
+   error = memread(vm, vcpuid, gpa, val, 1, arg);
+   if (error)
+   break;
+
+   /* get the second operand */
+   reg = gpr_map[vie-reg];
+
+   if (vie-rex_w)
+   size = 8;
+
+   /* write the result */
+   error = vie_update_register(vm, vcpuid, reg, val, size);
+   break;
+   default:
+   break;
+   }
+   return (error);
+}
+
 static int
 emulate_and(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
@@ -447,6 +513,10 @@ vmm_emulate_instruction(void *vm, int vc
error = emulate_mov(vm, vcpuid, gpa, vie,
memread, memwrite, memarg);
break;
+   case VIE_OP_TYPE_MOVZX:
+   error = emulate_movzx(vm, vcpuid, gpa, vie,
+ memread, memwrite, memarg);
+   break;
case VIE_OP_TYPE_AND:
error = emulate_and(vm, vcpuid, gpa, vie,
memread, memwrite, memarg);
@@ -609,6 +679,23 @@ decode_rex(struct vie *vie)
 }
 
 static int
+decode_two_byte_opcode(struct vie *vie)
+{
+   uint8_t x;
+
+   if (vie_peek(vie, x))
+   return (-1);
+
+   vie-op = two_byte_opcodes[x];
+
+   if (vie-op.op_type == VIE_OP_TYPE_NONE)
+   return (-1);
+
+   vie_advance(vie);
+   return (0);
+}
+
+static int
 decode_opcode(struct vie *vie)
 {
uint8_t x;
@@ -622,6 +709,10 @@ decode_opcode(struct vie *vie)
return (-1);
 
vie_advance(vie);
+
+   if (vie-op.op_type == VIE_OP_TYPE_TWO_BYTE)
+   return (decode_two_byte_opcode(vie));
+
return (0);
 }
 
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


svn commit: r260997 - head/share/misc

2014-01-21 Thread Tycho Nightingale
Author: tychon
Date: Tue Jan 21 23:45:31 2014
New Revision: 260997
URL: http://svnweb.freebsd.org/changeset/base/260997

Log:
  Add myself to the src-committers list.
  
  Approved by:  neel (mentor)

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

Modified: head/share/misc/committers-src.dot
==
--- head/share/misc/committers-src.dot  Tue Jan 21 23:15:23 2014
(r260996)
+++ head/share/misc/committers-src.dot  Tue Jan 21 23:45:31 2014
(r260997)
@@ -286,6 +286,7 @@ trasz [label=Edward Tomasz Napierala\nt
 trhodes [label=Tom Rhodes\ntrho...@freebsd.org\n2002/05/28]
 trociny [label=Mikolaj Golub\ntroc...@freebsd.org\n2011/03/10]
 tuexen [label=Michael Tuexen\ntue...@freebsd.org\n2009/06/06]
+tychon [label=Tycho Nightingale\ntyc...@freebsd.org\n2014/01/21]
 ume [label=Hajimu UMEMOTO\n...@freebsd.org\n2000/02/26]
 uqs [label=Ulrich Spoerlein\n...@freebsd.org\n2010/01/28]
 vanhu [label=Yvan Vanhullebus\nva...@freebsd.org\n2008/07/21]
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-01-21 Thread Tycho Nightingale
Author: tychon
Date: Wed Jan 22 01:56:49 2014
New Revision: 260999
URL: http://svnweb.freebsd.org/changeset/base/260999

Log:
  Increase the block-layer backend maximum number of requests to match
  the AHCI command queue depth.  This allows a slew of commands issued
  by a Linux guest to be absorbed without error.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/block_if.c
==
--- head/usr.sbin/bhyve/block_if.c  Wed Jan 22 01:35:30 2014
(r260998)
+++ head/usr.sbin/bhyve/block_if.c  Wed Jan 22 01:56:49 2014
(r260999)
@@ -50,7 +50,7 @@ __FBSDID($FreeBSD$);
 
 #define BLOCKIF_SIG0xb109b109
 
-#define BLOCKIF_MAXREQ 16
+#define BLOCKIF_MAXREQ 32
 
 enum blockop {
BOP_READ,
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


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

2014-01-21 Thread Tycho Nightingale
Author: tychon
Date: Wed Jan 22 01:57:52 2014
New Revision: 261000
URL: http://svnweb.freebsd.org/changeset/base/261000

Log:
  Fix issue with stale fields from a recycled request pulled off the freelist.
  
  Approved by:  grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Wed Jan 22 01:56:49 2014
(r260999)
+++ head/usr.sbin/bhyve/pci_ahci.c  Wed Jan 22 01:57:52 2014
(r261000)
@@ -497,6 +497,8 @@ ahci_handle_flush(struct ahci_port *p, i
aior-cfis = cfis;
aior-slot = slot;
aior-len = 0;
+   aior-done = 0;
+   aior-prdtl = 0;
breq = aior-io_req;
 
err = blockif_flush(p-bctx, breq);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org