Skip to content

Commit 38b3390

Browse files
Andrew Jonesavpatel
authored andcommitted
RISC-V: KVM: Add SBI STA info to vcpu_arch
KVM's implementation of SBI STA needs to track the address of each VCPU's steal-time shared memory region as well as the amount of stolen time. Add a structure to vcpu_arch to contain this state and make sure that the address is always set to INVALID_GPA on vcpu reset. And, of course, ensure KVM won't try to update steal- time when the shared memory address is invalid. Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 2a1f6bf commit 38b3390

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

arch/riscv/include/asm/kvm_host.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ struct kvm_vcpu_arch {
263263

264264
/* 'static' configurations which are set only once */
265265
struct kvm_vcpu_config cfg;
266+
267+
/* SBI steal-time accounting */
268+
struct {
269+
gpa_t shmem;
270+
u64 last_steal;
271+
} sta;
266272
};
267273

268274
static inline void kvm_arch_sync_events(struct kvm *kvm) {}
@@ -373,6 +379,7 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask);
373379
void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu);
374380
void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu);
375381

382+
void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu);
376383
void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu);
377384

378385
#endif /* __RISCV_KVM_HOST_H__ */

arch/riscv/kvm/vcpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu)
8383
vcpu->arch.hfence_tail = 0;
8484
memset(vcpu->arch.hfence_queue, 0, sizeof(vcpu->arch.hfence_queue));
8585

86+
kvm_riscv_vcpu_sbi_sta_reset(vcpu);
87+
8688
/* Reset the guest CSRs for hotplug usecase */
8789
if (loaded)
8890
kvm_arch_vcpu_load(vcpu, smp_processor_id());

arch/riscv/kvm/vcpu_sbi_sta.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@
88
#include <asm/kvm_vcpu_sbi.h>
99
#include <asm/sbi.h>
1010

11+
void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu)
12+
{
13+
vcpu->arch.sta.shmem = INVALID_GPA;
14+
vcpu->arch.sta.last_steal = 0;
15+
}
16+
1117
void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
1218
{
19+
gpa_t shmem = vcpu->arch.sta.shmem;
20+
21+
if (shmem == INVALID_GPA)
22+
return;
1323
}
1424

1525
static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)