Re: [PATCH v9 13/22] KVM: arm64: pkvm: Use a single function to expose all id-regs

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

 



On Wed, Oct 13, 2021 at 01:03:37PM +0100, Marc Zyngier wrote:
> Rather than exposing a whole set of helper functions to retrieve
> individual ID registers, use the existing decoding tree and expose
> a single helper instead.
> 
> This allow a number of functions to be made static, and we now
> have a single entry point to maintain.
> 
> Signed-off-by: Marc Zyngier <maz@xxxxxxxxxx>
> ---
>  arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 14 +-------
>  arch/arm64/kvm/hyp/nvhe/pkvm.c             | 10 +++---
>  arch/arm64/kvm/hyp/nvhe/sys_regs.c         | 37 ++++++++++++----------
>  3 files changed, 26 insertions(+), 35 deletions(-)
> 
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/sys_regs.h b/arch/arm64/kvm/hyp/include/nvhe/sys_regs.h
> index 3288128738aa..8adc13227b1a 100644
> --- a/arch/arm64/kvm/hyp/include/nvhe/sys_regs.h
> +++ b/arch/arm64/kvm/hyp/include/nvhe/sys_regs.h
> @@ -9,19 +9,7 @@
>  
>  #include <asm/kvm_host.h>
>  
> -u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64isar0(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64mmfr1(const struct kvm_vcpu *vcpu);
> -u64 get_pvm_id_aa64mmfr2(const struct kvm_vcpu *vcpu);

This is nice.

> -
> +u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id);
>  bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code);
>  int kvm_check_pvm_sysreg_table(void);
>  void inject_undef64(struct kvm_vcpu *vcpu);
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index 633547cc1033..62377fa8a4cb 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -15,7 +15,7 @@
>   */
>  static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
>  {
> -	const u64 feature_ids = get_pvm_id_aa64pfr0(vcpu);
> +	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR0_EL1);
>  	u64 hcr_set = HCR_RW;
>  	u64 hcr_clear = 0;
>  	u64 cptr_set = 0;
> @@ -62,7 +62,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
>   */
>  static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)
>  {
> -	const u64 feature_ids = get_pvm_id_aa64pfr1(vcpu);
> +	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR1_EL1);
>  	u64 hcr_set = 0;
>  	u64 hcr_clear = 0;
>  
> @@ -81,7 +81,7 @@ static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)
>   */
>  static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
>  {
> -	const u64 feature_ids = get_pvm_id_aa64dfr0(vcpu);
> +	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64DFR0_EL1);
>  	u64 mdcr_set = 0;
>  	u64 mdcr_clear = 0;
>  	u64 cptr_set = 0;
> @@ -125,7 +125,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
>   */
>  static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)
>  {
> -	const u64 feature_ids = get_pvm_id_aa64mmfr0(vcpu);
> +	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64MMFR0_EL1);
>  	u64 mdcr_set = 0;
>  
>  	/* Trap Debug Communications Channel registers */
> @@ -140,7 +140,7 @@ static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)
>   */
>  static void pvm_init_traps_aa64mmfr1(struct kvm_vcpu *vcpu)
>  {
> -	const u64 feature_ids = get_pvm_id_aa64mmfr1(vcpu);
> +	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64MMFR1_EL1);
>  	u64 hcr_set = 0;
>  
>  	/* Trap LOR */
> diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
> index 6bde2dc5205c..f125d6a52880 100644
> --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c
> +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
> @@ -82,7 +82,7 @@ static u64 get_restricted_features_unsigned(u64 sys_reg_val,
>   * based on allowed features, system features, and KVM support.
>   */
>  
> -u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
>  {
>  	const struct kvm *kvm = (const struct kvm *)kern_hyp_va(vcpu->kvm);
>  	u64 set_mask = 0;
> @@ -103,7 +103,7 @@ u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
>  	return (id_aa64pfr0_el1_sys_val & allow_mask) | set_mask;
>  }
>  
> -u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
>  {
>  	const struct kvm *kvm = (const struct kvm *)kern_hyp_va(vcpu->kvm);
>  	u64 allow_mask = PVM_ID_AA64PFR1_ALLOW;
> @@ -114,7 +114,7 @@ u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
>  	return id_aa64pfr1_el1_sys_val & allow_mask;
>  }
>  
> -u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
>  {
>  	/*
>  	 * No support for Scalable Vectors, therefore, hyp has no sanitized
> @@ -124,7 +124,7 @@ u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> -u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
>  {
>  	/*
>  	 * No support for debug, including breakpoints, and watchpoints,
> @@ -134,7 +134,7 @@ u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> -u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)
>  {
>  	/*
>  	 * No support for debug, therefore, hyp has no sanitized copy of the
> @@ -144,7 +144,7 @@ u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> -u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
>  {
>  	/*
>  	 * No support for implementation defined features, therefore, hyp has no
> @@ -154,7 +154,7 @@ u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> -u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
>  {
>  	/*
>  	 * No support for implementation defined features, therefore, hyp has no
> @@ -164,12 +164,12 @@ u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> -u64 get_pvm_id_aa64isar0(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64isar0(const struct kvm_vcpu *vcpu)
>  {
>  	return id_aa64isar0_el1_sys_val & PVM_ID_AA64ISAR0_ALLOW;
>  }
>  
> -u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
>  {
>  	u64 allow_mask = PVM_ID_AA64ISAR1_ALLOW;
>  
> @@ -182,7 +182,7 @@ u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
>  	return id_aa64isar1_el1_sys_val & allow_mask;
>  }
>  
> -u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)
>  {
>  	u64 set_mask;
>  
> @@ -192,22 +192,19 @@ u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)
>  	return (id_aa64mmfr0_el1_sys_val & PVM_ID_AA64MMFR0_ALLOW) | set_mask;
>  }
>  
> -u64 get_pvm_id_aa64mmfr1(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64mmfr1(const struct kvm_vcpu *vcpu)
>  {
>  	return id_aa64mmfr1_el1_sys_val & PVM_ID_AA64MMFR1_ALLOW;
>  }
>  
> -u64 get_pvm_id_aa64mmfr2(const struct kvm_vcpu *vcpu)
> +static u64 get_pvm_id_aa64mmfr2(const struct kvm_vcpu *vcpu)
>  {
>  	return id_aa64mmfr2_el1_sys_val & PVM_ID_AA64MMFR2_ALLOW;
>  }
>  
> -/* Read a sanitized cpufeature ID register by its sys_reg_desc. */
> -static u64 read_id_reg(const struct kvm_vcpu *vcpu,
> -		       struct sys_reg_desc const *r)
> +/* Read a sanitized cpufeature ID register by its encoding */
> +u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id)
>  {
> -	u32 id = reg_to_encoding(r);
> -
>  	switch (id) {
>  	case SYS_ID_AA64PFR0_EL1:
>  		return get_pvm_id_aa64pfr0(vcpu);
> @@ -245,6 +242,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
>  	return 0;
>  }
>  
> +static u64 read_id_reg(const struct kvm_vcpu *vcpu,
> +		       struct sys_reg_desc const *r)
> +{
> +	return pvm_read_id_reg(vcpu, reg_to_encoding(r));
> +}
> +
>  /*
>   * Accessor for AArch32 feature id registers.
>   *
> -- 
> 2.30.2
>

Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx>

_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm



[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux