linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: avi@redhat.com, mst@redhat.com
Cc: gleb@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v8 2/6] kvm: Expose IRQ source IDs to userspace
Date: Fri, 10 Aug 2012 16:37:25 -0600	[thread overview]
Message-ID: <20120810223723.809.33669.stgit@bling.home> (raw)
In-Reply-To: <20120810223633.809.44188.stgit@bling.home>

Introduce KVM_IRQ_SOURCE_ID and KVM_CAP_NR_IRQ_SOURCE_ID to allow
user allocation of IRQ source IDs and querying both the capability
and the total count of IRQ source IDs.  These will later be used
by interfaces for setting up level IRQs.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 Documentation/virtual/kvm/api.txt |   20 ++++++++++++++++++++
 arch/x86/kvm/Kconfig              |    1 +
 arch/x86/kvm/x86.c                |    3 +++
 include/linux/kvm.h               |   11 +++++++++++
 include/linux/kvm_host.h          |    1 +
 virt/kvm/Kconfig                  |    3 +++
 virt/kvm/irq_comm.c               |   22 ++++++++++++++++++++++
 virt/kvm/kvm_main.c               |   16 ++++++++++++++++
 8 files changed, 77 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index bf33aaa..062cfd5 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1980,6 +1980,26 @@ return the hash table order in the parameter.  (If the guest is using
 the virtualized real-mode area (VRMA) facility, the kernel will
 re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.)
 
+4.77 KVM_IRQ_SOURCE_ID
+
+Capability: KVM_CAP_NR_IRQ_SOURCE_ID
+Architectures: x86
+Type: vm ioctl
+Parameters: struct kvm_irq_source_id (in/out)
+Returns: 0 on success, -errno on error
+
+Allows allocating and freeing IRQ source IDs.  Each IRQ source ID
+represents a complete set of irqchip pin inputs which are logically
+OR'd with other IRQ source IDs for determining the final assertion
+level of a pin.  The flag KVM_IRQ_SOURCE_ID_FLAG_DEASSIGN indicates
+whether the call is for an allocation or deallocation.
+kvm_irq_source_id.irq_source_id returns the allocated IRQ source ID
+on success and specifies the freed IRQ source ID on deassign.  The
+return value of KVM_CAP_NR_IRQ_SOURCE_ID indicates the total number
+of IRQ source IDs.  These IDs are also shared with KVM internal users
+(ex. KVM assigned devices, PIT, shared user ID), therefore not all IDs
+may be allocated through this interface.
+
 
 5. The kvm_run structure
 ------------------------
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index a28f338..bfd2082 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -37,6 +37,7 @@ config KVM
 	select TASK_DELAY_ACCT
 	select PERF_EVENTS
 	select HAVE_KVM_MSI
+	select HAVE_KVM_IRQ_SOURCE_ID
 	---help---
 	  Support hosting fully virtualized guest machines using hardware
 	  virtualization extensions.  You will need a fairly recent
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 42bce48..75e743e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2209,6 +2209,9 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_TSC_DEADLINE_TIMER:
 		r = boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER);
 		break;
+	case KVM_CAP_NR_IRQ_SOURCE_ID:
+		r = BITS_PER_LONG; /* kvm->arch.irq_sources_bitmap */
+		break;
 	default:
 		r = 0;
 		break;
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2ce09aa..67b6b49 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -618,6 +618,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_GET_SMMU_INFO 78
 #define KVM_CAP_S390_COW 79
 #define KVM_CAP_PPC_ALLOC_HTAB 80
+#define KVM_CAP_NR_IRQ_SOURCE_ID 81
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -691,6 +692,14 @@ struct kvm_irqfd {
 	__u8  pad[20];
 };
 
+#define KVM_IRQ_SOURCE_ID_FLAG_DEASSIGN (1 << 0)
+
+struct kvm_irq_source_id {
+	__u32 flags;
+	__u32 irq_source_id;
+	__u8 pad[24];
+};
+
 struct kvm_clock_data {
 	__u64 clock;
 	__u32 flags;
@@ -831,6 +840,8 @@ struct kvm_s390_ucas_mapping {
 #define KVM_PPC_GET_SMMU_INFO	  _IOR(KVMIO,  0xa6, struct kvm_ppc_smmu_info)
 /* Available with KVM_CAP_PPC_ALLOC_HTAB */
 #define KVM_PPC_ALLOCATE_HTAB	  _IOWR(KVMIO, 0xa7, __u32)
+/* Available with KVM_CAP_IRQ_SOURCE_ID */
+#define KVM_IRQ_SOURCE_ID         _IOWR(KVMIO, 0xa8, struct kvm_irq_source_id)
 
 /*
  * ioctls for vcpu fds
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 2ad3e4a..ea6d7a1 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -636,6 +636,7 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
 				   struct kvm_irq_ack_notifier *kian);
 int kvm_request_irq_source_id(struct kvm *kvm);
 void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
+int kvm_irq_source_id(struct kvm *kvm, struct kvm_irq_source_id *id);
 
 /* For vcpu->arch.iommu_flags */
 #define KVM_IOMMU_CACHE_COHERENCY	0x1
diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
index 28694f4..b7e0d4d 100644
--- a/virt/kvm/Kconfig
+++ b/virt/kvm/Kconfig
@@ -21,3 +21,6 @@ config KVM_ASYNC_PF
 
 config HAVE_KVM_MSI
        bool
+
+config HAVE_KVM_IRQ_SOURCE_ID
+       bool
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 7d75126..44d40c9 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -254,6 +254,28 @@ unlock:
 	mutex_unlock(&kvm->irq_lock);
 }
 
+int kvm_irq_source_id(struct kvm *kvm, struct kvm_irq_source_id *id)
+{
+	int irq_source_id;
+
+	if (id->flags & ~KVM_IRQ_SOURCE_ID_FLAG_DEASSIGN)
+		return -EINVAL;
+
+	if (id->flags & KVM_IRQ_SOURCE_ID_FLAG_DEASSIGN) {
+		if (id->irq_source_id == KVM_USERSPACE_IRQ_SOURCE_ID)
+			return -EINVAL;
+		kvm_free_irq_source_id(kvm, id->irq_source_id);
+		return 0;
+	}
+
+	irq_source_id = kvm_request_irq_source_id(kvm);
+	if (irq_source_id < 0)
+		return irq_source_id;
+
+	id->irq_source_id = irq_source_id;
+	return 0;
+}
+
 void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
 				    struct kvm_irq_mask_notifier *kimn)
 {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2468523..e120cb3 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2093,6 +2093,22 @@ static long kvm_vm_ioctl(struct file *filp,
 		break;
 	}
 #endif
+#ifdef CONFIG_HAVE_KVM_IRQ_SOURCE_ID
+	case KVM_IRQ_SOURCE_ID: {
+		struct kvm_irq_source_id id;
+
+		r = -EFAULT;
+		if (copy_from_user(&id, argp, sizeof(id)))
+			goto out;
+
+		r = kvm_irq_source_id(kvm, &id);
+		if (!r && copy_to_user(argp, &id, sizeof(id))) {
+			r = -EFAULT;
+			goto out;
+		}
+		break;
+	}
+#endif
 	default:
 		r = kvm_arch_vm_ioctl(filp, ioctl, arg);
 		if (r == -ENOTTY)


  parent reply	other threads:[~2012-08-10 22:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 22:37 [PATCH v8 0/6] kvm: level irqfd support Alex Williamson
2012-08-10 22:37 ` [PATCH v8 1/6] kvm: Allow filtering of acked irqs Alex Williamson
2012-08-15 12:27   ` Michael S. Tsirkin
2012-08-15 16:47     ` Alex Williamson
2012-08-15 19:24       ` Michael S. Tsirkin
2012-08-10 22:37 ` Alex Williamson [this message]
2012-08-15 12:59   ` [PATCH v8 2/6] kvm: Expose IRQ source IDs to userspace Michael S. Tsirkin
2012-08-15 17:05     ` Alex Williamson
2012-08-10 22:37 ` [PATCH v8 3/6] kvm: Add IRQ source ID option to KVM_IRQFD Alex Williamson
2012-08-15 13:49   ` Michael S. Tsirkin
2012-08-15 17:08     ` Alex Williamson
2012-08-10 22:37 ` [PATCH v8 4/6] kvm: Add assert-only " Alex Williamson
2012-08-10 22:37 ` [PATCH v8 5/6] kvm: KVM_IRQ_ACKFD Alex Williamson
2012-08-15 14:05   ` Michael S. Tsirkin
2012-08-15 17:17     ` Alex Williamson
2012-08-10 22:37 ` [PATCH v8 6/6] kvm: Add de-assert option to KVM_IRQ_ACKFD Alex Williamson
2012-08-15 14:11   ` Michael S. Tsirkin
2012-08-15 17:24     ` Alex Williamson
2012-08-15 14:28 ` [PATCH v8 0/6] kvm: level irqfd support Michael S. Tsirkin
2012-08-15 17:36   ` Alex Williamson
2012-08-15 19:22     ` Michael S. Tsirkin
2012-08-15 19:59       ` Alex Williamson
2012-08-16 12:34         ` Alex Williamson
2012-08-16 12:53           ` Michael S. Tsirkin
2012-08-16 16:29       ` Avi Kivity
2012-08-16 16:36         ` Michael S. Tsirkin
2012-08-16 16:39           ` Avi Kivity
2012-08-16 16:54             ` Michael S. Tsirkin
2012-08-16 16:54               ` Avi Kivity
2012-08-16 17:01                 ` Michael S. Tsirkin
2012-08-16 16:37         ` Alex Williamson
2012-08-16 16:32 ` Avi Kivity
2012-08-16 16:45   ` Alex Williamson

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=20120810223723.809.33669.stgit@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@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).