From patchwork Fri Apr 24 05:27:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47495 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ECFE320553 for ; Fri, 24 Apr 2015 05:30:29 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf9142907wgt.1 for ; Thu, 23 Apr 2015 22:30:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=gqjTTloFc3yXaWXWm3jWMP0t3Bu2vS4ZuBhGaBE6/Hg=; b=GoFmY3Nrk4opUd0DgfRmDe0erIpYwCcEm8z92W3cY6W/+bkZF5fhMzPqoGwYUwap8u kzuMV4mTCop1rq3NOcVhZpzX7lPWktSHTX0/Ohx7cU/J1+sMbbv9MCdghGlgHV/1NrPb wel5ALvGfgoG8M8OHTZiUaf6K2dHQ+6ABCvFnxTNh3L6b0dfBHtdijHbtTsQRL3y4Zgi 8SEt4sPmBrK+0o/nQaZT1ANkE5HjtTaCtKmlwaW3gYFw+CtOwesYBxGXSLEAJztc7AQd yFD48sZzvVTf67WuUbFIHz3n8LIgRf2A7YfeZgp79jz6EJfz7vhFFlEyieyozUgW2g/U xueQ== X-Gm-Message-State: ALoCoQmijAlaMAHP0EKXgvhnFib+mkTGJocs0KOD7i38ssyHU72U2IIpBKR1e6MFcRyCL32GZzo8 X-Received: by 10.112.203.168 with SMTP id kr8mr3206348lbc.10.1429853429258; Thu, 23 Apr 2015 22:30:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.169 with SMTP id x9ls449641lal.92.gmail; Thu, 23 Apr 2015 22:30:29 -0700 (PDT) X-Received: by 10.112.135.131 with SMTP id ps3mr5419913lbb.84.1429853428979; Thu, 23 Apr 2015 22:30:28 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id jj4si7453245lbb.174.2015.04.23.22.30.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:30:28 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by laat2 with SMTP id t2so27541920laa.1 for ; Thu, 23 Apr 2015 22:30:28 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr5448353lbc.86.1429853428834; Thu, 23 Apr 2015 22:30:28 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp977203lbt; Thu, 23 Apr 2015 22:30:27 -0700 (PDT) X-Received: by 10.70.55.165 with SMTP id t5mr2942938pdp.102.1429853426835; Thu, 23 Apr 2015 22:30:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id at5si15744662pbc.170.2015.04.23.22.30.25; Thu, 23 Apr 2015 22:30:26 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754508AbbDXFaU (ORCPT + 2 others); Fri, 24 Apr 2015 01:30:20 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:33948 "EHLO mail-ob0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754479AbbDXFaR (ORCPT ); Fri, 24 Apr 2015 01:30:17 -0400 Received: by obfe9 with SMTP id e9so30174855obf.1 for ; Thu, 23 Apr 2015 22:30:17 -0700 (PDT) X-Received: by 10.202.220.135 with SMTP id t129mr5429175oig.115.1429853417301; Thu, 23 Apr 2015 22:30:17 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id c3sm5241584obo.5.2015.04.23.22.30.15 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:30:16 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.12.y stable 10/63] ARM: KVM: Allow creating the VGIC after VCPUs Date: Fri, 24 Apr 2015 13:27:08 +0800 Message-Id: <1429853281-6136-11-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> References: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Christoffer Dall commit e1ba0207a1b3714bb3f000e506285ae5123cdfa7 upstream. Rework the VGIC initialization slightly to allow initialization of the vgic cpu-specific state even if the irqchip (the VGIC) hasn't been created by user space yet. This is safe, because the vgic data structures are already allocated when the CPU is allocated if VGIC support is compiled into the kernel. Further, the init process does not depend on any other information and the sacrifice is a slight performance degradation for creating VMs in the no-VGIC case. The reason is that the new device control API doesn't mandate creating the VGIC before creating the VCPU and it is unreasonable to require user space to create the VGIC before creating the VCPUs. At the same time move the irqchip_in_kernel check out of kvm_vcpu_first_run_init and into the init function to make the per-vcpu and global init functions symmetric and add comments on the exported functions making it a bit easier to understand the init flow by only looking at vgic.c. Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/kvm/arm.c | 7 ++++--- virt/kvm/arm/vgic.c | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 847d280..9cf0778 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -463,6 +463,8 @@ static void update_vttbr(struct kvm *kvm) static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) { + int ret; + if (likely(vcpu->arch.has_run_once)) return 0; @@ -472,9 +474,8 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) * Initialize the VGIC before running a vcpu the first time on * this VM. */ - if (irqchip_in_kernel(vcpu->kvm) && - unlikely(!vgic_initialized(vcpu->kvm))) { - int ret = kvm_vgic_init(vcpu->kvm); + if (unlikely(!vgic_initialized(vcpu->kvm))) { + ret = kvm_vgic_init(vcpu->kvm); if (ret) return ret; } diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 14d7b51..f4e6322 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1244,15 +1244,19 @@ static irqreturn_t vgic_maintenance_handler(int irq, void *data) return IRQ_HANDLED; } +/** + * kvm_vgic_vcpu_init - Initialize per-vcpu VGIC state + * @vcpu: pointer to the vcpu struct + * + * Initialize the vgic_cpu struct and vgic_dist struct fields pertaining to + * this vcpu and enable the VGIC for this VCPU + */ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; struct vgic_dist *dist = &vcpu->kvm->arch.vgic; int i; - if (!irqchip_in_kernel(vcpu->kvm)) - return 0; - if (vcpu->vcpu_id >= VGIC_MAX_CPUS) return -EBUSY; @@ -1384,10 +1388,22 @@ out: return ret; } +/** + * kvm_vgic_init - Initialize global VGIC state before running any VCPUs + * @kvm: pointer to the kvm struct + * + * Map the virtual CPU interface into the VM before running any VCPUs. We + * can't do this at creation time, because user space must first set the + * virtual CPU interface address in the guest physical address space. Also + * initialize the ITARGETSRn regs to 0 on the emulated distributor. + */ int kvm_vgic_init(struct kvm *kvm) { int ret = 0, i; + if (!irqchip_in_kernel(kvm)) + return 0; + mutex_lock(&kvm->lock); if (vgic_initialized(kvm))