VirtualBox

Changeset 106384 in vbox


Ignore:
Timestamp:
Oct 16, 2024 1:58:41 PM (7 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
165197
Message:

Main: Code for configuring and enabling nested virtualization support on ARM (M3 based hardware + macOS 15.0 aka Sequioa), bugref:10747

Location:
trunk
Files:
8 edited

Legend:

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

    r106061 r106384  
    12291229
    12301230    bool operator==(const PlatformARM&) const;
     1231
     1232    /** Nested hardware virtualization. */
     1233    bool                    fNestedHWVirt;              //< requires settings version 1.20 (VirtualBox 7.1)
    12311234};
    12321235#endif /* VBOX_WITH_VIRT_ARMV8 */
     
    15781581    void readPlatformCPUIDTreeX86(const xml::ElementNode &elmChild, PlatformX86 &platX86);
    15791582    void readPlatformX86(const xml::ElementNode &elmPlatformX86OrHardware, PlatformX86 &platX86);
     1583#ifdef VBOX_WITH_VIRT_ARMV8
     1584    void readPlatformARM(const xml::ElementNode &elmPlatformARM, PlatformARM &platARM);
     1585#endif
    15801586    void readPlatform(const xml::ElementNode &elmPlatformOrHardware, Hardware &hw, Platform &plat);
    15811587    void readHardware(const xml::ElementNode &elmHardware, Hardware &hw);
     
    16011607
    16021608    void buildPlatformX86XML(xml::ElementNode &elmParent, xml::ElementNode &elmCPU, const PlatformX86 &plat);
     1609#ifdef VBOX_WITH_VIRT_ARMV8
     1610    void buildPlatformARMXML(xml::ElementNode &elmParent, const PlatformARM &plat);
     1611#endif
    16031612    void buildPlatformXML(xml::ElementNode &elmParent, const Hardware &h, const Platform &plat);
    16041613    void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, uint32_t fl, std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r106061 r106384  
    250250    MODIFYVM_GUEST_DEBUG_ADDRESS,
    251251    MODIFYVM_GUEST_DEBUG_PORT,
     252
     253    /*
     254     * Stuff common between x86 and ARM.
     255     */
     256    MODIFYVM_NESTED_HW_VIRT,
     257
    252258    /*
    253259     * x86-specific stuff.
     
    267273    MODIFYVM_X86_MDS_CLEAR_ON_SCHED,
    268274    MODIFYVM_X86_MDS_CLEAR_ON_VM_ENTRY,
    269     MODIFYVM_X86_NESTED_HW_VIRT,
    270275    MODIFYVM_X86_NESTEDPAGING,
    271276    MODIFYVM_X86_PAE,
     
    516521    OPT1("--x86-mds-clear-on-vm-entry",                                 MODIFYVM_X86_MDS_CLEAR_ON_VM_ENTRY, RTGETOPT_REQ_BOOL_ONOFF),
    517522    OPT1("--mds-clear-on-vm-entry",                                     MODIFYVM_X86_MDS_CLEAR_ON_VM_ENTRY, RTGETOPT_REQ_BOOL_ONOFF),
    518     OPT1("--x86-nested-hw-virt",                                        MODIFYVM_X86_NESTED_HW_VIRT,        RTGETOPT_REQ_BOOL_ONOFF),
    519     OPT1("--nested-hw-virt",                                            MODIFYVM_X86_NESTED_HW_VIRT,        RTGETOPT_REQ_BOOL_ONOFF),
     523    OPT1("--x86-nested-hw-virt",                                        MODIFYVM_NESTED_HW_VIRT,            RTGETOPT_REQ_BOOL_ONOFF),
     524    OPT1("--nested-hw-virt",                                            MODIFYVM_NESTED_HW_VIRT,            RTGETOPT_REQ_BOOL_ONOFF),
    520525    OPT1("--x86-nested-paging",                                         MODIFYVM_X86_NESTEDPAGING,          RTGETOPT_REQ_BOOL_ONOFF),
    521526    OPT2("--nested-paging",                 "--nestedpaging",           MODIFYVM_X86_NESTEDPAGING,          RTGETOPT_REQ_BOOL_ONOFF),
     
    792797            break;
    793798
    794         case MODIFYVM_X86_NESTED_HW_VIRT:
     799        case MODIFYVM_NESTED_HW_VIRT:
    795800            CHECK_ERROR(platformX86, SetCPUProperty(CPUPropertyTypeX86_HWVirt, pValueUnion->f));
    796801            break;
     
    825830}
    826831
     832/**
     833 * Handles the x86-specific modifyvm options.
     834 *
     835 * @returns HRESULT
     836 * @retval  E_INVALIDARG if handed-in option was not being handled.
     837 * @param   pGetOptState        Pointer to GetOpt state to use.
     838 * @param   c                   Current GetOpt value (short form).
     839 * @param   pValueUnion         Pointer to current value union.
     840 * @param   sessionMachine      Session machine to use.
     841 * @param   platformARM         ARM-specific platform object to use.
     842 */
     843static HRESULT handleModifyVM_ARM(PRTGETOPTSTATE pGetOptState, int c, PRTGETOPTUNION pValueUnion,
     844                                  ComPtr<IMachine> &sessionMachine, ComPtr<IPlatformARM> &platformARM)
     845{
     846    RT_NOREF(pGetOptState, sessionMachine);
     847
     848    HRESULT hrc = S_OK;
     849
     850    switch (c)
     851    {
     852        case MODIFYVM_NESTED_HW_VIRT:
     853            CHECK_ERROR(platformARM, SetCPUProperty(CPUPropertyTypeARM_HWVirt, pValueUnion->f));
     854            break;
     855
     856        default:
     857            hrc = E_INVALIDARG;
     858            break;
     859    }
     860
     861    return hrc;
     862}
     863
    827864RTEXITCODE handleModifyVM(HandlerArg *a)
    828865{
     
    857894    ComPtr<IPlatform> platform;
    858895    CHECK_ERROR_RET(sessionMachine, COMGETTER(Platform)(platform.asOutParam()), RTEXITCODE_FAILURE);
    859 
    860     /* For the x86-based options we need the x86-specific platform object. */
    861     ComPtr<IPlatformX86> platformX86;
    862     platform->COMGETTER(X86)(platformX86.asOutParam());
    863896
    864897    ComPtr<IGraphicsAdapter> pGraphicsAdapter;
     
    37393772            default:
    37403773            {
    3741                 hrc = handleModifyVM_x86(&GetOptState, c, &ValueUnion, sessionMachine, platformX86);
     3774                PlatformArchitecture_T enmArch;
     3775                CHECK_ERROR_RET(platform, COMGETTER(Architecture)(&enmArch), RTEXITCODE_FAILURE);
     3776
     3777                if (enmArch == PlatformArchitecture_x86)
     3778                {
     3779                    /* For the x86-based options we need the x86-specific platform object. */
     3780                    ComPtr<IPlatformX86> platformX86;
     3781                    CHECK_ERROR_RET(platform, COMGETTER(X86)(platformX86.asOutParam()), RTEXITCODE_FAILURE);
     3782
     3783                    hrc = handleModifyVM_x86(&GetOptState, c, &ValueUnion, sessionMachine, platformX86);
     3784                }
     3785                else if (enmArch == PlatformArchitecture_ARM)
     3786                {
     3787                    /* For the ARM-based options we need the x86-specific platform object. */
     3788                    ComPtr<IPlatformARM> platformARM;
     3789                    CHECK_ERROR_RET(platform, COMGETTER(ARM)(platformARM.asOutParam()), RTEXITCODE_FAILURE);
     3790
     3791                    hrc = handleModifyVM_ARM(&GetOptState, c, &ValueUnion, sessionMachine, platformARM);
     3792                }
     3793                else
     3794                {
     3795                    errorArgument(ModifyVM::tr("Invalid platform architecture returned for VM"));
     3796                    hrc = E_FAIL;
     3797                }
     3798
    37423799                if (FAILED(hrc))
    37433800                    errorGetOpt(c, &ValueUnion);
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r106218 r106384  
    12211221        setting may slow down workloads causing many VM exits, so it is only
    12221222        recommended for situation where there is a real need to be paranoid.
     1223      </desc>
     1224    </const>
     1225  </enum>
     1226
     1227  <enum
     1228    name="CPUPropertyTypeARM"
     1229    uuid="c84685f6-6bd3-4071-97c6-86f34595648f"
     1230    >
     1231    <desc>
     1232      Virtual CPU property type for ARM-based CPUs. This enumeration represents possible values of the
     1233      IPlatformARM get- and setCPUProperty methods.
     1234    </desc>
     1235    <const name="Null"                  value="0">
     1236      <desc>Null value (never used by the API).</desc>
     1237    </const>
     1238    <const name="HWVirt"                value="1">
     1239      <desc>
     1240        Enables the hardware virtualization feature on the guest CPU.
     1241        This requires the nested virtualization feature on the host CPU.
    12231242      </desc>
    12241243    </const>
     
    73927411  <interface
    73937412    name="IPlatformARM" extends="$unknown"
    7394     uuid="75dff9be-6cb3-4857-bde6-2faf82ed9a8d"
     7413    uuid="002c75fe-3316-4920-aece-7d21ce6f624b"
    73957414    wsmap="managed"
    73967415    rest="managed"
     
    74037422    </desc>
    74047423
    7405     <!-- Currently empty, but that should change before long... -->
    7406     <attribute name="midlDoesNotLikeEmptyInterfaces" readonly="yes" type="boolean"/>
     7424    <method name="getCPUProperty" const="yes">
     7425      <rest request="get" path="/vms/{vmid}/configuration/"/>
     7426      <desc>
     7427        Returns the virtual CPU boolean value of the specified property.
     7428
     7429        <result name="E_INVALIDARG">
     7430          Invalid property.
     7431        </result>
     7432
     7433      </desc>
     7434      <param name="property" type="CPUPropertyTypeARM" dir="in">
     7435        <desc>
     7436          Property type to query.
     7437        </desc>
     7438      </param>
     7439      <param name="value" type="boolean" dir="return">
     7440        <desc>
     7441          Property value.
     7442        </desc>
     7443      </param>
     7444    </method>
     7445
     7446    <method name="setCPUProperty">
     7447      <rest request="post" path="/vms/{vmid}/configuration/"/>
     7448      <desc>
     7449        Sets the virtual CPU boolean value of the specified property.
     7450
     7451        <result name="E_INVALIDARG">
     7452          Invalid property.
     7453        </result>
     7454
     7455      </desc>
     7456      <param name="property" type="CPUPropertyTypeARM" dir="in">
     7457        <desc>
     7458          Property type to query.
     7459        </desc>
     7460      </param>
     7461      <param name="value" type="boolean" dir="in">
     7462        <desc>
     7463          Property value.
     7464        </desc>
     7465      </param>
     7466    </method>
    74077467
    74087468  </interface>
  • trunk/src/VBox/Main/include/PlatformARMImpl.h

    r106061 r106384  
    6868    HRESULT i_saveSettings(settings::PlatformARM &data);
    6969    HRESULT i_applyDefaults(GuestOSType *aOsType);
     70
     71private:
     72
     73    // wrapped IPlatformARM methods
     74    HRESULT getCPUProperty(CPUPropertyTypeARM_T aProperty, BOOL *aValue);
     75    HRESULT setCPUProperty(CPUPropertyTypeARM_T aProperty, BOOL aValue);
    7076};
    7177#endif /* !MAIN_INCLUDED_PlatformARMImpl_h */
  • trunk/src/VBox/Main/src-all/PlatformPropertiesImpl.cpp

    r106139 r106384  
    12771277            static const TpmType_T aTpmTypes[] =
    12781278            {
    1279                 TpmType_None
     1279                TpmType_None,
     1280                TpmType_v2_0
    12801281            };
    12811282            aSupportedTpmTypes.assign(aTpmTypes,
  • trunk/src/VBox/Main/src-client/ConsoleImplConfigArmV8.cpp

    r106361 r106384  
    153153#endif
    154154
     155    /* Get the ARM platform object. */
     156    ComPtr<IPlatformARM> platformARM;
     157    hrc = platform->COMGETTER(ARM)(platformARM.asOutParam());                               H();
     158
    155159    ComPtr<IPlatformProperties> pPlatformProperties;
    156160    hrc = platform->COMGETTER(Properties)(pPlatformProperties.asOutParam());                H();
     
    364368        PCFGMNODE pCpum;
    365369        InsertConfigNode(pRoot, "CPUM", &pCpum);
     370
     371        /* Nested Virtualization. */
     372        BOOL fNestedHWVirt = FALSE;
     373        hrc = platformARM->GetCPUProperty(CPUPropertyTypeARM_HWVirt, &fNestedHWVirt); H();
     374        InsertConfigInteger(pCpum, "NestedHWVirt", fNestedHWVirt ? true : false);
    366375
    367376
  • trunk/src/VBox/Main/src-server/PlatformARMImpl.cpp

    r106061 r106384  
    3131#include "PlatformImpl.h"
    3232#include "LoggingNew.h"
     33
     34#include "AutoStateDep.h"
    3335
    3436#include <VBox/settings.h>
     
    239241HRESULT PlatformARM::i_loadSettings(const settings::PlatformARM &data)
    240242{
    241     RT_NOREF(data);
    242 
    243     /* Nothing here yet. */
     243    AutoCaller autoCaller(this);
     244    AssertComRCReturnRC(autoCaller.hrc());
     245
     246    AutoReadLock mlock(mMachine COMMA_LOCKVAL_SRC_POS);
     247    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     248
     249    // simply copy
     250    m->bd.assignCopy(&data);
    244251    return S_OK;
    245252}
     
    255262HRESULT PlatformARM::i_saveSettings(settings::PlatformARM &data)
    256263{
    257     RT_NOREF(data);
     264    AutoCaller autoCaller(this);
     265    AssertComRCReturnRC(autoCaller.hrc());
     266
     267    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     268
     269    data = *m->bd.data();
     270
     271    return S_OK;
     272}
     273
     274HRESULT PlatformARM::i_applyDefaults(GuestOSType *aOsType)
     275{
     276    RT_NOREF(aOsType);
    258277
    259278    /* Nothing here yet. */
     
    261280}
    262281
    263 HRESULT PlatformARM::i_applyDefaults(GuestOSType *aOsType)
    264 {
    265     RT_NOREF(aOsType);
    266 
    267     /* Nothing here yet. */
    268     return S_OK;
    269 }
     282HRESULT PlatformARM::getCPUProperty(CPUPropertyTypeARM_T aProperty, BOOL *aValue)
     283{
     284    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     285
     286    switch (aProperty)
     287    {
     288        case CPUPropertyTypeARM_HWVirt:
     289            *aValue = m->bd->fNestedHWVirt;
     290            break;
     291
     292        default:
     293            return E_INVALIDARG;
     294    }
     295    return S_OK;
     296}
     297
     298HRESULT PlatformARM::setCPUProperty(CPUPropertyTypeARM_T aProperty, BOOL aValue)
     299{
     300    /* sanity */
     301    AutoCaller autoCaller(this);
     302    AssertComRCReturnRC(autoCaller.hrc());
     303
     304    /* the machine needs to be mutable */
     305    AutoMutableStateDependency adep(mMachine);
     306    if (FAILED(adep.hrc())) return adep.hrc();
     307
     308    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     309
     310    switch (aProperty)
     311    {
     312        case CPUPropertyTypeARM_HWVirt:
     313        {
     314            m->bd.backup();
     315            m->bd->fNestedHWVirt = !!aValue;
     316            break;
     317        }
     318
     319        default:
     320            return E_INVALIDARG;
     321    }
     322
     323    alock.release();
     324
     325    AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
     326    mMachine->i_setModified(Machine::IsModified_Platform);
     327
     328    return S_OK;
     329}
  • trunk/src/VBox/Main/xml/Settings.cpp

    r106061 r106384  
    39693969
    39703970#ifdef VBOX_WITH_VIRT_ARMV8
    3971 PlatformARM::PlatformARM()
     3971PlatformARM::PlatformARM() :
     3972    fNestedHWVirt(false)
    39723973{
    39733974}
     
    39753976bool PlatformARM::operator==(const PlatformARM& h) const
    39763977{
    3977     RT_NOREF(h);
    3978     return true;
     3978    return (this == &h)
     3979        || (fNestedHWVirt == h.fNestedHWVirt);
    39793980}
    39803981#endif /* VBOX_WITH_VIRT_ARMV8 */
     
    53065307}
    53075308
     5309#ifdef VBOX_WITH_VIRT_ARMV8
     5310/**
     5311 * Reads the ARM platform settings.
     5312 *
     5313 * For settings >= v1.20 these were stored under the "Platform/arm" node.
     5314 *
     5315 * @param elmPlatformARM  Platform/arm node to read from.
     5316 * @param platARM         Where to store the ARM platform settings.
     5317 */
     5318void MachineConfigFile::readPlatformARM(const xml::ElementNode &elmPlatformARM,
     5319                                        PlatformARM &platARM)
     5320{
     5321    xml::NodesLoop nl1(elmPlatformARM);
     5322
     5323    const xml::ElementNode *pelChild;
     5324    while ((pelChild = nl1.forAllNodes()))
     5325    {
     5326        if (pelChild->nameEquals("CPU"))
     5327        {
     5328            const xml::ElementNode *pelmCPUChild;
     5329            if ((pelmCPUChild = pelChild->findChildElement("NestedHWVirt")))
     5330                pelmCPUChild->getAttributeValue("enabled", platARM.fNestedHWVirt);
     5331        }
     5332    }
     5333}
     5334#endif
     5335
    53085336/**
    53095337 * Reads the platform settings.
     
    54435471        case PlatformArchitecture_ARM:
    54445472        {
    5445             /* Nothing here yet -- add ARM-specific stuff as soon as we have it. */
     5473            const xml::ElementNode *pelmPlatformARM;
     5474
     5475            pelmPlatformARM = elmPlatformOrHardware.findChildElement("arm");
     5476            if (pelmPlatformARM)
     5477                readPlatformARM(*pelmPlatformARM, plat.arm);
    54465478            break;
    54475479        }
     
    73507382}
    73517383
     7384#ifdef VBOX_WITH_VIRT_ARMV8
     7385/**
     7386 * Writes ARM-specific platform settings out to the XML.
     7387 *
     7388 * For settings >= v1.20 this creates a \<arm\> node under elmParent.
     7389 * keys under that. Called for both the \<Machine\> node and for snapshots.
     7390 *
     7391 * @param elmParent                         Parent element.
     7392 *                                          For settings >= v1.20 this is the \<Platform\> element.
     7393 * @param elmCPU                            CPU element platform-generic settings.
     7394 *                                          For settings >= v1.20 this is the \<Platform/CPU\> element.
     7395 * @param platARM                           ARM-specific platform settings to use for building the XML.
     7396 */
     7397void MachineConfigFile::buildPlatformARMXML(xml::ElementNode &elmParent, const PlatformARM &platARM)
     7398{
     7399    xml::ElementNode *pelmARMRoot = elmParent.createChild("arm");
     7400    xml::ElementNode *pelmARMCPU  = pelmARMRoot->createChild("CPU");
     7401
     7402    if (platARM.fNestedHWVirt)
     7403        pelmARMCPU->createChild("NestedHWVirt")->setAttribute("enabled", platARM.fNestedHWVirt);
     7404}
     7405#endif /* VBOX_WITH_VIRT_ARMV8 */
     7406
     7407
    73527408/**
    73537409 * Stores platform-generic and platform-specific data and then writes out the XML.
     
    74657521    if (plat.architectureType == PlatformArchitecture_x86)
    74667522        buildPlatformX86XML(*pelmPlatformOrHardware, *pelmCPU, plat.x86);
    7467     /** @todo Put ARM stuff here as soon as we have it. */
     7523#ifdef VBOX_WITH_VIRT_ARMV8
     7524    else if (plat.architectureType == PlatformArchitecture_ARM)
     7525    {
     7526        Assert(m->sv >= SettingsVersion_v1_20);
     7527        buildPlatformARMXML(*pelmPlatformOrHardware, plat.arm);
     7528    }
     7529#endif
    74687530}
    74697531
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