From patchwork Mon Dec 4 20:05:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10091425 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 BBEF56035E for ; Mon, 4 Dec 2017 20:05:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE1E828AB2 for ; Mon, 4 Dec 2017 20:05:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A310128BB9; Mon, 4 Dec 2017 20:05:17 +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 37A0728AB2 for ; Mon, 4 Dec 2017 20:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752034AbdLDUFQ (ORCPT ); Mon, 4 Dec 2017 15:05:16 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36934 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbdLDUFN (ORCPT ); Mon, 4 Dec 2017 15:05:13 -0500 Received: by mail-wm0-f65.google.com with SMTP id f140so16487239wmd.2 for ; Mon, 04 Dec 2017 12:05:12 -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:in-reply-to:references; bh=ZTTRBQ4EW5KX4vRw0MCmsatDV74bwFJnWH27O3yom+w=; b=FbpI+/TyA5gNBwCnSAYCSbFxJXLmNY06Ag7eCCEDAPBYtx9h0r6K6LWVgcpXScgfTn EBrpXL+6YNokMfdsfZbBn9wSSEtZPmF/MGpYAdYmrqp05rBYxlKVrxz9pVtXcKlq4TUe 45FLTmL4qVkXgTJI/AbsfZPpdiPYwvgFAGnTWhxXBvYlk1KSgv14c9ifmaU/Pju4o5x9 qLt//mkiRzVJj3mXF8n5li01JHct73aLC/1LM8BuJ817c32wG4aZP5FCEtd1DDZzqWZ/ ehkU1bo26LnkjCElHN6TM8FdnOuAJwzoqox6uu9GF/Lcbjb1BWCA+ElIxmLMgFClufEu ClUw== 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 :in-reply-to:references; bh=ZTTRBQ4EW5KX4vRw0MCmsatDV74bwFJnWH27O3yom+w=; b=NPoSbZsQuiespNc0fHuuQC+GXI0QAVSHzkZpvG/JRQ3//kAjb4S4ufihew7XOeXled pwABN4nyf4KI5xLguPNQ/0czEmTYnO+xwI0EFsMnz5Z/Khw4zvJWaiLco5WcYz9PYJmU Y/E5Ky9gTtX5cCld9MWP97L1MkjDQf//KD0fWgG8YpUfRjyvpuEVHI16pLdg5tE/OP30 +PV7VfayOlj4Jms6nQ1EY2bI6nKykFrtbLrMpnEhfFm/wU+X2RtEhOhlt0ZmKHQuUXZX leAmec8uEbOGGmdXzvtL1DXdHvgnBKcnUW31gdkUcCeFBT8qrnHbHOHNkCy4XxNwt7nm loVA== X-Gm-Message-State: AJaThX7USAnCZEHK4K+o1OwKzXX0wUM+WquHGUs3dyQbSOiU+ieUSy82 JZeQ72xuS6XBYJhmBV5TSY6biSc97us= X-Google-Smtp-Source: AGs4zMbKjBzZyk0UjZuD0baMISFLIJ7y1qgxZsOnyJIEB1bQLHYaD0plZWraSQj4u5n7paw9DBVrXA== X-Received: by 10.80.220.132 with SMTP id r4mr33167316edk.180.1512417912167; Mon, 04 Dec 2017 12:05:12 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id 26sm8374578eds.67.2017.12.04.12.05.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 12:05:11 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Christoffer Dall Subject: [PATCH v6 3/8] KVM: arm/arm64: Don't cache the timer IRQ level Date: Mon, 4 Dec 2017 21:05:01 +0100 Message-Id: <20171204200506.3224-4-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204200506.3224-1-cdall@kernel.org> References: <20171204200506.3224-1-cdall@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall The timer was modeled after a strict idea of modelling an interrupt line level in software, meaning that only transitions in the level needed to be reported to the VGIC. This works well for the timer, because the arch timer code is in complete control of the device and can track the transitions of the line. However, as we are about to support using the HW bit in the VGIC not just for the timer, but also for VFIO which cannot track transitions of the interrupt line, we have to decide on an interface for level triggered mapped interrupts to the GIC, which both the timer and VFIO can use. VFIO only sees an asserting transition of the physical interrupt line, and tells the VGIC when that happens. That means that part of the interrupt flow is offloaded to the hardware. To use the same interface for VFIO devices and the timer, we therefore have to change the timer (we cannot change VFIO because it doesn't know the details of the device it is assigning to a VM). Luckily, changing the timer is simple, we just need to stop 'caching' the line level, but instead let the VGIC know the state of the timer every time there is a potential change in the line level, and when the line level should be asserted from the timer ISR. The VGIC can ignore extra notifications using its validate mechanism. Reviewed-by: Andre Przywara Signed-off-by: Christoffer Dall --- virt/kvm/arm/arch_timer.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 4151250ce8da..dd5aca05c500 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -99,11 +99,9 @@ static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) } vtimer = vcpu_vtimer(vcpu); - if (!vtimer->irq.level) { - vtimer->cnt_ctl = read_sysreg_el0(cntv_ctl); - if (kvm_timer_irq_can_fire(vtimer)) - kvm_timer_update_irq(vcpu, true, vtimer); - } + vtimer->cnt_ctl = read_sysreg_el0(cntv_ctl); + if (kvm_timer_irq_can_fire(vtimer)) + kvm_timer_update_irq(vcpu, true, vtimer); if (unlikely(!irqchip_in_kernel(vcpu->kvm))) kvm_vtimer_update_mask_user(vcpu); @@ -324,12 +322,20 @@ static void kvm_timer_update_state(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); + bool level; if (unlikely(!timer->enabled)) return; - if (kvm_timer_should_fire(vtimer) != vtimer->irq.level) - kvm_timer_update_irq(vcpu, !vtimer->irq.level, vtimer); + /* + * The vtimer virtual interrupt is a 'mapped' interrupt, meaning part + * of its lifecycle is offloaded to the hardware, and we therefore may + * not have lowered the irq.level value before having to signal a new + * interrupt, but have to signal an interrupt every time the level is + * asserted. + */ + level = kvm_timer_should_fire(vtimer); + kvm_timer_update_irq(vcpu, level, vtimer); if (kvm_timer_should_fire(ptimer) != ptimer->irq.level) kvm_timer_update_irq(vcpu, !ptimer->irq.level, ptimer);