VirtualBox

Changeset 95406 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 28, 2022 12:23:51 PM (3 years ago)
Author:
vboxsync
Message:

ValKit/bs3-cpu-basic-2: Extended the #AC testcase with a couple of ring-3 #PF rounds to validate the priority (#AC is triggered before #PF). bugref:9898

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-x0.c

    r93115 r95406  
    15181518
    15191519
    1520 static void bs3CpuBasic2_RaiseXcpt11Worker(uint8_t bMode, uint8_t *pbBuf, unsigned cbCacheLine, bool fAm,
    1521                                            BS3CPUBASIC2PFTTSTCMNMODE const BS3_FAR *pCmn)
     1520static void bs3CpuBasic2_RaiseXcpt11Worker(uint8_t bMode, uint8_t *pbBuf, unsigned cbCacheLine, bool fAm, bool fPf,
     1521                                           RTCCUINTXREG uFlatBufPtr, BS3CPUBASIC2PFTTSTCMNMODE const BS3_FAR *pCmn)
    15221522{
    15231523    BS3TRAPFRAME        TrapCtx;
     
    15401540     * one also using xDX, so make sure they make some sense.
    15411541     */
    1542     Bs3RegCtxSaveEx(&Ctx, bMode, 0);
     1542    Bs3RegCtxSaveEx(&Ctx, bMode, 256);
    15431543
    15441544    for (iRing = 0; iRing < cRings; iRing++)
     
    15491549        Bs3RegCtxConvertToRingX(&Ctx, iRing);
    15501550
    1551         Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, pbBuf);
     1551        if (!fPf || BS3_MODE_IS_32BIT_CODE(bMode) || BS3_MODE_IS_64BIT_CODE(bMode))
     1552            Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, pbBuf);
     1553        else
     1554        {
     1555            /* Bs3RegCtxSetGrpDsFromCurPtr barfs when trying to output a sel:off address for the aliased buffer. */
     1556            Ctx.ds      = BS3_FP_SEG(pbBuf);
     1557            Ctx.rbx.u32 = BS3_FP_OFF(pbBuf);
     1558        }
    15521559        uEbx = Ctx.rbx.u32;
    15531560
     
    15831590                CtxUdExpected.cs     = Ctx.cs;
    15841591                CtxUdExpected.rflags = Ctx.rflags;
    1585 if (bMode == BS3_MODE_RM) CtxUdExpected.rflags.u32 &= ~X86_EFL_AC; /** @todo investigate. automatically cleared, or is it just our code? */
     1592if (bMode == BS3_MODE_RM) CtxUdExpected.rflags.u32 &= ~X86_EFL_AC; /** @todo investigate. automatically cleared, or is it just our code?  Observed with bs3-cpu-instr-3 too (10980xe). */
    15861593                CtxUdExpected.rdx    = Ctx.rdx;
    15871594                CtxUdExpected.rax    = Ctx.rax;
     
    16101617                for (offMem = 0; offMem < cbMax; offMem++)
    16111618                {
    1612                     unsigned offBuf = cbMax + cbMem * 2;
     1619                    bool const fMisaligned = (offMem & (cbMem - 1)) != 0; /** @todo assumes cbMem is a power of two! */
     1620                    unsigned   offBuf      = cbMax + cbMem * 2;
    16131621                    while (offBuf-- > 0)
    16141622                        pbBuf[offBuf] = 1; /* byte-by-byte to make sure it doesn't trigger AC. */
     
    16181626                        g_uBs3TrapEipHint = Ctx.rip.u32;
    16191627
    1620                     //Bs3TestPrintf("iRing=%d iTest=%d cs:rip=%04RX16:%08RX32 ds:rbx=%04RX16:%08RX32\n",
    1621                     //              iRing, iTest, Ctx.cs, Ctx.rip.u32, Ctx.ds, Ctx.rbx.u32);
     1628                    //if (iRing == 3 && fPf && fAm)
     1629                    //    Bs3TestPrintf("iRing=%d iTest=%d cs:rip=%04RX16:%08RX32 ds:rbx=%04RX16:%08RX32 bXcpt=%#x errcd=%#x fAm=%d fAc=%d\n",
     1630                    //                  iRing, iTest, Ctx.cs, Ctx.rip.u32, Ctx.ds, Ctx.rbx.u32, TrapCtx.bXcpt, (unsigned)TrapCtx.uErrCd, fAm, fAc);
    16221631
    16231632                    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    16241633
    1625                     if (!fAm || iRing != 3 || !fAc || !(offMem & (cbMem - 1))) /** @todo assumes cbMem is a power of two! */
     1634                    if (fPf && iRing == 3 && (!fAm || !fAc || !fMisaligned)) /* #AC beats #PF */
     1635                        bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx,
     1636                                                  X86_TRAP_PF_P | X86_TRAP_PF_US
     1637                                                  | (pCmn->paEntries[iTest].fOp & MYOP_ST ? X86_TRAP_PF_RW : 0),
     1638                                                  uFlatBufPtr + offMem);
     1639                    else if (!fAm || iRing != 3 || !fAc || !fMisaligned)
    16261640                    {
    16271641                        if (fOp & MYOP_EFL)
     
    16381652                    }
    16391653                    else
    1640                     {
    16411654                        bs3CpuBasic2_CompareAcCtx(&TrapCtx, &Ctx);
    1642                     }
    16431655
    16441656                    g_usBs3TestStep++;
     
    16821694    pbBuf = abBuf;
    16831695    if (BS3_FP_OFF(pbBuf) & (cbCacheLine - 1))
    1684         pbBuf = &abBuf[cbCacheLine - BS3_FP_OFF(pbBuf) & (cbCacheLine - 1)];
     1696        pbBuf = &abBuf[cbCacheLine - (BS3_FP_OFF(pbBuf) & (cbCacheLine - 1))];
     1697    BS3_ASSERT(pbBuf - abBuf <= cbCacheLine);
    16851698    //Bs3TestPrintf("pbBuf=%p\n", pbBuf);
    16861699
     
    16911704    //Bs3TestPrintf("idxCmnModes=%d bMode=%#x\n", idxCmnModes, bMode);
    16921705
    1693     /* First round is w/o aligment checks enabled. */
     1706    /* First round is w/o alignment checks enabled. */
    16941707    fCr0 = Bs3RegGetCr0();
    16951708    BS3_ASSERT(!(fCr0 & X86_CR0_AM));
    16961709    Bs3RegSetCr0(fCr0 & ~X86_CR0_AM);
    1697     bs3CpuBasic2_RaiseXcpt11Worker(bMode, pbBuf, cbCacheLine, false /*fAm*/, &g_aCmnModes[idxCmnModes]);
    1698 
    16991710#if 1
     1711    bs3CpuBasic2_RaiseXcpt11Worker(bMode, pbBuf, cbCacheLine, false /*fAm*/, false /*fPf*/, 0, &g_aCmnModes[idxCmnModes]);
     1712#endif
     1713
    17001714    /* The second round is with aligment checks enabled. */
     1715#if 1
    17011716    Bs3RegSetCr0(Bs3RegGetCr0() | X86_CR0_AM);
    1702     bs3CpuBasic2_RaiseXcpt11Worker(bMode, pbBuf, cbCacheLine, true /*fAm*/, &g_aCmnModes[idxCmnModes]);
     1717    bs3CpuBasic2_RaiseXcpt11Worker(bMode, pbBuf, cbCacheLine, true /*fAm*/, false /*fPf*/, 0, &g_aCmnModes[idxCmnModes]);
     1718#endif
     1719
     1720#if 1
     1721    /* The third and fourth round access the buffer via a page alias that's not
     1722       accessible from ring-3.  The third round has ACs disabled and the fourth
     1723       has them enabled. */
     1724    if (BS3_MODE_IS_PAGED(bMode) && !BS3_MODE_IS_V86(bMode)) //&& (BS3_MODE_IS_32BIT_CODE(bMode) || BS3_MODE_IS_64BIT_CODE(bMode)))
     1725    {
     1726        /* Alias the buffer as system memory so ring-3 access with AC+AM will cause #PF: */
     1727        int            rc;
     1728        RTCCUINTXREG   uFlatBufPtr = Bs3SelPtrToFlat(pbBuf);
     1729        uint64_t const uAliasPgPtr = bMode & BS3_MODE_CODE_64 ? UINT64_C(0x0000648680000000) : UINT32_C(0x80000000);
     1730        rc = Bs3PagingAlias(uAliasPgPtr, uFlatBufPtr & ~(uint64_t)X86_PAGE_OFFSET_MASK, X86_PAGE_SIZE * 2,
     1731                            X86_PTE_P | X86_PTE_RW);
     1732        if (RT_SUCCESS(rc))
     1733        {
     1734            RTCCUINTXREG     uAliasBufPtr = (RTCCUINTXREG)uAliasPgPtr + (uFlatBufPtr & X86_PAGE_OFFSET_MASK);
     1735            uint8_t BS3_FAR *pbBufAlias   = BS3_FP_MAKE(BS3_SEL_SPARE_00 | 3, uFlatBufPtr & X86_PAGE_OFFSET_MASK);;
     1736            Bs3SelSetup16BitData(&Bs3GdteSpare00, uAliasPgPtr);
     1737
     1738            Bs3TestPrintf("round three\n");
     1739            Bs3RegSetCr0(Bs3RegGetCr0() & ~X86_CR0_AM);
     1740            bs3CpuBasic2_RaiseXcpt11Worker(bMode, pbBufAlias, cbCacheLine, false /*fAm*/,
     1741                                           true /*fPf*/, uAliasBufPtr, &g_aCmnModes[idxCmnModes]);
     1742
     1743            Bs3TestPrintf("round four\n");
     1744            Bs3RegSetCr0(Bs3RegGetCr0() | X86_CR0_AM);
     1745            bs3CpuBasic2_RaiseXcpt11Worker(bMode, pbBufAlias, cbCacheLine, true /*fAm*/,
     1746                                           true /*fPf*/, uAliasBufPtr, &g_aCmnModes[idxCmnModes]);
     1747            Bs3TestPrintf("done\n");
     1748
     1749            Bs3PagingUnalias(uAliasPgPtr, X86_PAGE_SIZE * 2);
     1750        }
     1751        else
     1752            Bs3TestFailedF("Bs3PagingAlias failed with %Rrc", rc);
     1753    }
    17031754#endif
    17041755
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