All of lore.kernel.org
 help / color / mirror / Atom feed
From: harry harry <hiharryharryharry@gmail.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: kvm@vger.kernel.org, libvir-list@redhat.com,
	qemu-devel@nongnu.org, Maxim Levitsky <mlevitsk@redhat.com>,
	mathieu.tarral@protonmail.com, stefanha@redhat.com,
	pbonzini@redhat.com
Subject: Re: Why guest physical addresses are not the same as the corresponding host virtual addresses in QEMU/KVM? Thanks!
Date: Tue, 13 Oct 2020 01:33:28 -0400	[thread overview]
Message-ID: <CA+-xGqO4DtUs3-jH+QMPEze2GrXwtNX0z=vVUVak5HOpPKaDxQ@mail.gmail.com> (raw)
In-Reply-To: <20201013045245.GA11344@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 3203 bytes --]

Hi Sean,

Thanks for the prompt reply. Please see my following reply. Thanks.

On Tue, Oct 13, 2020 at 12:52 AM Sean Christopherson <
sean.j.christopherson@intel.com> wrote:
>
> On Tue, Oct 13, 2020 at 12:30:39AM -0400, harry harry wrote:
> > Hi Sean,
> >
> > Thank you very much for your thorough explanations. Please see my
> > inline replies as follows. Thanks!
> >
> > On Mon, Oct 12, 2020 at 12:54 PM Sean Christopherson
> > <sean.j.christopherson@intel.com> wrote:
> > >
> > > No, the guest physical address spaces is not intrinsically tied to
the host
> > > virtual address spaces.  The fact that GPAs and HVAs are related in
KVM is a
> > > property KVM's architecture.  EPT/NPT has absolutely nothing to do
with HVAs.
> > >
> > > As Maxim pointed out, KVM links a guest's physical address space,
i.e. GPAs, to
> > > the host's virtual address space, i.e. HVAs, via memslots.  For all
intents and
> > > purposes, this is an extra layer of address translation that is
purely software
> > > defined.  The memslots allow KVM to retrieve the HPA for a given GPA
when
> > > servicing a shadow page fault (a.k.a. EPT violation).
> > >
> > > When EPT is enabled, a shadow page fault due to an unmapped GPA will
look like:
> > >
> > >  GVA -> [guest page tables] -> GPA -> EPT Violation VM-Exit
> > >
> > > The above walk of the guest page tables is done in hardware.  KVM
then does the
> > > following walks in software to retrieve the desired HPA:
> > >
> > >  GPA -> [memslots] -> HVA -> [host page tables] -> HPA
> >
> > Do you mean that GPAs are different from their corresponding HVAs when
> > KVM does the walks (as you said above) in software?
>
> What do you mean by "different"?  GPAs and HVAs are two completely
different
> address spaces.

Let me give you one concrete example as follows to explain the meaning of
``different''.

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.

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* different* from its
corresponding HVA.

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?

[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.
[2] Please note that this hardware walk assumes translating the VA to the
PA without virtualization involvement.

Please note that the above addresses are not real and just use for
explanations.

Thanks,
Harry

[-- Attachment #2: Type: text/html, Size: 4004 bytes --]

  reply	other threads:[~2020-10-13  5:34 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-11  5:26 Why guest physical addresses are not the same as the corresponding host virtual addresses in QEMU/KVM? Thanks! harry harry
2020-10-11  5:26 ` harry harry
2020-10-11  7:29 ` Maxim Levitsky
2020-10-11  7:29   ` Maxim Levitsky
2020-10-11 14:11   ` harry harry
2020-10-11 14:11     ` harry harry
2020-10-12 16:54     ` Sean Christopherson
2020-10-12 16:54       ` Sean Christopherson
2020-10-13  4:30       ` harry harry
2020-10-13  4:30         ` harry harry
2020-10-13  4:52         ` Sean Christopherson
2020-10-13  4:52           ` Sean Christopherson
2020-10-13  5:33           ` harry harry [this message]
2020-10-13  5:46             ` harry harry
2020-10-13  6:43               ` Paolo Bonzini
2020-10-13  6:43                 ` Paolo Bonzini
2020-10-13 20:36                 ` harry harry
2020-10-13 20:36                   ` harry harry
2020-10-14  8:27                   ` Paolo Bonzini
2020-10-14  8:27                     ` Paolo Bonzini
2020-10-14  8:29                   ` Maxim Levitsky
2020-10-14  8:29                     ` Maxim Levitsky
2020-10-15  3:45                     ` harry harry
2020-10-15  3:45                       ` harry harry
2020-10-13  7:03             ` Sean Christopherson
2020-10-13  7:03               ` Sean Christopherson
2020-10-13 22:40               ` harry harry
2020-10-13 22:40                 ` harry harry
2020-10-14  8:28                 ` Paolo Bonzini
2020-10-14  8:28                   ` Paolo Bonzini
2020-10-15  3:43                   ` harry harry
2020-10-15  3:43                     ` harry harry
2020-10-13  5:00       ` harry harry
2020-10-13  5:00         ` harry harry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+-xGqO4DtUs3-jH+QMPEze2GrXwtNX0z=vVUVak5HOpPKaDxQ@mail.gmail.com' \
    --to=hiharryharryharry@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=libvir-list@redhat.com \
    --cc=mathieu.tarral@protonmail.com \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.