From patchwork Wed Sep 6 12:26:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9940557 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 0D77560350 for ; Wed, 6 Sep 2017 12:26:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D638F28BC0 for ; Wed, 6 Sep 2017 12:26:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB1F328BC4; Wed, 6 Sep 2017 12:26:36 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 A746F28BC0 for ; Wed, 6 Sep 2017 12:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753586AbdIFM0d (ORCPT ); Wed, 6 Sep 2017 08:26:33 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35030 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753544AbdIFM03 (ORCPT ); Wed, 6 Sep 2017 08:26:29 -0400 Received: by mail-wm0-f51.google.com with SMTP id f199so8824529wme.0 for ; Wed, 06 Sep 2017 05:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T8jcgLljfKbDzc1UKHBLo/i389SZKO4SKs11j3TUEyM=; b=U38Gz+swOW8ay50ElTkUWyH3+PLL8f3utrdYLfwqH7W3tVGJFpH/Z0CjHFIBm8QiDd fzAXB9+a9arEom5QqBCsinhPS5tqkILAKmewLx+GhEIq5/d+zO6n2nOgVsjU3TfHbpZc 1LycS/LrWQErviqB833kH5Xl6SVBoy+08IeDs= 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=T8jcgLljfKbDzc1UKHBLo/i389SZKO4SKs11j3TUEyM=; b=Lol1BLJS4IaEzEqvBuTFm231BtIjUHsgd19M2g/ci0Sm47zS4hiAtClRVhhDWFZ/ZF /FeuYk+wfr4xwIaKsGOmD+TyepVKbg169gJ5ifUtVgtFBaDoQqgVjHo8LnnN9GJrkxS1 XOsUlHHlgnS1VwY3b8zTqsz+CJhXQFekPWLNLAwL9RWKqirleepNOUsFuy3aa6tC1Gev ltxV65JbmrAwJoP4qRjT0mJyvmc93k/8rKazfSFKd2cBTf58OhdsM9Pw1BT9N/AGApt+ HqmZCk3AGeqrySVjK7MSwhJdTTJ6ngjFUMNTZz5UoQg+HFAj4krAzCD8wIzpJAQPIGyt D2lw== X-Gm-Message-State: AHPjjUgoBr1+33bLl8xpmoRqihkWVhnzqB1piJ5muiyAJpfsUlaVs4Cp Wuz/diGWrqQEw9f/ X-Google-Smtp-Source: ADKCNb4eNrtnSy1QIQU/o8kJ2crdHbga4cwJZ3L6kslkyu9Jx/Exwg8BEdmv67KMInVhC6pc3h5B6A== X-Received: by 10.80.227.131 with SMTP id b3mr5835361edm.275.1504700787855; Wed, 06 Sep 2017 05:26:27 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id e12sm1251954edm.85.2017.09.06.05.26.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Sep 2017 05:26:26 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Eric Auger , Marc Zyngier Cc: Andre Przywara , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Christoffer Dall Subject: [PATCH v3 4/5] KVM: arm/arm64: Support VGIC dist pend/active changes for mapped IRQs Date: Wed, 6 Sep 2017 14:26:11 +0200 Message-Id: <20170906122612.18050-5-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170906122612.18050-1-cdall@linaro.org> References: <20170906122612.18050-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For mapped IRQs (with the HW bit set in the LR) we have to follow some rules of the architecture. One of these rules is that VM must not be allowed to deactivate a virtual interrupt with the HW bit set unless the physical interrupt is also active. This works fine when injecting mapped interrupts, because we leave it up to the injector to either set EOImode==1 or manually set the active state of the physical interrupt. However, the guest can set virtual interrupt to be pending or active by writing to the virtual distributor, which could lead to deactivating a virtual interrupt with the HW bit set without the physical interrupt being active. We could set the physical interrupt to active whenever we are about to enter the VM with a HW interrupt either pending or active, but that would be really slow, especially on GICv2. So we take the long way around and do the hard work when needed, which is expected to be extremely rare. When the VM sets the pending state for a HW interrupt on the virtual distributor we set the active state on the physical distributor, because the virtual interrupt can become active and then the guest can deactivate it. When the VM clears the pending state we also clear it on the physical side, because the injector might otherwise raise the interrupt. Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-mmio.c | 33 +++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 7 +++++++ virt/kvm/arm/vgic/vgic.h | 1 + 3 files changed, 41 insertions(+) diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c index c1e4bdd..00003ae 100644 --- a/virt/kvm/arm/vgic/vgic-mmio.c +++ b/virt/kvm/arm/vgic/vgic-mmio.c @@ -131,6 +131,9 @@ void vgic_mmio_write_spending(struct kvm_vcpu *vcpu, struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i); spin_lock(&irq->irq_lock); + if (irq->hw) + vgic_irq_set_phys_active(irq, true); + irq->pending_latch = true; vgic_queue_irq_unlock(vcpu->kvm, irq); @@ -149,6 +152,20 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i); spin_lock(&irq->irq_lock); + /* + * We don't want the guest to effectively mask the physical + * interrupt by doing a write to SPENDR followed by a write to + * CPENDR for HW interrupts, so we clear the active state on + * the physical side here. This may lead to taking an + * additional interrupt on the host, but that should not be a + * problem as the worst that can happen is an additional vgic + * injection. We also clear the pending state to maintain + * proper semantics for edge HW interrupts. + */ + if (irq->hw) { + vgic_irq_set_phys_pending(irq, false); + vgic_irq_set_phys_active(irq, false); + } irq->pending_latch = false; @@ -214,6 +231,22 @@ static void vgic_mmio_change_active(struct kvm_vcpu *vcpu, struct vgic_irq *irq, irq->vcpu->cpu != -1) /* VCPU thread is running */ cond_resched_lock(&irq->irq_lock); + if (irq->hw) { + /* + * We cannot support setting the physical active state for + * private interrupts from another CPU than the one running + * the VCPU which identifies which private interrupt it is + * trying to modify. + */ + if (irq->intid < VGIC_NR_PRIVATE_IRQS && + irq->target_vcpu != requester_vcpu) { + spin_unlock(&irq->irq_lock); + return; + } + + vgic_irq_set_phys_active(irq, new_active_state); + } + irq->active = new_active_state; if (new_active_state) vgic_queue_irq_unlock(vcpu->kvm, irq); diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 8072969..7aec730 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -140,6 +140,13 @@ void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) kfree(irq); } +void vgic_irq_set_phys_pending(struct vgic_irq *irq, bool pending) +{ + WARN_ON(irq_set_irqchip_state(irq->host_irq, + IRQCHIP_STATE_PENDING, + pending)); +} + /* Get the input level of a mapped IRQ directly from the physical GIC */ bool vgic_get_phys_line_level(struct vgic_irq *irq) { diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index 7bdcda2..498ee05 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -146,6 +146,7 @@ struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 intid); void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq); bool vgic_get_phys_line_level(struct vgic_irq *irq); +void vgic_irq_set_phys_pending(struct vgic_irq *irq, bool pending); void vgic_irq_set_phys_active(struct vgic_irq *irq, bool active); bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq); void vgic_kick_vcpus(struct kvm *kvm);