From patchwork Mon Oct 1 09:07:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1529831 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id ED4FCDF24C for ; Mon, 1 Oct 2012 09:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752399Ab2JAJHn (ORCPT ); Mon, 1 Oct 2012 05:07:43 -0400 Received: from mail-qa0-f46.google.com ([209.85.216.46]:35347 "EHLO mail-qa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752305Ab2JAJHm (ORCPT ); Mon, 1 Oct 2012 05:07:42 -0400 Received: by mail-qa0-f46.google.com with SMTP id c26so1404237qad.19 for ; Mon, 01 Oct 2012 02:07:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=pcid+ZtccbuhLNOJbB4s2agPdkGzPWB/m0SzZ8Vzbik=; b=M14o14heu1+2EDr68VW/oSYom0a63ovXSGsBIE56jApzyMvjngvOe+u4yWvZsZ+OLU q5fhskZRrtAkqSWPVp6nit0BcXvWbOq/xAxFqnVbZJxzZO7kkql8URIMi2N3XDMWGgm6 PR9gy4vBDyzNRZ8Yl38KKwdR9lu2hoK6S29jXtnZy+XjmVI5TlQN+EiaVYZ+nBCU1I54 oFzUXoh+PeXNA/YG5hwlKDGH7My/bSA+FlBM3eAcr5Tu+wlM+MTmLZnkIMwNeuNV2+0r 2/+SxCYWLnjg7tBX5qhqWg8GR4y5u/FKfrIVLBs9kmvFIdjCfWmjjhQnBglJZ9DYglWI mrpw== Received: by 10.224.77.81 with SMTP id f17mr18163118qak.66.1349082461933; Mon, 01 Oct 2012 02:07:41 -0700 (PDT) Received: from [127.0.1.1] (pool-72-80-83-148.nycmny.fios.verizon.net. [72.80.83.148]) by mx.google.com with ESMTPS id ep8sm23791792qab.22.2012.10.01.02.07.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Oct 2012 02:07:41 -0700 (PDT) Subject: [PATCH v2 01/10] ARM: KVM: Keep track of currently running vcpus To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu From: Christoffer Dall Cc: Marc Zyngier Date: Mon, 01 Oct 2012 05:07:40 -0400 Message-ID: <20121001090740.49038.4761.stgit@ubuntu> In-Reply-To: <20121001090716.49038.90056.stgit@ubuntu> References: <20121001090716.49038.90056.stgit@ubuntu> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQl//ZmD7AHwYrGvdeiKetat+ACjCq/p1TSKD4WIUI+hNu6AE8SEhlqlLDa/uqpwg6EBhmOW Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marc Zyngier 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 tun in kvm_arch_vcpu_ioctl_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. - 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 Signed-off-by: Christoffer Dall --- arch/arm/include/asm/kvm_host.h | 9 +++++++++ arch/arm/kvm/arm.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index e4b5352..69a8680 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -151,4 +151,13 @@ 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); + +int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); +unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu); +struct kvm_one_reg; +int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); +int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); #endif /* __ARM_KVM_HOST_H__ */ diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 50e9585..8764dd0 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -53,11 +53,38 @@ static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); static struct vfp_hard_struct __percpu *kvm_host_vfp_state; static unsigned long hyp_default_vectors; +/* 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; static 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; @@ -296,10 +323,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) cpumask_clear_cpu(cpu, &vcpu->arch.require_dcache_flush); flush_cache_all(); /* We'd really want v7_flush_dcache_all() */ } + + kvm_arm_set_running_vcpu(vcpu); } void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { + kvm_arm_set_running_vcpu(NULL); } int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,