vmm: retrieve timebase-frequency from KVM instead of hardcoding

The RISC-V device tree's timebase-frequency was hardcoded to 10 MHz
(0x989680). Actual hardware uses different frequencies.

Read the timebase frequency from KVM_GET_ONE_REG via
KVM_REG_RISCV_TIMER (offset 0, kvm_riscv_timer.frequency),
thread it through the VMM to arch to FDT layers, and fall back to
the 10 MHz default when KVM returns no value.

Signed-off-by: Meng Zhuo <mengzhuo@iscas.ac.cn>
This commit is contained in:
Meng Zhuo
2026-06-17 19:11:10 +08:00
committed by Rob Bradford
parent 085642dd42
commit 14aa30cd2e
6 changed files with 47 additions and 5 deletions

View File

@@ -642,6 +642,11 @@ impl Vcpu {
self.vcpu.run()
}
#[cfg(target_arch = "riscv64")]
pub fn get_timebase_frequency(&self) -> result::Result<u64, hypervisor::HypervisorCpuError> {
self.vcpu.get_timebase_frequency()
}
#[cfg(feature = "sev_snp")]
pub fn set_sev_control_register(&self, vmsa_pfn: u64) -> Result<()> {
self.vcpu

View File

@@ -1988,6 +1988,16 @@ impl Vm {
// TODO: PMU support for riscv64 is scheduled to next stage.
let timebase_frequency = self
.cpu_manager
.lock()
.unwrap()
.vcpus()
.first()
.and_then(|vcpu| vcpu.lock().unwrap().get_timebase_frequency().ok())
.map(|f| f as u32)
.unwrap_or(0x989680);
arch::configure_system(
&mem,
cmdline.as_cstring().unwrap().to_str().unwrap(),
@@ -1996,6 +2006,7 @@ impl Vm {
&initramfs_config,
&pci_space_info,
&vaia,
timebase_frequency,
)
.map_err(Error::ConfigureSystem)?;