VirtualBox

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


Ignore:
Timestamp:
Jul 26, 2023 1:16:19 PM (18 months ago)
Author:
vboxsync
Message:

VMM/NEMR3Native-darwin-armv8.cpp: Query ID registers and put them in a struct for passing it down to CPUM later on (ID registers are privileged and only accessible from EL1 popposed to the CPUID mechanism on x86, so they need support from the hypervisor interface), bugref:10390

File:
1 edited

Legend:

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

    r100705 r100708  
    191191    { HV_SYS_REG_TTBR1_EL1, CPUMCTX_EXTRN_SCTLR_TCR_TTBR,   RT_UOFFSETOF(CPUMCTX, Ttbr1.u64)        },
    192192    { HV_SYS_REG_VBAR_EL1,  CPUMCTX_EXTRN_SYSREG,           RT_UOFFSETOF(CPUMCTX, VBar.u64)         },
     193};
     194/** ID registers. */
     195static const struct
     196{
     197    hv_feature_reg_t enmHvReg;
     198    uint32_t         offIdStruct;
     199} s_aIdRegs[] =
     200{
     201    { HV_FEATURE_REG_ID_AA64DFR0_EL1,       RT_UOFFSETOF(HVIDREGS, u64IdDfReg0El1)  },
     202    { HV_FEATURE_REG_ID_AA64DFR1_EL1,       RT_UOFFSETOF(HVIDREGS, u64IdDfReg1El1)  },
     203    { HV_FEATURE_REG_ID_AA64ISAR0_EL1,      RT_UOFFSETOF(HVIDREGS, u64IdIsaReg0El1) },
     204    { HV_FEATURE_REG_ID_AA64ISAR1_EL1,      RT_UOFFSETOF(HVIDREGS, u64IdIsaReg1El1) },
     205    { HV_FEATURE_REG_ID_AA64MMFR0_EL1,      RT_UOFFSETOF(HVIDREGS, u64IdMmfReg0El1) },
     206    { HV_FEATURE_REG_ID_AA64MMFR1_EL1,      RT_UOFFSETOF(HVIDREGS, u64IdMmfReg1El1) },
     207    { HV_FEATURE_REG_ID_AA64MMFR2_EL1,      RT_UOFFSETOF(HVIDREGS, u64IdPfReg0El1)  },
     208    { HV_FEATURE_REG_ID_AA64PFR0_EL1,       RT_UOFFSETOF(HVIDREGS, u64IdPfReg1El1)  },
     209    { HV_FEATURE_REG_ID_AA64PFR1_EL1,       RT_UOFFSETOF(HVIDREGS, u64ClidrEl1)     },
     210    { HV_FEATURE_REG_CLIDR_EL1,             RT_UOFFSETOF(HVIDREGS, u64CtrEl0)       },
     211    { HV_FEATURE_REG_CTR_EL0,               RT_UOFFSETOF(HVIDREGS, u64DczidEl1)     },
    193212};
    194213
     
    657676static DECLCALLBACK(int) nemR3DarwinNativeInitVCpuOnEmt(PVM pVM, PVMCPU pVCpu, VMCPUID idCpu)
    658677{
    659     hv_return_t hrc = hv_vcpu_create(&pVCpu->nem.s.hVCpu, &pVCpu->nem.s.pHvExit, NULL);
     678    if (idCpu == 0)
     679    {
     680        Assert(pVM->nem.s.hVCpuCfg == NULL);
     681
     682        /* Create a new vCPU config and query the ID registers. */
     683        pVM->nem.s.hVCpuCfg = hv_vcpu_config_create();
     684        if (!pVM->nem.s.hVCpuCfg)
     685            return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS,
     686                              "Call to hv_vcpu_config_create failed on vCPU %u", idCpu);
     687
     688        for (uint32_t i = 0; i < RT_ELEMENTS(s_aIdRegs); i++)
     689        {
     690            uint64_t *pu64 = (uint64_t *)((uint8_t *)&pVM->nem.s.IdRegs + s_aIdRegs[i].offIdStruct);
     691            hv_return_t hrc = hv_vcpu_config_get_feature_reg(pVM->nem.s.hVCpuCfg, s_aIdRegs[i].enmHvReg, pu64);
     692            if (hrc != HV_SUCCESS)
     693                return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS,
     694                                  "Call to hv_vcpu_get_feature_reg(, %#x, ) failed: %#x (%Rrc)", hrc, nemR3DarwinHvSts2Rc(hrc));
     695        }
     696    }
     697
     698    hv_return_t hrc = hv_vcpu_create(&pVCpu->nem.s.hVCpu, &pVCpu->nem.s.pHvExit, pVM->nem.s.hVCpuCfg);
    660699    if (hrc != HV_SUCCESS)
    661700        return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS,
     
    667706                          "Setting MPIDR_EL1 failed on vCPU %u: %#x (%Rrc)", idCpu, hrc, nemR3DarwinHvSts2Rc(hrc));
    668707
    669     if (idCpu == 0)
    670     {
    671         /** @todo */
    672     }
    673 
    674708    return VINF_SUCCESS;
    675709}
     
    679713 * Worker to destroy the vCPU handle on the EMT running it later on (as required by HV).
    680714 *
    681  * @returns VBox status code
     715 * @returns VBox status code.
     716 * @param   pVM                 The VM handle.
    682717 * @param   pVCpu               The vCPU handle.
    683718 */
    684 static DECLCALLBACK(int) nemR3DarwinNativeTermVCpuOnEmt(PVMCPU pVCpu)
     719static DECLCALLBACK(int) nemR3DarwinNativeTermVCpuOnEmt(PVM pVM, PVMCPU pVCpu)
    685720{
    686721    hv_return_t hrc = hv_vcpu_destroy(pVCpu->nem.s.hVCpu);
    687722    Assert(hrc == HV_SUCCESS); RT_NOREF(hrc);
     723
     724    if (pVCpu->idCpu == 0)
     725    {
     726        os_release(pVM->nem.s.hVCpuCfg);
     727        pVM->nem.s.hVCpuCfg = NULL;
     728    }
    688729    return VINF_SUCCESS;
    689730}
     
    716757            /* Rollback. */
    717758            while (idCpu--)
    718                 VMR3ReqCallWait(pVM, idCpu, (PFNRT)nemR3DarwinNativeTermVCpuOnEmt, 1, pVCpu);
     759                VMR3ReqCallWait(pVM, idCpu, (PFNRT)nemR3DarwinNativeTermVCpuOnEmt, 2, pVM, pVCpu);
    719760
    720761            return VMSetError(pVM, VERR_NEM_VM_CREATE_FAILED, RT_SRC_POS, "Call to hv_vcpu_create failed: %Rrc", rc);
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