From patchwork Thu Dec 4 15:02:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 41938 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2656D25E8C for ; Thu, 4 Dec 2014 15:04:19 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf11185965eek.1 for ; Thu, 04 Dec 2014 07:04:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=WZleLRjnYMQDVrC1ZibMDySVWD2BJg1EyG2YwXD7FfA=; b=E37V895yND8iAvxFiLAhaw1TsxccNaISP9CddavtPyfcB5qZNp6JL2bS7i3izT2qGr q8tpZ6gyG+jlaD0mf3dDUzrv74y3LWckk91d9YgXlzVkMjcmeXO3onRTpFU//DmnFSN1 bD+zbAGxNoK1E6871xYLq0FykGesxZ14xZ9laKIPZdp/1KUG0sQRklIhVR7LfILr100n 3Lwtpk/VVFBxfUSlexm23q2jEtuYQmJxBpWnaxEEQhak9dMIknZ7weKwQDWYyVJxqwnC 69o8MMJg8csXKdU9Y4vQMtH71xu2ZStdVVN0HmpChZ9v5znpWnHWN/zA5WzKKKKDQ/G/ l08g== X-Gm-Message-State: ALoCoQmUqvF32nYA9fdIOjyIvFi8Zkn33TINE6zM8AZemctkoKv2TNMdBGqsnj5P8EacbVTg0cI2 X-Received: by 10.180.89.211 with SMTP id bq19mr12427400wib.4.1417705458396; Thu, 04 Dec 2014 07:04:18 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.116.48 with SMTP id jt16ls271024lab.44.gmail; Thu, 04 Dec 2014 07:04:18 -0800 (PST) X-Received: by 10.112.146.37 with SMTP id sz5mr9913563lbb.27.1417705458151; Thu, 04 Dec 2014 07:04:18 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id j1si26176500lah.68.2014.12.04.07.04.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Dec 2014 07:04:18 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ms9so14471292lab.10 for ; Thu, 04 Dec 2014 07:04:18 -0800 (PST) X-Received: by 10.152.43.12 with SMTP id s12mr9684143lal.67.1417705458027; Thu, 04 Dec 2014 07:04:18 -0800 (PST) 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.184.201 with SMTP id ew9csp50323lbc; Thu, 4 Dec 2014 07:04:16 -0800 (PST) X-Received: by 10.70.128.80 with SMTP id nm16mr6253283pdb.1.1417705456232; Thu, 04 Dec 2014 07:04:16 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id xy2si10252813pbb.222.2014.12.04.07.04.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Dec 2014 07:04:16 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XwXvq-0003Re-2U; Thu, 04 Dec 2014 15:03:02 +0000 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XwXvm-0003Jd-Dp for linux-arm-kernel@lists.infradead.org; Thu, 04 Dec 2014 15:02:59 +0000 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XwXvE-0000CW-Fj; Thu, 04 Dec 2014 15:02:24 +0000 From: Peter Maydell To: kvmarm@lists.cs.columbia.edu Subject: [PATCH] vgic: move reset initialization into vgic_init_maps() Date: Thu, 4 Dec 2014 15:02:24 +0000 Message-Id: <1417705344-747-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141204_070258_668393_8B534F38 X-CRM114-Status: GOOD ( 15.21 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: linux-arm-kernel@lists.infradead.org, Marc Zyngier , kvm@vger.kernel.org, Christoffer Dall X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@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.51 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 VGIC initialization currently happens in three phases: (1) kvm_vgic_create() (triggered by userspace GIC creation) (2) vgic_init_maps() (triggered by userspace GIC register read/write requests, or from kvm_vgic_init() if not already run) (3) kvm_vgic_init() (triggered by first VM run) We were doing initialization of some state to correspond with the state of a freshly-reset GIC in kvm_vgic_init(); this is too late, since it will overwrite changes made by userspace using the register access APIs before the VM is run. Move this initialization earlier, into the vgic_init_maps() phase. This fixes a bug where QEMU could successfully restore a saved VM state snapshot into a VM that had already been run, but could not restore it "from cold" using the -loadvm command line option (the symptoms being that the restored VM would run but interrupts were ignored). Signed-off-by: Peter Maydell --- You could make a good argument for renaming vgic_init_maps() and kvm_vgic_init() (eg vgic_init() and vgic_first_run() ?)... virt/kvm/arm/vgic.c | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 3aaca49..d2bc745 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1726,39 +1726,14 @@ static int vgic_vcpu_init_maps(struct kvm_vcpu *vcpu, int nr_irqs) int sz = (nr_irqs - VGIC_NR_PRIVATE_IRQS) / 8; vgic_cpu->pending_shared = kzalloc(sz, GFP_KERNEL); - vgic_cpu->vgic_irq_lr_map = kzalloc(nr_irqs, GFP_KERNEL); + vgic_cpu->vgic_irq_lr_map = kmalloc(nr_irqs, GFP_KERNEL); if (!vgic_cpu->pending_shared || !vgic_cpu->vgic_irq_lr_map) { kvm_vgic_vcpu_destroy(vcpu); return -ENOMEM; } - return 0; -} - -/** - * 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 - */ -static void 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; - - for (i = 0; i < dist->nr_irqs; i++) { - if (i < VGIC_NR_PPIS) - vgic_bitmap_set_irq_val(&dist->irq_enabled, - vcpu->vcpu_id, i, 1); - if (i < VGIC_NR_PRIVATE_IRQS) - vgic_bitmap_set_irq_val(&dist->irq_cfg, - vcpu->vcpu_id, i, VGIC_CFG_EDGE); - - vgic_cpu->vgic_irq_lr_map[i] = LR_EMPTY; - } + memset(vgic_cpu->vgic_irq_lr_map, LR_EMPTY, nr_irqs); /* * Store the number of LRs per vcpu, so we don't have to go @@ -1767,7 +1742,7 @@ static void kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) */ vgic_cpu->nr_lr = vgic->nr_lr; - vgic_enable(vcpu); + return 0; } void kvm_vgic_destroy(struct kvm *kvm) @@ -1865,11 +1840,23 @@ static int vgic_init_maps(struct kvm *kvm) kvm_err("VGIC: Failed to allocate vcpu memory\n"); break; } + for (i = 0; i < dist->nr_irqs; i++) { + if (i < VGIC_NR_PPIS) + vgic_bitmap_set_irq_val(&dist->irq_enabled, + vcpu->vcpu_id, i, 1); + if (i < VGIC_NR_PRIVATE_IRQS) + vgic_bitmap_set_irq_val(&dist->irq_cfg, + vcpu->vcpu_id, i, + VGIC_CFG_EDGE); + } } for (i = VGIC_NR_PRIVATE_IRQS; i < dist->nr_irqs; i += 4) vgic_set_target_reg(kvm, 0, i); + kvm_for_each_vcpu(i, vcpu, kvm) + vgic_enable(vcpu); + out: if (ret) kvm_vgic_destroy(kvm); @@ -1888,8 +1875,7 @@ out: */ int kvm_vgic_init(struct kvm *kvm) { - struct kvm_vcpu *vcpu; - int ret = 0, i; + int ret = 0; if (!irqchip_in_kernel(kvm)) return 0; @@ -1920,9 +1906,6 @@ int kvm_vgic_init(struct kvm *kvm) goto out; } - kvm_for_each_vcpu(i, vcpu, kvm) - kvm_vgic_vcpu_init(vcpu); - kvm->arch.vgic.ready = true; out: if (ret)