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 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation
Date: Mon, 23 Nov 2026 19:24:57 +0000 [thread overview]
Message-ID: <20261123192457.8700-4-maz@kernel.org> (raw)
In-Reply-To: <20261123192457.8700-1-maz@kernel.org>
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
prev parent reply other threads:[~2026-11-23 19:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261123192457.8700-1-maz@kernel.org>
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 [this message]
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-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox