LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Wanpeng Li <kernellwp@gmail.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Tim Shearer" <tshearer@advaoptical.com>,
	"Liran Alon" <liran.alon@oracle.com>
Subject: [PATCH 1/3] KVM: VMX: Introduce per-VM I/O permission bitmaps
Date: Mon, 16 Apr 2018 22:46:00 -0700	[thread overview]
Message-ID: <1523943962-25415-2-git-send-email-wanpengli@tencent.com> (raw)
In-Reply-To: <1523943962-25415-1-git-send-email-wanpengli@tencent.com>

From: Wanpeng Li <wanpengli@tencent.com>

This patch introduces per-VM I/O permission bitmaps, it will be used by 
later patches.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Tim Shearer <tshearer@advaoptical.com>
Cc: Liran Alon <liran.alon@oracle.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/vmx.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 5b49ad4..ebf1140 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -189,12 +189,19 @@ module_param(ple_window_max, uint, 0444);
 
 extern const ulong vmx_return;
 
+enum {
+	VMX_IO_BITMAP_A,
+	VMX_IO_BITMAP_B,
+	VMX_IO_BITMAP_NR
+};
+
 struct kvm_vmx {
 	struct kvm kvm;
 
 	unsigned int tss_addr;
 	bool ept_identity_pagetable_done;
 	gpa_t ept_identity_map_addr;
+	unsigned long *vmx_io_bitmap[VMX_IO_BITMAP_NR];
 };
 
 #define NR_AUTOLOAD_MSRS 8
@@ -3963,7 +3970,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
 #endif
 	      CPU_BASED_CR3_LOAD_EXITING |
 	      CPU_BASED_CR3_STORE_EXITING |
-	      CPU_BASED_UNCOND_IO_EXITING |
+	      CPU_BASED_USE_IO_BITMAPS |
 	      CPU_BASED_MOV_DR_EXITING |
 	      CPU_BASED_USE_TSC_OFFSETING |
 	      CPU_BASED_MWAIT_EXITING |
@@ -5940,6 +5947,12 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
 #endif
 	int i;
 
+	/* I/O */
+	vmcs_write64(IO_BITMAP_A,
+		__pa(to_kvm_vmx(vmx->vcpu.kvm)->vmx_io_bitmap[VMX_IO_BITMAP_A]));
+	vmcs_write64(IO_BITMAP_B,
+		__pa(to_kvm_vmx(vmx->vcpu.kvm)->vmx_io_bitmap[VMX_IO_BITMAP_B]));
+
 	if (enable_shadow_vmcs) {
 		vmcs_write64(VMREAD_BITMAP, __pa(vmx_vmread_bitmap));
 		vmcs_write64(VMWRITE_BITMAP, __pa(vmx_vmwrite_bitmap));
@@ -10093,9 +10106,24 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
 
 static int vmx_vm_init(struct kvm *kvm)
 {
+	int i;
+	struct kvm_vmx *kvm_vmx = to_kvm_vmx(kvm);
+
 	if (!ple_gap)
 		kvm->arch.pause_in_guest = true;
+
+	for (i = 0; i < VMX_IO_BITMAP_NR; i++) {
+		kvm_vmx->vmx_io_bitmap[i] = (unsigned long *)__get_free_page(GFP_KERNEL);
+		if (!kvm_vmx->vmx_io_bitmap[i])
+			goto out;
+		memset(kvm_vmx->vmx_io_bitmap[i], 0xff, PAGE_SIZE);
+	}
 	return 0;
+
+out:
+	for (i = 0; i < VMX_IO_BITMAP_NR; i++)
+		free_page((unsigned long)kvm_vmx->vmx_io_bitmap[i]);
+	return -ENOMEM;
 }
 
 static void __init vmx_check_processor_compat(void *rtn)
@@ -11128,8 +11156,8 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
 	}
 
 	/*
-	 * A vmexit (to either L1 hypervisor or L0 userspace) is always needed
-	 * for I/O port accesses.
+	 * Merging of IO bitmap not currently supported.
+	 * Rather, exit every time.
 	 */
 	exec_control &= ~CPU_BASED_USE_IO_BITMAPS;
 	exec_control |= CPU_BASED_UNCOND_IO_EXITING;
-- 
2.7.4

  reply	other threads:[~2018-04-17  5:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17  5:45 [PATCH 0/3] KVM: VMX: Allow to disable ioport intercept per-VM by userspace Wanpeng Li
2018-04-17  5:46 ` Wanpeng Li [this message]
2018-05-11 15:39   ` [PATCH 1/3] KVM: VMX: Introduce per-VM I/O permission bitmaps Konrad Rzeszutek Wilk
2018-05-15 21:55     ` Jim Mattson
2018-04-17  5:46 ` [PATCH 2/3] KVM: X86: Allow userspace to disable ioport intercept Wanpeng Li
2018-05-11 15:42   ` Konrad Rzeszutek Wilk
2018-05-11 15:43     ` Konrad Rzeszutek Wilk
2018-05-15 21:56       ` Jim Mattson
2018-05-16  1:13         ` Wanpeng Li
2018-04-17  5:46 ` [PATCH 3/3] KVM: VMX: Allow I/O port 0x80 bypass when userspace prefer Wanpeng Li
2018-05-11 15:44   ` Konrad Rzeszutek Wilk
2018-05-15 21:57     ` Jim Mattson
2018-05-08  7:55 ` [PATCH 0/3] KVM: VMX: Allow to disable ioport intercept per-VM by userspace Wanpeng Li
2018-05-08 16:14   ` Paolo Bonzini
2018-05-11 15:40 ` Konrad Rzeszutek Wilk
2018-05-12  1:03   ` Wanpeng Li
2018-05-14 13:48     ` Tim Shearer

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=1523943962-25415-2-git-send-email-wanpengli@tencent.com \
    --to=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liran.alon@oracle.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tshearer@advaoptical.com \
    --subject='Re: [PATCH 1/3] KVM: VMX: Introduce per-VM I/O permission bitmaps' \
    /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

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).