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: Tue, 13 Oct 2020 08:43:18 +0200 [thread overview] Message-ID: <a163c2d8-d8a1-dc03-6230-a2e104e3b039@redhat.com> (raw) In-Reply-To: <CA+-xGqMMa-DB1SND5MRugusDafjNA9CVw-=OBK7q=CK1impmTQ@mail.gmail.com> On 13/10/20 07:46, harry harry wrote: > 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? It has separate data structures that help with the translation. These data structures are specific to KVM for GPA to HVA translation, while for HVA to HPA the Linux functionality is reused. > BTW, I assume the software logic for KVM to find the HPA with a given > HVA (as you said like below) should be the same as the hardware logic in > MMU to translate ``GPA -> [extended/nested page tables] -> HPA''. 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. It performs instead two steps, from GPA to HVA and from HVA to HPA: * for GPA to HVA it uses a custom data structure. * for HVA to HPA it uses the host page tables as mentioned above. This is because: * the GPA to HVA translation is the one that is almost always sufficient, and the nested page tables do not provide this information * even if GPA to HPA is needed, the nested page tables are built lazily and therefore may not always contain the requested mapping. In addition using HPA requires special steps (such as calling get_page/put_page) and often these steps need an HVA anyway. 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: Tue, 13 Oct 2020 08:43:18 +0200 [thread overview] Message-ID: <a163c2d8-d8a1-dc03-6230-a2e104e3b039@redhat.com> (raw) In-Reply-To: <CA+-xGqMMa-DB1SND5MRugusDafjNA9CVw-=OBK7q=CK1impmTQ@mail.gmail.com> On 13/10/20 07:46, harry harry wrote: > 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? It has separate data structures that help with the translation. These data structures are specific to KVM for GPA to HVA translation, while for HVA to HPA the Linux functionality is reused. > BTW, I assume the software logic for KVM to find the HPA with a given > HVA (as you said like below) should be the same as the hardware logic in > MMU to translate ``GPA -> [extended/nested page tables] -> HPA''. 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. It performs instead two steps, from GPA to HVA and from HVA to HPA: * for GPA to HVA it uses a custom data structure. * for HVA to HPA it uses the host page tables as mentioned above. This is because: * the GPA to HVA translation is the one that is almost always sufficient, and the nested page tables do not provide this information * even if GPA to HPA is needed, the nested page tables are built lazily and therefore may not always contain the requested mapping. In addition using HPA requires special steps (such as calling get_page/put_page) and often these steps need an HVA anyway. Paolo
next prev parent reply other threads:[~2020-10-13 6:43 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 [this message] 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=a163c2d8-d8a1-dc03-6230-a2e104e3b039@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: linkBe 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.