KVM
Classes | Macros | Functions
irq.h File Reference
#include <linux/mm_types.h>
#include <linux/hrtimer.h>
#include <linux/kvm_host.h>
#include <linux/spinlock.h>
#include <kvm/iodev.h>
#include "lapic.h"
Include dependency graph for irq.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  kvm_kpic_state
 
struct  kvm_pic
 

Macros

#define PIC_NUM_PINS   16
 
#define SELECT_PIC(irq)    ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)
 

Functions

int kvm_pic_init (struct kvm *kvm)
 
void kvm_pic_destroy (struct kvm *kvm)
 
int kvm_pic_read_irq (struct kvm *kvm)
 
void kvm_pic_update_irq (struct kvm_pic *s)
 
static int irqchip_split (struct kvm *kvm)
 
static int irqchip_kernel (struct kvm *kvm)
 
static int pic_in_kernel (struct kvm *kvm)
 
static int irqchip_in_kernel (struct kvm *kvm)
 
void kvm_inject_pending_timer_irqs (struct kvm_vcpu *vcpu)
 
void kvm_inject_apic_timer_irqs (struct kvm_vcpu *vcpu)
 
void kvm_apic_nmi_wd_deliver (struct kvm_vcpu *vcpu)
 
void __kvm_migrate_apic_timer (struct kvm_vcpu *vcpu)
 
void __kvm_migrate_pit_timer (struct kvm_vcpu *vcpu)
 
void __kvm_migrate_timers (struct kvm_vcpu *vcpu)
 
int apic_has_pending_timer (struct kvm_vcpu *vcpu)
 
int kvm_setup_default_irq_routing (struct kvm *kvm)
 
int kvm_setup_empty_irq_routing (struct kvm *kvm)
 
int kvm_irq_delivery_to_apic (struct kvm *kvm, struct kvm_lapic *src, struct kvm_lapic_irq *irq, struct dest_map *dest_map)
 

Macro Definition Documentation

◆ PIC_NUM_PINS

#define PIC_NUM_PINS   16

Definition at line 21 of file irq.h.

◆ SELECT_PIC

#define SELECT_PIC (   irq)     ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)

Definition at line 22 of file irq.h.

Function Documentation

◆ __kvm_migrate_apic_timer()

void __kvm_migrate_apic_timer ( struct kvm_vcpu *  vcpu)

Definition at line 3029 of file lapic.c.

3030 {
3031  struct hrtimer *timer;
3032 
3033  if (!lapic_in_kernel(vcpu) ||
3035  return;
3036 
3037  timer = &vcpu->arch.apic->lapic_timer.timer;
3038  if (hrtimer_cancel(timer))
3039  hrtimer_start_expires(timer, HRTIMER_MODE_ABS_HARD);
3040 }
static bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu)
Definition: lapic.c:148
static bool lapic_in_kernel(struct kvm_vcpu *vcpu)
Definition: lapic.h:186
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __kvm_migrate_pit_timer()

void __kvm_migrate_pit_timer ( struct kvm_vcpu *  vcpu)

Definition at line 218 of file i8254.c.

219 {
220  struct kvm_pit *pit = vcpu->kvm->arch.vpit;
221  struct hrtimer *timer;
222 
223  /* Somewhat arbitrarily make vcpu0 the owner of the PIT. */
224  if (vcpu->vcpu_id || !pit)
225  return;
226 
227  timer = &pit->pit_state.timer;
228  mutex_lock(&pit->pit_state.lock);
229  if (hrtimer_cancel(timer))
230  hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
231  mutex_unlock(&pit->pit_state.lock);
232 }
struct mutex lock
Definition: i8254.h:33
struct hrtimer timer
Definition: i8254.h:31
Definition: i8254.h:40
struct kvm * kvm
Definition: i8254.h:43
struct kvm_kpit_state pit_state
Definition: i8254.h:44
Here is the caller graph for this function:

◆ __kvm_migrate_timers()

void __kvm_migrate_timers ( struct kvm_vcpu *  vcpu)

Definition at line 156 of file irq.c.

157 {
160  static_call_cond(kvm_x86_migrate_timers)(vcpu);
161 }
void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
Definition: i8254.c:218
void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
Definition: lapic.c:3029
Here is the call graph for this function:
Here is the caller graph for this function:

◆ apic_has_pending_timer()

int apic_has_pending_timer ( struct kvm_vcpu *  vcpu)

Definition at line 2752 of file lapic.c.

2753 {
2754  struct kvm_lapic *apic = vcpu->arch.apic;
2755 
2756  if (apic_enabled(apic) && apic_lvt_enabled(apic, APIC_LVTT))
2757  return atomic_read(&apic->lapic_timer.pending);
2758 
2759  return 0;
2760 }
static int apic_lvt_enabled(struct kvm_lapic *apic, int lvt_type)
Definition: lapic.c:538
static int apic_enabled(struct kvm_lapic *apic)
Definition: lapic.c:131
struct kvm_timer lapic_timer
Definition: lapic.h:62
struct kvm_vcpu * vcpu
Definition: lapic.h:64
atomic_t pending
Definition: lapic.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ irqchip_in_kernel()

static int irqchip_in_kernel ( struct kvm *  kvm)
inlinestatic

Definition at line 90 of file irq.h.

91 {
92  int mode = kvm->arch.irqchip_mode;
93 
94  /* Matches smp_wmb() when setting irqchip_mode */
95  smp_rmb();
96  return mode != KVM_IRQCHIP_NONE;
97 }

◆ irqchip_kernel()

static int irqchip_kernel ( struct kvm *  kvm)
inlinestatic

Definition at line 76 of file irq.h.

77 {
78  int mode = kvm->arch.irqchip_mode;
79 
80  /* Matches smp_wmb() when setting irqchip_mode */
81  smp_rmb();
82  return mode == KVM_IRQCHIP_KERNEL;
83 }
Here is the caller graph for this function:

◆ irqchip_split()

static int irqchip_split ( struct kvm *  kvm)
inlinestatic

Definition at line 67 of file irq.h.

68 {
69  int mode = kvm->arch.irqchip_mode;
70 
71  /* Matches smp_wmb() when setting irqchip_mode */
72  smp_rmb();
73  return mode == KVM_IRQCHIP_SPLIT;
74 }
Here is the caller graph for this function:

◆ kvm_apic_nmi_wd_deliver()

void kvm_apic_nmi_wd_deliver ( struct kvm_vcpu *  vcpu)

Definition at line 2782 of file lapic.c.

2783 {
2784  struct kvm_lapic *apic = vcpu->arch.apic;
2785 
2786  if (apic)
2787  kvm_apic_local_deliver(apic, APIC_LVT0);
2788 }
int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type)
Definition: lapic.c:2762
Here is the caller graph for this function:

◆ kvm_inject_apic_timer_irqs()

void kvm_inject_apic_timer_irqs ( struct kvm_vcpu *  vcpu)

Definition at line 2884 of file lapic.c.

2885 {
2886  struct kvm_lapic *apic = vcpu->arch.apic;
2887 
2888  if (atomic_read(&apic->lapic_timer.pending) > 0) {
2890  atomic_set(&apic->lapic_timer.pending, 0);
2891  }
2892 }
static void kvm_apic_inject_pending_timer_irqs(struct kvm_lapic *apic)
Definition: lapic.c:1879
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_inject_pending_timer_irqs()

void kvm_inject_pending_timer_irqs ( struct kvm_vcpu *  vcpu)

Definition at line 148 of file irq.c.

149 {
150  if (lapic_in_kernel(vcpu))
152  if (kvm_xen_timer_enabled(vcpu))
154 }
void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu)
Definition: lapic.c:2884
void kvm_xen_inject_timer_irqs(struct kvm_vcpu *vcpu)
Definition: xen.c:116
static bool kvm_xen_timer_enabled(struct kvm_vcpu *vcpu)
Definition: xen.h:155
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_irq_delivery_to_apic()

int kvm_irq_delivery_to_apic ( struct kvm *  kvm,
struct kvm_lapic src,
struct kvm_lapic_irq *  irq,
struct dest_map dest_map 
)

Definition at line 47 of file irq_comm.c.

49 {
50  int r = -1;
51  struct kvm_vcpu *vcpu, *lowest = NULL;
52  unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
53  unsigned int dest_vcpus = 0;
54 
55  if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
56  return r;
57 
58  if (irq->dest_mode == APIC_DEST_PHYSICAL &&
59  irq->dest_id == 0xff && kvm_lowest_prio_delivery(irq)) {
60  pr_info("apic: phys broadcast and lowest prio\n");
61  irq->delivery_mode = APIC_DM_FIXED;
62  }
63 
64  memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap));
65 
66  kvm_for_each_vcpu(i, vcpu, kvm) {
67  if (!kvm_apic_present(vcpu))
68  continue;
69 
70  if (!kvm_apic_match_dest(vcpu, src, irq->shorthand,
71  irq->dest_id, irq->dest_mode))
72  continue;
73 
74  if (!kvm_lowest_prio_delivery(irq)) {
75  if (r < 0)
76  r = 0;
77  r += kvm_apic_set_irq(vcpu, irq, dest_map);
78  } else if (kvm_apic_sw_enabled(vcpu->arch.apic)) {
80  if (!lowest)
81  lowest = vcpu;
82  else if (kvm_apic_compare_prio(vcpu, lowest) < 0)
83  lowest = vcpu;
84  } else {
85  __set_bit(i, dest_vcpu_bitmap);
86  dest_vcpus++;
87  }
88  }
89  }
90 
91  if (dest_vcpus != 0) {
92  int idx = kvm_vector_to_index(irq->vector, dest_vcpus,
93  dest_vcpu_bitmap, KVM_MAX_VCPUS);
94 
95  lowest = kvm_get_vcpu(kvm, idx);
96  }
97 
98  if (lowest)
99  r = kvm_apic_set_irq(lowest, irq, dest_map);
100 
101  return r;
102 }
bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map)
Definition: lapic.c:1208
int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq, struct dest_map *dest_map)
Definition: lapic.c:823
int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2)
Definition: lapic.c:1432
int kvm_vector_to_index(u32 vector, u32 dest_vcpus, const unsigned long *bitmap, u32 bitmap_size)
Definition: lapic.c:1092
bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, int shorthand, unsigned int dest, int dest_mode)
Definition: lapic.c:1067
static bool kvm_apic_sw_enabled(struct kvm_lapic *apic)
Definition: lapic.h:204
static bool kvm_lowest_prio_delivery(struct kvm_lapic_irq *irq)
Definition: lapic.h:242
static bool kvm_apic_present(struct kvm_vcpu *vcpu)
Definition: lapic.h:211
bool kvm_vector_hashing_enabled(void)
Definition: x86.c:13520
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pic_destroy()

void kvm_pic_destroy ( struct kvm *  kvm)

Definition at line 645 of file i8259.c.

646 {
647  struct kvm_pic *vpic = kvm->arch.vpic;
648 
649  if (!vpic)
650  return;
651 
652  mutex_lock(&kvm->slots_lock);
653  kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_master);
654  kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_slave);
655  kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_elcr);
656  mutex_unlock(&kvm->slots_lock);
657 
658  kvm->arch.vpic = NULL;
659  kfree(vpic);
660 }
int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, struct kvm_io_device *dev)
Definition: kvm_main.c:5941
Definition: irq.h:49
struct kvm_io_device dev_master
Definition: irq.h:56
struct kvm_io_device dev_elcr
Definition: irq.h:58
struct kvm_io_device dev_slave
Definition: irq.h:57
struct kvm * kvm
Definition: irq.h:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pic_init()

int kvm_pic_init ( struct kvm *  kvm)

Definition at line 590 of file i8259.c.

591 {
592  struct kvm_pic *s;
593  int ret;
594 
595  s = kzalloc(sizeof(struct kvm_pic), GFP_KERNEL_ACCOUNT);
596  if (!s)
597  return -ENOMEM;
598  spin_lock_init(&s->lock);
599  s->kvm = kvm;
600  s->pics[0].elcr_mask = 0xf8;
601  s->pics[1].elcr_mask = 0xde;
602  s->pics[0].pics_state = s;
603  s->pics[1].pics_state = s;
604 
605  /*
606  * Initialize PIO device
607  */
611  mutex_lock(&kvm->slots_lock);
612  ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0x20, 2,
613  &s->dev_master);
614  if (ret < 0)
615  goto fail_unlock;
616 
617  ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0xa0, 2, &s->dev_slave);
618  if (ret < 0)
619  goto fail_unreg_2;
620 
621  ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0x4d0, 2, &s->dev_elcr);
622  if (ret < 0)
623  goto fail_unreg_1;
624 
625  mutex_unlock(&kvm->slots_lock);
626 
627  kvm->arch.vpic = s;
628 
629  return 0;
630 
631 fail_unreg_1:
632  kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &s->dev_slave);
633 
634 fail_unreg_2:
635  kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &s->dev_master);
636 
637 fail_unlock:
638  mutex_unlock(&kvm->slots_lock);
639 
640  kfree(s);
641 
642  return ret;
643 }
static const struct kvm_io_device_ops picdev_elcr_ops
Definition: i8259.c:585
static const struct kvm_io_device_ops picdev_master_ops
Definition: i8259.c:575
static const struct kvm_io_device_ops picdev_slave_ops
Definition: i8259.c:580
static void kvm_iodevice_init(struct kvm_io_device *dev, const struct kvm_io_device_ops *ops)
Definition: iodev.h:36
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, struct kvm_io_device *dev)
Definition: kvm_main.c:5897
struct kvm_pic * pics_state
Definition: irq.h:46
u8 elcr_mask
Definition: irq.h:44
struct kvm_kpic_state pics[2]
Definition: irq.h:54
spinlock_t lock
Definition: irq.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pic_read_irq()

int kvm_pic_read_irq ( struct kvm *  kvm)

Definition at line 236 of file i8259.c.

237 {
238  int irq, irq2, intno;
239  struct kvm_pic *s = kvm->arch.vpic;
240 
241  s->output = 0;
242 
243  pic_lock(s);
244  irq = pic_get_irq(&s->pics[0]);
245  if (irq >= 0) {
246  pic_intack(&s->pics[0], irq);
247  if (irq == 2) {
248  irq2 = pic_get_irq(&s->pics[1]);
249  if (irq2 >= 0)
250  pic_intack(&s->pics[1], irq2);
251  else
252  /*
253  * spurious IRQ on slave controller
254  */
255  irq2 = 7;
256  intno = s->pics[1].irq_base + irq2;
257  } else
258  intno = s->pics[0].irq_base + irq;
259  } else {
260  /*
261  * spurious IRQ on host controller
262  */
263  irq = 7;
264  intno = s->pics[0].irq_base + irq;
265  }
266  pic_update_irq(s);
267  pic_unlock(s);
268 
269  return intno;
270 }
static void pic_intack(struct kvm_kpic_state *s, int irq)
Definition: i8259.c:219
static void pic_unlock(struct kvm_pic *s) __releases(&s -> lock)
Definition: i8259.c:50
static int pic_get_irq(struct kvm_kpic_state *s)
Definition: i8259.c:135
static void pic_lock(struct kvm_pic *s) __acquires(&s -> lock)
Definition: i8259.c:44
static void pic_update_irq(struct kvm_pic *s)
Definition: i8259.c:165
u8 irq_base
Definition: irq.h:34
int output
Definition: irq.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pic_update_irq()

void kvm_pic_update_irq ( struct kvm_pic s)

Definition at line 181 of file i8259.c.

182 {
183  pic_lock(s);
184  pic_update_irq(s);
185  pic_unlock(s);
186 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_setup_default_irq_routing()

int kvm_setup_default_irq_routing ( struct kvm *  kvm)

Definition at line 392 of file irq_comm.c.

393 {
395  ARRAY_SIZE(default_routing), 0);
396 }
static const struct kvm_irq_routing_entry default_routing[]
Definition: irq_comm.c:377
int kvm_set_irq_routing(struct kvm *kvm, const struct kvm_irq_routing_entry *ue, unsigned nr, unsigned flags)
Definition: irqchip.c:168
Here is the caller graph for this function:

◆ kvm_setup_empty_irq_routing()

int kvm_setup_empty_irq_routing ( struct kvm *  kvm)

Definition at line 400 of file irq_comm.c.

401 {
402  return kvm_set_irq_routing(kvm, empty_routing, 0, 0);
403 }
static const struct kvm_irq_routing_entry empty_routing[]
Definition: irq_comm.c:398
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pic_in_kernel()

static int pic_in_kernel ( struct kvm *  kvm)
inlinestatic

Definition at line 85 of file irq.h.

86 {
87  return irqchip_kernel(kvm);
88 }
static int irqchip_kernel(struct kvm *kvm)
Definition: irq.h:76
Here is the call graph for this function:
Here is the caller graph for this function: