On Sun, May 15, 2022 at 11:55 PM Lai Jiangshan <jiangshanlai@xxxxxxxxx> wrote: > > On Sat, May 14, 2022 at 4:28 AM David Matlack <dmatlack@xxxxxxxxxx> wrote: > > > -static hpa_t mmu_alloc_root(struct kvm_vcpu *vcpu, gfn_t gfn, gva_t gva, > > +static hpa_t mmu_alloc_root(struct kvm_vcpu *vcpu, gfn_t gfn, int quadrant, > > u8 level, bool direct) > > { > > + union kvm_mmu_page_role role; > > struct kvm_mmu_page *sp; > > > > - sp = kvm_mmu_get_page(vcpu, gfn, gva, level, direct, ACC_ALL); > > + role = vcpu->arch.mmu->root_role; > > + role.level = level; > > + role.direct = direct; > > + role.access = ACC_ALL; > > + > > + if (role.has_4_byte_gpte) > > + role.quadrant = quadrant; > > + > > + if (level <= vcpu->arch.mmu->cpu_role.base.level) > > + role.passthrough = 0; > > + > > > > + role.level = level; > + > + if (role.has_4_byte_gpte) > + role.quadrant = quadrant; > > Only these lines are needed because of mmu->pae_root, others are > the same as vcpu->arch.mmu->root_role. > > The argument @direct is vcpu->arch.mmu->root_role.direct. > vcpu->arch.mmu->root_role.access is always set to be ACC_ALL. > > vcpu->arch.mmu->root_role.passthrough is 0 when mmu->pae_root is used. > Or if vcpu->arch.mmu->root_role.passthrough is 1, @level must be 5 > and vcpu->arch.mmu->cpu_role.base.level must be 4, the code here > is useless. Ah, thank you for the tip. That is cleaner.