From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: QUESTION: mmu.gva_to_gpa versus nested_mmu.gva_to_gpa Date: Tue, 29 Dec 2015 00:25:29 +0100 Message-ID: <5681C4E9.9090503@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: David Matlack , kvm list Return-path: Received: from mail-wm0-f42.google.com ([74.125.82.42]:35799 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752643AbbL1XZe (ORCPT ); Mon, 28 Dec 2015 18:25:34 -0500 Received: by mail-wm0-f42.google.com with SMTP id l126so276231239wml.0 for ; Mon, 28 Dec 2015 15:25:34 -0800 (PST) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On 28/12/2015 23:23, David Matlack wrote: > I'm wondering if this comment in mmu.c:init_kvm_nested_mmu is correct (at > least in the context of Nested EPT): > > 4055 /* > 4056 * Note that arch.mmu.gva_to_gpa translates l2_gva to l1_gpa. The > 4057 * translation of l2_gpa to l1_gpa addresses is done using the > 4058 * arch.nested_mmu.gva_to_gpa function. Basically the gva_to_gpa > 4059 * functions between mmu and nested_mmu are swapped. > 4060 */ > > nested_mmu.get_cr3 gets set to get_cr3, which I believe will return L2's cr3. > In vmx.c:nested_ept_init_mmu_context, mmu.get_cr3 is set to > nested_ept_get_cr3, which should be the root of EPT12. Given these get_cr3 > functions, shouldn't nested_mmu.gva_to_gpa translate l2_gva->l2_gpa and > mmu.gva_to_gpa translate l2_gpa->l1_gpa? Yes, it's correct. It can be trivially seen by looking at kvm_init_shadow_ept_mmu's usage of &vcpu->arch.mmu. This is obviously a l2_gpa to l1_gpa translation. Whether the roles are swapped, depends on whether you think of "nested_mmu" as "nested guest" or "nested virtualization" nested_mmu is the MMU for the nested guest, mmu is the MMU for the L1 guest and it's the one that takes care of nested virtualization. Paolo