Skip to content

Commit

Permalink
target/riscv/kvm: fix timebase-frequency when using KVM acceleration
Browse files Browse the repository at this point in the history
The timebase-frequency of guest OS should be the same with host
machine. The timebase-frequency value in DTS should be got from
hypervisor when using KVM acceleration.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Message-ID: <20240314061510.9800-1-yongxuan.wang@sifive.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
(cherry picked from commit 385e575)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: context fix due to missing other changes in this area in 8.2.x)
  • Loading branch information
yong-xuan authored and Michael Tokarev committed Mar 27, 2024
1 parent 38f36fc commit 1e4ec09
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hw/riscv/virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,

qemu_fdt_add_subnode(ms->fdt, "/cpus");
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "timebase-frequency",
kvm_enabled() ?
kvm_riscv_get_timebase_frequency(first_cpu) :
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ);
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
Expand Down
9 changes: 9 additions & 0 deletions target/riscv/kvm/kvm-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,15 @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
env->kvm_timer_dirty = false;
}

uint64_t kvm_riscv_get_timebase_frequency(CPUState *cs)
{
uint64_t reg;

KVM_RISCV_GET_TIMER(cs, frequency, reg);

return reg;
}

typedef struct KVMScratchCPU {
int kvmfd;
int vmfd;
Expand Down
1 change: 1 addition & 0 deletions target/riscv/kvm/kvm_riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
uint64_t guest_num);
void riscv_kvm_aplic_request(void *opaque, int irq, int level);
int kvm_riscv_sync_mpstate_to_kvm(RISCVCPU *cpu, int state);
uint64_t kvm_riscv_get_timebase_frequency(CPUState *cs);

#endif

0 comments on commit 1e4ec09

Please sign in to comment.