VirtualBox

Changeset 79637 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Jul 9, 2019 9:08:37 AM (6 years ago)
Author:
vboxsync
Message:

VMM/HM: Nested VMX: bugref:9180 Unify TRPM to VMX event conversion, let's not have 3 places doing it.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/HMVMXAll.cpp

    r79572 r79637  
    11851185 * @param   uIntInfo    The VMX event.
    11861186 */
    1187 VMM_INT_DECL(TRPMEVENT) HMVmxEventToTrpmEventType(uint32_t uIntInfo)
    1188 {
     1187VMM_INT_DECL(TRPMEVENT) HMVmxEventTypeToTrpmEventType(uint32_t uIntInfo)
     1188{
     1189    Assert(VMX_IDT_VECTORING_INFO_IS_VALID(uIntInfo));
     1190
    11891191    TRPMEVENT enmTrapType;
    1190     uint8_t const uType   = VMX_ENTRY_INT_INFO_TYPE(uIntInfo);
    1191     uint8_t const uVector = VMX_ENTRY_INT_INFO_VECTOR(uIntInfo);
     1192    uint8_t const uType   = VMX_IDT_VECTORING_INFO_TYPE(uIntInfo);
     1193    uint8_t const uVector = VMX_IDT_VECTORING_INFO_VECTOR(uIntInfo);
    11921194
    11931195    switch (uType)
    11941196    {
    1195         case VMX_ENTRY_INT_INFO_TYPE_EXT_INT:
     1197        case VMX_IDT_VECTORING_INFO_TYPE_EXT_INT:
    11961198           enmTrapType = TRPM_HARDWARE_INT;
    11971199           break;
    11981200
    1199         case VMX_ENTRY_INT_INFO_TYPE_NMI:
    1200         case VMX_ENTRY_INT_INFO_TYPE_HW_XCPT:
     1201        case VMX_IDT_VECTORING_INFO_TYPE_NMI:
     1202        case VMX_IDT_VECTORING_INFO_TYPE_HW_XCPT:
    12011203            enmTrapType = TRPM_TRAP;
    12021204            break;
    12031205
    1204         case VMX_ENTRY_INT_INFO_TYPE_PRIV_SW_XCPT:  /* INT1 (ICEBP). */
     1206        case VMX_IDT_VECTORING_INFO_TYPE_PRIV_SW_XCPT:  /* INT1 (ICEBP). */
    12051207            Assert(uVector == X86_XCPT_DB); NOREF(uVector);
    12061208            enmTrapType = TRPM_SOFTWARE_INT;
    12071209            break;
    12081210
    1209         case VMX_ENTRY_INT_INFO_TYPE_SW_XCPT:       /* INT3 (#BP) and INTO (#OF) */
     1211        case VMX_IDT_VECTORING_INFO_TYPE_SW_XCPT:       /* INT3 (#BP) and INTO (#OF) */
    12101212            Assert(uVector == X86_XCPT_BP || uVector == X86_XCPT_OF); NOREF(uVector);
    12111213            enmTrapType = TRPM_SOFTWARE_INT;
    12121214            break;
    12131215
    1214         case VMX_ENTRY_INT_INFO_TYPE_SW_INT:
     1216        case VMX_IDT_VECTORING_INFO_TYPE_SW_INT:
    12151217            enmTrapType = TRPM_SOFTWARE_INT;
    12161218            break;
    12171219
    1218         case VMX_ENTRY_INT_INFO_TYPE_OTHER_EVENT:   /* Shouldn't really happen. */
    12191220        default:
    12201221            AssertMsgFailed(("Invalid trap type %#x\n", uType));
     
    12241225
    12251226    return enmTrapType;
     1227}
     1228
     1229
     1230/**
     1231 * Converts a TRPM event type into an appropriate VMX event type.
     1232 *
     1233 * @returns VMX event type mask.
     1234 * @param   uVector         The event vector.
     1235 * @param   enmTrpmEvent    The TRPM event.
     1236 */
     1237VMM_INT_DECL(uint32_t) HMTrpmEventTypeToVmxEventType(uint8_t uVector, TRPMEVENT enmTrpmEvent)
     1238{
     1239    uint32_t uIntInfoType = 0;
     1240    if (enmTrpmEvent == TRPM_TRAP)
     1241    {
     1242        /** @todo r=ramshankar: TRPM currently offers no way to determine a \#DB that was
     1243         *        generated using INT1 (ICEBP). */
     1244        switch (uVector)
     1245        {
     1246            case X86_XCPT_NMI:
     1247                uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_NMI << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1248                break;
     1249
     1250            case X86_XCPT_BP:
     1251            case X86_XCPT_OF:
     1252                uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_SW_XCPT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1253                break;
     1254
     1255            case X86_XCPT_PF:
     1256            case X86_XCPT_DF:
     1257            case X86_XCPT_TS:
     1258            case X86_XCPT_NP:
     1259            case X86_XCPT_SS:
     1260            case X86_XCPT_GP:
     1261            case X86_XCPT_AC:
     1262                uIntInfoType |= VMX_IDT_VECTORING_INFO_ERROR_CODE_VALID;
     1263                RT_FALL_THRU();
     1264            default:
     1265                uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_HW_XCPT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1266                break;
     1267        }
     1268    }
     1269    else if (enmTrpmEvent == TRPM_HARDWARE_INT)
     1270        uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_EXT_INT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1271    else if (enmTrpmEvent == TRPM_SOFTWARE_INT)
     1272    {
     1273        switch (uVector)
     1274        {
     1275            case X86_XCPT_BP:
     1276            case X86_XCPT_OF:
     1277                uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_SW_XCPT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1278                break;
     1279
     1280            default:
     1281                Assert(uVector == X86_XCPT_DB);
     1282                uIntInfoType |= (VMX_IDT_VECTORING_INFO_TYPE_SW_INT << VMX_IDT_VECTORING_INFO_TYPE_SHIFT);
     1283                break;
     1284        }
     1285    }
     1286    else
     1287        AssertMsgFailed(("Invalid TRPM event type %d\n", enmTrpmEvent));
     1288    return uIntInfoType;
    12261289}
    12271290
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r79628 r79637  
    86098609    AssertRC(rc);
    86108610
    8611     /* Refer Intel spec. 24.8.3 "VM-entry Controls for Event Injection" for the format of u32IntInfo. */
    8612     uint32_t u32IntInfo = uVector | VMX_EXIT_INT_INFO_VALID;
    8613     if (enmTrpmEvent == TRPM_TRAP)
    8614     {
    8615         /** @todo r=ramshankar: TRPM currently offers no way to determine a \#DB that was
    8616          *        generated using INT1 (ICEBP). */
    8617         switch (uVector)
    8618         {
    8619             case X86_XCPT_NMI:
    8620                 u32IntInfo |= (VMX_EXIT_INT_INFO_TYPE_NMI << VMX_EXIT_INT_INFO_TYPE_SHIFT);
    8621                 break;
    8622 
    8623             case X86_XCPT_BP:
    8624             case X86_XCPT_OF:
    8625                 u32IntInfo |= (VMX_EXIT_INT_INFO_TYPE_SW_XCPT << VMX_EXIT_INT_INFO_TYPE_SHIFT);
    8626                 break;
    8627 
    8628             case X86_XCPT_PF:
    8629             case X86_XCPT_DF:
    8630             case X86_XCPT_TS:
    8631             case X86_XCPT_NP:
    8632             case X86_XCPT_SS:
    8633             case X86_XCPT_GP:
    8634             case X86_XCPT_AC:
    8635                 u32IntInfo |= VMX_EXIT_INT_INFO_ERROR_CODE_VALID;
    8636                 RT_FALL_THRU();
    8637             default:
    8638                 u32IntInfo |= (VMX_EXIT_INT_INFO_TYPE_HW_XCPT << VMX_EXIT_INT_INFO_TYPE_SHIFT);
    8639                 break;
    8640         }
    8641     }
    8642     else if (enmTrpmEvent == TRPM_HARDWARE_INT)
    8643         u32IntInfo |= (VMX_EXIT_INT_INFO_TYPE_EXT_INT << VMX_EXIT_INT_INFO_TYPE_SHIFT);
    8644     else if (enmTrpmEvent == TRPM_SOFTWARE_INT)
    8645     {
    8646         switch (uVector)
    8647         {
    8648             case X86_XCPT_BP:
    8649             case X86_XCPT_OF:
    8650                 u32IntInfo |= (VMX_EXIT_INT_INFO_TYPE_SW_XCPT << VMX_EXIT_INT_INFO_TYPE_SHIFT);
    8651                 break;
    8652 
    8653             default:
    8654                 Assert(uVector == X86_XCPT_DB);
    8655                 u32IntInfo |= (VMX_EXIT_INT_INFO_TYPE_SW_INT << VMX_EXIT_INT_INFO_TYPE_SHIFT);
    8656                 break;
    8657         }
    8658     }
    8659     else
    8660         AssertMsgFailed(("Invalid TRPM event type %d\n", enmTrpmEvent));
     8611    uint32_t u32IntInfo;
     8612    u32IntInfo  = uVector | VMX_IDT_VECTORING_INFO_VALID;
     8613    u32IntInfo |= HMTrpmEventTypeToVmxEventType(uVector, enmTrpmEvent);
    86618614
    86628615    rc = TRPMResetTrap(pVCpu);
     
    86788631    Assert(pVCpu->hm.s.Event.fPending);
    86798632
    8680     uint32_t uVectorType     = VMX_IDT_VECTORING_INFO_TYPE(pVCpu->hm.s.Event.u64IntInfo);
    8681     uint32_t uVector         = VMX_IDT_VECTORING_INFO_VECTOR(pVCpu->hm.s.Event.u64IntInfo);
    8682     bool     fErrorCodeValid = VMX_IDT_VECTORING_INFO_IS_ERROR_CODE_VALID(pVCpu->hm.s.Event.u64IntInfo);
    8683     uint32_t uErrorCode      = pVCpu->hm.s.Event.u32ErrCode;
    8684 
    86858633    /* If a trap was already pending, we did something wrong! */
    86868634    Assert(TRPMQueryTrap(pVCpu, NULL /* pu8TrapNo */, NULL /* pEnmType */) == VERR_TRPM_NO_ACTIVE_TRAP);
    86878635
    8688     /** @todo Use HMVmxEventToTrpmEventType() later. */
    8689     TRPMEVENT enmTrapType;
    8690     switch (uVectorType)
    8691     {
    8692         case VMX_IDT_VECTORING_INFO_TYPE_EXT_INT:
    8693            enmTrapType = TRPM_HARDWARE_INT;
    8694            break;
    8695 
    8696         case VMX_IDT_VECTORING_INFO_TYPE_NMI:
    8697         case VMX_IDT_VECTORING_INFO_TYPE_HW_XCPT:
    8698             enmTrapType = TRPM_TRAP;
    8699             break;
    8700 
    8701         case VMX_IDT_VECTORING_INFO_TYPE_PRIV_SW_XCPT:  /* #DB (INT1/ICEBP). */
    8702             Assert(uVector == X86_XCPT_DB);
    8703             enmTrapType = TRPM_SOFTWARE_INT;
    8704             break;
    8705 
    8706         case VMX_IDT_VECTORING_INFO_TYPE_SW_XCPT:       /* #BP (INT3) and #OF (INTO) */
    8707             Assert(uVector == X86_XCPT_BP || uVector == X86_XCPT_OF);
    8708             enmTrapType = TRPM_SOFTWARE_INT;
    8709             break;
    8710 
    8711         case VMX_IDT_VECTORING_INFO_TYPE_SW_INT:
    8712             enmTrapType = TRPM_SOFTWARE_INT;
    8713             break;
    8714 
    8715         default:
    8716             AssertMsgFailed(("Invalid trap type %#x\n", uVectorType));
    8717             enmTrapType = TRPM_32BIT_HACK;
    8718             break;
    8719     }
     8636    uint32_t const  u32IntInfo  = pVCpu->hm.s.Event.u64IntInfo;
     8637    uint32_t const  uVector     = VMX_IDT_VECTORING_INFO_VECTOR(u32IntInfo);
     8638    TRPMEVENT const enmTrapType = HMVmxEventTypeToTrpmEventType(u32IntInfo);
    87208639
    87218640    Log4(("HM event->TRPM: uVector=%#x enmTrapType=%d\n", uVector, enmTrapType));
     
    87248643    AssertRC(rc);
    87258644
    8726     if (fErrorCodeValid)
    8727         TRPMSetErrorCode(pVCpu, uErrorCode);
    8728 
    8729     if (   uVectorType == VMX_IDT_VECTORING_INFO_TYPE_HW_XCPT
    8730         && uVector == X86_XCPT_PF)
     8645    if (VMX_IDT_VECTORING_INFO_IS_ERROR_CODE_VALID(u32IntInfo))
     8646        TRPMSetErrorCode(pVCpu, pVCpu->hm.s.Event.u32ErrCode);
     8647
     8648    if (VMX_IDT_VECTORING_INFO_IS_XCPT_PF(u32IntInfo))
    87318649        TRPMSetFaultAddress(pVCpu, pVCpu->hm.s.Event.GCPtrFaultAddress);
    8732     else if (enmTrapType == TRPM_SOFTWARE_INT)
     8650    else if (VMX_IDT_VECTORING_INFO_TYPE(u32IntInfo) == VMX_IDT_VECTORING_INFO_TYPE_SW_INT)
    87338651        TRPMSetInstrLength(pVCpu, pVCpu->hm.s.Event.cbInstr);
    87348652
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