From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01964CA9ED1 for ; Mon, 12 Oct 2026 16:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cgHxOnsDjhFeq3kyHckVAbfTfBfbr2qRfjtgtalaxwQ=; b=rIZeP6TjTB0BVSIjdKbkyWq6bl 85IAHJCQEFz+ehkPOn3tDyxGVMw5QR8wDgg/iC8PmiNCw+TAURT+Ez8d5Yi+ZzMA+OExxrJGj19An xReNVmDjOhG1reIHntKR2j7gRBIEyeZfEjPzeke/9iVVS2U0qEKh6nggYtuLhkdjEGC/D5RSMCkrF cLw1wAM0DsQ9fMRp9K6RubaXo6dYE1QFI//4cMCNUFpcq1s6yR68mig3k24FTkJ08k9EZR3SRD06v 1V4wP8wkHDYJbLnxkJ1k5t0hrL23hptWHKqZEffG4SAqdzpHnGbgi5DChlY5eOwihlaKd8D8jPAwK lhAS0j1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xGIgt-0000000Aw8W-2IrT; Mon, 12 Oct 2026 16:15:55 +0000 Received: from out-86.mta0.migadu.com ([2001:41d0:1004:224b::56] helo=mta0.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xGIgi-0000000Aw4y-1Zpl for linux-arm-kernel@lists.infradead.org; Mon, 12 Oct 2026 16:15:53 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=AlgWXXlL64ISukcpD4mn3Z6rAwsBvHEkYXTdPZYRaJc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1791821742; v=1; x=1792426542; b=HCuaq9+v5ALKLNCbRSNr8Z653I6mdvCxrk9bQmp8DV03vFB/P1Nc+Ab/75Mo573yKvazsQgW yTVC6k+z5RDOpY8I7NY22GD2A53NVDVjjDcxTX/2PCXa7VaO1AftYXw1cF8k2/v4Gs1gGsshkVd UlstUEETRWPCPBw1fu4LWkSk= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id da1724085719ce2e; Mon, 12 Oct 2026 16:15:42 +0000 X-Mizu-Trace-ID: da1724085719ce2e X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, mark.rutland@arm.com, vdonnefort@google.com, qperret@google.com, Sascha.Bischoff@arm.com, steven.price@arm.com, tabba@google.com Subject: [PATCH v3 3/5] KVM: arm64: Validate the host-provided vgic model in pKVM Date: Mon, 12 Oct 2026 17:15:22 +0100 Message-Id: <20261012161524.4016464-4-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20261012161524.4016464-1-fuad.tabba@linux.dev> References: <20261012161524.4016464-1-fuad.tabba@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261012_091546_311281_D644441C X-CRM114-Status: GOOD ( 12.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org EL2 copies vgic_model from the host's struct kvm unchecked, and the nVHE world switch dispatches on it with no cpucap guard. A host writing KVM_DEV_TYPE_ARM_VGIC_V5 makes EL2 access GICv5 CPU interface registers that are UNDEFINED without FEAT_GCIE, and panics the hypervisor on any GICv3 machine. Accept only GICv3, the one model pKVM supports, and force anything else to 0, as for a VM with no in-kernel irqchip. EL2 reads the model only to pick the GICv5 world switch and to emulate GICv3 CPU interface accesses, and the host's own copy is left alone. Fixes: 9b8e3d4ca0e73 ("KVM: arm64: gic-v5: Implement GICv5 load/put and save/restore") Reviewed-by: Suzuki K Poulose Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 459bd9eb7e4bc..a9d0e94709199 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -340,13 +340,19 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc { struct kvm *kvm = &hyp_vm->kvm; unsigned long host_arch_flags = READ_ONCE(host_kvm->arch.flags); + u32 vgic_model = READ_ONCE(host_kvm->arch.vgic.vgic_model); DECLARE_BITMAP(allowed_features, KVM_VCPU_MAX_FEATURES); /* CTR_EL0 is always under host control, even for protected VMs. */ hyp_vm->kvm.arch.ctr_el0 = host_kvm->arch.ctr_el0; - /* Preserve the vgic model so that GICv3 emulation works */ - hyp_vm->kvm.arch.vgic.vgic_model = host_kvm->arch.vgic.vgic_model; + /* + * pKVM runs only GICv3. Anything else becomes 0, the model of a VM + * with no in-kernel irqchip, which keeps EL2 off the GICv5 registers. + */ + if (vgic_model != KVM_DEV_TYPE_ARM_VGIC_V3) + vgic_model = 0; + hyp_vm->kvm.arch.vgic.vgic_model = vgic_model; /* No restrictions for non-protected VMs. */ if (!kvm_vm_is_protected(kvm)) { -- 2.39.5