Changeset 92426 in vbox for trunk/include/VBox
- Timestamp:
- Nov 15, 2021 1:25:47 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/vmm/pgm.h
r92409 r92426 34 34 #include <VBox/vmm/vmapi.h> 35 35 #include <VBox/vmm/gmm.h> /* for PGMMREGISTERSHAREDMODULEREQ */ 36 #include <VBox/vmm/hm_vmx.h> 36 37 #include <iprt/x86.h> 37 38 #include <VBox/param.h> … … 295 296 } PGMSLAT; 296 297 298 299 /** @name PGMPTATTRS - PGM page-table attributes. 300 * 301 * This is VirtualBox's combined page table attributes. It combines regular page 302 * table and Intel EPT attributes. It's 64-bit in size so there's ample room for 303 * bits added in the future to EPT or regular page tables (for e.g. Protection Key). 304 * 305 * The following bits map 1:1 (shifted by PGM_PTATTRS_EPT_SHIFT) to the Intel EPT 306 * attributes as these are unique to EPT and fit within 64-bits despite the shift: 307 * - EPT_R : Read access. 308 * - EPT_W : Write access. 309 * - EPT_X_SUPER : Execute or execute for supervisor-mode linear addr access. 310 * - EPT_MEMTYPE : EPT memory type. 311 * - EPT_IGNORE_PAT: Ignore PAT memory type. 312 * - EPT_X_USER : Execute access for user-mode linear addresses. 313 * 314 * For regular page tables, the R bit is always 1 (same as P bit). 315 * For Intel EPT, the EPT_R and EPT_W bits are copied to R and W bits respectively. 316 * 317 * The following EPT attributes are mapped to the following positions because they 318 * exist in the regular page tables at these positions OR are exclusive to EPT and 319 * have been mapped to arbitrarily chosen positions: 320 * - EPT_A : Accessed (EPT bit 8 maps to bit 5). 321 * - EPT_D : Dirty (EPT bit 9 maps to bit 6). 322 * - EPT_SUPER_SHW_STACK : Supervisor Shadow Stack (EPT bit 60 maps to bit 24). 323 * - EPT_SUPPRESS_VE_XCPT: Suppress \#VE exception (EPT bit 63 maps to bit 25). 324 * 325 * Bits 12, 11:9 and 43 are deliberately kept unused (correspond to bit PS and bits 326 * 11:9 in the regular page-table structures and to bit 11 in the EPT structures 327 * respectively) as bit 12 is the page-size bit and bits 11:9 are reserved for 328 * use by software and we may want to use/preserve them in the future. 329 * 330 * @{ */ 331 typedef uint64_t PGMPTATTRS; 332 /** Pointer to a PGMPTATTRS type. */ 333 typedef PGMPTATTRS *PPGMPTATTRS; 334 335 /** Read bit (always 1 for regular PT, copy of EPT_R for EPT). */ 336 #define PGM_PTATTRS_R_SHIFT 0 337 #define PGM_PTATTRS_R_MASK RT_BIT_64(PGM_PTATTRS_R_SHIFT) 338 /** Write access bit (aka read/write bit for regular PT). */ 339 #define PGM_PTATTRS_W_SHIFT 1 340 #define PGM_PTATTRS_W_MASK RT_BIT_64(PGM_PTATTRS_W_SHIFT) 341 /** User-mode access bit. */ 342 #define PGM_PTATTRS_US_SHIFT 2 343 #define PGM_PTATTRS_US_MASK RT_BIT_64(PGM_PTATTRS_US_SHIFT) 344 /** Write through cache bit. */ 345 #define PGM_PTATTRS_PWT_SHIFT 3 346 #define PGM_PTATTRS_PWT_MASK RT_BIT_64(PGM_PTATTRS_PWT_SHIFT) 347 /** Cache disabled bit. */ 348 #define PGM_PTATTRS_PCD_SHIFT 4 349 #define PGM_PTATTRS_PCD_MASK RT_BIT_64(PGM_PTATTRS_PCD_SHIFT) 350 /** Accessed bit. */ 351 #define PGM_PTATTRS_A_SHIFT 5 352 #define PGM_PTATTRS_A_MASK RT_BIT_64(PGM_PTATTRS_A_SHIFT) 353 /** Dirty bit. */ 354 #define PGM_PTATTRS_D_SHIFT 6 355 #define PGM_PTATTRS_D_MASK RT_BIT_64(PGM_PTATTRS_D_SHIFT) 356 /** The PAT bit. */ 357 #define PGM_PTATTRS_PAT_SHIFT 7 358 #define PGM_PTATTRS_PAT_MASK RT_BIT_64(PGM_PTATTRS_PAT_SHIFT) 359 /** The global bit. */ 360 #define PGM_PTATTRS_G_SHIFT 8 361 #define PGM_PTATTRS_G_MASK RT_BIT_64(PGM_PTATTRS_G_SHIFT) 362 /** Reserved (bits 12:9) unused. */ 363 #define PGM_PTATTRS_RSVD_12_9_SHIFT 9 364 #define PGM_PTATTRS_RSVD_12_9_MASK UINT64_C(0x0000000000001e00) 365 /** Read access bit - EPT only. */ 366 #define PGM_PTATTRS_EPT_R_SHIFT 13 367 #define PGM_PTATTRS_EPT_R_MASK RT_BIT_64(PGM_PTATTRS_EPT_R_SHIFT) 368 /** Write access bit - EPT only. */ 369 #define PGM_PTATTRS_EPT_W_SHIFT 14 370 #define PGM_PTATTRS_EPT_W_MASK RT_BIT_64(PGM_PTATTRS_EPT_W_SHIFT) 371 /** Execute or execute access for supervisor-mode linear addresses - EPT only. */ 372 #define PGM_PTATTRS_EPT_X_SUPER_SHIFT 15 373 #define PGM_PTATTRS_EPT_X_SUPER_MASK RT_BIT_64(PGM_PTATTRS_EPT_X_SUPER_SHIFT) 374 /** EPT memory type - EPT only. */ 375 #define PGM_PTATTRS_EPT_MEMTYPE_SHIFT 16 376 #define PGM_PTATTRS_EPT_MEMTYPE_MASK UINT64_C(0x0000000000070000) 377 /** Ignore PAT memory type - EPT only. */ 378 #define PGM_PTATTRS_EPT_IGNORE_PAT_SHIFT 19 379 #define PGM_PTATTRS_EPT_IGNORE_PAT_MASK RT_BIT_64(PGM_PTATTRS_EPT_IGNORE_PAT_SHIFT) 380 /** Reserved (bits 22:20) unused. */ 381 #define PGM_PTATTRS_RSVD_22_20_SHIFT 20 382 #define PGM_PTATTRS_RSVD_22_20_MASK UINT64_C(0x0000000000700000) 383 /** Execute access for user-mode linear addresses - EPT only. */ 384 #define PGM_PTATTRS_EPT_X_USER_SHIFT 23 385 #define PGM_PTATTRS_EPT_X_USER_MASK RT_BIT_64(PGM_PTATTRS_EPT_X_USER_SHIFT) 386 /** Reserved (bit 23) - unused. */ 387 #define PGM_PTATTRS_RSVD_23_SHIFT 24 388 #define PGM_PTATTRS_RSVD_23_MASK UINT64_C(0x0000000001000000) 389 /** Supervisor shadow stack - EPT only. */ 390 #define PGM_PTATTRS_EPT_SUPER_SHW_STACK_SHIFT 25 391 #define PGM_PTATTRS_EPT_SUPER_SHW_STACK_MASK RT_BIT_64(PGM_PTATTRS_EPT_SUPER_SHW_STACK_SHIFT) 392 /** Suppress \#VE exception - EPT only. */ 393 #define PGM_PTATTRS_EPT_SUPPRESS_VE_XCPT_SHIFT 26 394 #define PGM_PTATTRS_EPT_SUPPRESS_VE_XCPT_MASK RT_BIT_64(PGM_PTATTRS_EPT_SUPPRESS_VE_XCPT_SHIFT) 395 /** Reserved (bits 62:27) - unused. */ 396 #define PGM_PTATTRS_RSVD_62_27_SHIFT 27 397 #define PGM_PTATTRS_RSVD_62_27_MASK UINT64_C(0x7ffffffff8000000) 398 /** No-execute bit. */ 399 #define PGM_PTATTRS_NX_SHIFT 63 400 #define PGM_PTATTRS_NX_MASK RT_BIT_64(PGM_PTATTRS_NX_SHIFT) 401 402 RT_BF_ASSERT_COMPILE_CHECKS(PGM_PTATTRS_, UINT64_C(0), UINT64_MAX, 403 (R, W, US, PWT, PCD, A, D, PAT, G, RSVD_12_9, EPT_R, EPT_W, EPT_X_SUPER, EPT_MEMTYPE, EPT_IGNORE_PAT, 404 RSVD_22_20, EPT_X_USER, RSVD_23, EPT_SUPER_SHW_STACK, EPT_SUPPRESS_VE_XCPT, RSVD_62_27, NX)); 405 406 /** The bit position where the EPT specific attributes begin. */ 407 #define PGM_PTATTRS_EPT_SHIFT PGM_PTATTRS_EPT_R_SHIFT 408 /** The mask of EPT bits (bits 26:ATTR_SHIFT). In the future we might choose to 409 * use higher unused bits for something else, in that case adjust this mask. */ 410 #define PGM_PTATTRS_EPT_MASK UINT64_C(0x0000000007ffe000) 411 412 /** The mask of all PGM page attribute bits for regular page-tables. */ 413 #define PGM_PTATTRS_PT_VALID_MASK ( PGM_PTATTRS_R_MASK \ 414 | PGM_PTATTRS_W_MASK \ 415 | PGM_PTATTRS_US_MASK \ 416 | PGM_PTATTRS_PWT_MASK \ 417 | PGM_PTATTRS_PCD_MASK \ 418 | PGM_PTATTRS_A_MASK \ 419 | PGM_PTATTRS_D_MASK \ 420 | PGM_PTATTRS_PAT_MASK \ 421 | PGM_PTATTRS_G_MASK \ 422 | PGM_PTATTRS_NX_MASK) 423 424 /** The mask of all PGM page attribute bits for EPT. */ 425 #define PGM_PTATTRS_EPT_VALID_MASK ( PGM_PTATTRS_R_MASK \ 426 | PGM_PTATTRS_W_MASK \ 427 | PGM_PTATTRS_A_MASK \ 428 | PGM_PTATTRS_D_MASK \ 429 | PGM_PTATTRS_EPT_R_MASK \ 430 | PGM_PTATTRS_EPT_W_MASK \ 431 | PGM_PTATTRS_EPT_X_SUPER \ 432 | PGM_PTATTRS_EPT_MEMTYPE \ 433 | PGM_PTATTRS_EPT_IGNORE_PAT \ 434 | PGM_PTATTRS_EPT_X_USER \ 435 | PGM_PTATTRS_EPT_SUPER_SHW_STACK \ 436 | PGM_PTATTRS_EPT_SUPPRESS_VE_XCPT) 437 438 /* The mask of all PGM page attribute bits (combined). */ 439 #define PGM_PTATTRS_VALID_MASK (PGM_PTATTRS_PT_VALID_MASK | PGM_PTATTRS_PT_VALID_MASK) 440 441 /* Verify bits match the regular PT bits. */ 442 AssertCompile(PGM_PTATTRS_W_SHIFT == X86_PTE_BIT_RW); 443 AssertCompile(PGM_PTATTRS_US_SHIFT == X86_PTE_BIT_US); 444 AssertCompile(PGM_PTATTRS_PWT_SHIFT == X86_PTE_BIT_PWT); 445 AssertCompile(PGM_PTATTRS_PCD_SHIFT == X86_PTE_BIT_PCD); 446 AssertCompile(PGM_PTATTRS_A_SHIFT == X86_PTE_BIT_A); 447 AssertCompile(PGM_PTATTRS_D_SHIFT == X86_PTE_BIT_D); 448 AssertCompile(PGM_PTATTRS_PAT_SHIFT == X86_PTE_BIT_PAT); 449 AssertCompile(PGM_PTATTRS_G_SHIFT == X86_PTE_BIT_G); 450 AssertCompile(PGM_PTATTRS_W_MASK == X86_PTE_RW); 451 AssertCompile(PGM_PTATTRS_US_MASK == X86_PTE_US); 452 AssertCompile(PGM_PTATTRS_PWT_MASK == X86_PTE_PWT); 453 AssertCompile(PGM_PTATTRS_PCD_MASK == X86_PTE_PCD); 454 AssertCompile(PGM_PTATTRS_A_MASK == X86_PTE_A); 455 AssertCompile(PGM_PTATTRS_D_MASK == X86_PTE_D); 456 AssertCompile(PGM_PTATTRS_PAT_MASK == X86_PTE_PAT); 457 AssertCompile(PGM_PTATTRS_G_MASK == X86_PTE_G); 458 AssertCompile(PGM_PTATTRS_NX_MASK == X86_PTE_PAE_NX); 459 460 /* Verify those EPT bits that must map 1:1 (after shifting). */ 461 AssertCompile(PGM_PTATTRS_EPT_R_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_READ); 462 AssertCompile(PGM_PTATTRS_EPT_W_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_WRITE); 463 AssertCompile(PGM_PTATTRS_EPT_X_SUPER_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_EXECUTE); 464 AssertCompile(PGM_PTATTRS_EPT_IGNORE_PAT_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_IGNORE_PAT); 465 AssertCompile(PGM_PTATTRS_EPT_X_USER_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_USER_EXECUTE); 466 /** @} */ 467 468 469 /** 470 * Page table walk information. 471 * 472 * This provides extensive information regarding page faults (or EPT 473 * violations/misconfigurations) while traversing page tables. 474 */ 475 typedef struct PGMPTWALK 476 { 477 /** The linear address that is being resolved (input). */ 478 RTGCPTR GCPtr; 479 480 /** The second-level physical address (input/output). 481 * @remarks only valid if fIsSlat is set. */ 482 RTGCPHYS GCPhysNested; 483 484 /** The physical address that is the result of the walk (output). 485 * @remarks This is page aligned and only valid if fSucceeded is set. */ 486 RTGCPHYS GCPhys; 487 488 /** Set if the walk succeeded. */ 489 bool fSucceeded; 490 /** Whether this is a second-level address translation. */ 491 bool fIsSlat; 492 /** Whether the linear address (GCPtr) caused the second-level 493 * address translation. */ 494 bool fIsLinearAddrValid; 495 /** The level problem arrised at. 496 * PTE is level 1, PDE is level 2, PDPE is level 3, PML4 is level 4, CR3 is 497 * level 8. This is 0 on success. */ 498 uint8_t uLevel; 499 /** Set if the page isn't present. */ 500 bool fNotPresent; 501 /** Encountered a bad physical address. */ 502 bool fBadPhysAddr; 503 /** Set if there was reserved bit violations. */ 504 bool fRsvdError; 505 /** Set if it involves a big page (2/4 MB). */ 506 bool fBigPage; 507 /** Set if it involves a gigantic page (1 GB). */ 508 bool fGigantPage; 509 /** Set if the second-level fault was caused by an EPT misconfiguration. */ 510 bool fEptMisconfig; 511 bool afPadding[6]; 512 513 /** The effective attributes, PGM_PTATTRS_XXX. */ 514 PGMPTATTRS fEffective; 515 } PGMPTWALK; 516 /** Pointer to page walk information. */ 517 typedef PGMPTWALK *PPGMPTWALK; 518 /** Pointer to const page walk information. */ 519 typedef PGMPTWALK const *PCPGMPTWALK; 520 521 297 522 /** Macro for checking if the guest is using paging. 298 523 * @param enmMode PGMMODE_*. … … 351 576 #define PGM_MK_PG_IS_MMIO2 RT_BIT(1) 352 577 /** @}*/ 353 VMMDECL(int) PGMGstGetPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys); 354 VMMDECL(bool) PGMGstIsPagePresent(PVMCPUCC pVCpu, RTGCPTR GCPtr); 578 VMMDECL(int) PGMGstGetPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, PPGMPTWALK pWalk); 355 579 VMMDECL(int) PGMGstSetPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags); 356 580 VMMDECL(int) PGMGstModifyPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
Note:
See TracChangeset
for help on using the changeset viewer.