Skip to content

Commit

Permalink
KVM: irqfd
Browse files Browse the repository at this point in the history
KVM provides a complete virtual system environment for guests, including
support for injecting interrupts modeled after the real exception/interrupt
facilities present on the native platform (such as the IDT on x86).
Virtual interrupts can come from a variety of sources (emulated devices,
pass-through devices, etc) but all must be injected to the guest via
the KVM infrastructure.  This patch adds a new mechanism to inject a specific
interrupt to a guest using a decoupled eventfd mechnanism:  Any legal signal
on the irqfd (using eventfd semantics from either userspace or kernel) will
translate into an injected interrupt in the guest at the next available
interrupt window.

Signed-off-by: Gregory Haskins <ghaskins@novell.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
  • Loading branch information
Gregory Haskins authored and Avi Kivity committed Sep 10, 2009
1 parent 0ba12d1 commit 721eecb
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 1 deletion.
1 change: 1 addition & 0 deletions arch/x86/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ config KVM
select MMU_NOTIFIER
select ANON_INODES
select HAVE_KVM_IRQCHIP
select HAVE_KVM_EVENTFD
---help---
Support hosting fully virtualized guest machines using hardware
virtualization extensions. You will need a fairly recent
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm

kvm-y += $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
coalesced_mmio.o irq_comm.o)
coalesced_mmio.o irq_comm.o eventfd.o)
kvm-$(CONFIG_KVM_TRACE) += $(addprefix ../../../virt/kvm/, kvm_trace.o)
kvm-$(CONFIG_IOMMU_API) += $(addprefix ../../../virt/kvm/, iommu.o)

Expand Down
1 change: 1 addition & 0 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_REINJECT_CONTROL:
case KVM_CAP_IRQ_INJECT_STATUS:
case KVM_CAP_ASSIGN_DEV_IRQ:
case KVM_CAP_IRQFD:
r = 1;
break;
case KVM_CAP_COALESCED_MMIO:
Expand Down
11 changes: 11 additions & 0 deletions include/linux/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ struct kvm_trace_rec {
#ifdef __KVM_HAVE_MCE
#define KVM_CAP_MCE 31
#endif
#define KVM_CAP_IRQFD 32

#ifdef KVM_CAP_IRQ_ROUTING

Expand Down Expand Up @@ -470,6 +471,15 @@ struct kvm_x86_mce {
};
#endif

#define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)

struct kvm_irqfd {
__u32 fd;
__u32 gsi;
__u32 flags;
__u8 pad[20];
};

/*
* ioctls for VM fds
*/
Expand Down Expand Up @@ -514,6 +524,7 @@ struct kvm_x86_mce {
#define KVM_ASSIGN_SET_MSIX_ENTRY \
_IOW(KVMIO, 0x74, struct kvm_assigned_msix_entry)
#define KVM_DEASSIGN_DEV_IRQ _IOW(KVMIO, 0x75, struct kvm_assigned_irq)
#define KVM_IRQFD _IOW(KVMIO, 0x76, struct kvm_irqfd)

/*
* ioctls for vcpu fds
Expand Down
24 changes: 24 additions & 0 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ struct kvm {
struct list_head vm_list;
struct kvm_io_bus mmio_bus;
struct kvm_io_bus pio_bus;
#ifdef CONFIG_HAVE_KVM_EVENTFD
struct {
spinlock_t lock;
struct list_head items;
} irqfds;
#endif
struct kvm_vm_stat stat;
struct kvm_arch arch;
atomic_t users_count;
Expand Down Expand Up @@ -525,4 +531,22 @@ static inline void kvm_free_irq_routing(struct kvm *kvm) {}

#endif

#ifdef CONFIG_HAVE_KVM_EVENTFD

void kvm_irqfd_init(struct kvm *kvm);
int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
void kvm_irqfd_release(struct kvm *kvm);

#else

static inline void kvm_irqfd_init(struct kvm *kvm) {}
static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags)
{
return -EINVAL;
}

static inline void kvm_irqfd_release(struct kvm *kvm) {}

#endif /* CONFIG_HAVE_KVM_EVENTFD */

#endif
4 changes: 4 additions & 0 deletions virt/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ config HAVE_KVM

config HAVE_KVM_IRQCHIP
bool

config HAVE_KVM_EVENTFD
bool
select EVENTFD
Loading

0 comments on commit 721eecb

Please sign in to comment.