xref: /openbmc/linux/include/linux/kvm_irqfd.h (revision d583fbd7)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *
4  * irqfd: Allows an fd to be used to inject an interrupt to the guest
5  * Credit goes to Avi Kivity for the original idea.
6  */
7 
8 #ifndef __LINUX_KVM_IRQFD_H
9 #define __LINUX_KVM_IRQFD_H
10 
11 #include <linux/kvm_host.h>
12 #include <linux/poll.h>
13 
14 /*
15  * Resampling irqfds are a special variety of irqfds used to emulate
16  * level triggered interrupts.  The interrupt is asserted on eventfd
17  * trigger.  On acknowledgment through the irq ack notifier, the
18  * interrupt is de-asserted and userspace is notified through the
19  * resamplefd.  All resamplers on the same gsi are de-asserted
20  * together, so we don't need to track the state of each individual
21  * user.  We can also therefore share the same irq source ID.
22  */
23 struct kvm_kernel_irqfd_resampler {
24 	struct kvm *kvm;
25 	/*
26 	 * List of resampling struct _irqfd objects sharing this gsi.
27 	 * RCU list modified under kvm->irqfds.resampler_lock
28 	 */
29 	struct list_head list;
30 	struct kvm_irq_ack_notifier notifier;
31 	/*
32 	 * Entry in list of kvm->irqfd.resampler_list.  Use for sharing
33 	 * resamplers among irqfds on the same gsi.
34 	 * RCU list modified under kvm->irqfds.resampler_lock
35 	 */
36 	struct list_head link;
37 };
38 
39 struct kvm_kernel_irqfd {
40 	/* Used for MSI fast-path */
41 	struct kvm *kvm;
42 	wait_queue_entry_t wait;
43 	/* Update side is protected by irqfds.lock */
44 	struct kvm_kernel_irq_routing_entry irq_entry;
45 	seqcount_spinlock_t irq_entry_sc;
46 	/* Used for level IRQ fast-path */
47 	int gsi;
48 	struct work_struct inject;
49 	/* The resampler used by this irqfd (resampler-only) */
50 	struct kvm_kernel_irqfd_resampler *resampler;
51 	/* Eventfd notified on resample (resampler-only) */
52 	struct eventfd_ctx *resamplefd;
53 	/* Entry in list of irqfds for a resampler (resampler-only) */
54 	struct list_head resampler_link;
55 	/* Used for setup/shutdown */
56 	struct eventfd_ctx *eventfd;
57 	struct list_head list;
58 	poll_table pt;
59 	struct work_struct shutdown;
60 	struct irq_bypass_consumer consumer;
61 	struct irq_bypass_producer *producer;
62 };
63 
64 #endif /* __LINUX_KVM_IRQFD_H */
65