Re: [PATCH v2 2/3] KVM: x86: Handle the case of 5-level shadow page table

Sean Christopherson
2021-08-09T15:17:41Z

On Sun, Aug 08, 2021, Wei Huang wrote:
> @@ -3457,10 +3457,19 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
> mmu->pae_root[i] = root | pm_mask;
> }
>
> - if (mmu->shadow_root_level == PT64_ROOT_4LEVEL)
> + /*
> + * Depending on the shadow_root_level, build the root_hpa table by
> + * chaining either pml5->pml4->pae or pml4->pae.
> + */
> + mmu->root_hpa = __pa(mmu->pae_root);
> + if (mmu->shadow_root_level >= PT64_ROOT_4LEVEL) {
> + mmu->pml4_root[0] = mmu->root_hpa | pm_mask;
> mmu->root_hpa = __pa(mmu->pml4_root);
> - else
> - mmu->root_hpa = __pa(mmu->pae_root);
> + }
> + if (mmu->shadow_root_level == PT64_ROOT_5LEVEL) {
> + mmu->pml5_root[0] = mmu->root_hpa | pm_mask;
> + mmu->root_hpa = __pa(mmu->pml5_root);
> + }

I still really dislike this approach, it requires visually connecting multiple
statements to understand the chain. I don't see any advantage (the 6-level paging
comment was 99.9% a joke) of rewriting root_hpa other than that's how it's done today.

In the future, please give reviewers ample opportunity to respond before sending
a new version if there's disagreement, otherwise the conversation gets carried
over into a different thread and loses the original context.

>
> set_root_pgd:
> mmu->root_pgd = root_pgd;