VirtualBox

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


Ignore:
Timestamp:
May 22, 2014 4:42:22 AM (11 years ago)
Author:
vboxsync
Message:

VMM/GIM: Hyper-V provider, work-in-progress.

Location:
trunk/src/VBox/VMM/VMMR3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/GIM.cpp

    r50994 r51333  
    2828 * A GIM provider implements a particular hypervisor interface such as Microsoft
    2929 * Hyper-V, Linux KVM and so on. It hooks into various components in the VMM to
    30  * ease the guest in running under a recognized virtualized environment. This is
    31  * also referred to as paravirtualization interfaces.
     30 * ease the guest in running under a recognized, virtualized environment. This
     31 * is also referred to as paravirtualization interfaces.
    3232 *
    3333 * The idea behind this is primarily for making guests more accurate and
     
    3939 * itself, resulting in higher accuracy and saving several CPU cycles.
    4040 *
    41  * Only one provider can be active for a running VM.
     41 * At most, only one GIM provider can be active for a running VM and cannot be
     42 * changed during the lifetime of the VM.
    4243 */
    4344
     
    105106    AssertLogRelRCReturn(rc, rc);
    106107
     108    /** @cfgm{GIM/Version, uint32_t}
     109     * The interface version. The default is 0, which means "provide the most
     110     * up-to-date implementation". */
     111    uint32_t uVersion;
     112    rc = CFGMR3QueryU32Def(pCfgNode, "Version", &uVersion, 0 /* default */);
     113    AssertLogRelRCReturn(rc, rc);
     114
    107115    /*
    108116     * Setup the GIM provider for this VM.
    109117     */
    110     LogRel(("GIM: Using provider \"%s\"\n", szProvider));
     118    LogRel(("GIM: Using provider \"%s\" version %u\n", szProvider, uVersion));
    111119    if (!RTStrCmp(szProvider, "None"))
    112120    {
    113121        Assert(!pVM->gim.s.fEnabled);
    114         pVM->gim.s.enmProvider = GIMPROVIDER_NONE;
     122        pVM->gim.s.enmProviderId = GIMPROVIDERID_NONE;
    115123    }
    116124    else
    117125    {
    118126        pVM->gim.s.fEnabled = true;
     127        pVM->gim.s.u32Version = uVersion;
    119128        if (!RTStrCmp(szProvider, "Minimal"))
    120129        {
    121             pVM->gim.s.enmProvider = GIMPROVIDER_MINIMAL;
     130            pVM->gim.s.enmProviderId = GIMPROVIDERID_MINIMAL;
    122131            rc = GIMR3MinimalInit(pVM);
    123132        }
    124133        else if (!RTStrCmp(szProvider, "HyperV"))
    125134        {
    126             pVM->gim.s.enmProvider = GIMPROVIDER_HYPERV;
     135            pVM->gim.s.enmProviderId = GIMPROVIDERID_HYPERV;
    127136            rc = GIMR3HvInit(pVM);
    128137        }
     
    157166    }
    158167
    159     switch (pVM->gim.s.enmProvider)
    160     {
    161         case GIMPROVIDER_MINIMAL:
     168    switch (pVM->gim.s.enmProviderId)
     169    {
     170        case GIMPROVIDERID_MINIMAL:
    162171        {
    163172            GIMR3MinimalRelocate(pVM, offDelta);
     
    165174        }
    166175
    167         case GIMPROVIDER_HYPERV:
     176        case GIMPROVIDERID_HYPERV:
    168177        {
    169178            GIMR3HvRelocate(pVM, offDelta);
     
    171180        }
    172181
    173         case GIMPROVIDER_KVM:            /** @todo KVM. */
     182        case GIMPROVIDERID_KVM:            /** @todo KVM. */
    174183        default:
    175184        {
    176             AssertMsgFailed(("Invalid provider id %#x\n", pVM->gim.s.enmProvider));
     185            AssertMsgFailed(("Invalid provider Id %#x\n", pVM->gim.s.enmProviderId));
    177186            break;
    178187        }
  • trunk/src/VBox/VMM/VMMR3/GIMHv.cpp

    r50953 r51333  
    2525#include <iprt/assert.h>
    2626#include <iprt/err.h>
     27#include <iprt/string.h>
    2728
    2829#include <VBox/vmm/cpum.h>
     
    3031#include <VBox/vmm/hm.h>
    3132#include <VBox/vmm/pdmapi.h>
     33#include <VBox/version.h>
    3234
    3335/*******************************************************************************
     
    3739
    3840
     41/**
     42 * Initializes the Hyper-V GIM provider.
     43 *
     44 * @returns VBox status code.
     45 * @param   pVM         Pointer to the VM.
     46 * @param   uVersion    The interface version this VM should use.
     47 */
    3948VMMR3_INT_DECL(int) GIMR3HvInit(PVM pVM)
    4049{
    4150    AssertReturn(pVM, VERR_INVALID_PARAMETER);
    42     AssertReturn(pVM->gim.s.enmProvider == GIMPROVIDER_HYPERV, VERR_INTERNAL_ERROR_5);
     51    AssertReturn(pVM->gim.s.enmProviderId == GIMPROVIDERID_HYPERV, VERR_INTERNAL_ERROR_5);
    4352
    4453    int rc;
     54#if 0
    4555    pVM->gim.s.pfnHypercallR3 = &GIMHvHypercall;
    4656    if (!HMIsEnabled(pVM))
     
    5161    rc = PDMR3LdrGetSymbolR0(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallR0);
    5262    AssertRCReturn(rc, rc);
     63#endif
     64
     65    /*
     66     * Determine interface capabilities based on the version.
     67     */
     68    uint32_t uBaseFeat    = 0;
     69    uint32_t uPartFlags   = 0;
     70    uint32_t uPowMgmtFeat = 0;
     71    uint32_t uMiscFeat    = 0;
     72    uint32_t uHyperHints  = 0;
     73    if (!pVM->gim.s.u32Version)
     74    {
     75        uBaseFeat = GIM_HV_BASE_FEAT_PART_REF_COUNT_MSR;
     76        pVM->gim.s.u.hv.u16HyperIdVersionMajor = VBOX_VERSION_MAJOR;
     77        pVM->gim.s.u.hv.u16HyperIdVersionMajor = VBOX_VERSION_MINOR;
     78        pVM->gim.s.u.hv.u32HyperIdBuildNumber  = VBOX_VERSION_BUILD;
     79    }
    5380
    5481    /*
     
    5784    CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
    5885
    59     /** @todo Register CPUID leaves, MSR ranges with CPUM. */
     86    /*
     87     * Modify the standard hypervisor leaves for Hyper-V.
     88     */
     89    CPUMCPUIDLEAF HyperLeaf;
     90    RT_ZERO(HyperLeaf);
     91    HyperLeaf.uLeaf        = UINT32_C(0x40000000);
     92    HyperLeaf.uEax         = UINT32_C(0x40000005); /* Minimum value for Hyper-V */
     93    HyperLeaf.uEbx         = 0x7263694D;           /* 'Micr' */
     94    HyperLeaf.uEcx         = 0x666F736F;           /* 'osof' */
     95    HyperLeaf.uEdx         = 0x76482074;           /* 't Hv' */
     96    rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
     97    AssertLogRelRCReturn(rc, rc);
     98
     99    HyperLeaf.uLeaf        = UINT32_C(0x40000001);
     100    HyperLeaf.uEax         = 0x31237648;           /* 'Hv#1' */
     101    HyperLeaf.uEbx         = 0;                    /* Reserved */
     102    HyperLeaf.uEcx         = 0;                    /* Reserved */
     103    HyperLeaf.uEdx         = 0;                    /* Reserved */
     104    rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
     105    AssertLogRelRCReturn(rc, rc);
     106
     107    /*
     108     * Add Hyper-V specific leaves.
     109     */
     110    HyperLeaf.uLeaf        = UINT32_C(0x40000002); /* MBZ until MSR_HV_GUEST_OS_ID is set by the guest. */
     111    HyperLeaf.uEax         = 0;
     112    HyperLeaf.uEbx         = 0;
     113    HyperLeaf.uEcx         = 0;
     114    HyperLeaf.uEdx         = 0;
     115    rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
     116    AssertLogRelRCReturn(rc, rc);
     117
     118    HyperLeaf.uLeaf        = UINT32_C(0x40000003);
     119    HyperLeaf.uEax         = uBaseFeat;
     120    HyperLeaf.uEbx         = uPartFlags;
     121    HyperLeaf.uEcx         = uPowMgmtFeat;
     122    HyperLeaf.uEdx         = uMiscFeat;
     123    rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
     124    AssertLogRelRCReturn(rc, rc);
     125
     126    /*
     127     * Register the complete MSR range for Hyper-V.
     128     */
     129    CPUMMSRRANGE MsrRange;
     130    RT_ZERO(MsrRange);
     131    MsrRange.uFirst     = UINT32_C(0x40000000);
     132    MsrRange.uLast      = UINT32_C(0x40000105);
     133    MsrRange.enmRdFn    = kCpumMsrRdFn_Gim;
     134    MsrRange.enmWrFn    = kCpumMsrWrFn_Gim;
     135    RTStrCopy(MsrRange.szName, sizeof(MsrRange.szName), "Hyper-V");
     136    rc = CPUMR3MsrRangesInsert(pVM, &MsrRange);
     137    AssertLogRelRCReturn(rc, rc);
     138
     139
    60140    return VINF_SUCCESS;
    61141}
     
    64144VMMR3_INT_DECL(void) GIMR3HvRelocate(PVM pVM, RTGCINTPTR offDelta)
    65145{
    66     int rc = PDMR3LdrGetSymbolRC(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallRC);
    67     AssertFatalRC(rc);
     146//    int rc = PDMR3LdrGetSymbolRC(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallRC);
     147//    AssertFatalRC(rc);
    68148}
    69149
  • trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp

    r50994 r51333  
    3636{
    3737    AssertReturn(pVM, VERR_INVALID_PARAMETER);
    38     AssertReturn(pVM->gim.s.enmProvider == GIMPROVIDER_MINIMAL, VERR_INTERNAL_ERROR_5);
     38    AssertReturn(pVM->gim.s.enmProviderId == GIMPROVIDERID_MINIMAL, VERR_INTERNAL_ERROR_5);
    3939
    4040    Assert(CPUMGetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP));
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