VirtualBox

Changeset 71296 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Mar 10, 2018 12:53:26 AM (7 years ago)
Author:
vboxsync
Message:

NEM: Updates for build 17115 and fixes for AMD-V. bugref:9044

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp

    r71293 r71296  
    5454#include <iprt/path.h>
    5555#include <iprt/string.h>
     56#include <iprt/system.h>
    5657
    5758
     
    7172/** VID I/O control detection: Fake timeout input. */
    7273#define NEM_WIN_IOCTL_DETECTOR_FAKE_TIMEOUT         UINT32_C(0x00080286)
     74
     75
     76/*********************************************************************************************************************************
     77*   Structures and Typedefs                                                                                                      *
     78*********************************************************************************************************************************/
     79#ifndef NEM_WIN_USE_17110_PLUS_WDK
     80typedef HRESULT (WINAPI *PFNWHVGETCAPABILITY_17110)(WHV_CAPABILITY_CODE, void *, uint32_t, uint32_t *);
     81typedef HRESULT (WINAPI *PFNWHVSETPARTITIONPROPERTY_17110)(WHV_PARTITION_HANDLE, WHV_PARTITION_PROPERTY_CODE, void *, uint32_t);
     82#endif
    7383
    7484
     
    111121#endif
    112122/** @} */
     123
     124/** The Windows build number. */
     125static uint32_t g_uBuildNo = 17110;
     126
    113127
    114128
     
    212226
    213227# define VidMessageSlotHandleAndGetNext             g_pfnVidMessageSlotHandleAndGetNext
    214 # define VidStartVirtualProcessor                    g_pfnVidStartVirtualProcessor
     228# define VidStartVirtualProcessor                   g_pfnVidStartVirtualProcessor
    215229# define VidStopVirtualProcessor                    g_pfnVidStopVirtualProcessor
    216230
     
    512526
    513527/**
     528 * Wrapper for different WHvGetCapability signatures.
     529 */
     530DECLINLINE(HRESULT) WHvGetCapabilityWrapper(WHV_CAPABILITY_CODE enmCap, WHV_CAPABILITY *pOutput, uint32_t cbOutput)
     531{
     532#ifdef NEM_WIN_USE_17110_PLUS_WDK
     533    return g_pfnWHvGetCapability(enmCap, pOutput, cbOutput, NULL);
     534#else
     535    if (g_uBuildNo >= 17110)
     536    {
     537        PFNWHVGETCAPABILITY_17110 pfnNewVersion = (PFNWHVGETCAPABILITY_17110)g_pfnWHvGetCapability;
     538        return pfnNewVersion(enmCap, &pOutput->HypervisorPresent, cbOutput - RT_OFFSETOF(WHV_CAPABILITY, HypervisorPresent), NULL);
     539    }
     540    return g_pfnWHvGetCapability(enmCap, pOutput, cbOutput);
     541#endif
     542}
     543
     544
     545/**
    514546 * Worker for nemR3NativeInit that gets the hypervisor capabilities.
    515547 *
     
    543575    RT_ZERO(Caps);
    544576    SetLastError(0);
    545     HRESULT hrc = WHvGetCapability(WHvCapabilityCodeHypervisorPresent, &Caps, sizeof(Caps));
     577    HRESULT hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeHypervisorPresent, &Caps, sizeof(Caps));
    546578    DWORD   rcWin = GetLastError();
    547579    if (FAILED(hrc))
     
    563595     */
    564596    RT_ZERO(Caps);
    565     hrc = WHvGetCapability(WHvCapabilityCodeExtendedVmExits, &Caps, sizeof(Caps));
     597    hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeExtendedVmExits, &Caps, sizeof(Caps));
    566598    if (FAILED(hrc))
    567599        return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED,
     
    583615     */
    584616    RT_ZERO(Caps);
    585     hrc = WHvGetCapability(WHvCapabilityCodeFeatures, &Caps, sizeof(Caps));
     617    hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeFeatures, &Caps, sizeof(Caps));
    586618    if (FAILED(hrc))
    587619        return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED,
     
    596628     */
    597629    RT_ZERO(Caps);
    598     hrc = WHvGetCapability(WHvCapabilityCodeProcessorVendor, &Caps, sizeof(Caps));
     630    hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeProcessorVendor, &Caps, sizeof(Caps));
    599631    if (FAILED(hrc))
    600632        return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED,
     
    621653     */
    622654    RT_ZERO(Caps);
    623     hrc = WHvGetCapability(WHvCapabilityCodeProcessorFeatures, &Caps, sizeof(Caps));
     655    hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeProcessorFeatures, &Caps, sizeof(Caps));
    624656    if (FAILED(hrc))
    625657        return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED,
     
    680712     */
    681713    RT_ZERO(Caps);
    682     hrc = WHvGetCapability(WHvCapabilityCodeProcessorClFlushSize, &Caps, sizeof(Caps));
     714    hrc = WHvGetCapabilityWrapper(WHvCapabilityCodeProcessorClFlushSize, &Caps, sizeof(Caps));
    683715    if (FAILED(hrc))
    684716        return RTErrInfoSetF(pErrInfo, VERR_NEM_INIT_FAILED,
     
    710742            {
    711743                RT_ZERO(Caps);
    712                 hrc = WHvGetCapability((WHV_CAPABILITY_CODE)i, &Caps, sizeof(Caps));
     744                hrc = WHvGetCapabilityWrapper((WHV_CAPABILITY_CODE)i, &Caps, sizeof(Caps));
    713745                if (SUCCEEDED(hrc))
    714746                    LogRel(("NEM: Warning! Unknown capability %#x returning: %.*Rhxs\n", i, sizeof(Caps), &Caps));
     
    9771009
    9781010/**
     1011 * Wrapper for different WHvSetPartitionProperty signatures.
     1012 */
     1013DECLINLINE(HRESULT) WHvSetPartitionPropertyWrapper(WHV_PARTITION_HANDLE hPartition, WHV_PARTITION_PROPERTY_CODE enmProp,
     1014                                                   WHV_PARTITION_PROPERTY *pInput, uint32_t cbInput)
     1015{
     1016#ifdef NEM_WIN_USE_17110_PLUS_WDK
     1017    return g_pfnWHvSetPartitionProperty(hPartition, enmProp, pInput, cbInput, NULL);
     1018#else
     1019    pInput->PropertyCode = enmProp;
     1020    if (g_uBuildNo >= 17110)
     1021    {
     1022        PFNWHVSETPARTITIONPROPERTY_17110 pfnNewVersion = (PFNWHVSETPARTITIONPROPERTY_17110)g_pfnWHvSetPartitionProperty;
     1023        return pfnNewVersion(hPartition, enmProp, &pInput->ExtendedVmExits,
     1024                             cbInput - RT_UOFFSETOF(WHV_PARTITION_PROPERTY, ExtendedVmExits));
     1025    }
     1026    return g_pfnWHvSetPartitionProperty(hPartition, pInput, cbInput);
     1027#endif
     1028}
     1029
     1030
     1031/**
    9791032 * Creates and sets up a Hyper-V (exo) partition.
    9801033 *
     
    10121065    WHV_PARTITION_PROPERTY Property;
    10131066    RT_ZERO(Property);
    1014     Property.PropertyCode   = WHvPartitionPropertyCodeProcessorCount;
    10151067    Property.ProcessorCount = pVM->cCpus;
    1016     hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property));
     1068    hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorCount, &Property, sizeof(Property));
    10171069    if (SUCCEEDED(hrc))
    10181070    {
    10191071        RT_ZERO(Property);
    1020         Property.PropertyCode                  = WHvPartitionPropertyCodeExtendedVmExits;
     1072#if 0
    10211073        Property.ExtendedVmExits.X64CpuidExit  = pVM->nem.s.fExtendedCpuIdExit;
    10221074        Property.ExtendedVmExits.X64MsrExit    = pVM->nem.s.fExtendedMsrExit;
    10231075        Property.ExtendedVmExits.ExceptionExit = pVM->nem.s.fExtendedXcptExit;
    1024         hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property));
     1076#endif
     1077        hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeExtendedVmExits, &Property, sizeof(Property));
    10251078        if (SUCCEEDED(hrc))
    10261079        {
     
    10651118int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced)
    10661119{
     1120    g_uBuildNo = RTSystemGetNtBuildNo();
     1121
    10671122    /*
    10681123     * Error state.
     
    11591214     * Continue setting up the partition now that we've got most of the CPUID feature stuff.
    11601215     */
    1161 
    1162     /* Not sure if we really need to set the vendor. */
    11631216    WHV_PARTITION_PROPERTY Property;
     1217    HRESULT                hrc;
     1218
     1219#if 0
     1220    /* Not sure if we really need to set the vendor.
     1221       Update: Apparently we don't. WHvPartitionPropertyCodeProcessorVendor was removed in 17110. */
    11641222    RT_ZERO(Property);
    1165     Property.PropertyCode    = WHvPartitionPropertyCodeProcessorVendor;
    11661223    Property.ProcessorVendor = pVM->nem.s.enmCpuVendor == CPUMCPUVENDOR_AMD ? WHvProcessorVendorAmd
    11671224                             : WHvProcessorVendorIntel;
    1168     HRESULT hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property));
     1225    hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorVendor, &Property, sizeof(Property));
    11691226    if (FAILED(hrc))
    11701227        return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS,
    11711228                          "Failed to set WHvPartitionPropertyCodeProcessorVendor to %u: %Rhrc (Last=%#x/%u)",
    11721229                          Property.ProcessorVendor, hrc, RTNtLastStatusValue(), RTNtLastErrorValue());
     1230#endif
    11731231
    11741232    /* Not sure if we really need to set the cache line flush size. */
    11751233    RT_ZERO(Property);
    1176     Property.PropertyCode         = WHvPartitionPropertyCodeProcessorClFlushSize;
    11771234    Property.ProcessorClFlushSize = pVM->nem.s.cCacheLineFlushShift;
    1178     hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property));
     1235    hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorClFlushSize, &Property, sizeof(Property));
    11791236    if (FAILED(hrc))
    11801237        return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS,
     
    11891246    /* Set the partition property. */
    11901247    RT_ZERO(Property);
    1191     Property.PropertyCode               = WHvPartitionPropertyCodeProcessorFeatures;
    11921248    Property.ProcessorFeatures.AsUINT64 = pVM->nem.s.uCpuFeatures.u64;
    1193     hrc = WHvSetPartitionProperty(hPartition, &Property, sizeof(Property));
     1249    hrc = WHvSetPartitionPropertyWrapper(hPartition, WHvPartitionPropertyCodeProcessorFeatures, &Property, sizeof(Property));
    11941250    if (FAILED(hrc))
    11951251        return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS,
     
    24912547 *        information getters.
    24922548 *
     2549 *   Update: All concerns have been addressed in build 17110.
     2550 *
    24932551 *
    24942552 * - The WHvGetPartitionProperty function uses the same weird design as
    24952553 *   WHvGetCapability, see above.
     2554 *
     2555 *   Update: All concerns have been addressed in build 17110.
    24962556 *
    24972557 *
     
    25122572 *        and others for typical pattern for generic information setters and
    25132573 *        getters.
     2574 *
     2575 *   Update: All concerns have been addressed in build 17110.
     2576 *
    25142577 *
    25152578 *
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