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=1796056741; b=y9un1SB/E2xcXN9ydUyCwKAJUI4IQ583pviYelYy3t3uBZW14MNs5k0mm1yW0nPyeDRp VHzh73FIfGA1ptQ78DjBGba4NDSuGVt+z9IamFWYyQqVf9IRuzPt4vWmPBX2MkGS9Y4Uj jLIzHSQjnROTf2JNuFuo7n35iGqtTpAfcOcg0vo//5PGA6v9Q5UAJvNWgVGRkRsTJxeJa mN6svRgztGRThTebk2eJ4CW5cm1as0yFlx6jxxpISX8j+yTaDUsUjL1/tt1YyTV8FWoYh nO0cOnbORGoDtOd0OlaY6IFvXv5LfxaF/Tm3FrysTk4RQHy6J1U1zkoi/36xnHPxQjg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056741; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fi5JotIuASjwu+N4LdBCYIsqxwl9M7Zexk2W+lu1UpE=; b=3PqWH0NEknmp/XevRUmy4wGEfKdo7trQ3JDTb+57Xv+xIsdQ92SDUoJo41fXJVr1Qhwb CD7R0fgHzii6psfJPN4yfXYQTtWXHZuF9+3MODWTzzkLu3pzxEUDgHrUR+jP9t0IeMoc7 bLuLPArKKLnL3XTx3rms2FYo5iaatwrh2zFHKZg6GQ3fMuya03MpJfuc+PgA/bBG83bZA RiHyYiGsF+6CvV7Eh7eQRbQnZHClmINLj5iP4GV60EowcfjnAR8NOjEhN+7zjJBRLTYza 5hYqi3dXJSMUOoezEoTr2ToMWJVvc4g4qJ+eEWkJUpjJChKhcdVqNcvCbz9ICiuI8og== 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=B6+WQ35t; 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 5296E606A32D for ; Mon, 30 Nov 2026 16:39:01 +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=B6+WQ35t Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C6D51F0089C; Mon, 30 Nov 2026 16:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796056740; bh=fi5JotIuASjwu+N4LdBCYIsqxwl9M7Zexk2W+lu1UpE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=B6+WQ35tUz+HGbk3/znlv8EWG7+VdyTjfn4rnn3DVImK/svC5ASQbO5hcxF3Jrj/7 5UYtkWz2dpX21hd/hLGMs+B8nJ+EIC/Z/pcVzptUro2VZNZivYB4ZqxN6EcNjvKuxN OTeYI2TcQndQMmaqOxhP5jHV/7ErgH9YIzSdCiMaJ/R1oH8sHPo1nIe+bWPQ+9ZxrS aLnJJSRs4i0Ph2AZeLNGB9KrVyyHPI6tMeziWGO8M86Hs2sYd0vUNedWXfjupW1EJe oQjxpXMk7dmsQdrKoQiHKIalA8iNcT5YWix2E0sLfUKuSP5v8+LOZ6Qq91oDGGl+yv 5pQhluOnnwyrw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 25/25] KVM: arm64: Stage-2 huge mappings for protected VMs Reply-To: sashiko-reviews@lists.linux.dev To: "Vincent Donnefort" , kvmarm@lists.linux.dev Cc: "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261130155710.2371874-26-vdonnefort@google.com> References: <20261130155710.2371874-1-vdonnefort@google.com> <20261130155710.2371874-26-vdonnefort@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 16:38:59 +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 1 potential issue to consider: - [Medium] KVM: arm64: repeated PMD locked_vm over-charge in protected_pkvm_mem_abort() -- commit 941a975a4322f6921d62e29967a4f68fd50e4378 Author: Vincent Donnefort KVM: arm64: Stage-2 huge mappings for protected VMs This commit enables PMD-sized stage-2 block mappings for protected VMs when the backing host stage-1 mapping is a THP, falling back to a PAGE_SIZE donation if the PMD range overlaps an existing smaller mapping. > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 1db10d8d6db73..df8ec7c798ddc 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c [ ... ] > @@ -1893,26 +1872,83 @@ static int protected_pkvm_mem_abort(const struct = kvm_s2_fault_desc *s2fd) [ ... ] > +static int protected_pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd) > +{ > + struct kvm_s2_fault_vma_info s2vi =3D {}; > + struct kvm_vcpu *vcpu =3D s2fd->vcpu; > + struct kvm_pgtable *pgt =3D s2fd->mmu->pgt; > + struct mm_struct *mm =3D current->mm; > + struct kvm *kvm =3D vcpu->kvm; > + unsigned long unaccount; > + void *hyp_memcache; > + u64 size; > + int ret; > + > + hyp_memcache =3D get_mmu_memcache(vcpu); > + ret =3D topup_mmu_memcache(s2fd->mmu, hyp_memcache); > + if (ret) > + return -ENOMEM; > + > + ret =3D pkvm_pin_user_pages(s2fd, &s2vi); > + if (ret =3D=3D -EHWPOISON || ret =3D=3D -EAGAIN) > + return 0; > + else if (ret) > + return ret; > + > + size =3D s2vi.vma_pagesize; > + > + ret =3D account_locked_vm(mm, size / PAGE_SIZE, true); > + if (ret) > goto unpin; > + > + kvm_fault_lock(kvm); > + if (mmu_invalidate_retry(kvm, s2vi.mmu_seq)) { > + ret =3D -EAGAIN; > + } else { > + ret =3D pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(s2vi.gfn), size, > + __pfn_to_phys(s2vi.pfn), KVM_PGTABLE_PROT_RWX, > + hyp_memcache, 0); > + > + /* undo transparent_hugepage_adjust() and try again */ > + if (ret =3D=3D -E2BIG) { > + u64 ipa =3D ALIGN_DOWN(s2fd->fault_ipa, PAGE_SIZE); > + > + size =3D PAGE_SIZE; > + ret =3D pkvm_pgtable_stage2_map(pgt, ipa, size, > + page_to_phys(s2vi.page), > + KVM_PGTABLE_PROT_RWX, > + hyp_memcache, 0); > + } > } > + kvm_fault_unlock(kvm); > =20 > - write_lock(&kvm->mmu_lock); > - ret =3D pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(s2vi.gfn), PAGE_SIZE, > - page_to_phys(s2vi.page), KVM_PGTABLE_PROT_RWX, > - hyp_memcache, 0); > - write_unlock(&kvm->mmu_lock); > + unaccount =3D (ret ? s2vi.vma_pagesize : s2vi.vma_pagesize - size) / PA= GE_SIZE; > + account_locked_vm(mm, unaccount, false); [Severity: Medium] Does charging s2vi.vma_pagesize before checking for overlapping stage-2 mappings cause repeated PMD over-accounting and double mmap_write_lock(mm) acquisitions across a partially mapped THP range? When a 2MB guest IPA range already has at least one 4KB mapping in pgt->pkvm_mappings while the host stage-1 mapping is a PMD THP, get_user_mapping_size() still returns PMD_SIZE because donating a 4KB page leaves the host stage-1 PMD intact. Each subsequent 4KB fault in that 2MB range charges 512 pages under mmap_write_lock(mm), hits -E2BIG in pkvm_pgtable_stage2_map(), falls back to PAGE_SIZE, and then takes mmap_write_lock(mm) a second time to uncharge 511 pages. Across the remaining faults in that 2MB range, mm->locked_vm is temporarily charged up to 511 + 512 =3D 1023 pages for a 512-page region, which can cause spurious -ENOMEM fault failures when RLIMIT_MEMLOCK is sized to the VM memory. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130155710.2371= 874-1-vdonnefort@google.com?part=3D25