From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796320168; b=Bm+NN770GE5xE4e/u//MoRnYVT4+Qx0OWhrryTvbFnCfdIOWr2OPycOlxNZcCGkelxZp ULmb6W4IVS9E86e5LYZ3NI9ZdHccNammo+xLXtD8oafoGrhHnOQ8WKjxXWbAp1K4ygpXM Ed7Hwi/XOsh60HfZHEkfcrNHhpA23NIBoDbDw8AmMfYIt879JvArGYO+V1yxP4zcLUKJi CRktVRrikMffJan4xGJlxWNlqTmQJP+IUKgJX1g7g9FmsxC6abqqwrbUkApngyPxJkKrx apN2ymI5L65kNNJjOFR1pQl6+dmHyUeshZrAbJp/eMyvLY1fp0Uts5yWScq7mtjhIZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796320168; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=AxxZ9npPE63M54Jdm+pmkrBQSZuwSnr8OqqAA0KQI9o=; b=DlQLK9lmetQ57FLKvshj5pn72ezuf4DDVLtP/KSe3Qkqj5Rkrk6D0qISwYd/erY8svEp 7b6mwsBHc0KGG9vTaoF3xw/TW+dLGwofurnj/xDHYvK8g8upjUZZ6fF/9tssILAbDB9Ns 0y8gNyZG//lJIKzYVbbmk2EJWjbvwC+KD8caxj7u7T4eB4Y7rXlmk6BKOy5Xb0D0EEhYN I1/wD7cevZ8/XS4gaEWBb6hvVa430gcAkYtlBVUtEPYsfQGF9ZKkFFDafqxMmVmP1DO9J p9FsV1jsG8hcwmVH6aU2EIf1N7tptmBBTpfZK9HBjZdO869CHICaIFUGWp/lO8aA9Zw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TRRuLuEy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C731D606A683 for ; Thu, 3 Dec 2026 17:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TRRuLuEy Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFF171F000C1; Thu, 3 Dec 2026 17:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796320168; bh=AxxZ9npPE63M54Jdm+pmkrBQSZuwSnr8OqqAA0KQI9o=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=TRRuLuEyBXtRw+x/mNrkqbrf7737gh0JnAa8TgqsmAkp+yCrW9uo+av+I70nmaHB1 4Zg5CV4hRlU7SZtKYGGqCFqUx7umoZ2/wfcVCpEQjX2UlVKuYiUKXD8kUzV93twrOm 1dMJ/r1OF0XHXlitGF4ocfaUvgUHhMWOmK0fnzFFDyJAo0AaXWYqe3ro7LKX1HW+el bZu+m21kGi1E2yH7t3zh+Tn6wDvQY9K2val+H5LLrNVSsKX5XwT5GM67LyfBsVEq8n kNZcdHE7hBdLOze9vxIpfVmMTkaPC0zDYx+9crmXFU77mbEV6leYzGc8E7HzaFhLHj M8PhSuDFOyytQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 20/24] KVM: arm64: Add __pkvm_host_split_guest HVC Reply-To: sashiko-reviews@lists.linux.dev To: "Vincent Donnefort" , kvmarm@lists.linux.dev Cc: "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261203115209.1690207-21-vdonnefort@google.com> References: <20261203115209.1690207-1-vdonnefort@google.com> <20261203115209.1690207-21-vdonnefort@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 17:49:27 +0000 X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Low] KVM: arm64: __pkvm_host_split_guest() skips guest page state check - [Low] KVM: arm64: left-shift overflow on inputs in __pkvm_host_split_guest() - [Low] KVM: arm64: premature mc->nr_pages check in __pkvm_host_split_guest() -- commit c0a936c062694cf8e366e1ea2cfe5c0af145f622 Author: Vincent Donnefort KVM: arm64: Add __pkvm_host_split_guest HVC This commit adds the __pkvm_host_split_guest host hypercall and its EL2 implementation to split a PMD block mapping in a protected VM's stage-2 page table along with the corresponding host stage-2 GFN metadata. > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/n= vhe/mem_protect.c > index d94e1d94d9953..118f92472299d 100644 > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c [ ... ] > @@ -1783,6 +1831,55 @@ int __pkvm_host_mkyoung_guest(u64 gfn, struct pkvm= _hyp_vcpu *vcpu) > return 0; > } > =20 > +int __pkvm_host_split_guest(u64 gfn, u64 nr_pages, struct pkvm_hyp_vcpu = *vcpu) > +{ > + struct kvm_hyp_memcache *mc =3D &vcpu->vcpu.arch.stage2_mc; > + struct pkvm_hyp_vm *vm =3D pkvm_hyp_vcpu_to_hyp_vm(vcpu); > + u64 size =3D nr_pages << PAGE_SHIFT; > + u64 ipa =3D hyp_pfn_to_phys(gfn); > + kvm_pte_t pte, *table; > + phys_addr_t phys; > + s8 level; > + int ret; > + > + if (!mc->nr_pages) > + return -ENOMEM; [Severity: Low] Is this upfront mc->nr_pages check needed here? Checking it before validating the arguments and guest PTE returns -ENOMEM instead of -EINVAL, -ENOENT, or -E2BIG when stage2_mc is empty, and also rejects the split even when vm->pool already has free pages. Since kvm_pgtable_stage2_create_unlinked() allocates before either page table is modified, and guest_s2_zalloc_page() tries vm->pool before falling back to stage2_mc, dropping this check would preserve error precedence and allow reusing pooled pages. > + > + if (size !=3D PMD_SIZE || !IS_ALIGNED(ipa, PMD_SIZE)) > + return -EINVAL; [Severity: Low] Can the left shifts on nr_pages and gfn silently truncate out-of-range host HVC inputs? Non-zero bits in the upper PAGE_SHIFT bits wrap modulo 2^64, allowing invalid arguments to pass these checks and split an aliased PMD block instead of returning -EINVAL. Comparing nr_pages directly against PMD_SIZE >> PAGE_SHIFT (as in __guest_check_transition_size()) and checking hyp_phys_to_pfn(ipa) =3D=3D g= fn would avoid the truncation. > + > + level =3D KVM_PGTABLE_LAST_LEVEL - 1; > + > + host_lock_component(); > + guest_lock_component(vm); > + > + ret =3D get_valid_guest_pte(vm, ipa, size, &pte, &phys); > + if (ret) > + goto unlock; > + > + table =3D kvm_pgtable_stage2_create_unlinked(&vm->pgt, kvm_pte_to_phys(= pte), level, > + kvm_pgtable_stage2_pte_prot(pte), > + mc, true); > + if (IS_ERR(table)) { > + ret =3D PTR_ERR(table); > + goto unlock; > + } > + > + ret =3D host_stage2_try(host_stage2_split_gfn_meta, phys, ipa, size, vm= ); [Severity: Low] Should __pkvm_host_split_guest() verify that guest_get_page_state(pte, ipa) is PKVM_PAGE_OWNED before allocating the unlinked table and calling host_stage2_split_gfn_meta()? For a PMD block in PKVM_PAGE_SHARED_OWNED state, __pkvm_guest_share_host() leaves a valid PMD in both vm->pgt and host_mmu.pgt. Passing that valid host PTE from host_stage2_split_gfn_meta() to host_stage2_decode_gfn_meta() hits WARN_ON(kvm_pte_valid(pte)) and panics EL2. Today only __pkvm_ownership_selftest() shares a PMD_SIZE block from a protected VM, so this is host-kernel-only for now, but checking the guest page state first avoids the EL2 panic and prevents it from becoming guest-triggerable once huge-page guest memshare is enabled. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203115209.1690= 207-1-vdonnefort@google.com?part=3D20