aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
authorMarc Zyngier <marc.zyngier@arm.com>2013-01-21 19:36:11 -0500
committerMarc Zyngier <marc.zyngier@arm.com>2013-02-11 13:58:48 -0500
commit1638a12d4ee519ed397f4b9e6c088faed155d164 (patch)
tree7317fd8e6c91eccd62d9ad5d581037f868e65256 /arch/arm
parent3401d54696f992edf036f00f46c8c399d1b75c2a (diff)
ARM: KVM: Keep track of currently running vcpus
When an interrupt occurs for the guest, it is sometimes necessary to find out which vcpu was running at that point. Keep track of which vcpu is being run in kvm_arch_vcpu_ioctl_run(), and allow the data to be retrieved using either: - kvm_arm_get_running_vcpu(): returns the vcpu running at this point on the current CPU. Can only be used in a non-preemptible context. - kvm_arm_get_running_vcpus(): returns the per-CPU variable holding the running vcpus, usable for per-CPU interrupts. Reviewed-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/include/asm/kvm_host.h10
-rw-r--r--arch/arm/kvm/arm.c30
2 files changed, 40 insertions, 0 deletions
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 98b4d1a72923..fc161de21ea2 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -158,4 +158,14 @@ static inline int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
158{ 158{
159 return 0; 159 return 0;
160} 160}
161
162struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
163struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
164
165int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
166unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu);
167struct kvm_one_reg;
168int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
169int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
170
161#endif /* __ARM_KVM_HOST_H__ */ 171#endif /* __ARM_KVM_HOST_H__ */
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 523f77a44e44..0cf144f95945 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -54,11 +54,38 @@ static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
54static struct vfp_hard_struct __percpu *kvm_host_vfp_state; 54static struct vfp_hard_struct __percpu *kvm_host_vfp_state;
55static unsigned long hyp_default_vectors; 55static unsigned long hyp_default_vectors;
56 56
57/* Per-CPU variable containing the currently running vcpu. */
58static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
59
57/* The VMID used in the VTTBR */ 60/* The VMID used in the VTTBR */
58static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); 61static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
59static u8 kvm_next_vmid; 62static u8 kvm_next_vmid;
60static DEFINE_SPINLOCK(kvm_vmid_lock); 63static DEFINE_SPINLOCK(kvm_vmid_lock);
61 64
65static void kvm_arm_set_running_vcpu(struct kvm_vcpu *vcpu)
66{
67 BUG_ON(preemptible());
68 __get_cpu_var(kvm_arm_running_vcpu) = vcpu;
69}
70
71/**
72 * kvm_arm_get_running_vcpu - get the vcpu running on the current CPU.
73 * Must be called from non-preemptible context
74 */
75struct kvm_vcpu *kvm_arm_get_running_vcpu(void)
76{
77 BUG_ON(preemptible());
78 return __get_cpu_var(kvm_arm_running_vcpu);
79}
80
81/**
82 * kvm_arm_get_running_vcpus - get the per-CPU array of currently running vcpus.
83 */
84struct kvm_vcpu __percpu **kvm_get_running_vcpus(void)
85{
86 return &kvm_arm_running_vcpu;
87}
88
62int kvm_arch_hardware_enable(void *garbage) 89int kvm_arch_hardware_enable(void *garbage)
63{ 90{
64 return 0; 91 return 0;
@@ -310,10 +337,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
310 */ 337 */
311 if (cpumask_test_and_clear_cpu(cpu, &vcpu->arch.require_dcache_flush)) 338 if (cpumask_test_and_clear_cpu(cpu, &vcpu->arch.require_dcache_flush))
312 flush_cache_all(); /* We'd really want v7_flush_dcache_all() */ 339 flush_cache_all(); /* We'd really want v7_flush_dcache_all() */
340
341 kvm_arm_set_running_vcpu(vcpu);
313} 342}
314 343
315void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) 344void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
316{ 345{
346 kvm_arm_set_running_vcpu(NULL);
317} 347}
318 348
319int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 349int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,