Print this page
13275 bhyve needs richer INIT/SIPI support
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Gordon Ross <gordon.w.ross@gmail.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libvmmapi/common/vmmapi.c
          +++ new/usr/src/lib/libvmmapi/common/vmmapi.c
↓ open down ↓ 1294 lines elided ↑ open up ↑
1295 1295  
1296 1296          bzero(&x2apic, sizeof(x2apic));
1297 1297          x2apic.cpuid = vcpu;
1298 1298          x2apic.state = state;
1299 1299  
1300 1300          error = ioctl(ctx->fd, VM_SET_X2APIC_STATE, &x2apic);
1301 1301  
1302 1302          return (error);
1303 1303  }
1304 1304  
     1305 +#ifndef __FreeBSD__
     1306 +int
     1307 +vcpu_reset(struct vmctx *vmctx, int vcpu)
     1308 +{
     1309 +        struct vm_vcpu_reset vvr;
     1310 +
     1311 +        vvr.vcpuid = vcpu;
     1312 +        vvr.kind = VRK_RESET;
     1313 +
     1314 +        return (ioctl(vmctx->fd, VM_RESET_CPU, &vvr));
     1315 +}
     1316 +#else /* __FreeBSD__ */
1305 1317  /*
1306 1318   * From Intel Vol 3a:
1307 1319   * Table 9-1. IA-32 Processor States Following Power-up, Reset or INIT
1308 1320   */
1309 1321  int
1310 1322  vcpu_reset(struct vmctx *vmctx, int vcpu)
1311 1323  {
1312 1324          int error;
1313 1325          uint64_t rflags, rip, cr0, cr4, zero, desc_base, rdx;
1314 1326          uint32_t desc_access, desc_limit;
↓ open down ↓ 136 lines elided ↑ open up ↑
1451 1463          sel = 0;
1452 1464          if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, 0)) != 0)
1453 1465                  goto done;
1454 1466  
1455 1467          /* XXX cr2, debug registers */
1456 1468  
1457 1469          error = 0;
1458 1470  done:
1459 1471          return (error);
1460 1472  }
     1473 +#endif /* __FreeBSD__ */
1461 1474  
1462 1475  int
1463 1476  vm_get_gpa_pmap(struct vmctx *ctx, uint64_t gpa, uint64_t *pte, int *num)
1464 1477  {
1465 1478          int error, i;
1466 1479          struct vm_gpa_pte gpapte;
1467 1480  
1468 1481          bzero(&gpapte, sizeof(gpapte));
1469 1482          gpapte.gpa = gpa;
1470 1483  
↓ open down ↓ 361 lines elided ↑ open up ↑
1832 1845  }
1833 1846  
1834 1847  int
1835 1848  vm_wrlock_cycle(struct vmctx *ctx)
1836 1849  {
1837 1850          if (ioctl(ctx->fd, VM_WRLOCK_CYCLE, 0) != 0) {
1838 1851                  return (errno);
1839 1852          }
1840 1853          return (0);
1841 1854  }
     1855 +
     1856 +int
     1857 +vm_get_run_state(struct vmctx *ctx, int vcpu, enum vcpu_run_state *state,
     1858 +    uint8_t *sipi_vector)
     1859 +{
     1860 +        struct vm_run_state data;
     1861 +
     1862 +        data.vcpuid = vcpu;
     1863 +        if (ioctl(ctx->fd, VM_GET_RUN_STATE, &data) != 0) {
     1864 +                return (errno);
     1865 +        }
     1866 +
     1867 +        *state = data.state;
     1868 +        *sipi_vector = data.sipi_vector;
     1869 +        return (0);
     1870 +}
     1871 +
     1872 +int
     1873 +vm_set_run_state(struct vmctx *ctx, int vcpu, enum vcpu_run_state state,
     1874 +    uint8_t sipi_vector)
     1875 +{
     1876 +        struct vm_run_state data;
     1877 +
     1878 +        data.vcpuid = vcpu;
     1879 +        data.state = state;
     1880 +        data.sipi_vector = sipi_vector;
     1881 +        if (ioctl(ctx->fd, VM_SET_RUN_STATE, &data) != 0) {
     1882 +                return (errno);
     1883 +        }
     1884 +
     1885 +        return (0);
     1886 +}
     1887 +
1842 1888  #endif /* __FreeBSD__ */
1843 1889  
1844 1890  #ifdef __FreeBSD__
1845 1891  const cap_ioctl_t *
1846 1892  vm_get_ioctls(size_t *len)
1847 1893  {
1848 1894          cap_ioctl_t *cmds;
1849 1895          /* keep in sync with machine/vmm_dev.h */
1850 1896          static const cap_ioctl_t vm_ioctl_cmds[] = { VM_RUN, VM_SUSPEND, VM_REINIT,
1851 1897              VM_ALLOC_MEMSEG, VM_GET_MEMSEG, VM_MMAP_MEMSEG, VM_MMAP_MEMSEG,
↓ open down ↓ 31 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX