Re: [PATCH v3 06/13] RISC-V: KVM: Add SBI STA info to vcpu_arch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Dec 17, 2023 at 12:40 PM Andrew Jones <ajones@xxxxxxxxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxx>
> Signed-off-by: Andrew Jones <ajones@xxxxxxxxxxxxxxxx>
> ---
>  arch/riscv/include/asm/kvm_host.h |  7 +++++++
>  arch/riscv/kvm/vcpu.c             |  2 ++
>  arch/riscv/kvm/vcpu_sbi_sta.c     | 10 ++++++++++
>  3 files changed, 19 insertions(+)
>
> diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
> index 230b82c3118d..525cba63e0c5 100644
> --- a/arch/riscv/include/asm/kvm_host.h
> +++ b/arch/riscv/include/asm/kvm_host.h
> @@ -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__ */
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> index 6995b8b641e4..b5ca9f2e98ac 100644
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
> @@ -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());
> diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c
> index e28351c9488b..6592d287fc4e 100644
> --- a/arch/riscv/kvm/vcpu_sbi_sta.c
> +++ b/arch/riscv/kvm/vcpu_sbi_sta.c
> @@ -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)
> --
> 2.43.0
>

Reviewed-by: Atish Patra <atishp@xxxxxxxxxxxx>

-- 
Regards,
Atish





[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux