VirtualBox

Ignore:
Timestamp:
Oct 16, 2024 1:50:09 PM (3 months ago)
Author:
vboxsync
Message:

VMM/CPUMAllRegs-armv8.cpp: Some helpers to get at the TCR_EL1 of the guest, effective TTBR for a given virtul address and strip the PAC or any reserved bits from a given virtual address, bugref:10388

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs-armv8.cpp

    r106061 r106381  
    336336
    337337    Assert(bEl == ARMV8_AARCH64_EL_0 || bEl == ARMV8_AARCH64_EL_1);
    338     return RT_BOOL(pVCpu->cpum.s.Guest.Sctlr.u64 & ARMV8_SCTLR_EL2_M);
     338    return RT_BOOL(pVCpu->cpum.s.Guest.Sctlr.u64 & ARMV8_SCTLR_EL1_M);
     339}
     340
     341
     342/**
     343 * Returns the effective TTBR value for the given guest context pointer.
     344 *
     345 * @returns Physical base address of the translation table being used, or RTGCPHYS_MAX
     346 *          if MMU is disabled.
     347 */
     348VMM_INT_DECL(RTGCPHYS) CPUMGetEffectiveTtbr(PVMCPUCC pVCpu, RTGCPTR GCPtr)
     349{
     350    CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_PSTATE | CPUMCTX_EXTRN_SCTLR_TCR_TTBR);
     351
     352    uint8_t bEl = ARMV8_SPSR_EL2_AARCH64_GET_EL(pVCpu->cpum.s.Guest.fPState);
     353    if (bEl == ARMV8_AARCH64_EL_2)
     354    {
     355        CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_SYSREG_EL2);
     356        if (pVCpu->cpum.s.Guest.SctlrEl2.u64 & ARMV8_SCTLR_EL2_M)
     357            return   (GCPtr & RT_BIT_64(55))
     358                   ? ARMV8_TTBR_EL1_AARCH64_BADDR_GET(pVCpu->cpum.s.Guest.Ttbr1El2.u64)
     359                   : ARMV8_TTBR_EL1_AARCH64_BADDR_GET(pVCpu->cpum.s.Guest.Ttbr0El2.u64);
     360    }
     361    else
     362    {
     363        Assert(bEl == ARMV8_AARCH64_EL_0 || bEl == ARMV8_AARCH64_EL_1);
     364        if (pVCpu->cpum.s.Guest.Sctlr.u64 & ARMV8_SCTLR_EL1_M)
     365            return   (GCPtr & RT_BIT_64(55))
     366                   ? ARMV8_TTBR_EL1_AARCH64_BADDR_GET(pVCpu->cpum.s.Guest.Ttbr1.u64)
     367                   : ARMV8_TTBR_EL1_AARCH64_BADDR_GET(pVCpu->cpum.s.Guest.Ttbr0.u64);
     368    }
     369
     370    return RTGCPHYS_MAX;
     371}
     372
     373
     374/**
     375 * Returns the current TCR_EL1 system register value for the given vCPU.
     376 *
     377 * @returns TCR_EL1 value
     378 * @param   pVCpu       The cross context virtual CPU structure of the calling EMT.
     379 */
     380VMM_INT_DECL(uint64_t) CPUMGetTcrEl1(PVMCPUCC pVCpu)
     381{
     382    CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_SCTLR_TCR_TTBR);
     383    return pVCpu->cpum.s.Guest.Tcr.u64;
     384}
     385
     386
     387/**
     388 * Returns the virtual address given in the input stripped from any potential
     389 * pointer authentication code if enabled for the given vCPU.
     390 *
     391 * @returns Virtual address given in GCPtr stripped from any PAC (or reserved bits).
     392 * @param   pVCpu       The cross context virtual CPU structure of the calling EMT.
     393 */
     394VMM_INT_DECL(RTGCPTR) CPUMGetGCPtrPacStripped(PVMCPUCC pVCpu, RTGCPTR GCPtr)
     395{
     396    CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_SCTLR_TCR_TTBR);
     397
     398    /** @todo MTE support. */
     399    bool fUpper = RT_BOOL(GCPtr & RT_BIT_64(55)); /* Save the determinator for upper lower range. */
     400    uint8_t u8TxSz =   fUpper
     401                     ? ARMV8_TCR_EL1_AARCH64_T1SZ_GET(pVCpu->cpum.s.Guest.Tcr.u64)
     402                     : ARMV8_TCR_EL1_AARCH64_T0SZ_GET(pVCpu->cpum.s.Guest.Tcr.u64);
     403    RTGCPTR fNonPacMask = RT_BIT_64(64 - u8TxSz) - 1; /* Get mask of non PAC bits. */
     404    RTGCPTR fSign       =   fUpper
     405                          ? ~fNonPacMask
     406                          : 0;
     407
     408    return   (GCPtr & fNonPacMask)
     409           | fSign;
    339410}
    340411
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