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: 9503985 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 C1DF660757 for ; Mon, 9 Jan 2017 06:35:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B09952817F for ; Mon, 9 Jan 2017 06:35:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A24A82823E; Mon, 9 Jan 2017 06:35:11 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13DA32808F for ; Mon, 9 Jan 2017 06:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034053AbdAIGeo (ORCPT ); Mon, 9 Jan 2017 01:34:44 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:38371 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939734AbdAIG0N (ORCPT ); Mon, 9 Jan 2017 01:26:13 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q5JY017983 for ; Mon, 9 Jan 2017 01:26:11 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 36AB687 for ; Mon, 9 Jan 2017 01:26:11 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id 050A28B for ; Mon, 9 Jan 2017 01:26:11 -0500 (EST) Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QAm7041235 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:10 -0500 Received: by mail-qt0-f200.google.com with SMTP id q3so52481412qtf.4 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=PwPnxAYe1sOenIequvBCVPCTJebfzO1FXD5tfi7DtAsI4+9jDTeiOCD6APVkLL5XdZ zNfaGvumGtOhDonxw742AnLtauxnoFHFG2dSDXrWf32qr8ZtDEuE9JxKrNCEsWogd/ls suD1xMSZAW2UmmeCYZyeWbwN15LhJqvcNV2JQJvi53XLF/rp6p/UKoz7OQ4tFoRIFyVo Pcma3rAOg50TUSnphyVtCVKLEQJI91l0jE2DEg7u74CLD/zVBhWgEqJSHOuOAkKG8LrL Ec31QAAVbDR2XqPtLU4BsCqF7AxXLlP58oSf//Boyc5Kyfp3Zum4u7Mq7iVtfoWEiILX 1Vng== X-Gm-Message-State: AIkVDXLWj05OAjwuZL1ud/gfG5UKk/mdXoiZH6H5ZMBq7L487hRrMazTqojx8D4FipxErhjMgxo1uvYHmRdbV5os6C8UvZXvnMIY2+cdZIjv4ds9Qnc1xK7/79iV+vTxbjSLNyQwdhbJmjY= X-Received: by 10.55.127.129 with SMTP id a123mr83631787qkd.129.1483943170621; 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 Cc: jintack@cs.columbia.edu 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.13 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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. */