From patchwork Tue Dec 9 15:44:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 5463571 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4E1ECBEEBA for ; Tue, 9 Dec 2014 15:43:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7533F200EC for ; Tue, 9 Dec 2014 15:43:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 854B720155 for ; Tue, 9 Dec 2014 15:43:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757350AbaLIPnY (ORCPT ); Tue, 9 Dec 2014 10:43:24 -0500 Received: from mail-la0-f50.google.com ([209.85.215.50]:51207 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757236AbaLIPnW (ORCPT ); Tue, 9 Dec 2014 10:43:22 -0500 Received: by mail-la0-f50.google.com with SMTP id pn19so734518lab.37 for ; Tue, 09 Dec 2014 07:43:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r0DV2SggC0urV2iAqMxexjHmMnGvR/PBHvICZgRrtRM=; b=KrjcYFtModvXnEhWrc+4RhAD1ogyaIDd9j7phDPC4ZY7V+nl/sozGp1ohzff+4MmVR xY9/A2FdcvKKfl4URODV89jxra81Jt8WwhKfgnBXP2PvX7E/SQSN2xHst5ml8FdYUd3O 2xBmM0jtUJmaEtGI/zgCKabKklwNFL7yUNC2eU3zB5QGbRtsVot7pA4TM7oH0S2v1DeQ /rdoeC9xJKKPaOHynlC0o490aI8SmZW8hbteszJXv2PbAqb6/J2gkurMFpZmxOWIY82K xG0HOBdiAV2P4V8wIyN/4iBjPYXLsWBYNUiu+te5nfc/8xMWPp8phChOMfjmrq+DKpJJ TuWQ== X-Gm-Message-State: ALoCoQnIaNTbEztJlgxA6ydIIvSYa/7iw3kqxurbhFfnaSkA1I0j4M0XScJuCjso1VdCLwgidk5q X-Received: by 10.112.56.134 with SMTP id a6mr22584475lbq.25.1418139801530; Tue, 09 Dec 2014 07:43:21 -0800 (PST) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id i2sm180810lae.40.2014.12.09.07.43.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Dec 2014 07:43:20 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Christoffer Dall Subject: [PATCH 5/5] arm/arm64: KVM: Initialize the vgic on-demand when injecting IRQs Date: Tue, 9 Dec 2014 16:44:04 +0100 Message-Id: <1418139844-27892-6-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty In-Reply-To: <1418139844-27892-1-git-send-email-christoffer.dall@linaro.org> References: <1418139844-27892-1-git-send-email-christoffer.dall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Userspace assumes that it can wire up IRQ injections after having created all VCPUs and after having created the VGIC, but potentially before starting the first VCPU. This can currently lead to lost IRQs because the state of that IRQ injection is not stored anywhere and we don't return an error to userspace. We haven't seen this problem manifest itself yet, presumably because guests reset the devices on boot, but this could cause issues with migration and other non-standard startup configurations. Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index c98cc6b..feef015 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1693,8 +1693,13 @@ out: int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num, bool level) { - if (likely(vgic_ready(kvm)) && - vgic_update_irq_pending(kvm, cpuid, irq_num, level)) + if (unlikely(!vgic_initialized(kvm))) { + mutex_lock(&kvm->lock); + vgic_init(kvm); + mutex_unlock(&kvm->lock); + } + + if (vgic_update_irq_pending(kvm, cpuid, irq_num, level)) vgic_kick_vcpus(kvm); return 0;