VirtualBox

Changeset 81196 in vbox


Ignore:
Timestamp:
Oct 9, 2019 8:24:12 PM (5 years ago)
Author:
vboxsync
Message:

EFI/Firmware: Applied the SplitPage fix to the copy in CpuMpPei too as well as surrounding page entry updates that I could easily spot. bugref:4643

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/CpuMpPei/CpuPaging.c

    r80721 r81196  
    1313#include <Library/CpuLib.h>
    1414#include <Library/BaseLib.h>
     15#ifdef VBOX
     16# define IN_RING0
     17# include <iprt/asm.h>
     18#endif
    1519
    1620#include "CpuMpPei.h"
     
    6872};
    6973
     74#ifdef VBOX
     75/**
     76 Safe page table entry write function, make 104% sure the compiler won't
     77 split up the access (fatal if modifying entries for current code or data).
     78
     79 @param[in] PageEntry        The page table entry to modify.*
     80 @param[in] CurrentPageEntry The old page table value (for cmpxchg8b).
     81 @param[in] NewPageEntry     What to write.
     82**/
     83static VOID SafePageTableEntryWrite64 (UINT64 volatile *PageEntry, UINT64 CurrentPageEntry, UINT64 NewPageEntry)
     84{
     85# ifdef VBOX
     86  ASMAtomicWriteU64(PageEntry, NewPageEntry); RT_NOREF(CurrentPageEntry);
     87# else
     88  for (;;) {
     89    UINT64 CurValue = InterlockedCompareExchange64(PageEntry, CurrentPageEntry, NewPageEntry);
     90    if (CurValue == CurrentPageEntry)
     91      return;
     92    CurrentPageEntry = CurValue;
     93  }
     94# endif
     95}
     96#endif
     97
    7098/**
    7199  The function will check if IA32 PAE is supported.
     
    235263RETURN_STATUS
    236264SplitPage (
     265#ifdef VBOX
     266  IN  UINT64 volatile                   *PageEntry,
     267#else
    237268  IN  UINT64                            *PageEntry,
     269#endif
    238270  IN  PAGE_ATTRIBUTE                    PageAttribute,
    239271  IN  PAGE_ATTRIBUTE                    SplitAttribute,
     
    241273  )
    242274{
     275#ifdef VBOX
     276  UINT64            CurrentPageEntry;
     277#endif
    243278  UINT64            BaseAddress;
    244279  UINT64            *NewPageEntry;
     
    265300  AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) &
    266301                   mPageAttributeTable[SplitTo].AddressMask;
     302#ifdef VBOX
     303  CurrentPageEntry = *PageEntry;
     304  BaseAddress    = CurrentPageEntry &
     305#else
    267306  BaseAddress    = *PageEntry &
     307#endif
    268308                   ~PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) &
    269309                   mPageAttributeTable[PageAttribute].AddressMask;
    270310  for (Index = 0; Index < SIZE_4KB / sizeof(UINT64); Index++) {
    271311    NewPageEntry[Index] = BaseAddress | AddressEncMask |
     312#ifdef VBOX
     313                          (CurrentPageEntry & PAGE_PROGATE_BITS);
     314#else
    272315                          ((*PageEntry) & PAGE_PROGATE_BITS);
     316#endif
    273317
    274318    if (SplitTo != PageMin) {
     
    283327  }
    284328
     329#ifdef VBOX
     330  SafePageTableEntryWrite64 (PageEntry, CurrentPageEntry,
     331                             (UINT64)(UINTN)NewPageEntry | AddressEncMask | PAGE_ATTRIBUTE_BITS);
     332#else
    285333  (*PageEntry) = (UINT64)(UINTN)NewPageEntry | AddressEncMask | PAGE_ATTRIBUTE_BITS;
     334#endif
    286335
    287336  return RETURN_SUCCESS;
     
    318367  )
    319368{
     369#ifdef VBOX
     370  UINT64 volatile                   *PageEntry;
     371  UINT64                            CurrentPageEntry;
     372#else
    320373  UINT64                            *PageEntry;
     374#endif
    321375  PAGE_ATTRIBUTE                    PageAttribute;
    322376  RETURN_STATUS                     Status;
     
    364418    // Just take care of 'present' bit for Stack Guard.
    365419    //
     420#ifdef VBOX
     421    CurrentPageEntry = *PageEntry;
     422    if ((CurrentPageEntry & IA32_PG_P) != (Attributes & IA32_PG_P))
     423      SafePageTableEntryWrite64 (PageEntry, CurrentPageEntry,
     424                                 (CurrentPageEntry & ~(UINT64)IA32_PG_P) | (Attributes & IA32_PG_P));
     425#else
    366426    if ((Attributes & IA32_PG_P) != 0) {
    367427      *PageEntry |= (UINT64)IA32_PG_P;
     
    369429      *PageEntry &= ~((UINT64)IA32_PG_P);
    370430    }
     431#endif
    371432
    372433    //
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette