Re: [PATCH] drivers/virt: pkvm: Zero and clean memory before sharing it with the host
From: Vincent Donnefort
Date: Mon Nov 16 2026 - 09:04:51 EST
On Mon, Nov 16, 2026 at 12:25:43PM +0000, Fuad Tabba wrote:
> Hi Vincent,
>
> On Mon, 16 Nov 2026 at 11:28, Vincent Donnefort <vdonnefort@xxxxxxxxxx> wrote:
> [...]
> > > + /*
> > > + * The host can read the pages as soon as they are shared, possibly
> > > + * through a Non-cacheable mapping. No caller relies on their contents.
> > > + */
> > > + memset((void *)addr, 0, size);
> >
> > Are we sure we want that? The guest may want to setup memory and then share it.
> > I am not sure about modifying this API.
>
> Right! I wanted to fix the bug for the ITS property table, which is
> shared before it's initialized, and totally forgot that this is the
> path all sharing goes through... I'll drop this, and put that fix back
> in the ITS series.
>
> > > + dcache_clean_poc(addr, addr + size);
> >
> > I believe the hypervisor is already doing the cache maintainance when the page
> > is mapped back into the host. (see stage2_map_walker_try_leaf())
>
> I don't think it does on this path. host_mmu.mm_ops doesn't have a
> dcache_clean_inval_poc() callback, so stage2_map_walker_try_leaf()
> doesn't do the CMO for a host mapping. On the guest's side,
> __pkvm_guest_share_host() only changes the software bits of the
> existing mapping, and the walker returns before the CMO in that case.
>
> Cheers,
> /fuad
Ha yes of course, that's the host s2 we are mapping into. And on the guest side,
we are only changing the software bits, so no CMO. Actually I should have read
the comment in stage2_map_walker_try_leaf() more carefully.
That said, I wonder if that shouldn't be handled by the hypervisor, just like
hyp_poison_page() do the cache clean.
That would be slightly slower than letting the guest (who has a mapping already)
do it, but pKVM is enforcing isolation between host and guest, and it feels like
it should do it by default no matter the memory transition.
--
Vincent