From patchwork Mon Nov 20 19:16:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10067085 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 AFB2B602B7 for ; Mon, 20 Nov 2017 19:17:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FD0C29096 for ; Mon, 20 Nov 2017 19:17:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 949002935D; Mon, 20 Nov 2017 19:17:37 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 05F9829096 for ; Mon, 20 Nov 2017 19:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nOEkAs8zlSPbOex8icSmlo8XhILsFowNcPLnT9FqEoQ=; b=LR/PiPgQpFDOJ5W8+nZIdFXwo/ uXuldQtLEUMe42oKaBlM2DFkeQrCsDEBWlYUocRVY0cP4NRByJJmD/lnt5f7x3trd+OERa3VEM/Kz kFpY/FO8YGbou8CeOg77cBlHfq+hfZ5CYLimXJqasCLe/ZeyZeQ77hmkA0vjWs71hl2stQ2wHMMGt GbE5AmL90XsIfJXUaq9sxOCDKRkd3TelaRXnZJiE/ZJz9JEEJeiuOeA2wrowtVZwypNF1B40BO5tV jcLk8uzFozcbyE3qacmUbH2pnLgJZsf+rjvQF8RF0GtAvQDTmc6jtHA1tiz1Fbd6axReRulWQEPLv dGaDU0fg==; 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 1eGrZS-0008SE-3t; Mon, 20 Nov 2017 19:17:30 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eGrZ5-00080g-Mn for linux-arm-kernel@lists.infradead.org; Mon, 20 Nov 2017 19:17:09 +0000 Received: by mail-wr0-x241.google.com with SMTP id z75so7744740wrc.5 for ; Mon, 20 Nov 2017 11:16:50 -0800 (PST) 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=4Odfi7tWn7HpnMY+RDUVtIn1duagAkYmda9IYu+2jII=; b=ICdWWpJVkHW2fJb/O3VC22tL/fA03pr3taI7tpR7H7hxEH5uQ5Y87yi4j1tyV66Pu0 73gwzQnzlWAKZxdi1PFp4Fa7Zbfl9EwBlf/7dJHH7XbXnLFPwg7YMj3MQz6cK10TFCXO Cfc0zv+tRF5JEw2qtGIOHatJ/HRk0FBE1WQm8= 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=4Odfi7tWn7HpnMY+RDUVtIn1duagAkYmda9IYu+2jII=; b=WJ/wzfZ5Q0LcN3E6BhJcP7n7R28VABldrYFboTXlr2WiBdcDLRjENqtqP0lABN+Edz tM2KCz6J/fifkQrpgbgpeyEguJ+/i5A+As3IilQjyKkSycvl9kZ1JpsNtVY93P4HB1gs BrvWh4vuKNF0PJ8ZcHMs0+Vp1uXSW7OH4hBWatr9RPMCMdidTKZe68p0xJhiib6ezSuQ lEfb175dmVaTg91HudxeDSY3ffSb2LQN1aDZrj4WHxYHblhjBFRd31PqUdfdZnvKLvGu rLi91/5t9t/8EhM1Uc3kkNnk3jOCBeXEtDha+Fa5D1c5T2nOPttMMk21/oOhYcSijdBQ 8P0Q== X-Gm-Message-State: AJaThX7FFhJfJ3hfJ7TkOyWQTLuhIIkEtEyprHEQNeZvMDqn+RnrV6Jk F+YSTgh36r2jPWFcnN2favhosw== X-Google-Smtp-Source: AGs4zMYJM00wvX2pLJ45N2bmwIwInuafWBaPw349LEhucR4KwmUDEbPa5hL/nyUU2OfHSN7uIM2iCA== X-Received: by 10.223.135.59 with SMTP id a56mr13399500wra.173.1511205408617; Mon, 20 Nov 2017 11:16:48 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f132sm3726885wmf.17.2017.11.20.11.16.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Nov 2017 11:16:47 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 3/8] KVM: arm/arm64: Don't cache the timer IRQ level Date: Mon, 20 Nov 2017 20:16:44 +0100 Message-Id: <20171120191649.17290-4-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171120191649.17290-1-christoffer.dall@linaro.org> References: <20171120191649.17290-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171120_111707_897542_8AA494F1 X-CRM114-Status: GOOD ( 18.50 ) 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: Marc Zyngier , Eric Auger , Christoffer Dall , kvm@vger.kernel.org, Andre Przywara 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 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. Signed-off-by: Christoffer Dall Reviewed-by: Andre Przywara --- 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 190c99ed1b73..5f8ad8e3f3ff 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);