Skip to content

Commit efe5406

Browse files
author
Marc Zyngier
committed
KVM: arm64: Convert HCR_EL2 RES0 handling to compute_reg_res0_bits()
While HCR_EL2 is unlikely to ever be RES0 (at least when NV is on), but consistency doesn't hurt, and it can be described in the same way as the other registers. Convert it over to the new RES0-computing infrastructure. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent c99d627 commit efe5406

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

arch/arm64/kvm/config.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct reg_feat_map_desc {
136136
#define FEAT_AA32EL0 ID_AA64PFR0_EL1, EL0, AARCH32
137137
#define FEAT_AA32EL1 ID_AA64PFR0_EL1, EL1, AARCH32
138138
#define FEAT_AA64EL1 ID_AA64PFR0_EL1, EL1, IMP
139+
#define FEAT_AA64EL2 ID_AA64PFR0_EL1, EL2, IMP
139140
#define FEAT_AA64EL3 ID_AA64PFR0_EL1, EL3, IMP
140141
#define FEAT_AIE ID_AA64MMFR3_EL1, AIE, IMP
141142
#define FEAT_S2POE ID_AA64MMFR3_EL1, S2POE, IMP
@@ -1005,6 +1006,9 @@ static const struct reg_bits_to_feat_map hcr_feat_map[] = {
10051006
NEEDS_FEAT_FIXED(HCR_EL2_E2H, compute_hcr_e2h),
10061007
};
10071008

1009+
static const DECLARE_FEAT_MAP(hcr_desc, HCR_EL2,
1010+
hcr_feat_map, FEAT_AA64EL2);
1011+
10081012
static const struct reg_bits_to_feat_map sctlr2_feat_map[] = {
10091013
NEEDS_FEAT(SCTLR2_EL1_NMEA |
10101014
SCTLR2_EL1_EASE,
@@ -1187,8 +1191,7 @@ void __init check_feature_map(void)
11871191
check_reg_desc(&hdfgrtr2_desc);
11881192
check_reg_desc(&hdfgwtr2_desc);
11891193
check_reg_desc(&hcrx_desc);
1190-
check_feat_map(hcr_feat_map, ARRAY_SIZE(hcr_feat_map),
1191-
HCR_EL2_RES0, "HCR_EL2");
1194+
check_reg_desc(&hcr_desc);
11921195
check_feat_map(sctlr2_feat_map, ARRAY_SIZE(sctlr2_feat_map),
11931196
SCTLR2_EL1_RES0, "SCTLR2_EL1");
11941197
check_feat_map(tcr2_el2_feat_map, ARRAY_SIZE(tcr2_el2_feat_map),
@@ -1278,15 +1281,13 @@ static u64 compute_reg_res0_bits(struct kvm *kvm,
12781281
return res0;
12791282
}
12801283

1281-
static u64 compute_fixed_bits(struct kvm *kvm,
1282-
const struct reg_bits_to_feat_map *map,
1283-
int map_size,
1284-
u64 *fixed_bits,
1285-
unsigned long require,
1286-
unsigned long exclude)
1284+
static u64 compute_reg_fixed_bits(struct kvm *kvm,
1285+
const struct reg_feat_map_desc *r,
1286+
u64 *fixed_bits, unsigned long require,
1287+
unsigned long exclude)
12871288
{
1288-
return __compute_fixed_bits(kvm, map, map_size, fixed_bits,
1289-
require | FIXED_VALUE, exclude);
1289+
return __compute_fixed_bits(kvm, r->bit_feat_map, r->bit_feat_map_sz,
1290+
fixed_bits, require | FIXED_VALUE, exclude);
12901291
}
12911292

12921293
void compute_fgu(struct kvm *kvm, enum fgt_group_id fgt)
@@ -1391,12 +1392,9 @@ void get_reg_fixed_bits(struct kvm *kvm, enum vcpu_sysreg reg, u64 *res0, u64 *r
13911392
*res1 = __HCRX_EL2_RES1;
13921393
break;
13931394
case HCR_EL2:
1394-
mask = compute_fixed_bits(kvm, hcr_feat_map,
1395-
ARRAY_SIZE(hcr_feat_map), &fixed,
1396-
0, 0);
1397-
*res0 = compute_res0_bits(kvm, hcr_feat_map,
1398-
ARRAY_SIZE(hcr_feat_map), 0, 0);
1399-
*res0 |= HCR_EL2_RES0 | (mask & ~fixed);
1395+
mask = compute_reg_fixed_bits(kvm, &hcr_desc, &fixed, 0, 0);
1396+
*res0 = compute_reg_res0_bits(kvm, &hcr_desc, 0, 0);
1397+
*res0 |= (mask & ~fixed);
14001398
*res1 = HCR_EL2_RES1 | (mask & fixed);
14011399
break;
14021400
case SCTLR2_EL1:

0 commit comments

Comments
 (0)