From nobody Fri Sep 25 03:16:11 2026 Received: from mta0.migadu.com (out-128.mta0.migadu.com [91.218.175.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D168B4AAC4E for ; Thu, 17 Sep 2026 09:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636720; cv=none; b=Uoma0LAT8Ztkngy4owyGfRseTsnzFZ8ItqDub7MLyE2MuH+AKsssYCdrVVceXq6N02Z/QXMZ5mRwYJIFt35UhgkzbOs+CjLKBBhp7avwzM4QiGeidqAKu/3XILUnNXb6NCeWoi5N8qGNhv5FT/npMeowGZMCSvBC+YUPQvdJFMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636720; c=relaxed/simple; bh=BDabPLEAy+F0bC1m2aFAySlST0o2PCUlunhb/0Rg9F0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pY9hPDzK1T4voWBKcuB4LaX1VxUlIJuo+cxnczZxkVH97Wb1/LXzjpRBEZ4b293qkv26dInsAD9PZGjz4/DnHBwP8VJkhRVDjr+fWhuSd6+G/mqbdCQnoRTj+uZWt9kDiN1h2kkFHdjN/ZTj0jWrX9d6NofANSRBbAhGfrchRlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oleqo3rd; arc=none smtp.client-ip=91.218.175.128 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oleqo3rd" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=BDabPLEAy+F0bC1m2aFAySlST0o2PCUlunhb/0Rg9F0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789636716; v=1; x=1790241516; b=oleqo3rdDIL06DQxUICjC1cc39hspR0N98Kge6Qy1idNp8VNeZRcqy2S/W98xWSl1v5Y1G1x aoDjevkaKfBfQLV2utglGKxxD33wEnJiN/sbUgWLik7iG7o7AIm5S9FTdMjm/gED1McMZi531gy Lmpa0C8WhBbG2dQHb16oohb8= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 6582ff640713eed0; Thu, 17 Sep 2026 09:18:36 +0000 X-Mizu-Trace-ID: 6582ff640713eed0 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: maz@kernel.org, oupton@kernel.org Cc: joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, qperret@google.com, vdonnefort@google.com, martijnbogaard@google.com, seiden@linux.ibm.com, tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/4] KVM: arm64: Move the IPA limit rule into kvm_get_ipa_max() Date: Thu, 17 Sep 2026 10:18:23 +0100 Message-Id: <20260917091826.2639205-2-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260917091826.2639205-1-fuad.tabba@linux.dev> References: <20260917091826.2639205-1-fuad.tabba@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the rule kvm_set_ipa_limit() applies to PARange into a helper beside kvm_get_parange(), which bounds the same field by a different rule, so the hypervisor can size a guest's IPA space by it. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_pgtable.h | 15 +++++++++++++++ arch/arm64/kvm/reset.c | 12 +----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/= kvm_pgtable.h index 41a8687938eb6..8096b0bf381c2 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -48,6 +48,21 @@ static inline u64 kvm_get_parange(u64 mmfr0) return parange; } =20 +/* + * The largest IPA size a VM can be given. Unlike VTCR_EL2.PS + * (kvm_get_parange()), it isn't clamped to the kernel's PA configuration. + */ +static inline u32 kvm_get_ipa_max(u64 mmfr0) +{ + unsigned int parange =3D cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_EL1_PARANGE_SHIFT); + + if (!kvm_lpa2_is_enabled() && PAGE_SIZE !=3D SZ_64K) + parange =3D min(parange, (unsigned int)ID_AA64MMFR0_EL1_PARANGE_48); + + return id_aa64mmfr0_parange_to_phys_shift(parange); +} + typedef u64 kvm_pte_t; =20 #define KVM_PTE_VALID BIT(0) diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index 10eb7249aa9e8..757adbce2faac 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -231,19 +231,9 @@ u32 get_kvm_ipa_limit(void) =20 int __init kvm_set_ipa_limit(void) { - unsigned int parange; u64 mmfr0; =20 mmfr0 =3D read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); - parange =3D cpuid_feature_extract_unsigned_field(mmfr0, - ID_AA64MMFR0_EL1_PARANGE_SHIFT); - /* - * IPA size beyond 48 bits for 4K and 16K page size is only supported - * when LPA2 is available. So if we have LPA2, enable it, else cap to 48 - * bits, in case it's reported as larger on the system. - */ - if (!kvm_lpa2_is_enabled() && PAGE_SIZE !=3D SZ_64K) - parange =3D min(parange, (unsigned int)ID_AA64MMFR0_EL1_PARANGE_48); =20 /* * Check with ARMv8.5-GTG that our PAGE_SIZE is supported at @@ -264,7 +254,7 @@ int __init kvm_set_ipa_limit(void) return -EINVAL; } =20 - kvm_ipa_limit =3D id_aa64mmfr0_parange_to_phys_shift(parange); + kvm_ipa_limit =3D kvm_get_ipa_max(mmfr0); kvm_info("IPA Size Limit: %d bits%s\n", kvm_ipa_limit, ((kvm_ipa_limit < KVM_PHYS_SHIFT) ? " (Reduced IPA size, limited VM/VMM compatibility)" : "")); --=20 2.39.5 From nobody Fri Sep 25 03:16:11 2026 Received: from mta0.migadu.com (out-136.mta0.migadu.com [91.218.175.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 535834AC156 for ; Thu, 17 Sep 2026 09:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.136 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636721; cv=none; b=diXHt0/vn5P1Vn86CPt2KelJpQcgVclX0Vq/AC+oMFklJint1pUorOx6LQKXCXhYGUfW9TSFfhMCCBfNjYuMEFxgN5lScGmy2UpKadYuE4g6knnMNz8emTWQ36JFDK6JXPWPz0mCkc0UAalA0f/nL1mQp81Z6dozQt0FUYVcB8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636721; c=relaxed/simple; bh=qWxN+EE1n/NUST3E3o6AfroyhPJ5HLiC0YPhK6f/EL4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DiDjf0fNjzsS1xgX3RzMcEQ3nWaIRylRvRJZX8svCHUdOZD5LaPL9JJTQSeZ1bVxH7s2m6w+PnG+reYDKpy4qHL/vkC0oMKohsUIfl1/r5p7Bp8yFS28YOHgTi6ttxaK7JRwL13sna8uj/xg1xpiEmAiPyVrBM65brVuyRMy66k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lryTLbVG; arc=none smtp.client-ip=91.218.175.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lryTLbVG" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=qWxN+EE1n/NUST3E3o6AfroyhPJ5HLiC0YPhK6f/EL4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789636717; v=1; x=1790241517; b=lryTLbVG0IdxUM+FXjxuRvrAM6K+TupsS9K+15+MMaDRrKvxpUze5nEWAd9nQn7R2WfgbMP2 Juz23r1veoh4d5i0YPE3/YilRQDReNHe8K4QPweN0Zo7gD4R6UFcrXYLEnKBZUok8oTtZ45YVS+ Sv4wIcLIkmf72azCG/H9z2j4= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 2a294692267e0b73; Thu, 17 Sep 2026 09:18:37 +0000 X-Mizu-Trace-ID: 2a294692267e0b73 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: maz@kernel.org, oupton@kernel.org Cc: joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, qperret@google.com, vdonnefort@google.com, martijnbogaard@google.com, seiden@linux.ibm.com, tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/4] KVM: arm64: Check PGD alignment when creating a pVM Date: Thu, 17 Sep 2026 10:18:24 +0100 Message-Id: <20260917091826.2639205-3-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260917091826.2639205-1-fuad.tabba@linux.dev> References: <20260917091826.2639205-1-fuad.tabba@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Quentin Perret Martijn reported a hypervisor crash when providing pKVM with an undersized PGD allocation. Indeed, although the size of the PGD allocation at EL2 is not under host control, a smaller host-side allocation can lead to providing pKVM with a misaligned PGD, which will cause the guest stage-2 init to fail in a bad way. Specifically, guest_s2_zalloc_pages_exact() expects a successful allocation from hyp_alloc_pages(), which can only happen if the pool has been pre-filled with a physically aligned high-order page. In order to guarantee allocation success in this path, check the host-provided PGD alignment early on. Fixes: a1ec5c70d3f6 ("KVM: arm64: Add infrastructure to create and track pK= VM instances at EL2") Reported-by: Martijn Bogaard Signed-off-by: Quentin Perret [Fuad: rejected with -EINVAL before any donation is mapped, as the other input checks in __pkvm_init_vm() do] Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvh= e/mem_protect.c index 39aa8911f62c1..805dade1d4510 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -186,7 +186,7 @@ static void *guest_s2_zalloc_pages_exact(size_t size) { void *addr =3D hyp_alloc_pages(¤t_vm->pool, get_order(size)); =20 - WARN_ON(size !=3D (PAGE_SIZE << get_order(size))); + WARN_ON(!addr || size !=3D (PAGE_SIZE << get_order(size))); hyp_split_page(hyp_virt_to_page(addr)); =20 return addr; diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 459bd9eb7e4bc..3770315b50361 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -846,6 +846,10 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long= vm_hva, =20 vm_size =3D pkvm_get_hyp_vm_size(nr_vcpus); pgd_size =3D kvm_pgtable_stage2_pgd_size(host_mmu.arch.mmu.vtcr); + if (!IS_ALIGNED(pgd_hva, pgd_size)) { + ret =3D -EINVAL; + goto err_unpin_kvm; + } =20 ret =3D -ENOMEM; =20 --=20 2.39.5 From nobody Fri Sep 25 03:16:11 2026 Received: from mta0.migadu.com (out-145.mta0.migadu.com [91.218.175.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA3F4AE128 for ; Thu, 17 Sep 2026 09:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636722; cv=none; b=NK2bJadzrjmcwXvjPnQZ9NoNJEwep+rWtyIFJqiSgNxh24xpI7KdNoqJGyRbCnHXjwoj3+GPb4Ld25vr6JYpHqM03VhLX5WI0iS3XVUFX1anJFZ4TBThw3Tx3tjizjj46DySEsgoGheJRlolD7bqTpE2qrdpfHbETDabI6pd/+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636722; c=relaxed/simple; bh=9pjYOIEzdyKNdQkNYW5OL/VC49oIe6n7Ll8yQAOYXfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=df6f/NBBPey1JimGvYybmskXBzCf1AOCxL3phCZi90HVsvOzW1UD0FB7ODZxOyKzx4GHAhQKYkkDOXIqOIEHJkw9939GmteYBmSzHEssQ/+trGjGTYJX1FFQNuEs+UiDJm1ZbVhfVoK8NVj0NN4DtDCOEK77eDPYz1OKhH+NFhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fGAgII4S; arc=none smtp.client-ip=91.218.175.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fGAgII4S" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=9pjYOIEzdyKNdQkNYW5OL/VC49oIe6n7Ll8yQAOYXfg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789636718; v=1; x=1790241518; b=fGAgII4SOg0hosuZF62MUB97l48QjCncM+VdydLjbNWkq/qCiFowC4O8bNupmEwuuVIbwVdq kIh/pb5a78w2kWRfJSF7bzP4Y4pWcT2hZQvAW7WNLfUzuGOsKerbozzr37ZqjzwrhrS7hsaa5x0 eKQfOO7e3NQ3MdUvmXSZ3baQ= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 669cc4c428177e18; Thu, 17 Sep 2026 09:18:38 +0000 X-Mizu-Trace-ID: 669cc4c428177e18 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: maz@kernel.org, oupton@kernel.org Cc: joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, qperret@google.com, vdonnefort@google.com, martijnbogaard@google.com, seiden@linux.ibm.com, tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/4] KVM: arm64: Honour the requested IPA size under pKVM Date: Thu, 17 Sep 2026 10:18:25 +0100 Message-Id: <20260917091826.2639205-4-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260917091826.2639205-1-fuad.tabba@linux.dev> References: <20260917091826.2639205-1-fuad.tabba@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pKVM gives every VM the host's IPA limit, whatever KVM_VM_TYPE_ARM_IPA_SIZE requested, so vgic_init fails on any pKVM host whose limit exceeds 40 bits: the addresses it expects a 40-bit VM to reject are in range. EL2 also sizes the guest's stage 2 from the host stage 2's VTCR, which on a 64K kernel built for 48-bit PAs on a 52-bit part is 48 bits where the limit is 52: a memslot above 2^48 the host accepts returns -ERANGE on the guest's first access. Have EL2 take the IPA size from the VTCR the host sized the VM and the donated pgd with, bounded by kvm_get_ipa_max(), and drop the host-side override, so the request is checked and honoured as on any other host. Fixes: 60dfe093ec13 ("KVM: arm64: Instantiate guest stage-2 page-tables at = EL2") Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 20 ++++++++++++++++---- arch/arm64/kvm/mmu.c | 4 +--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 3770315b50361..85fc14b7a5bc3 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -423,7 +423,8 @@ static void unpin_host_vcpus(struct pkvm_hyp_vcpu *hyp_= vcpus[], } =20 static void init_pkvm_hyp_vm(struct kvm *host_kvm, struct pkvm_hyp_vm *hyp= _vm, - unsigned int nr_vcpus, pkvm_handle_t handle) + unsigned int nr_vcpus, pkvm_handle_t handle, + u64 vtcr) { struct kvm_s2_mmu *mmu =3D &hyp_vm->kvm.arch.mmu; int idx =3D vm_handle_to_idx(handle); @@ -439,7 +440,7 @@ static void init_pkvm_hyp_vm(struct kvm *host_kvm, stru= ct pkvm_hyp_vm *hyp_vm, /* VMID 0 is reserved for the host */ atomic64_set(&mmu->vmid.id, idx + 1); =20 - mmu->vtcr =3D host_mmu.arch.mmu.vtcr; + mmu->vtcr =3D vtcr; mmu->arch =3D &hyp_vm->kvm.arch; mmu->pgt =3D &hyp_vm->pgt; } @@ -826,6 +827,8 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long = vm_hva, unsigned int nr_vcpus; pkvm_handle_t handle; void *pgd =3D NULL; + u32 phys_shift; + u64 vtcr; int ret; =20 ret =3D hyp_pin_shared_mem(host_kvm, host_kvm + 1); @@ -844,8 +847,17 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long= vm_hva, goto err_unpin_kvm; } =20 + phys_shift =3D VTCR_EL2_IPA(READ_ONCE(host_kvm->arch.mmu.vtcr)); + if (phys_shift < ARM64_MIN_PARANGE_BITS || + phys_shift > kvm_get_ipa_max(id_aa64mmfr0_el1_sys_val)) { + ret =3D -EINVAL; + goto err_unpin_kvm; + } + vtcr =3D kvm_get_vtcr(id_aa64mmfr0_el1_sys_val, id_aa64mmfr1_el1_sys_val, + phys_shift); + vm_size =3D pkvm_get_hyp_vm_size(nr_vcpus); - pgd_size =3D kvm_pgtable_stage2_pgd_size(host_mmu.arch.mmu.vtcr); + pgd_size =3D kvm_pgtable_stage2_pgd_size(vtcr); if (!IS_ALIGNED(pgd_hva, pgd_size)) { ret =3D -EINVAL; goto err_unpin_kvm; @@ -861,7 +873,7 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long = vm_hva, if (!pgd) goto err_remove_mappings; =20 - init_pkvm_hyp_vm(host_kvm, hyp_vm, nr_vcpus, handle); + init_pkvm_hyp_vm(host_kvm, hyp_vm, nr_vcpus, handle, vtcr); =20 ret =3D kvm_guest_prepare_stage2(hyp_vm, pgd); if (ret) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 9ba86450fe4af..5a3a4863f3d13 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -909,9 +909,7 @@ static int kvm_init_ipa_range(struct kvm_s2_mmu *mmu, u= nsigned long type) u32 phys_shift; =20 phys_shift =3D KVM_VM_TYPE_ARM_IPA_SIZE(type); - if (is_protected_kvm_enabled()) { - phys_shift =3D kvm_ipa_limit; - } else if (phys_shift) { + if (phys_shift) { if (phys_shift > kvm_ipa_limit || phys_shift < ARM64_MIN_PARANGE_BITS) return -EINVAL; --=20 2.39.5 From nobody Fri Sep 25 03:16:11 2026 Received: from mta0.migadu.com (out-153.mta0.migadu.com [91.218.175.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF8264B0E24 for ; Thu, 17 Sep 2026 09:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636728; cv=none; b=mKhvRXKjM8xi4iWPS3z6NIKmv5rMBNaZyrdZQJaYKGmSkiSRipb7GzbXxr2amroAeQ5H3BDoKvjSJdgeOy+lBUuDWand9ZVxAhfNmWpLASl1RgXbuknjBXKZ+AOn7GhEFEWQ36m8xO0fKBrYLO+KJnt1Zaonl6ICeext75lhYPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789636728; c=relaxed/simple; bh=uv/QqzkCASpL/8RQbBzCZik975p5clqE6ezIH1NXyV0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=otQX82qGL7mCOgzY0hre/KTnTkEDe+kUgIRMhIYtL4SDROCiUYWaXG/NIGxFmOSibMVGk2CVL3piBvT4mxXVozUcacvSAJSKksx6T3UVJWEeCiMU41e6QH1HfOebDSq2AVuCvpVqJyQz790Fm2OqR2rTfGc68DpnfADvoF6XaCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=c5nNcqoP; arc=none smtp.client-ip=91.218.175.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="c5nNcqoP" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=uv/QqzkCASpL/8RQbBzCZik975p5clqE6ezIH1NXyV0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789636723; v=1; x=1790241523; b=c5nNcqoP5YWAKr+ihICugNGB3xouSZ4XFkDHJKmSX0/Rw5Y9yel3x9pufcYL/PsN/XWtYJwk iO5W6+iKPH6x3THUJNfQSSwixhYq3nJOwHun7Uu2P6iYzu2zmp94zkoRBXP5fC8gdnCyWLTIOQP 15T45bJ5/6iRrzazSaZyAYcw= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id c94fbe1e4d9196cd; Thu, 17 Sep 2026 09:18:43 +0000 X-Mizu-Trace-ID: c94fbe1e4d9196cd X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: maz@kernel.org, oupton@kernel.org Cc: joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, qperret@google.com, vdonnefort@google.com, martijnbogaard@google.com, seiden@linux.ibm.com, tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/4] KVM: arm64: selftests: Free the VM when the GIC device probe fails Date: Thu, 17 Sep 2026 10:18:26 +0100 Message-Id: <20260917091826.2639205-5-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260917091826.2639205-1-fuad.tabba@linux.dev> References: <20260917091826.2639205-1-fuad.tabba@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" test_kvm_device() creates a VM to probe the GIC version under test and returns without freeing it when the probe fails, in vgic_init and in its vgic_v5 copy. Free it on that path. Signed-off-by: Fuad Tabba --- tools/testing/selftests/kvm/arm64/vgic_init.c | 4 +++- tools/testing/selftests/kvm/arm64/vgic_v5.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/arm64/vgic_init.c b/tools/testing/= selftests/kvm/arm64/vgic_init.c index 47e34b43afb29..53894d32b0fc8 100644 --- a/tools/testing/selftests/kvm/arm64/vgic_init.c +++ b/tools/testing/selftests/kvm/arm64/vgic_init.c @@ -732,8 +732,10 @@ int test_kvm_device(u32 gic_dev_type) =20 /* trial mode */ ret =3D __kvm_test_create_device(v.vm, gic_dev_type); - if (ret) + if (ret) { + kvm_vm_free(v.vm); return ret; + } v.gic_fd =3D kvm_create_device(v.vm, gic_dev_type); =20 ret =3D __kvm_create_device(v.vm, gic_dev_type); diff --git a/tools/testing/selftests/kvm/arm64/vgic_v5.c b/tools/testing/se= lftests/kvm/arm64/vgic_v5.c index 96cfd6bb32f6f..10fdfe362428b 100644 --- a/tools/testing/selftests/kvm/arm64/vgic_v5.c +++ b/tools/testing/selftests/kvm/arm64/vgic_v5.c @@ -187,8 +187,10 @@ int test_kvm_device(u32 gic_dev_type) =20 /* trial mode */ ret =3D __kvm_test_create_device(v.vm, gic_dev_type); - if (ret) + if (ret) { + kvm_vm_free(v.vm); return ret; + } v.gic_fd =3D kvm_create_device(v.vm, gic_dev_type); =20 ret =3D __kvm_create_device(v.vm, gic_dev_type); --=20 2.39.5