* [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation
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
2026-11-24 8:35 ` Fuad Tabba
2026-11-23 19:24 ` [PATCH 2/3] KVM: arm64: Add GIC idregs sanitisation to common framework Marc Zyngier
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2026-11-23 19:24 UTC (permalink / raw)
To: kvmarm, kvm, linux-arm-kernel
Cc: Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton,
Zenghui Yu, Fuad Tabba
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation
2026-11-23 19:24 ` [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation Marc Zyngier
@ 2026-11-24 8:35 ` Fuad Tabba
0 siblings, 0 replies; 10+ messages in thread
From: Fuad Tabba @ 2026-11-24 8:35 UTC (permalink / raw)
To: Marc Zyngier
Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly,
Suzuki K Poulose, Oliver Upton, Zenghui Yu
Hi Marc,
On Mon, 23 Nov 2026 19:24:55 +0000, Marc Zyngier <maz@kernel.org> wrote:
[...]
> diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
[...]
> +static struct resx compute_idreg_field_deps(struct kvm *kvm,
> + const struct reg_bits_to_feat_map *map)
> +{
[...]
> + 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);
Sashiko flagged the res0 line [1]. With the tables in patch 2 the loop
picks tmp at run time, and GCC 14 and clang 23 builds of config.c
don't trip the BUILD_BUG it describes.
nit: could you still compute res1 first and derive res0 from it, as
Sashiko suggests (res0 = map->bits & ~resx.res1)? That way
field_prep() is only passed values that fit the field, whatever the
compiler folds.
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Cheers,
/fuad
[1] https://lore.kernel.org/all/sashiko-outbox-229945@kernel.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] KVM: arm64: Add GIC idregs sanitisation to common framework
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 ` [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation Marc Zyngier
@ 2026-11-23 19:24 ` 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:44 ` [PATCH 0/3] KVM: arm64: Convert GIC idreg sanitisation to the confic framework Fuad Tabba
3 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2026-11-23 19:24 UTC (permalink / raw)
To: kvmarm, kvm, linux-arm-kernel
Cc: Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton,
Zenghui Yu, Fuad Tabba
It takes no least than 3 ID registers to describe whether a GICv3 or
GICv5 is supported. Define the sanitisation tables for the relevant
fields and the set of relevant callbacks.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/config.c | 56 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
index 40965513ebacf..7e702ce587a48 100644
--- a/arch/arm64/kvm/config.c
+++ b/arch/arm64/kvm/config.c
@@ -436,6 +436,23 @@ static bool feat_vmid16(struct kvm *kvm)
return kvm_has_feat_enum(kvm, ID_AA64MMFR1_EL1, VMIDBits, 16);
}
+static bool feat_gicv3(struct kvm *kvm)
+{
+ return (irqchip_in_kernel(kvm) &&
+ kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3);
+}
+
+static bool feat_gicv3_aarch32(struct kvm *kvm)
+{
+ return (kvm_supports_32bit_el0() && feat_gicv3(kvm));
+}
+
+static bool feat_gcie(struct kvm *kvm)
+{
+ return (irqchip_in_kernel(kvm) &&
+ kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V5);
+}
+
static const struct reg_bits_to_feat_map hfgrtr_feat_map[] = {
NEEDS_FEAT(HFGRTR_EL2_nAMAIR2_EL1 |
HFGRTR_EL2_nMAIR2_EL1,
@@ -1357,6 +1374,42 @@ static const struct reg_bits_to_feat_map id_aa64mmfr3_el1_feat_map[] = {
static const DECLARE_IDREG_FEAT_MAP(id_aa64mmfr3_el1_desc, ID_AA64MMFR3_EL1,
id_aa64mmfr3_el1_feat_map, FEAT_AA64EL1);
+static const struct reg_bits_to_feat_map aa64pfr0_gicv3[] = {
+ ENUM_FEAT(ID_AA64PFR0_EL1_GIC_IMP, feat_gicv3 ),
+ ENUM_FEAT(ID_AA64PFR0_EL1_GIC_NI, NULL ),
+};
+
+static const struct reg_bits_to_feat_map id_aa64pfr0_el1_feat_map[] = {
+ NEEDS_FEAT_FIELD(ID_AA64PFR0_EL1_GIC, aa64pfr0_gicv3),
+};
+
+static const DECLARE_IDREG_FEAT_MAP(id_aa64pfr0_el1_desc, ID_AA64PFR0_EL1,
+ id_aa64pfr0_el1_feat_map, FEAT_AA64EL1);
+
+static const struct reg_bits_to_feat_map pfr1_gicv3[] = {
+ ENUM_FEAT(ID_PFR1_EL1_GIC_GICv3, feat_gicv3_aarch32),
+ ENUM_FEAT(ID_PFR1_EL1_GIC_NI, NULL),
+};
+
+static const struct reg_bits_to_feat_map id_pfr1_el1_feat_map[] = {
+ NEEDS_FEAT_FIELD(ID_PFR1_EL1_GIC, pfr1_gicv3),
+};
+
+static const DECLARE_IDREG_FEAT_MAP(id_pfr1_el1_desc, ID_PFR1_EL1,
+ id_pfr1_el1_feat_map, FEAT_AA64EL1);
+
+static const struct reg_bits_to_feat_map aa64pfr2_gcie[] = {
+ ENUM_FEAT(ID_AA64PFR2_EL1_GCIE_IMP, feat_gcie),
+ ENUM_FEAT(ID_AA64PFR2_EL1_GCIE_NI, NULL),
+};
+
+static const struct reg_bits_to_feat_map id_aa64pfr2_el1_feat_map[] = {
+ NEEDS_FEAT_FIELD(ID_AA64PFR2_EL1_GCIE, aa64pfr2_gcie),
+};
+
+static const DECLARE_IDREG_FEAT_MAP(id_aa64pfr2_el1_desc, ID_AA64PFR2_EL1,
+ id_aa64pfr2_el1_feat_map, FEAT_AA64EL1);
+
static const struct reg_bits_to_feat_map ich_hfgrtr_feat_map[] = {
NEEDS_FEAT(ICH_HFGRTR_EL2_ICC_APR_EL1 |
ICH_HFGRTR_EL2_ICC_IDRn_EL1 |
@@ -1468,6 +1521,9 @@ void __init check_feature_map(void)
static const struct reg_feat_map_desc *idreg_feat_maps[] = {
&id_aa64mmfr3_el1_desc,
+ &id_aa64pfr0_el1_desc,
+ &id_aa64pfr2_el1_desc,
+ &id_pfr1_el1_desc,
};
static struct resx compute_idreg_field_deps(struct kvm *kvm,
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 2/3] KVM: arm64: Add GIC idregs sanitisation to common framework
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
0 siblings, 0 replies; 10+ messages in thread
From: Fuad Tabba @ 2026-11-24 9:05 UTC (permalink / raw)
To: Marc Zyngier
Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly,
Suzuki K Poulose, Oliver Upton, Zenghui Yu
Hi Marc,
On Mon, 23 Nov 2026 19:24:56 +0000, Marc Zyngier <maz@kernel.org> wrote:
> It takes no least than 3 ID registers to describe whether a GICv3 or
> GICv5 is supported. Define the sanitisation tables for the relevant
> fields and the set of relevant callbacks.
nit: s/no least than/no less than/
[...]
> diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
[...]
> +static bool feat_gicv3(struct kvm *kvm)
> +{
> + return (irqchip_in_kernel(kvm) &&
> + kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3);
> +}
nit: could this be irqchip_in_kernel(kvm) && vgic_is_v3(kvm), and
feat_gcie() use vgic_is_v5() the same way?
[...]
> +static const struct reg_bits_to_feat_map aa64pfr0_gicv3[] = {
> + ENUM_FEAT(ID_AA64PFR0_EL1_GIC_IMP, feat_gicv3 ),
> + ENUM_FEAT(ID_AA64PFR0_EL1_GIC_NI, NULL ),
> +};
nit: stray spaces before the closing parentheses.
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Cheers,
/fuad
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation
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 ` [PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation Marc Zyngier
2026-11-23 19:24 ` [PATCH 2/3] KVM: arm64: Add GIC idregs sanitisation to common framework Marc Zyngier
@ 2026-11-23 19:24 ` Marc Zyngier
2026-11-24 9:38 ` Fuad Tabba
2026-11-24 9:44 ` [PATCH 0/3] KVM: arm64: Convert GIC idreg sanitisation to the confic framework Fuad Tabba
3 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2026-11-23 19:24 UTC (permalink / raw)
To: kvmarm, kvm, linux-arm-kernel
Cc: Steffen Eiden, Joey Gouly, Suzuki K Poulose, Oliver Upton,
Zenghui Yu, Fuad Tabba
Now that we have a generic mechanism to sanitise the GIC idregs,
drop the open-coded version and replace it with a call to the
new code.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/sys_regs.c | 45 ---------------------------------
arch/arm64/kvm/vgic/vgic-init.c | 31 +----------------------
include/kvm/arm_vgic.h | 1 -
3 files changed, 1 insertion(+), 76 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 0687b78cd7c2b..d145541420b3a 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -5874,51 +5874,6 @@ static int kvm_vm_finalize_sys_regs(struct kvm *kvm)
kvm_idregs_enforce_dependencies(kvm);
- /*
- * This hacks into the ID registers, so only perform it when the
- * first vcpu runs, or the kvm_set_vm_id_reg() helper will scream.
- */
- if (!irqchip_in_kernel(kvm)) {
- u64 val;
-
- val = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1) & ~ID_AA64PFR0_EL1_GIC;
- kvm_set_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1, val);
- val = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR2_EL1) & ~ID_AA64PFR2_EL1_GCIE;
- kvm_set_vm_id_reg(kvm, SYS_ID_AA64PFR2_EL1, val);
- val = kvm_read_vm_id_reg(kvm, SYS_ID_PFR1_EL1) & ~ID_PFR1_EL1_GIC;
- kvm_set_vm_id_reg(kvm, SYS_ID_PFR1_EL1, val);
- } else {
- /*
- * Certain userspace software - QEMU - samples the system
- * register state without creating an irqchip, then blindly
- * restores the state prior to running the final guest. This
- * means that it restores the virtualization & emulation
- * capabilities of the host system, rather than something that
- * reflects the final guest state. Moreover, it checks that the
- * state was "correctly" restored (i.e., verbatim), bailing if
- * it isn't, so masking off invalid state isn't an option.
- *
- * On GICv5 hardware that supports FEAT_GCIE_LEGACY we can run
- * both GICv3- and GICv5-based guests. Therefore, we initially
- * present both ID_AA64PFR0.GIC and ID_AA64PFR2.GCIE as IMP to
- * reflect that userspace can create EITHER a vGICv3 or a
- * vGICv5. This is an architecturally invalid combination, of
- * course. Once an in-kernel GIC is created, the sysreg state is
- * updated to reflect the actual, valid configuration.
- *
- * Setting both the GIC and GCIE features to IMP unsurprisingly
- * results in guests falling over, and hence we need to fix up
- * this mess in KVM. Before running for the first time we yet
- * again ensure that the GIC and GCIE fields accurately reflect
- * the actual hardware the guest should see.
- *
- * This hack allows legacy QEMU-based GICv3 guests to run
- * unmodified on compatible GICv5 hosts, and avoids the inverse
- * problem for GICv5-based guests in the future.
- */
- kvm_vgic_finalize_idregs(kvm);
- }
-
set_bit(KVM_ARCH_FLAG_ID_REGS_FINAL, &kvm->arch.flags);
return 0;
diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
index c9991e24cb6b7..b6236146602d8 100644
--- a/arch/arm64/kvm/vgic/vgic-init.c
+++ b/arch/arm64/kvm/vgic/vgic-init.c
@@ -180,7 +180,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
* We've now created the GIC. Update the system register state
* to accurately reflect what we've created.
*/
- kvm_vgic_finalize_idregs(kvm);
+ kvm_idregs_enforce_dependencies(kvm);
kvm_for_each_vcpu(i, vcpu, kvm) {
ret = vgic_allocate_private_irqs_locked(vcpu, type);
@@ -770,35 +770,6 @@ int kvm_vgic_map_resources(struct kvm *kvm)
return ret;
}
-void kvm_vgic_finalize_idregs(struct kvm *kvm)
-{
- u32 type = kvm->arch.vgic.vgic_model;
- u64 aa64pfr0, aa64pfr2, pfr1;
-
- aa64pfr0 = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1) & ~ID_AA64PFR0_EL1_GIC;
- aa64pfr2 = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR2_EL1) & ~ID_AA64PFR2_EL1_GCIE;
- pfr1 = kvm_read_vm_id_reg(kvm, SYS_ID_PFR1_EL1) & ~ID_PFR1_EL1_GIC;
-
- switch (type) {
- case KVM_DEV_TYPE_ARM_VGIC_V2:
- break;
- case KVM_DEV_TYPE_ARM_VGIC_V3:
- aa64pfr0 |= SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, GIC, IMP);
- if (kvm_supports_32bit_el0())
- pfr1 |= SYS_FIELD_PREP_ENUM(ID_PFR1_EL1, GIC, GICv3);
- break;
- case KVM_DEV_TYPE_ARM_VGIC_V5:
- aa64pfr2 |= SYS_FIELD_PREP_ENUM(ID_AA64PFR2_EL1, GCIE, IMP);
- break;
- default:
- WARN_ONCE(1, "Unknown VGIC type!!!\n");
- }
-
- kvm_set_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1, aa64pfr0);
- kvm_set_vm_id_reg(kvm, SYS_ID_AA64PFR2_EL1, aa64pfr2);
- kvm_set_vm_id_reg(kvm, SYS_ID_PFR1_EL1, pfr1);
-}
-
/* GENERIC PROBE */
void kvm_vgic_cpu_up(void)
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index 4b2c41917b77c..956c68f75e7c0 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -689,7 +689,6 @@ int kvm_vgic_create(struct kvm *kvm, u32 type);
void kvm_vgic_destroy(struct kvm *kvm);
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu);
int kvm_vgic_map_resources(struct kvm *kvm);
-void kvm_vgic_finalize_idregs(struct kvm *kvm);
int kvm_vgic_hyp_init(void);
void kvm_vgic_init_cpu_hardware(void);
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation
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
0 siblings, 1 reply; 10+ messages in thread
From: Fuad Tabba @ 2026-11-24 9:38 UTC (permalink / raw)
To: Marc Zyngier
Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly,
Suzuki K Poulose, Oliver Upton, Zenghui Yu
Hi Marc,
On Mon, 23 Nov 2026 19:24:57 +0000, Marc Zyngier <maz@kernel.org> wrote:
[...]
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
[...]
> @@ -5874,51 +5874,6 @@ static int kvm_vm_finalize_sys_regs(struct kvm *kvm)
[...]
> - * On GICv5 hardware that supports FEAT_GCIE_LEGACY we can run
> - * both GICv3- and GICv5-based guests. Therefore, we initially
> - * present both ID_AA64PFR0.GIC and ID_AA64PFR2.GCIE as IMP to
> - * reflect that userspace can create EITHER a vGICv3 or a
> - * vGICv5. This is an architecturally invalid combination, of
> - * course. Once an in-kernel GIC is created, the sysreg state is
> - * updated to reflect the actual, valid configuration.
nit: This comment is the only place that explains why, on a
FEAT_GCIE_LEGACY host, a VM's ID registers can show both GIC and GCIE
as IMP before the VM first runs. sanitise_id_aa64pfr0_el1() and
sanitise_id_aa64pfr2_el1() still set both at reset. Is it worth having
a short version of it next to the tables patch 2 adds?
[...]
> diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
[...]
> @@ -180,7 +180,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
> * We've now created the GIC. Update the system register state
> * to accurately reflect what we've created.
> */
> - kvm_vgic_finalize_idregs(kvm);
> + kvm_idregs_enforce_dependencies(kvm);
This now also applies the S1P[IO]E dependencies when the vGIC is
created, at a point where userspace can still write the ID registers.
Was that intended? If this clears S1PIE or S1POE, the first KVM_RUN
doesn't restore it, so the final ID_AA64MMFR3_EL1 can change with the
order in which userspace writes the ID registers and creates the vGIC.
If that's the intent, should it say so in the commit message?
Cheers,
/fuad
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation
2026-11-24 9:38 ` Fuad Tabba
@ 2026-11-24 10:50 ` Marc Zyngier
2026-11-24 12:02 ` Fuad Tabba
0 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2026-11-24 10:50 UTC (permalink / raw)
To: Fuad Tabba
Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly,
Suzuki K Poulose, Oliver Upton, Zenghui Yu
On Tue, 24 Nov 2026 09:38:00 +0000,
Fuad Tabba <fuad.tabba@linux.dev> wrote:
>
> Hi Marc,
>
> On Mon, 23 Nov 2026 19:24:57 +0000, Marc Zyngier <maz@kernel.org> wrote:
> [...]
> > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> [...]
> > @@ -5874,51 +5874,6 @@ static int kvm_vm_finalize_sys_regs(struct kvm *kvm)
> [...]
> > - * On GICv5 hardware that supports FEAT_GCIE_LEGACY we can run
> > - * both GICv3- and GICv5-based guests. Therefore, we initially
> > - * present both ID_AA64PFR0.GIC and ID_AA64PFR2.GCIE as IMP to
> > - * reflect that userspace can create EITHER a vGICv3 or a
> > - * vGICv5. This is an architecturally invalid combination, of
> > - * course. Once an in-kernel GIC is created, the sysreg state is
> > - * updated to reflect the actual, valid configuration.
>
> nit: This comment is the only place that explains why, on a
> FEAT_GCIE_LEGACY host, a VM's ID registers can show both GIC and GCIE
> as IMP before the VM first runs. sanitise_id_aa64pfr0_el1() and
> sanitise_id_aa64pfr2_el1() still set both at reset. Is it worth having
> a short version of it next to the tables patch 2 adds?
I don't think that's the correct place. If anything, such comment
should be in the reset code, not in the sanitisation code, which
actually generates the architecturally compliant view.
>
> [...]
> > diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
> [...]
> > @@ -180,7 +180,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
> > * We've now created the GIC. Update the system register state
> > * to accurately reflect what we've created.
> > */
> > - kvm_vgic_finalize_idregs(kvm);
> > + kvm_idregs_enforce_dependencies(kvm);
>
> This now also applies the S1P[IO]E dependencies when the vGIC is
> created, at a point where userspace can still write the ID registers.
> Was that intended? If this clears S1PIE or S1POE, the first KVM_RUN
> doesn't restore it, so the final ID_AA64MMFR3_EL1 can change with the
> order in which userspace writes the ID registers and creates the vGIC.
> If that's the intent, should it say so in the commit message?
The commit message has no influence on the behaviour of the kernel.
However, I want to know whether this change is an acceptable behaviour
or not *from an ABI perspective*. We have several options:
(1) delay all idreg enforcement to the same (late) point
(2) keep things as currently done, meaning that the GIC fields are
special and sanitised at a different time
(3) say that idregs can change at any point if you change the
configuration of the system, such as creating a GIC
I'd be tempted to go with either (1) or (3). (2) feels like a total
bodge.
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation
2026-11-24 10:50 ` Marc Zyngier
@ 2026-11-24 12:02 ` Fuad Tabba
0 siblings, 0 replies; 10+ messages in thread
From: Fuad Tabba @ 2026-11-24 12:02 UTC (permalink / raw)
To: Marc Zyngier
Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly,
Suzuki K Poulose, Oliver Upton, Zenghui Yu
Hi Marc,
On Tue, 24 Nov 2026 10:50:11 +0000, Marc Zyngier <maz@kernel.org> wrote:
[...]
> However, I want to know whether this change is an acceptable behaviour
> or not *from an ABI perspective*. We have several options:
>
> (1) delay all idreg enforcement to the same (late) point
>
> (2) keep things as currently done, meaning that the GIC fields are
> special and sanitised at a different time
>
> (3) say that idregs can change at any point if you change the
> configuration of the system, such as creating a GIC
>
> I'd be tempted to go with either (1) or (3). (2) feels like a total
> bodge.
(3) works. The GIC fields can already change when userspace creates
the vGIC. The final ID_AA64MMFR3_EL1 only depends on the order if
userspace sets S1PIE or S1POE without the features they imply, creates
the vGIC, then sets those features.
(1) changes one thing afaict. A VMM that saves the ID registers
between creating the vGIC and the first run, and writes them back once
the VM has run, would get -EBUSY where the vGIC's GIC fields differ
from their reset value. QEMU and crosvm copy the registers as a block,
but I don't know if either ever does that.
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Cheers,
/fuad
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] KVM: arm64: Convert GIC idreg sanitisation to the confic framework
2026-11-23 19:24 [PATCH 0/3] KVM: arm64: Convert GIC idreg sanitisation to the confic framework Marc Zyngier
` (2 preceding siblings ...)
2026-11-23 19:24 ` [PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation Marc Zyngier
@ 2026-11-24 9:44 ` Fuad Tabba
3 siblings, 0 replies; 10+ messages in thread
From: Fuad Tabba @ 2026-11-24 9:44 UTC (permalink / raw)
To: Marc Zyngier
Cc: kvmarm, kvm, linux-arm-kernel, Steffen Eiden, Joey Gouly,
Suzuki K Poulose, Oliver Upton, Zenghui Yu
Hi Marc,
On Mon, 23 Nov 2026 19:24:54 +0000, Marc Zyngier <maz@kernel.org> wrote:
> Having started adding some sanitisation code in the idreg department
> with ID_AA64MMFR3_EL1.S1P[IO]E, I'm back with some more and trying to
> wrestle the GIC into submission...
[...]
Tested on QEMU, booting protected and non-protected guests on pKVM,
nVHE and VHE hosts, and running the set_id_regs, vgic_init and no-vgic
selftests on the nVHE and VHE hosts. Also ran the vgic_v5 selftest on
FVP, with and without GCIE_LEGACY.
Tested-by: Fuad Tabba <fuad.tabba@linux.dev>
Cheers,
/fuad
^ permalink raw reply [flat|nested] 10+ messages in thread