Skip to content

Commit ad90512

Browse files
author
Marc Zyngier
committed
KVM: arm64: Add REQUIRES_E2H1 constraint as configuration flags
A bunch of EL2 configuration are very similar to their EL1 counterpart, with the added constraint that HCR_EL2.E2H being 1. For us, this means HCR_EL2.E2H being RES1, which is something we can statically evaluate. Add a REQUIRES_E2H1 constraint, which allows us to express conditions in a much simpler way (without extra code). Existing occurrences are converted, before we add a lot more. Reviewed-by: Fuad Tabba <tabba@google.com> Tested-by: Fuad Tabba <tabba@google.com> Link: https://patch.msgid.link/20260202184329.2724080-12-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 8d94458 commit ad90512

1 file changed

Lines changed: 14 additions & 24 deletions

File tree

arch/arm64/kvm/config.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct reg_bits_to_feat_map {
2525
#define FIXED_VALUE BIT(2) /* RAZ/WI or RAO/WI in KVM */
2626
#define MASKS_POINTER BIT(3) /* Pointer to fgt_masks struct instead of bits */
2727
#define AS_RES1 BIT(4) /* RES1 when not supported */
28+
#define REQUIRES_E2H1 BIT(5) /* Add HCR_EL2.E2H RES1 as a pre-condition */
2829

2930
unsigned long flags;
3031

@@ -311,21 +312,6 @@ static bool feat_trbe_mpam(struct kvm *kvm)
311312
(read_sysreg_s(SYS_TRBIDR_EL1) & TRBIDR_EL1_MPAM));
312313
}
313314

314-
static bool feat_asid2_e2h1(struct kvm *kvm)
315-
{
316-
return kvm_has_feat(kvm, FEAT_ASID2) && !kvm_has_feat(kvm, FEAT_E2H0);
317-
}
318-
319-
static bool feat_d128_e2h1(struct kvm *kvm)
320-
{
321-
return kvm_has_feat(kvm, FEAT_D128) && !kvm_has_feat(kvm, FEAT_E2H0);
322-
}
323-
324-
static bool feat_mec_e2h1(struct kvm *kvm)
325-
{
326-
return kvm_has_feat(kvm, FEAT_MEC) && !kvm_has_feat(kvm, FEAT_E2H0);
327-
}
328-
329315
static bool feat_ebep_pmuv3_ss(struct kvm *kvm)
330316
{
331317
return kvm_has_feat(kvm, FEAT_EBEP) || kvm_has_feat(kvm, FEAT_PMUv3_SS);
@@ -1045,15 +1031,15 @@ static const DECLARE_FEAT_MAP(sctlr2_desc, SCTLR2_EL1,
10451031
sctlr2_feat_map, FEAT_SCTLR2);
10461032

10471033
static const struct reg_bits_to_feat_map tcr2_el2_feat_map[] = {
1048-
NEEDS_FEAT(TCR2_EL2_FNG1 |
1049-
TCR2_EL2_FNG0 |
1050-
TCR2_EL2_A2,
1051-
feat_asid2_e2h1),
1052-
NEEDS_FEAT(TCR2_EL2_DisCH1 |
1053-
TCR2_EL2_DisCH0 |
1054-
TCR2_EL2_D128,
1055-
feat_d128_e2h1),
1056-
NEEDS_FEAT(TCR2_EL2_AMEC1, feat_mec_e2h1),
1034+
NEEDS_FEAT_FLAG(TCR2_EL2_FNG1 |
1035+
TCR2_EL2_FNG0 |
1036+
TCR2_EL2_A2,
1037+
REQUIRES_E2H1, FEAT_ASID2),
1038+
NEEDS_FEAT_FLAG(TCR2_EL2_DisCH1 |
1039+
TCR2_EL2_DisCH0 |
1040+
TCR2_EL2_D128,
1041+
REQUIRES_E2H1, FEAT_D128),
1042+
NEEDS_FEAT_FLAG(TCR2_EL2_AMEC1, REQUIRES_E2H1, FEAT_MEC),
10571043
NEEDS_FEAT(TCR2_EL2_AMEC0, FEAT_MEC),
10581044
NEEDS_FEAT(TCR2_EL2_HAFT, FEAT_HAFT),
10591045
NEEDS_FEAT(TCR2_EL2_PTTWI |
@@ -1284,6 +1270,7 @@ static struct resx compute_resx_bits(struct kvm *kvm,
12841270
unsigned long require,
12851271
unsigned long exclude)
12861272
{
1273+
bool e2h0 = kvm_has_feat(kvm, FEAT_E2H0);
12871274
struct resx resx = {};
12881275

12891276
for (int i = 0; i < map_size; i++) {
@@ -1306,6 +1293,9 @@ static struct resx compute_resx_bits(struct kvm *kvm,
13061293
match = idreg_feat_match(kvm, &map[i]);
13071294
}
13081295

1296+
if (map[i].flags & REQUIRES_E2H1)
1297+
match &= !e2h0;
1298+
13091299
if (!match) {
13101300
if (map[i].flags & AS_RES1)
13111301
resx.res1 |= reg_feat_map_bits(&map[i]);

0 commit comments

Comments
 (0)