1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
|
/* $Id: HMR0.cpp $ */
/** @file
* Hardware Assisted Virtualization Manager (HM) - Host Context Ring-0.
*/
/*
* Copyright (C) 2006-2019 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_HM
#define VMCPU_INCL_CPUM_GST_CTX
#include <VBox/vmm/hm.h>
#include <VBox/vmm/pgm.h>
#include "HMInternal.h"
#include <VBox/vmm/vm.h>
#include <VBox/vmm/hm_svm.h>
#include <VBox/vmm/hmvmxinline.h>
#include <VBox/err.h>
#include <VBox/log.h>
#include <iprt/assert.h>
#include <iprt/asm.h>
#include <iprt/asm-amd64-x86.h>
#include <iprt/cpuset.h>
#include <iprt/mem.h>
#include <iprt/memobj.h>
#include <iprt/once.h>
#include <iprt/param.h>
#include <iprt/power.h>
#include <iprt/string.h>
#include <iprt/thread.h>
#include <iprt/x86.h>
#include "HMVMXR0.h"
#include "HMSVMR0.h"
/*********************************************************************************************************************************
* Internal Functions *
*********************************************************************************************************************************/
static DECLCALLBACK(void) hmR0EnableCpuCallback(RTCPUID idCpu, void *pvUser1, void *pvUser2);
static DECLCALLBACK(void) hmR0DisableCpuCallback(RTCPUID idCpu, void *pvUser1, void *pvUser2);
static DECLCALLBACK(void) hmR0InitIntelCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2);
static DECLCALLBACK(void) hmR0InitAmdCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2);
static DECLCALLBACK(void) hmR0PowerCallback(RTPOWEREVENT enmEvent, void *pvUser);
static DECLCALLBACK(void) hmR0MpEventCallback(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvData);
/*********************************************************************************************************************************
* Structures and Typedefs *
*********************************************************************************************************************************/
/**
* This is used to manage the status code of a RTMpOnAll in HM.
*/
typedef struct HMR0FIRSTRC
{
/** The status code. */
int32_t volatile rc;
/** The ID of the CPU reporting the first failure. */
RTCPUID volatile idCpu;
} HMR0FIRSTRC;
/** Pointer to a first return code structure. */
typedef HMR0FIRSTRC *PHMR0FIRSTRC;
/*********************************************************************************************************************************
* Global Variables *
*********************************************************************************************************************************/
/**
* Global data.
*/
static struct
{
/** Per CPU globals. */
HMPHYSCPU aCpuInfo[RTCPUSET_MAX_CPUS];
/** @name Ring-0 method table for AMD-V and VT-x specific operations.
* @{ */
DECLR0CALLBACKMEMBER(int, pfnEnterSession, (PVMCPU pVCpu));
DECLR0CALLBACKMEMBER(void, pfnThreadCtxCallback, (RTTHREADCTXEVENT enmEvent, PVMCPU pVCpu, bool fGlobalInit));
DECLR0CALLBACKMEMBER(int, pfnExportHostState, (PVMCPU pVCpu));
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnRunGuestCode, (PVMCPU pVCpu));
DECLR0CALLBACKMEMBER(int, pfnEnableCpu, (PHMPHYSCPU pHostCpu, PVM pVM, void *pvCpuPage, RTHCPHYS HCPhysCpuPage,
bool fEnabledByHost, PCSUPHWVIRTMSRS pHwvirtMsrs));
DECLR0CALLBACKMEMBER(int, pfnDisableCpu, (void *pvCpuPage, RTHCPHYS HCPhysCpuPage));
DECLR0CALLBACKMEMBER(int, pfnInitVM, (PVM pVM));
DECLR0CALLBACKMEMBER(int, pfnTermVM, (PVM pVM));
DECLR0CALLBACKMEMBER(int, pfnSetupVM, (PVM pVM));
/** @} */
/** Hardware-virtualization data. */
struct
{
union
{
/** VT-x data. */
struct
{
/** Host CR4 value (set by ring-0 VMX init) */
uint64_t u64HostCr4;
/** Host EFER value (set by ring-0 VMX init) */
uint64_t u64HostEfer;
/** Host SMM monitor control (used for logging/diagnostics) */
uint64_t u64HostSmmMonitorCtl;
/** Last instruction error. */
uint32_t ulLastInstrError;
/** The shift mask employed by the VMX-Preemption timer. */
uint8_t cPreemptTimerShift;
/** Padding. */
uint8_t abPadding[3];
/** Whether we're using the preemption timer or not. */
bool fUsePreemptTimer;
/** Whether we're using SUPR0EnableVTx or not. */
bool fUsingSUPR0EnableVTx;
/** Set if we've called SUPR0EnableVTx(true) and should disable it during
* module termination. */
bool fCalledSUPR0EnableVTx;
/** Set to by us to indicate VMX is supported by the CPU. */
bool fSupported;
} vmx;
/** AMD-V data. */
struct
{
/** SVM revision. */
uint32_t u32Rev;
/** SVM feature bits from cpuid 0x8000000a */
uint32_t u32Features;
/** Padding. */
bool afPadding[3];
/** Set by us to indicate SVM is supported by the CPU. */
bool fSupported;
} svm;
} u;
/** Maximum allowed ASID/VPID (inclusive). */
uint32_t uMaxAsid;
/** MSRs. */
SUPHWVIRTMSRS Msrs;
} hwvirt;
/** Last recorded error code during HM ring-0 init. */
int32_t rcInit;
/** If set, VT-x/AMD-V is enabled globally at init time, otherwise it's
* enabled and disabled each time it's used to execute guest code. */
bool fGlobalInit;
/** Indicates whether the host is suspending or not. We'll refuse a few
* actions when the host is being suspended to speed up the suspending and
* avoid trouble. */
bool volatile fSuspended;
/** Whether we've already initialized all CPUs.
* @remarks We could check the EnableAllCpusOnce state, but this is
* simpler and hopefully easier to understand. */
bool fEnabled;
/** Serialize initialization in HMR0EnableAllCpus. */
RTONCE EnableAllCpusOnce;
} g_HmR0;
/**
* Initializes a first return code structure.
*
* @param pFirstRc The structure to init.
*/
static void hmR0FirstRcInit(PHMR0FIRSTRC pFirstRc)
{
pFirstRc->rc = VINF_SUCCESS;
pFirstRc->idCpu = NIL_RTCPUID;
}
/**
* Try set the status code (success ignored).
*
* @param pFirstRc The first return code structure.
* @param rc The status code.
*/
static void hmR0FirstRcSetStatus(PHMR0FIRSTRC pFirstRc, int rc)
{
if ( RT_FAILURE(rc)
&& ASMAtomicCmpXchgS32(&pFirstRc->rc, rc, VINF_SUCCESS))
pFirstRc->idCpu = RTMpCpuId();
}
/**
* Get the status code of a first return code structure.
*
* @returns The status code; VINF_SUCCESS or error status, no informational or
* warning errors.
* @param pFirstRc The first return code structure.
*/
static int hmR0FirstRcGetStatus(PHMR0FIRSTRC pFirstRc)
{
return pFirstRc->rc;
}
#ifdef VBOX_STRICT
# ifndef DEBUG_bird
/**
* Get the CPU ID on which the failure status code was reported.
*
* @returns The CPU ID, NIL_RTCPUID if no failure was reported.
* @param pFirstRc The first return code structure.
*/
static RTCPUID hmR0FirstRcGetCpuId(PHMR0FIRSTRC pFirstRc)
{
return pFirstRc->idCpu;
}
# endif
#endif /* VBOX_STRICT */
/** @name Dummy callback handlers.
* @{ */
static DECLCALLBACK(int) hmR0DummyEnter(PVMCPU pVCpu)
{
RT_NOREF1(pVCpu);
return VINF_SUCCESS;
}
static DECLCALLBACK(void) hmR0DummyThreadCtxCallback(RTTHREADCTXEVENT enmEvent, PVMCPU pVCpu, bool fGlobalInit)
{
RT_NOREF3(enmEvent, pVCpu, fGlobalInit);
}
static DECLCALLBACK(int) hmR0DummyEnableCpu(PHMPHYSCPU pHostCpu, PVM pVM, void *pvCpuPage, RTHCPHYS HCPhysCpuPage,
bool fEnabledBySystem, PCSUPHWVIRTMSRS pHwvirtMsrs)
{
RT_NOREF6(pHostCpu, pVM, pvCpuPage, HCPhysCpuPage, fEnabledBySystem, pHwvirtMsrs);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) hmR0DummyDisableCpu(void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
{
RT_NOREF2(pvCpuPage, HCPhysCpuPage);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) hmR0DummyInitVM(PVM pVM)
{
RT_NOREF1(pVM);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) hmR0DummyTermVM(PVM pVM)
{
RT_NOREF1(pVM);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) hmR0DummySetupVM(PVM pVM)
{
RT_NOREF1(pVM);
return VINF_SUCCESS;
}
static DECLCALLBACK(VBOXSTRICTRC) hmR0DummyRunGuestCode(PVMCPU pVCpu)
{
RT_NOREF(pVCpu);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) hmR0DummyExportHostState(PVMCPU pVCpu)
{
RT_NOREF1(pVCpu);
return VINF_SUCCESS;
}
/** @} */
/**
* Checks if the CPU is subject to the "VMX-Preemption Timer Does Not Count
* Down at the Rate Specified" erratum.
*
* Errata names and related steppings:
* - BA86 - D0.
* - AAX65 - C2.
* - AAU65 - C2, K0.
* - AAO95 - B1.
* - AAT59 - C2.
* - AAK139 - D0.
* - AAM126 - C0, C1, D0.
* - AAN92 - B1.
* - AAJ124 - C0, D0.
* - AAP86 - B1.
*
* Steppings: B1, C0, C1, C2, D0, K0.
*
* @returns true if subject to it, false if not.
*/
static bool hmR0InitIntelIsSubjectToVmxPreemptTimerErratum(void)
{
uint32_t u = ASMCpuId_EAX(1);
u &= ~(RT_BIT_32(14) | RT_BIT_32(15) | RT_BIT_32(28) | RT_BIT_32(29) | RT_BIT_32(30) | RT_BIT_32(31));
if ( u == UINT32_C(0x000206E6) /* 323344.pdf - BA86 - D0 - Intel Xeon Processor 7500 Series */
|| u == UINT32_C(0x00020652) /* 323056.pdf - AAX65 - C2 - Intel Xeon Processor L3406 */
/* 322814.pdf - AAT59 - C2 - Intel CoreTM i7-600, i5-500, i5-400 and i3-300 Mobile Processor Series */
/* 322911.pdf - AAU65 - C2 - Intel CoreTM i5-600, i3-500 Desktop Processor Series and Intel Pentium Processor G6950 */
|| u == UINT32_C(0x00020655) /* 322911.pdf - AAU65 - K0 - Intel CoreTM i5-600, i3-500 Desktop Processor Series and Intel Pentium Processor G6950 */
|| u == UINT32_C(0x000106E5) /* 322373.pdf - AAO95 - B1 - Intel Xeon Processor 3400 Series */
/* 322166.pdf - AAN92 - B1 - Intel CoreTM i7-800 and i5-700 Desktop Processor Series */
/* 320767.pdf - AAP86 - B1 - Intel Core i7-900 Mobile Processor Extreme Edition Series, Intel Core i7-800 and i7-700 Mobile Processor Series */
|| u == UINT32_C(0x000106A0) /* 321333.pdf - AAM126 - C0 - Intel Xeon Processor 3500 Series Specification */
|| u == UINT32_C(0x000106A1) /* 321333.pdf - AAM126 - C1 - Intel Xeon Processor 3500 Series Specification */
|| u == UINT32_C(0x000106A4) /* 320836.pdf - AAJ124 - C0 - Intel Core i7-900 Desktop Processor Extreme Edition Series and Intel Core i7-900 Desktop Processor Series */
|| u == UINT32_C(0x000106A5) /* 321333.pdf - AAM126 - D0 - Intel Xeon Processor 3500 Series Specification */
/* 321324.pdf - AAK139 - D0 - Intel Xeon Processor 5500 Series Specification */
/* 320836.pdf - AAJ124 - D0 - Intel Core i7-900 Desktop Processor Extreme Edition Series and Intel Core i7-900 Desktop Processor Series */
)
return true;
return false;
}
/**
* Intel specific initialization code.
*
* @returns VBox status code (will only fail if out of memory).
*/
static int hmR0InitIntel(void)
{
/* Read this MSR now as it may be useful for error reporting when initializing VT-x fails. */
g_HmR0.hwvirt.Msrs.u.vmx.u64FeatCtrl = ASMRdMsr(MSR_IA32_FEATURE_CONTROL);
/*
* First try use native kernel API for controlling VT-x.
* (This is only supported by some Mac OS X kernels atm.)
*/
int rc = g_HmR0.rcInit = SUPR0EnableVTx(true /* fEnable */);
g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx = rc != VERR_NOT_SUPPORTED;
if (g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
{
AssertLogRelMsg(rc == VINF_SUCCESS || rc == VERR_VMX_IN_VMX_ROOT_MODE || rc == VERR_VMX_NO_VMX, ("%Rrc\n", rc));
if (RT_SUCCESS(rc))
{
g_HmR0.hwvirt.u.vmx.fSupported = true;
rc = SUPR0EnableVTx(false /* fEnable */);
AssertLogRelRC(rc);
}
}
else
{
HMR0FIRSTRC FirstRc;
hmR0FirstRcInit(&FirstRc);
g_HmR0.rcInit = RTMpOnAll(hmR0InitIntelCpu, &FirstRc, NULL);
if (RT_SUCCESS(g_HmR0.rcInit))
g_HmR0.rcInit = hmR0FirstRcGetStatus(&FirstRc);
}
if (RT_SUCCESS(g_HmR0.rcInit))
{
/* Read CR4 and EFER for logging/diagnostic purposes. */
g_HmR0.hwvirt.u.vmx.u64HostCr4 = ASMGetCR4();
g_HmR0.hwvirt.u.vmx.u64HostEfer = ASMRdMsr(MSR_K6_EFER);
/* Get VMX MSRs for determining VMX features we can ultimately use. */
SUPR0GetHwvirtMsrs(&g_HmR0.hwvirt.Msrs, SUPVTCAPS_VT_X, false /* fForce */);
/*
* Nested KVM workaround: Intel SDM section 34.15.5 describes that
* MSR_IA32_SMM_MONITOR_CTL depends on bit 49 of MSR_IA32_VMX_BASIC while
* table 35-2 says that this MSR is available if either VMX or SMX is supported.
*/
uint64_t const uVmxBasicMsr = g_HmR0.hwvirt.Msrs.u.vmx.u64Basic;
if (RT_BF_GET(uVmxBasicMsr, VMX_BF_BASIC_DUAL_MON))
g_HmR0.hwvirt.u.vmx.u64HostSmmMonitorCtl = ASMRdMsr(MSR_IA32_SMM_MONITOR_CTL);
/* Initialize VPID - 16 bits ASID. */
g_HmR0.hwvirt.uMaxAsid = 0x10000; /* exclusive */
/*
* If the host OS has not enabled VT-x for us, try enter VMX root mode
* to really verify if VT-x is usable.
*/
if (!g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
{
/* Allocate a temporary VMXON region. */
RTR0MEMOBJ hScatchMemObj;
rc = RTR0MemObjAllocCont(&hScatchMemObj, PAGE_SIZE, false /* fExecutable */);
if (RT_FAILURE(rc))
{
LogRel(("hmR0InitIntel: RTR0MemObjAllocCont(,PAGE_SIZE,false) -> %Rrc\n", rc));
return rc;
}
void *pvScatchPage = RTR0MemObjAddress(hScatchMemObj);
RTHCPHYS HCPhysScratchPage = RTR0MemObjGetPagePhysAddr(hScatchMemObj, 0);
ASMMemZeroPage(pvScatchPage);
/* Set revision dword at the beginning of the VMXON structure. */
*(uint32_t *)pvScatchPage = RT_BF_GET(uVmxBasicMsr, VMX_BF_BASIC_VMCS_ID);
/* Make sure we don't get rescheduled to another CPU during this probe. */
RTCCUINTREG const fEFlags = ASMIntDisableFlags();
/* Check CR4.VMXE. */
g_HmR0.hwvirt.u.vmx.u64HostCr4 = ASMGetCR4();
if (!(g_HmR0.hwvirt.u.vmx.u64HostCr4 & X86_CR4_VMXE))
{
/* In theory this bit could be cleared behind our back. Which would cause #UD
faults when we try to execute the VMX instructions... */
ASMSetCR4(g_HmR0.hwvirt.u.vmx.u64HostCr4 | X86_CR4_VMXE);
}
/*
* The only way of checking if we're in VMX root mode or not is to try and enter it.
* There is no instruction or control bit that tells us if we're in VMX root mode.
* Therefore, try and enter VMX root mode here.
*/
rc = VMXEnable(HCPhysScratchPage);
if (RT_SUCCESS(rc))
{
g_HmR0.hwvirt.u.vmx.fSupported = true;
VMXDisable();
}
else
{
/*
* KVM leaves the CPU in VMX root mode. Not only is this not allowed,
* it will crash the host when we enter raw mode, because:
*
* (a) clearing X86_CR4_VMXE in CR4 causes a #GP (we no longer modify
* this bit), and
* (b) turning off paging causes a #GP (unavoidable when switching
* from long to 32 bits mode or 32 bits to PAE).
*
* They should fix their code, but until they do we simply refuse to run.
*/
g_HmR0.rcInit = VERR_VMX_IN_VMX_ROOT_MODE;
Assert(g_HmR0.hwvirt.u.vmx.fSupported == false);
}
/*
* Restore CR4 again; don't leave the X86_CR4_VMXE flag set if it was not
* set before (some software could incorrectly think it is in VMX mode).
*/
ASMSetCR4(g_HmR0.hwvirt.u.vmx.u64HostCr4);
ASMSetFlags(fEFlags);
RTR0MemObjFree(hScatchMemObj, false);
}
if (g_HmR0.hwvirt.u.vmx.fSupported)
{
rc = VMXR0GlobalInit();
if (RT_FAILURE(rc))
g_HmR0.rcInit = rc;
/*
* Install the VT-x methods.
*/
g_HmR0.pfnEnterSession = VMXR0Enter;
g_HmR0.pfnThreadCtxCallback = VMXR0ThreadCtxCallback;
g_HmR0.pfnExportHostState = VMXR0ExportHostState;
g_HmR0.pfnRunGuestCode = VMXR0RunGuestCode;
g_HmR0.pfnEnableCpu = VMXR0EnableCpu;
g_HmR0.pfnDisableCpu = VMXR0DisableCpu;
g_HmR0.pfnInitVM = VMXR0InitVM;
g_HmR0.pfnTermVM = VMXR0TermVM;
g_HmR0.pfnSetupVM = VMXR0SetupVM;
/*
* Check for the VMX-Preemption Timer and adjust for the "VMX-Preemption
* Timer Does Not Count Down at the Rate Specified" CPU erratum.
*/
uint32_t const fPinCtls = RT_HI_U32(g_HmR0.hwvirt.Msrs.u.vmx.u64PinCtls);
if (fPinCtls & VMX_PIN_CTLS_PREEMPT_TIMER)
{
uint64_t const uVmxMiscMsr = g_HmR0.hwvirt.Msrs.u.vmx.u64Misc;
g_HmR0.hwvirt.u.vmx.fUsePreemptTimer = true;
g_HmR0.hwvirt.u.vmx.cPreemptTimerShift = RT_BF_GET(uVmxMiscMsr, VMX_BF_MISC_PREEMPT_TIMER_TSC);
if (hmR0InitIntelIsSubjectToVmxPreemptTimerErratum())
g_HmR0.hwvirt.u.vmx.cPreemptTimerShift = 0; /* This is about right most of the time here. */
}
}
}
#ifdef LOG_ENABLED
else
SUPR0Printf("hmR0InitIntelCpu failed with rc=%Rrc\n", g_HmR0.rcInit);
#endif
return VINF_SUCCESS;
}
/**
* AMD-specific initialization code.
*
* @returns VBox status code (will only fail if out of memory).
*/
static int hmR0InitAmd(void)
{
/* Call the global AMD-V initialization routine (should only fail in out-of-memory situations). */
int rc = SVMR0GlobalInit();
if (RT_FAILURE(rc))
{
g_HmR0.rcInit = rc;
return rc;
}
/*
* Install the AMD-V methods.
*/
g_HmR0.pfnEnterSession = SVMR0Enter;
g_HmR0.pfnThreadCtxCallback = SVMR0ThreadCtxCallback;
g_HmR0.pfnExportHostState = SVMR0ExportHostState;
g_HmR0.pfnRunGuestCode = SVMR0RunGuestCode;
g_HmR0.pfnEnableCpu = SVMR0EnableCpu;
g_HmR0.pfnDisableCpu = SVMR0DisableCpu;
g_HmR0.pfnInitVM = SVMR0InitVM;
g_HmR0.pfnTermVM = SVMR0TermVM;
g_HmR0.pfnSetupVM = SVMR0SetupVM;
/* Query AMD features. */
uint32_t u32Dummy;
ASMCpuId(0x8000000a, &g_HmR0.hwvirt.u.svm.u32Rev, &g_HmR0.hwvirt.uMaxAsid, &u32Dummy, &g_HmR0.hwvirt.u.svm.u32Features);
/*
* We need to check if AMD-V has been properly initialized on all CPUs.
* Some BIOSes might do a poor job.
*/
HMR0FIRSTRC FirstRc;
hmR0FirstRcInit(&FirstRc);
rc = RTMpOnAll(hmR0InitAmdCpu, &FirstRc, NULL);
AssertRC(rc);
if (RT_SUCCESS(rc))
rc = hmR0FirstRcGetStatus(&FirstRc);
#ifndef DEBUG_bird
AssertMsg(rc == VINF_SUCCESS || rc == VERR_SVM_IN_USE,
("hmR0InitAmdCpu failed for cpu %d with rc=%Rrc\n", hmR0FirstRcGetCpuId(&FirstRc), rc));
#endif
if (RT_SUCCESS(rc))
{
SUPR0GetHwvirtMsrs(&g_HmR0.hwvirt.Msrs, SUPVTCAPS_AMD_V, false /* fForce */);
g_HmR0.hwvirt.u.svm.fSupported = true;
}
else
{
g_HmR0.rcInit = rc;
if (rc == VERR_SVM_DISABLED || rc == VERR_SVM_IN_USE)
rc = VINF_SUCCESS; /* Don't fail if AMD-V is disabled or in use. */
}
return rc;
}
/**
* Does global Ring-0 HM initialization (at module init).
*
* @returns VBox status code.
*/
VMMR0_INT_DECL(int) HMR0Init(void)
{
/*
* Initialize the globals.
*/
g_HmR0.fEnabled = false;
static RTONCE s_OnceInit = RTONCE_INITIALIZER;
g_HmR0.EnableAllCpusOnce = s_OnceInit;
for (unsigned i = 0; i < RT_ELEMENTS(g_HmR0.aCpuInfo); i++)
{
g_HmR0.aCpuInfo[i].idCpu = NIL_RTCPUID;
g_HmR0.aCpuInfo[i].hMemObj = NIL_RTR0MEMOBJ;
g_HmR0.aCpuInfo[i].HCPhysMemObj = NIL_RTHCPHYS;
g_HmR0.aCpuInfo[i].pvMemObj = NULL;
#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm = NIL_RTR0MEMOBJ;
g_HmR0.aCpuInfo[i].n.svm.HCPhysNstGstMsrpm = NIL_RTHCPHYS;
g_HmR0.aCpuInfo[i].n.svm.pvNstGstMsrpm = NULL;
#endif
}
/* Fill in all callbacks with placeholders. */
g_HmR0.pfnEnterSession = hmR0DummyEnter;
g_HmR0.pfnThreadCtxCallback = hmR0DummyThreadCtxCallback;
g_HmR0.pfnExportHostState = hmR0DummyExportHostState;
g_HmR0.pfnRunGuestCode = hmR0DummyRunGuestCode;
g_HmR0.pfnEnableCpu = hmR0DummyEnableCpu;
g_HmR0.pfnDisableCpu = hmR0DummyDisableCpu;
g_HmR0.pfnInitVM = hmR0DummyInitVM;
g_HmR0.pfnTermVM = hmR0DummyTermVM;
g_HmR0.pfnSetupVM = hmR0DummySetupVM;
/* Default is global VT-x/AMD-V init. */
g_HmR0.fGlobalInit = true;
/*
* Make sure aCpuInfo is big enough for all the CPUs on this system.
*/
if (RTMpGetArraySize() > RT_ELEMENTS(g_HmR0.aCpuInfo))
{
LogRel(("HM: Too many real CPUs/cores/threads - %u, max %u\n", RTMpGetArraySize(), RT_ELEMENTS(g_HmR0.aCpuInfo)));
return VERR_TOO_MANY_CPUS;
}
/*
* Check for VT-x or AMD-V support.
* Return failure only in out-of-memory situations.
*/
uint32_t fCaps = 0;
int rc = SUPR0GetVTSupport(&fCaps);
if (RT_SUCCESS(rc))
{
if (fCaps & SUPVTCAPS_VT_X)
{
rc = hmR0InitIntel();
if (RT_FAILURE(rc))
return rc;
}
else
{
Assert(fCaps & SUPVTCAPS_AMD_V);
rc = hmR0InitAmd();
if (RT_FAILURE(rc))
return rc;
}
}
else
g_HmR0.rcInit = VERR_UNSUPPORTED_CPU;
/*
* Register notification callbacks that we can use to disable/enable CPUs
* when brought offline/online or suspending/resuming.
*/
if (!g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
{
rc = RTMpNotificationRegister(hmR0MpEventCallback, NULL);
AssertRC(rc);
rc = RTPowerNotificationRegister(hmR0PowerCallback, NULL);
AssertRC(rc);
}
/* We return success here because module init shall not fail if HM fails to initialize. */
return VINF_SUCCESS;
}
/**
* Does global Ring-0 HM termination (at module termination).
*
* @returns VBox status code.
*/
VMMR0_INT_DECL(int) HMR0Term(void)
{
int rc;
if ( g_HmR0.hwvirt.u.vmx.fSupported
&& g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
{
/*
* Simple if the host OS manages VT-x.
*/
Assert(g_HmR0.fGlobalInit);
if (g_HmR0.hwvirt.u.vmx.fCalledSUPR0EnableVTx)
{
rc = SUPR0EnableVTx(false /* fEnable */);
g_HmR0.hwvirt.u.vmx.fCalledSUPR0EnableVTx = false;
}
else
rc = VINF_SUCCESS;
for (unsigned iCpu = 0; iCpu < RT_ELEMENTS(g_HmR0.aCpuInfo); iCpu++)
{
g_HmR0.aCpuInfo[iCpu].fConfigured = false;
Assert(g_HmR0.aCpuInfo[iCpu].hMemObj == NIL_RTR0MEMOBJ);
}
}
else
{
Assert(!g_HmR0.hwvirt.u.vmx.fSupported || !g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx);
/* Doesn't really matter if this fails. */
rc = RTMpNotificationDeregister(hmR0MpEventCallback, NULL); AssertRC(rc);
rc = RTPowerNotificationDeregister(hmR0PowerCallback, NULL); AssertRC(rc);
/*
* Disable VT-x/AMD-V on all CPUs if we enabled it before.
*/
if (g_HmR0.fGlobalInit)
{
HMR0FIRSTRC FirstRc;
hmR0FirstRcInit(&FirstRc);
rc = RTMpOnAll(hmR0DisableCpuCallback, NULL /* pvUser 1 */, &FirstRc);
Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
if (RT_SUCCESS(rc))
rc = hmR0FirstRcGetStatus(&FirstRc);
}
/*
* Free the per-cpu pages used for VT-x and AMD-V.
*/
for (unsigned i = 0; i < RT_ELEMENTS(g_HmR0.aCpuInfo); i++)
{
if (g_HmR0.aCpuInfo[i].hMemObj != NIL_RTR0MEMOBJ)
{
RTR0MemObjFree(g_HmR0.aCpuInfo[i].hMemObj, false);
g_HmR0.aCpuInfo[i].hMemObj = NIL_RTR0MEMOBJ;
g_HmR0.aCpuInfo[i].HCPhysMemObj = NIL_RTHCPHYS;
g_HmR0.aCpuInfo[i].pvMemObj = NULL;
}
#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
if (g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm != NIL_RTR0MEMOBJ)
{
RTR0MemObjFree(g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm, false);
g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm = NIL_RTR0MEMOBJ;
g_HmR0.aCpuInfo[i].n.svm.HCPhysNstGstMsrpm = NIL_RTHCPHYS;
g_HmR0.aCpuInfo[i].n.svm.pvNstGstMsrpm = NULL;
}
#endif
}
}
/** @todo This needs cleaning up. There's no matching
* hmR0TermIntel()/hmR0TermAmd() and all the VT-x/AMD-V specific bits
* should move into their respective modules. */
/* Finally, call global VT-x/AMD-V termination. */
if (g_HmR0.hwvirt.u.vmx.fSupported)
VMXR0GlobalTerm();
else if (g_HmR0.hwvirt.u.svm.fSupported)
SVMR0GlobalTerm();
return rc;
}
/**
* Worker function used by hmR0PowerCallback() and HMR0Init() to initalize VT-x
* on a CPU.
*
* @param idCpu The identifier for the CPU the function is called on.
* @param pvUser1 Pointer to the first RC structure.
* @param pvUser2 Ignored.
*/
static DECLCALLBACK(void) hmR0InitIntelCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
{
PHMR0FIRSTRC pFirstRc = (PHMR0FIRSTRC)pvUser1;
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
Assert(idCpu == (RTCPUID)RTMpCpuIdToSetIndex(idCpu)); /** @todo fix idCpu == index assumption (rainy day) */
NOREF(idCpu); NOREF(pvUser2);
int rc = SUPR0GetVmxUsability(NULL /* pfIsSmxModeAmbiguous */);
hmR0FirstRcSetStatus(pFirstRc, rc);
}
/**
* Worker function used by hmR0PowerCallback() and HMR0Init() to initalize AMD-V
* on a CPU.
*
* @param idCpu The identifier for the CPU the function is called on.
* @param pvUser1 Pointer to the first RC structure.
* @param pvUser2 Ignored.
*/
static DECLCALLBACK(void) hmR0InitAmdCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
{
PHMR0FIRSTRC pFirstRc = (PHMR0FIRSTRC)pvUser1;
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
Assert(idCpu == (RTCPUID)RTMpCpuIdToSetIndex(idCpu)); /** @todo fix idCpu == index assumption (rainy day) */
NOREF(idCpu); NOREF(pvUser2);
int rc = SUPR0GetSvmUsability(true /* fInitSvm */);
hmR0FirstRcSetStatus(pFirstRc, rc);
}
/**
* Enable VT-x or AMD-V on the current CPU
*
* @returns VBox status code.
* @param pVM The cross context VM structure. Can be NULL.
* @param idCpu The identifier for the CPU the function is called on.
*
* @remarks Maybe called with interrupts disabled!
*/
static int hmR0EnableCpu(PVM pVM, RTCPUID idCpu)
{
PHMPHYSCPU pHostCpu = &g_HmR0.aCpuInfo[idCpu];
Assert(idCpu == (RTCPUID)RTMpCpuIdToSetIndex(idCpu)); /** @todo fix idCpu == index assumption (rainy day) */
Assert(idCpu < RT_ELEMENTS(g_HmR0.aCpuInfo));
Assert(!pHostCpu->fConfigured);
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
pHostCpu->idCpu = idCpu;
/* Do NOT reset cTlbFlushes here, see @bugref{6255}. */
int rc;
if ( g_HmR0.hwvirt.u.vmx.fSupported
&& g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
rc = g_HmR0.pfnEnableCpu(pHostCpu, pVM, NULL /* pvCpuPage */, NIL_RTHCPHYS, true, &g_HmR0.hwvirt.Msrs);
else
{
AssertLogRelMsgReturn(pHostCpu->hMemObj != NIL_RTR0MEMOBJ, ("hmR0EnableCpu failed idCpu=%u.\n", idCpu), VERR_HM_IPE_1);
rc = g_HmR0.pfnEnableCpu(pHostCpu, pVM, pHostCpu->pvMemObj, pHostCpu->HCPhysMemObj, false, &g_HmR0.hwvirt.Msrs);
}
if (RT_SUCCESS(rc))
pHostCpu->fConfigured = true;
return rc;
}
/**
* Worker function passed to RTMpOnAll() that is to be called on all CPUs.
*
* @param idCpu The identifier for the CPU the function is called on.
* @param pvUser1 Opaque pointer to the VM (can be NULL!).
* @param pvUser2 The 2nd user argument.
*/
static DECLCALLBACK(void) hmR0EnableCpuCallback(RTCPUID idCpu, void *pvUser1, void *pvUser2)
{
PVM pVM = (PVM)pvUser1; /* can be NULL! */
PHMR0FIRSTRC pFirstRc = (PHMR0FIRSTRC)pvUser2;
AssertReturnVoid(g_HmR0.fGlobalInit);
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
hmR0FirstRcSetStatus(pFirstRc, hmR0EnableCpu(pVM, idCpu));
}
/**
* RTOnce callback employed by HMR0EnableAllCpus.
*
* @returns VBox status code.
* @param pvUser Pointer to the VM.
*/
static DECLCALLBACK(int32_t) hmR0EnableAllCpuOnce(void *pvUser)
{
PVM pVM = (PVM)pvUser;
/*
* Indicate that we've initialized.
*
* Note! There is a potential race between this function and the suspend
* notification. Kind of unlikely though, so ignored for now.
*/
AssertReturn(!g_HmR0.fEnabled, VERR_HM_ALREADY_ENABLED_IPE);
ASMAtomicWriteBool(&g_HmR0.fEnabled, true);
/*
* The global init variable is set by the first VM.
*/
g_HmR0.fGlobalInit = pVM->hm.s.fGlobalInit;
#ifdef VBOX_STRICT
for (unsigned i = 0; i < RT_ELEMENTS(g_HmR0.aCpuInfo); i++)
{
Assert(g_HmR0.aCpuInfo[i].hMemObj == NIL_RTR0MEMOBJ);
Assert(g_HmR0.aCpuInfo[i].HCPhysMemObj == NIL_RTHCPHYS);
Assert(g_HmR0.aCpuInfo[i].pvMemObj == NULL);
Assert(!g_HmR0.aCpuInfo[i].fConfigured);
Assert(!g_HmR0.aCpuInfo[i].cTlbFlushes);
Assert(!g_HmR0.aCpuInfo[i].uCurrentAsid);
# ifdef VBOX_WITH_NESTED_HWVIRT_SVM
Assert(g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm == NIL_RTR0MEMOBJ);
Assert(g_HmR0.aCpuInfo[i].n.svm.HCPhysNstGstMsrpm == NIL_RTHCPHYS);
Assert(g_HmR0.aCpuInfo[i].n.svm.pvNstGstMsrpm == NULL);
# endif
}
#endif
int rc;
if ( g_HmR0.hwvirt.u.vmx.fSupported
&& g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
{
/*
* Global VT-x initialization API (only darwin for now).
*/
rc = SUPR0EnableVTx(true /* fEnable */);
if (RT_SUCCESS(rc))
{
g_HmR0.hwvirt.u.vmx.fCalledSUPR0EnableVTx = true;
/* If the host provides a VT-x init API, then we'll rely on that for global init. */
g_HmR0.fGlobalInit = pVM->hm.s.fGlobalInit = true;
}
else
AssertMsgFailed(("hmR0EnableAllCpuOnce/SUPR0EnableVTx: rc=%Rrc\n", rc));
}
else
{
/*
* We're doing the job ourselves.
*/
/* Allocate one page per cpu for the global VT-x and AMD-V pages */
for (unsigned i = 0; i < RT_ELEMENTS(g_HmR0.aCpuInfo); i++)
{
Assert(g_HmR0.aCpuInfo[i].hMemObj == NIL_RTR0MEMOBJ);
#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
Assert(g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm == NIL_RTR0MEMOBJ);
#endif
if (RTMpIsCpuPossible(RTMpCpuIdFromSetIndex(i)))
{
/** @todo NUMA */
rc = RTR0MemObjAllocCont(&g_HmR0.aCpuInfo[i].hMemObj, PAGE_SIZE, false /* executable R0 mapping */);
AssertLogRelRCReturn(rc, rc);
g_HmR0.aCpuInfo[i].HCPhysMemObj = RTR0MemObjGetPagePhysAddr(g_HmR0.aCpuInfo[i].hMemObj, 0);
Assert(g_HmR0.aCpuInfo[i].HCPhysMemObj != NIL_RTHCPHYS);
Assert(!(g_HmR0.aCpuInfo[i].HCPhysMemObj & PAGE_OFFSET_MASK));
g_HmR0.aCpuInfo[i].pvMemObj = RTR0MemObjAddress(g_HmR0.aCpuInfo[i].hMemObj);
AssertPtr(g_HmR0.aCpuInfo[i].pvMemObj);
ASMMemZeroPage(g_HmR0.aCpuInfo[i].pvMemObj);
#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
rc = RTR0MemObjAllocCont(&g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm, SVM_MSRPM_PAGES << X86_PAGE_4K_SHIFT,
false /* executable R0 mapping */);
AssertLogRelRCReturn(rc, rc);
g_HmR0.aCpuInfo[i].n.svm.HCPhysNstGstMsrpm = RTR0MemObjGetPagePhysAddr(g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm, 0);
Assert(g_HmR0.aCpuInfo[i].n.svm.HCPhysNstGstMsrpm != NIL_RTHCPHYS);
Assert(!(g_HmR0.aCpuInfo[i].n.svm.HCPhysNstGstMsrpm & PAGE_OFFSET_MASK));
g_HmR0.aCpuInfo[i].n.svm.pvNstGstMsrpm = RTR0MemObjAddress(g_HmR0.aCpuInfo[i].n.svm.hNstGstMsrpm);
AssertPtr(g_HmR0.aCpuInfo[i].n.svm.pvNstGstMsrpm);
ASMMemFill32(g_HmR0.aCpuInfo[i].n.svm.pvNstGstMsrpm, SVM_MSRPM_PAGES << X86_PAGE_4K_SHIFT, UINT32_C(0xffffffff));
#endif
}
}
rc = VINF_SUCCESS;
}
if ( RT_SUCCESS(rc)
&& g_HmR0.fGlobalInit)
{
/* First time, so initialize each cpu/core. */
HMR0FIRSTRC FirstRc;
hmR0FirstRcInit(&FirstRc);
rc = RTMpOnAll(hmR0EnableCpuCallback, (void *)pVM, &FirstRc);
if (RT_SUCCESS(rc))
rc = hmR0FirstRcGetStatus(&FirstRc);
}
return rc;
}
/**
* Sets up HM on all cpus.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
*/
VMMR0_INT_DECL(int) HMR0EnableAllCpus(PVM pVM)
{
/* Make sure we don't touch HM after we've disabled HM in preparation of a suspend. */
if (ASMAtomicReadBool(&g_HmR0.fSuspended))
return VERR_HM_SUSPEND_PENDING;
return RTOnce(&g_HmR0.EnableAllCpusOnce, hmR0EnableAllCpuOnce, pVM);
}
/**
* Disable VT-x or AMD-V on the current CPU.
*
* @returns VBox status code.
* @param idCpu The identifier for the CPU this function is called on.
*
* @remarks Must be called with preemption disabled.
*/
static int hmR0DisableCpu(RTCPUID idCpu)
{
PHMPHYSCPU pHostCpu = &g_HmR0.aCpuInfo[idCpu];
Assert(!g_HmR0.hwvirt.u.vmx.fSupported || !g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx);
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
Assert(idCpu == (RTCPUID)RTMpCpuIdToSetIndex(idCpu)); /** @todo fix idCpu == index assumption (rainy day) */
Assert(idCpu < RT_ELEMENTS(g_HmR0.aCpuInfo));
Assert(!pHostCpu->fConfigured || pHostCpu->hMemObj != NIL_RTR0MEMOBJ);
AssertRelease(idCpu == RTMpCpuId());
if (pHostCpu->hMemObj == NIL_RTR0MEMOBJ)
return pHostCpu->fConfigured ? VERR_NO_MEMORY : VINF_SUCCESS /* not initialized. */;
AssertPtr(pHostCpu->pvMemObj);
Assert(pHostCpu->HCPhysMemObj != NIL_RTHCPHYS);
int rc;
if (pHostCpu->fConfigured)
{
rc = g_HmR0.pfnDisableCpu(pHostCpu->pvMemObj, pHostCpu->HCPhysMemObj);
AssertRCReturn(rc, rc);
pHostCpu->fConfigured = false;
pHostCpu->idCpu = NIL_RTCPUID;
}
else
rc = VINF_SUCCESS; /* nothing to do */
return rc;
}
/**
* Worker function passed to RTMpOnAll() that is to be called on the target
* CPUs.
*
* @param idCpu The identifier for the CPU the function is called on.
* @param pvUser1 The 1st user argument.
* @param pvUser2 Opaque pointer to the FirstRc.
*/
static DECLCALLBACK(void) hmR0DisableCpuCallback(RTCPUID idCpu, void *pvUser1, void *pvUser2)
{
PHMR0FIRSTRC pFirstRc = (PHMR0FIRSTRC)pvUser2; NOREF(pvUser1);
AssertReturnVoid(g_HmR0.fGlobalInit);
hmR0FirstRcSetStatus(pFirstRc, hmR0DisableCpu(idCpu));
}
/**
* Worker function passed to RTMpOnSpecific() that is to be called on the target
* CPU.
*
* @param idCpu The identifier for the CPU the function is called on.
* @param pvUser1 Null, not used.
* @param pvUser2 Null, not used.
*/
static DECLCALLBACK(void) hmR0DisableCpuOnSpecificCallback(RTCPUID idCpu, void *pvUser1, void *pvUser2)
{
NOREF(pvUser1);
NOREF(pvUser2);
hmR0DisableCpu(idCpu);
}
/**
* Callback function invoked when a cpu goes online or offline.
*
* @param enmEvent The Mp event.
* @param idCpu The identifier for the CPU the function is called on.
* @param pvData Opaque data (PVM pointer).
*/
static DECLCALLBACK(void) hmR0MpEventCallback(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvData)
{
NOREF(pvData);
Assert(!g_HmR0.hwvirt.u.vmx.fSupported || !g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx);
/*
* We only care about uninitializing a CPU that is going offline. When a
* CPU comes online, the initialization is done lazily in HMR0Enter().
*/
switch (enmEvent)
{
case RTMPEVENT_OFFLINE:
{
RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
RTThreadPreemptDisable(&PreemptState);
if (idCpu == RTMpCpuId())
{
int rc = hmR0DisableCpu(idCpu);
AssertRC(rc);
RTThreadPreemptRestore(&PreemptState);
}
else
{
RTThreadPreemptRestore(&PreemptState);
RTMpOnSpecific(idCpu, hmR0DisableCpuOnSpecificCallback, NULL /* pvUser1 */, NULL /* pvUser2 */);
}
break;
}
default:
break;
}
}
/**
* Called whenever a system power state change occurs.
*
* @param enmEvent The Power event.
* @param pvUser User argument.
*/
static DECLCALLBACK(void) hmR0PowerCallback(RTPOWEREVENT enmEvent, void *pvUser)
{
NOREF(pvUser);
Assert(!g_HmR0.hwvirt.u.vmx.fSupported || !g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx);
#ifdef LOG_ENABLED
if (enmEvent == RTPOWEREVENT_SUSPEND)
SUPR0Printf("hmR0PowerCallback RTPOWEREVENT_SUSPEND\n");
else
SUPR0Printf("hmR0PowerCallback RTPOWEREVENT_RESUME\n");
#endif
if (enmEvent == RTPOWEREVENT_SUSPEND)
ASMAtomicWriteBool(&g_HmR0.fSuspended, true);
if (g_HmR0.fEnabled)
{
int rc;
HMR0FIRSTRC FirstRc;
hmR0FirstRcInit(&FirstRc);
if (enmEvent == RTPOWEREVENT_SUSPEND)
{
if (g_HmR0.fGlobalInit)
{
/* Turn off VT-x or AMD-V on all CPUs. */
rc = RTMpOnAll(hmR0DisableCpuCallback, NULL /* pvUser 1 */, &FirstRc);
Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
}
/* else nothing to do here for the local init case */
}
else
{
/* Reinit the CPUs from scratch as the suspend state might have
messed with the MSRs. (lousy BIOSes as usual) */
if (g_HmR0.hwvirt.u.vmx.fSupported)
rc = RTMpOnAll(hmR0InitIntelCpu, &FirstRc, NULL);
else
rc = RTMpOnAll(hmR0InitAmdCpu, &FirstRc, NULL);
Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
if (RT_SUCCESS(rc))
rc = hmR0FirstRcGetStatus(&FirstRc);
#ifdef LOG_ENABLED
if (RT_FAILURE(rc))
SUPR0Printf("hmR0PowerCallback hmR0InitXxxCpu failed with %Rc\n", rc);
#endif
if (g_HmR0.fGlobalInit)
{
/* Turn VT-x or AMD-V back on on all CPUs. */
rc = RTMpOnAll(hmR0EnableCpuCallback, NULL /* pVM */, &FirstRc /* output ignored */);
Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
}
/* else nothing to do here for the local init case */
}
}
if (enmEvent == RTPOWEREVENT_RESUME)
ASMAtomicWriteBool(&g_HmR0.fSuspended, false);
}
/**
* Does ring-0 per-VM HM initialization.
*
* This will call the CPU specific init. routine which may initialize and allocate
* resources for virtual CPUs.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
*
* @remarks This is called after HMR3Init(), see vmR3CreateU() and
* vmR3InitRing3().
*/
VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM)
{
AssertReturn(pVM, VERR_INVALID_PARAMETER);
/* Make sure we don't touch HM after we've disabled HM in preparation of a suspend. */
if (ASMAtomicReadBool(&g_HmR0.fSuspended))
return VERR_HM_SUSPEND_PENDING;
/*
* Copy globals to the VM structure.
*/
Assert(!(pVM->hm.s.vmx.fSupported && pVM->hm.s.svm.fSupported));
if (pVM->hm.s.vmx.fSupported)
{
pVM->hm.s.vmx.fUsePreemptTimer &= g_HmR0.hwvirt.u.vmx.fUsePreemptTimer; /* Can be overridden by CFGM see HMR3Init(). */
pVM->hm.s.vmx.cPreemptTimerShift = g_HmR0.hwvirt.u.vmx.cPreemptTimerShift;
pVM->hm.s.vmx.u64HostCr4 = g_HmR0.hwvirt.u.vmx.u64HostCr4;
pVM->hm.s.vmx.u64HostEfer = g_HmR0.hwvirt.u.vmx.u64HostEfer;
pVM->hm.s.vmx.u64HostSmmMonitorCtl = g_HmR0.hwvirt.u.vmx.u64HostSmmMonitorCtl;
HMGetVmxMsrsFromHwvirtMsrs(&g_HmR0.hwvirt.Msrs, &pVM->hm.s.vmx.Msrs);
}
else if (pVM->hm.s.svm.fSupported)
{
pVM->hm.s.svm.u32Rev = g_HmR0.hwvirt.u.svm.u32Rev;
pVM->hm.s.svm.u32Features = g_HmR0.hwvirt.u.svm.u32Features;
pVM->hm.s.svm.u64MsrHwcr = g_HmR0.hwvirt.Msrs.u.svm.u64MsrHwcr;
}
pVM->hm.s.rcInit = g_HmR0.rcInit;
pVM->hm.s.uMaxAsid = g_HmR0.hwvirt.uMaxAsid;
/*
* Set default maximum inner loops in ring-0 before returning to ring-3.
* Can be overriden using CFGM.
*/
if (!pVM->hm.s.cMaxResumeLoops)
{
pVM->hm.s.cMaxResumeLoops = 1024;
if (RTThreadPreemptIsPendingTrusty())
pVM->hm.s.cMaxResumeLoops = 8192;
}
/*
* Initialize some per-VCPU fields.
*/
for (VMCPUID i = 0; i < pVM->cCpus; i++)
{
PVMCPU pVCpu = &pVM->aCpus[i];
pVCpu->hm.s.idEnteredCpu = NIL_RTCPUID;
pVCpu->hm.s.idLastCpu = NIL_RTCPUID;
/* We'll aways increment this the first time (host uses ASID 0). */
AssertReturn(!pVCpu->hm.s.uCurrentAsid, VERR_HM_IPE_3);
}
/*
* Get host kernel features that HM might need to know in order
* to co-operate and function properly with the host OS (e.g. SMAP).
*
* Technically, we could do this as part of the pre-init VM procedure
* but it shouldn't be done later than this point so we do it here.
*/
pVM->hm.s.fHostKernelFeatures = SUPR0GetKernelFeatures();
/*
* Call the hardware specific initialization method.
*/
return g_HmR0.pfnInitVM(pVM);
}
/**
* Does ring-0 per VM HM termination.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
*/
VMMR0_INT_DECL(int) HMR0TermVM(PVM pVM)
{
Log(("HMR0TermVM: %p\n", pVM));
AssertReturn(pVM, VERR_INVALID_PARAMETER);
/*
* Call the hardware specific method.
*
* Note! We might be preparing for a suspend, so the pfnTermVM() functions should probably not
* mess with VT-x/AMD-V features on the CPU, currently all they do is free memory so this is safe.
*/
return g_HmR0.pfnTermVM(pVM);
}
/**
* Sets up a VT-x or AMD-V session.
*
* This is mostly about setting up the hardware VM state.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
*/
VMMR0_INT_DECL(int) HMR0SetupVM(PVM pVM)
{
Log(("HMR0SetupVM: %p\n", pVM));
AssertReturn(pVM, VERR_INVALID_PARAMETER);
/* Make sure we don't touch HM after we've disabled HM in preparation of a suspend. */
AssertReturn(!ASMAtomicReadBool(&g_HmR0.fSuspended), VERR_HM_SUSPEND_PENDING);
/* On first entry we'll sync everything. */
for (VMCPUID i = 0; i < pVM->cCpus; i++)
{
PVMCPU pVCpu = &pVM->aCpus[i];
pVCpu->hm.s.fCtxChanged |= HM_CHANGED_HOST_CONTEXT | HM_CHANGED_ALL_GUEST;
}
/*
* Call the hardware specific setup VM method. This requires the CPU to be
* enabled for AMD-V/VT-x and preemption to be prevented.
*/
RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
RTThreadPreemptDisable(&PreemptState);
RTCPUID const idCpu = RTMpCpuId();
/* Enable VT-x or AMD-V if local init is required. */
int rc;
if (!g_HmR0.fGlobalInit)
{
Assert(!g_HmR0.hwvirt.u.vmx.fSupported || !g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx);
rc = hmR0EnableCpu(pVM, idCpu);
if (RT_FAILURE(rc))
{
RTThreadPreemptRestore(&PreemptState);
return rc;
}
}
/* Setup VT-x or AMD-V. */
rc = g_HmR0.pfnSetupVM(pVM);
/* Disable VT-x or AMD-V if local init was done before. */
if (!g_HmR0.fGlobalInit)
{
Assert(!g_HmR0.hwvirt.u.vmx.fSupported || !g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx);
int rc2 = hmR0DisableCpu(idCpu);
AssertRC(rc2);
}
RTThreadPreemptRestore(&PreemptState);
return rc;
}
/**
* Turns on HM on the CPU if necessary and initializes the bare minimum state
* required for entering HM context.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*
* @remarks No-long-jump zone!!!
*/
VMMR0_INT_DECL(int) hmR0EnterCpu(PVMCPU pVCpu)
{
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
int rc = VINF_SUCCESS;
RTCPUID const idCpu = RTMpCpuId();
PHMPHYSCPU pHostCpu = &g_HmR0.aCpuInfo[idCpu];
AssertPtr(pHostCpu);
/* Enable VT-x or AMD-V if local init is required, or enable if it's a freshly onlined CPU. */
if (!pHostCpu->fConfigured)
rc = hmR0EnableCpu(pVCpu->CTX_SUFF(pVM), idCpu);
/* Reload host-state (back from ring-3/migrated CPUs) and shared guest/host bits. */
if (g_HmR0.hwvirt.u.vmx.fSupported)
pVCpu->hm.s.fCtxChanged |= HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_HOST_GUEST_SHARED_STATE;
else
pVCpu->hm.s.fCtxChanged |= HM_CHANGED_HOST_CONTEXT | HM_CHANGED_SVM_HOST_GUEST_SHARED_STATE;
Assert(pHostCpu->idCpu == idCpu && pHostCpu->idCpu != NIL_RTCPUID);
pVCpu->hm.s.idEnteredCpu = idCpu;
return rc;
}
/**
* Enters the VT-x or AMD-V session.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*
* @remarks This is called with preemption disabled.
*/
VMMR0_INT_DECL(int) HMR0Enter(PVMCPU pVCpu)
{
/* Make sure we can't enter a session after we've disabled HM in preparation of a suspend. */
AssertReturn(!ASMAtomicReadBool(&g_HmR0.fSuspended), VERR_HM_SUSPEND_PENDING);
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
/* Load the bare minimum state required for entering HM. */
int rc = hmR0EnterCpu(pVCpu);
if (RT_SUCCESS(rc))
{
if (g_HmR0.hwvirt.u.vmx.fSupported)
{
Assert((pVCpu->hm.s.fCtxChanged & (HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_HOST_GUEST_SHARED_STATE))
== (HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_HOST_GUEST_SHARED_STATE));
}
else
{
Assert((pVCpu->hm.s.fCtxChanged & (HM_CHANGED_HOST_CONTEXT | HM_CHANGED_SVM_HOST_GUEST_SHARED_STATE))
== (HM_CHANGED_HOST_CONTEXT | HM_CHANGED_SVM_HOST_GUEST_SHARED_STATE));
}
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
AssertReturn(!VMMR0ThreadCtxHookIsEnabled(pVCpu), VERR_HM_IPE_5);
bool const fStartedSet = PGMR0DynMapStartOrMigrateAutoSet(pVCpu);
#endif
/* Keep track of the CPU owning the VMCS for debugging scheduling weirdness and ring-3 calls. */
rc = g_HmR0.pfnEnterSession(pVCpu);
AssertMsgRCReturnStmt(rc, ("rc=%Rrc pVCpu=%p\n", rc, pVCpu), pVCpu->hm.s.idEnteredCpu = NIL_RTCPUID, rc);
/* Exports the host-state as we may be resuming code after a longjmp and quite
possibly now be scheduled on a different CPU. */
rc = g_HmR0.pfnExportHostState(pVCpu);
AssertMsgRCReturnStmt(rc, ("rc=%Rrc pVCpu=%p\n", rc, pVCpu), pVCpu->hm.s.idEnteredCpu = NIL_RTCPUID, rc);
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
if (fStartedSet)
PGMRZDynMapReleaseAutoSet(pVCpu);
#endif
}
return rc;
}
/**
* Deinitializes the bare minimum state used for HM context and if necessary
* disable HM on the CPU.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*
* @remarks No-long-jump zone!!!
*/
VMMR0_INT_DECL(int) HMR0LeaveCpu(PVMCPU pVCpu)
{
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
VMCPU_ASSERT_EMT_RETURN(pVCpu, VERR_HM_WRONG_CPU);
RTCPUID const idCpu = RTMpCpuId();
PCHMPHYSCPU pHostCpu = &g_HmR0.aCpuInfo[idCpu];
if ( !g_HmR0.fGlobalInit
&& pHostCpu->fConfigured)
{
int rc = hmR0DisableCpu(idCpu);
AssertRCReturn(rc, rc);
Assert(!pHostCpu->fConfigured);
Assert(pHostCpu->idCpu == NIL_RTCPUID);
/* For obtaining a non-zero ASID/VPID on next re-entry. */
pVCpu->hm.s.idLastCpu = NIL_RTCPUID;
}
/* Clear it while leaving HM context, hmPokeCpuForTlbFlush() relies on this. */
pVCpu->hm.s.idEnteredCpu = NIL_RTCPUID;
return VINF_SUCCESS;
}
/**
* Thread-context hook for HM.
*
* @param enmEvent The thread-context event.
* @param pvUser Opaque pointer to the VMCPU.
*/
VMMR0_INT_DECL(void) HMR0ThreadCtxCallback(RTTHREADCTXEVENT enmEvent, void *pvUser)
{
PVMCPU pVCpu = (PVMCPU)pvUser;
Assert(pVCpu);
Assert(g_HmR0.pfnThreadCtxCallback);
g_HmR0.pfnThreadCtxCallback(enmEvent, pVCpu, g_HmR0.fGlobalInit);
}
/**
* Runs guest code in a hardware accelerated VM.
*
* @returns Strict VBox status code. (VBOXSTRICTRC isn't used because it's
* called from setjmp assembly.)
* @param pVM The cross context VM structure.
* @param pVCpu The cross context virtual CPU structure.
*
* @remarks Can be called with preemption enabled if thread-context hooks are
* used!!!
*/
VMMR0_INT_DECL(int) HMR0RunGuestCode(PVM pVM, PVMCPU pVCpu)
{
RT_NOREF(pVM);
#ifdef VBOX_STRICT
/* With thread-context hooks we would be running this code with preemption enabled. */
if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD))
{
PCHMPHYSCPU pHostCpu = &g_HmR0.aCpuInfo[RTMpCpuId()];
Assert(!VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL));
Assert(pHostCpu->fConfigured);
AssertReturn(!ASMAtomicReadBool(&g_HmR0.fSuspended), VERR_HM_SUSPEND_PENDING);
}
#endif
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
AssertReturn(!VMMR0ThreadCtxHookIsEnabled(pVCpu), VERR_HM_IPE_4);
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
PGMRZDynMapStartAutoSet(pVCpu);
#endif
VBOXSTRICTRC rcStrict = g_HmR0.pfnRunGuestCode(pVCpu);
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
PGMRZDynMapReleaseAutoSet(pVCpu);
#endif
return VBOXSTRICTRC_VAL(rcStrict);
}
/**
* Notification from CPUM that it has unloaded the guest FPU/SSE/AVX state from
* the host CPU and that guest access to it must be intercepted.
*
* @param pVCpu The cross context virtual CPU structure of the calling EMT.
*/
VMMR0_INT_DECL(void) HMR0NotifyCpumUnloadedGuestFpuState(PVMCPU pVCpu)
{
ASMAtomicUoOrU64(&pVCpu->hm.s.fCtxChanged, HM_CHANGED_GUEST_CR0);
}
/**
* Notification from CPUM that it has modified the host CR0 (because of FPU).
*
* @param pVCpu The cross context virtual CPU structure of the calling EMT.
*/
VMMR0_INT_DECL(void) HMR0NotifyCpumModifiedHostCr0(PVMCPU pVCpu)
{
ASMAtomicUoOrU64(&pVCpu->hm.s.fCtxChanged, HM_CHANGED_HOST_CONTEXT);
}
#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
/**
* Save guest FPU/XMM state (64 bits guest mode & 32 bits host only)
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param pVCpu The cross context virtual CPU structure.
* @param pCtx Pointer to the guest CPU context.
*/
VMMR0_INT_DECL(int) HMR0SaveFPUState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
{
RT_NOREF(pCtx);
STAM_COUNTER_INC(&pVCpu->hm.s.StatFpu64SwitchBack);
if (pVM->hm.s.vmx.fSupported)
return VMXR0Execute64BitsHandler(pVCpu, HM64ON32OP_HMRCSaveGuestFPU64, 0, NULL);
return SVMR0Execute64BitsHandler(pVCpu, HM64ON32OP_HMRCSaveGuestFPU64, 0, NULL);
}
/**
* Save guest debug state (64 bits guest mode & 32 bits host only)
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param pVCpu The cross context virtual CPU structure.
* @param pCtx Pointer to the guest CPU context.
*/
VMMR0_INT_DECL(int) HMR0SaveDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
{
RT_NOREF(pCtx);
STAM_COUNTER_INC(&pVCpu->hm.s.StatDebug64SwitchBack);
if (pVM->hm.s.vmx.fSupported)
return VMXR0Execute64BitsHandler(pVCpu, HM64ON32OP_HMRCSaveGuestDebug64, 0, NULL);
return SVMR0Execute64BitsHandler(pVCpu, HM64ON32OP_HMRCSaveGuestDebug64, 0, NULL);
}
/**
* Test the 32->64 bits switcher.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
*/
VMMR0_INT_DECL(int) HMR0TestSwitcher3264(PVM pVM)
{
PVMCPU pVCpu = &pVM->aCpus[0];
uint32_t aParam[5] = { 0, 1, 2, 3, 4 };
int rc;
STAM_PROFILE_ADV_START(&pVCpu->hm.s.StatWorldSwitch3264, z);
if (pVM->hm.s.vmx.fSupported)
rc = VMXR0Execute64BitsHandler(pVCpu, HM64ON32OP_HMRCTestSwitcher64, 5, &aParam[0]);
else
rc = SVMR0Execute64BitsHandler(pVCpu, HM64ON32OP_HMRCTestSwitcher64, 5, &aParam[0]);
STAM_PROFILE_ADV_STOP(&pVCpu->hm.s.StatWorldSwitch3264, z);
return rc;
}
#endif /* HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) */
/**
* Returns suspend status of the host.
*
* @returns Suspend pending or not.
*/
VMMR0_INT_DECL(bool) HMR0SuspendPending(void)
{
return ASMAtomicReadBool(&g_HmR0.fSuspended);
}
/**
* Invalidates a guest page from the host TLB.
*
* @param pVCpu The cross context virtual CPU structure.
* @param GCVirt Page to invalidate.
*/
VMMR0_INT_DECL(int) HMR0InvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt)
{
PVM pVM = pVCpu->CTX_SUFF(pVM);
if (pVM->hm.s.vmx.fSupported)
return VMXR0InvalidatePage(pVCpu, GCVirt);
return SVMR0InvalidatePage(pVCpu, GCVirt);
}
/**
* Returns the cpu structure for the current cpu.
* Keep in mind that there is no guarantee it will stay the same (long jumps to ring 3!!!).
*
* @returns The cpu structure pointer.
*/
VMMR0_INT_DECL(PHMPHYSCPU) hmR0GetCurrentCpu(void)
{
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
RTCPUID const idCpu = RTMpCpuId();
Assert(idCpu < RT_ELEMENTS(g_HmR0.aCpuInfo));
return &g_HmR0.aCpuInfo[idCpu];
}
/**
* Interface for importing state on demand (used by IEM).
*
* @returns VBox status code.
* @param pVCpu The cross context CPU structure.
* @param fWhat What to import, CPUMCTX_EXTRN_XXX.
*/
VMMR0_INT_DECL(int) HMR0ImportStateOnDemand(PVMCPU pVCpu, uint64_t fWhat)
{
if (pVCpu->CTX_SUFF(pVM)->hm.s.vmx.fSupported)
return VMXR0ImportStateOnDemand(pVCpu, fWhat);
return SVMR0ImportStateOnDemand(pVCpu, fWhat);
}
#ifdef VBOX_WITH_RAW_MODE
/**
* Raw-mode switcher hook - disable VT-x if it's active *and* the current
* switcher turns off paging.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param enmSwitcher The switcher we're about to use.
* @param pfVTxDisabled Where to store whether VT-x was disabled or not.
*/
VMMR0_INT_DECL(int) HMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled)
{
NOREF(pVM);
Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
*pfVTxDisabled = false;
/* No such issues with AMD-V */
if (!g_HmR0.hwvirt.u.vmx.fSupported)
return VINF_SUCCESS;
/* Check if the switching we're up to is safe. */
switch (enmSwitcher)
{
case VMMSWITCHER_32_TO_32:
case VMMSWITCHER_PAE_TO_PAE:
return VINF_SUCCESS; /* safe switchers as they don't turn off paging */
case VMMSWITCHER_32_TO_PAE:
case VMMSWITCHER_PAE_TO_32: /* is this one actually used?? */
case VMMSWITCHER_AMD64_TO_32:
case VMMSWITCHER_AMD64_TO_PAE:
break; /* unsafe switchers */
default:
AssertFailedReturn(VERR_HM_WRONG_SWITCHER);
}
/* When using SUPR0EnableVTx we must let the host suspend and resume VT-x,
regardless of whether we're currently using VT-x or not. */
if (g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
{
*pfVTxDisabled = SUPR0SuspendVTxOnCpu();
return VINF_SUCCESS;
}
/** @todo Check if this code is presumptive wrt other VT-x users on the
* system... */
/* Nothing to do if we haven't enabled VT-x. */
if (!g_HmR0.fEnabled)
return VINF_SUCCESS;
/* Local init implies the CPU is currently not in VMX root mode. */
if (!g_HmR0.fGlobalInit)
return VINF_SUCCESS;
/* Ok, disable VT-x. */
PCHMPHYSCPU pHostCpu = hmR0GetCurrentCpu();
AssertReturn( pHostCpu
&& pHostCpu->hMemObj != NIL_RTR0MEMOBJ
&& pHostCpu->pvMemObj
&& pHostCpu->HCPhysMemObj != NIL_RTHCPHYS,
VERR_HM_IPE_2);
*pfVTxDisabled = true;
return VMXR0DisableCpu(pHostCpu->pvMemObj, pHostCpu->HCPhysMemObj);
}
/**
* Raw-mode switcher hook - re-enable VT-x if was active *and* the current
* switcher turned off paging.
*
* @param pVM The cross context VM structure.
* @param fVTxDisabled Whether VT-x was disabled or not.
*/
VMMR0_INT_DECL(void) HMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled)
{
Assert(!ASMIntAreEnabled());
if (!fVTxDisabled)
return; /* nothing to do */
Assert(g_HmR0.hwvirt.u.vmx.fSupported);
if (g_HmR0.hwvirt.u.vmx.fUsingSUPR0EnableVTx)
SUPR0ResumeVTxOnCpu(fVTxDisabled);
else
{
Assert(g_HmR0.fEnabled);
Assert(g_HmR0.fGlobalInit);
PHMPHYSCPU pHostCpu = hmR0GetCurrentCpu();
AssertReturnVoid( pHostCpu
&& pHostCpu->hMemObj != NIL_RTR0MEMOBJ
&& pHostCpu->pvMemObj
&& pHostCpu->HCPhysMemObj != NIL_RTHCPHYS);
VMXR0EnableCpu(pHostCpu, pVM, pHostCpu->pvMemObj, pHostCpu->HCPhysMemObj, false, &g_HmR0.hwvirt.Msrs);
}
}
#endif /* VBOX_WITH_RAW_MODE */
#ifdef VBOX_STRICT
/**
* Dumps a descriptor.
*
* @param pDesc Descriptor to dump.
* @param Sel Selector number.
* @param pszMsg Message to prepend the log entry with.
*/
VMMR0_INT_DECL(void) hmR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg)
{
/*
* Make variable description string.
*/
static struct
{
unsigned cch;
const char *psz;
} const s_aTypes[32] =
{
# define STRENTRY(str) { sizeof(str) - 1, str }
/* system */
# if HC_ARCH_BITS == 64
STRENTRY("Reserved0 "), /* 0x00 */
STRENTRY("Reserved1 "), /* 0x01 */
STRENTRY("LDT "), /* 0x02 */
STRENTRY("Reserved3 "), /* 0x03 */
STRENTRY("Reserved4 "), /* 0x04 */
STRENTRY("Reserved5 "), /* 0x05 */
STRENTRY("Reserved6 "), /* 0x06 */
STRENTRY("Reserved7 "), /* 0x07 */
STRENTRY("Reserved8 "), /* 0x08 */
STRENTRY("TSS64Avail "), /* 0x09 */
STRENTRY("ReservedA "), /* 0x0a */
STRENTRY("TSS64Busy "), /* 0x0b */
STRENTRY("Call64 "), /* 0x0c */
STRENTRY("ReservedD "), /* 0x0d */
STRENTRY("Int64 "), /* 0x0e */
STRENTRY("Trap64 "), /* 0x0f */
# else
STRENTRY("Reserved0 "), /* 0x00 */
STRENTRY("TSS16Avail "), /* 0x01 */
STRENTRY("LDT "), /* 0x02 */
STRENTRY("TSS16Busy "), /* 0x03 */
STRENTRY("Call16 "), /* 0x04 */
STRENTRY("Task "), /* 0x05 */
STRENTRY("Int16 "), /* 0x06 */
STRENTRY("Trap16 "), /* 0x07 */
STRENTRY("Reserved8 "), /* 0x08 */
STRENTRY("TSS32Avail "), /* 0x09 */
STRENTRY("ReservedA "), /* 0x0a */
STRENTRY("TSS32Busy "), /* 0x0b */
STRENTRY("Call32 "), /* 0x0c */
STRENTRY("ReservedD "), /* 0x0d */
STRENTRY("Int32 "), /* 0x0e */
STRENTRY("Trap32 "), /* 0x0f */
# endif
/* non system */
STRENTRY("DataRO "), /* 0x10 */
STRENTRY("DataRO Accessed "), /* 0x11 */
STRENTRY("DataRW "), /* 0x12 */
STRENTRY("DataRW Accessed "), /* 0x13 */
STRENTRY("DataDownRO "), /* 0x14 */
STRENTRY("DataDownRO Accessed "), /* 0x15 */
STRENTRY("DataDownRW "), /* 0x16 */
STRENTRY("DataDownRW Accessed "), /* 0x17 */
STRENTRY("CodeEO "), /* 0x18 */
STRENTRY("CodeEO Accessed "), /* 0x19 */
STRENTRY("CodeER "), /* 0x1a */
STRENTRY("CodeER Accessed "), /* 0x1b */
STRENTRY("CodeConfEO "), /* 0x1c */
STRENTRY("CodeConfEO Accessed "), /* 0x1d */
STRENTRY("CodeConfER "), /* 0x1e */
STRENTRY("CodeConfER Accessed ") /* 0x1f */
# undef SYSENTRY
};
# define ADD_STR(psz, pszAdd) do { strcpy(psz, pszAdd); psz += strlen(pszAdd); } while (0)
char szMsg[128];
char *psz = &szMsg[0];
unsigned i = pDesc->Gen.u1DescType << 4 | pDesc->Gen.u4Type;
memcpy(psz, s_aTypes[i].psz, s_aTypes[i].cch);
psz += s_aTypes[i].cch;
if (pDesc->Gen.u1Present)
ADD_STR(psz, "Present ");
else
ADD_STR(psz, "Not-Present ");
# if HC_ARCH_BITS == 64
if (pDesc->Gen.u1Long)
ADD_STR(psz, "64-bit ");
else
ADD_STR(psz, "Comp ");
# else
if (pDesc->Gen.u1Granularity)
ADD_STR(psz, "Page ");
if (pDesc->Gen.u1DefBig)
ADD_STR(psz, "32-bit ");
else
ADD_STR(psz, "16-bit ");
# endif
# undef ADD_STR
*psz = '\0';
/*
* Limit and Base and format the output.
*/
#ifdef LOG_ENABLED
uint32_t u32Limit = X86DESC_LIMIT_G(pDesc);
# if HC_ARCH_BITS == 64
uint64_t u32Base = X86DESC64_BASE(pDesc);
Log(("%s %04x - %RX64 %RX64 - base=%RX64 limit=%08x dpl=%d %s\n", pszMsg,
Sel, pDesc->au64[0], pDesc->au64[1], u32Base, u32Limit, pDesc->Gen.u2Dpl, szMsg));
# else
uint32_t u32Base = X86DESC_BASE(pDesc);
Log(("%s %04x - %08x %08x - base=%08x limit=%08x dpl=%d %s\n", pszMsg,
Sel, pDesc->au32[0], pDesc->au32[1], u32Base, u32Limit, pDesc->Gen.u2Dpl, szMsg));
# endif
#else
NOREF(Sel); NOREF(pszMsg);
#endif
}
/**
* Formats a full register dump.
*
* @param pVCpu The cross context virtual CPU structure.
*/
VMMR0_INT_DECL(void) hmR0DumpRegs(PVMCPU pVCpu)
{
/*
* Format the flags.
*/
static struct
{
const char *pszSet; const char *pszClear; uint32_t fFlag;
} const s_aFlags[] =
{
{ "vip", NULL, X86_EFL_VIP },
{ "vif", NULL, X86_EFL_VIF },
{ "ac", NULL, X86_EFL_AC },
{ "vm", NULL, X86_EFL_VM },
{ "rf", NULL, X86_EFL_RF },
{ "nt", NULL, X86_EFL_NT },
{ "ov", "nv", X86_EFL_OF },
{ "dn", "up", X86_EFL_DF },
{ "ei", "di", X86_EFL_IF },
{ "tf", NULL, X86_EFL_TF },
{ "nt", "pl", X86_EFL_SF },
{ "nz", "zr", X86_EFL_ZF },
{ "ac", "na", X86_EFL_AF },
{ "po", "pe", X86_EFL_PF },
{ "cy", "nc", X86_EFL_CF },
};
char szEFlags[80];
char *psz = szEFlags;
PCCPUMCTX pCtx = &pVCpu->cpum.GstCtx;
uint32_t uEFlags = pCtx->eflags.u32;
for (unsigned i = 0; i < RT_ELEMENTS(s_aFlags); i++)
{
const char *pszAdd = s_aFlags[i].fFlag & uEFlags ? s_aFlags[i].pszSet : s_aFlags[i].pszClear;
if (pszAdd)
{
strcpy(psz, pszAdd);
psz += strlen(pszAdd);
*psz++ = ' ';
}
}
psz[-1] = '\0';
/*
* Format the registers.
*/
if (CPUMIsGuestIn64BitCode(pVCpu))
{
Log(("rax=%016RX64 rbx=%016RX64 rcx=%016RX64 rdx=%016RX64\n"
"rsi=%016RX64 rdi=%016RX64 r8 =%016RX64 r9 =%016RX64\n"
"r10=%016RX64 r11=%016RX64 r12=%016RX64 r13=%016RX64\n"
"r14=%016RX64 r15=%016RX64\n"
"rip=%016RX64 rsp=%016RX64 rbp=%016RX64 iopl=%d %*s\n"
"cs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"ds={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"es={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"fs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"gs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"ss={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"cr0=%016RX64 cr2=%016RX64 cr3=%016RX64 cr4=%016RX64\n"
"dr0=%016RX64 dr1=%016RX64 dr2=%016RX64 dr3=%016RX64\n"
"dr4=%016RX64 dr5=%016RX64 dr6=%016RX64 dr7=%016RX64\n"
"gdtr=%016RX64:%04x idtr=%016RX64:%04x eflags=%08x\n"
"ldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"tr ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"SysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
,
pCtx->rax, pCtx->rbx, pCtx->rcx, pCtx->rdx, pCtx->rsi, pCtx->rdi,
pCtx->r8, pCtx->r9, pCtx->r10, pCtx->r11, pCtx->r12, pCtx->r13,
pCtx->r14, pCtx->r15,
pCtx->rip, pCtx->rsp, pCtx->rbp, X86_EFL_GET_IOPL(uEFlags), 31, szEFlags,
pCtx->cs.Sel, pCtx->cs.u64Base, pCtx->cs.u32Limit, pCtx->cs.Attr.u,
pCtx->ds.Sel, pCtx->ds.u64Base, pCtx->ds.u32Limit, pCtx->ds.Attr.u,
pCtx->es.Sel, pCtx->es.u64Base, pCtx->es.u32Limit, pCtx->es.Attr.u,
pCtx->fs.Sel, pCtx->fs.u64Base, pCtx->fs.u32Limit, pCtx->fs.Attr.u,
pCtx->gs.Sel, pCtx->gs.u64Base, pCtx->gs.u32Limit, pCtx->gs.Attr.u,
pCtx->ss.Sel, pCtx->ss.u64Base, pCtx->ss.u32Limit, pCtx->ss.Attr.u,
pCtx->cr0, pCtx->cr2, pCtx->cr3, pCtx->cr4,
pCtx->dr[0], pCtx->dr[1], pCtx->dr[2], pCtx->dr[3],
pCtx->dr[4], pCtx->dr[5], pCtx->dr[6], pCtx->dr[7],
pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, uEFlags,
pCtx->ldtr.Sel, pCtx->ldtr.u64Base, pCtx->ldtr.u32Limit, pCtx->ldtr.Attr.u,
pCtx->tr.Sel, pCtx->tr.u64Base, pCtx->tr.u32Limit, pCtx->tr.Attr.u,
pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp));
}
else
Log(("eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
"eip=%08x esp=%08x ebp=%08x iopl=%d %*s\n"
"cs={%04x base=%016RX64 limit=%08x flags=%08x} dr0=%08RX64 dr1=%08RX64\n"
"ds={%04x base=%016RX64 limit=%08x flags=%08x} dr2=%08RX64 dr3=%08RX64\n"
"es={%04x base=%016RX64 limit=%08x flags=%08x} dr4=%08RX64 dr5=%08RX64\n"
"fs={%04x base=%016RX64 limit=%08x flags=%08x} dr6=%08RX64 dr7=%08RX64\n"
"gs={%04x base=%016RX64 limit=%08x flags=%08x} cr0=%08RX64 cr2=%08RX64\n"
"ss={%04x base=%016RX64 limit=%08x flags=%08x} cr3=%08RX64 cr4=%08RX64\n"
"gdtr=%016RX64:%04x idtr=%016RX64:%04x eflags=%08x\n"
"ldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"tr ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"SysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
,
pCtx->eax, pCtx->ebx, pCtx->ecx, pCtx->edx, pCtx->esi, pCtx->edi,
pCtx->eip, pCtx->esp, pCtx->ebp, X86_EFL_GET_IOPL(uEFlags), 31, szEFlags,
pCtx->cs.Sel, pCtx->cs.u64Base, pCtx->cs.u32Limit, pCtx->cs.Attr.u, pCtx->dr[0], pCtx->dr[1],
pCtx->ds.Sel, pCtx->ds.u64Base, pCtx->ds.u32Limit, pCtx->ds.Attr.u, pCtx->dr[2], pCtx->dr[3],
pCtx->es.Sel, pCtx->es.u64Base, pCtx->es.u32Limit, pCtx->es.Attr.u, pCtx->dr[4], pCtx->dr[5],
pCtx->fs.Sel, pCtx->fs.u64Base, pCtx->fs.u32Limit, pCtx->fs.Attr.u, pCtx->dr[6], pCtx->dr[7],
pCtx->gs.Sel, pCtx->gs.u64Base, pCtx->gs.u32Limit, pCtx->gs.Attr.u, pCtx->cr0, pCtx->cr2,
pCtx->ss.Sel, pCtx->ss.u64Base, pCtx->ss.u32Limit, pCtx->ss.Attr.u, pCtx->cr3, pCtx->cr4,
pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, uEFlags,
pCtx->ldtr.Sel, pCtx->ldtr.u64Base, pCtx->ldtr.u32Limit, pCtx->ldtr.Attr.u,
pCtx->tr.Sel, pCtx->tr.u64Base, pCtx->tr.u32Limit, pCtx->tr.Attr.u,
pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp));
PX86FXSTATE pFpuCtx = &pCtx->CTX_SUFF(pXState)->x87;
Log(("FPU:\n"
"FCW=%04x FSW=%04x FTW=%02x\n"
"FOP=%04x FPUIP=%08x CS=%04x Rsrvd1=%04x\n"
"FPUDP=%04x DS=%04x Rsvrd2=%04x MXCSR=%08x MXCSR_MASK=%08x\n"
,
pFpuCtx->FCW, pFpuCtx->FSW, pFpuCtx->FTW,
pFpuCtx->FOP, pFpuCtx->FPUIP, pFpuCtx->CS, pFpuCtx->Rsrvd1,
pFpuCtx->FPUDP, pFpuCtx->DS, pFpuCtx->Rsrvd2,
pFpuCtx->MXCSR, pFpuCtx->MXCSR_MASK));
Log(("MSR:\n"
"EFER =%016RX64\n"
"PAT =%016RX64\n"
"STAR =%016RX64\n"
"CSTAR =%016RX64\n"
"LSTAR =%016RX64\n"
"SFMASK =%016RX64\n"
"KERNELGSBASE =%016RX64\n",
pCtx->msrEFER,
pCtx->msrPAT,
pCtx->msrSTAR,
pCtx->msrCSTAR,
pCtx->msrLSTAR,
pCtx->msrSFMASK,
pCtx->msrKERNELGSBASE));
NOREF(pFpuCtx);
}
#endif /* VBOX_STRICT */
|