VirtualBox

Changeset 72778 in vbox for trunk/src/VBox/VMM/VMMR0


Ignore:
Timestamp:
Jun 29, 2018 8:02:35 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123320
Message:

VMM,SUPDrv,IPRT: Redirect ring-0 release logging on EMTs to VBox.log.

  • VMM: Added release ring-0 logging on EMTs that writes to VBox.log.
  • IPRT: Made 'msprog' and 'timeprog' work for ring-0 logging on EMTs.
  • IPRT: Removed RTLogSetCustomPrefixCallbackForR0.
  • VMM: Removed vmmR0LoggerPrefix that was assoicated with the above API.
  • IPRT Fixed missing log prefix on the first log line.
  • SUPDrv: Turns out we require actual code for SUPR0GetDefaultLogRelInstanceEx and SUPR0GetDefaultLogInstanceEx.

Note! Requires updating the support driver.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r72428 r72778  
    19131913     * Search the handles in a linear fashion as we don't dare to take the lock (assert).
    19141914     */
     1915/** @todo introduce some pid hash table here, please. */
    19151916    for (unsigned i = 1; i < RT_ELEMENTS(pGVMM->aHandles); i++)
    19161917    {
     
    19271928            PGVM pGVM = pGVMM->aHandles[i].pGVM;
    19281929            VMCPUID const cCpus = pGVM->cCpus;
     1930            ASMCompilerBarrier();
    19291931            if (    cCpus < 1
    19301932                ||  cCpus > VMM_MAX_CPU_COUNT)
     
    19331935                if (pGVM->aCpus[idCpu].hEMT == hEMT)
    19341936                    return pGVMM->aHandles[i].pVM;
     1937        }
     1938    }
     1939    return NULL;
     1940}
     1941
     1942
     1943/**
     1944 * Looks up the GVMCPU belonging to the specified EMT thread.
     1945 *
     1946 * This is used by the assertion machinery in VMMR0.cpp to avoid causing
     1947 * unnecessary kernel panics when the EMT thread hits an assertion. The
     1948 * call may or not be an EMT thread.
     1949 *
     1950 * @returns Pointer to the VM on success, NULL on failure.
     1951 * @param   hEMT    The native thread handle of the EMT.
     1952 *                  NIL_RTNATIVETHREAD means the current thread
     1953 */
     1954GVMMR0DECL(PGVMCPU) GVMMR0GetGVCpuByEMT(RTNATIVETHREAD hEMT)
     1955{
     1956    /*
     1957     * No Assertions here as we're usually called in a AssertMsgN,
     1958     * RTAssert*, Log and LogRel contexts.
     1959     */
     1960    PGVMM pGVMM = g_pGVMM;
     1961    if (   !VALID_PTR(pGVMM)
     1962        || pGVMM->u32Magic != GVMM_MAGIC)
     1963        return NULL;
     1964
     1965    if (hEMT == NIL_RTNATIVETHREAD)
     1966        hEMT = RTThreadNativeSelf();
     1967    RTPROCESS ProcId = RTProcSelf();
     1968
     1969    /*
     1970     * Search the handles in a linear fashion as we don't dare to take the lock (assert).
     1971     */
     1972/** @todo introduce some pid hash table here, please. */
     1973    for (unsigned i = 1; i < RT_ELEMENTS(pGVMM->aHandles); i++)
     1974    {
     1975        if (   pGVMM->aHandles[i].iSelf == i
     1976            && pGVMM->aHandles[i].ProcId == ProcId
     1977            && VALID_PTR(pGVMM->aHandles[i].pvObj)
     1978            && VALID_PTR(pGVMM->aHandles[i].pVM)
     1979            && VALID_PTR(pGVMM->aHandles[i].pGVM))
     1980        {
     1981            PGVM pGVM = pGVMM->aHandles[i].pGVM;
     1982            if (pGVMM->aHandles[i].hEMT0 == hEMT)
     1983                return &pGVM->aCpus[0];
     1984
     1985            /* This is fearly safe with the current process per VM approach. */
     1986            VMCPUID const cCpus = pGVM->cCpus;
     1987            ASMCompilerBarrier();
     1988            ASMCompilerBarrier();
     1989            if (   cCpus < 1
     1990                || cCpus > VMM_MAX_CPU_COUNT)
     1991                continue;
     1992            for (VMCPUID idCpu = 1; idCpu < cCpus; idCpu++)
     1993                if (pGVM->aCpus[idCpu].hEMT == hEMT)
     1994                    return &pGVM->aCpus[idCpu];
    19351995        }
    19361996    }
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r72642 r72778  
    390390        return rc;
    391391
    392 
    393392#ifdef LOG_ENABLED
    394393    /*
     
    23452344}
    23462345
    2347 /**
    2348  * Internal R0 logger worker: Custom prefix.
    2349  *
    2350  * @returns Number of chars written.
    2351  *
    2352  * @param   pLogger     The logger instance.
    2353  * @param   pchBuf      The output buffer.
    2354  * @param   cchBuf      The size of the buffer.
    2355  * @param   pvUser      User argument (ignored).
    2356  */
    2357 VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
    2358 {
    2359     NOREF(pvUser);
    2360 #ifdef LOG_ENABLED
    2361     PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
    2362     if (    !VALID_PTR(pR0Logger)
    2363         ||  !VALID_PTR(pR0Logger + 1)
    2364         ||  pLogger->u32Magic != RTLOGGER_MAGIC
    2365         ||  cchBuf < 2)
    2366         return 0;
    2367 
    2368     static const char s_szHex[17] = "0123456789abcdef";
    2369     VMCPUID const     idCpu       = pR0Logger->idCpu;
    2370     pchBuf[1] = s_szHex[ idCpu       & 15];
    2371     pchBuf[0] = s_szHex[(idCpu >> 4) & 15];
    2372 
    2373     return 2;
    2374 #else
    2375     NOREF(pLogger); NOREF(pchBuf); NOREF(cchBuf);
    2376     return 0;
    2377 #endif
    2378 }
    2379 
    23802346#ifdef LOG_ENABLED
    23812347
     
    23892355    if (pVCpu->vmm.s.pR0LoggerR0)
    23902356        pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
     2357    if (pVCpu->vmm.s.pR0RelLoggerR0)
     2358        pVCpu->vmm.s.pR0RelLoggerR0->fFlushingDisabled = true;
    23912359}
    23922360
     
    24012369    if (pVCpu->vmm.s.pR0LoggerR0)
    24022370        pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
     2371    if (pVCpu->vmm.s.pR0RelLoggerR0)
     2372        pVCpu->vmm.s.pR0RelLoggerR0->fFlushingDisabled = false;
    24032373}
    24042374
     
    24132383    if (pVCpu->vmm.s.pR0LoggerR0)
    24142384        return pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled;
     2385    if (pVCpu->vmm.s.pR0RelLoggerR0)
     2386        return pVCpu->vmm.s.pR0RelLoggerR0->fFlushingDisabled;
    24152387    return true;
    24162388}
     2389
    24172390#endif /* LOG_ENABLED */
     2391
     2392/**
     2393 * Override RTLogRelGetDefaultInstanceEx so we can do LogRel to VBox.log from EMTs in ring-0.
     2394 */
     2395DECLEXPORT(PRTLOGGER) RTLogRelGetDefaultInstanceEx(uint32_t fFlagsAndGroup)
     2396{
     2397    PGVMCPU pGVCpu = GVMMR0GetGVCpuByEMT(NIL_RTNATIVETHREAD);
     2398    if (pGVCpu)
     2399    {
     2400        PVMCPU pVCpu = pGVCpu->pVCpu;
     2401        if (RT_VALID_PTR(pVCpu))
     2402        {
     2403            PVMMR0LOGGER pVmmLogger = pVCpu->vmm.s.pR0RelLoggerR0;
     2404            if (RT_VALID_PTR(pVmmLogger))
     2405            {
     2406                if (   pVmmLogger->fCreated
     2407                    && pVmmLogger->pVM == pGVCpu->pVM)
     2408                {
     2409                    if (pVmmLogger->Logger.fFlags & RTLOGFLAGS_DISABLED)
     2410                        return NULL;
     2411                    uint16_t const fFlags = RT_LO_U16(fFlagsAndGroup);
     2412                    uint16_t const iGroup = RT_HI_U16(fFlagsAndGroup);
     2413                    if (   iGroup != UINT16_MAX
     2414                        && (   (  pVmmLogger->Logger.afGroups[iGroup < pVmmLogger->Logger.cGroups ? iGroup : 0]
     2415                                & (fFlags | (uint32_t)RTLOGGRPFLAGS_ENABLED))
     2416                            != (fFlags | (uint32_t)RTLOGGRPFLAGS_ENABLED)))
     2417                        return NULL;
     2418                    return &pVmmLogger->Logger;
     2419                }
     2420            }
     2421        }
     2422    }
     2423    return SUPR0GetDefaultLogRelInstanceEx(fFlagsAndGroup);
     2424}
     2425
    24182426
    24192427/**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette