<div dir="ltr">Hi Sean,<br><br>Thanks for the prompt reply. Please see my following reply. Thanks.<br><br>On Tue, Oct 13, 2020 at 12:52 AM Sean Christopherson <<a href="mailto:sean.j.christopherson@intel.com" target="_blank">sean.j.christopherson@intel.com</a>> wrote:<br>><br>> On Tue, Oct 13, 2020 at 12:30:39AM -0400, harry harry wrote:<br>> > Hi Sean,<br>> ><br>> > Thank you very much for your thorough explanations. Please see my<br>> > inline replies as follows. Thanks!<br>> ><br>> > On Mon, Oct 12, 2020 at 12:54 PM Sean Christopherson<br>> > <<a href="mailto:sean.j.christopherson@intel.com" target="_blank">sean.j.christopherson@intel.com</a>> wrote:<br>> > ><br>> > > No, the guest physical address spaces is not intrinsically tied to the host<br>> > > virtual address spaces.  The fact that GPAs and HVAs are related in KVM is a<br>> > > property KVM's architecture.  EPT/NPT has absolutely nothing to do with HVAs.<br>> > ><br>> > > As Maxim pointed out, KVM links a guest's physical address space, i.e. GPAs, to<br>> > > the host's virtual address space, i.e. HVAs, via memslots.  For all intents and<br>> > > purposes, this is an extra layer of address translation that is purely software<br>> > > defined.  The memslots allow KVM to retrieve the HPA for a given GPA when<br>> > > servicing a shadow page fault (a.k.a. EPT violation).<br>> > ><br>> > > When EPT is enabled, a shadow page fault due to an unmapped GPA will look like:<br>> > ><br>> > >  GVA -> [guest page tables] -> GPA -> EPT Violation VM-Exit<br>> > ><br>> > > The above walk of the guest page tables is done in hardware.  KVM then does the<br>> > > following walks in software to retrieve the desired HPA:<br>> > ><br>> > >  GPA -> [memslots] -> HVA -> [host page tables] -> HPA<br>> ><br>> > Do you mean that GPAs are different from their corresponding HVAs when<br>> > KVM does the walks (as you said above) in software?<br>><br>> What do you mean by "different"?  GPAs and HVAs are two completely different<br>> address spaces.<br><br>Let me give you one concrete example as follows to explain the meaning of ``different''.<br><br>Suppose a program is running in a single-vCPU VM. The program allocates and references one page (e.g., array[1024*4]). Assume that allocating and referencing the page in the guest OS triggers a page fault and host OS allocates a machine page to back it.<br><br>Assume that GVA of array[0] is 0x000000000021 and its corresponding GPA is 0x0000000000000081. I think array[0]'s corresponding HVA should also be 0x0000000000000081, which is the same as array[0]'s GPA. If array[0]'s HVA is not 0x0000000000000081, array[0]'s GPA is<b><font color="#ff0000"> different</font></b> from its corresponding HVA.<div><br></div><div>Now, let's assume array[0]'s GPA is different from its corresponding HVA. I think there might be one issue like this: I think MMU's hardware logic to translate ``GPA ->[extended/nested page tables] -> HPA''[1] should be the same as ``VA-> [page tables] -> PA"[2]; if true, how does KVM find the correct HPA with the different HVA (e.g., array[0]'s HVA is not 

0x0000000000000081) when there are EPT violations?<br><br>[1] Please note that this hardware walk is the last step, which only translates the guest physical address to the host physical address through the four-level nested page table.<br>[2] Please note that this hardware walk assumes translating the VA to the PA without virtualization involvement.<br><div><br></div><div>Please note that the above addresses are not real and just use for explanations.</div></div><div><br></div><div>Thanks,</div><div>Harry</div></div>