Skip to content

Commit 52ec4b6

Browse files
committed
RISC-V: KVM: Save mvendorid, marchid, and mimpid when creating VCPU
We should save VCPU mvendorid, marchid, and mimpid at the time of creating VCPU so that we don't have to do host SBI call every time Guest/VM ask for these details. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent a1a44e2 commit 52ec4b6

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

arch/riscv/include/asm/kvm_host.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ struct kvm_vcpu_arch {
165165
/* ISA feature bits (similar to MISA) */
166166
DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
167167

168+
/* Vendor, Arch, and Implementation details */
169+
unsigned long mvendorid;
170+
unsigned long marchid;
171+
unsigned long mimpid;
172+
168173
/* SSCRATCH, STVEC, and SCOUNTEREN of Host */
169174
unsigned long host_sscratch;
170175
unsigned long host_stvec;

arch/riscv/kvm/vcpu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <asm/csr.h>
2222
#include <asm/cacheflush.h>
2323
#include <asm/hwcap.h>
24+
#include <asm/sbi.h>
2425

2526
const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
2627
KVM_GENERIC_VCPU_STATS(),
@@ -171,6 +172,11 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
171172
set_bit(host_isa, vcpu->arch.isa);
172173
}
173174

175+
/* Setup vendor, arch, and implementation details */
176+
vcpu->arch.mvendorid = sbi_get_mvendorid();
177+
vcpu->arch.marchid = sbi_get_marchid();
178+
vcpu->arch.mimpid = sbi_get_mimpid();
179+
174180
/* Setup VCPU hfence queue */
175181
spin_lock_init(&vcpu->arch.hfence_lock);
176182

arch/riscv/kvm/vcpu_sbi_base.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
1919
{
2020
int ret = 0;
2121
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
22-
struct sbiret ecall_ret;
2322

2423
switch (cp->a6) {
2524
case SBI_EXT_BASE_GET_SPEC_VERSION:
@@ -48,13 +47,13 @@ static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
4847
*out_val = kvm_vcpu_sbi_find_ext(cp->a0) ? 1 : 0;
4948
break;
5049
case SBI_EXT_BASE_GET_MVENDORID:
50+
*out_val = vcpu->arch.mvendorid;
51+
break;
5152
case SBI_EXT_BASE_GET_MARCHID:
53+
*out_val = vcpu->arch.marchid;
54+
break;
5255
case SBI_EXT_BASE_GET_MIMPID:
53-
ecall_ret = sbi_ecall(SBI_EXT_BASE, cp->a6, 0, 0, 0, 0, 0, 0);
54-
if (!ecall_ret.error)
55-
*out_val = ecall_ret.value;
56-
/*TODO: We are unnecessarily converting the error twice */
57-
ret = sbi_err_map_linux_errno(ecall_ret.error);
56+
*out_val = vcpu->arch.mimpid;
5857
break;
5958
default:
6059
ret = -EOPNOTSUPP;

0 commit comments

Comments
 (0)