VirtualBox

Changeset 69654 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 10, 2017 7:22:45 PM (7 years ago)
Author:
vboxsync
Message:

VBoxCpuReporter: cleanups

Location:
trunk/src/VBox/VMM/tools
Files:
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/tools/Makefile.kmk

    r69582 r69654  
    6060VBoxCpuReport_SOURCES   = \
    6161        VBoxCpuReport.cpp \
    62         MsrSup.cpp        \
    63        ../VMMR3/CPUMR3CpuId.cpp
    64 VBoxCpuReport_SOURCES.linux = MsrLinux.cpp
     62        VBoxCpuReportMsrSup.cpp \
     63        ../VMMR3/CPUMR3CpuId.cpp
     64VBoxCpuReport_SOURCES.linux = \
     65        VBoxCpuReportMsrLinux.cpp
    6566VBoxCpuReport_DEFS.linux    = VBCR_HAVE_PLATFORM_MSR_PROBER
    6667VBoxCpuReport_LIBS      = \
  • trunk/src/VBox/VMM/tools/VBoxCpuReport.cpp

    r69653 r69654  
    7979static uint64_t         g_uMsrIntelP6FsbFrequency = UINT64_MAX;
    8080
    81 /** MSR prober routines. */
    82 static VBMSRFNS         g_MsrAcc;
    83 /** Wheter MSR prober can read/modify/restore MSRs more or less
    84  *  atomically, without allowing other code to be executed. */
    85 static bool             g_fAtomicMsrMod;
     81/** The MSR accessors interface. */
     82static VBCPUREPMSRACCESSORS g_MsrAcc;
     83
     84
    8685
    8786void vbCpuRepDebug(const char *pszMsg, ...)
     
    226225{
    227226    bool fGp;
    228     int rc = g_MsrAcc.msrWrite(uMsr, NIL_RTCPUID, uValue, &fGp);
     227    int rc = g_MsrAcc.pfnMsrWrite(uMsr, NIL_RTCPUID, uValue, &fGp);
    229228    AssertRC(rc);
    230229    return RT_SUCCESS(rc) && !fGp;
     
    237236    *puValue = 0;
    238237    bool fGp;
    239     int rc = g_MsrAcc.msrRead(uMsr, NIL_RTCPUID, puValue, &fGp);
     238    int rc = g_MsrAcc.pfnMsrProberRead(uMsr, NIL_RTCPUID, puValue, &fGp);
    240239    AssertRC(rc);
    241240    return RT_SUCCESS(rc) && !fGp;
     
    247246{
    248247    SUPMSRPROBERMODIFYRESULT Result;
    249     int rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, UINT64_MAX, 0, &Result);
     248    int rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, UINT64_MAX, 0, &Result);
    250249    return RT_SUCCESS(rc)
    251250        && !Result.fBeforeGp
     
    260259{
    261260    SUPMSRPROBERMODIFYRESULT Result;
    262     int rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, 0, 0, &Result);
     261    int rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, 0, 0, &Result);
    263262    return RT_SUCCESS(rc)
    264263        && !Result.fBeforeGp
     
    288287        /* Set it. */
    289288        SUPMSRPROBERMODIFYRESULT ResultSet;
    290         int rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, ~fBitMask, fBitMask, &ResultSet);
     289        int rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, ~fBitMask, fBitMask, &ResultSet);
    291290        if (RT_FAILURE(rc))
    292             return RTMsgErrorRc(rc, "msrModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, fBitMask, rc);
     291            return RTMsgErrorRc(rc, "pfnMsrProberModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, fBitMask, rc);
    293292
    294293        /* Clear it. */
    295294        SUPMSRPROBERMODIFYRESULT ResultClear;
    296         rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, ~fBitMask, 0, &ResultClear);
     295        rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, ~fBitMask, 0, &ResultClear);
    297296        if (RT_FAILURE(rc))
    298             return RTMsgErrorRc(rc, "msrModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, 0, rc);
     297            return RTMsgErrorRc(rc, "pfnMsrProberModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, 0, rc);
    299298
    300299        if (ResultSet.fModifyGp || ResultClear.fModifyGp)
     
    331330    /* Set it. */
    332331    SUPMSRPROBERMODIFYRESULT ResultSet;
    333     int rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, ~fBitMask, fBitMask, &ResultSet);
     332    int rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, ~fBitMask, fBitMask, &ResultSet);
    334333    if (RT_FAILURE(rc))
    335         return RTMsgErrorRc(-2, "msrModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, fBitMask, rc);
     334        return RTMsgErrorRc(-2, "pfnMsrProberModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, fBitMask, rc);
    336335
    337336    /* Clear it. */
    338337    SUPMSRPROBERMODIFYRESULT ResultClear;
    339     rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, ~fBitMask, 0, &ResultClear);
     338    rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, ~fBitMask, 0, &ResultClear);
    340339    if (RT_FAILURE(rc))
    341         return RTMsgErrorRc(-2, "msrModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, 0, rc);
     340        return RTMsgErrorRc(-2, "pfnMsrProberModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, ~fBitMask, 0, rc);
    342341
    343342    if (ResultSet.fModifyGp || ResultClear.fModifyGp)
     
    370369{
    371370    SUPMSRPROBERMODIFYRESULT Result;
    372     int rc = g_MsrAcc.msrModify(uMsr, NIL_RTCPUID, fAndMask, fOrMask, &Result);
     371    int rc = g_MsrAcc.pfnMsrProberModify(uMsr, NIL_RTCPUID, fAndMask, fOrMask, &Result);
    373372    if (RT_FAILURE(rc))
    374373    {
    375         RTMsgError("g_MsrAcc.msrModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, fAndMask, fOrMask, rc);
     374        RTMsgError("g_MsrAcc.pfnMsrProberModify(%#x,,%#llx,%#llx,): %Rrc", uMsr, fAndMask, fOrMask, rc);
    376375        return false;
    377376    }
     
    538537                uint64_t uValue = 0;
    539538                bool     fGp    = true;
    540                 int rc = g_MsrAcc.msrRead(uMsr, NIL_RTCPUID, &uValue, &fGp);
     539                int rc = g_MsrAcc.pfnMsrProberRead(uMsr, NIL_RTCPUID, &uValue, &fGp);
    541540                if (RT_FAILURE(rc))
    542541                {
    543542                    RTMemFree(*ppaMsrs);
    544543                    *ppaMsrs = NULL;
    545                     return RTMsgErrorRc(rc, "msrRead failed on %#x: %Rrc\n", uMsr, rc);
     544                    return RTMsgErrorRc(rc, "pfnMsrProberRead failed on %#x: %Rrc\n", uMsr, rc);
    546545                }
    547546
     
    569568#endif
    570569                    fGp = true;
    571                     rc = g_MsrAcc.msrWrite(uMsr, NIL_RTCPUID, 0, &fGp);
     570                    rc = g_MsrAcc.pfnMsrProberWrite(uMsr, NIL_RTCPUID, 0, &fGp);
    572571                    if (RT_FAILURE(rc))
    573572                    {
    574573                        RTMemFree(*ppaMsrs);
    575574                        *ppaMsrs = NULL;
    576                         return RTMsgErrorRc(rc, "msrWrite failed on %#x: %Rrc\n", uMsr, rc);
     575                        return RTMsgErrorRc(rc, "pfnMsrProberWrite failed on %#x: %Rrc\n", uMsr, rc);
    577576                    }
    578577                    uValue = 0;
     
    25582557         */
    25592558        case 0x00000010: /* IA32_TIME_STAMP_COUNTER */
    2560             if (!g_fAtomicMsrMod)
     2559            if (!g_MsrAcc.fAtomic)
    25612560                return VBCPUREPBADNESS_BOND_VILLAIN;
    25622561            break;
     
    25752574        case 0xc0000101: /* AMD64_GS_BASE */
    25762575        case 0xc0000102: /* AMD64_KERNEL_GS_BASE */
    2577             if (!g_fAtomicMsrMod)
     2576            if (!g_MsrAcc.fAtomic)
    25782577                return VBCPUREPBADNESS_MIGHT_BITE;
    25792578            break;
     
    33643363
    33653364    /* If the OS uses the APIC, we have to be super careful. */
    3366     if (!g_fAtomicMsrMod)
     3365    if (!g_MsrAcc.fAtomic)
    33673366        fSkipMask |= UINT64_C(0x0000000ffffff000);
    33683367
     
    33943393
    33953394    /* If the OS is using MONITOR/MWAIT we'd better not disable it! */
    3396     if (!g_fAtomicMsrMod)
     3395    if (!g_MsrAcc.fAtomic)
    33973396        fSkipMask |= RT_BIT(18);
    33983397
     
    36923691    {
    36933692        fSkipMask |= MSR_K6_EFER_LME;
    3694         if (!g_fAtomicMsrMod && (uValue & MSR_K6_EFER_SCE))
     3693        if (!g_MsrAcc.fAtomic && (uValue & MSR_K6_EFER_SCE))
    36953694            fSkipMask |= MSR_K6_EFER_SCE;
    36963695    }
     
    44044403     * First try the the support library (also checks if we can really read MSRs).
    44054404     */
    4406     int rc = SupDrvMsrProberInit(&g_MsrAcc, &g_fAtomicMsrMod);
     4405    int rc = VbCpuRepMsrProberInitSupDrv(&g_MsrAcc);
    44074406    if (RT_FAILURE(rc))
    44084407    {
    44094408#ifdef VBCR_HAVE_PLATFORM_MSR_PROBER
    44104409        /* Next try a platform-specific interface. */
    4411         rc = PlatformMsrProberInit(&g_MsrAcc, &g_fAtomicMsrMod);
     4410        rc = VbCpuRepMsrProberInitPlatform(&g_MsrAcc);
    44124411#endif
    44134412        if (RT_FAILURE(rc))
     
    44204419    uint64_t uValue;
    44214420    bool     fGp;
    4422     rc = g_MsrAcc.msrRead(MSR_IA32_TSC, NIL_RTCPUID, &uValue, &fGp);
     4421    rc = g_MsrAcc.pfnMsrProberRead(MSR_IA32_TSC, NIL_RTCPUID, &uValue, &fGp);
    44234422    if (RT_FAILURE(rc))
    44244423    {
     
    44274426    }
    44284427    vbCpuRepDebug("MSR_IA32_TSC: %#llx fGp=%RTbool\n", uValue, fGp);
    4429     rc = g_MsrAcc.msrRead(0xdeadface, NIL_RTCPUID, &uValue, &fGp);
     4428    rc = g_MsrAcc.pfnMsrProberRead(0xdeadface, NIL_RTCPUID, &uValue, &fGp);
    44304429    vbCpuRepDebug("0xdeadface: %#llx fGp=%RTbool rc=%Rrc\n", uValue, fGp, rc);
    44314430
     
    44854484        paMsrs = NULL;
    44864485    }
    4487     g_MsrAcc.msrProberTerm();
     4486    if (g_MsrAcc.pfnTerm)
     4487        g_MsrAcc.pfnTerm();
    44884488    RT_ZERO(g_MsrAcc);
    44894489    return rc;
  • trunk/src/VBox/VMM/tools/VBoxCpuReport.h

    r69653 r69654  
    1616 */
    1717
    18 typedef struct VBMSRFNS {
    19    int (*msrRead)(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp);
    20    int (*msrWrite)(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp);
    21    int (*msrModify)(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, PSUPMSRPROBERMODIFYRESULT pResult);
    22    int (*msrProberTerm)(void);
    23 } VBMSRFNS;
     18
     19#ifndef ___VBoxCpuReport_h___
     20#define ___VBoxCpuReport_h___
     21
     22#include <VBox/sup.h>
     23
     24RT_C_DECLS_BEGIN
     25
     26typedef struct VBCPUREPMSRACCESSORS
     27{
     28    /** Wheter MSR prober can read/modify/restore MSRs more or less
     29     *  atomically, without allowing other code to be executed. */
     30    bool                    fAtomic;
     31    /** @copydoc SUPR3MsrProberRead  */
     32    DECLCALLBACKMEMBER(int, pfnMsrProberRead)(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp);
     33    /** @copydoc SUPR3MsrProberWrite  */
     34    DECLCALLBACKMEMBER(int, pfnMsrProberWrite)(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp);
     35    /** @copydoc SUPR3MsrProberModify */
     36    DECLCALLBACKMEMBER(int, pfnMsrProberModify)(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask,
     37                                                PSUPMSRPROBERMODIFYRESULT pResult);
     38    /** Termination callback, optional. */
     39    DECLCALLBACKMEMBER(void, pfnTerm)(void);
     40} VBCPUREPMSRACCESSORS;
     41typedef VBCPUREPMSRACCESSORS *PVBCPUREPMSRACCESSORS;
    2442
    2543extern void vbCpuRepDebug(const char *pszMsg, ...);
    2644extern void vbCpuRepPrintf(const char *pszMsg, ...);
    27 extern int SupDrvMsrProberInit(VBMSRFNS *fnsMsr, bool *pfAtomicMsrMod);
    28 extern int PlatformMsrProberInit(VBMSRFNS *fnsMsr, bool *pfAtomicMsrMod);
     45extern int  VbCpuRepMsrProberInitSupDrv(PVBCPUREPMSRACCESSORS pMsrAccessors);
     46extern int  VbCpuRepMsrProberInitPlatform(PVBCPUREPMSRACCESSORS pMsrAccessors);
    2947
     48RT_C_DECLS_END
     49
     50#endif
     51
  • trunk/src/VBox/VMM/tools/VBoxCpuReportMsrLinux.cpp

    r69653 r69654  
    2020*   Header Files                                                                                                                 *
    2121*********************************************************************************************************************************/
    22 #include <iprt/ctype.h>
     22#include "VBoxCpuReport.h"
     23
     24#include <iprt/file.h>
    2325#include <iprt/thread.h>
    2426
    25 #include <VBox/sup.h>
    26 #include "VBoxCpuReport.h"
    27 
    28 #include <unistd.h>
     27#ifndef RT_OS_WINDOWS
     28# include <unistd.h>
     29#else /* RT_OS_WINDOWS: for test compiling this file on windows */
     30# include <io.h>
     31int pread(int, void *, size_t, off_t);
     32int pwrite(int, void const *, size_t, off_t);
     33#endif
    2934#include <fcntl.h>
    3035#include <errno.h>
    3136
    3237
     38/*********************************************************************************************************************************
     39*   Defined Constants And Macros                                                                                                 *
     40*********************************************************************************************************************************/
    3341#define MSR_DEV_NAME    "/dev/cpu/0/msr"
    34 
    35 
    36 /*********************************************************************************************************************************
    37 *   Structures and Typedefs                                                                                                      *
    38 *********************************************************************************************************************************/
    3942
    4043
     
    4649
    4750
     51/**
     52 * @interface_method_impl{VBCPUREPMSRACCESSORS,pfnMsrProberRead}
     53 */
    4854static int linuxMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp)
    4955{
     
    6571}
    6672
     73
     74/**
     75 * @interface_method_impl{VBCPUREPMSRACCESSORS,pfnMsrProberWrite}
     76 */
    6777static int linuxMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp)
    6878{
     
    8494}
    8595
    86 static int linuxMsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, PSUPMSRPROBERMODIFYRESULT pResult)
     96/**
     97 * @interface_method_impl{VBCPUREPMSRACCESSORS,pfnMsrProberModify}
     98 */
     99static DECLCALLBACK(int) linuxMsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask,
     100                                              PSUPMSRPROBERMODIFYRESULT pResult)
    87101{
    88102    int         rc = VINF_SUCCESS;
     
    100114    RTThreadSleep(10);
    101115#endif
    102     rcBefore = pread(g_fdMsr, &uBefore, sizeof(uBefore), uMsr) != sizeof(uBefore);
     116    rcBefore = pread(g_fdMsr, &uBefore, sizeof(uBefore), uMsr);
    103117    uWrite = (uBefore & fAndMask) | fOrMask;
    104118    rcWrite = pwrite(g_fdMsr, &uWrite, sizeof(uWrite), uMsr);
    105     rcAfter = pread(g_fdMsr, &uAfter, sizeof(uAfter), uMsr) != sizeof(uAfter);
    106     rcRestore = pwrite(g_fdMsr, &uBefore, sizeof(uBefore), uMsr) != sizeof(uBefore);
     119    rcAfter = pread(g_fdMsr, &uAfter, sizeof(uAfter), uMsr);
     120    rcRestore = pwrite(g_fdMsr, &uBefore, sizeof(uBefore), uMsr);
    107121
    108122#if 0
     
    114128    pResult->uWritten   = uWrite;
    115129    pResult->uAfter     = uAfter;
    116     pResult->fBeforeGp  = rcBefore;
    117     pResult->fModifyGp  = rcWrite != sizeof(uWrite);
    118     pResult->fAfterGp   = rcAfter;
    119     pResult->fRestoreGp = rcRestore;
     130    pResult->fBeforeGp  = rcBefore  != sizeof(uBefore);
     131    pResult->fModifyGp  = rcWrite   != sizeof(uWrite);
     132    pResult->fAfterGp   = rcAfter   != sizeof(uAfter);
     133    pResult->fRestoreGp = rcRestore != sizeof(uBefore);
    120134
    121135    return rc;
    122136}
    123137
    124 static int linuxMsrProberTerm(void)
     138
     139/**
     140 * @interface_method_impl{VBCPUREPMSRACCESSORS,pfnTerm}
     141 */
     142static DECLCALLBACK(void) linuxMsrProberTerm(void)
    125143{
    126     if (g_fdMsr < 0)
    127         return VERR_INVALID_STATE;
    128 
    129     close(g_fdMsr);
    130     return VINF_SUCCESS;
     144    if (g_fdMsr >= 0)
     145    {
     146        close(g_fdMsr);
     147        g_fdMsr = -1;
     148    }
    131149}
    132150
    133 int PlatformMsrProberInit(VBMSRFNS *fnsMsr, bool *pfAtomicMsrMod)
     151int VbCpuRepMsrProberInitPlatform(PVBCPUREPMSRACCESSORS pMsrAccessors)
    134152{
    135     if (access(MSR_DEV_NAME, F_OK))
     153    RTFILE hFile;
     154    int rc = RTFileOpen(&hFile, MSR_DEV_NAME, RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_OPEN);
     155    if (RT_SUCCESS(rc))
    136156    {
    137         vbCpuRepDebug("warning: The " MSR_DEV_NAME " device does not exist\n");
    138         return VERR_NOT_FOUND;
     157        g_fdMsr = RTFileToNative(hFile);
     158        Assert(g_fdMsr != -1);
     159
     160        pMsrAccessors->fAtomic             = false; /* Can't modify/restore MSRs without trip to R3. */
     161        pMsrAccessors->pfnMsrProberRead    = linuxMsrProberRead;
     162        pMsrAccessors->pfnMsrProberWrite   = linuxMsrProberWrite;
     163        pMsrAccessors->pfnMsrProberModify  = linuxMsrProberModify;
     164        pMsrAccessors->pfnTerm             = linuxMsrProberTerm;
     165        return VINF_SUCCESS;
    139166    }
    140 
    141     g_fdMsr = open(MSR_DEV_NAME, O_RDWR);
    142     if (g_fdMsr <= 0)
    143     {
    144         vbCpuRepDebug("warning: Failed to open " MSR_DEV_NAME "\n");
    145         return VERR_ACCESS_DENIED;
    146     }
    147 
    148     fnsMsr->msrRead       = linuxMsrProberRead;
    149     fnsMsr->msrWrite      = linuxMsrProberWrite;
    150     fnsMsr->msrModify     = linuxMsrProberModify;
    151     fnsMsr->msrProberTerm = linuxMsrProberTerm;
    152     *pfAtomicMsrMod       = false;  /* Can't modify/restore MSRs without trip to R3. */
    153 
    154     return VINF_SUCCESS;
     167    vbCpuRepDebug("warning: Failed to open " MSR_DEV_NAME ": %Rrc\n", rc);
     168    return rc;
    155169}
  • trunk/src/VBox/VMM/tools/VBoxCpuReportMsrSup.cpp

    r69651 r69654  
    2020*   Header Files                                                                                                                 *
    2121*********************************************************************************************************************************/
    22 #include <iprt/ctype.h>
     22#include "VBoxCpuReport.h"
    2323#include <iprt/x86.h>
    2424
    25 #include <VBox/sup.h>
    26 #include "VBoxCpuReport.h"
    2725
     26int VbCpuRepMsrProberInitSupDrv(PVBCPUREPMSRACCESSORS pMsrFunctions)
     27{
     28    int rc = SUPR3Init(NULL);
     29    if (RT_SUCCESS(rc))
     30    {
     31        /* Test if the MSR prober is available, since the interface is optional. The TSC MSR will exist on any supported CPU. */
     32        uint64_t uValue;
     33        bool     fGp;
     34        rc = SUPR3MsrProberRead(MSR_IA32_TSC, NIL_RTCPUID, &uValue, &fGp);
     35        if (   rc != VERR_NOT_IMPLEMENTED
     36            && rc != VERR_INVALID_FUNCTION)
     37        {
     38            pMsrFunctions->fAtomic            = true;
     39            pMsrFunctions->pfnMsrProberRead   = SUPR3MsrProberRead;
     40            pMsrFunctions->pfnMsrProberWrite  = SUPR3MsrProberWrite;
     41            pMsrFunctions->pfnMsrProberModify = SUPR3MsrProberModify;
    2842
    29 /* Wrappers to mask funny SUPR3 calling conventions on some platforms. */
    30 static int supMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp)
    31 {
    32     return SUPR3MsrProberRead(uMsr, idCpu, puValue, pfGp);
     43            pMsrFunctions->pfnTerm            = NULL;
     44            return VINF_SUCCESS;
     45
     46        }
     47        vbCpuRepDebug("warning: MSR probing not supported by the support driver (%Rrc).\n", rc);
     48    }
     49    else
     50        vbCpuRepDebug("warning: Unable to initialize the support library (%Rrc).\n", rc);
     51    return rc;
    3352}
    3453
    35 static int supMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp)
    36 {
    37     return SUPR3MsrProberWrite(uMsr, idCpu, uValue, pfGp);
    38 }
    39 
    40 static int supMsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, PSUPMSRPROBERMODIFYRESULT pResult)
    41 {
    42     return SUPR3MsrProberModify(uMsr, idCpu, fAndMask, fOrMask, pResult);
    43 }
    44 
    45 static int supMsrProberTerm(void)
    46 {
    47     return VINF_SUCCESS;
    48 }
    49 
    50 int SupDrvMsrProberInit(VBMSRFNS *fnsMsr, bool *pfAtomicMsrMod)
    51 {
    52     int rc = SUPR3Init(NULL);
    53     if (RT_FAILURE(rc))
    54     {
    55         vbCpuRepDebug("warning: Unable to initialize the support library (%Rrc).\n", rc);
    56         return VERR_NOT_FOUND;
    57     }
    58 
    59     /* Test if the MSR prober is available, since the interface is optional. The TSC MSR will exist on any supported CPU. */
    60     uint64_t uValue;
    61     bool     fGp;
    62     rc = SUPR3MsrProberRead(MSR_IA32_TSC, NIL_RTCPUID, &uValue, &fGp);
    63     if (RT_FAILURE(rc))
    64     {
    65         vbCpuRepDebug("warning: MSR probing not supported by the support driver (%Rrc).\n", rc);
    66         return VERR_NOT_SUPPORTED;
    67     }
    68 
    69     fnsMsr->msrRead       = supMsrProberRead;
    70     fnsMsr->msrWrite      = supMsrProberWrite;
    71     fnsMsr->msrModify     = supMsrProberModify;
    72     fnsMsr->msrProberTerm = supMsrProberTerm;
    73     *pfAtomicMsrMod       = true;
    74 
    75     return VINF_SUCCESS;
    76 }
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