-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Ovmf memory debug logging4 #11021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ovmf memory debug logging4 #11021
Conversation
⚠ WARNING: Cannot add some reviewers: A user specified as a reviewer for this PR is not a collaborator of the repository. Please add them as a collaborator to the repository so they can be requested in the future. Non-collaborators requested: Attn Admins: Admin Instructions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: you can simply force-push to your branch, there is no need to open a new PR for each revision of the patch set.
Please don't create yet another PR for this series. |
Sorry, just saw this. #11031 will be the last PR from me on this series. |
No, please use this PR instead. |
I'm sure you'll figure it out. |
It appears that PRs cannot be reopened after the branch has been force-pushed or recreated (without some extreme git hackery)... |
Just do
|
Doesn't work:
Commit 59f80a8 got vaporized when I deleted/recreated the branch last week |
Misread the log, apologies. Please fetch the commit from tianocore/edk2 first. |
You can fetch |
59f80a8
to
7664c0b
Compare
The OVMF Memory Debug Logging feature logs DEBUG() messages to a memory buffer allowing for extraction of debug messages directly from a qemu process or core file. Add the GUIDs and PCDs definitions required for the OVMF Memory Debug Logging feature. Cc: Gerd Hoffmann <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Jiewen Yao <[email protected]> Signed-off-by: Aaron Young <[email protected]>
a9786dc
to
f62bf48
Compare
I think this is good to go now. Thanks for the assistance. |
Adding Adding a |
Add the Memory Debug Logging feature MemDebugLogLib library which provides the key MemDebugLogWrite() function. Several versions (i.e. SEC, PEIM, DXE, runtime) of the function are included to provide the proper method to write the debug messages to the memory debug log buffer. The library also provides the core functions to maintain the circular memory debug log buffer. Cc: Gerd Hoffmann <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Jiewen Yao <[email protected]> Signed-off-by: Aaron Young <[email protected]>
Add the OvmfPkg MemDebugLogPei PEI Module which is responsible for allocating and initializing the main memory log buffer. Cc: Gerd Hoffmann <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Jiewen Yao <[email protected]> Signed-off-by: Aaron Young <[email protected]>
Extend OvmfPkg PlatformDebugLibIoPort library to also write debug messages to memory. Include NULL versions of MemDebugLogLib to all OVMF builds which use PlatformDebugLibIoPort. Cc: Gerd Hoffmann <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Jiewen Yao <[email protected]> Signed-off-by: Aaron Young <[email protected]>
…uffer Add the memory debug log buffer size (pages) to TotalPages in PlatformPei:GetPeiMemoryCap() help ensure we don't run out of memory. Also Reserve the "early" memory debug log buffer. Cc: Gerd Hoffmann <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Jiewen Yao <[email protected]> Signed-off-by: Aaron Young <[email protected]>
Add the OVMF Memory Debug Logging feature (MemDebugLogLib library and MemDebugLogPei PEIM) to the Ia32X64 and X64 OVMF builds. This includes reserving the "early" memory debug log buffer in the .fdf files. The OVMF Memory Debug Logging feature is enabled via the -D DEBUG_TO_MEM build flag. Cc: Gerd Hoffmann <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Jiewen Yao <[email protected]> Signed-off-by: Aaron Young <[email protected]>
f62bf48
to
f3d0af4
Compare
It's part of fb584b5 Let me know if that is not sufficient.
Good idea. I added the MemDebugLogEnabled() and checks in PlatformDebugLibIoPort/DebugLib.c to skip the debug string formatting. |
Signed-off-by: Aaron Young <[email protected]>
b104007
to
a8d21ee
Compare
Description
OVMF Memory Debug Logging Support
Overview:
This PR adds support to log OVMF debug messages to a memory buffer. The memory buffer can be extracted from a VM's QEMU process (or a core file) to debug issues.
Background:
OVMF currently offers 2 methods to collect debug messages:
Both of these methods are impractical under normal VM operation. They increase VM boot time, clutter the serial console, and use host disk resources. In contrast, logging the debug messages to memory is fast and takes no disk resources allowing it to be enabled by default for customer environments. This allows for "first-time" issue analysis, negating the need to reproduce issues with debug messages enabled, which makes for a much better customer experience should an issue occur.
Code Overview:
The code introduces a new PEIM:
The code also introduces 1 new library:
A bit of complication arises from the the fact that main memory is not available until the PEI phase and several debug messages are logged before then. To remedy this, the code makes use of a "early" memory buffer (taken from the top of PeiMemFvBase) which is used to log the initial (pre-memory) messages. Once memory becomes available, the PEIM allocates the main memory debug log buffer, copies the messages from the early buffer and installs a HOB containing the main memory buffer address.
Thus, the SEC version of MemDebugLogLib:MemDebugLogWrite() writes debug messages to the "early" debug log buffer. The PeiCore and PEIM version of MemDebugLogLib:MemDebugLogWrite() also writes initial messages to the early buffer until the MemDebugLogPei HOB is installed. Once the HOB is installed it switches to write to the main memory buffer (obtaining the main memory buffer address from the HOB). The DXE and runtime versions of the MemDebugLogLib:MemDebugLogWrite() write to the main memory debug log buffer (by also using the HOB). The runtime version of MemDebugLogLib:MemDebugLogWrite() (used by DXE_RUNTIME_DRIVER type drivers) will allow memory debug log writes until the OS makes the SetVirtualAddressMap() BS call - at which point memory debug logging ends.
The OvmfPkg/Library/PlatformDebugLibIoPort library was modified to also write debug messages to memory. This allows both writes to debugcon and memory simultaneously.
Putting it all together, when debugcon is configured in the build (the default), the OVMF debug message call sequence is:
The feature (i.e. the new MemDebugLogLib library and PEIM) are disabled by default and are enabled via the new "DEBUG_TO_MEM" build flag (which can be enabled on the build command line - similar to DEBUG_ON_SERIAL_PORT).
Notes:
The debug log memory buffer size can be configured via FwCfg (-fw_cfg name=opt/ovmf/MemDebugLogPages,string=n - where 'n' denotes the number of pages) and is circular - i.e. only the most recent debug messages are retained if the memory buffer overflows. This is appropriate as typically only the most recent debug messages are relevant when debugging an issue. The code currently defaults to a 32 page (128K) sized memory debug log buffer (the default is configured via a PCD). The maximum size that can be specified via FwCfg is 2MB. The feature can be disabled by specifying 0 via FwCfg.
It is straight-forward to implement a host-side tool/utility to search the VM's QEMU memory regions to locate the OVMF memory debug log buffer (located on a page boundary), decipher the buffer header and display the circular buffer contents (debug messages). We (Oracle) already have such a utility which can extract the OVMF memory debug log from a live QEMU process or a QEMU core file.
This feature doesn't work with Confidential Computing VMs as the guest memory is encrypted and thus not readable from the host. A future enhancement could possibly be made to mark the OVMF memory debug log buffer as unencrypted (?) TBD
This PR only covers OVMF (x86_64) but was written to be easily extended to AAVMF (Arm) in a future PR. TBD
How This Was Tested
OVMF builds for both OvmfPkgIa32X64.dsc and OvmfPkgX64.dsc (both with and without -D DEBUG_TO_MEM) were built/tested and the OVMF Memory Debug Log extracted from the VM's QEMU process (by a custom utility) and assessed for correctness.
Integration Instructions
N/A