VirtualBox

Changeset 71108 in vbox


Ignore:
Timestamp:
Feb 22, 2018 3:38:35 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120973
Message:

Added speculation control settings to API, refined implementation.

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r70712 r71108  
    907907    bool                fIBPBOnVMExit;          //< added out of cycle, after 1.16 was out.
    908908    bool                fIBPBOnVMEntry;         //< added out of cycle, after 1.16 was out.
     909    bool                fSpecCtrl;              //< added out of cycle, after 1.16 was out.
     910    bool                fSpecCtrlByHost;        //< added out of cycle, after 1.16 was out.
    909911    bool                fNestedHWVirt;          //< requires settings version 1.17 (VirtualBox 6.0)
    910912    typedef enum LongModeType { LongMode_Enabled, LongMode_Disabled, LongMode_Legacy } LongModeType;
  • trunk/include/VBox/vmm/cpum.h

    r71091 r71108  
    12231223VMMR0_INT_DECL(void)        CPUMR0SetGuestTscAux(PVMCPU pVCpu, uint64_t uValue);
    12241224VMMR0_INT_DECL(uint64_t)    CPUMR0GetGuestTscAux(PVMCPU pVCpu);
     1225VMMR0_INT_DECL(void)        CPUMR0SetGuestSpecCtrl(PVMCPU pVCpu, uint64_t uValue);
     1226VMMR0_INT_DECL(uint64_t)    CPUMR0GetGuestSpecCtrl(PVMCPU pVCpu);
    12251227/** @} */
    12261228
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r70766 r71108  
    514514                     "                            [--ibpb-on-vm-exit on|off]\n"
    515515                     "                            [--ibpb-on-vm-entry on|off]\n"
     516                     "                            [--spec-ctrl on|off]\n"
    516517                     "                            [--nested-hw-virt on|off]\n"
    517518                     "                            [--cpu-profile \"host|Intel 80[86|286|386]\"]\n"
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r70712 r71108  
    7777    MODIFYVM_IBPB_ON_VM_EXIT,
    7878    MODIFYVM_IBPB_ON_VM_ENTRY,
     79    MODIFYVM_SPEC_CTRL,
    7980    MODIFYVM_NESTED_HW_VIRT,
    8081    MODIFYVM_CPUS,
     
    260261    { "--ibpb-on-vm-exit",          MODIFYVM_IBPB_ON_VM_EXIT,           RTGETOPT_REQ_BOOL_ONOFF },
    261262    { "--ibpb-on-vm-entry",         MODIFYVM_IBPB_ON_VM_ENTRY,          RTGETOPT_REQ_BOOL_ONOFF },
    262     { "--nested-hw-virt",           MODIFYVM_NESTED_HW_VIRT,             RTGETOPT_REQ_BOOL_ONOFF },
     263    { "--spec-ctrl",                MODIFYVM_SPEC_CTRL,                 RTGETOPT_REQ_BOOL_ONOFF },
     264    { "--nested-hw-virt",           MODIFYVM_NESTED_HW_VIRT,            RTGETOPT_REQ_BOOL_ONOFF },
    263265    { "--cpuid-set",                MODIFYVM_SETCPUID,                  RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_HEX },
    264266    { "--cpuid-remove",             MODIFYVM_DELCPUID,                  RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_HEX },
     
    808810                break;
    809811
     812            case MODIFYVM_SPEC_CTRL:
     813                CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_SpecCtrl, ValueUnion.f));
     814                break;
     815
    810816            case MODIFYVM_NESTED_HW_VIRT:
    811817                CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_HWVirt, ValueUnion.f));
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r70712 r71108  
    10091009        host CPU supports it.  This setting will significantly slow down workloads
    10101010        causing many VM exits, so it is only recommended for situation where there
    1011         real need to be paranoid.
     1011        is a real need to be paranoid.
    10121012      </desc>
    10131013    </const>
     
    10171017        host CPU supports it.  This setting will significantly slow down workloads
    10181018        causing many VM exits, so it is only recommended for situation where there
    1019         real need to be paranoid.
     1019        is a real need to be paranoid.
    10201020      </desc>
    10211021    </const>
     
    10241024        Enabled the hardware virtualization (AMD-V/VT-x) feature on the guest CPU.
    10251025        This requires hardware virtualization on the host CPU.
     1026      </desc>
     1027    </const>
     1028    <const name="SpecCtrl"              value="9">
     1029      <desc>
     1030        If set, the speculation control CPUID bits and MSRs, when available on the
     1031        host, are exposed to the guest. Depending on the host CPU and operating
     1032        system, this may significantly slow down workloads causing many VM exits.
     1033      </desc>
     1034    </const>
     1035    <const name="SpecCtrlByHost"        value="10">
     1036      <desc>
     1037        If set, the speculation controls are managed by the host. This is intended
     1038        for guests which do not set the speculation controls themselves.
    10261039      </desc>
    10271040    </const>
  • trunk/src/VBox/Main/include/MachineImpl.h

    r70712 r71108  
    290290        BOOL                mIBPBOnVMExit;
    291291        BOOL                mIBPBOnVMEntry;
     292        BOOL                mSpecCtrl;
     293        BOOL                mSpecCtrlByHost;
    292294        BOOL                mNestedHWVirt;
    293295        ULONG               mCPUCount;
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r70772 r71108  
    10221022        }
    10231023
     1024        /* Speculation Control. */
     1025        BOOL fSpecCtrl = FALSE;
     1026        hrc = pMachine->GetCPUProperty(CPUPropertyType_SpecCtrl, &fSpecCtrl);      H();
     1027        InsertConfigInteger(pCPUM, "SpecCtrl", fSpecCtrl);
     1028
    10241029        /* Nested VT-x / AMD-V. */
    10251030        BOOL fNestedHWVirt = FALSE;
     
    11721177        hrc = pMachine->GetCPUProperty(CPUPropertyType_IBPBOnVMEntry, &fIBPBOnVMEntry); H();
    11731178        InsertConfigInteger(pHM, "IBPBOnVMEntry", fIBPBOnVMEntry);
     1179
     1180        BOOL fSpecCtrlByHost = false;
     1181        hrc = pMachine->GetCPUProperty(CPUPropertyType_SpecCtrlByHost, &fSpecCtrlByHost); H();
     1182        InsertConfigInteger(pHM, "SpecCtrlByHost", fSpecCtrlByHost);
    11741183
    11751184        /* Reset overwrite. */
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r70712 r71108  
    198198    mIBPBOnVMExit = false;
    199199    mIBPBOnVMEntry = false;
     200    mSpecCtrl = false;
     201    mSpecCtrlByHost = false;
    200202    mNestedHWVirt = false;
    201203    mHPETEnabled = false;
     
    22672269            break;
    22682270
     2271        case CPUPropertyType_SpecCtrl:
     2272            *aValue = mHWData->mSpecCtrl;
     2273            break;
     2274
     2275        case CPUPropertyType_SpecCtrlByHost:
     2276            *aValue = mHWData->mSpecCtrlByHost;
     2277            break;
     2278
    22692279        case CPUPropertyType_HWVirt:
    22702280            *aValue = mHWData->mNestedHWVirt;
     
    23302340            mHWData.backup();
    23312341            mHWData->mIBPBOnVMEntry = !!aValue;
     2342            break;
     2343
     2344        case CPUPropertyType_SpecCtrl:
     2345            i_setModified(IsModified_MachineData);
     2346            mHWData.backup();
     2347            mHWData->mSpecCtrl = !!aValue;
     2348            break;
     2349
     2350        case CPUPropertyType_SpecCtrlByHost:
     2351            i_setModified(IsModified_MachineData);
     2352            mHWData.backup();
     2353            mHWData->mSpecCtrlByHost = !!aValue;
    23322354            break;
    23332355
     
    90239045        mHWData->mIBPBOnVMExit                = data.fIBPBOnVMExit;
    90249046        mHWData->mIBPBOnVMEntry               = data.fIBPBOnVMEntry;
     9047        mHWData->mSpecCtrl                    = data.fSpecCtrl;
     9048        mHWData->mSpecCtrlByHost              = data.fSpecCtrlByHost;
    90259049        mHWData->mNestedHWVirt                = data.fNestedHWVirt;
    90269050        mHWData->mCPUCount                    = data.cCPUs;
     
    1034910373        data.fIBPBOnVMExit          = !!mHWData->mIBPBOnVMExit;
    1035010374        data.fIBPBOnVMEntry         = !!mHWData->mIBPBOnVMEntry;
     10375        data.fSpecCtrl              = !!mHWData->mSpecCtrl;
     10376        data.fSpecCtrlByHost        = !!mHWData->mSpecCtrlByHost;
    1035110377        data.fNestedHWVirt          = !!mHWData->mNestedHWVirt;
    1035210378        data.cCPUs                  = mHWData->mCPUCount;
  • trunk/src/VBox/Main/xml/Settings.cpp

    r70768 r71108  
    27802780    fIBPBOnVMExit(false),
    27812781    fIBPBOnVMEntry(false),
     2782    fSpecCtrl(false),
     2783    fSpecCtrlByHost(false),
    27822784    fNestedHWVirt(false),
    27832785    enmLongMode(HC_ARCH_BITS == 64 ? Hardware::LongMode_Enabled : Hardware::LongMode_Disabled),
     
    29362938            && fIBPBOnVMExit             == h.fIBPBOnVMExit
    29372939            && fIBPBOnVMEntry            == h.fIBPBOnVMEntry
     2940            && fSpecCtrl                 == h.fSpecCtrl
     2941            && fSpecCtrlByHost           == h.fSpecCtrlByHost
    29382942            && fNestedHWVirt             == h.fNestedHWVirt
    29392943            && cCPUs                     == h.cCPUs
     
    39453949                pelmCPUChild->getAttributeValue("vmentry", hw.fIBPBOnVMEntry);
    39463950            }
     3951            pelmCPUChild = pelmHwChild->findChildElement("SpecCtrl");
     3952            if (pelmCPUChild)
     3953                pelmCPUChild->getAttributeValue("enabled", hw.fSpecCtrl);
     3954            pelmCPUChild = pelmHwChild->findChildElement("SpecCtrlByHost");
     3955            if (pelmCPUChild)
     3956                pelmCPUChild->getAttributeValue("enabled", hw.fSpecCtrlByHost);
    39473957            pelmCPUChild = pelmHwChild->findChildElement("NestedHWVirt");
    39483958            if (pelmCPUChild)
     
    52845294        }
    52855295    }
     5296    if (m->sv >= SettingsVersion_v1_16 && hw.fSpecCtrl)
     5297        pelmCPU->createChild("SpecCtrl")->setAttribute("enabled", hw.fSpecCtrl);
     5298    if (m->sv >= SettingsVersion_v1_16 && hw.fSpecCtrlByHost)
     5299        pelmCPU->createChild("SpecCtrlByHost")->setAttribute("enabled", hw.fSpecCtrlByHost);
    52865300    if (m->sv >= SettingsVersion_v1_17 && hw.fNestedHWVirt)
    52875301        pelmCPU->createChild("NestedHWVirt")->setAttribute("enabled", hw.fNestedHWVirt);
     
    69696983            || hardwareMachine.fX2APIC
    69706984            || hardwareMachine.fIBPBOnVMExit
    6971             || hardwareMachine.fIBPBOnVMEntry)
     6985            || hardwareMachine.fIBPBOnVMEntry
     6986            || hardwareMachine.fSpecCtrl
     6987            || hardwareMachine.fSpecCtrlByHost)
    69726988        {
    69736989            m->sv = SettingsVersion_v1_16;
  • trunk/src/VBox/VMM/VMMAll/CPUMAllMsrs.cpp

    r70913 r71108  
    62956295}
    62966296
     6297/**
     6298 * Fast way for HM to access the IA32_SPEC_CTRL register.
     6299 *
     6300 * @returns The register value.
     6301 * @param   pVCpu   The cross context virtual CPU structure of the calling EMT.
     6302 * @thread  EMT(pVCpu)
     6303 */
     6304VMMR0_INT_DECL(uint64_t) CPUMR0GetGuestSpecCtrl(PVMCPU pVCpu)
     6305{
     6306    return pVCpu->cpum.s.GuestMsrs.msr.SpecCtrl;
     6307}
     6308
     6309
     6310/**
     6311 * Fast way for HM to access the IA32_SPEC_CTRL register.
     6312 *
     6313 * @param   pVCpu   The cross context virtual CPU structure of the calling EMT.
     6314 * @param   uValue  The new value.
     6315 * @thread  EMT(pVCpu)
     6316 */
     6317VMMR0_INT_DECL(void) CPUMR0SetGuestSpecCtrl(PVMCPU pVCpu, uint64_t uValue)
     6318{
     6319    pVCpu->cpum.s.GuestMsrs.msr.SpecCtrl = uValue;
     6320}
     6321
    62976322#endif /* IN_RING0 */
    62986323
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r70612 r71108  
    24912491        }
    24922492#endif
     2493        /*
     2494         * The IA32_PRED_CMD MSR is write-only and has no state associated with it. We never need to intercept
     2495         * access (writes need to be executed without exiting, reds will #GP-fault anyway).
     2496         */
     2497        if (pVM->cpum.ro.GuestFeatures.fIbpb)
     2498            hmR0VmxSetMsrPermission(pVCpu, MSR_IA32_PRED_CMD,     VMXMSREXIT_PASSTHRU_READ, VMXMSREXIT_PASSTHRU_WRITE);
     2499
    24932500        /* Though MSR_IA32_PERF_GLOBAL_CTRL is saved/restored lazily, we want intercept reads/write to it for now. */
    24942501    }
     
    66306637            case MSR_K8_SF_MASK:        pMixedCtx->msrSFMASK       = pMsr->u64Value;             break;
    66316638            case MSR_K8_KERNEL_GS_BASE: pMixedCtx->msrKERNELGSBASE = pMsr->u64Value;             break;
     6639            case MSR_IA32_SPEC_CTRL:    CPUMR0SetGuestSpecCtrl(pVCpu, pMsr->u64Value);           break;
    66326640            case MSR_K6_EFER: /* Nothing to do here since we intercept writes, see hmR0VmxLoadGuestMsrs(). */
    66336641                break;
     
    91729180            Assert(!pVCpu->hm.s.vmx.cMsrs || pVCpu->hm.s.vmx.fUpdatedHostMsrs);
    91739181        }
     9182    }
     9183
     9184    if (pVM->cpum.ro.GuestFeatures.fIbrs)
     9185    {
     9186        bool fMsrUpdated;
     9187        int rc2 = hmR0VmxSaveGuestAutoLoadStoreMsrs(pVCpu, pMixedCtx);
     9188        AssertRC(rc2);
     9189        Assert(HMVMXCPU_GST_IS_UPDATED(pVCpu, HMVMX_UPDATED_GUEST_AUTO_LOAD_STORE_MSRS));
     9190
     9191        rc2 = hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_IA32_SPEC_CTRL, CPUMR0GetGuestSpecCtrl(pVCpu), true /* fUpdateHostMsr */,
     9192                                         &fMsrUpdated);
     9193        AssertRC(rc2);
     9194        Assert(fMsrUpdated || pVCpu->hm.s.vmx.fUpdatedHostMsrs);
     9195        /* Finally, mark that all host MSR values are updated so we don't redo it without leaving VT-x. See @bugref{6956}. */
     9196        pVCpu->hm.s.vmx.fUpdatedHostMsrs = true;
    91749197    }
    91759198
  • trunk/src/VBox/VMM/VMMR3/CPUMR3CpuId.cpp

    r70948 r71108  
    17501750            pFeatures->fIbrs                = pFeatures->fIbpb;
    17511751            pFeatures->fStibp               = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_STIBP);
     1752#if 0   // Disabled until IA32_ARCH_CAPABILITIES support can be tested
    17521753            pFeatures->fArchCap             = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_ARCHCAP);
     1754#endif
    17531755        }
    17541756
     
    43144316
    43154317        /* Check if speculation control is enabled. */
    4316         rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "EnableSpecCtrl", &fEnable, false);
     4318        rc = CFGMR3QueryBoolDef(pCpumCfg, "SpecCtrl", &fEnable, false);
    43174319        AssertRCReturn(rc, rc);
    43184320        if (fEnable)
     
    46214623                {
    46224624                    pLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_IBRS_IBPB;
     4625                    pVM->cpum.s.GuestFeatures.fIbrs = 1;
    46234626                    if (pVM->cpum.s.HostFeatures.fStibp)
     4627                    {
    46244628                        pLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_STIBP;
     4629                        pVM->cpum.s.GuestFeatures.fStibp = 1;
     4630                    }
    46254631
    46264632                    /* Make sure we have the speculation control MSR... */
  • trunk/src/VBox/VMM/VMMR3/HM.cpp

    r71064 r71108  
    464464                              "|IBPBOnVMExit"
    465465                              "|IBPBOnVMEntry"
     466                              "|SpecCtrlByHost"
    466467                              "|TPRPatchingEnabled"
    467468                              "|64bitEnabled"
     
    649650     * Costly paranoia setting. */
    650651    rc = CFGMR3QueryBoolDef(pCfgHm, "IBPBOnVMEntry", &pVM->hm.s.fIbpbOnVmEntry, false);
     652    AssertLogRelRCReturn(rc, rc);
     653
     654    /** @cfgm{/HM/SpecCtrlByHost, bool}
     655     * Another expensive paranoia setting. */
     656    rc = CFGMR3QueryBoolDef(pCfgHm, "SpecCtrlByHost", &pVM->hm.s.fSpecCtrlByHost, false);
    651657    AssertLogRelRCReturn(rc, rc);
    652658
  • trunk/src/VBox/VMM/include/HMInternal.h

    r70606 r71108  
    421421    /** Set if indirect branch prediction barrier on VM entry. */
    422422    bool                        fIbpbOnVmEntry;
     423    /** Set if host manages speculation control settings. */
     424    bool                        fSpecCtrlByHost;
    423425    /** Explicit padding. */
    424     bool                        afPadding[3];
     426    bool                        afPadding[2];
    425427
    426428    /** Maximum ASID allowed. */
Note: See TracChangeset for help on using the changeset viewer.

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