Re: [PATCH v3 01/17] KVM: arm64: Add pkvm_private_va_range_pa
Vincent Donnefort <[email protected]> Fri, 31 Jul 2026 09:05:16 +0100
| Newsgroups | dev.linux.lists.sashiko-reviews,dev.linux.lists.kvmarm |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Jul 20, 2026 at 05:25:59PM +0000, [email protected] wrote: > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: > - [High] Incorrect physical address calculation for block mappings in pkvm_private_va_range_pa() > -- > > --- Patch [1]: [PATCH v3 01/17] KVM: arm64: Add pkvm_private_va_range_pa --- > commit 81aa726ac7516be8619c0cb2674493e48b6fca16 > Author: Vincent Donnefort <[email protected]> > > KVM: arm64: Add pkvm_private_va_range_pa > > This commit introduces pkvm_private_va_range_pa() to resolve physical > addresses for the pKVM private range by walking the hypervisor page-table. > This prepares for the upcoming pKVM heap allocator. > > > diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c > > --- a/arch/arm64/kvm/hyp/nvhe/mm.c > > +++ b/arch/arm64/kvm/hyp/nvhe/mm.c > [ ... ] > > +phys_addr_t pkvm_private_va_range_pa(void *va) > > +{ > > + kvm_pte_t pte = 0; > > + > > + guard(hyp_spinlock)(&pkvm_pgd_lock); > > + WARN_ON(kvm_pgtable_get_leaf(&pkvm_pgtable, (u64)va, &pte, NULL)); > > + WARN_ON(!kvm_pte_valid(pte)); > > + > > + return kvm_pte_to_phys(pte) + offset_in_page(va); > > [Severity: High] > Does this calculation handle block mappings correctly? There's no risk to step into a block mapping with the users of that function. I could WARN_ON() though... > > If the virtual address is mapped via a block descriptor (such as a 2MB > large page), kvm_pte_to_phys(pte) returns the base physical address of > the block. Adding offset_in_page(va) will only preserve the lowest 12 > bits, discarding the intermediate offset bits between the page size and > the block size. > > Could this cause multiple virtual pages within the block mapping to > incorrectly resolve to the same physical base page plus a small offset? > Perhaps this should retrieve the mapping level from kvm_pgtable_get_leaf() > and mask the virtual address with the corresponding granule size? > > > +} > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 -- -- Vincent