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 2/3] KVM: X86: Allow userspace to disable ioport intercept
Date: Mon, 16 Apr 2018 22:46:01 -0700	[thread overview]
Message-ID: <1523943962-25415-3-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>

Allow to disable ioport intercept by userspace.

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>
---
 Documentation/virtual/kvm/api.txt | 11 +++++++++++
 arch/x86/include/asm/kvm_host.h   |  2 ++
 arch/x86/kvm/x86.c                |  5 +++++
 include/uapi/linux/kvm.h          |  1 +
 4 files changed, 19 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 1c7958b..3d0488e 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -4378,6 +4378,17 @@ all such vmexits.
 
 Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
 
+7.14 KVM_CAP_IOPORT_DISABLE_INTERCEPT
+
+Architectures: x86
+Parameters: args[0] defines whether ioport intercept
+
+When disable intercept (args[0] == 1), some ioports which frequently
+access will not be intercepted.
+
+When enable intercept (args[0] == 0), behavior is as if this facility
+is unsupported.
+
 8. Other capabilities.
 ----------------------
 
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c25775f..2f29f64 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -808,6 +808,8 @@ struct kvm_arch {
 	bool hlt_in_guest;
 	bool pause_in_guest;
 
+	bool ioport_disable_intercept;
+
 	unsigned long irq_sources_bitmap;
 	s64 kvmclock_offset;
 	raw_spinlock_t tsc_write_lock;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 51ecd38..044e314 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2881,6 +2881,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
  	case KVM_CAP_SPLIT_IRQCHIP:
 	case KVM_CAP_IMMEDIATE_EXIT:
 	case KVM_CAP_GET_MSR_FEATURES:
+	case KVM_CAP_IOPORT_DISABLE_INTERCEPT:
 		r = 1;
 		break;
 	case KVM_CAP_SYNC_REGS:
@@ -4250,6 +4251,10 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
 			kvm->arch.pause_in_guest = true;
 		r = 0;
 		break;
+	case KVM_CAP_IOPORT_DISABLE_INTERCEPT:
+		kvm->arch.ioport_disable_intercept = cap->args[0];
+		r = 0;
+		break;
 	default:
 		r = -EINVAL;
 		break;
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 1065006..92730d8 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -941,6 +941,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_S390_BPB 152
 #define KVM_CAP_GET_MSR_FEATURES 153
 #define KVM_CAP_HYPERV_EVENTFD 154
+#define KVM_CAP_IOPORT_DISABLE_INTERCEPT 155
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
-- 
2.7.4

  parent 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 ` [PATCH 1/3] KVM: VMX: Introduce per-VM I/O permission bitmaps Wanpeng Li
2018-05-11 15:39   ` Konrad Rzeszutek Wilk
2018-05-15 21:55     ` Jim Mattson
2018-04-17  5:46 ` Wanpeng Li [this message]
2018-05-11 15:42   ` [PATCH 2/3] KVM: X86: Allow userspace to disable ioport intercept 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-3-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 2/3] KVM: X86: Allow userspace to disable ioport intercept' \
    /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).