Re: [RFC PATCH V3 3/4] KVM: X86: Alloc role.pae_root shadow page

From: Sean Christopherson
Date: Thu Apr 14 2022 - 11:45:54 EST


On Thu, Apr 14, 2022, Lai Jiangshan wrote:
> On Wed, Apr 13, 2022 at 5:14 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> >
> > On Wed, Mar 30, 2022, Lai Jiangshan wrote:
> > > From: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx>
> > >
> > > Currently pae_root is special root page, this patch adds facility to
> > > allow using kvm_mmu_get_page() to allocate pae_root shadow page.
> >
> > I don't think this will work for shadow paging. CR3 only has to be 32-byte aligned
> > for PAE paging. Unless I'm missing something subtle in the code, KVM will incorrectly
> > reuse a pae_root if the guest puts multiple PAE CR3s on a single page because KVM's
> > gfn calculation will drop bits 11:5.
>
> I forgot about it.
>
> >
> > Handling this as a one-off is probably easier. For TDP, only 32-bit KVM with NPT
> > benefits from reusing roots, IMO and shaving a few pages in that case is not worth
> > the complexity.
> >
>
> I liked the one-off idea yesterday and started trying it.
>
> But things were not going as smoothly as I thought. There are too
> many corner cases to cover. Maybe I don't get what you envisioned.

Hmm, I believe I was thinking that each vCPU could have a pre-allocated pae_root
shadow page, i.e. keep pae_root, but make it

struct kvm_mmu_page pae_root;

The alloc/free paths would still need special handling, but at least in theory,
all other code that expects root a shadow page will Just Work.