Skip to content

Commit dcaffa7

Browse files
James MorseMarc Zyngier
authored andcommitted
KVM: arm64: Remove target_table from exit handlers
Whenever KVM searches for a register (e.g. due to a guest exit), it works with two tables, as the target table overrides the sys_regs array. Now that everything is in the sys_regs array, and the target table is empty, stop doing that. Remove the second table and its size from all the functions that take it. Signed-off-by: James Morse <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent af47382 commit dcaffa7

File tree

1 file changed

+16
-71
lines changed

1 file changed

+16
-71
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,9 +2269,7 @@ static void unhandled_cp_access(struct kvm_vcpu *vcpu,
22692269
*/
22702270
static int kvm_handle_cp_64(struct kvm_vcpu *vcpu,
22712271
const struct sys_reg_desc *global,
2272-
size_t nr_global,
2273-
const struct sys_reg_desc *target_specific,
2274-
size_t nr_specific)
2272+
size_t nr_global)
22752273
{
22762274
struct sys_reg_params params;
22772275
u32 hsr = kvm_vcpu_get_hsr(vcpu);
@@ -2298,14 +2296,11 @@ static int kvm_handle_cp_64(struct kvm_vcpu *vcpu,
22982296
}
22992297

23002298
/*
2301-
* Try to emulate the coprocessor access using the target
2302-
* specific table first, and using the global table afterwards.
2303-
* If either of the tables contains a handler, handle the
2299+
* If the table contains a handler, handle the
23042300
* potential register operation in the case of a read and return
23052301
* with success.
23062302
*/
2307-
if (!emulate_cp(vcpu, &params, target_specific, nr_specific) ||
2308-
!emulate_cp(vcpu, &params, global, nr_global)) {
2303+
if (!emulate_cp(vcpu, &params, global, nr_global)) {
23092304
/* Split up the value between registers for the read side */
23102305
if (!params.is_write) {
23112306
vcpu_set_reg(vcpu, Rt, lower_32_bits(params.regval));
@@ -2326,9 +2321,7 @@ static int kvm_handle_cp_64(struct kvm_vcpu *vcpu,
23262321
*/
23272322
static int kvm_handle_cp_32(struct kvm_vcpu *vcpu,
23282323
const struct sys_reg_desc *global,
2329-
size_t nr_global,
2330-
const struct sys_reg_desc *target_specific,
2331-
size_t nr_specific)
2324+
size_t nr_global)
23322325
{
23332326
struct sys_reg_params params;
23342327
u32 hsr = kvm_vcpu_get_hsr(vcpu);
@@ -2344,8 +2337,7 @@ static int kvm_handle_cp_32(struct kvm_vcpu *vcpu,
23442337
params.Op1 = (hsr >> 14) & 0x7;
23452338
params.Op2 = (hsr >> 17) & 0x7;
23462339

2347-
if (!emulate_cp(vcpu, &params, target_specific, nr_specific) ||
2348-
!emulate_cp(vcpu, &params, global, nr_global)) {
2340+
if (!emulate_cp(vcpu, &params, global, nr_global)) {
23492341
if (!params.is_write)
23502342
vcpu_set_reg(vcpu, Rt, params.regval);
23512343
return 1;
@@ -2357,38 +2349,22 @@ static int kvm_handle_cp_32(struct kvm_vcpu *vcpu,
23572349

23582350
int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run)
23592351
{
2360-
const struct sys_reg_desc *target_specific;
2361-
size_t num;
2362-
2363-
target_specific = get_target_table(vcpu->arch.target, false, &num);
2364-
return kvm_handle_cp_64(vcpu,
2365-
cp15_64_regs, ARRAY_SIZE(cp15_64_regs),
2366-
target_specific, num);
2352+
return kvm_handle_cp_64(vcpu, cp15_64_regs, ARRAY_SIZE(cp15_64_regs));
23672353
}
23682354

23692355
int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run)
23702356
{
2371-
const struct sys_reg_desc *target_specific;
2372-
size_t num;
2373-
2374-
target_specific = get_target_table(vcpu->arch.target, false, &num);
2375-
return kvm_handle_cp_32(vcpu,
2376-
cp15_regs, ARRAY_SIZE(cp15_regs),
2377-
target_specific, num);
2357+
return kvm_handle_cp_32(vcpu, cp15_regs, ARRAY_SIZE(cp15_regs));
23782358
}
23792359

23802360
int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run)
23812361
{
2382-
return kvm_handle_cp_64(vcpu,
2383-
cp14_64_regs, ARRAY_SIZE(cp14_64_regs),
2384-
NULL, 0);
2362+
return kvm_handle_cp_64(vcpu, cp14_64_regs, ARRAY_SIZE(cp14_64_regs));
23852363
}
23862364

23872365
int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run)
23882366
{
2389-
return kvm_handle_cp_32(vcpu,
2390-
cp14_regs, ARRAY_SIZE(cp14_regs),
2391-
NULL, 0);
2367+
return kvm_handle_cp_32(vcpu, cp14_regs, ARRAY_SIZE(cp14_regs));
23922368
}
23932369

23942370
static bool is_imp_def_sys_reg(struct sys_reg_params *params)
@@ -2400,15 +2376,9 @@ static bool is_imp_def_sys_reg(struct sys_reg_params *params)
24002376
static int emulate_sys_reg(struct kvm_vcpu *vcpu,
24012377
struct sys_reg_params *params)
24022378
{
2403-
size_t num;
2404-
const struct sys_reg_desc *table, *r;
2405-
2406-
table = get_target_table(vcpu->arch.target, true, &num);
2379+
const struct sys_reg_desc *r;
24072380

2408-
/* Search target-specific then generic table. */
2409-
r = find_reg(params, table, num);
2410-
if (!r)
2411-
r = find_reg(params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
2381+
r = find_reg(params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
24122382

24132383
if (likely(r)) {
24142384
perform_access(vcpu, params, r);
@@ -2512,8 +2482,7 @@ const struct sys_reg_desc *find_reg_by_id(u64 id,
25122482
static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
25132483
u64 id)
25142484
{
2515-
size_t num;
2516-
const struct sys_reg_desc *table, *r;
2485+
const struct sys_reg_desc *r;
25172486
struct sys_reg_params params;
25182487

25192488
/* We only do sys_reg for now. */
@@ -2523,10 +2492,7 @@ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
25232492
if (!index_to_params(id, &params))
25242493
return NULL;
25252494

2526-
table = get_target_table(vcpu->arch.target, true, &num);
2527-
r = find_reg(&params, table, num);
2528-
if (!r)
2529-
r = find_reg(&params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
2495+
r = find_reg(&params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
25302496

25312497
/* Not saved in the sys_reg array and not otherwise accessible? */
25322498
if (r && !(r->reg || r->get_user))
@@ -2826,38 +2792,17 @@ static int walk_one_sys_reg(const struct kvm_vcpu *vcpu,
28262792
/* Assumed ordered tables, see kvm_sys_reg_table_init. */
28272793
static int walk_sys_regs(struct kvm_vcpu *vcpu, u64 __user *uind)
28282794
{
2829-
const struct sys_reg_desc *i1, *i2, *end1, *end2;
2795+
const struct sys_reg_desc *i2, *end2;
28302796
unsigned int total = 0;
2831-
size_t num;
28322797
int err;
28332798

2834-
/* We check for duplicates here, to allow arch-specific overrides. */
2835-
i1 = get_target_table(vcpu->arch.target, true, &num);
2836-
end1 = i1 + num;
28372799
i2 = sys_reg_descs;
28382800
end2 = sys_reg_descs + ARRAY_SIZE(sys_reg_descs);
28392801

2840-
if (i1 == end1)
2841-
i1 = NULL;
2842-
2843-
BUG_ON(i2 == end2);
2844-
2845-
/* Walk carefully, as both tables may refer to the same register. */
2846-
while (i1 || i2) {
2847-
int cmp = cmp_sys_reg(i1, i2);
2848-
/* target-specific overrides generic entry. */
2849-
if (cmp <= 0)
2850-
err = walk_one_sys_reg(vcpu, i1, &uind, &total);
2851-
else
2852-
err = walk_one_sys_reg(vcpu, i2, &uind, &total);
2853-
2802+
while (i2 != end2) {
2803+
err = walk_one_sys_reg(vcpu, i2++, &uind, &total);
28542804
if (err)
28552805
return err;
2856-
2857-
if (cmp <= 0 && ++i1 == end1)
2858-
i1 = NULL;
2859-
if (cmp >= 0 && ++i2 == end2)
2860-
i2 = NULL;
28612806
}
28622807
return total;
28632808
}

0 commit comments

Comments
 (0)