On 18/08/12 03:58, Christoffer Dall wrote: > On Thu, Jul 5, 2012 at 11:28 AM, Marc Zyngier <marc.zyngier@xxxxxxx> wrote: >> When an interrupt occurs for the guest, it is sometimes necessary >> to find out which vcpu was running at that point. > > s/was/is/ ? > >> >> Keep track of which vcpu is being tun in kvm_arch_vcpu_ioctl_run(), > > s/tun/run/ > >> and allow the data to be retrived 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-preemptable context. > > was last run you mean - if you can call this function it's not run, > strictly speaking > > or just say: the vcpu loaded at this point, eh maybe not. > >> - kvm_arm_get_running_vcpus(): returns the per-CPU variable holding >> the the running vcpus, useable for per-CPU interrupts. >> >> Signed-off-by: Marc Zyngier <marc.zyngier@xxxxxxx> >> --- >> arch/arm/include/asm/kvm_host.h | 3 +++ >> arch/arm/kvm/arm.c | 29 +++++++++++++++++++++++++++++ >> 2 files changed, 32 insertions(+) >> >> diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h >> index 9d0cc83..91be029 100644 >> --- a/arch/arm/include/asm/kvm_host.h >> +++ b/arch/arm/include/asm/kvm_host.h >> @@ -156,4 +156,7 @@ static inline int kvm_test_age_hva(struct kvm *kvm, unsigned long hva) >> return 0; >> } >> >> +struct kvm_vcpu *kvm_arm_get_running_vcpu(void); >> +struct kvm_vcpu __percpu **kvm_get_running_vcpus(void); >> + >> #endif /* __ARM_KVM_HOST_H__ */ >> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c >> index 44691e1..8bb53cb 100644 >> --- a/arch/arm/kvm/arm.c >> +++ b/arch/arm/kvm/arm.c >> @@ -46,11 +46,38 @@ >> >> static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); >> >> +/* Per-CPU variable containing the currently running vcpu. */ >> +static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu); >> + >> /* The VMID used in the VTTBR */ >> static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); >> static u8 kvm_next_vmid; >> DEFINE_SPINLOCK(kvm_vmid_lock); >> >> +static void kvm_arm_set_running_vcpu(struct kvm_vcpu *vcpu) >> +{ >> + BUG_ON(preemptible()); >> + __get_cpu_var(kvm_arm_running_vcpu) = vcpu; >> +} >> + >> +/** >> + * kvm_arm_get_running_vcpu - get the vcpu running on the current CPU. >> + * Must be called from non-preemptible context >> + */ >> +struct kvm_vcpu *kvm_arm_get_running_vcpu(void) >> +{ >> + BUG_ON(preemptible()); >> + return __get_cpu_var(kvm_arm_running_vcpu); >> +} >> + >> +/** >> + * kvm_arm_get_running_vcpus - get the per-CPU array on currently running vcpus. >> + */ >> +struct kvm_vcpu __percpu **kvm_get_running_vcpus(void) >> +{ >> + return &kvm_arm_running_vcpu; >> +} >> + >> int kvm_arch_hardware_enable(void *garbage) >> { >> return 0; >> @@ -576,9 +603,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) >> trace_kvm_entry(vcpu->arch.regs.pc); >> kvm_guest_enter(); >> vcpu->mode = IN_GUEST_MODE; >> + kvm_arm_set_running_vcpu(vcpu); >> >> ret = __kvm_vcpu_run(vcpu); >> >> + kvm_arm_set_running_vcpu(NULL); > > this made your function quite useless, but I guess you know that > because of the fixup you posted :) Useless? If you put that back in the context of how the code was structured two months ago (circa v9), it makes a lot more sense. Interrupts would have already been dealt with before returning from __kvm_vcpu_run(). These days, this code has been moved to kvm_arch_vcpu_load() and kvm_arch_vcpu_put(). > with the fixup it all looks ok to me. > >> vcpu->mode = OUTSIDE_GUEST_MODE; >> vcpu->stat.exits++; >> kvm_guest_exit(); >> -- >> 1.7.10.3 >> >> > -- Jazz is not dead. It just smells funny... _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm