Deleted Added
full compact
bhyvectl.c (273375) bhyvectl.c (276428)
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/bhyvectl/bhyvectl.c 273375 2014-10-21 07:10:43Z neel $
26 * $FreeBSD: head/usr.sbin/bhyvectl/bhyvectl.c 276428 2014-12-30 22:19:34Z neel $
27 */
28
29#include <sys/cdefs.h>
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/usr.sbin/bhyvectl/bhyvectl.c 273375 2014-10-21 07:10:43Z neel $");
30__FBSDID("$FreeBSD: head/usr.sbin/bhyvectl/bhyvectl.c 276428 2014-12-30 22:19:34Z neel $");
31
32#include <sys/param.h>
33#include <sys/types.h>
34#include <sys/sysctl.h>
35#include <sys/errno.h>
36#include <sys/mman.h>
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <stdbool.h>
41#include <string.h>
42#include <unistd.h>
43#include <libgen.h>
44#include <libutil.h>
45#include <fcntl.h>
46#include <string.h>
47#include <getopt.h>
31
32#include <sys/param.h>
33#include <sys/types.h>
34#include <sys/sysctl.h>
35#include <sys/errno.h>
36#include <sys/mman.h>
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <stdbool.h>
41#include <string.h>
42#include <unistd.h>
43#include <libgen.h>
44#include <libutil.h>
45#include <fcntl.h>
46#include <string.h>
47#include <getopt.h>
48#include <time.h>
48#include <assert.h>
49
50#include <machine/cpufunc.h>
51#include <machine/vmm.h>
52#include <machine/specialreg.h>
53#include <vmmapi.h>
54
55#include "amd/vmcb.h"

--- 96 unchanged lines hidden (view full) ---

152 " [--set-mem=<memory in units of MB>]\n"
153 " [--get-lowmem]\n"
154 " [--get-highmem]\n"
155 " [--get-gpa-pmap]\n"
156 " [--assert-lapic-lvt=<pin>]\n"
157 " [--inject-nmi]\n"
158 " [--force-reset]\n"
159 " [--force-poweroff]\n"
49#include <assert.h>
50
51#include <machine/cpufunc.h>
52#include <machine/vmm.h>
53#include <machine/specialreg.h>
54#include <vmmapi.h>
55
56#include "amd/vmcb.h"

--- 96 unchanged lines hidden (view full) ---

153 " [--set-mem=<memory in units of MB>]\n"
154 " [--get-lowmem]\n"
155 " [--get-highmem]\n"
156 " [--get-gpa-pmap]\n"
157 " [--assert-lapic-lvt=<pin>]\n"
158 " [--inject-nmi]\n"
159 " [--force-reset]\n"
160 " [--force-poweroff]\n"
161 " [--get-rtc-time]\n"
162 " [--set-rtc-time=<secs>]\n"
163 " [--get-rtc-nvram]\n"
164 " [--set-rtc-nvram=<val>]\n"
165 " [--rtc-nvram-offset=<offset>]\n"
160 " [--get-active-cpus]\n"
161 " [--get-suspended-cpus]\n"
162 " [--get-intinfo]\n"
163 " [--get-eptp]\n"
164 " [--set-exception-bitmap]\n"
165 " [--get-exception-bitmap]\n"
166 " [--get-tsc-offset]\n"
167 " [--get-guest-pat]\n"

--- 47 unchanged lines hidden (view full) ---

215 " [--get-avic-apic-bar]\n"
216 " [--get-avic-backing-page]\n"
217 " [--get-avic-table]\n"
218 );
219 }
220 exit(1);
221}
222
166 " [--get-active-cpus]\n"
167 " [--get-suspended-cpus]\n"
168 " [--get-intinfo]\n"
169 " [--get-eptp]\n"
170 " [--set-exception-bitmap]\n"
171 " [--get-exception-bitmap]\n"
172 " [--get-tsc-offset]\n"
173 " [--get-guest-pat]\n"

--- 47 unchanged lines hidden (view full) ---

221 " [--get-avic-apic-bar]\n"
222 " [--get-avic-backing-page]\n"
223 " [--get-avic-table]\n"
224 );
225 }
226 exit(1);
227}
228
229static int get_rtc_time, set_rtc_time;
230static int get_rtc_nvram, set_rtc_nvram;
231static int rtc_nvram_offset;
232static uint8_t rtc_nvram_value;
233static time_t rtc_secs;
234
223static int get_stats, getcap, setcap, capval, get_gpa_pmap;
224static int inject_nmi, assert_lapic_lvt;
225static int force_reset, force_poweroff;
226static const char *capname;
227static int create, destroy, get_lowmem, get_highmem;
228static int get_intinfo;
229static int get_active_cpus, get_suspended_cpus;
230static uint64_t memsize;

--- 309 unchanged lines hidden (view full) ---

540 SET_X2APIC_STATE,
541 SET_EXCEPTION_BITMAP,
542 SET_VMCS_ENTRY_INTERRUPTION_INFO,
543 SET_CAP,
544 CAPNAME,
545 UNASSIGN_PPTDEV,
546 GET_GPA_PMAP,
547 ASSERT_LAPIC_LVT,
235static int get_stats, getcap, setcap, capval, get_gpa_pmap;
236static int inject_nmi, assert_lapic_lvt;
237static int force_reset, force_poweroff;
238static const char *capname;
239static int create, destroy, get_lowmem, get_highmem;
240static int get_intinfo;
241static int get_active_cpus, get_suspended_cpus;
242static uint64_t memsize;

--- 309 unchanged lines hidden (view full) ---

552 SET_X2APIC_STATE,
553 SET_EXCEPTION_BITMAP,
554 SET_VMCS_ENTRY_INTERRUPTION_INFO,
555 SET_CAP,
556 CAPNAME,
557 UNASSIGN_PPTDEV,
558 GET_GPA_PMAP,
559 ASSERT_LAPIC_LVT,
560 SET_RTC_TIME,
561 SET_RTC_NVRAM,
562 RTC_NVRAM_OFFSET,
548};
549
550static void
551print_cpus(const char *banner, const cpuset_t *cpus)
552{
553 int i, first;
554
555 first = 1;

--- 708 unchanged lines hidden (view full) ---

1264 { "set-x2apic-state",REQ_ARG, 0, SET_X2APIC_STATE },
1265 { "set-exception-bitmap",
1266 REQ_ARG, 0, SET_EXCEPTION_BITMAP },
1267 { "capname", REQ_ARG, 0, CAPNAME },
1268 { "unassign-pptdev", REQ_ARG, 0, UNASSIGN_PPTDEV },
1269 { "setcap", REQ_ARG, 0, SET_CAP },
1270 { "get-gpa-pmap", REQ_ARG, 0, GET_GPA_PMAP },
1271 { "assert-lapic-lvt", REQ_ARG, 0, ASSERT_LAPIC_LVT },
563};
564
565static void
566print_cpus(const char *banner, const cpuset_t *cpus)
567{
568 int i, first;
569
570 first = 1;

--- 708 unchanged lines hidden (view full) ---

1279 { "set-x2apic-state",REQ_ARG, 0, SET_X2APIC_STATE },
1280 { "set-exception-bitmap",
1281 REQ_ARG, 0, SET_EXCEPTION_BITMAP },
1282 { "capname", REQ_ARG, 0, CAPNAME },
1283 { "unassign-pptdev", REQ_ARG, 0, UNASSIGN_PPTDEV },
1284 { "setcap", REQ_ARG, 0, SET_CAP },
1285 { "get-gpa-pmap", REQ_ARG, 0, GET_GPA_PMAP },
1286 { "assert-lapic-lvt", REQ_ARG, 0, ASSERT_LAPIC_LVT },
1287 { "get-rtc-time", NO_ARG, &get_rtc_time, 1 },
1288 { "set-rtc-time", REQ_ARG, 0, SET_RTC_TIME },
1289 { "rtc-nvram-offset", REQ_ARG, 0, RTC_NVRAM_OFFSET },
1290 { "get-rtc-nvram", NO_ARG, &get_rtc_nvram, 1 },
1291 { "set-rtc-nvram", REQ_ARG, 0, SET_RTC_NVRAM },
1272 { "getcap", NO_ARG, &getcap, 1 },
1273 { "get-stats", NO_ARG, &get_stats, 1 },
1274 { "get-desc-ds",NO_ARG, &get_desc_ds, 1 },
1275 { "set-desc-ds",NO_ARG, &set_desc_ds, 1 },
1276 { "get-desc-es",NO_ARG, &get_desc_es, 1 },
1277 { "set-desc-es",NO_ARG, &set_desc_es, 1 },
1278 { "get-desc-ss",NO_ARG, &get_desc_ss, 1 },
1279 { "set-desc-ss",NO_ARG, &set_desc_ss, 1 },

--- 177 unchanged lines hidden (view full) ---

1457 }
1458
1459 memcpy(cp, &null_opt, sizeof(null_opt));
1460 cp += sizeof(null_opt);
1461
1462 return (all_opts);
1463}
1464
1292 { "getcap", NO_ARG, &getcap, 1 },
1293 { "get-stats", NO_ARG, &get_stats, 1 },
1294 { "get-desc-ds",NO_ARG, &get_desc_ds, 1 },
1295 { "set-desc-ds",NO_ARG, &set_desc_ds, 1 },
1296 { "get-desc-es",NO_ARG, &get_desc_es, 1 },
1297 { "set-desc-es",NO_ARG, &set_desc_es, 1 },
1298 { "get-desc-ss",NO_ARG, &get_desc_ss, 1 },
1299 { "set-desc-ss",NO_ARG, &set_desc_ss, 1 },

--- 177 unchanged lines hidden (view full) ---

1477 }
1478
1479 memcpy(cp, &null_opt, sizeof(null_opt));
1480 cp += sizeof(null_opt);
1481
1482 return (all_opts);
1483}
1484
1485static const char *
1486wday_str(int idx)
1487{
1488 static const char *weekdays[] = {
1489 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
1490 };
1491
1492 if (idx >= 0 && idx < 7)
1493 return (weekdays[idx]);
1494 else
1495 return ("UNK");
1496}
1497
1498static const char *
1499mon_str(int idx)
1500{
1501 static const char *months[] = {
1502 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1503 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
1504 };
1505
1506 if (idx >= 0 && idx < 12)
1507 return (months[idx]);
1508 else
1509 return ("UNK");
1510}
1511
1465int
1466main(int argc, char *argv[])
1467{
1468 char *vmname;
1469 int error, ch, vcpu, ptenum;
1470 vm_paddr_t gpa, gpa_pmap;
1471 size_t len;
1472 struct vm_exit vmexit;
1473 uint64_t rax, cr0, cr3, cr4, dr7, rsp, rip, rflags, efer, pat;
1474 uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2];
1475 struct vmctx *ctx;
1476 int wired;
1477 cpuset_t cpus;
1478 bool cpu_intel;
1479 uint64_t cs, ds, es, fs, gs, ss, tr, ldtr;
1512int
1513main(int argc, char *argv[])
1514{
1515 char *vmname;
1516 int error, ch, vcpu, ptenum;
1517 vm_paddr_t gpa, gpa_pmap;
1518 size_t len;
1519 struct vm_exit vmexit;
1520 uint64_t rax, cr0, cr3, cr4, dr7, rsp, rip, rflags, efer, pat;
1521 uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2];
1522 struct vmctx *ctx;
1523 int wired;
1524 cpuset_t cpus;
1525 bool cpu_intel;
1526 uint64_t cs, ds, es, fs, gs, ss, tr, ldtr;
1527 struct tm tm;
1480 struct option *opts;
1481
1482 cpu_intel = cpu_vendor_intel();
1483 opts = setup_options(cpu_intel);
1484
1485 vcpu = 0;
1486 vmname = NULL;
1487 assert_lapic_lvt = -1;

--- 101 unchanged lines hidden (view full) ---

1589 case SET_VMCS_ENTRY_INTERRUPTION_INFO:
1590 vmcs_entry_interruption_info = strtoul(optarg, NULL, 0);
1591 set_vmcs_entry_interruption_info = 1;
1592 break;
1593 case SET_CAP:
1594 capval = strtoul(optarg, NULL, 0);
1595 setcap = 1;
1596 break;
1528 struct option *opts;
1529
1530 cpu_intel = cpu_vendor_intel();
1531 opts = setup_options(cpu_intel);
1532
1533 vcpu = 0;
1534 vmname = NULL;
1535 assert_lapic_lvt = -1;

--- 101 unchanged lines hidden (view full) ---

1637 case SET_VMCS_ENTRY_INTERRUPTION_INFO:
1638 vmcs_entry_interruption_info = strtoul(optarg, NULL, 0);
1639 set_vmcs_entry_interruption_info = 1;
1640 break;
1641 case SET_CAP:
1642 capval = strtoul(optarg, NULL, 0);
1643 setcap = 1;
1644 break;
1645 case SET_RTC_TIME:
1646 rtc_secs = strtoul(optarg, NULL, 0);
1647 set_rtc_time = 1;
1648 break;
1649 case SET_RTC_NVRAM:
1650 rtc_nvram_value = (uint8_t)strtoul(optarg, NULL, 0);
1651 set_rtc_nvram = 1;
1652 break;
1653 case RTC_NVRAM_OFFSET:
1654 rtc_nvram_offset = strtoul(optarg, NULL, 0);
1655 break;
1597 case GET_GPA_PMAP:
1598 gpa_pmap = strtoul(optarg, NULL, 0);
1599 get_gpa_pmap = 1;
1600 break;
1601 case CAPNAME:
1602 capname = optarg;
1603 break;
1604 case UNASSIGN_PPTDEV:

--- 361 unchanged lines hidden (view full) ---

1966 printf("gpa %#lx:", gpa_pmap);
1967 pte = &pteval[0];
1968 while (ptenum-- > 0)
1969 printf(" %#lx", *pte++);
1970 printf("\n");
1971 }
1972 }
1973
1656 case GET_GPA_PMAP:
1657 gpa_pmap = strtoul(optarg, NULL, 0);
1658 get_gpa_pmap = 1;
1659 break;
1660 case CAPNAME:
1661 capname = optarg;
1662 break;
1663 case UNASSIGN_PPTDEV:

--- 361 unchanged lines hidden (view full) ---

2025 printf("gpa %#lx:", gpa_pmap);
2026 pte = &pteval[0];
2027 while (ptenum-- > 0)
2028 printf(" %#lx", *pte++);
2029 printf("\n");
2030 }
2031 }
2032
2033 if (!error && set_rtc_nvram)
2034 error = vm_rtc_write(ctx, rtc_nvram_offset, rtc_nvram_value);
2035
2036 if (!error && (get_rtc_nvram || get_all)) {
2037 error = vm_rtc_read(ctx, rtc_nvram_offset, &rtc_nvram_value);
2038 if (error == 0) {
2039 printf("rtc nvram[%03d]: 0x%02x\n", rtc_nvram_offset,
2040 rtc_nvram_value);
2041 }
2042 }
2043
2044 if (!error && set_rtc_time)
2045 error = vm_rtc_settime(ctx, rtc_secs);
2046
2047 if (!error && (get_rtc_time || get_all)) {
2048 error = vm_rtc_gettime(ctx, &rtc_secs);
2049 if (error == 0) {
2050 gmtime_r(&rtc_secs, &tm);
2051 printf("rtc time %#lx: %s %s %02d %02d:%02d:%02d %d\n",
2052 rtc_secs, wday_str(tm.tm_wday), mon_str(tm.tm_mon),
2053 tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
2054 1900 + tm.tm_year);
2055 }
2056 }
2057
1974 if (!error && (getcap || get_all)) {
1975 int captype, val, getcaptype;
1976
1977 if (getcap && capname)
1978 getcaptype = vm_capability_name2type(capname);
1979 else
1980 getcaptype = -1;
1981

--- 80 unchanged lines hidden ---
2058 if (!error && (getcap || get_all)) {
2059 int captype, val, getcaptype;
2060
2061 if (getcap && capname)
2062 getcaptype = vm_capability_name2type(capname);
2063 else
2064 getcaptype = -1;
2065

--- 80 unchanged lines hidden ---