From patchwork Mon Jan 9 06:24:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A50EC60710 for ; Mon, 9 Jan 2017 06:42:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9307228112 for ; Mon, 9 Jan 2017 06:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87A092811C; Mon, 9 Jan 2017 06:42:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 13DC42815E for ; Mon, 9 Jan 2017 06:42:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cQTf0-00054v-SC; Mon, 09 Jan 2017 06:42:26 +0000 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTPZ-0002F9-4h for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:26:34 +0000 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q9na006312 for ; Mon, 9 Jan 2017 01:26:11 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 1FDFE7E for ; Mon, 9 Jan 2017 01:26:11 -0500 (EST) Received: from sendprodmail02.cc.columbia.edu (sendprodmail02.cc.columbia.edu [128.59.72.14]) by hazelnut (Postfix) with ESMTP id F18297E for ; Mon, 9 Jan 2017 01:26:10 -0500 (EST) Received: from mail-qt0-f197.google.com (mail-qt0-f197.google.com [209.85.216.197]) by sendprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QAr6042477 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:10 -0500 Received: by mail-qt0-f197.google.com with SMTP id t56so77866151qte.3 for ; Sun, 08 Jan 2017 22:26:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/wx6AONLN4eDqiShzhbPCIMZeoXS5t77Oc4Wbt8MFTQ=; b=JCM3la156RJNip3KjgNvyrqdx4vJGDPwxoRdEyYGjmHQDlO3+kI/fySAHfodPT2uDW HWFnzUiJe7tTggQO9tK8w73AU289tpwTmPVtxG+raWYWroQJin9lF5NZ2CTAVwn5CoTX Wjd1GqoiYTc+eHBVqklyIdfcMSBUnFaIe/cwB8AK2+oUx41y1S+xy8Kx+C7me0X6qVYQ vD6OVSxm5XH4togNkF+KqmAcpt6nD+klL+VXZZTKLyNwizh0yKLoA0H9W4RfFwHp4qKI UvEyWJNQaspB18rocCi2hoODQk1k7qwdQD95/PmHsdstPzbrycHS+7jyT9Ve8Edu6B9O WDxg== X-Gm-Message-State: AIkVDXJKjHz+KT3qY8UqDuz/WR6You4WWjcY8L2Ht8VVl40sDEWupoFBc1WYuXISX48K/RUh+tVQoxZBNRd1941ha+w75+m8n4ikThBcbEIEKJ2YGpGBsHv8wkQAviQvkiTGyBheLwEsB82hqR7+adYSmSJy/wo65u2FEw== X-Received: by 10.55.127.129 with SMTP id a123mr83631768qkd.129.1483943170617; Sun, 08 Jan 2017 22:26:10 -0800 (PST) X-Received: by 10.55.127.129 with SMTP id a123mr83631758qkd.129.1483943170465; Sun, 08 Jan 2017 22:26:10 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.26.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26:09 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC 30/55] KVM: arm/arm64: Inject irqs to the guest hypervisor Date: Mon, 9 Jan 2017 01:24:26 -0500 Message-Id: <1483943091-1364-31-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.14 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170108_222629_725022_D2650900 X-CRM114-Status: GOOD ( 13.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jintack@cs.columbia.edu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If we have a pending IRQ for the guest and the guest expects IRQs to be handled in its virtual EL2 mode (the virtual IMO bit is set) and it is not already running in virtual EL2 mode, then we have to emulate an IRQ exception. Signed-off-by: Jintack Lim Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 6440b56..4a98654 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "vgic.h" @@ -652,6 +653,28 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu) /* Nuke remaining LRs */ for ( ; count < kvm_vgic_global_state.nr_lr; count++) vgic_clear_lr(vcpu, count); + + /* + * If we have any pending IRQ for the guest and the guest expects IRQs + * to be handled in its virtual EL2 mode (the virtual IMO bit is set) + * and it is not already running in virtual EL2 mode, then we have to + * emulate an IRQ exception to virtual IRQ. Note that a pending IRQ + * means an irq of which state is pending but not active. + */ + if (vcpu_el2_imo_is_set(vcpu) && !vcpu_mode_el2(vcpu)) { + bool pending = false; + + list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) { + spin_lock(&irq->irq_lock); + pending = irq->pending && irq->enabled && !irq->active; + spin_unlock(&irq->irq_lock); + + if (pending) { + kvm_inject_nested_irq(vcpu); + break; + } + } + } } /* Sync back the hardware VGIC state into our emulation after a guest's run. */