]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
RISC-V: KVM: Add SBI STA info to vcpu_arch
authorAndrew Jones <ajones@ventanamicro.com>
Wed, 20 Dec 2023 16:00:19 +0000 (17:00 +0100)
committerAnup Patel <anup@brainfault.org>
Sat, 30 Dec 2023 05:56:26 +0000 (11:26 +0530)
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>
arch/riscv/include/asm/kvm_host.h
arch/riscv/kvm/vcpu.c
arch/riscv/kvm/vcpu_sbi_sta.c

index 230b82c3118d54b56d1e34dae7fc9b8f6d896add..525cba63e0c5350f7ff5887918f5f12f357de287 100644 (file)
@@ -263,6 +263,12 @@ struct kvm_vcpu_arch {
 
        /* 'static' configurations which are set only once */
        struct kvm_vcpu_config cfg;
+
+       /* SBI steal-time accounting */
+       struct {
+               gpa_t shmem;
+               u64 last_steal;
+       } sta;
 };
 
 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);
 void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu);
 void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu);
 
+void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu);
 void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu);
 
 #endif /* __RISCV_KVM_HOST_H__ */
index 6995b8b641e4294803431027be14814436f8f9b9..b5ca9f2e98acd216caf4dd7537d106ce4f5bcdc0 100644 (file)
@@ -83,6 +83,8 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu)
        vcpu->arch.hfence_tail = 0;
        memset(vcpu->arch.hfence_queue, 0, sizeof(vcpu->arch.hfence_queue));
 
+       kvm_riscv_vcpu_sbi_sta_reset(vcpu);
+
        /* Reset the guest CSRs for hotplug usecase */
        if (loaded)
                kvm_arch_vcpu_load(vcpu, smp_processor_id());
index e28351c9488b3dae5d26f968c5d24ed310272a49..6592d287fc4e57d608b5ae6ea3e43e8985a7cea3 100644 (file)
@@ -8,8 +8,18 @@
 #include <asm/kvm_vcpu_sbi.h>
 #include <asm/sbi.h>
 
+void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu)
+{
+       vcpu->arch.sta.shmem = INVALID_GPA;
+       vcpu->arch.sta.last_steal = 0;
+}
+
 void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
 {
+       gpa_t shmem = vcpu->arch.sta.shmem;
+
+       if (shmem == INVALID_GPA)
+               return;
 }
 
 static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu)