Changeset 87529 in vbox for trunk/src/VBox/VMM/VMMR0
- Timestamp:
- Feb 2, 2021 10:56:44 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 142554
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp
r87522 r87529 1791 1791 * 1792 1792 * @returns VBox status code. 1793 * @param hMemObj The ring-0 memory object associated withthe allocation.1793 * @param phMemObj Where to return the handle to the allocation. 1794 1794 * @param paAllocInfo The pointer to the first element of the VMX 1795 1795 * page-allocation info object array. 1796 1796 * @param cEntries The number of elements in the @a paAllocInfo array. 1797 1797 */ 1798 static int hmR0VmxPagesAllocZ(RTR0MEMOBJ hMemObj, PVMXPAGEALLOCINFO paAllocInfo, uint32_t cEntries) 1799 { 1798 static int hmR0VmxPagesAllocZ(PRTR0MEMOBJ phMemObj, PVMXPAGEALLOCINFO paAllocInfo, uint32_t cEntries) 1799 { 1800 *phMemObj = NIL_RTR0MEMOBJ; 1801 1800 1802 /* Figure out how many pages to allocate. */ 1801 1803 uint32_t cPages = 0; … … 1806 1808 if (cPages) 1807 1809 { 1808 size_t const cbPages = cPages << X86_PAGE_4K_SHIFT;1809 int rc = RTR0MemObjAllocPage( &hMemObj, cbPages, false /* fExecutable */);1810 size_t const cbPages = cPages << PAGE_SHIFT; 1811 int rc = RTR0MemObjAllocPage(phMemObj, cbPages, false /* fExecutable */); 1810 1812 if (RT_FAILURE(rc)) 1811 1813 return rc; 1812 1814 1813 1815 /* Zero the contents and assign each page to the corresponding VMX page-allocation entry. */ 1814 void *pvFirstPage = RTR0MemObjAddress( hMemObj);1815 ASMMemZero32(pvFirstPage, cbPages);1816 void *pvFirstPage = RTR0MemObjAddress(*phMemObj); 1817 RT_BZERO(pvFirstPage, cbPages); 1816 1818 1817 1819 uint32_t iPage = 0; … … 1819 1821 if (paAllocInfo[i].fValid) 1820 1822 { 1821 RTHCPHYS const HCPhysPage = RTR0MemObjGetPagePhysAddr( hMemObj, iPage);1823 RTHCPHYS const HCPhysPage = RTR0MemObjGetPagePhysAddr(*phMemObj, iPage); 1822 1824 void *pvPage = (void *)((uintptr_t)pvFirstPage + (iPage << X86_PAGE_4K_SHIFT)); 1823 1825 Assert(HCPhysPage && HCPhysPage != NIL_RTHCPHYS); … … 1914 1916 bool const fShadowVmcs = !fIsNstGstVmcs ? pVM->hm.s.vmx.fUseVmcsShadowing : pVM->cpum.ro.GuestFeatures.fVmxVmcsShadowing; 1915 1917 Assert(!pVM->cpum.ro.GuestFeatures.fVmxVmcsShadowing); /* VMCS shadowing is not yet exposed to the guest. */ 1916 VMXPAGEALLOCINFO aAllocInfo[] = { 1918 VMXPAGEALLOCINFO aAllocInfo[] = 1919 { 1917 1920 { true, 0 /* Unused */, &pVmcsInfo->HCPhysVmcs, &pVmcsInfo->pvVmcs }, 1918 1921 { true, 0 /* Unused */, &pVmcsInfo->HCPhysGuestMsrLoad, &pVmcsInfo->pvGuestMsrLoad }, … … 1922 1925 }; 1923 1926 1924 int rc = hmR0VmxPagesAllocZ( pVmcsInfo->hMemObj, &aAllocInfo[0], RT_ELEMENTS(aAllocInfo));1927 int rc = hmR0VmxPagesAllocZ(&pVmcsInfo->hMemObj, &aAllocInfo[0], RT_ELEMENTS(aAllocInfo)); 1925 1928 if (RT_FAILURE(rc)) 1926 1929 return rc; … … 2022 2025 bool const fVirtApicAccess = RT_BOOL(pVM->hm.s.vmx.Msrs.ProcCtls2.n.allowed1 & VMX_PROC_CTLS2_VIRT_APIC_ACCESS); 2023 2026 bool const fUseVmcsShadowing = pVM->hm.s.vmx.fUseVmcsShadowing; 2024 VMXPAGEALLOCINFO aAllocInfo[] = { 2027 VMXPAGEALLOCINFO aAllocInfo[] = 2028 { 2025 2029 { fVirtApicAccess, 0 /* Unused */, &pVM->hm.s.vmx.HCPhysApicAccess, (PRTR0PTR)&pVM->hm.s.vmx.pbApicAccess }, 2026 2030 { fUseVmcsShadowing, 0 /* Unused */, &pVM->hm.s.vmx.HCPhysVmreadBitmap, &pVM->hm.s.vmx.pvVmreadBitmap }, … … 2031 2035 }; 2032 2036 2033 int rc = hmR0VmxPagesAllocZ(pVM->hm.s.vmx.hMemObj, &aAllocInfo[0], RT_ELEMENTS(aAllocInfo)); 2034 if (RT_FAILURE(rc)) 2035 goto cleanup; 2036 2037 int rc = hmR0VmxPagesAllocZ(&pVM->hm.s.vmx.hMemObj, &aAllocInfo[0], RT_ELEMENTS(aAllocInfo)); 2038 if (RT_SUCCESS(rc)) 2039 { 2037 2040 #ifdef VBOX_WITH_NESTED_HWVIRT_VMX 2038 /* Allocate the shadow VMCS-fields array. */ 2039 if (fUseVmcsShadowing) 2040 { 2041 Assert(!pVM->hm.s.vmx.cShadowVmcsFields); 2042 Assert(!pVM->hm.s.vmx.cShadowVmcsRoFields); 2043 pVM->hm.s.vmx.paShadowVmcsFields = (uint32_t *)RTMemAllocZ(sizeof(g_aVmcsFields)); 2044 pVM->hm.s.vmx.paShadowVmcsRoFields = (uint32_t *)RTMemAllocZ(sizeof(g_aVmcsFields)); 2045 if (RT_LIKELY( pVM->hm.s.vmx.paShadowVmcsFields 2046 && pVM->hm.s.vmx.paShadowVmcsRoFields)) 2047 { /* likely */ } 2048 else 2049 { 2050 rc = VERR_NO_MEMORY; 2051 goto cleanup; 2052 } 2053 } 2041 /* Allocate the shadow VMCS-fields array. */ 2042 if (fUseVmcsShadowing) 2043 { 2044 Assert(!pVM->hm.s.vmx.cShadowVmcsFields); 2045 Assert(!pVM->hm.s.vmx.cShadowVmcsRoFields); 2046 pVM->hm.s.vmx.paShadowVmcsFields = (uint32_t *)RTMemAllocZ(sizeof(g_aVmcsFields)); 2047 pVM->hm.s.vmx.paShadowVmcsRoFields = (uint32_t *)RTMemAllocZ(sizeof(g_aVmcsFields)); 2048 if (!pVM->hm.s.vmx.paShadowVmcsFields || !pVM->hm.s.vmx.paShadowVmcsRoFields) 2049 rc = VERR_NO_MEMORY; 2050 } 2054 2051 #endif 2055 2052 2056 /* 2057 * Allocate per-VCPU VT-x structures. 2058 */ 2059 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++) 2060 { 2061 /* Allocate the guest VMCS structures. */ 2062 PVMCPUCC pVCpu = VMCC_GET_CPU(pVM, idCpu); 2063 rc = hmR0VmxAllocVmcsInfo(pVCpu, &pVCpu->hmr0.s.vmx.VmcsInfo, false /* fIsNstGstVmcs */); 2064 if (RT_FAILURE(rc)) 2065 goto cleanup; 2053 /* 2054 * Allocate per-VCPU VT-x structures. 2055 */ 2056 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus && RT_SUCCESS(rc); idCpu++) 2057 { 2058 /* Allocate the guest VMCS structures. */ 2059 PVMCPUCC pVCpu = VMCC_GET_CPU(pVM, idCpu); 2060 rc = hmR0VmxAllocVmcsInfo(pVCpu, &pVCpu->hmr0.s.vmx.VmcsInfo, false /* fIsNstGstVmcs */); 2066 2061 2067 2062 #ifdef VBOX_WITH_NESTED_HWVIRT_VMX 2068 /* Allocate the nested-guest VMCS structures, when the VMX feature is exposed to the guest. */ 2069 if (pVM->cpum.ro.GuestFeatures.fVmx) 2070 { 2071 rc = hmR0VmxAllocVmcsInfo(pVCpu, &pVCpu->hmr0.s.vmx.VmcsInfoNstGst, true /* fIsNstGstVmcs */); 2072 if (RT_FAILURE(rc)) 2073 goto cleanup; 2074 } 2063 /* Allocate the nested-guest VMCS structures, when the VMX feature is exposed to the guest. */ 2064 if (pVM->cpum.ro.GuestFeatures.fVmx && RT_SUCCESS(rc)) 2065 rc = hmR0VmxAllocVmcsInfo(pVCpu, &pVCpu->hmr0.s.vmx.VmcsInfoNstGst, true /* fIsNstGstVmcs */); 2075 2066 #endif 2076 } 2077 2078 return VINF_SUCCESS; 2079 2080 cleanup: 2067 } 2068 if (RT_SUCCESS(rc)) 2069 return VINF_SUCCESS; 2070 } 2081 2071 hmR0VmxStructsFree(pVM); 2082 Assert(rc != VINF_SUCCESS);2083 2072 return rc; 2084 2073 }
Note:
See TracChangeset
for help on using the changeset viewer.