[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aCd7l455qd4NmOeb@google.com>
Date: Fri, 16 May 2025 18:53:27 +0100
From: Vincent Donnefort <vdonnefort@...gle.com>
To: Marc Zyngier <maz@...nel.org>
Cc: oliver.upton@...ux.dev, joey.gouly@....com, suzuki.poulose@....com,
yuzenghui@...wei.com, catalin.marinas@....com, will@...nel.org,
qperret@...gle.com, linux-arm-kernel@...ts.infradead.org,
kvmarm@...ts.linux.dev, linux-kernel@...r.kernel.org,
kernel-team@...roid.com
Subject: Re: [PATCH v4 01/10] KVM: arm64: Handle huge mappings for np-guest
CMOs
Hi,
Thanks for having a look at the series.
On Fri, May 16, 2025 at 01:15:00PM +0100, Marc Zyngier wrote:
> On Fri, 09 May 2025 14:16:57 +0100,
> Vincent Donnefort <vdonnefort@...gle.com> wrote:
> >
> > clean_dcache_guest_page() and invalidate_icache_guest_page() accept a
> > size as an argument. But they also rely on fixmap, which can only map a
> > single PAGE_SIZE page.
> >
> > With the upcoming stage-2 huge mappings for pKVM np-guests, those
> > callbacks will get size > PAGE_SIZE. Loop the CMOs on a PAGE_SIZE basis
> > until the whole range is done.
> >
> > Signed-off-by: Vincent Donnefort <vdonnefort@...gle.com>
> >
> > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> > index 31173c694695..23544928a637 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> > @@ -219,14 +219,28 @@ static void guest_s2_put_page(void *addr)
> >
> > static void clean_dcache_guest_page(void *va, size_t size)
> > {
> > - __clean_dcache_guest_page(hyp_fixmap_map(__hyp_pa(va)), size);
> > - hyp_fixmap_unmap();
> > + WARN_ON(!PAGE_ALIGNED(size));
>
> What if "va" isn't aligned?
So the only callers are either for PAGE_SIZE or PMD_SIZE with the right
alignment addr alignment.
But happy to make this more future-proof, after all an ALIGN() is quite cheap.
>
> > +
> > + while (size) {
> > + __clean_dcache_guest_page(hyp_fixmap_map(__hyp_pa(va)),
> > + PAGE_SIZE);
> > + hyp_fixmap_unmap();
> > + va += PAGE_SIZE;
> > + size -= PAGE_SIZE;
> > + }
>
> I know pKVM dies on WARN, but this code "looks" unsafe. Can you align
> va and size to be on page boundaries, so that we are 100% sure the
> loop terminates?
>
> > }
> >
> > static void invalidate_icache_guest_page(void *va, size_t size)
> > {
> > - __invalidate_icache_guest_page(hyp_fixmap_map(__hyp_pa(va)), size);
> > - hyp_fixmap_unmap();
> > + WARN_ON(!PAGE_ALIGNED(size));
> > +
> > + while (size) {
> > + __invalidate_icache_guest_page(hyp_fixmap_map(__hyp_pa(va)),
> > + PAGE_SIZE);
> > + hyp_fixmap_unmap();
> > + va += PAGE_SIZE;
> > + size -= PAGE_SIZE;
> > + }
>
> Same here.
>
> Thanks,
>
> M.
>
> --
> Without deviation from the norm, progress is not possible.
Powered by blists - more mailing lists