From: Marc Zyngier <maz@kernel.org>
To: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Cc: Steffen Eiden <seiden@linux.ibm.com>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oupton@kernel.org>,
Zenghui Yu <yuzenghui@huawei.com>,
Fuad Tabba <fuad.tabba@linux.dev>
Subject: [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation
Date: Mon, 23 Nov 2026 19:24:55 +0000 [thread overview]
Message-ID: <20261123192457.8700-2-maz@kernel.org> (raw)
In-Reply-To: <20261123192457.8700-1-maz@kernel.org>
While a good deal of ID register fields are simple booleans, simply
indicating whether a feature is supported, a number of them are more
structured and indicate a level of support.
Reuse the existing framework in a nested way to expose which level
applies for the current configuration. This relies on the levels
being ordered from the most to the least capable, and the fallback
to have a NULL callback.
Yes, this is pretty obscure, but the following patches will make
this clearer (at least one hopes...).
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/config.c | 44 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
index cfdb6c7133204..40965513ebacf 100644
--- a/arch/arm64/kvm/config.c
+++ b/arch/arm64/kvm/config.c
@@ -28,6 +28,7 @@ struct reg_bits_to_feat_map {
#define REQUIRES_E2H1 BIT(5) /* Add HCR_EL2.E2H RES1 as a pre-condition */
#define RES1_WHEN_E2H0 BIT(6) /* RES1 when E2H=0 and not supported */
#define RES1_WHEN_E2H1 BIT(7) /* RES1 when E2H=1 and not supported */
+#define IDREG_FIELDS BIT(8) /* idreg fields */
unsigned long flags;
@@ -40,6 +41,7 @@ struct reg_bits_to_feat_map {
s8 lo_lim;
};
bool (*match)(struct kvm *);
+ const struct reg_bits_to_feat_map *idreg_field_deps;
};
};
@@ -73,6 +75,13 @@ struct reg_feat_map_desc {
.lo_lim = id ##_## fld ##_## lim \
}
+#define __NEEDS_FEAT_2(m, f, w, dummy, deps) \
+ { \
+ .w = (m), \
+ .flags = (f), \
+ .idreg_field_deps = (deps), \
+ }
+
#define __NEEDS_FEAT_1(m, f, w, fun) \
{ \
.w = (m), \
@@ -95,6 +104,11 @@ struct reg_feat_map_desc {
#define NEEDS_FEAT_MASKS(p, ...) \
__NEEDS_FEAT_FLAG(p, MASKS_POINTER, masks, __VA_ARGS__)
+#define NEEDS_FEAT_FIELD(m, ...) \
+ __NEEDS_FEAT_FLAG(m, IDREG_FIELDS, bits, blah, __VA_ARGS__)
+
+#define ENUM_FEAT(e, f) { .bits = e, .match = f }
+
/*
* Declare the dependency between a set of bits and a set of features,
* generating a struct reg_bit_to_feat_map.
@@ -1456,6 +1470,27 @@ static const struct reg_feat_map_desc *idreg_feat_maps[] = {
&id_aa64mmfr3_el1_desc,
};
+static struct resx compute_idreg_field_deps(struct kvm *kvm,
+ const struct reg_bits_to_feat_map *map)
+{
+ const struct reg_bits_to_feat_map *tmp;
+ struct resx resx;
+
+ /*
+ * Assume the enum values are ordered in reverse order of
+ * capability (from most to least capable). A NULL callback
+ * value indicates the ultimate fallback (not implemented).
+ */
+ for (tmp = map->idreg_field_deps; tmp->match; tmp++)
+ if (tmp->match(kvm))
+ break;
+
+ resx.res0 = field_prep(map->bits, ~(tmp->bits));
+ resx.res1 = field_prep(map->bits, tmp->bits);
+
+ return resx;
+}
+
static bool idreg_apply_deps(struct kvm *kvm, const struct reg_feat_map_desc *r)
{
struct resx resx = {};
@@ -1463,8 +1498,15 @@ static bool idreg_apply_deps(struct kvm *kvm, const struct reg_feat_map_desc *r)
for (int i = 0; i < r->bit_feat_map_sz; i++) {
if ((r->bit_feat_map[i].flags & CALL_FUNC) &&
- !r->bit_feat_map[i].match(kvm))
+ !r->bit_feat_map[i].match(kvm)) {
resx.res0 |= reg_feat_map_bits(&r->bit_feat_map[i]);
+ } else if (r->bit_feat_map[i].flags & IDREG_FIELDS) {
+ struct resx tmp;
+
+ tmp = compute_idreg_field_deps(kvm, &r->bit_feat_map[i]);
+ resx.res0 |= tmp.res0;
+ resx.res1 |= tmp.res1;
+ }
}
val = kvm->arch.id_regs[r->idreg_idx];
--
2.47.3
next prev parent reply other threads:[~2026-11-23 19:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 19:24 [PATCH 0/3] KVM: arm64: Convert GIC idreg sanitisation to the confic framework Marc Zyngier
2026-11-23 19:24 ` Marc Zyngier [this message]
2026-11-23 19:34 ` [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation sashiko-bot
2026-11-24 8:35 ` Fuad Tabba
2026-11-25 15:50 ` Wei-Lin Chang
2026-11-23 19:24 ` [PATCH 2/3] KVM: arm64: Add GIC idregs sanitisation to common framework Marc Zyngier
2026-11-24 9:05 ` Fuad Tabba
2026-11-23 19:24 ` [PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation Marc Zyngier
2026-11-24 9:38 ` Fuad Tabba
2026-11-24 10:50 ` Marc Zyngier
2026-11-24 12:02 ` Fuad Tabba
2026-11-24 9:44 ` [PATCH 0/3] KVM: arm64: Convert GIC idreg sanitisation to the confic framework Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123192457.8700-2-maz@kernel.org \
--to=maz@kernel.org \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.