Skip to content

Conversation

@zevorn
Copy link

@zevorn zevorn commented Nov 29, 2025

Description

Add a constructor function that calls GetPerformanceCounterProperties(NULL, NULL) to ensure mTimeBase is initialized during DXE phase, before virtual memory is enabled.

This fixes crashes on RISC-V platforms without fw_cfg device support (e.g., QEMU rvsp-ref) where Runtime Services may call GetPerformanceCounterProperties() before mTimeBase has been initialized. When virtual memory is then enabled, the uninitialized mTimeBase value causes HOB access to fail with a page fault.

Fixes: #11747

How This Was Tested

To boot a kernel that has enabled the EFI timer service for time retrieval using EDKII on the QEMU rvsp-ref Machine (or other boards without fw_cfg support).

Since the rvsp-ref board has not yet been merged into the QEMU mainline, you can test it through my personal repo:

https://github.com/zevorn/qemu/tree/rvsp-ref-v4

Integration Instructions

N/A

…eBase

Add a constructor function that calls GetPerformanceCounterProperties(NULL, NULL)
to ensure mTimeBase is initialized during DXE phase, before virtual memory is
enabled.

This fixes crashes on RISC-V platforms without fw_cfg device support (e.g.,
QEMU rvsp-ref) where Runtime Services may call GetPerformanceCounterProperties()
before mTimeBase has been initialized. When virtual memory is then enabled, the
uninitialized mTimeBase value causes HOB access to fail with a page fault.

Fixes: tianocore#11747

Signed-off-by: Chao Liu <chao.liu.riscv@isrc.iscas.ac.cn>
Reported-by: Xiaofan Tan <xiaofan@iscas.ac.cn>
Suggested-by: Laszlo Ersek <lersek@redhat.com>
@xfan1024
Copy link

xfan1024 commented Nov 29, 2025

In my view, you might consider moving mTimeBase initialization from GetPerformanceCounterProperties into Constructor.
Once the Constructor has been called, we don't need to check mTimeBase is zero everywhere, which can make the code logic simpler and clearer.

In this way:

  1. You can use mTimeBase instead of GET_TIME_BASE() and remove this macro.
  2. In GetPerformanceCounterProperties, you can return mTimeBase directly without checking it was zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: BaseRiscV64CpuTimerLib is not safe for OS-runtime, crashes RealTimeClockRuntimeDxe in gRT->GetTime

2 participants