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

2020-12-17 Thread Peter Grehan
Author: grehan
Date: Fri Dec 18 00:38:48 2020
New Revision: 368747
URL: https://svnweb.freebsd.org/changeset/base/368747

Log:
  Fix issues with various VNC clients.
  
  - support VNC version 3.3 (macos "Screen Sharing" builtin client)
  - wait until client has requested an update prior to sending framebuffer data
  - don't send an update if no framebuffer updates detected
  - increase framebuffer poll frequency to 30Hz, and double that when
kbd/mouse input detected
  - zero uninitialized array elements in rfb_send_server_init_msg()
  - fix overly large allocation in rfb_init()
  - use atomics for flags shared between input and output threads
  - use #defines for constants
  
   This work was contributed by Marko Kiiskila, with reuse of some earlier
  work by Henrik Gulbrandsen.
  
  Clients tested :
  FreeBSD-current
   - tightvnc
   - tigervnc
   - krdc
   - vinagre
  
  Linux (Ubuntu)
   - krdc
   - vinagre
   - tigervnc
   - xtightvncviewer
   - remmina
  
  MacOS
   - VNC Viewer
   - TigerVNC
   - Screen Sharing (builtin client)
  
  Windows 10
   - Tiger VNC
   - VNC Viewer (cursor lag)
   - UltraVNC (cursor lag)
  
  o/s independent
   - noVNC (browser) using websockify relay
  
  PR: 250795
  Submitted by: Marko Kiiskila 
  Reviewed by:  jhb (bhyve)
  MFC after:3 weeks
  Relnotes: yes
  Differential Revision:https://reviews.freebsd.org/D27605

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

Modified: head/usr.sbin/bhyve/rfb.c
==
--- head/usr.sbin/bhyve/rfb.c   Thu Dec 17 23:35:18 2020(r368746)
+++ head/usr.sbin/bhyve/rfb.c   Fri Dec 18 00:38:48 2020(r368747)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -72,6 +73,11 @@ __FBSDID("$FreeBSD$");
 #include 
 #endif
 
+/* Delays in microseconds */
+#defineCFD_SEL_DELAY   1
+#defineSCREEN_REFRESH_DELAY33300   /* 30Hz */
+#defineSCREEN_POLL_DELAY   (SCREEN_REFRESH_DELAY / 2)
+
 static int rfb_debug = 0;
 #defineDPRINTF(params) if (rfb_debug) PRINTLN params
 #defineWPRINTF(params) PRINTLN params
@@ -80,6 +86,19 @@ static int rfb_debug = 0;
 #define AUTH_LENGTH16
 #define PASSWD_LENGTH  8
 
+/* Protocol versions */
+#define CVERS_3_3  '3'
+#define CVERS_3_7  '7'
+#define CVERS_3_8  '8'
+
+/* Client-to-server msg types */
+#define CS_SET_PIXEL_FORMAT0
+#define CS_SET_ENCODINGS   2
+#define CS_UPDATE_MSG  3
+#define CS_KEY_EVENT   4
+#define CS_POINTER_EVENT   5
+#define CS_CUT_TEXT6
+
 #define SECURITY_TYPE_NONE 1
 #define SECURITY_TYPE_VNC_AUTH 2
 
@@ -96,16 +115,22 @@ struct rfb_softc {
 
char*password;
 
-   boolenc_raw_ok;
-   boolenc_zlib_ok;
-   boolenc_resize_ok;
+   boolenc_raw_ok;
+   boolenc_zlib_ok;
+   boolenc_resize_ok;
 
z_streamzstream;
uint8_t *zbuf;
int zbuflen;
 
int conn_wait;
-   int sending;
+   int wrcount;
+
+   atomic_bool sending;
+   atomic_bool pending;
+   atomic_bool update_all;
+   atomic_bool input_detected;
+
pthread_mutex_t mtx;
pthread_cond_t  cond;
 
@@ -202,7 +227,6 @@ struct rfb_cuttext_msg {
uint32_tlength;
 };
 
-
 static void
 rfb_send_server_init_msg(int cfd)
 {
@@ -223,6 +247,9 @@ rfb_send_server_init_msg(int cfd)
sinfo.pixfmt.red_shift = 16;
sinfo.pixfmt.green_shift = 8;
sinfo.pixfmt.blue_shift = 0;
+   sinfo.pixfmt.pad[0] = 0;
+   sinfo.pixfmt.pad[1] = 0;
+   sinfo.pixfmt.pad[2] = 0;
sinfo.namelen = htonl(strlen("bhyve"));
(void)stream_write(cfd, , sizeof(sinfo));
(void)stream_write(cfd, "bhyve", strlen("bhyve"));
@@ -265,7 +292,6 @@ rfb_recv_set_encodings_msg(struct rfb_softc *rc, int c
int i;
uint32_t encoding;
 
-   assert((sizeof(enc_msg) - 1) == 3);
(void)stream_read(cfd, ((void *)_msg)+1, sizeof(enc_msg)-1);
 
for (i = 0; i < htons(enc_msg.numencs); i++) {
@@ -308,12 +334,23 @@ fast_crc32(void *buf, int len, uint32_t crcval)
return (crcval);
 }
 
+static int
+rfb_send_update_header(struct rfb_softc *rc, int cfd, int numrects)
+{
+   struct rfb_srvr_updt_msg supdt_msg;
 
+   supdt_msg.type = 0;
+   supdt_msg.pad = 0;
+   supdt_msg.numrects = htons(numrects);
+
+   return stream_write(cfd, _msg,
+   sizeof(struct rfb_srvr_updt_msg));
+}
+
 static int
 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
   int x, int y, int w, int h)
 {
-   struct rfb_srvr_updt_msg supdt_msg;
struct rfb_srvr_rect_hdr srect_hdr;
unsigned long zlen;
ssize_t nwrite, total;
@@ -325,16 +362,6 @@ 

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

2020-12-08 Thread Peter Grehan
Author: grehan
Date: Wed Dec  9 02:47:39 2020
New Revision: 368477
URL: https://svnweb.freebsd.org/changeset/base/368477

Log:
  MFC r367762
Add legacy debug/test interfaces for kvm unit tests.

Added:
  stable/12/usr.sbin/bhyve/pctestdev.c
 - copied unchanged from r367762, head/usr.sbin/bhyve/pctestdev.c
  stable/12/usr.sbin/bhyve/pctestdev.h
 - copied unchanged from r367762, head/usr.sbin/bhyve/pctestdev.h
Modified:
  stable/12/usr.sbin/bhyve/Makefile
  stable/12/usr.sbin/bhyve/bhyve.8
  stable/12/usr.sbin/bhyve/pci_lpc.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/Makefile
==
--- stable/12/usr.sbin/bhyve/Makefile   Wed Dec  9 02:21:25 2020
(r368476)
+++ stable/12/usr.sbin/bhyve/Makefile   Wed Dec  9 02:47:39 2020
(r368477)
@@ -50,6 +50,7 @@ SRCS= \
pci_virtio_scsi.c   \
pci_uart.c  \
pci_xhci.c  \
+   pctestdev.c \
pm.c\
post.c  \
ps2kbd.c\

Modified: stable/12/usr.sbin/bhyve/bhyve.8
==
--- stable/12/usr.sbin/bhyve/bhyve.8Wed Dec  9 02:21:25 2020
(r368476)
+++ stable/12/usr.sbin/bhyve/bhyve.8Wed Dec  9 02:47:39 2020
(r368477)
@@ -168,9 +168,11 @@ Allow devices behind the LPC PCI-ISA bridge to be conf
 The only supported devices are the TTY-class devices
 .Ar com1
 and
-.Ar com2
-and the boot ROM device
-.Ar bootrom .
+.Ar com2 ,
+the boot ROM device
+.Ar bootrom ,
+and the debug/test device
+.Ar pc-testdev .
 .Pp
 .Ar help
 print a list of supported LPC devices.
@@ -259,7 +261,8 @@ Intel e82545 network interface.
 .It Li uart
 PCI 16550 serial device.
 .It Li lpc
-LPC PCI-ISA bridge with COM1 and COM2 16550 serial ports and a boot ROM.
+LPC PCI-ISA bridge with COM1 and COM2 16550 serial ports, a boot ROM, and,
+optionally, the debug/test device.
 The LPC bridge emulation can only be configured on bus 0.
 .It Li fbuf
 Raw framebuffer device attached to VNC server.

Modified: stable/12/usr.sbin/bhyve/pci_lpc.c
==
--- stable/12/usr.sbin/bhyve/pci_lpc.c  Wed Dec  9 02:21:25 2020
(r368476)
+++ stable/12/usr.sbin/bhyve/pci_lpc.c  Wed Dec  9 02:47:39 2020
(r368477)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
 #include "pci_emul.h"
 #include "pci_irq.h"
 #include "pci_lpc.h"
+#include "pctestdev.h"
 #include "uart_emul.h"
 
 #defineIO_ICU1 0x20
@@ -79,6 +80,8 @@ static struct lpc_uart_softc {
 
 static const char *lpc_uart_names[LPC_UART_NUM] = { "COM1", "COM2" };
 
+static bool pctestdev_present;
+
 /*
  * LPC device configuration is in the following form:
  * [,]
@@ -106,6 +109,18 @@ lpc_device_parse(const char *opts)
goto done;
}
}
+   if (strcasecmp(lpcdev, pctestdev_getname()) == 0) {
+   if (pctestdev_present) {
+   EPRINTLN("More than one %s device conf is "
+   "specified; only one is allowed.",
+   pctestdev_getname());
+   } else if (pctestdev_parse(str) == 0) {
+   pctestdev_present = true;
+   error = 0;
+   free(cpy);
+   goto done;
+   }
+   }
}
 
 done:
@@ -123,6 +138,7 @@ lpc_print_supported_devices()
printf("bootrom\n");
for (i = 0; i < LPC_UART_NUM; i++)
printf("%s\n", lpc_uart_names[i]);
+   printf("%s\n", pctestdev_getname());
 }
 
 const char *
@@ -229,6 +245,13 @@ lpc_init(struct vmctx *ctx)
error = register_inout();
assert(error == 0);
sc->enabled = 1;
+   }
+
+   /* pc-testdev */
+   if (pctestdev_present) {
+   error = pctestdev_init(ctx);
+   if (error)
+   return (error);
}
 
return (0);

Copied: stable/12/usr.sbin/bhyve/pctestdev.c (from r367762, 
head/usr.sbin/bhyve/pctestdev.c)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/12/usr.sbin/bhyve/pctestdev.cWed Dec  9 02:47:39 2020
(r368477, copy of r367762, head/usr.sbin/bhyve/pctestdev.c)
@@ -0,0 +1,270 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Adam Fenn 
+ *
+ * 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 

svn commit: r368135 - stable/12/sys/amd64/vmm/amd

2020-11-28 Thread Peter Grehan
Author: grehan
Date: Sun Nov 29 00:54:13 2020
New Revision: 368135
URL: https://svnweb.freebsd.org/changeset/base/368135

Log:
  MFC r368047
   Remove manual instruction encodings for VMLOAD, VMRUN, and VMSAVE.

Modified:
  stable/12/sys/amd64/vmm/amd/svm_support.S
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/amd64/vmm/amd/svm_support.S
==
--- stable/12/sys/amd64/vmm/amd/svm_support.S   Sun Nov 29 00:49:14 2020
(r368134)
+++ stable/12/sys/amd64/vmm/amd/svm_support.S   Sun Nov 29 00:54:13 2020
(r368135)
@@ -39,10 +39,6 @@
 #defineVENTER  push %rbp ; mov %rsp,%rbp
 #defineVLEAVE  pop %rbp
 
-#defineVMLOAD  .byte 0x0f, 0x01, 0xda
-#defineVMRUN   .byte 0x0f, 0x01, 0xd8
-#defineVMSAVE  .byte 0x0f, 0x01, 0xdb
-
 /*
  * svm_launch(uint64_t vmcb, struct svm_regctx *gctx, struct pcpu *pcpu)
  * %rdi: physical address of VMCB
@@ -91,9 +87,9 @@ ENTRY(svm_launch)
movq SCTX_RDI(%rsi), %rdi
movq SCTX_RSI(%rsi), %rsi   /* %rsi must be restored last */
 
-   VMLOAD
-   VMRUN
-   VMSAVE
+   vmload %rax
+   vmrun %rax
+   vmsave %rax
 
pop %rax/* pop guest context pointer from the stack */
 
___
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: r368115 - in head/sys/amd64: include vmm vmm/amd vmm/intel

2020-11-27 Thread Peter Grehan
Author: grehan
Date: Sat Nov 28 01:16:59 2020
New Revision: 368115
URL: https://svnweb.freebsd.org/changeset/base/368115

Log:
  Convert vmm_ops calls to IFUNC
  
  There is no need for these to be function pointers since they are
  never modified post-module load.
  
  Rename AMD/Intel ops to be more consistent.
  
  Submitted by: adam_fenn.io
  Reviewed by:  markj, grehan
  Approved by:  grehan (bhyve)
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D27375

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/intel/vmx.h
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_util.c
  head/sys/amd64/vmm/vmm_util.h

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hFri Nov 27 21:38:03 2020
(r368114)
+++ head/sys/amd64/include/vmm.hSat Nov 28 01:16:59 2020
(r368115)
@@ -189,32 +189,32 @@ typedef int   (*vmi_snapshot_vmcx_t)(void *vmi, 
struct v
 typedef int(*vmi_restore_tsc_t)(void *vmi, int vcpuid, uint64_t now);
 
 struct vmm_ops {
-   vmm_init_func_t init;   /* module wide initialization */
-   vmm_cleanup_func_t  cleanup;
-   vmm_resume_func_t   resume;
+   vmm_init_func_t modinit;/* module wide initialization */
+   vmm_cleanup_func_t  modcleanup;
+   vmm_resume_func_t   modresume;
 
-   vmi_init_func_t vminit; /* vm-specific initialization */
-   vmi_run_func_t  vmrun;
-   vmi_cleanup_func_t  vmcleanup;
-   vmi_get_register_t  vmgetreg;
-   vmi_set_register_t  vmsetreg;
-   vmi_get_desc_t  vmgetdesc;
-   vmi_set_desc_t  vmsetdesc;
-   vmi_get_cap_t   vmgetcap;
-   vmi_set_cap_t   vmsetcap;
+   vmi_init_func_t init;   /* vm-specific initialization */
+   vmi_run_func_t  run;
+   vmi_cleanup_func_t  cleanup;
+   vmi_get_register_t  getreg;
+   vmi_set_register_t  setreg;
+   vmi_get_desc_t  getdesc;
+   vmi_set_desc_t  setdesc;
+   vmi_get_cap_t   getcap;
+   vmi_set_cap_t   setcap;
vmi_vmspace_alloc   vmspace_alloc;
vmi_vmspace_freevmspace_free;
vmi_vlapic_init vlapic_init;
vmi_vlapic_cleanup  vlapic_cleanup;
 
/* checkpoint operations */
-   vmi_snapshot_t  vmsnapshot;
+   vmi_snapshot_t  snapshot;
vmi_snapshot_vmcx_t vmcx_snapshot;
-   vmi_restore_tsc_t   vm_restore_tsc;
+   vmi_restore_tsc_t   restore_tsc;
 };
 
-extern struct vmm_ops vmm_ops_intel;
-extern struct vmm_ops vmm_ops_amd;
+extern const struct vmm_ops vmm_ops_intel;
+extern const struct vmm_ops vmm_ops_amd;
 
 int vm_create(const char *name, struct vm **retvm);
 void vm_destroy(struct vm *vm);

Modified: head/sys/amd64/vmm/amd/svm.c
==
--- head/sys/amd64/vmm/amd/svm.cFri Nov 27 21:38:03 2020
(r368114)
+++ head/sys/amd64/vmm/amd/svm.cSat Nov 28 01:16:59 2020
(r368115)
@@ -132,6 +132,7 @@ static VMM_STAT_AMD(VCPU_EXITINTINFO, "VM exits during
 static VMM_STAT_AMD(VCPU_INTINFO_INJECTED, "Events pending at VM entry");
 static VMM_STAT_AMD(VMEXIT_VINTR, "VM exits due to interrupt window");
 
+static int svm_getdesc(void *arg, int vcpu, int reg, struct seg_desc *desc);
 static int svm_setreg(void *arg, int vcpu, int ident, uint64_t val);
 
 static __inline int
@@ -162,7 +163,7 @@ svm_disable(void *arg __unused)
  * Disable SVM on all CPUs.
  */
 static int
-svm_cleanup(void)
+svm_modcleanup(void)
 {
 
smp_rendezvous(NULL, svm_disable, NULL, NULL);
@@ -240,7 +241,7 @@ svm_available(void)
 }
 
 static int
-svm_init(int ipinum)
+svm_modinit(int ipinum)
 {
int error, cpu;
 
@@ -274,7 +275,7 @@ svm_init(int ipinum)
 }
 
 static void
-svm_restore(void)
+svm_modresume(void)
 {
 
svm_enable(NULL);
@@ -551,7 +552,7 @@ vmcb_init(struct svm_softc *sc, int vcpu, uint64_t iop
  * Initialize a virtual machine.
  */
 static void *
-svm_vminit(struct vm *vm, pmap_t pmap)
+svm_init(struct vm *vm, pmap_t pmap)
 {
struct svm_softc *svm_sc;
struct svm_vcpu *vcpu;
@@ -728,7 +729,7 @@ svm_inout_str_seginfo(struct svm_softc *svm_sc, int vc
vis->seg_name = vm_segment_name(s);
}
 
-   error = vmcb_getdesc(svm_sc, vcpu, vis->seg_name, >seg_desc);
+   error = svm_getdesc(svm_sc, vcpu, vis->seg_name, >seg_desc);
KASSERT(error == 0, ("%s: svm_getdesc error %d", __func__, error));
 }
 
@@ -1984,7 +1985,7 @@ svm_dr_leave_guest(struct svm_regctx *gctx)
  * Start vcpu with specified RIP.
  */
 static int
-svm_vmrun(void *arg, int vcpu, register_t rip, pmap_t 

svn commit: r368047 - head/sys/amd64/vmm/amd

2020-11-25 Thread Peter Grehan
Author: grehan
Date: Thu Nov 26 05:58:55 2020
New Revision: 368047
URL: https://svnweb.freebsd.org/changeset/base/368047

Log:
  Remove manual instruction encodings for   VMLOAD, VMRUN, and VMSAVE.
  
  This is   a relic from when these instructions weren't supported by the 
toolchain.
  No functional change.
  
  Submitted by: adam_fenn.io
  Reviewed by:  grehan
  Approved by:  grehan (bhyve)
  MFC after:3 days
  Differential Revision:https://reviews.freebsd.org/D27130

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

Modified: head/sys/amd64/vmm/amd/svm_support.S
==
--- head/sys/amd64/vmm/amd/svm_support.SThu Nov 26 04:55:02 2020
(r368046)
+++ head/sys/amd64/vmm/amd/svm_support.SThu Nov 26 05:58:55 2020
(r368047)
@@ -39,10 +39,6 @@
 #defineVENTER  push %rbp ; mov %rsp,%rbp
 #defineVLEAVE  pop %rbp
 
-#defineVMLOAD  .byte 0x0f, 0x01, 0xda
-#defineVMRUN   .byte 0x0f, 0x01, 0xd8
-#defineVMSAVE  .byte 0x0f, 0x01, 0xdb
-
 /*
  * svm_launch(uint64_t vmcb, struct svm_regctx *gctx, struct pcpu *pcpu)
  * %rdi: physical address of VMCB
@@ -91,9 +87,9 @@ ENTRY(svm_launch)
movq SCTX_RDI(%rsi), %rdi
movq SCTX_RSI(%rsi), %rsi   /* %rsi must be restored last */
 
-   VMLOAD
-   VMRUN
-   VMSAVE
+   vmload %rax
+   vmrun %rax
+   vmsave %rax
 
pop %rax/* pop guest context pointer from the stack */
 
___
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: r367975 - svnadmin/conf

2020-11-23 Thread Peter Grehan
Author: grehan
Date: Tue Nov 24 02:05:43 2020
New Revision: 367975
URL: https://svnweb.freebsd.org/changeset/base/367975

Log:
  Restore Bryan Venteicher's commit bit
  
  grehan to rementor
  
  Approved by:  core@

Modified:
  svnadmin/conf/access
  svnadmin/conf/mentors

Modified: svnadmin/conf/access
==
--- svnadmin/conf/accessTue Nov 24 00:30:47 2020(r367974)
+++ svnadmin/conf/accessTue Nov 24 02:05:43 2020(r367975)
@@ -43,6 +43,7 @@ br
 brd
 brooks
 brueffer
+bryanv
 bwidawsk
 bz
 cem

Modified: svnadmin/conf/mentors
==
--- svnadmin/conf/mentors   Tue Nov 24 00:30:47 2020(r367974)
+++ svnadmin/conf/mentors   Tue Nov 24 02:05:43 2020(r367975)
@@ -13,6 +13,7 @@
 afedorov   vmaffione   Co-mentor: jhb
 anish  jhb
 brdallanjude   Co-mentor: bapt
+bryanv grehan
 gordon delphij Co-mentor: emaste
 jceel  trasz
 jkhrwatson
___
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: r367859 - stable/12/usr.sbin/bhyve

2020-11-19 Thread Peter Grehan
Author: grehan
Date: Fri Nov 20 03:33:30 2020
New Revision: 367859
URL: https://svnweb.freebsd.org/changeset/base/367859

Log:
  MFC r367709
  Fix regression in AHCI controller settings.
  
  PR:   250924
  Submitted by: Rolf Stalder
  Reported by:  Rolf Stalder
  Relnotes: Yes

Modified:
  stable/12/usr.sbin/bhyve/pci_ahci.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/pci_ahci.c
==
--- stable/12/usr.sbin/bhyve/pci_ahci.c Fri Nov 20 02:03:58 2020
(r367858)
+++ stable/12/usr.sbin/bhyve/pci_ahci.c Fri Nov 20 03:33:30 2020
(r367859)
@@ -1000,7 +1000,7 @@ ata_identify_init(struct ahci_port* p, int atapi)
ata_ident->capabilities1 = ATA_SUPPORT_LBA |
ATA_SUPPORT_DMA;
ata_ident->capabilities2 = (1 << 14 | 1);
-   ata_ident->atavalid = ATA_FLAG_54_58 | ATA_FLAG_64_70;
+   ata_ident->atavalid = ATA_FLAG_64_70 | ATA_FLAG_88;
ata_ident->obsolete62 = 0x3f;
ata_ident->mwdmamodes = 7;
if (p->xfermode & ATA_WDMA0)
@@ -1049,8 +1049,7 @@ ata_identify_init(struct ahci_port* p, int atapi)
ata_ident->capabilities1 = ATA_SUPPORT_DMA |
ATA_SUPPORT_LBA | ATA_SUPPORT_IORDY;
ata_ident->capabilities2 = (1 << 14);
-   ata_ident->atavalid = ATA_FLAG_54_58 |
-   ATA_FLAG_64_70;
+   ata_ident->atavalid = ATA_FLAG_64_70 | ATA_FLAG_88;
if (p->mult_sectors)
ata_ident->multi = (ATA_MULTI_VALID | p->mult_sectors);
if (sectors <= 0x0fff) {
___
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: r367834 - head/usr.sbin/bhyve

2020-11-18 Thread Peter Grehan
Author: grehan
Date: Thu Nov 19 07:23:39 2020
New Revision: 367834
URL: https://svnweb.freebsd.org/changeset/base/367834

Log:
  Advance RIP after userspace instruction decode
  
  Add update to RIP after a userspace instruction decode (as is done for
  the in-kernel counterpart of this case).
  
  Submitted by: adam_fenn.io
  Reviewed by:  cem, markj
  Approved by:  grehan (bhyve)
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D27243

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

Modified: head/usr.sbin/bhyve/bhyverun.c
==
--- head/usr.sbin/bhyve/bhyverun.c  Thu Nov 19 06:30:25 2020
(r367833)
+++ head/usr.sbin/bhyve/bhyverun.c  Thu Nov 19 07:23:39 2020
(r367834)
@@ -766,7 +766,11 @@ vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vm
vie_restart(vie);
mode = vmexit->u.inst_emul.paging.cpu_mode;
cs_d = vmexit->u.inst_emul.cs_d;
-   (void)vmm_decode_instruction(mode, cs_d, vie);
+   if (vmm_decode_instruction(mode, cs_d, vie) != 0)
+   goto fail;
+   if (vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RIP,
+   vmexit->rip + vie->num_processed) != 0)
+   goto fail;
}
 
err = emulate_mem(ctx, *pvcpu, vmexit->u.inst_emul.gpa,
@@ -777,15 +781,17 @@ vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vm
EPRINTLN("Unhandled memory access to 0x%lx\n",
vmexit->u.inst_emul.gpa);
}
-
-   fprintf(stderr, "Failed to emulate instruction sequence [ ");
-   for (i = 0; i < vie->num_valid; i++)
-   fprintf(stderr, "%02x", vie->inst[i]);
-   FPRINTLN(stderr, " ] at 0x%lx", vmexit->rip);
-   return (VMEXIT_ABORT);
+   goto fail;
}
 
return (VMEXIT_CONTINUE);
+
+fail:
+   fprintf(stderr, "Failed to emulate instruction sequence [ ");
+   for (i = 0; i < vie->num_valid; i++)
+   fprintf(stderr, "%02x", vie->inst[i]);
+   FPRINTLN(stderr, " ] at 0x%lx", vmexit->rip);
+   return (VMEXIT_ABORT);
 }
 
 static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER;
___
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: r367762 - head/usr.sbin/bhyve

2020-11-17 Thread Peter Grehan
Author: grehan
Date: Tue Nov 17 13:14:04 2020
New Revision: 367762
URL: https://svnweb.freebsd.org/changeset/base/367762

Log:
  Add legacy debug/test interfaces for kvm unit tests.
  
  Implement the legacy debug/test interfaces expected by KVM-unit-tests'
  realmode, emulator, and ioapic tests.
  
  Submitted by: adam_fenn.io
  Reviewed by:  markj, grehan
  Approved by:  grehan (bhyve)
  MFC after:3 weeks
  Relnotes: Yes
  Differential Revision:https://reviews.freebsd.org/D27130

Added:
  head/usr.sbin/bhyve/pctestdev.c   (contents, props changed)
  head/usr.sbin/bhyve/pctestdev.h   (contents, props changed)
Modified:
  head/usr.sbin/bhyve/Makefile
  head/usr.sbin/bhyve/bhyve.8
  head/usr.sbin/bhyve/pci_lpc.c

Modified: head/usr.sbin/bhyve/Makefile
==
--- head/usr.sbin/bhyve/MakefileTue Nov 17 12:36:59 2020
(r367761)
+++ head/usr.sbin/bhyve/MakefileTue Nov 17 13:14:04 2020
(r367762)
@@ -56,6 +56,7 @@ SRCS= \
pci_virtio_scsi.c   \
pci_uart.c  \
pci_xhci.c  \
+   pctestdev.c \
pm.c\
post.c  \
ps2kbd.c\

Modified: head/usr.sbin/bhyve/bhyve.8
==
--- head/usr.sbin/bhyve/bhyve.8 Tue Nov 17 12:36:59 2020(r367761)
+++ head/usr.sbin/bhyve/bhyve.8 Tue Nov 17 13:14:04 2020(r367762)
@@ -169,9 +169,11 @@ Allow devices behind the LPC PCI-ISA bridge to be conf
 The only supported devices are the TTY-class devices
 .Ar com1
 and
-.Ar com2
-and the boot ROM device
-.Ar bootrom .
+.Ar com2 ,
+the boot ROM device
+.Ar bootrom ,
+and the debug/test device
+.Ar pc-testdev .
 .Pp
 .Ar help
 print a list of supported LPC devices.
@@ -277,7 +279,8 @@ Intel e82545 network interface.
 .It Li uart
 PCI 16550 serial device.
 .It Li lpc
-LPC PCI-ISA bridge with COM1 and COM2 16550 serial ports and a boot ROM.
+LPC PCI-ISA bridge with COM1 and COM2 16550 serial ports, a boot ROM, and,
+optionally, the debug/test device.
 The LPC bridge emulation can only be configured on bus 0.
 .It Li fbuf
 Raw framebuffer device attached to VNC server.

Modified: head/usr.sbin/bhyve/pci_lpc.c
==
--- head/usr.sbin/bhyve/pci_lpc.c   Tue Nov 17 12:36:59 2020
(r367761)
+++ head/usr.sbin/bhyve/pci_lpc.c   Tue Nov 17 13:14:04 2020
(r367762)
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
 #include "pci_emul.h"
 #include "pci_irq.h"
 #include "pci_lpc.h"
+#include "pctestdev.h"
 #include "uart_emul.h"
 
 #defineIO_ICU1 0x20
@@ -80,6 +81,8 @@ static struct lpc_uart_softc {
 
 static const char *lpc_uart_names[LPC_UART_NUM] = { "COM1", "COM2" };
 
+static bool pctestdev_present;
+
 /*
  * LPC device configuration is in the following form:
  * [,]
@@ -107,6 +110,18 @@ lpc_device_parse(const char *opts)
goto done;
}
}
+   if (strcasecmp(lpcdev, pctestdev_getname()) == 0) {
+   if (pctestdev_present) {
+   EPRINTLN("More than one %s device conf is "
+   "specified; only one is allowed.",
+   pctestdev_getname());
+   } else if (pctestdev_parse(str) == 0) {
+   pctestdev_present = true;
+   error = 0;
+   free(cpy);
+   goto done;
+   }
+   }
}
 
 done:
@@ -124,6 +139,7 @@ lpc_print_supported_devices()
printf("bootrom\n");
for (i = 0; i < LPC_UART_NUM; i++)
printf("%s\n", lpc_uart_names[i]);
+   printf("%s\n", pctestdev_getname());
 }
 
 const char *
@@ -230,6 +246,13 @@ lpc_init(struct vmctx *ctx)
error = register_inout();
assert(error == 0);
sc->enabled = 1;
+   }
+
+   /* pc-testdev */
+   if (pctestdev_present) {
+   error = pctestdev_init(ctx);
+   if (error)
+   return (error);
}
 
return (0);

Added: head/usr.sbin/bhyve/pctestdev.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/bhyve/pctestdev.c Tue Nov 17 13:14:04 2020
(r367762)
@@ -0,0 +1,270 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Adam Fenn 
+ *
+ * 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 

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

2020-11-15 Thread Peter Grehan
Author: grehan
Date: Sun Nov 15 12:59:24 2020
New Revision: 367709
URL: https://svnweb.freebsd.org/changeset/base/367709

Log:
  Fix regression in AHCI controller settings.
  
  When the AHCI code was reworked to use FreeBSD struct
  definitions, the valid element was mis-transcribed resulting
  in the UMDA capability being hidden. This prevented Illumos
  from using AHCI disk/cdrom drives.
  
  Fix by using definitions that match the code pre-rework.
  
  PR:   250924
  Submitted by: Rolf Stalder
  Reported by:  Rolf Stalder
  MFC after:3 days

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Sun Nov 15 12:31:07 2020
(r367708)
+++ head/usr.sbin/bhyve/pci_ahci.c  Sun Nov 15 12:59:24 2020
(r367709)
@@ -1004,7 +1004,7 @@ ata_identify_init(struct ahci_port* p, int atapi)
ata_ident->capabilities1 = ATA_SUPPORT_LBA |
ATA_SUPPORT_DMA;
ata_ident->capabilities2 = (1 << 14 | 1);
-   ata_ident->atavalid = ATA_FLAG_54_58 | ATA_FLAG_64_70;
+   ata_ident->atavalid = ATA_FLAG_64_70 | ATA_FLAG_88;
ata_ident->obsolete62 = 0x3f;
ata_ident->mwdmamodes = 7;
if (p->xfermode & ATA_WDMA0)
@@ -1053,8 +1053,7 @@ ata_identify_init(struct ahci_port* p, int atapi)
ata_ident->capabilities1 = ATA_SUPPORT_DMA |
ATA_SUPPORT_LBA | ATA_SUPPORT_IORDY;
ata_ident->capabilities2 = (1 << 14);
-   ata_ident->atavalid = ATA_FLAG_54_58 |
-   ATA_FLAG_64_70;
+   ata_ident->atavalid = ATA_FLAG_64_70 | ATA_FLAG_88;
if (p->mult_sectors)
ata_ident->multi = (ATA_MULTI_VALID | p->mult_sectors);
if (sectors <= 0x0fff) {
___
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: r365873 - head/usr.sbin/bhyve

2020-09-17 Thread Peter Grehan
Author: grehan
Date: Fri Sep 18 05:54:59 2020
New Revision: 365873
URL: https://svnweb.freebsd.org/changeset/base/365873

Log:
  Fix byte-reversal of language ID in string descriptor.
  
  The language id of String Descriptors in usb mouse is
  0x0904, while the spec require 0x0409 (English - United States)
  
  Submitted by: Wanpeng Qian
  Reviewed by:  grehan
  Approved by:  grehan (#bhyve)
  MFC after:3 days
  Differential Revision:https://reviews.freebsd.org/D26472

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

Modified: head/usr.sbin/bhyve/usb_mouse.c
==
--- head/usr.sbin/bhyve/usb_mouse.c Fri Sep 18 03:11:47 2020
(r365872)
+++ head/usr.sbin/bhyve/usb_mouse.c Fri Sep 18 05:54:59 2020
(r365873)
@@ -74,7 +74,7 @@ enum {
 };
 
 static const char *umouse_desc_strings[] = {
-   "\x04\x09",
+   "\x09\x04",
"BHYVE",
"HID Tablet",
"01",
___
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: r365560 - in stable/12/sys: amd64/amd64 amd64/include amd64/vmm amd64/vmm/intel i386/i386 x86/include

2020-09-10 Thread Peter Grehan
Author: grehan
Date: Thu Sep 10 10:49:59 2020
New Revision: 365560
URL: https://svnweb.freebsd.org/changeset/base/365560

Log:
  MFC r364340, r364343, r364656
  
r364340Support guest rdtscp and rdpid instructions on Intel VT-x
  
Follow-on commits:
r364343Export a routine to provide the TSC_AUX MSR value and use this 
in vmm
r364656assert caller is preventing CPU migration
  
Submitted by:   adam_fenn.io
Differential Revision: https://reviews.freebsd.org/D26003

Modified:
  stable/12/sys/amd64/amd64/initcpu.c
  stable/12/sys/amd64/include/vmm.h
  stable/12/sys/amd64/vmm/intel/vmx.c
  stable/12/sys/amd64/vmm/intel/vmx.h
  stable/12/sys/amd64/vmm/intel/vmx_msr.c
  stable/12/sys/amd64/vmm/intel/vmx_msr.h
  stable/12/sys/amd64/vmm/x86.c
  stable/12/sys/i386/i386/initcpu.c
  stable/12/sys/x86/include/x86_var.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/amd64/amd64/initcpu.c
==
--- stable/12/sys/amd64/amd64/initcpu.c Thu Sep 10 09:50:43 2020
(r365559)
+++ stable/12/sys/amd64/amd64/initcpu.c Thu Sep 10 10:49:59 2020
(r365560)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -218,6 +219,18 @@ init_via(void)
 }
 
 /*
+ * The value for the TSC_AUX MSR and rdtscp/rdpid on the invoking CPU.
+ *
+ * Caller should prevent CPU migration.
+ */
+u_int
+cpu_auxmsr(void)
+{
+   KASSERT((read_rflags() & PSL_I) == 0, ("context switch possible"));
+   return (PCPU_GET(cpuid));
+}
+
+/*
  * Initialize CPU control registers
  */
 void
@@ -283,7 +296,7 @@ initializecpu(void)
 
if ((amd_feature & AMDID_RDTSCP) != 0 ||
(cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0)
-   wrmsr(MSR_TSC_AUX, PCPU_GET(cpuid));
+   wrmsr(MSR_TSC_AUX, cpu_auxmsr());
 }
 
 void

Modified: stable/12/sys/amd64/include/vmm.h
==
--- stable/12/sys/amd64/include/vmm.h   Thu Sep 10 09:50:43 2020
(r365559)
+++ stable/12/sys/amd64/include/vmm.h   Thu Sep 10 10:49:59 2020
(r365560)
@@ -436,6 +436,8 @@ enum vm_cap_type {
VM_CAP_UNRESTRICTED_GUEST,
VM_CAP_ENABLE_INVPCID,
VM_CAP_BPT_EXIT,
+   VM_CAP_RDPID,
+   VM_CAP_RDTSCP,
VM_CAP_MAX
 };
 

Modified: stable/12/sys/amd64/vmm/intel/vmx.c
==
--- stable/12/sys/amd64/vmm/intel/vmx.c Thu Sep 10 09:50:43 2020
(r365559)
+++ stable/12/sys/amd64/vmm/intel/vmx.c Thu Sep 10 10:49:59 2020
(r365560)
@@ -160,6 +160,14 @@ static int cap_pause_exit;
 SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, pause_exit, CTLFLAG_RD, _pause_exit,
 0, "PAUSE triggers a VM-exit");
 
+static int cap_rdpid;
+SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, rdpid, CTLFLAG_RD, _rdpid, 0,
+"Guests are allowed to use RDPID");
+
+static int cap_rdtscp;
+SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, rdtscp, CTLFLAG_RD, _rdtscp, 0,
+"Guests are allowed to use RDTSCP");
+
 static int cap_unrestricted_guest;
 SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, unrestricted_guest, CTLFLAG_RD,
 _unrestricted_guest, 0, "Unrestricted guests");
@@ -293,6 +301,18 @@ static int vmx_getreg(void *arg, int vcpu, int reg, ui
 static int vmxctx_setreg(struct vmxctx *vmxctx, int reg, uint64_t val);
 static void vmx_inject_pir(struct vlapic *vlapic);
 
+static inline bool
+host_has_rdpid(void)
+{
+   return ((cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0);
+}
+
+static inline bool
+host_has_rdtscp(void)
+{
+   return ((amd_feature & AMDID_RDTSCP) != 0);
+}
+
 #ifdef KTR
 static const char *
 exit_reason_to_str(int reason)
@@ -745,6 +765,43 @@ vmx_init(int ipinum)
 PROCBASED_PAUSE_EXITING, 0,
 ) == 0);
 
+   /*
+* Check support for RDPID and/or RDTSCP.
+*
+* Support a pass-through-based implementation of these via the
+* "enable RDTSCP" VM-execution control and the "RDTSC exiting"
+* VM-execution control.
+*
+* The "enable RDTSCP" VM-execution control applies to both RDPID
+* and RDTSCP (see SDM volume 3, section 25.3, "Changes to
+* Instruction Behavior in VMX Non-root operation"); this is why
+* only this VM-execution control needs to be enabled in order to
+* enable passing through whichever of RDPID and/or RDTSCP are
+* supported by the host.
+*
+* The "RDTSC exiting" VM-execution control applies to both RDTSC
+* and RDTSCP (again, per SDM volume 3, section 25.3), and is
+* already set up for RDTSC and RDTSCP pass-through by the current
+* implementation of RDTSC.
+*
+* Although RDPID and RDTSCP are optional capabilities, since there
+* does not currently 

svn commit: r365443 - stable/12/sys/amd64/vmm

2020-09-07 Thread Peter Grehan
Author: grehan
Date: Tue Sep  8 03:55:49 2020
New Revision: 365443
URL: https://svnweb.freebsd.org/changeset/base/365443

Log:
  MFC 364339
 Allow guest device MMIO access from bootmem memory segments.
  
 Differential Revision: https://reviews.freebsd.org/D25955

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

Modified: stable/12/sys/amd64/vmm/vmm.c
==
--- stable/12/sys/amd64/vmm/vmm.c   Tue Sep  8 03:00:31 2020
(r365442)
+++ stable/12/sys/amd64/vmm/vmm.c   Tue Sep  8 03:55:49 2020
(r365443)
@@ -980,8 +980,7 @@ vm_gpa_hold(struct vm *vm, int vcpuid, vm_paddr_t gpa,
count = 0;
for (i = 0; i < VM_MAX_MEMMAPS; i++) {
mm = >mem_maps[i];
-   if (sysmem_mapping(vm, mm) && gpa >= mm->gpa &&
-   gpa < mm->gpa + mm->len) {
+   if (gpa >= mm->gpa && gpa < mm->gpa + mm->len) {
count = vm_fault_quick_hold_pages(>vmspace->vm_map,
trunc_page(gpa), PAGE_SIZE, reqprot, , 1);
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: r364656 - in head/sys: amd64/amd64 i386/i386

2020-08-24 Thread Peter Grehan
Author: grehan
Date: Mon Aug 24 11:49:49 2020
New Revision: 364656
URL: https://svnweb.freebsd.org/changeset/base/364656

Log:
  cpu_auxmsr: assert caller is preventing CPU migration.
  
  Submitted by: Adam Fenn (adam at fenn dot io)
  Requested by: kib
  Reviewed by:  kib, grehan
  Approved by:  kib
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D26166

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

Modified: head/sys/amd64/amd64/initcpu.c
==
--- head/sys/amd64/amd64/initcpu.c  Mon Aug 24 11:44:20 2020
(r364655)
+++ head/sys/amd64/amd64/initcpu.c  Mon Aug 24 11:49:49 2020
(r364656)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -218,11 +219,14 @@ init_via(void)
 }
 
 /*
- * The value for the TSC_AUX MSR and rdtscp/rdpid.
+ * The value for the TSC_AUX MSR and rdtscp/rdpid on the invoking CPU.
+ *
+ * Caller should prevent CPU migration.
  */
 u_int
 cpu_auxmsr(void)
 {
+   KASSERT((read_rflags() & PSL_I) == 0, ("context switch possible"));
return (PCPU_GET(cpuid));
 }
 

Modified: head/sys/i386/i386/initcpu.c
==
--- head/sys/i386/i386/initcpu.cMon Aug 24 11:44:20 2020
(r364655)
+++ head/sys/i386/i386/initcpu.cMon Aug 24 11:49:49 2020
(r364656)
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -628,11 +629,14 @@ init_transmeta(void)
 #endif
 
 /*
- * The value for the TSC_AUX MSR and rdtscp/rdpid.
+ * The value for the TSC_AUX MSR and rdtscp/rdpid on the invoking CPU.
+ *
+ * Caller should prevent CPU migration.
  */
 u_int
 cpu_auxmsr(void)
 {
+   KASSERT((read_eflags() & PSL_I) == 0, ("context switch possible"));
return (PCPU_GET(cpuid));
 }
 
___
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: r364343 - in head/sys: amd64/amd64 amd64/vmm/intel i386/i386 x86/include

2020-08-18 Thread Peter Grehan
Author: grehan
Date: Tue Aug 18 11:36:38 2020
New Revision: 364343
URL: https://svnweb.freebsd.org/changeset/base/364343

Log:
  Export a routine to provide the   TSC_AUX MSR value and use this in vmm.
  
  Also, drop an unnecessary set of braces.
  
  Requested by: kib
  Reviewed by:  kib
  MFC after:3 weeks

Modified:
  head/sys/amd64/amd64/initcpu.c
  head/sys/amd64/vmm/intel/vmx_msr.c
  head/sys/i386/i386/initcpu.c
  head/sys/x86/include/x86_var.h

Modified: head/sys/amd64/amd64/initcpu.c
==
--- head/sys/amd64/amd64/initcpu.c  Tue Aug 18 10:30:55 2020
(r364342)
+++ head/sys/amd64/amd64/initcpu.c  Tue Aug 18 11:36:38 2020
(r364343)
@@ -218,6 +218,15 @@ init_via(void)
 }
 
 /*
+ * The value for the TSC_AUX MSR and rdtscp/rdpid.
+ */
+u_int
+cpu_auxmsr(void)
+{
+   return (PCPU_GET(cpuid));
+}
+
+/*
  * Initialize CPU control registers
  */
 void
@@ -283,7 +292,7 @@ initializecpu(void)
 
if ((amd_feature & AMDID_RDTSCP) != 0 ||
(cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0)
-   wrmsr(MSR_TSC_AUX, PCPU_GET(cpuid));
+   wrmsr(MSR_TSC_AUX, cpu_auxmsr());
 }
 
 void

Modified: head/sys/amd64/vmm/intel/vmx_msr.c
==
--- head/sys/amd64/vmm/intel/vmx_msr.c  Tue Aug 18 10:30:55 2020
(r364342)
+++ head/sys/amd64/vmm/intel/vmx_msr.c  Tue Aug 18 11:36:38 2020
(r364343)
@@ -365,9 +365,9 @@ void
 vmx_msr_guest_enter_tsc_aux(struct vmx *vmx, int vcpuid)
 {
uint64_t guest_tsc_aux = vmx->guest_msrs[vcpuid][IDX_MSR_TSC_AUX];
-   uint32_t cpuid = PCPU_GET(cpuid);
+   uint32_t host_aux = cpu_auxmsr();
 
-   if (vmx_have_msr_tsc_aux(vmx) && (guest_tsc_aux != cpuid))
+   if (vmx_have_msr_tsc_aux(vmx) && guest_tsc_aux != host_aux)
wrmsr(MSR_TSC_AUX, guest_tsc_aux);
 }
 
@@ -396,9 +396,9 @@ void
 vmx_msr_guest_exit_tsc_aux(struct vmx *vmx, int vcpuid)
 {
uint64_t guest_tsc_aux = vmx->guest_msrs[vcpuid][IDX_MSR_TSC_AUX];
-   uint32_t cpuid = PCPU_GET(cpuid);
+   uint32_t host_aux = cpu_auxmsr();
 
-   if (vmx_have_msr_tsc_aux(vmx) && (guest_tsc_aux != cpuid))
+   if (vmx_have_msr_tsc_aux(vmx) && guest_tsc_aux != host_aux)
/*
 * Note that it is not necessary to save the guest value
 * here; vmx->guest_msrs[vcpuid][IDX_MSR_TSC_AUX] always
@@ -406,7 +406,7 @@ vmx_msr_guest_exit_tsc_aux(struct vmx *vmx, int vcpuid
 * the guest writes to it (which is expected to be very
 * rare).
 */
-   wrmsr(MSR_TSC_AUX, cpuid);
+   wrmsr(MSR_TSC_AUX, host_aux);
 }
 
 int

Modified: head/sys/i386/i386/initcpu.c
==
--- head/sys/i386/i386/initcpu.cTue Aug 18 10:30:55 2020
(r364342)
+++ head/sys/i386/i386/initcpu.cTue Aug 18 11:36:38 2020
(r364343)
@@ -627,6 +627,15 @@ init_transmeta(void)
 }
 #endif
 
+/*
+ * The value for the TSC_AUX MSR and rdtscp/rdpid.
+ */
+u_int
+cpu_auxmsr(void)
+{
+   return (PCPU_GET(cpuid));
+}
+
 extern int elf32_nxstack;
 
 void
@@ -751,7 +760,7 @@ initializecpu(void)
}
if ((amd_feature & AMDID_RDTSCP) != 0 ||
(cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0)
-   wrmsr(MSR_TSC_AUX, PCPU_GET(cpuid));
+   wrmsr(MSR_TSC_AUX, cpu_auxmsr());
 }
 
 void

Modified: head/sys/x86/include/x86_var.h
==
--- head/sys/x86/include/x86_var.h  Tue Aug 18 10:30:55 2020
(r364342)
+++ head/sys/x86/include/x86_var.h  Tue Aug 18 11:36:38 2020
(r364343)
@@ -115,6 +115,7 @@ typedef void alias_for_inthand_t(void);
 bool   acpi_get_fadt_bootflags(uint16_t *flagsp);
 void   *alloc_fpusave(int flags);
 void   busdma_swi(void);
+u_int  cpu_auxmsr(void);
 vm_paddr_t cpu_getmaxphyaddr(void);
 bool   cpu_mwait_usable(void);
 void   cpu_probe_amdc1e(void);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r364340 - in head/sys/amd64: include vmm vmm/intel

2020-08-18 Thread Peter Grehan

On 8/18/20 6:48 PM, Konstantin Belousov wrote:

On Tue, Aug 18, 2020 at 07:23:47AM +, Peter Grehan wrote:

+void
+vmx_msr_guest_exit_tsc_aux(struct vmx *vmx, int vcpuid)
+{
+   uint64_t guest_tsc_aux = vmx->guest_msrs[vcpuid][IDX_MSR_TSC_AUX];
+   uint32_t cpuid = PCPU_GET(cpuid);
+
+   if (vmx_have_msr_tsc_aux(vmx) && (guest_tsc_aux != cpuid))

This is quite unobvious place to look at if host TSC_AUX is ever going
to provide something different from cpuid.

Could you please add a comment at
{i386/i386,


 No bhyve on i386.


amd64/amd64}/initcpu.c::initializecpu() around TSC_AUX
settings pointing out this code ?


 Sure, will do.

later,

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

2020-08-18 Thread Peter Grehan
Author: grehan
Date: Tue Aug 18 07:23:47 2020
New Revision: 364340
URL: https://svnweb.freebsd.org/changeset/base/364340

Log:
  Support guest rdtscp and rdpid instructions on Intel VT-x
  
  Enable any of rdtscp and/or rdpid for bhyve guests on Intel-based hosts
  that support the "enable RDTSCP" VM-execution control.
  
  Submitted by: adam_fenn.io
  Reported by:  chuck
  Reviewed by:  chuck, grehan, jhb
  Approved by:  jhb (bhyve), grehan
  MFC after:3 weeks
  Relnotes: Yes
  Differential Revision:https://reviews.freebsd.org/D26003

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

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hTue Aug 18 07:08:17 2020
(r364339)
+++ head/sys/amd64/include/vmm.hTue Aug 18 07:23:47 2020
(r364340)
@@ -481,6 +481,8 @@ enum vm_cap_type {
VM_CAP_UNRESTRICTED_GUEST,
VM_CAP_ENABLE_INVPCID,
VM_CAP_BPT_EXIT,
+   VM_CAP_RDPID,
+   VM_CAP_RDTSCP,
VM_CAP_MAX
 };
 

Modified: head/sys/amd64/vmm/intel/vmx.c
==
--- head/sys/amd64/vmm/intel/vmx.c  Tue Aug 18 07:08:17 2020
(r364339)
+++ head/sys/amd64/vmm/intel/vmx.c  Tue Aug 18 07:23:47 2020
(r364340)
@@ -167,6 +167,14 @@ static int cap_pause_exit;
 SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, pause_exit, CTLFLAG_RD, _pause_exit,
 0, "PAUSE triggers a VM-exit");
 
+static int cap_rdpid;
+SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, rdpid, CTLFLAG_RD, _rdpid, 0,
+"Guests are allowed to use RDPID");
+
+static int cap_rdtscp;
+SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, rdtscp, CTLFLAG_RD, _rdtscp, 0,
+"Guests are allowed to use RDTSCP");
+
 static int cap_unrestricted_guest;
 SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, unrestricted_guest, CTLFLAG_RD,
 _unrestricted_guest, 0, "Unrestricted guests");
@@ -303,6 +311,18 @@ static void vmx_inject_pir(struct vlapic *vlapic);
 static int vmx_restore_tsc(void *arg, int vcpu, uint64_t now);
 #endif
 
+static inline bool
+host_has_rdpid(void)
+{
+   return ((cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0);
+}
+
+static inline bool
+host_has_rdtscp(void)
+{
+   return ((amd_feature & AMDID_RDTSCP) != 0);
+}
+
 #ifdef KTR
 static const char *
 exit_reason_to_str(int reason)
@@ -755,6 +775,43 @@ vmx_init(int ipinum)
 PROCBASED_PAUSE_EXITING, 0,
 ) == 0);
 
+   /*
+* Check support for RDPID and/or RDTSCP.
+*
+* Support a pass-through-based implementation of these via the
+* "enable RDTSCP" VM-execution control and the "RDTSC exiting"
+* VM-execution control.
+*
+* The "enable RDTSCP" VM-execution control applies to both RDPID
+* and RDTSCP (see SDM volume 3, section 25.3, "Changes to
+* Instruction Behavior in VMX Non-root operation"); this is why
+* only this VM-execution control needs to be enabled in order to
+* enable passing through whichever of RDPID and/or RDTSCP are
+* supported by the host.
+*
+* The "RDTSC exiting" VM-execution control applies to both RDTSC
+* and RDTSCP (again, per SDM volume 3, section 25.3), and is
+* already set up for RDTSC and RDTSCP pass-through by the current
+* implementation of RDTSC.
+*
+* Although RDPID and RDTSCP are optional capabilities, since there
+* does not currently seem to be a use case for enabling/disabling
+* these via libvmmapi, choose not to support this and, instead,
+* just statically always enable or always disable this support
+* across all vCPUs on all VMs. (Note that there may be some
+* complications to providing this functionality, e.g., the MSR
+* bitmap is currently per-VM rather than per-vCPU while the
+* capability API wants to be able to control capabilities on a
+* per-vCPU basis).
+*/
+   error = vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS2,
+  MSR_VMX_PROCBASED_CTLS2,
+  PROCBASED2_ENABLE_RDTSCP, 0, );
+   cap_rdpid = error == 0 && host_has_rdpid();
+   cap_rdtscp = error == 0 && host_has_rdtscp();
+   if (cap_rdpid || cap_rdtscp)
+   procbased_ctls2 |= PROCBASED2_ENABLE_RDTSCP;
+
cap_unrestricted_guest = (vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS2,
MSR_VMX_PROCBASED_CTLS2,
PROCBASED2_UNRESTRICTED_GUEST, 0,
@@ -1007,6 +1064,15 @@ vmx_vminit(struct vm *vm, pmap_t pmap)
 * the "use TSC offsetting" execution control is enabled 

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

2020-08-18 Thread Peter Grehan
Author: grehan
Date: Tue Aug 18 07:08:17 2020
New Revision: 364339
URL: https://svnweb.freebsd.org/changeset/base/364339

Log:
  Allow guest device MMIO access from bootmem memory segments.
  
  Recent versions of UEFI have moved local APIC timer initialization into
  the early SEC phase which runs out of ROM, prior to self-relocating
  into RAM. This results in a hypervisor exit.
  
  Currently bhyve prevents instruction emulation from segments that aren't
  marked as "sysmem" aka guest RAM, with the vm_gpa_hold() routine failing.
  However, there is no reason for this restriction: the hypervisor already
  controls whether EPT mappings are marked as executable.
  
  Fix by dropping the redundant check of sysmem.
  
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D25955

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

Modified: head/sys/amd64/vmm/vmm.c
==
--- head/sys/amd64/vmm/vmm.cTue Aug 18 06:55:12 2020(r364338)
+++ head/sys/amd64/vmm/vmm.cTue Aug 18 07:08:17 2020(r364339)
@@ -999,8 +999,7 @@ vm_gpa_hold(struct vm *vm, int vcpuid, vm_paddr_t gpa,
count = 0;
for (i = 0; i < VM_MAX_MEMMAPS; i++) {
mm = >mem_maps[i];
-   if (sysmem_mapping(vm, mm) && gpa >= mm->gpa &&
-   gpa < mm->gpa + mm->len) {
+   if (gpa >= mm->gpa && gpa < mm->gpa + mm->len) {
count = vm_fault_quick_hold_pages(>vmspace->vm_map,
trunc_page(gpa), PAGE_SIZE, reqprot, , 1);
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: r364334 - in stable/12: sys/sys usr.sbin/bhyve

2020-08-17 Thread Peter Grehan
Author: grehan
Date: Tue Aug 18 03:40:09 2020
New Revision: 364334
URL: https://svnweb.freebsd.org/changeset/base/364334

Log:
  MFC 363596, 363719, 363733
  
   363596Support the setting of additional AHCI controller parameters.
   363719  Definition for the 'removable media flag' from word 0 in the 
Identify page.
   363733  Replace magic numbers in Identify page register 0 with ATA 
definitions.
  
  Relnotes: yes

Modified:
  stable/12/sys/sys/ata.h
  stable/12/usr.sbin/bhyve/bhyve.8
  stable/12/usr.sbin/bhyve/pci_ahci.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/sys/ata.h
==
--- stable/12/sys/sys/ata.h Tue Aug 18 02:42:51 2020(r364333)
+++ stable/12/sys/sys/ata.h Tue Aug 18 03:40:09 2020(r364334)
@@ -46,6 +46,7 @@ struct ata_params {
 #define ATA_ATAPI_TYPE_TAPE 0x0100  /* streaming tape */
 #define ATA_ATAPI_TYPE_CDROM0x0500  /* CD-ROM device */
 #define ATA_ATAPI_TYPE_OPTICAL  0x0700  /* optical disk */
+#define ATA_ATAPI_REMOVABLE 0x0080
 #define ATA_DRQ_MASK0x0060
 #define ATA_DRQ_SLOW0x  /* cpu 3 ms delay */
 #define ATA_DRQ_INTR0x0020  /* interrupt 10 ms delay */

Modified: stable/12/usr.sbin/bhyve/bhyve.8
==
--- stable/12/usr.sbin/bhyve/bhyve.8Tue Aug 18 02:42:51 2020
(r364333)
+++ stable/12/usr.sbin/bhyve/bhyve.8Tue Aug 18 03:40:09 2020
(r364334)
@@ -494,6 +494,27 @@ Sector size (defaults to blockif sector size).
 .It Li ser
 Serial number with maximum 20 characters.
 .El
+.Pp
+AHCI devices:
+.Bl -tag -width 10n
+.It Li nmrr
+Nominal Media Rotation Rate, known as RPM. value 1 will indicate device as 
Solid State Disk. default value is 0, not report.
+.It Li ser
+Serial Number with maximum 20 characters.
+.It Li rev
+Revision Number with maximum 8 characters.
+.It Li model
+Model Number with maximum 40 characters.
+.El
+.Pp
+HD Audio devices:
+.Bl -tag -width 10n
+.It Li play
+Playback device, typically
+.Ar /dev/dsp0 .
+.It Li rec
+Recording device, typically
+.Ar /dev/dsp0 .
 .El
 .It Fl S
 Wire guest memory.

Modified: stable/12/usr.sbin/bhyve/pci_ahci.c
==
--- stable/12/usr.sbin/bhyve/pci_ahci.c Tue Aug 18 02:42:51 2020
(r364333)
+++ stable/12/usr.sbin/bhyve/pci_ahci.c Tue Aug 18 03:40:09 2020
(r364334)
@@ -136,9 +136,9 @@ struct ahci_ioreq {
 struct ahci_port {
struct blockif_ctxt *bctx;
struct pci_ahci_softc *pr_sc;
+   struct ata_params ata_ident;
uint8_t *cmd_lst;
uint8_t *rfis;
-   char ident[AHCI_PORT_IDENT];
int port;
int atapi;
int reset;
@@ -983,7 +983,50 @@ handle_identify(struct ahci_port *p, int slot, uint8_t
ahci_write_fis_d2h(p, slot, cfis,
(ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR);
} else {
-   uint16_t buf[256];
+   ahci_write_fis_piosetup(p);
+   write_prdt(p, slot, cfis, (void*)>ata_ident, sizeof(struct 
ata_params));
+   ahci_write_fis_d2h(p, slot, cfis, ATA_S_DSC | ATA_S_READY);
+   }
+}
+
+static void
+ata_identify_init(struct ahci_port* p, int atapi)
+{
+   struct ata_params* ata_ident = >ata_ident;
+
+   if (atapi) {
+   ata_ident->config = ATA_PROTO_ATAPI | ATA_ATAPI_TYPE_CDROM |
+   ATA_ATAPI_REMOVABLE | ATA_DRQ_FAST;
+   ata_ident->capabilities1 = ATA_SUPPORT_LBA |
+   ATA_SUPPORT_DMA;
+   ata_ident->capabilities2 = (1 << 14 | 1);
+   ata_ident->atavalid = ATA_FLAG_54_58 | ATA_FLAG_64_70;
+   ata_ident->obsolete62 = 0x3f;
+   ata_ident->mwdmamodes = 7;
+   if (p->xfermode & ATA_WDMA0)
+   ata_ident->mwdmamodes |= (1 << ((p->xfermode & 7) + 8));
+   ata_ident->apiomodes = 3;
+   ata_ident->mwdmamin = 0x0078;
+   ata_ident->mwdmarec = 0x0078;
+   ata_ident->pioblind = 0x0078;
+   ata_ident->pioiordy = 0x0078;
+   ata_ident->satacapabilities = (ATA_SATA_GEN1 | ATA_SATA_GEN2 | 
ATA_SATA_GEN3);
+   ata_ident->satacapabilities2 = ((p->ssts & ATA_SS_SPD_MASK) >> 
3);
+   ata_ident->satasupport = ATA_SUPPORT_NCQ_STREAM;
+   ata_ident->version_major = 0x3f0;
+   ata_ident->support.command1 = (ATA_SUPPORT_POWERMGT | 
ATA_SUPPORT_PACKET |
+   ATA_SUPPORT_RESET | ATA_SUPPORT_NOP);
+   ata_ident->support.command2 = (1 << 14);
+   ata_ident->support.extension = (1 << 14);
+   ata_ident->enabled.command1 = (ATA_SUPPORT_POWERMGT | 
ATA_SUPPORT_PACKET |
+

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

2020-07-31 Thread Peter Grehan
Author: grehan
Date: Fri Jul 31 12:10:28 2020
New Revision: 363733
URL: https://svnweb.freebsd.org/changeset/base/363733

Log:
  Replace magic numbers in Identify page register 0 with ATA definitions.
  
  No functional change. Verified with objdump output before/after.
  
  Requested by: rpokala
  Reviewed by:  rpokala
  MFC after:3 weeks

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Fri Jul 31 12:09:59 2020
(r363732)
+++ head/usr.sbin/bhyve/pci_ahci.c  Fri Jul 31 12:10:28 2020
(r363733)
@@ -999,7 +999,8 @@ ata_identify_init(struct ahci_port* p, int atapi)
struct ata_params* ata_ident = >ata_ident;
 
if (atapi) {
-   ata_ident->config = (2 << 14 | 5 << 8 | 1 << 7 | 2 << 5);
+   ata_ident->config = ATA_PROTO_ATAPI | ATA_ATAPI_TYPE_CDROM |
+   ATA_ATAPI_REMOVABLE | ATA_DRQ_FAST;
ata_ident->capabilities1 = ATA_SUPPORT_LBA |
ATA_SUPPORT_DMA;
ata_ident->capabilities2 = (1 << 14 | 1);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r363719 - head/sys/sys

2020-07-30 Thread Peter Grehan
Author: grehan
Date: Thu Jul 30 23:49:49 2020
New Revision: 363719
URL: https://svnweb.freebsd.org/changeset/base/363719

Log:
  Definition for the 'removable media flag' from word 0 in the Identify page.
  
  This will be used to remove a magic number in the bhyve AHCI emulation.
  
  Reported by:  rpokala
  Reviewed by:  imp, rpokala
  Approved by:  imp, rpokala
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D25893

Modified:
  head/sys/sys/ata.h

Modified: head/sys/sys/ata.h
==
--- head/sys/sys/ata.h  Thu Jul 30 23:20:09 2020(r363718)
+++ head/sys/sys/ata.h  Thu Jul 30 23:49:49 2020(r363719)
@@ -46,6 +46,7 @@ struct ata_params {
 #define ATA_ATAPI_TYPE_TAPE 0x0100  /* streaming tape */
 #define ATA_ATAPI_TYPE_CDROM0x0500  /* CD-ROM device */
 #define ATA_ATAPI_TYPE_OPTICAL  0x0700  /* optical disk */
+#define ATA_ATAPI_REMOVABLE 0x0080
 #define ATA_DRQ_MASK0x0060
 #define ATA_DRQ_SLOW0x  /* cpu 3 ms delay */
 #define ATA_DRQ_INTR0x0020  /* interrupt 10 ms delay */
___
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: r363596 - head/usr.sbin/bhyve

2020-07-27 Thread Peter Grehan
Author: grehan
Date: Mon Jul 27 07:56:55 2020
New Revision: 363596
URL: https://svnweb.freebsd.org/changeset/base/363596

Log:
  Support the setting of additional AHCI controller parameters.
  
  Allow the serial number, firmware revision, model number and nominal media
  rotation rate (nmrr) parameters to be set from the command line.
  
  Note that setting the nmrr value can be   used to indicate the AHCI
  device is an SSD.
  
  Submitted by: Wanpeng Qian
  Reviewed by:  jhb, grehan (#bhyve)
  Approved by:  jhb, grehan
  MFC after:3 weeks
  Relnotes: yes
  Differential Revision:https://reviews.freebsd.org/D24174

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

Modified: head/usr.sbin/bhyve/bhyve.8
==
--- head/usr.sbin/bhyve/bhyve.8 Mon Jul 27 03:13:23 2020(r363595)
+++ head/usr.sbin/bhyve/bhyve.8 Mon Jul 27 07:56:55 2020(r363596)
@@ -540,6 +540,18 @@ Sector size (defaults to blockif sector size).
 Serial number with maximum 20 characters.
 .El
 .Pp
+AHCI devices:
+.Bl -tag -width 10n
+.It Li nmrr
+Nominal Media Rotation Rate, known as RPM. value 1 will indicate device as 
Solid State Disk. default value is 0, not report.
+.It Li ser
+Serial Number with maximum 20 characters.
+.It Li rev
+Revision Number with maximum 8 characters.
+.It Li model
+Model Number with maximum 40 characters.
+.El
+.Pp
 HD Audio devices:
 .Bl -tag -width 10n
 .It Li play

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Mon Jul 27 03:13:23 2020
(r363595)
+++ head/usr.sbin/bhyve/pci_ahci.c  Mon Jul 27 07:56:55 2020
(r363596)
@@ -139,9 +139,9 @@ struct ahci_ioreq {
 struct ahci_port {
struct blockif_ctxt *bctx;
struct pci_ahci_softc *pr_sc;
+   struct ata_params ata_ident;
uint8_t *cmd_lst;
uint8_t *rfis;
-   char ident[AHCI_PORT_IDENT];
int port;
int atapi;
int reset;
@@ -987,7 +987,49 @@ handle_identify(struct ahci_port *p, int slot, uint8_t
ahci_write_fis_d2h(p, slot, cfis,
(ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR);
} else {
-   uint16_t buf[256];
+   ahci_write_fis_piosetup(p);
+   write_prdt(p, slot, cfis, (void*)>ata_ident, sizeof(struct 
ata_params));
+   ahci_write_fis_d2h(p, slot, cfis, ATA_S_DSC | ATA_S_READY);
+   }
+}
+
+static void
+ata_identify_init(struct ahci_port* p, int atapi)
+{
+   struct ata_params* ata_ident = >ata_ident;
+
+   if (atapi) {
+   ata_ident->config = (2 << 14 | 5 << 8 | 1 << 7 | 2 << 5);
+   ata_ident->capabilities1 = ATA_SUPPORT_LBA |
+   ATA_SUPPORT_DMA;
+   ata_ident->capabilities2 = (1 << 14 | 1);
+   ata_ident->atavalid = ATA_FLAG_54_58 | ATA_FLAG_64_70;
+   ata_ident->obsolete62 = 0x3f;
+   ata_ident->mwdmamodes = 7;
+   if (p->xfermode & ATA_WDMA0)
+   ata_ident->mwdmamodes |= (1 << ((p->xfermode & 7) + 8));
+   ata_ident->apiomodes = 3;
+   ata_ident->mwdmamin = 0x0078;
+   ata_ident->mwdmarec = 0x0078;
+   ata_ident->pioblind = 0x0078;
+   ata_ident->pioiordy = 0x0078;
+   ata_ident->satacapabilities = (ATA_SATA_GEN1 | ATA_SATA_GEN2 | 
ATA_SATA_GEN3);
+   ata_ident->satacapabilities2 = ((p->ssts & ATA_SS_SPD_MASK) >> 
3);
+   ata_ident->satasupport = ATA_SUPPORT_NCQ_STREAM;
+   ata_ident->version_major = 0x3f0;
+   ata_ident->support.command1 = (ATA_SUPPORT_POWERMGT | 
ATA_SUPPORT_PACKET |
+   ATA_SUPPORT_RESET | ATA_SUPPORT_NOP);
+   ata_ident->support.command2 = (1 << 14);
+   ata_ident->support.extension = (1 << 14);
+   ata_ident->enabled.command1 = (ATA_SUPPORT_POWERMGT | 
ATA_SUPPORT_PACKET |
+   ATA_SUPPORT_RESET | ATA_SUPPORT_NOP);
+   ata_ident->enabled.extension = (1 << 14);
+   ata_ident->udmamodes = 0x7f;
+   if (p->xfermode & ATA_UDMA0)
+   ata_ident->udmamodes |= (1 << ((p->xfermode & 7) + 8));
+   ata_ident->transport_major = 0x1020;
+   ata_ident->integrity = 0x00a5;
+   } else {
uint64_t sectors;
int sectsz, psectsz, psectoff, candelete, ro;
uint16_t cyl;
@@ -999,87 +1041,85 @@ handle_identify(struct ahci_port *p, int slot, uint8_t
sectors = blockif_size(p->bctx) / sectsz;
blockif_chs(p->bctx, , , );
blockif_psectsz(p->bctx, , );
-   memset(buf, 0, sizeof(buf));
-   buf[0] = 0x0040;
-   buf[1] = cyl;
-   

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

2020-07-15 Thread Peter Grehan
Author: grehan
Date: Thu Jul 16 03:05:10 2020
New Revision: 363240
URL: https://svnweb.freebsd.org/changeset/base/363240

Log:
  MFC r362952
  
  Silence ACPI RTC error/warning in Linux guests.

Modified:
  stable/12/usr.sbin/bhyve/pm.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/pm.c
==
--- stable/12/usr.sbin/bhyve/pm.c   Thu Jul 16 02:53:13 2020
(r363239)
+++ stable/12/usr.sbin/bhyve/pm.c   Thu Jul 16 03:05:10 2020
(r363240)
@@ -191,7 +191,7 @@ pm1_enable_handler(struct vmctx *ctx, int vcpu, int in
 * the global lock, but ACPI-CA whines profusely if it
 * can't set GBL_EN.
 */
-   pm1_enable = *eax & (PM1_PWRBTN_EN | PM1_GBL_EN);
+   pm1_enable = *eax & (PM1_RTC_EN | PM1_PWRBTN_EN | PM1_GBL_EN);
sci_update(ctx);
}
pthread_mutex_unlock(_lock);
___
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: r363239 - stable/12/usr.sbin/bhyve

2020-07-15 Thread Peter Grehan
Author: grehan
Date: Thu Jul 16 02:53:13 2020
New Revision: 363239
URL: https://svnweb.freebsd.org/changeset/base/363239

Log:
  MFC r362644
  
  Prevent calling USB backends multiple times.

Modified:
  stable/12/usr.sbin/bhyve/pci_xhci.c
  stable/12/usr.sbin/bhyve/usb_mouse.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/pci_xhci.c
==
--- stable/12/usr.sbin/bhyve/pci_xhci.c Wed Jul 15 22:42:50 2020
(r363238)
+++ stable/12/usr.sbin/bhyve/pci_xhci.c Thu Jul 16 02:53:13 2020
(r363239)
@@ -1838,6 +1838,9 @@ retry:
 
DPRINTF(("pci_xhci[%d]: xfer->ndata %u", __LINE__, xfer->ndata));
 
+   if (xfer->ndata <= 0)
+   goto errout;
+
if (epid == 1) {
err = USB_ERR_NOT_STARTED;
if (dev->dev_ue->ue_request != NULL)
@@ -1852,6 +1855,7 @@ retry:
 
err = USB_TO_XHCI_ERR(err);
if ((err == XHCI_TRB_ERROR_SUCCESS) ||
+   (err == XHCI_TRB_ERROR_STALL) ||
(err == XHCI_TRB_ERROR_SHORT_PKT)) {
err = pci_xhci_xfer_complete(sc, xfer, slot, epid, _intr);
if (err != XHCI_TRB_ERROR_SUCCESS)

Modified: stable/12/usr.sbin/bhyve/usb_mouse.c
==
--- stable/12/usr.sbin/bhyve/usb_mouse.cWed Jul 15 22:42:50 2020
(r363238)
+++ stable/12/usr.sbin/bhyve/usb_mouse.cThu Jul 16 02:53:13 2020
(r363239)
@@ -388,7 +388,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
 "sizeof(umouse_dev_desc) %lu",
 len, sizeof(umouse_dev_desc)));
if ((value & 0xFF) != 0) {
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
if (len > sizeof(umouse_dev_desc)) {
@@ -403,7 +403,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
case UDESC_CONFIG:
DPRINTF(("umouse: (->UDESC_CONFIG)"));
if ((value & 0xFF) != 0) {
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
if (len > sizeof(umouse_confd)) {
@@ -472,7 +472,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
 
default:
DPRINTF(("umouse: unknown(%d)->ERROR", value >> 8));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
eshort = data->blen > 0;
@@ -496,7 +496,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
break;
default:
DPRINTF(("umouse: IO ERROR"));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
eshort = data->blen > 0;
@@ -507,7 +507,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
if (index != 0) {
DPRINTF(("umouse get_interface, invalid index %d",
index));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
 
@@ -578,7 +578,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
case UREQ(UR_SET_FEATURE, UT_WRITE_INTERFACE):
case UREQ(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
DPRINTF(("umouse: (UR_CLEAR_FEATURE, UT_WRITE_INTERFACE)"));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
 
case UREQ(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
@@ -617,7 +617,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
memcpy(data->buf, >um_report, len);
data->bdone += len;
} else {
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
eshort = data->blen > 0;
@@ -659,7 +659,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
 
default:
DPRINTF((" umouse request unhandled"));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
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: r363070 - head/usr.sbin/bhyve

2020-07-10 Thread Peter Grehan
Author: grehan
Date: Fri Jul 10 07:26:50 2020
New Revision: 363070
URL: https://svnweb.freebsd.org/changeset/base/363070

Log:
  Advertise 64-bit physical-address capability.
  
  This fixes a coredump with NetBSD guests when XHCI is configured.
  On seeing the AC64 flag clear, the NetBSD XHCI driver was only writing
  to the lower 32-bits of 64-bit physical address registers. The emulation
  relies on a write to the hi 32-bits to calculate a host virtual address
  for internal use, and has always supported 64-bit addressing.
  
  All other guests were seen to write to both the lo- and hi- address
  registers, regardless of the AC64 setting.
  
  Discussed with:  Leon Dang (author)
  Tested with:  Ubuntu 16/18/20, Windows10, OpenBSD UEFI guests.
  
  MFC after:2 weeks.

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

Modified: head/usr.sbin/bhyve/pci_xhci.c
==
--- head/usr.sbin/bhyve/pci_xhci.c  Fri Jul 10 06:47:58 2020
(r363069)
+++ head/usr.sbin/bhyve/pci_xhci.c  Fri Jul 10 07:26:50 2020
(r363070)
@@ -2805,7 +2805,8 @@ pci_xhci_init(struct vmctx *ctx, struct pci_devinst *p
sc->hcsparams2 = XHCI_SET_HCSP2_ERSTMAX(XHCI_ERST_MAX) |
 XHCI_SET_HCSP2_IST(0x04);
sc->hcsparams3 = 0; /* no latency */
-   sc->hccparams1 = XHCI_SET_HCCP1_NSS(1) |/* no 2nd-streams */
+   sc->hccparams1 = XHCI_SET_HCCP1_AC64(1) |   /* 64-bit addrs */
+XHCI_SET_HCCP1_NSS(1) |/* no 2nd-streams */
 XHCI_SET_HCCP1_SPC(1) |/* short packet */
 XHCI_SET_HCCP1_MAXPSA(XHCI_STREAMS_MAX);
sc->hccparams2 = XHCI_SET_HCCP2_LEC(1) |
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


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

2020-07-06 Thread Peter Grehan
Author: grehan
Date: Mon Jul  6 08:36:14 2020
New Revision: 362952
URL: https://svnweb.freebsd.org/changeset/base/362952

Log:
  Silence ACPI RTC error/warning in Linux guests.
  
  Allow guests to   set the RTC bit in the ACPI PM control register.
  This eliminates an annoying   (and harmless) Linux kernel boot message.
  
  PR:   244721
  Submitted by: Jose Luis Duran
  MFC after:1 week

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

Modified: head/usr.sbin/bhyve/pm.c
==
--- head/usr.sbin/bhyve/pm.cMon Jul  6 02:00:35 2020(r362951)
+++ head/usr.sbin/bhyve/pm.cMon Jul  6 08:36:14 2020(r362952)
@@ -198,7 +198,7 @@ pm1_enable_handler(struct vmctx *ctx, int vcpu, int in
 * the global lock, but ACPI-CA whines profusely if it
 * can't set GBL_EN.
 */
-   pm1_enable = *eax & (PM1_PWRBTN_EN | PM1_GBL_EN);
+   pm1_enable = *eax & (PM1_RTC_EN | PM1_PWRBTN_EN | PM1_GBL_EN);
sci_update(ctx);
}
pthread_mutex_unlock(_lock);
___
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: r362644 - head/usr.sbin/bhyve

2020-06-26 Thread Peter Grehan
Author: grehan
Date: Fri Jun 26 08:20:38 2020
New Revision: 362644
URL: https://svnweb.freebsd.org/changeset/base/362644

Log:
  Prevent calling USB backends multiple times.
  
  The TRB processing loop could potentially call a back-end twice
  with the same status transaction. While this was generally benign,
  some code paths in the tablet backend weren't set up to handle
  this case, resulting in a NULL dereference.
  
  Fix by
   - returning a STALL error when an invalid request was seen in the backend
   - skipping a call to the backend if the number of packets in a status
 transaction was zero (this code fragment was taken from the Intel ACRN
 xhci backend)
  
  PR:   246964
  Reported by:  Ali Abdallah
  Discussed with: Leon Dang (author)
  Reviewed by: jhb (#bhyve), Leon Dang
  Approved by: jhb
  Obtained from:  Intel ACRN (partially)
  MFC after: 2 weeks
  Differential Revision:https://reviews.freebsd.org/D25228

Modified:
  head/usr.sbin/bhyve/pci_xhci.c
  head/usr.sbin/bhyve/usb_mouse.c

Modified: head/usr.sbin/bhyve/pci_xhci.c
==
--- head/usr.sbin/bhyve/pci_xhci.c  Fri Jun 26 06:11:50 2020
(r362643)
+++ head/usr.sbin/bhyve/pci_xhci.c  Fri Jun 26 08:20:38 2020
(r362644)
@@ -1843,6 +1843,9 @@ retry:
 
DPRINTF(("pci_xhci[%d]: xfer->ndata %u", __LINE__, xfer->ndata));
 
+   if (xfer->ndata <= 0)
+   goto errout;
+
if (epid == 1) {
err = USB_ERR_NOT_STARTED;
if (dev->dev_ue->ue_request != NULL)
@@ -1857,6 +1860,7 @@ retry:
 
err = USB_TO_XHCI_ERR(err);
if ((err == XHCI_TRB_ERROR_SUCCESS) ||
+   (err == XHCI_TRB_ERROR_STALL) ||
(err == XHCI_TRB_ERROR_SHORT_PKT)) {
err = pci_xhci_xfer_complete(sc, xfer, slot, epid, _intr);
if (err != XHCI_TRB_ERROR_SUCCESS)

Modified: head/usr.sbin/bhyve/usb_mouse.c
==
--- head/usr.sbin/bhyve/usb_mouse.c Fri Jun 26 06:11:50 2020
(r362643)
+++ head/usr.sbin/bhyve/usb_mouse.c Fri Jun 26 08:20:38 2020
(r362644)
@@ -390,7 +390,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
 "sizeof(umouse_dev_desc) %lu",
 len, sizeof(umouse_dev_desc)));
if ((value & 0xFF) != 0) {
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
if (len > sizeof(umouse_dev_desc)) {
@@ -405,7 +405,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
case UDESC_CONFIG:
DPRINTF(("umouse: (->UDESC_CONFIG)"));
if ((value & 0xFF) != 0) {
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
if (len > sizeof(umouse_confd)) {
@@ -474,7 +474,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
 
default:
DPRINTF(("umouse: unknown(%d)->ERROR", value >> 8));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
eshort = data->blen > 0;
@@ -498,7 +498,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
break;
default:
DPRINTF(("umouse: IO ERROR"));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
eshort = data->blen > 0;
@@ -509,7 +509,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
if (index != 0) {
DPRINTF(("umouse get_interface, invalid index %d",
index));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
}
 
@@ -580,7 +580,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
case UREQ(UR_SET_FEATURE, UT_WRITE_INTERFACE):
case UREQ(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
DPRINTF(("umouse: (UR_CLEAR_FEATURE, UT_WRITE_INTERFACE)"));
-   err = USB_ERR_IOERROR;
+   err = USB_ERR_STALLED;
goto done;
 
case UREQ(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
@@ -619,7 +619,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer
memcpy(data->buf, >um_report, len);
data->bdone += len;
} else {
-   err = USB_ERR_IOERROR;
+   

svn commit: r362643 - head

2020-06-26 Thread Peter Grehan
Author: grehan
Date: Fri Jun 26 06:11:50 2020
New Revision: 362643
URL: https://svnweb.freebsd.org/changeset/base/362643

Log:
  Update bhyve maintainers.
  
  Suggested by: jhb
  Approved by:  jhb, tychon

Modified:
  head/MAINTAINERS

Modified: head/MAINTAINERS
==
--- head/MAINTAINERSFri Jun 26 04:46:45 2020(r362642)
+++ head/MAINTAINERSFri Jun 26 06:11:50 2020(r362643)
@@ -119,11 +119,11 @@ usr.sbin/bsdconfigdteske  Pre-commit phabricator 
revie
 usr.sbin/dpv   dteske  Pre-commit review requested. Keep in sync with libdpv.
 usr.sbin/pkg   pkg@Please coordinate behavior or flag changes with pkg 
team.
 usr.sbin/sysrc dteske  Pre-commit phabricator review requested. Keep in sync 
with bsdconfig(8) sysrc.subr.
-vmm(4) tychon, jhb Pre-commit review requested via #bhyve
+vmm(4) jhb, grehan Pre-commit review requested via #bhyve
phabricator group.
-libvmmapi  tychon, jhb Pre-commit review requested via #bhyve
+libvmmapi  jhb, grehan Pre-commit review requested via #bhyve
phabricator group.
-usr.sbin/bhyve*tychon, jhb Pre-commit review requested via #bhyve
+usr.sbin/bhyve*jhb, grehan Pre-commit review requested via #bhyve
phabricator group.
 autofs(5)  trasz   Pre-commit review recommended.
 iscsi(4)   trasz   Pre-commit review recommended.
___
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: r361686 - stable/12/usr.sbin/bhyve

2020-05-31 Thread Peter Grehan
Author: grehan
Date: Mon Jun  1 05:14:01 2020
New Revision: 361686
URL: https://svnweb.freebsd.org/changeset/base/361686

Log:
  MFC r361442
  Fix pci-passthru MSI issues with OpenBSD guests
  
  PR:   245392

Modified:
  stable/12/usr.sbin/bhyve/pci_emul.c
  stable/12/usr.sbin/bhyve/pci_emul.h
  stable/12/usr.sbin/bhyve/pci_passthru.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/pci_emul.c
==
--- stable/12/usr.sbin/bhyve/pci_emul.c Mon Jun  1 03:37:58 2020
(r361685)
+++ stable/12/usr.sbin/bhyve/pci_emul.c Mon Jun  1 05:14:01 2020
(r361686)
@@ -874,7 +874,7 @@ pci_emul_add_msixcap(struct pci_devinst *pi, int msgnu
sizeof(msixcap)));
 }
 
-void
+static void
 msixcap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
 int bytes, uint32_t val)
 {
@@ -898,7 +898,7 @@ msixcap_cfgwrite(struct pci_devinst *pi, int capoff, i
CFGWRITE(pi, offset, val, bytes);
 }
 
-void
+static void
 msicap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
int bytes, uint32_t val)
 {
@@ -977,30 +977,34 @@ pci_emul_add_pciecap(struct pci_devinst *pi, int type)
 
 /*
  * This function assumes that 'coff' is in the capabilities region of the
- * config space.
+ * config space. A capoff parameter of zero will force a search for the
+ * offset and type.
  */
-static void
-pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes, uint32_t val)
+void
+pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes, uint32_t val,
+uint8_t capoff, int capid)
 {
-   int capid;
-   uint8_t capoff, nextoff;
+   uint8_t nextoff;
 
/* Do not allow un-aligned writes */
if ((offset & (bytes - 1)) != 0)
return;
 
-   /* Find the capability that we want to update */
-   capoff = CAP_START_OFFSET;
-   while (1) {
-   nextoff = pci_get_cfgdata8(pi, capoff + 1);
-   if (nextoff == 0)
-   break;
-   if (offset >= capoff && offset < nextoff)
-   break;
+   if (capoff == 0) {
+   /* Find the capability that we want to update */
+   capoff = CAP_START_OFFSET;
+   while (1) {
+   nextoff = pci_get_cfgdata8(pi, capoff + 1);
+   if (nextoff == 0)
+   break;
+   if (offset >= capoff && offset < nextoff)
+   break;
 
-   capoff = nextoff;
+   capoff = nextoff;
+   }
+   assert(offset >= capoff);
+   capid = pci_get_cfgdata8(pi, capoff);
}
-   assert(offset >= capoff);
 
/*
 * Capability ID and Next Capability Pointer are readonly.
@@ -1017,7 +1021,6 @@ pci_emul_capwrite(struct pci_devinst *pi, int offset, 
return;
}
 
-   capid = pci_get_cfgdata8(pi, capoff);
switch (capid) {
case PCIY_MSI:
msicap_cfgwrite(pi, capoff, offset, bytes, val);
@@ -1896,7 +1899,7 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus
pci_set_cfgdata32(pi, coff, bar);
 
} else if (pci_emul_iscap(pi, coff)) {
-   pci_emul_capwrite(pi, coff, bytes, *eax);
+   pci_emul_capwrite(pi, coff, bytes, *eax, 0, 0);
} else if (coff >= PCIR_COMMAND && coff < PCIR_REVID) {
pci_emul_cmdsts_write(pi, coff, *eax, bytes);
} else {

Modified: stable/12/usr.sbin/bhyve/pci_emul.h
==
--- stable/12/usr.sbin/bhyve/pci_emul.h Mon Jun  1 03:37:58 2020
(r361685)
+++ stable/12/usr.sbin/bhyve/pci_emul.h Mon Jun  1 05:14:01 2020
(r361686)
@@ -212,10 +212,6 @@ typedef void (*pci_lintr_cb)(int b, int s, int pin, in
 int ioapic_irq, void *arg);
 
 intinit_pci(struct vmctx *ctx);
-void   msicap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
-   int bytes, uint32_t val);
-void   msixcap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
-   int bytes, uint32_t val);
 void   pci_callback(void);
 intpci_emul_alloc_bar(struct pci_devinst *pdi, int idx,
enum pcibar_type type, uint64_t size);
@@ -223,6 +219,8 @@ int pci_emul_alloc_pbar(struct pci_devinst *pdi, int i
uint64_t hostbase, enum pcibar_type type, uint64_t size);
 intpci_emul_add_msicap(struct pci_devinst *pi, int msgnum);
 intpci_emul_add_pciecap(struct pci_devinst *pi, int pcie_device_type);
+void   pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes,
+   uint32_t val, uint8_t capoff, int capid);
 void   pci_emul_cmd_changed(struct pci_devinst *pi, uint16_t 

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

2020-05-25 Thread Peter Grehan
Author: grehan
Date: Mon May 25 06:25:31 2020
New Revision: 361442
URL: https://svnweb.freebsd.org/changeset/base/361442

Log:
  Fix pci-passthru MSI issues with OpenBSD guests
  
  - Return 2 x 16-bit registers in the correct byte order
   for a 4-byte read that spans the CMD/STATUS register.
This reversal was hiding the capabilities-list, which prevented
   the MSI capability from being found for XHCI passthru.
  
  - Reorganize MSI/MSI-x config writes so that a 4-byte write at the
   capability offset would have the read-only portion skipped.
This prevented MSI interrupts from being enabled.
  
   Reported and extensively tested by Anatoli (me at anatoli dot ws)
  
  PR:   245392
  Reported by:  Anatoli (me at anatoli dot ws)
  Reviewed by:  jhb (bhyve)
  Approved by:  jhb, bz (mentor)
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D24951

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

Modified: head/usr.sbin/bhyve/pci_emul.c
==
--- head/usr.sbin/bhyve/pci_emul.c  Mon May 25 04:57:57 2020
(r361441)
+++ head/usr.sbin/bhyve/pci_emul.c  Mon May 25 06:25:31 2020
(r361442)
@@ -875,7 +875,7 @@ pci_emul_add_msixcap(struct pci_devinst *pi, int msgnu
sizeof(msixcap)));
 }
 
-void
+static void
 msixcap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
 int bytes, uint32_t val)
 {
@@ -899,7 +899,7 @@ msixcap_cfgwrite(struct pci_devinst *pi, int capoff, i
CFGWRITE(pi, offset, val, bytes);
 }
 
-void
+static void
 msicap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
int bytes, uint32_t val)
 {
@@ -978,30 +978,34 @@ pci_emul_add_pciecap(struct pci_devinst *pi, int type)
 
 /*
  * This function assumes that 'coff' is in the capabilities region of the
- * config space.
+ * config space. A capoff parameter of zero will force a search for the
+ * offset and type.
  */
-static void
-pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes, uint32_t val)
+void
+pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes, uint32_t val,
+uint8_t capoff, int capid)
 {
-   int capid;
-   uint8_t capoff, nextoff;
+   uint8_t nextoff;
 
/* Do not allow un-aligned writes */
if ((offset & (bytes - 1)) != 0)
return;
 
-   /* Find the capability that we want to update */
-   capoff = CAP_START_OFFSET;
-   while (1) {
-   nextoff = pci_get_cfgdata8(pi, capoff + 1);
-   if (nextoff == 0)
-   break;
-   if (offset >= capoff && offset < nextoff)
-   break;
+   if (capoff == 0) {
+   /* Find the capability that we want to update */
+   capoff = CAP_START_OFFSET;
+   while (1) {
+   nextoff = pci_get_cfgdata8(pi, capoff + 1);
+   if (nextoff == 0)
+   break;
+   if (offset >= capoff && offset < nextoff)
+   break;
 
-   capoff = nextoff;
+   capoff = nextoff;
+   }
+   assert(offset >= capoff);
+   capid = pci_get_cfgdata8(pi, capoff);
}
-   assert(offset >= capoff);
 
/*
 * Capability ID and Next Capability Pointer are readonly.
@@ -1018,7 +1022,6 @@ pci_emul_capwrite(struct pci_devinst *pi, int offset, 
return;
}
 
-   capid = pci_get_cfgdata8(pi, capoff);
switch (capid) {
case PCIY_MSI:
msicap_cfgwrite(pi, capoff, offset, bytes, val);
@@ -1897,7 +1900,7 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus
pci_set_cfgdata32(pi, coff, bar);
 
} else if (pci_emul_iscap(pi, coff)) {
-   pci_emul_capwrite(pi, coff, bytes, *eax);
+   pci_emul_capwrite(pi, coff, bytes, *eax, 0, 0);
} else if (coff >= PCIR_COMMAND && coff < PCIR_REVID) {
pci_emul_cmdsts_write(pi, coff, *eax, bytes);
} else {

Modified: head/usr.sbin/bhyve/pci_emul.h
==
--- head/usr.sbin/bhyve/pci_emul.h  Mon May 25 04:57:57 2020
(r361441)
+++ head/usr.sbin/bhyve/pci_emul.h  Mon May 25 06:25:31 2020
(r361442)
@@ -218,10 +218,6 @@ typedef void (*pci_lintr_cb)(int b, int s, int pin, in
 int ioapic_irq, void *arg);
 
 intinit_pci(struct vmctx *ctx);
-void   msicap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
-   int bytes, uint32_t val);
-void   msixcap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
-   int bytes, uint32_t val);
 void   

svn commit: r361151 - releng/11.4/sys/amd64/vmm

2020-05-18 Thread Peter Grehan
Author: grehan
Date: Mon May 18 07:06:35 2020
New Revision: 361151
URL: https://svnweb.freebsd.org/changeset/base/361151

Log:
  MFS r361132
 Hide host CPUID 0x15 TSC/Crystal ratio/freq info from guest
  
  Approved by: re (kib), bz (mentor)

Modified:
  releng/11.4/sys/amd64/vmm/x86.c
  releng/11.4/sys/amd64/vmm/x86.h
Directory Properties:
  releng/11.4/   (props changed)

Modified: releng/11.4/sys/amd64/vmm/x86.c
==
--- releng/11.4/sys/amd64/vmm/x86.c Mon May 18 02:14:25 2020
(r361150)
+++ releng/11.4/sys/amd64/vmm/x86.c Mon May 18 07:06:35 2020
(r361151)
@@ -554,6 +554,18 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
}
break;
 
+   case CPUID__0015:
+   /*
+* Don't report CPU TSC/Crystal ratio and clock
+* values since guests may use these to derive the
+* local APIC frequency..
+*/
+   regs[0] = 0;
+   regs[1] = 0;
+   regs[2] = 0;
+   regs[3] = 0;
+   break;
+
case 0x4000:
regs[0] = CPUID_VM_HIGH;
bcopy(bhyve_id, [1], 4);

Modified: releng/11.4/sys/amd64/vmm/x86.h
==
--- releng/11.4/sys/amd64/vmm/x86.h Mon May 18 02:14:25 2020
(r361150)
+++ releng/11.4/sys/amd64/vmm/x86.h Mon May 18 07:06:35 2020
(r361151)
@@ -39,6 +39,7 @@
 #defineCPUID__000A (0xA)
 #defineCPUID__000B (0xB)
 #defineCPUID__000D (0xD)
+#defineCPUID__0015 (0x15)
 #define CPUID_8000_(0x8000)
 #define CPUID_8000_0001(0x8001)
 #define CPUID_8000_0002(0x8002)
___
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: r361132 - stable/11/sys/amd64/vmm

2020-05-17 Thread Peter Grehan
Author: grehan
Date: Sun May 17 11:13:12 2020
New Revision: 361132
URL: https://svnweb.freebsd.org/changeset/base/361132

Log:
MFC r361064
Hide host CPUID 0x15 TSC/Crystal ratio/freq info from guest
  
In recent Linux (5.3+) and OpenBSD (6.6+) kernels, and with hosts that
support CPUID 0x15, the local APIC frequency is determined directly
from the reported crystal clock to avoid calibration against the 8254
timer.
  
However, the local APIC frequency implemented by bhyve is 128MHz, where
most h/w systems report frequencies around 25MHz. This shows up on
OpenBSD guests as repeated keystrokes on the emulated PS2 keyboard
when using VNC, since the kernel's timers are now much shorter.
  
Fix by reporting all-zeroes for CPUID 0x15. This allows guests to fall
back to using the 8254 to calibrate the local APIC frequency.
  
Future work could be to compute values returned for 0x15 that would
match the host TSC and bhyve local APIC frequency, though all 
dependencies
on this would need to be examined (for example, Linux will start using
0x16 for some hosts).
  
PR: 246321
Reported by:Jason Tubnor (and tested)
  
  Approved by:  bz (mentor)

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

Modified: stable/11/sys/amd64/vmm/x86.c
==
--- stable/11/sys/amd64/vmm/x86.c   Sun May 17 11:09:38 2020
(r361131)
+++ stable/11/sys/amd64/vmm/x86.c   Sun May 17 11:13:12 2020
(r361132)
@@ -554,6 +554,18 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
}
break;
 
+   case CPUID__0015:
+   /*
+* Don't report CPU TSC/Crystal ratio and clock
+* values since guests may use these to derive the
+* local APIC frequency..
+*/
+   regs[0] = 0;
+   regs[1] = 0;
+   regs[2] = 0;
+   regs[3] = 0;
+   break;
+
case 0x4000:
regs[0] = CPUID_VM_HIGH;
bcopy(bhyve_id, [1], 4);

Modified: stable/11/sys/amd64/vmm/x86.h
==
--- stable/11/sys/amd64/vmm/x86.h   Sun May 17 11:09:38 2020
(r361131)
+++ stable/11/sys/amd64/vmm/x86.h   Sun May 17 11:13:12 2020
(r361132)
@@ -39,6 +39,7 @@
 #defineCPUID__000A (0xA)
 #defineCPUID__000B (0xB)
 #defineCPUID__000D (0xD)
+#defineCPUID__0015 (0x15)
 #define CPUID_8000_(0x8000)
 #define CPUID_8000_0001(0x8001)
 #define CPUID_8000_0002(0x8002)
___
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: r361131 - stable/12/sys/amd64/vmm

2020-05-17 Thread Peter Grehan
Author: grehan
Date: Sun May 17 11:09:38 2020
New Revision: 361131
URL: https://svnweb.freebsd.org/changeset/base/361131

Log:
  MFC r361064
  Hide host CPUID 0x15 TSC/Crystal ratio/freq info from guest
  
  In recent Linux (5.3+) and OpenBSD (6.6+) kernels, and with hosts that
  support CPUID 0x15, the local APIC frequency is determined directly
  from the reported crystal clock to avoid calibration against the 8254
  timer.
  
  However, the local APIC frequency implemented by bhyve is 128MHz, where
  most h/w systems report frequencies around 25MHz. This shows up on
  OpenBSD guests as repeated keystrokes on the emulated PS2 keyboard
  when using VNC, since the kernel's timers are now much shorter.
  
  Fix by reporting all-zeroes for CPUID 0x15. This allows guests to fall
  back to using the 8254 to calibrate the local APIC frequency.
  
  Future work could be to compute values returned for 0x15 that would
  match the host TSC and bhyve local APIC frequency, though all dependencies
  on this would need to be examined (for example, Linux will start using
  0x16 for some hosts).
  
  PR:   246321
  Reported by:  Jason Tubnor (and tested)
  
  Approved by:  bz (mentor)

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

Modified: stable/12/sys/amd64/vmm/x86.c
==
--- stable/12/sys/amd64/vmm/x86.c   Sun May 17 09:34:29 2020
(r361130)
+++ stable/12/sys/amd64/vmm/x86.c   Sun May 17 11:09:38 2020
(r361131)
@@ -559,6 +559,18 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
}
break;
 
+   case CPUID__0015:
+   /*
+* Don't report CPU TSC/Crystal ratio and clock
+* values since guests may use these to derive the
+* local APIC frequency..
+*/
+   regs[0] = 0;
+   regs[1] = 0;
+   regs[2] = 0;
+   regs[3] = 0;
+   break;
+
case 0x4000:
regs[0] = CPUID_VM_HIGH;
bcopy(bhyve_id, [1], 4);

Modified: stable/12/sys/amd64/vmm/x86.h
==
--- stable/12/sys/amd64/vmm/x86.h   Sun May 17 09:34:29 2020
(r361130)
+++ stable/12/sys/amd64/vmm/x86.h   Sun May 17 11:09:38 2020
(r361131)
@@ -41,6 +41,7 @@
 #defineCPUID__000A (0xA)
 #defineCPUID__000B (0xB)
 #defineCPUID__000D (0xD)
+#defineCPUID__0015 (0x15)
 #define CPUID_8000_(0x8000)
 #define CPUID_8000_0001(0x8001)
 #define CPUID_8000_0002(0x8002)
___
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: r361064 - head/sys/amd64/vmm

2020-05-14 Thread Peter Grehan
Author: grehan
Date: Thu May 14 22:18:12 2020
New Revision: 361064
URL: https://svnweb.freebsd.org/changeset/base/361064

Log:
  Hide host CPUID 0x15 TSC/Crystal ratio/freq info from guest
  
  In recent Linux (5.3+) and OpenBSD (6.6+) kernels, and with hosts that
  support CPUID 0x15, the local APIC frequency is determined directly
  from the reported crystal clock to avoid calibration against the 8254
  timer.
  
  However, the local APIC frequency implemented by bhyve is 128MHz, where
  most h/w systems report frequencies around 25MHz. This shows up on
  OpenBSD guests as repeated keystrokes on the emulated PS2 keyboard
  when using VNC, since the kernel's timers are now much shorter.
  
  Fix by reporting all-zeroes for CPUID 0x15. This allows guests to fall
  back to using the 8254 to calibrate the local APIC frequency.
  
  Future work could be to compute values returned for 0x15 that would
  match the host TSC and bhyve local APIC frequency, though all dependencies
  on this would need to be examined (for example, Linux will start using
  0x16 for some hosts).
  
  PR:   246321
  Reported by:  Jason Tubnor (and tested)
  Reviewed by:  jhb
  Approved by:  jhb, bz (mentor)
  MFC after:3 days
  Differential Revision:https://reviews.freebsd.org/D24837

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

Modified: head/sys/amd64/vmm/x86.c
==
--- head/sys/amd64/vmm/x86.cThu May 14 21:59:23 2020(r361063)
+++ head/sys/amd64/vmm/x86.cThu May 14 22:18:12 2020(r361064)
@@ -560,6 +560,18 @@ x86_emulate_cpuid(struct vm *vm, int vcpu_id,
}
break;
 
+   case CPUID__0015:
+   /*
+* Don't report CPU TSC/Crystal ratio and clock
+* values since guests may use these to derive the
+* local APIC frequency..
+*/
+   regs[0] = 0;
+   regs[1] = 0;
+   regs[2] = 0;
+   regs[3] = 0;
+   break;
+
case 0x4000:
regs[0] = CPUID_VM_HIGH;
bcopy(bhyve_id, [1], 4);

Modified: head/sys/amd64/vmm/x86.h
==
--- head/sys/amd64/vmm/x86.hThu May 14 21:59:23 2020(r361063)
+++ head/sys/amd64/vmm/x86.hThu May 14 22:18:12 2020(r361064)
@@ -41,6 +41,7 @@
 #defineCPUID__000A (0xA)
 #defineCPUID__000B (0xB)
 #defineCPUID__000D (0xD)
+#defineCPUID__0015 (0x15)
 #define CPUID_8000_(0x8000)
 #define CPUID_8000_0001(0x8001)
 #define CPUID_8000_0002(0x8002)
___
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: r360432 - in stable/11/sys/amd64/vmm: intel io

2020-04-28 Thread Peter Grehan
Author: grehan
Date: Tue Apr 28 08:28:13 2020
New Revision: 360432
URL: https://svnweb.freebsd.org/changeset/base/360432

Log:
  MFC r358848: Untangle TPR shadowing and APIC virtualization.
  
This speeds up Windows guests tremendously.
  
The patch does:
Add a new tuneable 'hw.vmm.vmx.use_tpr_shadowing' to disable TLP shadowing.
Also add 'hw.vmm.vmx.cap.tpr_shadowing' to be able to query if TPR 
shadowing is used.
  
Detach the initialization of TPR shadowing from the initialization of APIC 
virtualization.
APIC virtualization still needs TPR shadowing, but not vice versa.
Any CPU that supports APIC virtualization should also support TPR shadowing.
  
When TPR shadowing is used, the APIC page of each vCPU is written to the 
VMCS_VIRTUAL_APIC field of the VMCS
so that the CPU can write directly to the page without intercept.
  
On vm exit, vlapic_update_ppr() is called to update the PPR.
  
  Submitted by:   Yamagi Burmeister
  Reviewed by:grehan
  Differential Revision:https://reviews.freebsd.org/D22942
  Approved by:bz (mentor)
  Tested by:  Jason Tubnor

Modified:
  stable/11/sys/amd64/vmm/intel/vmx.c
  stable/11/sys/amd64/vmm/io/vlapic.c
  stable/11/sys/amd64/vmm/io/vlapic.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/amd64/vmm/intel/vmx.c
==
--- stable/11/sys/amd64/vmm/intel/vmx.c Tue Apr 28 08:06:56 2020
(r360431)
+++ stable/11/sys/amd64/vmm/intel/vmx.c Tue Apr 28 08:28:13 2020
(r360432)
@@ -170,6 +170,10 @@ static int cap_invpcid;
 SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, invpcid, CTLFLAG_RD, _invpcid,
 0, "Guests are allowed to use INVPCID");
 
+static int tpr_shadowing;
+SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, tpr_shadowing, CTLFLAG_RD,
+_shadowing, 0, "TPR shadowing support");
+
 static int virtual_interrupt_delivery;
 SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, virtual_interrupt_delivery, CTLFLAG_RD,
 _interrupt_delivery, 0, "APICv virtual interrupt delivery 
support");
@@ -625,7 +629,7 @@ vmx_restore(void)
 static int
 vmx_init(int ipinum)
 {
-   int error, use_tpr_shadow;
+   int error;
uint64_t basic, fixed0, fixed1, feature_control;
uint32_t tmp, procbased2_vid_bits;
 
@@ -749,6 +753,24 @@ vmx_init(int ipinum)
) == 0);
 
/*
+* Check support for TPR shadow.
+*/
+   error = vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS,
+   MSR_VMX_TRUE_PROCBASED_CTLS, PROCBASED_USE_TPR_SHADOW, 0,
+   );
+   if (error == 0) {
+   tpr_shadowing = 1;
+   TUNABLE_INT_FETCH("hw.vmm.vmx.use_tpr_shadowing",
+   _shadowing);
+   }
+
+   if (tpr_shadowing) {
+   procbased_ctls |= PROCBASED_USE_TPR_SHADOW;
+   procbased_ctls &= ~PROCBASED_CR8_LOAD_EXITING;
+   procbased_ctls &= ~PROCBASED_CR8_STORE_EXITING;
+   }
+
+   /*
 * Check support for virtual interrupt delivery.
 */
procbased2_vid_bits = (PROCBASED2_VIRTUALIZE_APIC_ACCESSES |
@@ -756,13 +778,9 @@ vmx_init(int ipinum)
PROCBASED2_APIC_REGISTER_VIRTUALIZATION |
PROCBASED2_VIRTUAL_INTERRUPT_DELIVERY);
 
-   use_tpr_shadow = (vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS,
-   MSR_VMX_TRUE_PROCBASED_CTLS, PROCBASED_USE_TPR_SHADOW, 0,
-   ) == 0);
-
error = vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS2, MSR_VMX_PROCBASED_CTLS2,
procbased2_vid_bits, 0, );
-   if (error == 0 && use_tpr_shadow) {
+   if (error == 0 && tpr_shadowing) {
virtual_interrupt_delivery = 1;
TUNABLE_INT_FETCH("hw.vmm.vmx.use_apic_vid",
_interrupt_delivery);
@@ -774,13 +792,6 @@ 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.
 */
@@ -1049,10 +1060,13 @@ vmx_vminit(struct vm *vm, pmap_t pmap)
vmx->ctx[i].guest_dr6 = DBREG_DR6_RESERVED1;
error += vmwrite(VMCS_GUEST_DR7, DBREG_DR7_RESERVED1);
 
-   if (virtual_interrupt_delivery) {
-   error += vmwrite(VMCS_APIC_ACCESS, APIC_ACCESS_ADDRESS);
+   if (tpr_shadowing) {
error += vmwrite(VMCS_VIRTUAL_APIC,
vtophys(>apic_page[i]));
+   }
+
+   if (virtual_interrupt_delivery) {
+   error += vmwrite(VMCS_APIC_ACCESS, APIC_ACCESS_ADDRESS);
   

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

2020-04-19 Thread Peter Grehan

Unless there is an ABI problem, I think we should probably go
ahead and bump VM_MAX_MEMMAPS


 That's a reasonable fix - double it (or more) until it's made dynamic.
The VGA code is another (future) client of this, and it would allow 
other things like multiple frame buffers.


later,

Peter.
___
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: r334913 - head

2018-06-09 Thread Peter Grehan
Author: grehan
Date: Sun Jun 10 04:25:19 2018
New Revision: 334913
URL: https://svnweb.freebsd.org/changeset/base/334913

Log:
  Pass on   bhyve kernel module maintenance to
  tychon and jhb who've both had a long history
  with the codebase.
  
  Discussed with:tychon, jhb

Modified:
  head/MAINTAINERS

Modified: head/MAINTAINERS
==
--- head/MAINTAINERSSun Jun 10 02:36:38 2018(r334912)
+++ head/MAINTAINERSSun Jun 10 04:25:19 2018(r334913)
@@ -104,7 +104,7 @@ usr.sbin/bsdconfig  dteske  Pre-commit phabricator revie
 usr.sbin/dpv   dteske  Pre-commit review requested. Keep in sync with libdpv.
 usr.sbin/pkg   pkg@Please coordinate behavior or flag changes with pkg 
team.
 usr.sbin/sysrc dteske  Pre-commit phabricator review requested. Keep in sync 
with bsdconfig(8) sysrc.subr.
-vmm(4) grehan  Pre-commit review requested.
+vmm(4) tychon, jhb Pre-commit review requested.
 autofs(5)  trasz   Pre-commit review recommended.
 iscsi(4)   trasz   Pre-commit review recommended.
 rctl(8)trasz   Pre-commit review recommended.
___
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: r334407 - head/sys/dev/pci

2018-05-30 Thread Peter Grehan

Log:
   Only conform to PCIe spec of 1 device per bus on !x86
   
   bhyve's root PCI complex shows up as PCIe, but behaves as traditional PCI.

   Until that is special cased in a root complex driver, leave x86 as it was.


 Thanks Justin !

later,

Peter.
___
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: r334365 - head/sys/dev/pci

2018-05-30 Thread Peter Grehan

If bhyve has its own  attachment id, it is trivial
to add a special case on it quickly, too.


  vendor_id -- 0x1275


 Actually, this can also be AMD. A better check would be if the system 
is running virtualized.


later,

Peter.
___
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: r334365 - head/sys/dev/pci

2018-05-30 Thread Peter Grehan

Hi Justin,


I can add one either tonight or tomorrow.


 Thanks.


If bhyve has its own  attachment id, it is trivial
to add a special case on it quickly, too.


 vendor_id -- 0x1275

later,

Peter.
___
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: r334365 - head/sys/dev/pci

2018-05-30 Thread Peter Grehan

Hi Nathan,

There are a ton of ARM boards that need this too. You can find one-off 
hacks all through the tree and one of the nice things about this change 
is that all of those can be consolidated/removed now. If we are going to 
have some #ifdef and special cases, it would be better to make them for 
bhyve.


 Sure, but there are multiple orders of magnitude more users of bhyve 
than power9/affected ARM boards, so can a amd64/i386 ifdef be put there 
until that work is done ?


later,

Peter.
___
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: r334365 - head/sys/dev/pci

2018-05-30 Thread Peter Grehan

   PCIe only permits 1 device on an endpoint, so some devices ignore the device
   part of B:D:F probing.  Although ARI likely fixes this, not all platforms
   support ARI completely or correctly, so some devices end up showing up 32
   times on the bus.


 I think this might have broken bhyve - a fake PCIe capability is put 
on the root port so that guests will use MSI/MSI-x, but otherwise it 
looks like parallel PCI. Not exactly spec-compliant, but then neither is 
most of the world of PCI/PCIe.


 It may be worth #ifdef'ing this with powerpc.

later,

Peter.
___
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: r333235 - head/usr.sbin/bhyve

2018-05-03 Thread Peter Grehan
Author: grehan
Date: Fri May  4 01:36:49 2018
New Revision: 333235
URL: https://svnweb.freebsd.org/changeset/base/333235

Log:
  Allow arbitrary numbers of columns for VNC server screen resolution.
  
  The prior code only allowed multiples of 32 for the
  numbers of columns. Remove this restriction to allow
  a forthcoming UEFI firmware update to allow arbitrary
  x,y resolutions.
  
  (the code for handling rows already supported non mult-32 values)
  
  Reviewed by:  Leon Dang (original author)
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D15274

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

Modified: head/usr.sbin/bhyve/rfb.c
==
--- head/usr.sbin/bhyve/rfb.c   Fri May  4 00:56:41 2018(r333234)
+++ head/usr.sbin/bhyve/rfb.c   Fri May  4 01:36:49 2018(r333235)
@@ -541,40 +541,23 @@ rfb_send_screen(struct rfb_softc *rc, int cfd, int all
}
 
for (x = 0; x < xcells; x++) {
+   if (x == (xcells - 1) && rem_x > 0)
+   cellwidth = rem_x;
+   else
+   cellwidth = PIX_PER_CELL;
+
if (rc->hw_crc)
crc_p[x] = fast_crc32(p,
-PIX_PER_CELL * sizeof(uint32_t),
+cellwidth * sizeof(uint32_t),
 crc_p[x]);
else
crc_p[x] = (uint32_t)crc32(crc_p[x],
 (Bytef *)p,
-PIX_PER_CELL * sizeof(uint32_t));
+cellwidth * sizeof(uint32_t));
 
-   p += PIX_PER_CELL;
+   p += cellwidth;
 
/* check for crc delta if last row in cell */
-   if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
-   if (orig_crc[x] != crc_p[x]) {
-   orig_crc[x] = crc_p[x];
-   crc_p[x] = 1;
-   changes++;
-   } else {
-   crc_p[x] = 0;
-   }
-   }
-   }
-
-   if (rem_x) {
-   if (rc->hw_crc)
-   crc_p[x] = fast_crc32(p,
-   rem_x * sizeof(uint32_t),
-   crc_p[x]);
-   else
-   crc_p[x] = (uint32_t)crc32(crc_p[x],
-   (Bytef *)p,
-   rem_x * sizeof(uint32_t));
-   p += rem_x;
-
if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
if (orig_crc[x] != crc_p[x]) {
orig_crc[x] = crc_p[x];
___
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: r333230 - head/sys/dev/pci

2018-05-03 Thread Peter Grehan
Author: grehan
Date: Thu May  3 22:51:44 2018
New Revision: 333230
URL: https://svnweb.freebsd.org/changeset/base/333230

Log:
  Allow PCI VGA devices to be detached.
  
  GPUs often have a VGA PCI class code and are probed/attached
  by the VGA driver. Allow them to be detached so they can
  be presented as passthru devices to VM guests.
  
  Submitted by: mmacy
  Reviewed by:  jhb, imp, rgrimes
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D15269

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

Modified: head/sys/dev/pci/vga_pci.c
==
--- head/sys/dev/pci/vga_pci.c  Thu May  3 21:45:59 2018(r333229)
+++ head/sys/dev/pci/vga_pci.c  Thu May  3 22:51:44 2018(r333230)
@@ -283,6 +283,17 @@ vga_pci_suspend(device_t dev)
 }
 
 static int
+vga_pci_detach(device_t dev)
+{
+   int error; 
+
+   error = bus_generic_detach(dev);
+   if (error == 0)
+   error = device_delete_children(dev);
+   return (error);
+}
+
+static int
 vga_pci_resume(device_t dev)
 {
 
@@ -620,6 +631,7 @@ static device_method_t vga_pci_methods[] = {
DEVMETHOD(device_attach,vga_pci_attach),
DEVMETHOD(device_shutdown,  bus_generic_shutdown),
DEVMETHOD(device_suspend,   vga_pci_suspend),
+   DEVMETHOD(device_detach,vga_pci_detach),
DEVMETHOD(device_resume,vga_pci_resume),
 
/* Bus interface */
___
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: r333174 - head/sys/amd64/vmm/io

2018-05-02 Thread Peter Grehan

That places the MFC right before the optional 11.2 Beta3, I would rather
see this "low risk" change merged before May 11th, the code freeze
date and Beta1, if it is desired in 11.2, for maximal test exposure.


 Sure, that can be done.

later,

Peter.
___
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: r333174 - head/sys/amd64/vmm/io

2018-05-02 Thread Peter Grehan
Author: grehan
Date: Wed May  2 17:41:00 2018
New Revision: 333174
URL: https://svnweb.freebsd.org/changeset/base/333174

Log:
  Use PCI power-mgmt to reset a device if FLR fails.
  
  A large number of devices don't support PCIe FLR, in particular
  graphics adapters. Use PCI power management to perform the
  reset if FLR fails or isn't available, by cycling the device
  through the D3 state.
  
  This has been tested by a number of users with Nvidia and AMD GPUs.
  
  Submitted and tested by: Matt Macy
  Reviewed by:  jhb, imp, rgrimes
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D15268

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

Modified: head/sys/amd64/vmm/io/ppt.c
==
--- head/sys/amd64/vmm/io/ppt.c Wed May  2 15:59:15 2018(r333173)
+++ head/sys/amd64/vmm/io/ppt.c Wed May  2 17:41:00 2018(r333174)
@@ -353,6 +353,30 @@ ppt_is_mmio(struct vm *vm, vm_paddr_t gpa)
return (FALSE);
 }
 
+static void
+ppt_pci_reset(device_t dev)
+{
+   int ps;
+
+   if (pcie_flr(dev,
+max(pcie_get_max_completion_timeout(dev) / 1000, 10),
+true))
+   return;
+
+   /*
+* If FLR fails, attempt a power-management reset by cycling
+* the device in/out of D3 state.
+* PCI spec says we can only go into D3 state from D0 state.
+* Transition from D[12] into D0 before going to D3 state.
+*/
+   ps = pci_get_powerstate(dev);
+   if (ps != PCI_POWERSTATE_D0 && ps != PCI_POWERSTATE_D3)
+   pci_set_powerstate(dev, PCI_POWERSTATE_D0);
+   if (pci_get_powerstate(dev) != PCI_POWERSTATE_D3)
+   pci_set_powerstate(dev, PCI_POWERSTATE_D3);
+   pci_set_powerstate(dev, ps);
+}
+
 int
 ppt_assign_device(struct vm *vm, int bus, int slot, int func)
 {
@@ -368,9 +392,7 @@ ppt_assign_device(struct vm *vm, int bus, int slot, in
return (EBUSY);
 
pci_save_state(ppt->dev);
-   pcie_flr(ppt->dev,
-   max(pcie_get_max_completion_timeout(ppt->dev) / 1000, 10),
-   true);
+   ppt_pci_reset(ppt->dev);
pci_restore_state(ppt->dev);
ppt->vm = vm;
iommu_add_device(vm_iommu_domain(vm), pci_get_rid(ppt->dev));
@@ -393,9 +415,7 @@ ppt_unassign_device(struct vm *vm, int bus, int slot, 
return (EBUSY);
 
pci_save_state(ppt->dev);
-   pcie_flr(ppt->dev,
-   max(pcie_get_max_completion_timeout(ppt->dev) / 1000, 10),
-   true);
+   ppt_pci_reset(ppt->dev);
pci_restore_state(ppt->dev);
ppt_unmap_mmio(vm, ppt);
ppt_teardown_msi(ppt);
___
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: r332517 - stable/11/usr.sbin/bhyvectl

2018-04-15 Thread Peter Grehan
Author: grehan
Date: Sun Apr 15 20:29:37 2018
New Revision: 332517
URL: https://svnweb.freebsd.org/changeset/base/332517

Log:
  MFC r330764
Add CR2 get/set support.

Modified:
  stable/11/usr.sbin/bhyvectl/bhyvectl.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyvectl/bhyvectl.c
==
--- stable/11/usr.sbin/bhyvectl/bhyvectl.c  Sun Apr 15 20:20:08 2018
(r332516)
+++ stable/11/usr.sbin/bhyvectl/bhyvectl.c  Sun Apr 15 20:29:37 2018
(r332517)
@@ -109,6 +109,8 @@ usage(bool cpu_intel)
"   [--desc-access=]\n"
"   [--set-cr0=]\n"
"   [--get-cr0]\n"
+   "   [--set-cr2=]\n"
+   "   [--get-cr2]\n"
"   [--set-cr3=]\n"
"   [--get-cr3]\n"
"   [--set-cr4=]\n"
@@ -254,7 +256,8 @@ static int create, destroy, get_memmap, get_memseg;
 static int get_intinfo;
 static int get_active_cpus, get_suspended_cpus;
 static uint64_t memsize;
-static int set_cr0, get_cr0, set_cr3, get_cr3, set_cr4, get_cr4;
+static int set_cr0, get_cr0, set_cr2, get_cr2, set_cr3, get_cr3;
+static int set_cr4, get_cr4;
 static int set_efer, get_efer;
 static int set_dr0, get_dr0;
 static int set_dr1, get_dr1;
@@ -551,6 +554,7 @@ enum {
SET_MEM,
SET_EFER,
SET_CR0,
+   SET_CR2,
SET_CR3,
SET_CR4,
SET_DR0,
@@ -662,7 +666,7 @@ cpu_vendor_intel(void)
 static int
 get_all_registers(struct vmctx *ctx, int vcpu)
 {
-   uint64_t cr0, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
+   uint64_t cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
uint64_t rsp, rip, rflags, efer;
uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp;
uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
@@ -680,6 +684,12 @@ get_all_registers(struct vmctx *ctx, int vcpu)
printf("cr0[%d]\t\t0x%016lx\n", vcpu, cr0);
}
 
+   if (!error && (get_cr2 || get_all)) {
+   error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR2, );
+   if (error == 0)
+   printf("cr2[%d]\t\t0x%016lx\n", vcpu, cr2);
+   }
+
if (!error && (get_cr3 || get_all)) {
error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR3, );
if (error == 0)
@@ -1322,6 +1332,7 @@ setup_options(bool cpu_intel)
{ "set-mem",REQ_ARG,0,  SET_MEM },
{ "set-efer",   REQ_ARG,0,  SET_EFER },
{ "set-cr0",REQ_ARG,0,  SET_CR0 },
+   { "set-cr2",REQ_ARG,0,  SET_CR2 },
{ "set-cr3",REQ_ARG,0,  SET_CR3 },
{ "set-cr4",REQ_ARG,0,  SET_CR4 },
{ "set-dr0",REQ_ARG,0,  SET_DR0 },
@@ -1384,6 +1395,7 @@ setup_options(bool cpu_intel)
{ "get-memseg", NO_ARG, _memseg,1 },
{ "get-efer",   NO_ARG, _efer,  1 },
{ "get-cr0",NO_ARG, _cr0,   1 },
+   { "get-cr2",NO_ARG, _cr2,   1 },
{ "get-cr3",NO_ARG, _cr3,   1 },
{ "get-cr4",NO_ARG, _cr4,   1 },
{ "get-dr0",NO_ARG, _dr0,   1 },
@@ -1668,7 +1680,7 @@ main(int argc, char *argv[])
int error, ch, vcpu, ptenum;
vm_paddr_t gpa_pmap;
struct vm_exit vmexit;
-   uint64_t rax, cr0, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
+   uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
uint64_t rsp, rip, rflags, efer, pat;
uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2];
struct vmctx *ctx;
@@ -1708,6 +1720,10 @@ main(int argc, char *argv[])
cr0 = strtoul(optarg, NULL, 0);
set_cr0 = 1;
break;
+   case SET_CR2:
+   cr2 = strtoul(optarg, NULL, 0);
+   set_cr2 = 1;
+   break;
case SET_CR3:
cr3 = strtoul(optarg, NULL, 0);
set_cr3 = 1;
@@ -1870,6 +1886,9 @@ main(int argc, char *argv[])
 
if (!error && set_cr0)
error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR0, cr0);
+
+   if (!error && set_cr2)
+   error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR2, cr2);
 
if (!error && set_cr3)
error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR3, cr3);
___
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: r332516 - stable/11/sys/amd64/vmm

2018-04-15 Thread Peter Grehan
Author: grehan
Date: Sun Apr 15 20:20:08 2018
New Revision: 332516
URL: https://svnweb.freebsd.org/changeset/base/332516

Log:
  MFC r325261
Emulate the "OR reg, r/m" instruction (opcode 0BH).
  
This is needed for the HDA emulation with FreeBSD guests.

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

Modified: stable/11/sys/amd64/vmm/vmm_instruction_emul.c
==
--- stable/11/sys/amd64/vmm/vmm_instruction_emul.c  Sun Apr 15 19:23:37 
2018(r332515)
+++ stable/11/sys/amd64/vmm/vmm_instruction_emul.c  Sun Apr 15 20:20:08 
2018(r332516)
@@ -109,6 +109,10 @@ static const struct vie_op one_byte_opcodes[256] = {
.op_byte = 0x0F,
.op_type = VIE_OP_TYPE_TWO_BYTE
},
+   [0x0B] = {
+   .op_byte = 0x0B,
+   .op_type = VIE_OP_TYPE_OR,
+   },
[0x2B] = {
.op_byte = 0x2B,
.op_type = VIE_OP_TYPE_SUB,
@@ -992,12 +996,38 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct 
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
 {
int error, size;
-   uint64_t val1, result, rflags, rflags2;
+   enum vm_reg_name reg;
+   uint64_t result, rflags, rflags2, val1, val2;
 
size = vie->opsize;
error = EINVAL;
 
switch (vie->op.op_byte) {
+   case 0x0B:
+   /*
+* OR reg (ModRM:reg) and mem (ModRM:r/m) and store the
+* result in reg.
+*
+* 0b/r or r16, r/m16
+* 0b/r or r32, r/m32
+* REX.W + 0b/r or r64, r/m64
+*/
+
+   /* get the first operand */
+   reg = gpr_map[vie->reg];
+   error = vie_read_register(vm, vcpuid, reg, );
+   if (error)
+   break;
+   
+   /* get the second operand */
+   error = memread(vm, vcpuid, gpa, , size, arg);
+   if (error)
+   break;
+
+   /* perform the operation and write the result */
+   result = val1 | val2;
+   error = vie_update_register(vm, vcpuid, reg, result, size);
+   break;
case 0x81:
case 0x83:
/*
___
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: r330764 - head/usr.sbin/bhyvectl

2018-03-11 Thread Peter Grehan
Author: grehan
Date: Sun Mar 11 08:27:11 2018
New Revision: 330764
URL: https://svnweb.freebsd.org/changeset/base/330764

Log:
  Add CR2 get/set support.
  
  Reported/Tested by:  Fabian Freyer
  Reviewed by:  araujo
  Differential Revision:https://reviews.freebsd.org/D14648
  MFC after:3 weeks

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

Modified: head/usr.sbin/bhyvectl/bhyvectl.c
==
--- head/usr.sbin/bhyvectl/bhyvectl.c   Sun Mar 11 08:07:40 2018
(r330763)
+++ head/usr.sbin/bhyvectl/bhyvectl.c   Sun Mar 11 08:27:11 2018
(r330764)
@@ -109,6 +109,8 @@ usage(bool cpu_intel)
"   [--desc-access=]\n"
"   [--set-cr0=]\n"
"   [--get-cr0]\n"
+   "   [--set-cr2=]\n"
+   "   [--get-cr2]\n"
"   [--set-cr3=]\n"
"   [--get-cr3]\n"
"   [--set-cr4=]\n"
@@ -254,7 +256,8 @@ static int create, destroy, get_memmap, get_memseg;
 static int get_intinfo;
 static int get_active_cpus, get_suspended_cpus;
 static uint64_t memsize;
-static int set_cr0, get_cr0, set_cr3, get_cr3, set_cr4, get_cr4;
+static int set_cr0, get_cr0, set_cr2, get_cr2, set_cr3, get_cr3;
+static int set_cr4, get_cr4;
 static int set_efer, get_efer;
 static int set_dr0, get_dr0;
 static int set_dr1, get_dr1;
@@ -551,6 +554,7 @@ enum {
SET_MEM,
SET_EFER,
SET_CR0,
+   SET_CR2,
SET_CR3,
SET_CR4,
SET_DR0,
@@ -662,7 +666,7 @@ cpu_vendor_intel(void)
 static int
 get_all_registers(struct vmctx *ctx, int vcpu)
 {
-   uint64_t cr0, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
+   uint64_t cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
uint64_t rsp, rip, rflags, efer;
uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp;
uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
@@ -680,6 +684,12 @@ get_all_registers(struct vmctx *ctx, int vcpu)
printf("cr0[%d]\t\t0x%016lx\n", vcpu, cr0);
}
 
+   if (!error && (get_cr2 || get_all)) {
+   error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR2, );
+   if (error == 0)
+   printf("cr2[%d]\t\t0x%016lx\n", vcpu, cr2);
+   }
+
if (!error && (get_cr3 || get_all)) {
error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR3, );
if (error == 0)
@@ -1322,6 +1332,7 @@ setup_options(bool cpu_intel)
{ "set-mem",REQ_ARG,0,  SET_MEM },
{ "set-efer",   REQ_ARG,0,  SET_EFER },
{ "set-cr0",REQ_ARG,0,  SET_CR0 },
+   { "set-cr2",REQ_ARG,0,  SET_CR2 },
{ "set-cr3",REQ_ARG,0,  SET_CR3 },
{ "set-cr4",REQ_ARG,0,  SET_CR4 },
{ "set-dr0",REQ_ARG,0,  SET_DR0 },
@@ -1384,6 +1395,7 @@ setup_options(bool cpu_intel)
{ "get-memseg", NO_ARG, _memseg,1 },
{ "get-efer",   NO_ARG, _efer,  1 },
{ "get-cr0",NO_ARG, _cr0,   1 },
+   { "get-cr2",NO_ARG, _cr2,   1 },
{ "get-cr3",NO_ARG, _cr3,   1 },
{ "get-cr4",NO_ARG, _cr4,   1 },
{ "get-dr0",NO_ARG, _dr0,   1 },
@@ -1668,7 +1680,7 @@ main(int argc, char *argv[])
int error, ch, vcpu, ptenum;
vm_paddr_t gpa_pmap;
struct vm_exit vmexit;
-   uint64_t rax, cr0, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
+   uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
uint64_t rsp, rip, rflags, efer, pat;
uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2];
struct vmctx *ctx;
@@ -1708,6 +1720,10 @@ main(int argc, char *argv[])
cr0 = strtoul(optarg, NULL, 0);
set_cr0 = 1;
break;
+   case SET_CR2:
+   cr2 = strtoul(optarg, NULL, 0);
+   set_cr2 = 1;
+   break;
case SET_CR3:
cr3 = strtoul(optarg, NULL, 0);
set_cr3 = 1;
@@ -1870,6 +1886,9 @@ main(int argc, char *argv[])
 
if (!error && set_cr0)
error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR0, cr0);
+
+   if (!error && set_cr2)
+   error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR2, cr2);
 
if (!error && set_cr3)
error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR3, cr3);
___
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: r327990 - head/share/man/man4

2018-01-14 Thread Peter Grehan
Author: grehan
Date: Mon Jan 15 04:52:12 2018
New Revision: 327990
URL: https://svnweb.freebsd.org/changeset/base/327990

Log:
  The vmm(4) man page is conditional on MK_BHYVE.
  
  Submitted by: kevlo

Modified:
  head/share/man/man4/Makefile

Modified: head/share/man/man4/Makefile
==
--- head/share/man/man4/MakefileMon Jan 15 01:19:11 2018
(r327989)
+++ head/share/man/man4/MakefileMon Jan 15 04:52:12 2018
(r327990)
@@ -555,8 +555,8 @@ MAN=aac.4 \
${_virtio_scsi.4} \
vkbd.4 \
vlan.4 \
-   vmm.4 \
vxlan.4 \
+   ${_vmm.4} \
${_vmx.4} \
vpo.4 \
vr.4 \
@@ -875,6 +875,7 @@ MLINKS+=sfxge.4 if_sfxge.4
 
 .if ${MK_BHYVE} != "no"
 _bhyve.4=  bhyve.4
+_vmm.4=vmm.4
 .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"


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

2017-10-31 Thread Peter Grehan
Author: grehan
Date: Wed Nov  1 03:26:53 2017
New Revision: 325261
URL: https://svnweb.freebsd.org/changeset/base/325261

Log:
  Emulate the "OR reg, r/m" instruction (opcode 0BH).
  
  This is   needed for the HDA emulation with FreeBSD guests.
  
  Reviewed by:  marcelo
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D12832

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 Nov  1 03:09:16 2017
(r325260)
+++ head/sys/amd64/vmm/vmm_instruction_emul.c   Wed Nov  1 03:26:53 2017
(r325261)
@@ -109,6 +109,10 @@ static const struct vie_op one_byte_opcodes[256] = {
.op_byte = 0x0F,
.op_type = VIE_OP_TYPE_TWO_BYTE
},
+   [0x0B] = {
+   .op_byte = 0x0B,
+   .op_type = VIE_OP_TYPE_OR,
+   },
[0x2B] = {
.op_byte = 0x2B,
.op_type = VIE_OP_TYPE_SUB,
@@ -992,12 +996,38 @@ emulate_or(void *vm, int vcpuid, uint64_t gpa, struct 
mem_region_read_t memread, mem_region_write_t memwrite, void *arg)
 {
int error, size;
-   uint64_t val1, result, rflags, rflags2;
+   enum vm_reg_name reg;
+   uint64_t result, rflags, rflags2, val1, val2;
 
size = vie->opsize;
error = EINVAL;
 
switch (vie->op.op_byte) {
+   case 0x0B:
+   /*
+* OR reg (ModRM:reg) and mem (ModRM:r/m) and store the
+* result in reg.
+*
+* 0b/r or r16, r/m16
+* 0b/r or r32, r/m32
+* REX.W + 0b/r or r64, r/m64
+*/
+
+   /* get the first operand */
+   reg = gpr_map[vie->reg];
+   error = vie_read_register(vm, vcpuid, reg, );
+   if (error)
+   break;
+   
+   /* get the second operand */
+   error = memread(vm, vcpuid, gpa, , size, arg);
+   if (error)
+   break;
+
+   /* perform the operation and write the result */
+   result = val1 | val2;
+   error = vie_update_register(vm, vcpuid, reg, result, size);
+   break;
case 0x81:
case 0x83:
/*
___
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: r325108 - head/sys/amd64/vmm/io

2017-10-29 Thread Peter Grehan

Hi Ian,


In fact I did check maintainers, and I just now checked it again, and
seeing nothing on-point, wrote a really snarky reply.

Luckily, before hitting send I realized you wouldn't have said anything
unless there was an entry in there, so I checked like 4 more times
before I noticed the line that begins vmm(4).  I had been looking for a
line that began with sys/amd64.

So... sorry about that.  Should I revert it and open a review?


 No, it's fine. It's a good idea in general for code in that area since 
there are often unintended side-effects with guest behaviour, and 
putting up a review can at least flush out folk who might have more 
insight into that.


 I'll update the maintainer's file to include the directory.


Longer-term, I was hoping to find some time over the next few weeks to
further explore the roundoff errors in the timers and attempt a better
fix, and I was definitely intending to put that up for review
(especially because it involves math, and I'm always better off asking
for help with that).


 I know Rod Grimes is going to be doing some testing this week with 
clock drift in guests, and I'll do some dtrace work on HPET usage with 
non-FreeBSD guests.


 Timer accuracy has long been an issue with bhyve so any help in this 
area is much appreciated.


later,

Peter.

___
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: r325108 - head/sys/amd64/vmm/io

2017-10-29 Thread Peter Grehan

   Improve the performance of the hpet timer in bhyve guests by making the
   timer frequency a power of two.  This changes the frequency from 10 to
   16.7 MHz (2 ^ 24 HZ).  Using a power of two avoids roundoff errors when
   doing arithmetic in sbintime_t units.
   
   Testing shows this can fix erratic ntpd behavior in guests using the

   hpet timer (which is the default for multicore guests).
   
   Reported by:	bsam@


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


 In the future please respect MAINTAINERS and file a phab review for 
code in this area.


later,

Peter.
___
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: r320935 - releng/11.1/usr.sbin/bhyve

2017-07-13 Thread Peter Grehan
Author: grehan
Date: Thu Jul 13 08:13:29 2017
New Revision: 320935
URL: https://svnweb.freebsd.org/changeset/base/320935

Log:
  MFS 320891
  MFC r317542, r317543, r317543
  
317542   comment fix
317543   set rfb default port
317543   listen on localhost by default for rfb
  
  Approved by:  re (kib)

Modified:
  releng/11.1/usr.sbin/bhyve/pci_fbuf.c
  releng/11.1/usr.sbin/bhyve/pci_xhci.c
  releng/11.1/usr.sbin/bhyve/rfb.c
Directory Properties:
  releng/11.1/   (props changed)

Modified: releng/11.1/usr.sbin/bhyve/pci_fbuf.c
==
--- releng/11.1/usr.sbin/bhyve/pci_fbuf.c   Thu Jul 13 07:55:00 2017
(r320934)
+++ releng/11.1/usr.sbin/bhyve/pci_fbuf.c   Thu Jul 13 08:13:29 2017
(r320935)
@@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
  * BAR0 points to the current mode information.
  * BAR1 is the 32-bit framebuffer address.
  *
- *  -s ,fbuf,wait,tcp=:port,w=width,h=height
+ *  -s ,fbuf,wait,vga=on|io|off,rfb=:port,w=width,h=height
  */
 
 static int fbuf_debug = 1;

Modified: releng/11.1/usr.sbin/bhyve/pci_xhci.c
==
--- releng/11.1/usr.sbin/bhyve/pci_xhci.c   Thu Jul 13 07:55:00 2017
(r320934)
+++ releng/11.1/usr.sbin/bhyve/pci_xhci.c   Thu Jul 13 08:13:29 2017
(r320935)
@@ -28,7 +28,7 @@
 -s ,xhci,{devices}
 
devices:
- ums USB tablet mouse
+ tablet USB tablet mouse
  */
 #include 
 __FBSDID("$FreeBSD$");

Modified: releng/11.1/usr.sbin/bhyve/rfb.c
==
--- releng/11.1/usr.sbin/bhyve/rfb.cThu Jul 13 07:55:00 2017
(r320934)
+++ releng/11.1/usr.sbin/bhyve/rfb.cThu Jul 13 08:13:29 2017
(r320935)
@@ -897,11 +897,11 @@ rfb_init(char *hostname, int port, int wait)
 
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
-   sin.sin_port = htons(port);
+   sin.sin_port = port ? htons(port) : htons(5900);
if (hostname && strlen(hostname) > 0)
inet_pton(AF_INET, hostname, &(sin.sin_addr));
else
-   sin.sin_addr.s_addr = htonl(INADDR_ANY);
+   sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 
if (bind(rc->sfd, (struct sockaddr *), sizeof(sin)) < 0) {
perror("bind");
___
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: r320934 - in releng/11.1: lib/libvmmapi usr.sbin/bhyve

2017-07-13 Thread Peter Grehan
Author: grehan
Date: Thu Jul 13 07:55:00 2017
New Revision: 320934
URL: https://svnweb.freebsd.org/changeset/base/320934

Log:
  MFS 320866
  MFC 313727, 317483
In addition, replace the missing caph routines with
  small helper functions (bhyverun.c) or an open-coded
  replacement (uart_emul.c)
  
  313727   Capsicumize bhyve
  317483   Allow CAP_MMAP_RW on memfd for PCI passthru
  
  Approved by:  re (kib)

Modified:
  releng/11.1/lib/libvmmapi/vmmapi.c
  releng/11.1/lib/libvmmapi/vmmapi.h
  releng/11.1/usr.sbin/bhyve/bhyverun.c
  releng/11.1/usr.sbin/bhyve/block_if.c
  releng/11.1/usr.sbin/bhyve/consport.c
  releng/11.1/usr.sbin/bhyve/dbgport.c
  releng/11.1/usr.sbin/bhyve/mevent.c
  releng/11.1/usr.sbin/bhyve/pci_e82545.c
  releng/11.1/usr.sbin/bhyve/pci_passthru.c
  releng/11.1/usr.sbin/bhyve/pci_virtio_net.c
  releng/11.1/usr.sbin/bhyve/pci_virtio_rnd.c
  releng/11.1/usr.sbin/bhyve/rfb.c
  releng/11.1/usr.sbin/bhyve/uart_emul.c
Directory Properties:
  releng/11.1/   (props changed)

Modified: releng/11.1/lib/libvmmapi/vmmapi.c
==
--- releng/11.1/lib/libvmmapi/vmmapi.c  Thu Jul 13 07:32:55 2017
(r320933)
+++ releng/11.1/lib/libvmmapi/vmmapi.c  Thu Jul 13 07:55:00 2017
(r320934)
@@ -1416,3 +1416,45 @@ vm_restart_instruction(void *arg, int vcpu)
 
return (ioctl(ctx->fd, VM_RESTART_INSTRUCTION, ));
 }
+
+int
+vm_get_device_fd(struct vmctx *ctx)
+{
+
+   return (ctx->fd);
+}
+
+const cap_ioctl_t *
+vm_get_ioctls(size_t *len)
+{
+   cap_ioctl_t *cmds;
+   /* keep in sync with machine/vmm_dev.h */
+   static const cap_ioctl_t vm_ioctl_cmds[] = { VM_RUN, VM_SUSPEND, 
VM_REINIT,
+   VM_ALLOC_MEMSEG, VM_GET_MEMSEG, VM_MMAP_MEMSEG, VM_MMAP_MEMSEG,
+   VM_MMAP_GETNEXT, VM_SET_REGISTER, VM_GET_REGISTER,
+   VM_SET_SEGMENT_DESCRIPTOR, VM_GET_SEGMENT_DESCRIPTOR,
+   VM_INJECT_EXCEPTION, VM_LAPIC_IRQ, VM_LAPIC_LOCAL_IRQ,
+   VM_LAPIC_MSI, VM_IOAPIC_ASSERT_IRQ, VM_IOAPIC_DEASSERT_IRQ,
+   VM_IOAPIC_PULSE_IRQ, VM_IOAPIC_PINCOUNT, VM_ISA_ASSERT_IRQ,
+   VM_ISA_DEASSERT_IRQ, VM_ISA_PULSE_IRQ, VM_ISA_SET_IRQ_TRIGGER,
+   VM_SET_CAPABILITY, VM_GET_CAPABILITY, VM_BIND_PPTDEV,
+   VM_UNBIND_PPTDEV, VM_MAP_PPTDEV_MMIO, VM_PPTDEV_MSI,
+   VM_PPTDEV_MSIX, VM_INJECT_NMI, VM_STATS, VM_STAT_DESC,
+   VM_SET_X2APIC_STATE, VM_GET_X2APIC_STATE,
+   VM_GET_HPET_CAPABILITIES, VM_GET_GPA_PMAP, VM_GLA2GPA,
+   VM_ACTIVATE_CPU, VM_GET_CPUS, VM_SET_INTINFO, VM_GET_INTINFO,
+   VM_RTC_WRITE, VM_RTC_READ, VM_RTC_SETTIME, VM_RTC_GETTIME,
+   VM_RESTART_INSTRUCTION };
+
+   if (len == NULL) {
+   cmds = malloc(sizeof(vm_ioctl_cmds));
+   if (cmds == NULL)
+   return (NULL);
+   bcopy(vm_ioctl_cmds, cmds, sizeof(vm_ioctl_cmds));
+   return (cmds);
+   }
+
+   *len = nitems(vm_ioctl_cmds);
+   return (NULL);
+}
+

Modified: releng/11.1/lib/libvmmapi/vmmapi.h
==
--- releng/11.1/lib/libvmmapi/vmmapi.h  Thu Jul 13 07:32:55 2017
(r320933)
+++ releng/11.1/lib/libvmmapi/vmmapi.h  Thu Jul 13 07:55:00 2017
(r320934)
@@ -36,7 +36,7 @@
  * API version for out-of-tree consumers like grub-bhyve for making compile
  * time decisions.
  */
-#defineVMMAPI_VERSION  0102/* 2 digit major followed by 2 digit 
minor */
+#defineVMMAPI_VERSION  0103/* 2 digit major followed by 2 digit 
minor */
 
 struct iovec;
 struct vmctx;
@@ -102,6 +102,7 @@ int vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, 
vm_ooffset_t segoff, size_t len, int prot);
 
 intvm_create(const char *name);
+intvm_get_device_fd(struct vmctx *ctx);
 struct vmctx *vm_open(const char *name);
 void   vm_destroy(struct vmctx *ctx);
 intvm_parse_memsize(const char *optarg, size_t *memsize);
@@ -161,6 +162,8 @@ int vm_setup_pptdev_msix(struct vmctx *ctx, int vcpu, 
 
 intvm_get_intinfo(struct vmctx *ctx, int vcpu, uint64_t *i1, uint64_t *i2);
 intvm_set_intinfo(struct vmctx *ctx, int vcpu, uint64_t exit_intinfo);
+
+const cap_ioctl_t *vm_get_ioctls(size_t *len);
 
 /*
  * Return a pointer to the statistics buffer. Note that this is not MT-safe.

Modified: releng/11.1/usr.sbin/bhyve/bhyverun.c
==
--- releng/11.1/usr.sbin/bhyve/bhyverun.c   Thu Jul 13 07:32:55 2017
(r320933)
+++ releng/11.1/usr.sbin/bhyve/bhyverun.c   Thu Jul 13 07:55:00 2017
(r320934)
@@ -30,6 +30,9 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#endif
 #include 
 #include 
 
@@ -40,6 +43,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,8 +52,15 @@ 

svn commit: r320933 - releng/11.1/usr.sbin/bhyve

2017-07-13 Thread Peter Grehan
Author: grehan
Date: Thu Jul 13 07:32:55 2017
New Revision: 320933
URL: https://svnweb.freebsd.org/changeset/base/320933

Log:
  MFS r320855
ps2 mouse fixes, found by plan9/9front.
  
  Approved by:re (kib)

Modified:
  releng/11.1/usr.sbin/bhyve/ps2mouse.c
Directory Properties:
  releng/11.1/   (props changed)

Modified: releng/11.1/usr.sbin/bhyve/ps2mouse.c
==
--- releng/11.1/usr.sbin/bhyve/ps2mouse.c   Thu Jul 13 04:46:00 2017
(r320932)
+++ releng/11.1/usr.sbin/bhyve/ps2mouse.c   Thu Jul 13 07:32:55 2017
(r320933)
@@ -62,6 +62,16 @@ __FBSDID("$FreeBSD$");
 /* mouse device id */
 #definePS2MOUSE_DEV_ID 0x0
 
+/* mouse data bits */
+#definePS2M_DATA_Y_OFLOW   0x80
+#definePS2M_DATA_X_OFLOW   0x40
+#definePS2M_DATA_Y_SIGN0x20
+#definePS2M_DATA_X_SIGN0x10
+#definePS2M_DATA_AONE  0x08
+#definePS2M_DATA_MID_BUTTON0x04
+#definePS2M_DATA_RIGHT_BUTTON  0x02
+#definePS2M_DATA_LEFT_BUTTON   0x01
+
 /* mouse status bits */
 #definePS2M_STS_REMOTE_MODE0x40
 #definePS2M_STS_ENABLE_DEV 0x20
@@ -169,19 +179,20 @@ movement_get(struct ps2mouse_softc *sc)
 
assert(pthread_mutex_isowned_np(>mtx));
 
-   val0 =  sc->status & (PS2M_STS_LEFT_BUTTON |
-   PS2M_STS_RIGHT_BUTTON | PS2M_STS_MID_BUTTON);
+   val0 = PS2M_DATA_AONE;
+   val0 |= sc->status & (PS2M_DATA_LEFT_BUTTON |
+   PS2M_DATA_RIGHT_BUTTON | PS2M_DATA_MID_BUTTON);
 
if (sc->delta_x >= 0) {
if (sc->delta_x > 255) {
-   val0 |= (1 << 6);
+   val0 |= PS2M_DATA_X_OFLOW;
val1 = 255;
} else
val1 = sc->delta_x;
} else {
-   val0 |= (1 << 4);
+   val0 |= PS2M_DATA_X_SIGN;
if (sc->delta_x < -255) {
-   val0 |= (1 << 6);
+   val0 |= PS2M_DATA_X_OFLOW;
val1 = 255;
} else
val1 = sc->delta_x;
@@ -190,14 +201,14 @@ movement_get(struct ps2mouse_softc *sc)
 
if (sc->delta_y >= 0) {
if (sc->delta_y > 255) {
-   val0 |= (1 << 7);
+   val0 |= PS2M_DATA_Y_OFLOW;
val2 = 255;
} else
val2 = sc->delta_y;
} else {
-   val0 |= (1 << 5);
+   val0 |= PS2M_DATA_Y_SIGN;
if (sc->delta_y < -255) {
-   val0 |= (1 << 7);
+   val0 |= PS2M_DATA_Y_OFLOW;
val2 = 255;
} else
val2 = sc->delta_y;
___
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: r320891 - stable/11/usr.sbin/bhyve

2017-07-11 Thread Peter Grehan
Author: grehan
Date: Tue Jul 11 06:39:12 2017
New Revision: 320891
URL: https://svnweb.freebsd.org/changeset/base/320891

Log:
  MFC r317542, r317543, r317543
  
317542   comment fix
317543   set rfb default port
317543   listen on localhost by default for rfb

Modified:
  stable/11/usr.sbin/bhyve/pci_fbuf.c
  stable/11/usr.sbin/bhyve/pci_xhci.c
  stable/11/usr.sbin/bhyve/rfb.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/pci_fbuf.c
==
--- stable/11/usr.sbin/bhyve/pci_fbuf.c Tue Jul 11 05:49:42 2017
(r320890)
+++ stable/11/usr.sbin/bhyve/pci_fbuf.c Tue Jul 11 06:39:12 2017
(r320891)
@@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
  * BAR0 points to the current mode information.
  * BAR1 is the 32-bit framebuffer address.
  *
- *  -s ,fbuf,wait,tcp=:port,w=width,h=height
+ *  -s ,fbuf,wait,vga=on|io|off,rfb=:port,w=width,h=height
  */
 
 static int fbuf_debug = 1;

Modified: stable/11/usr.sbin/bhyve/pci_xhci.c
==
--- stable/11/usr.sbin/bhyve/pci_xhci.c Tue Jul 11 05:49:42 2017
(r320890)
+++ stable/11/usr.sbin/bhyve/pci_xhci.c Tue Jul 11 06:39:12 2017
(r320891)
@@ -28,7 +28,7 @@
 -s ,xhci,{devices}
 
devices:
- ums USB tablet mouse
+ tablet USB tablet mouse
  */
 #include 
 __FBSDID("$FreeBSD$");

Modified: stable/11/usr.sbin/bhyve/rfb.c
==
--- stable/11/usr.sbin/bhyve/rfb.c  Tue Jul 11 05:49:42 2017
(r320890)
+++ stable/11/usr.sbin/bhyve/rfb.c  Tue Jul 11 06:39:12 2017
(r320891)
@@ -1003,11 +1003,11 @@ rfb_init(char *hostname, int port, int wait, char *pas
 
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
-   sin.sin_port = htons(port);
+   sin.sin_port = port ? htons(port) : htons(5900);
if (hostname && strlen(hostname) > 0)
inet_pton(AF_INET, hostname, &(sin.sin_addr));
else
-   sin.sin_addr.s_addr = htonl(INADDR_ANY);
+   sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 
if (bind(rc->sfd, (struct sockaddr *), sizeof(sin)) < 0) {
perror("bind");
___
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: r320866 - in stable/11: lib/libvmmapi usr.sbin/bhyve

2017-07-10 Thread Peter Grehan
Author: grehan
Date: Mon Jul 10 06:28:50 2017
New Revision: 320866
URL: https://svnweb.freebsd.org/changeset/base/320866

Log:
  MFC 313727, 317483
In addition, replace the missing caph   routines with
  small helper functions (bhyverun.c) or an open-coded
  replacement (uart_emul.c)
  
313727   Capsicumizebhyve
317483   Allow CAP_MMAP_RW on   memfd for PCI passthru

Modified:
  stable/11/lib/libvmmapi/vmmapi.c
  stable/11/lib/libvmmapi/vmmapi.h
  stable/11/usr.sbin/bhyve/bhyverun.c
  stable/11/usr.sbin/bhyve/block_if.c
  stable/11/usr.sbin/bhyve/consport.c
  stable/11/usr.sbin/bhyve/dbgport.c
  stable/11/usr.sbin/bhyve/mevent.c
  stable/11/usr.sbin/bhyve/pci_e82545.c
  stable/11/usr.sbin/bhyve/pci_passthru.c
  stable/11/usr.sbin/bhyve/pci_virtio_net.c
  stable/11/usr.sbin/bhyve/pci_virtio_rnd.c
  stable/11/usr.sbin/bhyve/rfb.c
  stable/11/usr.sbin/bhyve/uart_emul.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libvmmapi/vmmapi.c
==
--- stable/11/lib/libvmmapi/vmmapi.cMon Jul 10 06:25:30 2017
(r320865)
+++ stable/11/lib/libvmmapi/vmmapi.cMon Jul 10 06:28:50 2017
(r320866)
@@ -1416,3 +1416,45 @@ vm_restart_instruction(void *arg, int vcpu)
 
return (ioctl(ctx->fd, VM_RESTART_INSTRUCTION, ));
 }
+
+int
+vm_get_device_fd(struct vmctx *ctx)
+{
+
+   return (ctx->fd);
+}
+
+const cap_ioctl_t *
+vm_get_ioctls(size_t *len)
+{
+   cap_ioctl_t *cmds;
+   /* keep in sync with machine/vmm_dev.h */
+   static const cap_ioctl_t vm_ioctl_cmds[] = { VM_RUN, VM_SUSPEND, 
VM_REINIT,
+   VM_ALLOC_MEMSEG, VM_GET_MEMSEG, VM_MMAP_MEMSEG, VM_MMAP_MEMSEG,
+   VM_MMAP_GETNEXT, VM_SET_REGISTER, VM_GET_REGISTER,
+   VM_SET_SEGMENT_DESCRIPTOR, VM_GET_SEGMENT_DESCRIPTOR,
+   VM_INJECT_EXCEPTION, VM_LAPIC_IRQ, VM_LAPIC_LOCAL_IRQ,
+   VM_LAPIC_MSI, VM_IOAPIC_ASSERT_IRQ, VM_IOAPIC_DEASSERT_IRQ,
+   VM_IOAPIC_PULSE_IRQ, VM_IOAPIC_PINCOUNT, VM_ISA_ASSERT_IRQ,
+   VM_ISA_DEASSERT_IRQ, VM_ISA_PULSE_IRQ, VM_ISA_SET_IRQ_TRIGGER,
+   VM_SET_CAPABILITY, VM_GET_CAPABILITY, VM_BIND_PPTDEV,
+   VM_UNBIND_PPTDEV, VM_MAP_PPTDEV_MMIO, VM_PPTDEV_MSI,
+   VM_PPTDEV_MSIX, VM_INJECT_NMI, VM_STATS, VM_STAT_DESC,
+   VM_SET_X2APIC_STATE, VM_GET_X2APIC_STATE,
+   VM_GET_HPET_CAPABILITIES, VM_GET_GPA_PMAP, VM_GLA2GPA,
+   VM_ACTIVATE_CPU, VM_GET_CPUS, VM_SET_INTINFO, VM_GET_INTINFO,
+   VM_RTC_WRITE, VM_RTC_READ, VM_RTC_SETTIME, VM_RTC_GETTIME,
+   VM_RESTART_INSTRUCTION };
+
+   if (len == NULL) {
+   cmds = malloc(sizeof(vm_ioctl_cmds));
+   if (cmds == NULL)
+   return (NULL);
+   bcopy(vm_ioctl_cmds, cmds, sizeof(vm_ioctl_cmds));
+   return (cmds);
+   }
+
+   *len = nitems(vm_ioctl_cmds);
+   return (NULL);
+}
+

Modified: stable/11/lib/libvmmapi/vmmapi.h
==
--- stable/11/lib/libvmmapi/vmmapi.hMon Jul 10 06:25:30 2017
(r320865)
+++ stable/11/lib/libvmmapi/vmmapi.hMon Jul 10 06:28:50 2017
(r320866)
@@ -36,7 +36,7 @@
  * API version for out-of-tree consumers like grub-bhyve for making compile
  * time decisions.
  */
-#defineVMMAPI_VERSION  0102/* 2 digit major followed by 2 digit 
minor */
+#defineVMMAPI_VERSION  0103/* 2 digit major followed by 2 digit 
minor */
 
 struct iovec;
 struct vmctx;
@@ -102,6 +102,7 @@ int vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, 
vm_ooffset_t segoff, size_t len, int prot);
 
 intvm_create(const char *name);
+intvm_get_device_fd(struct vmctx *ctx);
 struct vmctx *vm_open(const char *name);
 void   vm_destroy(struct vmctx *ctx);
 intvm_parse_memsize(const char *optarg, size_t *memsize);
@@ -161,6 +162,8 @@ int vm_setup_pptdev_msix(struct vmctx *ctx, int vcpu, 
 
 intvm_get_intinfo(struct vmctx *ctx, int vcpu, uint64_t *i1, uint64_t *i2);
 intvm_set_intinfo(struct vmctx *ctx, int vcpu, uint64_t exit_intinfo);
+
+const cap_ioctl_t *vm_get_ioctls(size_t *len);
 
 /*
  * Return a pointer to the statistics buffer. Note that this is not MT-safe.

Modified: stable/11/usr.sbin/bhyve/bhyverun.c
==
--- stable/11/usr.sbin/bhyve/bhyverun.c Mon Jul 10 06:25:30 2017
(r320865)
+++ stable/11/usr.sbin/bhyve/bhyverun.c Mon Jul 10 06:28:50 2017
(r320866)
@@ -30,6 +30,9 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#endif
 #include 
 #include 
 
@@ -40,6 +43,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,8 +52,15 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#ifndef WITHOUT_CAPSICUM
+#include 
+#include 

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

2017-07-09 Thread Peter Grehan
Author: grehan
Date: Mon Jul 10 03:11:48 2017
New Revision: 320855
URL: https://svnweb.freebsd.org/changeset/base/320855

Log:
  MFC r311699
  
  ps2 mouse fixes, found by plan9/9front.
  
  Reminded by:  sevan

Modified:
  stable/11/usr.sbin/bhyve/ps2mouse.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/ps2mouse.c
==
--- stable/11/usr.sbin/bhyve/ps2mouse.c Sun Jul  9 23:14:51 2017
(r320854)
+++ stable/11/usr.sbin/bhyve/ps2mouse.c Mon Jul 10 03:11:48 2017
(r320855)
@@ -62,6 +62,16 @@ __FBSDID("$FreeBSD$");
 /* mouse device id */
 #definePS2MOUSE_DEV_ID 0x0
 
+/* mouse data bits */
+#definePS2M_DATA_Y_OFLOW   0x80
+#definePS2M_DATA_X_OFLOW   0x40
+#definePS2M_DATA_Y_SIGN0x20
+#definePS2M_DATA_X_SIGN0x10
+#definePS2M_DATA_AONE  0x08
+#definePS2M_DATA_MID_BUTTON0x04
+#definePS2M_DATA_RIGHT_BUTTON  0x02
+#definePS2M_DATA_LEFT_BUTTON   0x01
+
 /* mouse status bits */
 #definePS2M_STS_REMOTE_MODE0x40
 #definePS2M_STS_ENABLE_DEV 0x20
@@ -169,19 +179,20 @@ movement_get(struct ps2mouse_softc *sc)
 
assert(pthread_mutex_isowned_np(>mtx));
 
-   val0 =  sc->status & (PS2M_STS_LEFT_BUTTON |
-   PS2M_STS_RIGHT_BUTTON | PS2M_STS_MID_BUTTON);
+   val0 = PS2M_DATA_AONE;
+   val0 |= sc->status & (PS2M_DATA_LEFT_BUTTON |
+   PS2M_DATA_RIGHT_BUTTON | PS2M_DATA_MID_BUTTON);
 
if (sc->delta_x >= 0) {
if (sc->delta_x > 255) {
-   val0 |= (1 << 6);
+   val0 |= PS2M_DATA_X_OFLOW;
val1 = 255;
} else
val1 = sc->delta_x;
} else {
-   val0 |= (1 << 4);
+   val0 |= PS2M_DATA_X_SIGN;
if (sc->delta_x < -255) {
-   val0 |= (1 << 6);
+   val0 |= PS2M_DATA_X_OFLOW;
val1 = 255;
} else
val1 = sc->delta_x;
@@ -190,14 +201,14 @@ movement_get(struct ps2mouse_softc *sc)
 
if (sc->delta_y >= 0) {
if (sc->delta_y > 255) {
-   val0 |= (1 << 7);
+   val0 |= PS2M_DATA_Y_OFLOW;
val2 = 255;
} else
val2 = sc->delta_y;
} else {
-   val0 |= (1 << 5);
+   val0 |= PS2M_DATA_Y_SIGN;
if (sc->delta_y < -255) {
-   val0 |= (1 << 7);
+   val0 |= PS2M_DATA_Y_OFLOW;
val2 = 255;
} else
val2 = sc->delta_y;
___
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: r319487 - head/usr.sbin/bhyve

2017-06-10 Thread Peter Grehan

Hi Conrad,


Here, keystr is not zero initialized
Note that strncpy below does not fill the remainder of the buffer with
nuls if rc->password is shorter than 7 characters.


+* The client then sends the resulting 16-bytes response.
+*/
+#ifndef NO_OPENSSL
+   strncpy(keystr, rc->password, PASSWD_LENGTH);


 strncpy() is specified to zero-fill if the source is shorter than the 
length. Are we missing something ?


 The other issues you brought up look valid.

later,

Peter.
___
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: r316311 - in head: lib/libstand sys/boot/geli sys/boot/i386/gptboot sys/boot/i386/loader sys/boot/i386/zfsboot

2017-03-31 Thread Peter Grehan

So... can anyone provide a clue what's "explicit" (or different in any
way) between explicit_bzero() and normal bzero()?



https://www.freebsd.org/cgi/man.cgi?query=explicit_bzero=3=FreeBSD+12-current

later,

Peter.

___
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: r315930 - stable/11/sys/dev/usb/input

2017-03-24 Thread Peter Grehan
Author: grehan
Date: Sat Mar 25 05:41:34 2017
New Revision: 315930
URL: https://svnweb.freebsd.org/changeset/base/315930

Log:
  MFC r315716
Bring the handling of the y axis in the ums driver in-line with the other
axes.
  
No functional change.

Modified:
  stable/11/sys/dev/usb/input/ums.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/usb/input/ums.c
==
--- stable/11/sys/dev/usb/input/ums.c   Sat Mar 25 05:21:49 2017
(r315929)
+++ stable/11/sys/dev/usb/input/ums.c   Sat Mar 25 05:41:34 2017
(r315930)
@@ -283,7 +283,7 @@ ums_intr_callback(struct usb_xfer *xfer,
 
if ((info->sc_flags & UMS_FLAG_Y_AXIS) &&
(id == info->sc_iid_y))
-   dy = -hid_get_data(buf, len, >sc_loc_y);
+   dy -= hid_get_data(buf, len, >sc_loc_y);
 
if ((info->sc_flags & UMS_FLAG_Z_AXIS) &&
(id == info->sc_iid_z)) {
___
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: r315929 - stable/11/usr.sbin/bhyve

2017-03-24 Thread Peter Grehan
Author: grehan
Date: Sat Mar 25 05:21:49 2017
New Revision: 315929
URL: https://svnweb.freebsd.org/changeset/base/315929

Log:
  MFC r315715  Fix a type in bhyve's USB mouse emulation.

Modified:
  stable/11/usr.sbin/bhyve/usb_mouse.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/usb_mouse.c
==
--- stable/11/usr.sbin/bhyve/usb_mouse.cSat Mar 25 05:09:03 2017
(r315928)
+++ stable/11/usr.sbin/bhyve/usb_mouse.cSat Mar 25 05:21:49 2017
(r315929)
@@ -284,7 +284,7 @@ umouse_event(uint8_t button, int x, int 
 
/* scale coords to mouse resolution */
sc->um_report.x = MOUSE_MAX_X * x / gc->width;
-   sc->um_report.y = MOUSE_MAX_X * y / gc->height;
+   sc->um_report.y = MOUSE_MAX_Y * y / gc->height;
sc->newdata = 1;
pthread_mutex_unlock(>mtx);
 
___
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: r315928 - in stable/10/sys: amd64/vmm x86/include x86/x86

2017-03-24 Thread Peter Grehan
Author: grehan
Date: Sat Mar 25 05:09:03 2017
New Revision: 315928
URL: https://svnweb.freebsd.org/changeset/base/315928

Log:
  MFC  r315361 and  r315364: Hide MONITORX/MWAITX from guests.
  
  r315361
Add the AMD MONITORX/MWAITX feature definition introduced in
Bulldozer/Ryzen CPUs.
  
  r315364
Hide the AMD MONITORX/MWAITX capability.
Otherwise, recent Linux guests will use these instructions, resulting
in #UD exceptions since bhyve doesn't implement MONITOR/MWAIT exits.
  
This fixes boot-time hangs in recent Linux guests on Ryzen CPUs
(and probably Bulldozer aka AMD FX as well).

Modified:
  stable/10/sys/amd64/vmm/x86.c
  stable/10/sys/x86/include/specialreg.h
  stable/10/sys/x86/x86/identcpu.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/vmm/x86.c
==
--- stable/10/sys/amd64/vmm/x86.c   Sat Mar 25 05:05:12 2017
(r315927)
+++ stable/10/sys/amd64/vmm/x86.c   Sat Mar 25 05:09:03 2017
(r315928)
@@ -176,6 +176,9 @@ x86_emulate_cpuid(struct vm *vm, int vcp
/* Don't advertise the OS visible workaround feature */
regs[2] &= ~AMDID2_OSVW;
 
+   /* Hide mwaitx/monitorx capability from the guest */
+   regs[2] &= ~AMDID2_MWAITX;
+
/*
 * Hide rdtscp/ia32_tsc_aux until we know how
 * to deal with them.

Modified: stable/10/sys/x86/include/specialreg.h
==
--- stable/10/sys/x86/include/specialreg.h  Sat Mar 25 05:05:12 2017
(r315927)
+++ stable/10/sys/x86/include/specialreg.h  Sat Mar 25 05:09:03 2017
(r315928)
@@ -226,6 +226,7 @@
 #defineAMDID2_DBE  0x0400
 #defineAMDID2_PTSC 0x0800
 #defineAMDID2_PTSCEL2I 0x1000
+#defineAMDID2_MWAITX   0x2000
 
 /*
  * CPUID instruction 1 eax info

Modified: stable/10/sys/x86/x86/identcpu.c
==
--- stable/10/sys/x86/x86/identcpu.cSat Mar 25 05:05:12 2017
(r315927)
+++ stable/10/sys/x86/x86/identcpu.cSat Mar 25 05:09:03 2017
(r315928)
@@ -875,7 +875,7 @@ printcpuinfo(void)
"\033DBE"   /* Data Breakpoint extension */
"\034PTSC"  /* Performance TSC */
"\035PL2I"  /* L2I perf count */
-   "\036"
+   "\036MWAITX"/* MONITORX/MWAITX instructions 
*/
"\037"
"\040"
);
___
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: r315927 - in stable/11/sys: amd64/vmm x86/include x86/x86

2017-03-24 Thread Peter Grehan
Author: grehan
Date: Sat Mar 25 05:05:12 2017
New Revision: 315927
URL: https://svnweb.freebsd.org/changeset/base/315927

Log:
  MFC  r315361 and  r315364: Hide MONITORX/MWAITX from guests.
  
  r315361
Add the AMD MONITORX/MWAITX feature definition introduced in
Bulldozer/Ryzen CPUs.
  
  r315364
Hide the AMD MONITORX/MWAITX capability.
Otherwise, recent Linux guests will use these instructions, resulting
in #UD exceptions since bhyve doesn't implement MONITOR/MWAIT exits.
  
This fixes boot-time hangs in recent Linux guests on Ryzen CPUs
(and probably Bulldozer aka AMD FX as well).

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

Modified: stable/11/sys/amd64/vmm/x86.c
==
--- stable/11/sys/amd64/vmm/x86.c   Sat Mar 25 02:55:13 2017
(r315926)
+++ stable/11/sys/amd64/vmm/x86.c   Sat Mar 25 05:05:12 2017
(r315927)
@@ -176,6 +176,9 @@ x86_emulate_cpuid(struct vm *vm, int vcp
/* Don't advertise the OS visible workaround feature */
regs[2] &= ~AMDID2_OSVW;
 
+   /* Hide mwaitx/monitorx capability from the guest */
+   regs[2] &= ~AMDID2_MWAITX;
+
/*
 * Hide rdtscp/ia32_tsc_aux until we know how
 * to deal with them.

Modified: stable/11/sys/x86/include/specialreg.h
==
--- stable/11/sys/x86/include/specialreg.h  Sat Mar 25 02:55:13 2017
(r315926)
+++ stable/11/sys/x86/include/specialreg.h  Sat Mar 25 05:05:12 2017
(r315927)
@@ -227,6 +227,7 @@
 #defineAMDID2_DBE  0x0400
 #defineAMDID2_PTSC 0x0800
 #defineAMDID2_PTSCEL2I 0x1000
+#defineAMDID2_MWAITX   0x2000
 
 /*
  * CPUID instruction 1 eax info

Modified: stable/11/sys/x86/x86/identcpu.c
==
--- stable/11/sys/x86/x86/identcpu.cSat Mar 25 02:55:13 2017
(r315926)
+++ stable/11/sys/x86/x86/identcpu.cSat Mar 25 05:05:12 2017
(r315927)
@@ -906,7 +906,7 @@ printcpuinfo(void)
"\033DBE"   /* Data Breakpoint extension */
"\034PTSC"  /* Performance TSC */
"\035PL2I"  /* L2I perf count */
-   "\036"
+   "\036MWAITX"/* MONITORX/MWAITX instructions 
*/
"\037"
"\040"
);
___
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: r315716 - head/sys/dev/usb/input

2017-03-22 Thread Peter Grehan
Author: grehan
Date: Wed Mar 22 17:06:57 2017
New Revision: 315716
URL: https://svnweb.freebsd.org/changeset/base/315716

Log:
  Bring the handling of the y axis in the ums driver in-line with the other
  axes.
  
  No functional change.
  
  Submitted by: Vicki Pfau (vi AT endrift.com)
  Approved by:  hps
  MFC after:3 days
  Differential Revision:https://reviews.freebsd.org/D9595

Modified:
  head/sys/dev/usb/input/ums.c

Modified: head/sys/dev/usb/input/ums.c
==
--- head/sys/dev/usb/input/ums.cWed Mar 22 16:53:03 2017
(r315715)
+++ head/sys/dev/usb/input/ums.cWed Mar 22 17:06:57 2017
(r315716)
@@ -283,7 +283,7 @@ ums_intr_callback(struct usb_xfer *xfer,
 
if ((info->sc_flags & UMS_FLAG_Y_AXIS) &&
(id == info->sc_iid_y))
-   dy = -hid_get_data(buf, len, >sc_loc_y);
+   dy -= hid_get_data(buf, len, >sc_loc_y);
 
if ((info->sc_flags & UMS_FLAG_Z_AXIS) &&
(id == info->sc_iid_z)) {
___
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: r315715 - head/usr.sbin/bhyve

2017-03-22 Thread Peter Grehan
Author: grehan
Date: Wed Mar 22 16:53:03 2017
New Revision: 315715
URL: https://svnweb.freebsd.org/changeset/base/315715

Log:
  This fixes a typo in bhyve's USB mouse emulation.
  There is no behavioral difference, as it's just swapping
  out the name of two identically-valued constants.
  
  Submitted by: Vicki Pfau (vi AT endrift.com)
  MFC after:3 days
  Differential Revision:https://reviews.freebsd.org/D9597

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

Modified: head/usr.sbin/bhyve/usb_mouse.c
==
--- head/usr.sbin/bhyve/usb_mouse.c Wed Mar 22 15:46:31 2017
(r315714)
+++ head/usr.sbin/bhyve/usb_mouse.c Wed Mar 22 16:53:03 2017
(r315715)
@@ -284,7 +284,7 @@ umouse_event(uint8_t button, int x, int 
 
/* scale coords to mouse resolution */
sc->um_report.x = MOUSE_MAX_X * x / gc->width;
-   sc->um_report.y = MOUSE_MAX_X * y / gc->height;
+   sc->um_report.y = MOUSE_MAX_Y * y / gc->height;
sc->newdata = 1;
pthread_mutex_unlock(>mtx);
 
___
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: r315364 - head/sys/amd64/vmm

2017-03-15 Thread Peter Grehan
Author: grehan
Date: Thu Mar 16 03:21:42 2017
New Revision: 315364
URL: https://svnweb.freebsd.org/changeset/base/315364

Log:
  Hide the AMD MONITORX/MWAITX capability.
  Otherwise, recent Linux guests will use these instructions, resulting
  in #UD exceptions since bhyve doesn't implement MONITOR/MWAIT exits.
  
  This fixes boot-time hangs in recent Linux guests on Ryzen CPUs
  (and probably Bulldozer aka AMD FX as well).
  
  Reviewed by:  kib
  MFC after:1 week

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

Modified: head/sys/amd64/vmm/x86.c
==
--- head/sys/amd64/vmm/x86.cThu Mar 16 03:20:59 2017(r315363)
+++ head/sys/amd64/vmm/x86.cThu Mar 16 03:21:42 2017(r315364)
@@ -176,6 +176,9 @@ x86_emulate_cpuid(struct vm *vm, int vcp
/* Don't advertise the OS visible workaround feature */
regs[2] &= ~AMDID2_OSVW;
 
+   /* Hide mwaitx/monitorx capability from the guest */
+   regs[2] &= ~AMDID2_MWAITX;
+
/*
 * Hide rdtscp/ia32_tsc_aux until we know how
 * to deal with them.
___
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: r315361 - in head/sys/x86: include x86

2017-03-15 Thread Peter Grehan
Author: grehan
Date: Thu Mar 16 03:06:50 2017
New Revision: 315361
URL: https://svnweb.freebsd.org/changeset/base/315361

Log:
  Add the AMD MONITORX/MWAITX feature definition introduced in
  Bulldozer/Ryzen CPUs.
  
  Reviewed by:  kib
  MFC after:1 week

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

Modified: head/sys/x86/include/specialreg.h
==
--- head/sys/x86/include/specialreg.h   Thu Mar 16 02:31:42 2017
(r315360)
+++ head/sys/x86/include/specialreg.h   Thu Mar 16 03:06:50 2017
(r315361)
@@ -227,6 +227,7 @@
 #defineAMDID2_DBE  0x0400
 #defineAMDID2_PTSC 0x0800
 #defineAMDID2_PTSCEL2I 0x1000
+#defineAMDID2_MWAITX   0x2000
 
 /*
  * CPUID instruction 1 eax info

Modified: head/sys/x86/x86/identcpu.c
==
--- head/sys/x86/x86/identcpu.c Thu Mar 16 02:31:42 2017(r315360)
+++ head/sys/x86/x86/identcpu.c Thu Mar 16 03:06:50 2017(r315361)
@@ -906,7 +906,7 @@ printcpuinfo(void)
"\033DBE"   /* Data Breakpoint extension */
"\034PTSC"  /* Performance TSC */
"\035PL2I"  /* L2I perf count */
-   "\036"
+   "\036MWAITX"/* MONITORX/MWAITX instructions 
*/
"\037"
"\040"
);
___
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: r313812 - stable/10/usr.sbin/bhyve

2017-02-16 Thread Peter Grehan
Author: grehan
Date: Thu Feb 16 17:08:43 2017
New Revision: 313812
URL: https://svnweb.freebsd.org/changeset/base/313812

Log:
  MFC r311702
Use correct PCI device id for virtio-rng.
This prevented the device from attaching with a
Windows guest (most other guests use the device type
for matching)
  
PR:   212711

Modified:
  stable/10/usr.sbin/bhyve/virtio.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/bhyve/virtio.h
==
--- stable/10/usr.sbin/bhyve/virtio.h   Thu Feb 16 17:07:20 2017
(r313811)
+++ stable/10/usr.sbin/bhyve/virtio.h   Thu Feb 16 17:08:43 2017
(r313812)
@@ -209,7 +209,7 @@ struct vring_used {
 #defineVIRTIO_VENDOR   0x1AF4
 #defineVIRTIO_DEV_NET  0x1000
 #defineVIRTIO_DEV_BLOCK0x1001
-#defineVIRTIO_DEV_RANDOM   0x1002
+#defineVIRTIO_DEV_RANDOM   0x1005
 
 /*
  * PCI config space constants.
___
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: r313811 - stable/11/usr.sbin/bhyve

2017-02-16 Thread Peter Grehan
Author: grehan
Date: Thu Feb 16 17:07:20 2017
New Revision: 313811
URL: https://svnweb.freebsd.org/changeset/base/313811

Log:
  MFC r311702
Use correct PCI device id for virtio-rng.
This prevented the device from attaching with a
Windows guest (most other guests use the device type
for matching)
  
PR:   212711

Modified:
  stable/11/usr.sbin/bhyve/virtio.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/virtio.h
==
--- stable/11/usr.sbin/bhyve/virtio.h   Thu Feb 16 14:13:36 2017
(r313810)
+++ stable/11/usr.sbin/bhyve/virtio.h   Thu Feb 16 17:07:20 2017
(r313811)
@@ -209,7 +209,7 @@ struct vring_used {
 #defineVIRTIO_VENDOR   0x1AF4
 #defineVIRTIO_DEV_NET  0x1000
 #defineVIRTIO_DEV_BLOCK0x1001
-#defineVIRTIO_DEV_RANDOM   0x1002
+#defineVIRTIO_DEV_RANDOM   0x1005
 
 /*
  * PCI config space constants.
___
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: r311702 - head/usr.sbin/bhyve

2017-01-08 Thread Peter Grehan
Author: grehan
Date: Sun Jan  8 20:58:58 2017
New Revision: 311702
URL: https://svnweb.freebsd.org/changeset/base/311702

Log:
  Use correct PCI device id for virtio-rng.
  This prevented the device from attaching with a
  Windows guest (most other guests use the device type
  for matching)
  
  PR:   212711
  Submitted by: jbeich
  MFC after:3 days

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

Modified: head/usr.sbin/bhyve/virtio.h
==
--- head/usr.sbin/bhyve/virtio.hSun Jan  8 20:41:32 2017
(r311701)
+++ head/usr.sbin/bhyve/virtio.hSun Jan  8 20:58:58 2017
(r311702)
@@ -209,8 +209,8 @@ struct vring_used {
 #defineVIRTIO_VENDOR   0x1AF4
 #defineVIRTIO_DEV_NET  0x1000
 #defineVIRTIO_DEV_BLOCK0x1001
-#defineVIRTIO_DEV_RANDOM   0x1002
 #defineVIRTIO_DEV_CONSOLE  0x1003
+#defineVIRTIO_DEV_RANDOM   0x1005
 
 /*
  * PCI config space constants.
___
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: r311699 - head/usr.sbin/bhyve

2017-01-08 Thread Peter Grehan
Author: grehan
Date: Sun Jan  8 20:29:35 2017
New Revision: 311699
URL: https://svnweb.freebsd.org/changeset/base/311699

Log:
  Make sure the 'Always-one' bit is always set to one,
  in the first byte of the 3-byte mouse data report.
  Plan9/9front requires this.
  
  Switch over to using #defines for the data report bits.
  
  Verified no regression on Win10/Fedora-live.
  
  Reported and tested by: Trent Thompson (trentnthompson at gmail com)
  MFC after:1 week

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

Modified: head/usr.sbin/bhyve/ps2mouse.c
==
--- head/usr.sbin/bhyve/ps2mouse.c  Sun Jan  8 19:48:13 2017
(r311698)
+++ head/usr.sbin/bhyve/ps2mouse.c  Sun Jan  8 20:29:35 2017
(r311699)
@@ -62,6 +62,16 @@ __FBSDID("$FreeBSD$");
 /* mouse device id */
 #definePS2MOUSE_DEV_ID 0x0
 
+/* mouse data bits */
+#definePS2M_DATA_Y_OFLOW   0x80
+#definePS2M_DATA_X_OFLOW   0x40
+#definePS2M_DATA_Y_SIGN0x20
+#definePS2M_DATA_X_SIGN0x10
+#definePS2M_DATA_AONE  0x08
+#definePS2M_DATA_MID_BUTTON0x04
+#definePS2M_DATA_RIGHT_BUTTON  0x02
+#definePS2M_DATA_LEFT_BUTTON   0x01
+
 /* mouse status bits */
 #definePS2M_STS_REMOTE_MODE0x40
 #definePS2M_STS_ENABLE_DEV 0x20
@@ -169,19 +179,20 @@ movement_get(struct ps2mouse_softc *sc)
 
assert(pthread_mutex_isowned_np(>mtx));
 
-   val0 =  sc->status & (PS2M_STS_LEFT_BUTTON |
-   PS2M_STS_RIGHT_BUTTON | PS2M_STS_MID_BUTTON);
+   val0 = PS2M_DATA_AONE;
+   val0 |= sc->status & (PS2M_DATA_LEFT_BUTTON |
+   PS2M_DATA_RIGHT_BUTTON | PS2M_DATA_MID_BUTTON);
 
if (sc->delta_x >= 0) {
if (sc->delta_x > 255) {
-   val0 |= (1 << 6);
+   val0 |= PS2M_DATA_X_OFLOW;
val1 = 255;
} else
val1 = sc->delta_x;
} else {
-   val0 |= (1 << 4);
+   val0 |= PS2M_DATA_X_SIGN;
if (sc->delta_x < -255) {
-   val0 |= (1 << 6);
+   val0 |= PS2M_DATA_X_OFLOW;
val1 = 255;
} else
val1 = sc->delta_x;
@@ -190,14 +201,14 @@ movement_get(struct ps2mouse_softc *sc)
 
if (sc->delta_y >= 0) {
if (sc->delta_y > 255) {
-   val0 |= (1 << 7);
+   val0 |= PS2M_DATA_Y_OFLOW;
val2 = 255;
} else
val2 = sc->delta_y;
} else {
-   val0 |= (1 << 5);
+   val0 |= PS2M_DATA_Y_SIGN;
if (sc->delta_y < -255) {
-   val0 |= (1 << 7);
+   val0 |= PS2M_DATA_Y_OFLOW;
val2 = 255;
} else
val2 = sc->delta_y;
___
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: r305718 - stable/11/usr.sbin/bhyve

2016-09-11 Thread Peter Grehan
Author: grehan
Date: Mon Sep 12 00:24:56 2016
New Revision: 305718
URL: https://svnweb.freebsd.org/changeset/base/305718

Log:
  MFC r305061
  Invert calloc(3) argument order

Modified:
  stable/11/usr.sbin/bhyve/pci_e82545.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/pci_e82545.c
==
--- stable/11/usr.sbin/bhyve/pci_e82545.c   Mon Sep 12 00:21:55 2016
(r305717)
+++ stable/11/usr.sbin/bhyve/pci_e82545.c   Mon Sep 12 00:24:56 2016
(r305718)
@@ -2273,7 +2273,7 @@ e82545_init(struct vmctx *ctx, struct pc
int mac_provided;
 
/* Setup our softc */
-   sc = calloc(sizeof(*sc), 1);
+   sc = calloc(1, sizeof(*sc));
 
pi->pi_arg = sc;
sc->esc_pi = pi;
___
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: r305717 - stable/11/usr.sbin/bhyve

2016-09-11 Thread Peter Grehan
Author: grehan
Date: Mon Sep 12 00:21:55 2016
New Revision: 305717
URL: https://svnweb.freebsd.org/changeset/base/305717

Log:
  MFC r303352
  - Change the fbuf "vga" parameter to "vga=on|io|off".
 "io" is the default, and allows VGA i/o registers to be
 accessed. This is required by Win7/2k8 graphics guests that
 use a combination of BIOS int10 and UEFI.
 "off" disables all VGA i/o and mem accesses.
 "on" is not yet hooked up, but will enable full VGA rendering.
  
 OpenBSD/UEFI >= 5.9 graphics guests can be booted using "vga=off"
  
  - Allow "rfb" to be used instead of "tcp" for the fbuf VNC
description. "tcp" will be removed at a future point and is
kept as an alias.

Modified:
  stable/11/usr.sbin/bhyve/pci_fbuf.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/pci_fbuf.c
==
--- stable/11/usr.sbin/bhyve/pci_fbuf.c Mon Sep 12 00:16:26 2016
(r305716)
+++ stable/11/usr.sbin/bhyve/pci_fbuf.c Mon Sep 12 00:21:55 2016
(r305717)
@@ -95,7 +95,8 @@ struct pci_fbuf_softc {
char  *rfb_host;
int   rfb_port;
int   rfb_wait;
-   int   use_vga;
+   int   vga_enabled;
+   int   vga_full;
 
uint32_t  fbaddr;
char  *fb_base;
@@ -114,7 +115,7 @@ pci_fbuf_usage(char *opt)
 {
 
fprintf(stderr, "Invalid fbuf emulation \"%s\"\r\n", opt);
-   fprintf(stderr, "fbuf: {wait,}tcp=:port\r\n");
+   fprintf(stderr, "fbuf: {wait,}{vga=on|io|off,}rfb=:port\r\n");
 }
 
 static void
@@ -234,13 +235,6 @@ pci_fbuf_parse_opts(struct pci_fbuf_soft
continue;
}
 
-#if 0 /* notyet */ 
-   if (strcmp(xopts, "vga") == 0) {
-   sc->use_vga = 1;
-   continue;
-   }
-#endif
-
if ((config = strchr(xopts, '=')) == NULL) {
pci_fbuf_usage(xopts);
ret = -1;
@@ -252,17 +246,31 @@ pci_fbuf_parse_opts(struct pci_fbuf_soft
DPRINTF(DEBUG_VERBOSE, ("pci_fbuf option %s = %s\r\n",
   xopts, config));
 
-   if (!strcmp(xopts, "tcp")) {
+   if (!strcmp(xopts, "tcp") || !strcmp(xopts, "rfb")) {
/* parse host-ip:port */
-   tmpstr = strsep(, ":");
+   tmpstr = strsep(, ":");
if (!config)
sc->rfb_port = atoi(tmpstr);
else {
sc->rfb_port = atoi(config);
sc->rfb_host = tmpstr;
}
-   } else if (!strcmp(xopts, "w")) {
-   sc->memregs.width = atoi(config);
+   } else if (!strcmp(xopts, "vga")) {
+   if (!strcmp(config, "off")) {
+   sc->vga_enabled = 0;
+   } else if (!strcmp(config, "io")) {
+   sc->vga_enabled = 1;
+   sc->vga_full = 0;
+   } else if (!strcmp(config, "on")) {
+   sc->vga_enabled = 1;
+   sc->vga_full = 1;
+   } else {
+   pci_fbuf_usage(opts);
+   ret = -1;
+   goto done;
+   }
+   } else if (!strcmp(xopts, "w")) {
+   sc->memregs.width = atoi(config);
if (sc->memregs.width > COLS_MAX) {
pci_fbuf_usage(xopts);
ret = -1;
@@ -299,7 +307,7 @@ pci_fbuf_render(struct bhyvegc *gc, void
 
sc = arg;
 
-   if (sc->use_vga && sc->gc_image->vgamode) {
+   if (sc->vga_full && sc->gc_image->vgamode) {
/* TODO: mode switching to vga and vesa should use the special
 *  EFI-bhyve protocol port.
 */
@@ -352,12 +360,21 @@ pci_fbuf_init(struct vmctx *ctx, struct 
sc->memregs.height = ROWS_DEFAULT;
sc->memregs.depth  = 32;
 
+   sc->vga_enabled = 1;
+   sc->vga_full = 0;
+
sc->fsc_pi = pi;
 
error = pci_fbuf_parse_opts(sc, opts);
if (error != 0)
goto done;
 
+   /* XXX until VGA rendering is enabled */
+   if (sc->vga_full != 0) {
+   fprintf(stderr, "pci_fbuf: VGA rendering not enabled");
+   goto done;
+   }
+
sc->fb_base = vm_create_devmem(ctx, VM_FRAMEBUFFER, "framebuffer", 
FB_SIZE);
if (sc->fb_base == MAP_FAILED) {
error = -1;
@@ -382,7 +399,8 @@ pci_fbuf_init(struct vmctx *ctx, struct 
console_init(sc->memregs.width, 

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

2016-09-11 Thread Peter Grehan
Author: grehan
Date: Mon Sep 12 00:16:26 2016
New Revision: 305716
URL: https://svnweb.freebsd.org/changeset/base/305716

Log:
  MFC r302972,r303349
  
  r302972
  Disallow interrupt requests on disabled endpoints.
  
  r303349
  Catch another case where an XHCI interrupt was being
  injected without state being set up.

Modified:
  stable/11/usr.sbin/bhyve/pci_xhci.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/pci_xhci.c
==
--- stable/11/usr.sbin/bhyve/pci_xhci.c Mon Sep 12 00:15:40 2016
(r305715)
+++ stable/11/usr.sbin/bhyve/pci_xhci.c Mon Sep 12 00:16:26 2016
(r305716)
@@ -2537,9 +2537,11 @@ static int
 pci_xhci_dev_intr(struct usb_hci *hci, int epctx)
 {
struct pci_xhci_dev_emu *dev;
+   struct xhci_dev_ctx *dev_ctx;
struct xhci_trb evtrb;
struct pci_xhci_softc   *sc;
struct pci_xhci_portregs *p;
+   struct xhci_endp_ctx*ep_ctx;
int error;
int dir_in;
int epid;
@@ -2557,7 +2559,8 @@ pci_xhci_dev_intr(struct usb_hci *hci, i
 
/* check if device is ready; OS has to initialise it */
if (sc->rtsregs.erstba_p == NULL ||
-   (sc->opregs.usbcmd & XHCI_CMD_RS) == 0)
+   (sc->opregs.usbcmd & XHCI_CMD_RS) == 0 ||
+   dev->dev_ctx == NULL)
return (0);
 
p = XHCI_PORTREG_PTR(sc, hci->hci_port);
@@ -2578,6 +2581,14 @@ pci_xhci_dev_intr(struct usb_hci *hci, i
goto done;
}
 
+   dev_ctx = dev->dev_ctx;
+   ep_ctx = _ctx->ctx_ep[epid];
+   if ((ep_ctx->dwEpCtx0 & 0x7) == XHCI_ST_EPCTX_DISABLED) {
+   DPRINTF(("xhci device interrupt on disabled endpoint %d\r\n",
+epid));
+   return (0);
+   }
+
DPRINTF(("xhci device interrupt on endpoint %d\r\n", epid));
 
pci_xhci_device_doorbell(sc, hci->hci_port, epid, 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: r305714 - stable/11/usr.sbin/bhyve

2016-09-11 Thread Peter Grehan
Author: grehan
Date: Mon Sep 12 00:03:14 2016
New Revision: 305714
URL: https://svnweb.freebsd.org/changeset/base/305714

Log:
  MFC r302546
  Implement right shift/ctl, and convert the VNC/xorg scancode
  of 0xff03 into right-alt.

Modified:
  stable/11/usr.sbin/bhyve/ps2kbd.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/ps2kbd.c
==
--- stable/11/usr.sbin/bhyve/ps2kbd.c   Sun Sep 11 23:08:57 2016
(r305713)
+++ stable/11/usr.sbin/bhyve/ps2kbd.c   Mon Sep 12 00:03:14 2016
(r305714)
@@ -324,7 +324,9 @@ ps2kbd_keysym_queue(struct ps2kbd_softc 
fifo_put(sc, 0x12);
break;
case 0xffe2:/* Right shift */
-   /* XXX */
+   if (!down)
+   fifo_put(sc, 0xf0);
+   fifo_put(sc, 0x59);
break;
case 0xffe3:/* Left control */
if (!down)
@@ -332,7 +334,10 @@ ps2kbd_keysym_queue(struct ps2kbd_softc 
fifo_put(sc, 0x14);
break;
case 0xffe4:/* Right control */
-   /* XXX */
+   fifo_put(sc, 0xe0);
+   if (!down)
+   fifo_put(sc, 0xf0);
+   fifo_put(sc, 0x14);
break;
case 0xffe7:/* Left meta */
/* XXX */
@@ -345,6 +350,7 @@ ps2kbd_keysym_queue(struct ps2kbd_softc 
fifo_put(sc, 0xf0);
fifo_put(sc, 0x11);
break;
+   case 0xfe03:/* AltGr */
case 0xffea:/* Right alt */
fifo_put(sc, 0xe0);
if (!down)
___
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: r303352 - head/usr.sbin/bhyve

2016-07-26 Thread Peter Grehan
Author: grehan
Date: Wed Jul 27 00:03:29 2016
New Revision: 303352
URL: https://svnweb.freebsd.org/changeset/base/303352

Log:
  - Change the fbuf "vga" parameter to "vga=on|io|off".
 "io" is the default, and allows VGA i/o registers to be
 accessed. This is required by Win7/2k8 graphics guests that
 use a combination of BIOS int10 and UEFI.
 "off" disables all VGA i/o and mem accesses.
 "on" is not yet hooked up, but will enable full VGA rendering.
  
 OpenBSD/UEFI >= 5.9 graphics guests can be booted using "vga=off"
  
  - Allow "rfb" to be used instead of "tcp" for the fbuf VNC
description. "tcp" will be removed at a future point and is
kept as an alias.
  
  Discussed with:   Leon Dang
  MFC after:3 days

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

Modified: head/usr.sbin/bhyve/pci_fbuf.c
==
--- head/usr.sbin/bhyve/pci_fbuf.c  Wed Jul 27 00:03:18 2016
(r303351)
+++ head/usr.sbin/bhyve/pci_fbuf.c  Wed Jul 27 00:03:29 2016
(r303352)
@@ -95,7 +95,8 @@ struct pci_fbuf_softc {
char  *rfb_host;
int   rfb_port;
int   rfb_wait;
-   int   use_vga;
+   int   vga_enabled;
+   int   vga_full;
 
uint32_t  fbaddr;
char  *fb_base;
@@ -114,7 +115,7 @@ pci_fbuf_usage(char *opt)
 {
 
fprintf(stderr, "Invalid fbuf emulation \"%s\"\r\n", opt);
-   fprintf(stderr, "fbuf: {wait,}tcp=:port\r\n");
+   fprintf(stderr, "fbuf: {wait,}{vga=on|io|off,}rfb=:port\r\n");
 }
 
 static void
@@ -234,13 +235,6 @@ pci_fbuf_parse_opts(struct pci_fbuf_soft
continue;
}
 
-#if 0 /* notyet */ 
-   if (strcmp(xopts, "vga") == 0) {
-   sc->use_vga = 1;
-   continue;
-   }
-#endif
-
if ((config = strchr(xopts, '=')) == NULL) {
pci_fbuf_usage(xopts);
ret = -1;
@@ -252,17 +246,31 @@ pci_fbuf_parse_opts(struct pci_fbuf_soft
DPRINTF(DEBUG_VERBOSE, ("pci_fbuf option %s = %s\r\n",
   xopts, config));
 
-   if (!strcmp(xopts, "tcp")) {
+   if (!strcmp(xopts, "tcp") || !strcmp(xopts, "rfb")) {
/* parse host-ip:port */
-   tmpstr = strsep(, ":");
+   tmpstr = strsep(, ":");
if (!config)
sc->rfb_port = atoi(tmpstr);
else {
sc->rfb_port = atoi(config);
sc->rfb_host = tmpstr;
}
-   } else if (!strcmp(xopts, "w")) {
-   sc->memregs.width = atoi(config);
+   } else if (!strcmp(xopts, "vga")) {
+   if (!strcmp(config, "off")) {
+   sc->vga_enabled = 0;
+   } else if (!strcmp(config, "io")) {
+   sc->vga_enabled = 1;
+   sc->vga_full = 0;
+   } else if (!strcmp(config, "on")) {
+   sc->vga_enabled = 1;
+   sc->vga_full = 1;
+   } else {
+   pci_fbuf_usage(opts);
+   ret = -1;
+   goto done;
+   }
+   } else if (!strcmp(xopts, "w")) {
+   sc->memregs.width = atoi(config);
if (sc->memregs.width > COLS_MAX) {
pci_fbuf_usage(xopts);
ret = -1;
@@ -299,7 +307,7 @@ pci_fbuf_render(struct bhyvegc *gc, void
 
sc = arg;
 
-   if (sc->use_vga && sc->gc_image->vgamode) {
+   if (sc->vga_full && sc->gc_image->vgamode) {
/* TODO: mode switching to vga and vesa should use the special
 *  EFI-bhyve protocol port.
 */
@@ -352,12 +360,21 @@ pci_fbuf_init(struct vmctx *ctx, struct 
sc->memregs.height = ROWS_DEFAULT;
sc->memregs.depth  = 32;
 
+   sc->vga_enabled = 1;
+   sc->vga_full = 0;
+
sc->fsc_pi = pi;
 
error = pci_fbuf_parse_opts(sc, opts);
if (error != 0)
goto done;
 
+   /* XXX until VGA rendering is enabled */
+   if (sc->vga_full != 0) {
+   fprintf(stderr, "pci_fbuf: VGA rendering not enabled");
+   goto done;
+   }
+
sc->fb_base = vm_create_devmem(ctx, VM_FRAMEBUFFER, "framebuffer", 
FB_SIZE);
if (sc->fb_base == MAP_FAILED) {
error = -1;
@@ -382,7 +399,8 @@ pci_fbuf_init(struct vmctx *ctx, struct 
console_init(sc->memregs.width, sc->memregs.height, sc->fb_base);

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

2016-07-26 Thread Peter Grehan
Author: grehan
Date: Tue Jul 26 23:40:25 2016
New Revision: 303349
URL: https://svnweb.freebsd.org/changeset/base/303349

Log:
  Catch another case where an XHCI interrupt was being
  injected without state being set up.
  
  This fixes a core dump when dropping to the UEFI prompt
  with graphics enabled and moving the mouse around.
  
  Discussed with:   Leon Dang
  MFC after:3 days

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

Modified: head/usr.sbin/bhyve/pci_xhci.c
==
--- head/usr.sbin/bhyve/pci_xhci.c  Tue Jul 26 23:29:37 2016
(r303348)
+++ head/usr.sbin/bhyve/pci_xhci.c  Tue Jul 26 23:40:25 2016
(r303349)
@@ -2559,7 +2559,8 @@ pci_xhci_dev_intr(struct usb_hci *hci, i
 
/* check if device is ready; OS has to initialise it */
if (sc->rtsregs.erstba_p == NULL ||
-   (sc->opregs.usbcmd & XHCI_CMD_RS) == 0)
+   (sc->opregs.usbcmd & XHCI_CMD_RS) == 0 ||
+   dev->dev_ctx == NULL)
return (0);
 
p = XHCI_PORTREG_PTR(sc, hci->hci_port);
___
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: r302972 - head/usr.sbin/bhyve

2016-07-17 Thread Peter Grehan
Author: grehan
Date: Sun Jul 17 20:34:46 2016
New Revision: 302972
URL: https://svnweb.freebsd.org/changeset/base/302972

Log:
  Disallow interrupt requests on disabled endpoints.
  
  Submitted by: Leon Dang
  MFC after:3 days

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

Modified: head/usr.sbin/bhyve/pci_xhci.c
==
--- head/usr.sbin/bhyve/pci_xhci.c  Sun Jul 17 19:24:28 2016
(r302971)
+++ head/usr.sbin/bhyve/pci_xhci.c  Sun Jul 17 20:34:46 2016
(r302972)
@@ -2537,9 +2537,11 @@ static int
 pci_xhci_dev_intr(struct usb_hci *hci, int epctx)
 {
struct pci_xhci_dev_emu *dev;
+   struct xhci_dev_ctx *dev_ctx;
struct xhci_trb evtrb;
struct pci_xhci_softc   *sc;
struct pci_xhci_portregs *p;
+   struct xhci_endp_ctx*ep_ctx;
int error;
int dir_in;
int epid;
@@ -2578,6 +2580,14 @@ pci_xhci_dev_intr(struct usb_hci *hci, i
goto done;
}
 
+   dev_ctx = dev->dev_ctx;
+   ep_ctx = _ctx->ctx_ep[epid];
+   if ((ep_ctx->dwEpCtx0 & 0x7) == XHCI_ST_EPCTX_DISABLED) {
+   DPRINTF(("xhci device interrupt on disabled endpoint %d\r\n",
+epid));
+   return (0);
+   }
+
DPRINTF(("xhci device interrupt on endpoint %d\r\n", epid));
 
pci_xhci_device_doorbell(sc, hci->hci_port, epid, 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: r302546 - head/usr.sbin/bhyve

2016-07-11 Thread Peter Grehan
Author: grehan
Date: Mon Jul 11 06:31:15 2016
New Revision: 302546
URL: https://svnweb.freebsd.org/changeset/base/302546

Log:
  Implement right shift/ctl, and convert the VNC/xorg scancode
  of 0xff03 into right-alt.
  
  Reported by:  lme@
  MFC after:1 week

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

Modified: head/usr.sbin/bhyve/ps2kbd.c
==
--- head/usr.sbin/bhyve/ps2kbd.cMon Jul 11 06:29:56 2016
(r302545)
+++ head/usr.sbin/bhyve/ps2kbd.cMon Jul 11 06:31:15 2016
(r302546)
@@ -324,7 +324,9 @@ ps2kbd_keysym_queue(struct ps2kbd_softc 
fifo_put(sc, 0x12);
break;
case 0xffe2:/* Right shift */
-   /* XXX */
+   if (!down)
+   fifo_put(sc, 0xf0);
+   fifo_put(sc, 0x59);
break;
case 0xffe3:/* Left control */
if (!down)
@@ -332,7 +334,10 @@ ps2kbd_keysym_queue(struct ps2kbd_softc 
fifo_put(sc, 0x14);
break;
case 0xffe4:/* Right control */
-   /* XXX */
+   fifo_put(sc, 0xe0);
+   if (!down)
+   fifo_put(sc, 0xf0);
+   fifo_put(sc, 0x14);
break;
case 0xffe7:/* Left meta */
/* XXX */
@@ -345,6 +350,7 @@ ps2kbd_keysym_queue(struct ps2kbd_softc 
fifo_put(sc, 0xf0);
fifo_put(sc, 0x11);
break;
+   case 0xfe03:/* AltGr */
case 0xffea:/* Right alt */
fifo_put(sc, 0xe0);
if (!down)
___
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: r302332 - head/usr.sbin/bhyve

2016-07-05 Thread Peter Grehan

This breaks the external GCC 5.2 build:


 Fix being worked on in https://reviews.freebsd.org/D7119

later,

Peter.

___
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: r302332 - head/usr.sbin/bhyve

2016-07-03 Thread Peter Grehan
Author: grehan
Date: Mon Jul  4 03:19:06 2016
New Revision: 302332
URL: https://svnweb.freebsd.org/changeset/base/302332

Log:
  Import bhyve_graphics into CURRENT. Thanks to all who tested
  this on the branch.
  
  Original commit message:
Initial bhyve native graphics support.
  
This adds emulations for a raw framebuffer device, PS2 keyboard/mouse,
XHCI USB controller and a USB tablet.
  
A simple VNC server is provided for keyboard/mouse input, and graphics
output.
  
A VGA emulation is included, but is currently disconnected until an
additional bhyve change to block out VGA memory is committed.
  
Credits:
 - raw framebuffer, VNC server, XHCI controller, USB bus/device emulation
and UEFI f/w support by Leon Dang
 - VGA, console/g, initial VNC server  by tychon@
 - PS2 keyboard/mouse jointly done by tychon@ and Leon Dang
 - hypervisor framebuffer mem support by neel@
  
Tested by: Michael Dexter, in a number of revisions of this code.
  
With the appropriate UEFI image, FreeBSD, Windows and Linux guests can
installed and run in graphics mode using the UEFI/GOP framebuffer.
  
  Approved by:  re (gjb)

Added:
 - copied unchanged from r302324, projects/bhyve_graphics/atkbdc.h
 - copied unchanged from r302324, projects/bhyve_graphics/bhyvegc.c
 - copied unchanged from r302324, projects/bhyve_graphics/bhyvegc.h
 - copied unchanged from r302324, projects/bhyve_graphics/console.c
 - copied unchanged from r302324, projects/bhyve_graphics/console.h
 - copied unchanged from r302324, projects/bhyve_graphics/pci_fbuf.c
 - copied unchanged from r302324, projects/bhyve_graphics/pci_xhci.c
 - copied unchanged from r302324, projects/bhyve_graphics/pci_xhci.h
 - copied unchanged from r302324, projects/bhyve_graphics/ps2kbd.c
 - copied unchanged from r302324, projects/bhyve_graphics/ps2kbd.h
 - copied unchanged from r302324, projects/bhyve_graphics/ps2mouse.c
 - copied unchanged from r302324, projects/bhyve_graphics/ps2mouse.h
 - copied unchanged from r302324, projects/bhyve_graphics/rfb.c
 - copied unchanged from r302324, projects/bhyve_graphics/rfb.h
 - copied unchanged from r302324, projects/bhyve_graphics/sockstream.c
 - copied unchanged from r302324, projects/bhyve_graphics/sockstream.h
 - copied unchanged from r302324, projects/bhyve_graphics/usb_emul.c
 - copied unchanged from r302324, projects/bhyve_graphics/usb_emul.h
 - copied unchanged from r302324, projects/bhyve_graphics/usb_mouse.c
 - copied unchanged from r302324, projects/bhyve_graphics/vga.c
 - copied unchanged from r302324, projects/bhyve_graphics/vga.h
Directory Properties:
  head/usr.sbin/bhyve/atkbdc.h   (props changed)
  head/usr.sbin/bhyve/bhyvegc.c   (props changed)
  head/usr.sbin/bhyve/bhyvegc.h   (props changed)
  head/usr.sbin/bhyve/console.c   (props changed)
  head/usr.sbin/bhyve/console.h   (props changed)
  head/usr.sbin/bhyve/pci_fbuf.c   (props changed)
  head/usr.sbin/bhyve/pci_xhci.c   (props changed)
  head/usr.sbin/bhyve/pci_xhci.h   (props changed)
  head/usr.sbin/bhyve/ps2kbd.c   (props changed)
  head/usr.sbin/bhyve/ps2kbd.h   (props changed)
  head/usr.sbin/bhyve/ps2mouse.c   (props changed)
  head/usr.sbin/bhyve/ps2mouse.h   (props changed)
  head/usr.sbin/bhyve/rfb.c   (props changed)
  head/usr.sbin/bhyve/rfb.h   (props changed)
  head/usr.sbin/bhyve/sockstream.c   (props changed)
  head/usr.sbin/bhyve/sockstream.h   (props changed)
  head/usr.sbin/bhyve/usb_emul.c   (props changed)
  head/usr.sbin/bhyve/usb_emul.h   (props changed)
  head/usr.sbin/bhyve/usb_mouse.c   (props changed)
  head/usr.sbin/bhyve/vga.c   (props changed)
  head/usr.sbin/bhyve/vga.h   (props changed)
Modified:
  head/usr.sbin/bhyve/Makefile
  head/usr.sbin/bhyve/atkbdc.c
  head/usr.sbin/bhyve/bhyverun.c

Modified: head/usr.sbin/bhyve/Makefile
==
--- head/usr.sbin/bhyve/MakefileSun Jul  3 19:31:21 2016
(r302331)
+++ head/usr.sbin/bhyve/MakefileMon Jul  4 03:19:06 2016
(r302332)
@@ -14,9 +14,11 @@ BHYVE_SYSDIR?=${SRCTOP}
 SRCS=  \
atkbdc.c\
acpi.c  \
+   bhyvegc.c   \
bhyverun.c  \
block_if.c  \
bootrom.c   \
+   console.c   \
consport.c  \
dbgport.c   \
fwctl.c \
@@ -27,6 +29,7 @@ SRCS= \
mptbl.c \
pci_ahci.c  \
pci_emul.c  \
+   pci_fbuf.c  \
pci_hostbridge.c\
pci_irq.c   \
pci_lpc.c   \
@@ -35,20 +38,30 @@ SRCS=   \
pci_virtio_net.c\
pci_virtio_rnd.c\
pci_uart.c  \
+   pci_xhci.c  \
   

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

2016-04-20 Thread Peter Grehan
Author: grehan
Date: Wed Apr 20 17:05:32 2016
New Revision: 298355
URL: https://svnweb.freebsd.org/changeset/base/298355

Log:
  Don't use SYSDIR to avoid conflicts with existing usage.
  Also, use SRCTOP to locate the top of the source tree
  instead of a relative path.
  
  PR:   208856

Modified:
  head/usr.sbin/bhyve/Makefile

Modified: head/usr.sbin/bhyve/Makefile
==
--- head/usr.sbin/bhyve/MakefileWed Apr 20 16:19:44 2016
(r298354)
+++ head/usr.sbin/bhyve/MakefileWed Apr 20 17:05:32 2016
(r298355)
@@ -9,7 +9,7 @@ DEBUG_FLAGS= -g -O0
 
 MAN=   bhyve.8
 
-SYSDIR?=${.CURDIR}/../..
+BHYVE_SYSDIR?=${SRCTOP}
 
 SRCS=  \
atkbdc.c\
@@ -45,7 +45,7 @@ SRCS= \
xmsr.c  \
spinup_ap.c
 
-.PATH:  ${SYSDIR}/sys/amd64/vmm
+.PATH:  ${BHYVE_SYSDIR}/sys/amd64/vmm
 SRCS+= vmm_instruction_emul.c
 
 LIBADD=vmmapi md pthread
___
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: r297806 - head/sys/amd64/vmm/amd

2016-04-11 Thread Peter Grehan

Hi Shawn,


Pardon my ignorance, but does that mean that prior to this commit, a
bhyve guest on AMD could modify hardware?


 No. Before this commit, the guest would exit if it attempted to update 
microcode. Now it just ignores the attempt.


later,

Peter.

___
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: r297778 - head/usr.sbin/bhyve

2016-04-09 Thread Peter Grehan
Author: grehan
Date: Sun Apr 10 05:58:19 2016
New Revision: 297778
URL: https://svnweb.freebsd.org/changeset/base/297778

Log:
  Allow the location of the kernel source tree to be overridden.
  This makes it easier for the bhyve executable to be built
  out of the tree.

Modified:
  head/usr.sbin/bhyve/Makefile

Modified: head/usr.sbin/bhyve/Makefile
==
--- head/usr.sbin/bhyve/MakefileSun Apr 10 05:06:58 2016
(r29)
+++ head/usr.sbin/bhyve/MakefileSun Apr 10 05:58:19 2016
(r297778)
@@ -8,6 +8,8 @@ DEBUG_FLAGS= -g -O0
 
 MAN=   bhyve.8
 
+SYSDIR?=${.CURDIR}/../..
+
 SRCS=  \
atkbdc.c\
acpi.c  \
@@ -42,7 +44,7 @@ SRCS= \
xmsr.c  \
spinup_ap.c
 
-.PATH: ${.CURDIR}/../../sys/amd64/vmm
+.PATH:  ${SYSDIR}/sys/amd64/vmm
 SRCS+= vmm_instruction_emul.c
 
 LIBADD=vmmapi md pthread
___
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: r296428 - head/sys/boot/common

2016-03-07 Thread Peter Grehan

Are the CFI directives so that DTRACE works, or is there some other reason?


 It allows gdb to backtrace across exception frames.

later,

Peter.

___
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: r295124 - in stable/10: lib/libvmmapi share/examples/bhyve sys/amd64/include sys/amd64/vmm sys/amd64/vmm/amd sys/amd64/vmm/intel sys/amd64/vmm/io sys/sys usr.sbin/bhyve usr.sbin/bhyvect...

2016-02-01 Thread Peter Grehan
Author: grehan
Date: Mon Feb  1 14:56:11 2016
New Revision: 295124
URL: https://svnweb.freebsd.org/changeset/base/295124

Log:
  MFC r284539, r284630, r284688, r284877, r285217, r285218,
  r286837, r286838, r288470, r288522, r288524, r288826,
  r289001
  
  Pull in bhyve bug fixes and changes to allow UEFI booting.
  This provides Windows support.
  
  Tested on Intel and AMD with:
- Arch Linux i386+amd64 (kernel 4.3.3)
- Ubuntu 15.10 server 64-bit
- FreeBSD-CURRENT/amd64 20160127 snap
- FreeBSD 10.2 i386+amd64
- OpenBSD 5.8 i386+amd64
- SmartOS latest
- Windows 10 build 1511'
  
  Huge thanks to Yamagi Burmeister who submitted the patch
  and did the majority of the testing.
  
  r284539 - bootrom mem allocation support
  r284630 - Add SO_REUSEADDR when starting debug port
  r284688 - Fix a regression in "movs" emulation
  r284877 - verify_gla() non-zero segment base fix
  r285217 - Always assert DCD and DSR in the uart
  r285218 - devmem nodes moved to /dev/vmm.io/
  r286837 - Add define for SATA Check-Power-Mode
  r286838 - Add simple (no-op) SATA cmd emulations
  r288470 - Increase virtio-blk indirect descs
  r288522 - Firmware guest query interface
  r288524 - Fix post-test typo
  r288826 - Clean up SATA unimplemented cmd msg
  r289001 - Add -l option to specify userboot path
  
  Submitted by: Yamagi Burmeister
  Approved by:  re (kib)

Added:
  stable/10/usr.sbin/bhyve/bootrom.c
 - copied unchanged from r284539, head/usr.sbin/bhyve/bootrom.c
  stable/10/usr.sbin/bhyve/bootrom.h
 - copied unchanged from r284539, head/usr.sbin/bhyve/bootrom.h
  stable/10/usr.sbin/bhyve/fwctl.c
 - copied, changed from r288522, head/usr.sbin/bhyve/fwctl.c
  stable/10/usr.sbin/bhyve/fwctl.h
 - copied unchanged from r288522, head/usr.sbin/bhyve/fwctl.h
Modified:
  stable/10/lib/libvmmapi/vmmapi.c
  stable/10/lib/libvmmapi/vmmapi.h
  stable/10/share/examples/bhyve/vmrun.sh
  stable/10/sys/amd64/include/vmm.h
  stable/10/sys/amd64/include/vmm_dev.h
  stable/10/sys/amd64/vmm/amd/svm.c
  stable/10/sys/amd64/vmm/intel/vmx.c
  stable/10/sys/amd64/vmm/io/ppt.c
  stable/10/sys/amd64/vmm/vmm.c
  stable/10/sys/amd64/vmm/vmm_dev.c
  stable/10/sys/amd64/vmm/vmm_instruction_emul.c
  stable/10/sys/amd64/vmm/vmm_mem.c
  stable/10/sys/amd64/vmm/vmm_mem.h
  stable/10/sys/sys/ata.h
  stable/10/usr.sbin/bhyve/Makefile
  stable/10/usr.sbin/bhyve/bhyve.8
  stable/10/usr.sbin/bhyve/bhyverun.c
  stable/10/usr.sbin/bhyve/dbgport.c
  stable/10/usr.sbin/bhyve/pci_ahci.c
  stable/10/usr.sbin/bhyve/pci_lpc.c
  stable/10/usr.sbin/bhyve/pci_lpc.h
  stable/10/usr.sbin/bhyve/pci_passthru.c
  stable/10/usr.sbin/bhyve/pci_virtio_net.c
  stable/10/usr.sbin/bhyve/uart_emul.c
  stable/10/usr.sbin/bhyvectl/bhyvectl.c
  stable/10/usr.sbin/bhyveload/bhyveload.8
  stable/10/usr.sbin/bhyveload/bhyveload.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libvmmapi/vmmapi.c
==
--- stable/10/lib/libvmmapi/vmmapi.cMon Feb  1 14:28:58 2016
(r295123)
+++ stable/10/lib/libvmmapi/vmmapi.cMon Feb  1 14:56:11 2016
(r295124)
@@ -58,15 +58,23 @@ __FBSDID("$FreeBSD$");
 #defineMB  (1024 * 1024UL)
 #defineGB  (1024 * 1024 * 1024UL)
 
+/*
+ * Size of the guard region before and after the virtual address space
+ * mapping the guest physical memory. This must be a multiple of the
+ * superpage size for performance reasons.
+ */
+#defineVM_MMAP_GUARD_SIZE  (4 * MB)
+
+#definePROT_RW (PROT_READ | PROT_WRITE)
+#definePROT_ALL(PROT_READ | PROT_WRITE | PROT_EXEC)
+
 struct vmctx {
int fd;
uint32_t lowmem_limit;
-   enum vm_mmap_style vms;
int memflags;
size_t  lowmem;
-   char*lowmem_addr;
size_t  highmem;
-   char*highmem_addr;
+   char*baseaddr;
char*name;
 };
 
@@ -157,22 +165,6 @@ vm_parse_memsize(const char *optarg, siz
return (error);
 }
 
-int
-vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len,
- int *wired)
-{
-   int error;
-   struct vm_memory_segment seg;
-
-   bzero(, sizeof(seg));
-   seg.gpa = gpa;
-   error = ioctl(ctx->fd, VM_GET_MEMORY_SEG, );
-   *ret_len = seg.len;
-   if (wired != NULL)
-   *wired = seg.wired;
-   return (error);
-}
-
 uint32_t
 vm_get_lowmem_limit(struct vmctx *ctx)
 {
@@ -194,39 +186,184 @@ vm_set_memflags(struct vmctx *ctx, int f
ctx->memflags = flags;
 }
 
+int
+vm_get_memflags(struct vmctx *ctx)
+{
+
+   return (ctx->memflags);
+}
+
+/*
+ * Map segment 'segid' starting at 'off' into guest address range 
[gpa,gpa+len).
+ */
+int
+vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, int segid, vm_ooffset_t off,
+size_t len, int prot)
+{
+   struct vm_memmap memmap;
+   int error, flags;
+
+   memmap.gpa 

svn commit: r295084 - svnadmin/conf

2016-01-30 Thread Peter Grehan
Author: grehan
Date: Sat Jan 30 20:48:45 2016
New Revision: 295084
URL: https://svnweb.freebsd.org/changeset/base/295084

Log:
  Welcome Anish Gupta (anish) as a new src committer. Anish added
  support for AMD/SVM processors to bhyve and will be continuing
  to work on that along with new features such as IOMMU support
  for AMD.
  
  neel@ and I will be mentoring him.
  
  Approved by:  core

Modified:
  svnadmin/conf/access
  svnadmin/conf/mentors

Modified: svnadmin/conf/access
==
--- svnadmin/conf/accessSat Jan 30 20:10:20 2016(r295083)
+++ svnadmin/conf/accessSat Jan 30 20:48:45 2016(r295084)
@@ -30,6 +30,7 @@ ambrisko
 andre
 andreast
 andrew
+anish
 antoine
 araujo
 arybchik

Modified: svnadmin/conf/mentors
==
--- svnadmin/conf/mentors   Sat Jan 30 20:10:20 2016(r295083)
+++ svnadmin/conf/mentors   Sat Jan 30 20:48:45 2016(r295084)
@@ -11,6 +11,7 @@
 
 # Mentee   Mentor  Optional comment
 achim  scottl  Co-mentor: emaste
+anish  neelCo-mentor: grehan
 agcscottl  Co-mentor: emax
 araujo baptCo-mentor: rodrigc
 avos   adrian
___
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: r292061 - head

2015-12-10 Thread Peter Grehan
Author: grehan
Date: Thu Dec 10 12:12:47 2015
New Revision: 292061
URL: https://svnweb.freebsd.org/changeset/base/292061

Log:
  vmm is still maintained.

Modified:
  head/MAINTAINERS

Modified: head/MAINTAINERS
==
--- head/MAINTAINERSThu Dec 10 11:49:32 2015(r292060)
+++ head/MAINTAINERSThu Dec 10 12:12:47 2015(r292061)
@@ -77,6 +77,7 @@ usr.sbin/pkg  pkg@Please coordinate beha
 lprgad Pre-commit review requested, particularly for
lpd/recvjob.c and lpd/printjob.c.
 nis(8), yp(8)  araujo  Pre-commit review requested.
+vmm(4) neel,grehan Pre-commit review requested.
  OLD 
 libc/posix1e   rwatson Pre-commit review requested.
 POSIX.1e ACLs  rwatson Pre-commit review requested.
@@ -156,4 +157,4 @@ cmx dan...@roe.ch   Pre-commit review pre
 filemonobrien  Pre-commit review preferred.
 sysdoc trhodes Pre-commit review preferred.
 nanobsdimp Pre-commit review requested for coordination.
-vmm(4) neel,grehan Pre-commit review requested.
+
___
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: r288826 - head/usr.sbin/bhyve

2015-10-05 Thread Peter Grehan
Author: grehan
Date: Mon Oct  5 14:57:45 2015
New Revision: 288826
URL: https://svnweb.freebsd.org/changeset/base/288826

Log:
  Clean up some harmless unimplemented-command warning messages.
  
  - Don't advertize trusted-computing capability in the Identify page.
This prevents Windows from issuing a TRUSTED_RECEIVE_DMA command.
  - Windows will send down SMART and SECURITY_FREEZE_LOCK
 even though smart and security capabilities were not advertized.
 Send back a silent abort.
  
  Reviewed by:  mav

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Mon Oct  5 13:33:02 2015
(r288825)
+++ head/usr.sbin/bhyve/pci_ahci.c  Mon Oct  5 14:57:45 2015
(r288826)
@@ -926,7 +926,7 @@ handle_identify(struct ahci_port *p, int
ata_string((uint8_t *)(buf+23), "001", 8);
ata_string((uint8_t *)(buf+27), "BHYVE SATA DISK", 40);
buf[47] = (0x8000 | 128);
-   buf[48] = 0x1;
+   buf[48] = 0;
buf[49] = (1 << 8 | 1 << 9 | 1 << 11);
buf[50] = (1 << 14);
buf[53] = (1 << 1 | 1 << 2);
@@ -1683,6 +1683,8 @@ ahci_handle_cmd(struct ahci_port *p, int
case ATA_READ_LOG_DMA_EXT:
ahci_handle_read_log(p, slot, cfis);
break;
+   case ATA_SECURITY_FREEZE_LOCK:
+   case ATA_SMART_CMD:
case ATA_NOP:
ahci_write_fis_d2h(p, slot, cfis,
(ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


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

2015-10-02 Thread Peter Grehan
Author: grehan
Date: Fri Oct  2 22:05:51 2015
New Revision: 288524
URL: https://svnweb.freebsd.org/changeset/base/288524

Log:
  Fix post-test typo that snuck in.

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

Modified: head/usr.sbin/bhyve/fwctl.c
==
--- head/usr.sbin/bhyve/fwctl.c Fri Oct  2 21:25:48 2015(r288523)
+++ head/usr.sbin/bhyve/fwctl.c Fri Oct  2 22:05:51 2015(r288524)
@@ -536,7 +536,7 @@ fwctl_handler(struct vmctx *ctx, int vcp
return (0);
 }
 INOUT_PORT(fwctl_wreg, FWCTL_OUT, IOPORT_F_INOUT, fwctl_handler);
-INOUT_PORT(fwctl_rreg, FWCTL_IN,  IOPORT_F_OUT,   fwctl_handler);
+INOUT_PORT(fwctl_rreg, FWCTL_IN,  IOPORT_F_IN,fwctl_handler);
 
 void
 fwctl_init(void)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


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

2015-10-02 Thread Peter Grehan
Author: grehan
Date: Fri Oct  2 21:09:49 2015
New Revision: 288522
URL: https://svnweb.freebsd.org/changeset/base/288522

Log:
  Simple sysctl-like firmware query interface. Similar in operation
  to the qemu one, and uses the same i/o ports but with different
  messaging. Requires the 'bootrom' option to be enabled.
  
  This is used by UEFI (and potentially other BIOSs/firmware) to
  request information from bhyve. Currently, only the number of
  vCPUs is made available, with more to follow.
  
  A very large thankyou to Ben Perrault who helped out testing
  an earlier version of this, and bhyve/Windows in general.
  
  Reviewed by:  tychon
  Discussed with:   neel
  Sponsored by: Nahanni Systems

Added:
  head/usr.sbin/bhyve/fwctl.c   (contents, props changed)
  head/usr.sbin/bhyve/fwctl.h   (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 Oct  2 20:13:56 2015
(r288521)
+++ head/usr.sbin/bhyve/MakefileFri Oct  2 21:09:49 2015
(r288522)
@@ -16,6 +16,7 @@ SRCS= \
bootrom.c   \
consport.c  \
dbgport.c   \
+   fwctl.c \
inout.c \
ioapic.c\
mem.c   \

Modified: head/usr.sbin/bhyve/bhyverun.c
==
--- head/usr.sbin/bhyve/bhyverun.c  Fri Oct  2 20:13:56 2015
(r288521)
+++ head/usr.sbin/bhyve/bhyverun.c  Fri Oct  2 21:09:49 2015
(r288522)
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
 #include "acpi.h"
 #include "inout.h"
 #include "dbgport.h"
+#include "fwctl.h"
 #include "ioapic.h"
 #include "mem.h"
 #include "mevent.h"
@@ -950,6 +951,9 @@ main(int argc, char *argv[])
assert(error == 0);
}
 
+   if (lpc_bootrom())
+   fwctl_init();
+
/*
 * Change the proc title to include the VM name.
 */

Added: head/usr.sbin/bhyve/fwctl.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/bhyve/fwctl.c Fri Oct  2 21:09:49 2015(r288522)
@@ -0,0 +1,549 @@
+/*-
+ * Copyright (c) 2015  Peter Grehan <gre...@freebsd.org>
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Guest firmware interface. Uses i/o ports x510/x511 as Qemu does,
+ * but with a request/response messaging protocol.
+ */
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "bhyverun.h"
+#include "inout.h"
+#include "fwctl.h"
+
+/*
+ * Messaging protocol base operations
+ */
+#defineOP_NULL 1
+#defineOP_ECHO 2
+#defineOP_GET  3
+#defineOP_GET_LEN  4
+#defineOP_SET  5
+#defineOP_MAX  OP_SET
+
+/* I/O ports */
+#defineFWCTL_OUT   0x510
+#defineFWCTL_IN0x511
+
+/*
+ * Back-end state-machine
+ */
+enum state {
+   DORMANT,
+   IDENT_WAIT,
+   IDENT_SEND,
+   REQ,
+   RESP
+} be_state = DORMANT;
+
+static uint8_t sig[] = { 'B', 'H', 'Y', 'V' };
+static u_int ident_idx;
+
+struct op_info {
+   int op;
+   int  (*op_start)(int len);
+   void (*op_data)(uint32_t data, int len)

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

2015-10-01 Thread Peter Grehan
Author: grehan
Date: Fri Oct  2 02:09:50 2015
New Revision: 288470
URL: https://svnweb.freebsd.org/changeset/base/288470

Log:
  - Increase the max number of indirect descriptors to match
the largest that the Windows virtio driver can send down
  
  - Always advertize indirect descriptors. The Illumos virtio
driver won't attach unless this capability is seen.
  
  Reviewed by:  neel

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

Modified: head/usr.sbin/bhyve/pci_virtio_net.c
==
--- head/usr.sbin/bhyve/pci_virtio_net.cFri Oct  2 02:08:40 2015
(r288469)
+++ head/usr.sbin/bhyve/pci_virtio_net.cFri Oct  2 02:09:50 2015
(r288470)
@@ -57,7 +57,7 @@ __FBSDID("$FreeBSD$");
 
 #define VTNET_RINGSZ   1024
 
-#define VTNET_MAXSEGS  32
+#define VTNET_MAXSEGS  256
 
 /*
  * Host capabilities.  Note that we only offer a few of these.
@@ -84,7 +84,7 @@ __FBSDID("$FreeBSD$");
 
 #define VTNET_S_HOSTCAPS  \
   ( VIRTIO_NET_F_MAC | VIRTIO_NET_F_MRG_RXBUF | VIRTIO_NET_F_STATUS | \
-VIRTIO_F_NOTIFY_ON_EMPTY)
+VIRTIO_F_NOTIFY_ON_EMPTY | VIRTIO_RING_F_INDIRECT_DESC)
 
 /*
  * PCI config-space "registers"
___
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: r286838 - head/usr.sbin/bhyve

2015-08-17 Thread Peter Grehan
Author: grehan
Date: Mon Aug 17 05:59:36 2015
New Revision: 286838
URL: https://svnweb.freebsd.org/changeset/base/286838

Log:
  Add simple (no-op) emulations for the CHECK_POWER_MODE,
  READ_VERIFY and READ_VERIFY_EXT commands.
  
  Reviewed by:  mav

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==
--- head/usr.sbin/bhyve/pci_ahci.c  Mon Aug 17 05:56:41 2015
(r286837)
+++ head/usr.sbin/bhyve/pci_ahci.c  Mon Aug 17 05:59:36 2015
(r286838)
@@ -1687,11 +1687,17 @@ ahci_handle_cmd(struct ahci_port *p, int
ahci_write_fis_d2h(p, slot, cfis,
(ATA_E_ABORT  8) | ATA_S_READY | ATA_S_ERROR);
break;
+   case ATA_CHECK_POWER_MODE:
+   cfis[12] = 0xff;/* always on */
+   ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);
+   break;
case ATA_STANDBY_CMD:
case ATA_STANDBY_IMMEDIATE:
case ATA_IDLE_CMD:
case ATA_IDLE_IMMEDIATE:
case ATA_SLEEP:
+   case ATA_READ_VERIFY:
+   case ATA_READ_VERIFY48:
ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);
break;
case ATA_ATAPI_IDENTIFY:
___
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: r286837 - head/sys/sys

2015-08-16 Thread Peter Grehan
Author: grehan
Date: Mon Aug 17 05:56:41 2015
New Revision: 286837
URL: https://svnweb.freebsd.org/changeset/base/286837

Log:
  Add define for SATA Check-Power-Mode command, 0xe5.

Modified:
  head/sys/sys/ata.h

Modified: head/sys/sys/ata.h
==
--- head/sys/sys/ata.h  Mon Aug 17 05:53:37 2015(r286836)
+++ head/sys/sys/ata.h  Mon Aug 17 05:56:41 2015(r286837)
@@ -399,6 +399,7 @@ struct ata_params {
 #define ATA_IDLE_CMD0xe3/* idle */
 #define ATA_READ_BUFFER 0xe4/* read buffer */
 #define ATA_READ_PM 0xe4/* read portmultiplier */
+#define ATA_CHECK_POWER_MODE0xe5/* device power mode */
 #define ATA_SLEEP   0xe6/* sleep */
 #define ATA_FLUSHCACHE  0xe7/* flush cache to disk */
 #define ATA_WRITE_PM0xe8/* write portmultiplier */
___
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: r285217 - head/usr.sbin/bhyve

2015-07-06 Thread Peter Grehan

This seems like a wrong fix.  A real 3-wire serial console doesn't have
DCD and DSR wired on.  Why isn't the right fix here having the user with
this problem to do stty -f /dev/ttyu0.lock clocal, maybe in rc.local?

Hmmm, or maybe it would be right for getty to do the equivelent when it
sees a 3wire type?


 Sure, but this will do until that's available.

later,

Peter.

___
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


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

2015-07-06 Thread Peter Grehan

Ok, so I just tested on real hardware, and something is wrong w/
FreeBSD's behavior...  Could this be a change between 10 and HEAD?


 uart_tty.c r264175 wasn't MFC'd - see UPDATING, 20140405 for the details.

later,

Peter.

___
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


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

2015-07-06 Thread Peter Grehan

Though there is a question is why DCD isn't assert by bhyve when
there is a session attached to the console...


 Modem signal policy wasn't implemented. The workaround now is that DCD
is permanently asserted, but at some point when a proper terminal 
backend is in place, the signal policy would be pushed out to there.


later,

Peter.
___
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: r283168 - head/usr.sbin/bhyve

2015-05-20 Thread Peter Grehan
Author: grehan
Date: Thu May 21 04:19:22 2015
New Revision: 283168
URL: https://svnweb.freebsd.org/changeset/base/283168

Log:
  Temporarily revert r282922 which bumped the max descriptors.
  
  While there is no issued with the number of descriptors in
  a virtio indirect descriptor, it's a guest's choice as to
  whether indirect descriptors are used. For the case where
  they aren't, the virtio block ring size is still 64 which
  is less than the now reported max_segs of 67. This results
  in an assertion in recent Linux guests even though it was
  benign since they were using indirect descs.
  
  The intertwined relationship between virtio ring size,
  max seg size and blockif queue size will be addressed
  in an upcoming commit, at which point the max descriptors
  will again be bumped up to 67.

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

Modified: head/usr.sbin/bhyve/block_if.h
==
--- head/usr.sbin/bhyve/block_if.h  Thu May 21 03:32:44 2015
(r283167)
+++ head/usr.sbin/bhyve/block_if.h  Thu May 21 04:19:22 2015
(r283168)
@@ -39,7 +39,7 @@
 #include sys/uio.h
 #include sys/unistd.h
 
-#define BLOCKIF_IOV_MAX67  /* not practical to be IOV_MAX 
*/
+#define BLOCKIF_IOV_MAX33  /* not practical to be IOV_MAX 
*/
 
 struct blockif_req {
struct iovecbr_iov[BLOCKIF_IOV_MAX];
___
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


  1   2   3   >