aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/kvm/arm.c
diff options
context:
space:
mode:
authorChristoffer Dall <cdall@cs.columbia.edu>2013-01-20 18:28:08 -0500
committerChristoffer Dall <c.dall@virtualopensystems.com>2013-01-23 13:29:12 -0500
commit86ce85352f0da7e1431ad8efcb04323819a620e7 (patch)
tree0f5a0a971b0092c9cfd74659254f76a4c7117294 /arch/arm/kvm/arm.c
parentd5d8184d35c990b1324d9b30bcd0e4e8aa08f56d (diff)
KVM: ARM: Inject IRQs and FIQs from userspace
All interrupt injection is now based on the VM ioctl KVM_IRQ_LINE. This works semantically well for the GIC as we in fact raise/lower a line on a machine component (the gic). The IOCTL uses the follwing struct. struct kvm_irq_level { union { __u32 irq; /* GSI */ __s32 status; /* not used for KVM_IRQ_LEVEL */ }; __u32 level; /* 0 or 1 */ }; ARM can signal an interrupt either at the CPU level, or at the in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to use PPIs designated for specific cpus. The irq field is interpreted like this:  bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 | field: | irq_type | vcpu_index | irq_number | The irq_type field has the following values: - irq_type[0]: out-of-kernel GIC: irq_number 0 is IRQ, irq_number 1 is FIQ - irq_type[1]: in-kernel GIC: SPI, irq_number between 32 and 1019 (incl.) (the vcpu_index field is ignored) - irq_type[2]: in-kernel GIC: PPI, irq_number between 16 and 31 (incl.) The irq_number thus corresponds to the irq ID in as in the GICv2 specs. This is documented in Documentation/kvm/api.txt. Reviewed-by: Will Deacon <will.deacon@arm.com> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
Diffstat (limited to 'arch/arm/kvm/arm.c')
-rw-r--r--arch/arm/kvm/arm.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index d810afb6cb84..2101152c3a4b 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -24,6 +24,7 @@
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/mman.h> 25#include <linux/mman.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/kvm.h>
27#include <trace/events/kvm.h> 28#include <trace/events/kvm.h>
28 29
29#define CREATE_TRACE_POINTS 30#define CREATE_TRACE_POINTS
@@ -284,6 +285,7 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
284 285
285void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 286void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
286{ 287{
288 vcpu->cpu = cpu;
287} 289}
288 290
289void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) 291void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
@@ -319,6 +321,69 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
319 return -EINVAL; 321 return -EINVAL;
320} 322}
321 323
324static int vcpu_interrupt_line(struct kvm_vcpu *vcpu, int number, bool level)
325{
326 int bit_index;
327 bool set;
328 unsigned long *ptr;
329
330 if (number == KVM_ARM_IRQ_CPU_IRQ)
331 bit_index = __ffs(HCR_VI);
332 else /* KVM_ARM_IRQ_CPU_FIQ */
333 bit_index = __ffs(HCR_VF);
334
335 ptr = (unsigned long *)&vcpu->arch.irq_lines;
336 if (level)
337 set = test_and_set_bit(bit_index, ptr);
338 else
339 set = test_and_clear_bit(bit_index, ptr);
340
341 /*
342 * If we didn't change anything, no need to wake up or kick other CPUs
343 */
344 if (set == level)
345 return 0;
346
347 /*
348 * The vcpu irq_lines field was updated, wake up sleeping VCPUs and
349 * trigger a world-switch round on the running physical CPU to set the
350 * virtual IRQ/FIQ fields in the HCR appropriately.
351 */
352 kvm_vcpu_kick(vcpu);
353
354 return 0;
355}
356
357int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level)
358{
359 u32 irq = irq_level->irq;
360 unsigned int irq_type, vcpu_idx, irq_num;
361 int nrcpus = atomic_read(&kvm->online_vcpus);
362 struct kvm_vcpu *vcpu = NULL;
363 bool level = irq_level->level;
364
365 irq_type = (irq >> KVM_ARM_IRQ_TYPE_SHIFT) & KVM_ARM_IRQ_TYPE_MASK;
366 vcpu_idx = (irq >> KVM_ARM_IRQ_VCPU_SHIFT) & KVM_ARM_IRQ_VCPU_MASK;
367 irq_num = (irq >> KVM_ARM_IRQ_NUM_SHIFT) & KVM_ARM_IRQ_NUM_MASK;
368
369 trace_kvm_irq_line(irq_type, vcpu_idx, irq_num, irq_level->level);
370
371 if (irq_type != KVM_ARM_IRQ_TYPE_CPU)
372 return -EINVAL;
373
374 if (vcpu_idx >= nrcpus)
375 return -EINVAL;
376
377 vcpu = kvm_get_vcpu(kvm, vcpu_idx);
378 if (!vcpu)
379 return -EINVAL;
380
381 if (irq_num > KVM_ARM_IRQ_CPU_FIQ)
382 return -EINVAL;
383
384 return vcpu_interrupt_line(vcpu, irq_num, level);
385}
386
322long kvm_arch_vcpu_ioctl(struct file *filp, 387long kvm_arch_vcpu_ioctl(struct file *filp,
323 unsigned int ioctl, unsigned long arg) 388 unsigned int ioctl, unsigned long arg)
324{ 389{