linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: KarimAllah Ahmed <karahmed@amazon.de>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "KarimAllah Ahmed" <karahmed@amazon.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Subject: [RFC 02/12] KVM/VMX: Use the new host mapping API for apic_access_page
Date: Mon,  5 Feb 2018 19:47:21 +0100	[thread overview]
Message-ID: <1517856451-2932-3-git-send-email-karahmed@amazon.de> (raw)
In-Reply-To: <1517856451-2932-1-git-send-email-karahmed@amazon.de>

For nested guests the apic_access_page was mapped to the host kernel using
kvm_vcpu_gpa_to_page which assumes that all guest memory is backed by a
"struct page". This breaks guests that have their memory outside the kernel
control.

Switch to the new host mapping API which takes care of this use-case as
well.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
---
 arch/x86/kvm/vmx.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 5d8a6a91..b76ab06 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -451,7 +451,7 @@ struct nested_vmx {
 	 * Guest pages referred to in the vmcs02 with host-physical
 	 * pointers, so we must keep them pinned while L2 runs.
 	 */
-	struct page *apic_access_page;
+	struct kvm_host_mapping apic_access_mapping;
 	struct page *virtual_apic_page;
 	struct page *pi_desc_page;
 	struct pi_desc *pi_desc;
@@ -7500,10 +7500,8 @@ static void free_nested(struct vcpu_vmx *vmx)
 	}
 	kfree(vmx->nested.cached_vmcs12);
 	/* Unpin physical memory we referred to in the vmcs02 */
-	if (vmx->nested.apic_access_page) {
-		kvm_release_page_dirty(vmx->nested.apic_access_page);
-		vmx->nested.apic_access_page = NULL;
-	}
+	if (vmx->nested.apic_access_mapping.pfn)
+		kvm_release_host_mapping(&vmx->nested.apic_access_mapping, true);
 	if (vmx->nested.virtual_apic_page) {
 		kvm_release_page_dirty(vmx->nested.virtual_apic_page);
 		vmx->nested.virtual_apic_page = NULL;
@@ -10056,25 +10054,22 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
 		 * physical address remains valid. We keep a reference
 		 * to it so we can release it later.
 		 */
-		if (vmx->nested.apic_access_page) { /* shouldn't happen */
-			kvm_release_page_dirty(vmx->nested.apic_access_page);
-			vmx->nested.apic_access_page = NULL;
-		}
-		page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->apic_access_addr);
+		if (vmx->nested.apic_access_mapping.pfn) /* shouldn't happen */
+			kvm_release_host_mapping(&vmx->nested.apic_access_mapping, true);
+
 		/*
 		 * If translation failed, no matter: This feature asks
 		 * to exit when accessing the given address, and if it
 		 * can never be accessed, this feature won't do
 		 * anything anyway.
 		 */
-		if (!is_error_page(page)) {
-			vmx->nested.apic_access_page = page;
-			hpa = page_to_phys(vmx->nested.apic_access_page);
-			vmcs_write64(APIC_ACCESS_ADDR, hpa);
-		} else {
+		if (kvm_vcpu_gpa_to_host_mapping(vcpu, vmcs12->apic_access_addr,
+						 &vmx->nested.apic_access_mapping, false))
+			vmcs_write64(APIC_ACCESS_ADDR,
+				     vmx->nested.apic_access_mapping.pfn << PAGE_SHIFT);
+		else
 			vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL,
 					SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES);
-		}
 	} else if (!(nested_cpu_has_virt_x2apic_mode(vmcs12)) &&
 		   cpu_need_virtualize_apic_accesses(&vmx->vcpu)) {
 		vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL,
@@ -11686,10 +11681,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
 	vmx->host_rsp = 0;
 
 	/* Unpin physical memory we referred to in vmcs02 */
-	if (vmx->nested.apic_access_page) {
-		kvm_release_page_dirty(vmx->nested.apic_access_page);
-		vmx->nested.apic_access_page = NULL;
-	}
+	if (vmx->nested.apic_access_mapping.pfn)
+		kvm_release_host_mapping(&vmx->nested.apic_access_mapping, true);
 	if (vmx->nested.virtual_apic_page) {
 		kvm_release_page_dirty(vmx->nested.virtual_apic_page);
 		vmx->nested.virtual_apic_page = NULL;
-- 
2.7.4

  parent reply	other threads:[~2018-02-05 18:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-05 18:47 [RFC 00/12] KVM/X86: Introduce a new guest mapping API KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 01/12] KVM: Introduce helper functions to map/unmap guest memory KarimAllah Ahmed
2018-02-05 18:47 ` KarimAllah Ahmed [this message]
2018-02-05 19:27   ` [RFC 02/12] KVM/VMX: Use the new host mapping API for apic_access_page Jim Mattson
2018-02-05 18:47 ` [RFC 03/12] KVM/VMX: Use the new host mapping API for virtual_apic_page KarimAllah Ahmed
2018-02-05 22:26   ` Jim Mattson
2018-02-09 12:15     ` KarimAllah Ahmed
2018-02-09 22:55       ` Jim Mattson
2018-02-05 18:47 ` [RFC 04/12] KVM/VMX: Use the new host mapping API for pi_desc_page KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 05/12] KVM/VMX: Use the new host mapping API for mapping nested vmptr KarimAllah Ahmed
2018-02-05 22:15   ` Jim Mattson
2018-02-08 18:51     ` KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 06/12] KVM/VMX: Use the new host mapping API for handle_vmptrld KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 07/12] KVM/VMX: Use the new host mapping API for mapping L12 MSR bitmap KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 08/12] KVM/VMX: Use the new host mapping API for mapping nested PML KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 09/12] KVM/VMX: Use the new host mapping API for cmpxchg_emulated KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 10/12] KVM/VMX: Use the new host mapping API for synic_clear_sint_msg_pending KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 11/12] KVM/VMX: Use the new host mapping API for synic_deliver_msg KarimAllah Ahmed
2018-02-05 18:47 ` [RFC 12/12] KVM/VMX: Remove kvm_vcpu_gpa_to_page as it is now unused KarimAllah Ahmed
2018-02-05 19:26 ` [RFC 00/12] KVM/X86: Introduce a new guest mapping API Mihai Donțu
2018-02-10 11:33   ` KarimAllah Ahmed
2018-02-16 11:40     ` Mihai Donțu

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=1517856451-2932-3-git-send-email-karahmed@amazon.de \
    --to=karahmed@amazon.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).