Skip to content

Commit ce75916

Browse files
author
Marc Zyngier
committed
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: Marc Zyngier <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Tested-by: Fuad Tabba <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8a04986 commit ce75916

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

arch/arm64/kvm/hyp/include/nvhe/sys_regs.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@
99

1010
#include <asm/kvm_host.h>
1111

12-
u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu);
13-
u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu);
14-
u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu);
15-
u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu);
16-
u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu);
17-
u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu);
18-
u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu);
19-
u64 get_pvm_id_aa64isar0(const struct kvm_vcpu *vcpu);
20-
u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu);
21-
u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu);
22-
u64 get_pvm_id_aa64mmfr1(const struct kvm_vcpu *vcpu);
23-
u64 get_pvm_id_aa64mmfr2(const struct kvm_vcpu *vcpu);
24-
12+
u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id);
2513
bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code);
2614
int kvm_check_pvm_sysreg_table(void);
2715
void inject_undef64(struct kvm_vcpu *vcpu);

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
1717
{
18-
const u64 feature_ids = get_pvm_id_aa64pfr0(vcpu);
18+
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR0_EL1);
1919
u64 hcr_set = HCR_RW;
2020
u64 hcr_clear = 0;
2121
u64 cptr_set = 0;
@@ -62,7 +62,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
6262
*/
6363
static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)
6464
{
65-
const u64 feature_ids = get_pvm_id_aa64pfr1(vcpu);
65+
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR1_EL1);
6666
u64 hcr_set = 0;
6767
u64 hcr_clear = 0;
6868

@@ -81,7 +81,7 @@ static void pvm_init_traps_aa64pfr1(struct kvm_vcpu *vcpu)
8181
*/
8282
static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
8383
{
84-
const u64 feature_ids = get_pvm_id_aa64dfr0(vcpu);
84+
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64DFR0_EL1);
8585
u64 mdcr_set = 0;
8686
u64 mdcr_clear = 0;
8787
u64 cptr_set = 0;
@@ -125,7 +125,7 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
125125
*/
126126
static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)
127127
{
128-
const u64 feature_ids = get_pvm_id_aa64mmfr0(vcpu);
128+
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64MMFR0_EL1);
129129
u64 mdcr_set = 0;
130130

131131
/* Trap Debug Communications Channel registers */
@@ -140,7 +140,7 @@ static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)
140140
*/
141141
static void pvm_init_traps_aa64mmfr1(struct kvm_vcpu *vcpu)
142142
{
143-
const u64 feature_ids = get_pvm_id_aa64mmfr1(vcpu);
143+
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64MMFR1_EL1);
144144
u64 hcr_set = 0;
145145

146146
/* Trap LOR */

arch/arm64/kvm/hyp/nvhe/sys_regs.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static u64 get_restricted_features_unsigned(u64 sys_reg_val,
8282
* based on allowed features, system features, and KVM support.
8383
*/
8484

85-
u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
85+
static u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
8686
{
8787
const struct kvm *kvm = (const struct kvm *)kern_hyp_va(vcpu->kvm);
8888
u64 set_mask = 0;
@@ -103,7 +103,7 @@ u64 get_pvm_id_aa64pfr0(const struct kvm_vcpu *vcpu)
103103
return (id_aa64pfr0_el1_sys_val & allow_mask) | set_mask;
104104
}
105105

106-
u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
106+
static u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
107107
{
108108
const struct kvm *kvm = (const struct kvm *)kern_hyp_va(vcpu->kvm);
109109
u64 allow_mask = PVM_ID_AA64PFR1_ALLOW;
@@ -114,7 +114,7 @@ u64 get_pvm_id_aa64pfr1(const struct kvm_vcpu *vcpu)
114114
return id_aa64pfr1_el1_sys_val & allow_mask;
115115
}
116116

117-
u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
117+
static u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
118118
{
119119
/*
120120
* No support for Scalable Vectors, therefore, hyp has no sanitized
@@ -124,7 +124,7 @@ u64 get_pvm_id_aa64zfr0(const struct kvm_vcpu *vcpu)
124124
return 0;
125125
}
126126

127-
u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
127+
static u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
128128
{
129129
/*
130130
* No support for debug, including breakpoints, and watchpoints,
@@ -134,7 +134,7 @@ u64 get_pvm_id_aa64dfr0(const struct kvm_vcpu *vcpu)
134134
return 0;
135135
}
136136

137-
u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)
137+
static u64 get_pvm_id_aa64dfr1(const struct kvm_vcpu *vcpu)
138138
{
139139
/*
140140
* 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)
144144
return 0;
145145
}
146146

147-
u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
147+
static u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
148148
{
149149
/*
150150
* No support for implementation defined features, therefore, hyp has no
@@ -154,7 +154,7 @@ u64 get_pvm_id_aa64afr0(const struct kvm_vcpu *vcpu)
154154
return 0;
155155
}
156156

157-
u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
157+
static u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
158158
{
159159
/*
160160
* No support for implementation defined features, therefore, hyp has no
@@ -164,12 +164,12 @@ u64 get_pvm_id_aa64afr1(const struct kvm_vcpu *vcpu)
164164
return 0;
165165
}
166166

167-
u64 get_pvm_id_aa64isar0(const struct kvm_vcpu *vcpu)
167+
static u64 get_pvm_id_aa64isar0(const struct kvm_vcpu *vcpu)
168168
{
169169
return id_aa64isar0_el1_sys_val & PVM_ID_AA64ISAR0_ALLOW;
170170
}
171171

172-
u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
172+
static u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
173173
{
174174
u64 allow_mask = PVM_ID_AA64ISAR1_ALLOW;
175175

@@ -182,7 +182,7 @@ u64 get_pvm_id_aa64isar1(const struct kvm_vcpu *vcpu)
182182
return id_aa64isar1_el1_sys_val & allow_mask;
183183
}
184184

185-
u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)
185+
static u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)
186186
{
187187
u64 set_mask;
188188

@@ -192,22 +192,19 @@ u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu)
192192
return (id_aa64mmfr0_el1_sys_val & PVM_ID_AA64MMFR0_ALLOW) | set_mask;
193193
}
194194

195-
u64 get_pvm_id_aa64mmfr1(const struct kvm_vcpu *vcpu)
195+
static u64 get_pvm_id_aa64mmfr1(const struct kvm_vcpu *vcpu)
196196
{
197197
return id_aa64mmfr1_el1_sys_val & PVM_ID_AA64MMFR1_ALLOW;
198198
}
199199

200-
u64 get_pvm_id_aa64mmfr2(const struct kvm_vcpu *vcpu)
200+
static u64 get_pvm_id_aa64mmfr2(const struct kvm_vcpu *vcpu)
201201
{
202202
return id_aa64mmfr2_el1_sys_val & PVM_ID_AA64MMFR2_ALLOW;
203203
}
204204

205-
/* Read a sanitized cpufeature ID register by its sys_reg_desc. */
206-
static u64 read_id_reg(const struct kvm_vcpu *vcpu,
207-
struct sys_reg_desc const *r)
205+
/* Read a sanitized cpufeature ID register by its encoding */
206+
u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id)
208207
{
209-
u32 id = reg_to_encoding(r);
210-
211208
switch (id) {
212209
case SYS_ID_AA64PFR0_EL1:
213210
return get_pvm_id_aa64pfr0(vcpu);
@@ -245,6 +242,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
245242
return 0;
246243
}
247244

245+
static u64 read_id_reg(const struct kvm_vcpu *vcpu,
246+
struct sys_reg_desc const *r)
247+
{
248+
return pvm_read_id_reg(vcpu, reg_to_encoding(r));
249+
}
250+
248251
/*
249252
* Accessor for AArch32 feature id registers.
250253
*

0 commit comments

Comments
 (0)