From patchwork Mon Mar 5 10:36:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10258687 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 5C39A60134 for ; Mon, 5 Mar 2018 10:36:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B8FB289E3 for ; Mon, 5 Mar 2018 10:36:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FDF0289E5; Mon, 5 Mar 2018 10:36:50 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 A641B289E3 for ; Mon, 5 Mar 2018 10:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934124AbeCEKgr (ORCPT ); Mon, 5 Mar 2018 05:36:47 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39942 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933510AbeCEKgq (ORCPT ); Mon, 5 Mar 2018 05:36:46 -0500 Received: by mail-wm0-f68.google.com with SMTP id t6so14471946wmt.5 for ; Mon, 05 Mar 2018 02:36:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=zTHc60lUZGV0fW/KBGH6b2bSKcNKs/W4GELpARfUn5M=; b=Gz35I859EPwXAm7E4O0MF1rUlTyWDoKdZDnsDB1M86CoLPOiKvN7hlw9k1fDb2JEQr RHY3PQ6yyh9rWeDJvPa/6FnsXWcj04YOU6/voKvhJPaWSb/EMd3NVYBR+Mo05qFcwggp ZPJqKaJd3NP4FCerIg9UCGXim/rdY0cWYPKbDBDdf7T80k9I+TgaWGZXK4PR8jwHGw95 dkmqUOgtI9sGjT5a9fJ0nVD1qMMSKZIvSY1jY3JeUJConKDQoL7i9c6A49h1kg1WdsBb Y/Wl5rx/z4Y9vBTXODCSP4P+1rxfoLSq3NPbymcTFu1nLovWZ0rtOOKAcLJKSApg53gV /D+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=zTHc60lUZGV0fW/KBGH6b2bSKcNKs/W4GELpARfUn5M=; b=TSGCQkYdBrOSZPb6dXv8EIeu2D1SWs1jE4+ubiq+VD4wdaxBr9CTwUKyUJAgITtkNJ dshpIRVsohfxGie8Su8/LtsGMul4zaiE5cGsJMKeBcJvyidJbtqkOG66jG3bXqOOPd5T gwhW11MwJ79lPmdCtPiWGaHcdek2vVJhh9cVBv/UFC1lS4RTGXlM9MHboO7EvMLEK85X JDHkpMZWbEPFV2Q6/cKNSE/TnEbZt5LTPyT4q9UEBWLibGfavvF8er5wXnubGf4xCmnU SkZpgjO8kEDr5eXZjXxHrhQ2zT6I3I+KRmpweM010F9T1/e1JFt72EfIOE8wThWfzMnA XuFQ== X-Gm-Message-State: AElRT7EXvd4gCcO8vOE9PnySrISROXCCt6eVpLBMaWSy6OT8nKBkCd4c UVf7bLOxu1701WqazMWsM4Hp/w== X-Google-Smtp-Source: AG47ELvUYw9q7bGk+zFuAdI1wDJXUcYvq90rfsINss1dZAbKzPgzbj12XJMozHOkA8doxytI1V5f2Q== X-Received: by 10.80.144.5 with SMTP id b5mr8681782eda.118.1520246205051; Mon, 05 Mar 2018 02:36:45 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id x23sm6488223edm.7.2018.03.05.02.36.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 02:36:43 -0800 (PST) From: Christoffer Dall To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , Christoffer Dall Subject: [PATCH] KVM: arm/arm64: Reset mapped IRQs on VM reset Date: Mon, 5 Mar 2018 11:36:38 +0100 Message-Id: <20180305103638.1633-1-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We currently don't allow resetting mapped IRQs from userspace, because their state is controlled by the hardware. But we do need to reset the state when the VM is reset, so we provide a function for the 'owner' of the mapped interrupt to reset the interrupt state. Currently only the timer uses mapped interrupts, so we call this function from the timer reset logic. Signed-off-by: Christoffer Dall --- This depends on "KVM: arm/arm64: Avoid vcpu_load for other vcpu ioctls than KVM_RUN" from the VHE optimization series so that the reset doesn't get called while vtimer->loaded is true. include/kvm/arm_vgic.h | 1 + virt/kvm/arm/arch_timer.c | 4 ++++ virt/kvm/arm/vgic/vgic.c | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index cdbd142ca7f2..02924ae2527e 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -360,6 +360,7 @@ void kvm_vgic_put(struct kvm_vcpu *vcpu); bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu); void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu); void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu); +void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid); void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 70268c0bec79..09890a5268d1 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -571,6 +571,7 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) { + struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); @@ -584,6 +585,9 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) ptimer->cnt_ctl = 0; kvm_timer_update_state(vcpu); + if (timer->enabled && irqchip_in_kernel(vcpu->kvm)) + kvm_vgic_reset_mapped_irq(vcpu, vtimer->irq.irq); + return 0; } diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index c7c5ef190afa..0001858a2c23 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -495,6 +495,32 @@ int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, return ret; } +/** + * kvm_vgic_reset_mapped_irq - Reset a mapped IRQ + * @vcpu: The VCPU pointer + * @vintid: The INTID of the interrupt + * + * Reset the active and pending states of a mapped interrupt. Kernel + * subsystems injecting mapped interrupts should reset their interrupt lines + * when we are doing a reset of the VM. + */ +void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid) +{ + struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid); + unsigned long flags; + + if (!irq->hw) + goto out; + + spin_lock_irqsave(&irq->irq_lock, flags); + irq->active = false; + irq->pending_latch = false; + irq->line_level = false; + spin_unlock_irqrestore(&irq->irq_lock, flags); +out: + vgic_put_irq(vcpu->kvm, irq); +} + int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid) { struct vgic_irq *irq;