Commit ce759167 authored by Marc Zyngier's avatar Marc Zyngier

KVM: arm64: pkvm: Use a single function to expose all id-regs

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: default avatarMarc Zyngier <maz@kernel.org>
Reviewed-by: default avatarAndrew Jones <drjones@redhat.com>
Reviewed-by: default avatarFuad Tabba <tabba@google.com>
Tested-by: default avatarFuad Tabba <tabba@google.com>
Link: https://lore.kernel.org/r/20211013120346.2926621-3-maz@kernel.org
parent 8a049862
...@@ -9,19 +9,7 @@ ...@@ -9,19 +9,7 @@
#include <asm/kvm_host.h> #include <asm/kvm_host.h>
u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu); u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id);
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);
bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code); bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code);
int kvm_check_pvm_sysreg_table(void); int kvm_check_pvm_sysreg_table(void);
void inject_undef64(struct kvm_vcpu *vcpu); void inject_undef64(struct kvm_vcpu *vcpu);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu) 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_set = HCR_RW;
u64 hcr_clear = 0; u64 hcr_clear = 0;
u64 cptr_set = 0; u64 cptr_set = 0;
...@@ -62,7 +62,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu) ...@@ -62,7 +62,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
*/ */
static void pvm_init_traps_aa64pfr1(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_set = 0;
u64 hcr_clear = 0; u64 hcr_clear = 0;
...@@ -81,7 +81,7 @@ static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu) ...@@ -81,7 +81,7 @@ static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)
*/ */
static void pvm_init_traps_aa64dfr0(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_set = 0;
u64 mdcr_clear = 0; u64 mdcr_clear = 0;
u64 cptr_set = 0; u64 cptr_set = 0;
...@@ -125,7 +125,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu) ...@@ -125,7 +125,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
*/ */
static void pvm_init_traps_aa64mmfr0(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; u64 mdcr_set = 0;
/* Trap Debug Communications Channel registers */ /* Trap Debug Communications Channel registers */
...@@ -140,7 +140,7 @@ static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu) ...@@ -140,7 +140,7 @@ static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)
*/ */
static void pvm_init_traps_aa64mmfr1(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; u64 hcr_set = 0;
/* Trap LOR */ /* Trap LOR */
......
...@@ -82,7 +82,7 @@ static u64 get_restricted_features_unsigned(u64 sys_reg_val, ...@@ -82,7 +82,7 @@ static u64 get_restricted_features_unsigned(u64 sys_reg_val,
* based on allowed features, system features, and KVM support. * 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); const struct kvm *kvm = (const struct kvm *)kern_hyp_va(vcpu->kvm);
u64 set_mask = 0; u64 set_mask = 0;
...@@ -103,7 +103,7 @@ u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu) ...@@ -103,7 +103,7 @@ u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
return (id_aa64pfr0_el1_sys_val & allow_mask) | set_mask; 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); const struct kvm *kvm = (const struct kvm *)kern_hyp_va(vcpu->kvm);
u64 allow_mask = PVM_ID_AA64PFR1_ALLOW; u64 allow_mask = PVM_ID_AA64PFR1_ALLOW;
...@@ -114,7 +114,7 @@ u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu) ...@@ -114,7 +114,7 @@ u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
return id_aa64pfr1_el1_sys_val & allow_mask; 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 * No support for Scalable Vectors, therefore, hyp has no sanitized
...@@ -124,7 +124,7 @@ u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu) ...@@ -124,7 +124,7 @@ u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
return 0; 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, * No support for debug, including breakpoints, and watchpoints,
...@@ -134,7 +134,7 @@ u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu) ...@@ -134,7 +134,7 @@ u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
return 0; 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 * 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) ...@@ -144,7 +144,7 @@ u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)
return 0; 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 * No support for implementation defined features, therefore, hyp has no
...@@ -154,7 +154,7 @@ u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu) ...@@ -154,7 +154,7 @@ u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
return 0; 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 * No support for implementation defined features, therefore, hyp has no
...@@ -164,12 +164,12 @@ u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu) ...@@ -164,12 +164,12 @@ u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
return 0; 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; 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; u64 allow_mask = PVM_ID_AA64ISAR1_ALLOW;
...@@ -182,7 +182,7 @@ u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu) ...@@ -182,7 +182,7 @@ u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
return id_aa64isar1_el1_sys_val & allow_mask; 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; u64 set_mask;
...@@ -192,22 +192,19 @@ u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu) ...@@ -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; 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; 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; return id_aa64mmfr2_el1_sys_val & PVM_ID_AA64MMFR2_ALLOW;
} }
/* Read a sanitized cpufeature ID register by its sys_reg_desc. */ /* Read a sanitized cpufeature ID register by its encoding */
static u64 read_id_reg(const struct kvm_vcpu *vcpu, u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id)
struct sys_reg_desc const *r)
{ {
u32 id = reg_to_encoding(r);
switch (id) { switch (id) {
case SYS_ID_AA64PFR0_EL1: case SYS_ID_AA64PFR0_EL1:
return get_pvm_id_aa64pfr0(vcpu); return get_pvm_id_aa64pfr0(vcpu);
...@@ -245,6 +242,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu, ...@@ -245,6 +242,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
return 0; 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. * Accessor for AArch32 feature id registers.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment