All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: harry harry <hiharryharryharry@gmail.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Maxim Levitsky <mlevitsk@redhat.com>,
	qemu-devel@nongnu.org, mathieu.tarral@protonmail.com,
	stefanha@redhat.com, libvir-list@redhat.com, kvm@vger.kernel.org
Subject: Re: Why guest physical addresses are not the same as the corresponding host virtual addresses in QEMU/KVM? Thanks!
Date: Wed, 14 Oct 2020 10:27:22 +0200	[thread overview]
Message-ID: <24cdf8f2-7dc7-1232-8d78-86f9b4b8eda3@redhat.com> (raw)
In-Reply-To: <CA+-xGqOMKRh+_5vYXeLOiGnTMw4L_gUccqdQ+HGSOzuTosp6tw@mail.gmail.com>

On 13/10/20 22:36, harry harry wrote:
> Hi Paolo and Sean,
> 
> Thanks much for your prompt replies and clear explanations.
> 
> On Tue, Oct 13, 2020 at 2:43 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> No, the logic to find the HPA with a given HVA is the same as the
>> hardware logic to translate HVA -> HPA.  That is it uses the host
>> "regular" page tables, not the nested page tables.
>>
>> In order to translate GPA to HPA, instead, KVM does not use the nested
>> page tables.
> 
> I am curious why KVM does not directly use GPAs as HVAs and leverage
> nested page tables to translate HVAs (i.e., GPAs) to HPAs?

GPAs and HVAs are different things.  In fact I'm not aware of any
hypervisor that uses HVA==GPA.  On 32-bit x86 systems HVAs are 32-bit
(obviously) but GPAs are 36-bit.

In the case of KVM, HVAs are controlled by the rest of Linux; for
example, when you do "mmap" to allocate guest memory you cannot ask the
OS to return the guest memory at the exact HVA that is needed by the
guest.  There could be something else at that HVA (or you don't want
anything at that HVA: GPA 0 is valid, but HVA 0 is the NULL pointer!).
There's also cases where the same memory appears in multiple places in
the guest memory map (aliasing).

Paolo


WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: harry harry <hiharryharryharry@gmail.com>,
	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
Subject: Re: Why guest physical addresses are not the same as the corresponding host virtual addresses in QEMU/KVM? Thanks!
Date: Wed, 14 Oct 2020 10:27:22 +0200	[thread overview]
Message-ID: <24cdf8f2-7dc7-1232-8d78-86f9b4b8eda3@redhat.com> (raw)
In-Reply-To: <CA+-xGqOMKRh+_5vYXeLOiGnTMw4L_gUccqdQ+HGSOzuTosp6tw@mail.gmail.com>

On 13/10/20 22:36, harry harry wrote:
> Hi Paolo and Sean,
> 
> Thanks much for your prompt replies and clear explanations.
> 
> On Tue, Oct 13, 2020 at 2:43 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> No, the logic to find the HPA with a given HVA is the same as the
>> hardware logic to translate HVA -> HPA.  That is it uses the host
>> "regular" page tables, not the nested page tables.
>>
>> In order to translate GPA to HPA, instead, KVM does not use the nested
>> page tables.
> 
> I am curious why KVM does not directly use GPAs as HVAs and leverage
> nested page tables to translate HVAs (i.e., GPAs) to HPAs?

GPAs and HVAs are different things.  In fact I'm not aware of any
hypervisor that uses HVA==GPA.  On 32-bit x86 systems HVAs are 32-bit
(obviously) but GPAs are 36-bit.

In the case of KVM, HVAs are controlled by the rest of Linux; for
example, when you do "mmap" to allocate guest memory you cannot ask the
OS to return the guest memory at the exact HVA that is needed by the
guest.  There could be something else at that HVA (or you don't want
anything at that HVA: GPA 0 is valid, but HVA 0 is the NULL pointer!).
There's also cases where the same memory appears in multiple places in
the guest memory map (aliasing).

Paolo



  reply	other threads:[~2020-10-14  8:27 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
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 [this message]
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=24cdf8f2-7dc7-1232-8d78-86f9b4b8eda3@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=hiharryharryharry@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=libvir-list@redhat.com \
    --cc=mathieu.tarral@protonmail.com \
    --cc=mlevitsk@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.