From patchwork Fri Sep 15 22:19:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9953883 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 A8A72601AE for ; Fri, 15 Sep 2017 22:22:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9355628161 for ; Fri, 15 Sep 2017 22:22:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8821D283C7; Fri, 15 Sep 2017 22:22:07 +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 C3C4E2956F for ; Fri, 15 Sep 2017 22:22:05 +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=8HsjYVHd0hin+2WdfgsCYxzuJ1XB6nyYQzdqPrJ2vOA=; b=U94UXb7gBgxZnNANT31Px6oqUq /KHL2z+i7VNW2+VmhqKMLDeR8SOB/PjYEIDFo4xP9xAW+amV6sG9D2CpfW1Yb8nwv3WL+rnZCM2El IepMRh0aX3My6ttt6P9Um8072y1/7U+1koXBEXsq8ys/JyrcNFxK5cySBtlp2gsDsQS/CURYC3m77 AgzUCmL/ZxmaD7hQ2zd3242HVDFT8sPCNag9NZdveBF18ILOTEewwLA9VZeAokZP4n3bkYuNWXY+q +OD790uZto9GpY/xHhnRMxK6uar6k3EmxVhLltvluUfkHmrbsduwSyIStrVNUibsE6vIgpAVHyZhq EJCP+0OA==; 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 1dsyzE-0003vt-Vd; Fri, 15 Sep 2017 22:21:25 +0000 Received: from mail-ua0-x230.google.com ([2607:f8b0:400c:c08::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dsyyM-0002MT-7G for linux-arm-kernel@lists.infradead.org; Fri, 15 Sep 2017 22:20:37 +0000 Received: by mail-ua0-x230.google.com with SMTP id 97so1917503uai.6 for ; Fri, 15 Sep 2017 15:20:08 -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=CuY3rYG1zgZeE/3ZD9Ax+vz1kZ2dB8Cfd4O8GOkhYKw=; b=UYwJKNJnomNRGc4q/zneDKGy4+4iWlTbIzyV8dRyB9IYSj2Wf6K2FX1qso8C8ZsU2R RuuHjmBWezK63F7vN+frSnPZZBdT68/GPV7M6dBxTozJDyw8hl3SqYjMoOX6IgIjGosZ qHEnbf/N0R1NdTa0svgilO9WEo0feh8N3IGo8= 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=CuY3rYG1zgZeE/3ZD9Ax+vz1kZ2dB8Cfd4O8GOkhYKw=; b=Q4uxLcLVY+qC44x9udGuOZy4ckmkP294BUh6p0v7jUZHLBd8xiOSGNgcu8QmIXarO8 juQD94lsukMcDDfb9eYwsn9LU/f3+blL8zMBJ0tMUcVap9Mi9gjUZw7QvxB1/WPKbfw2 86IlAMjodX+kkh949/iz0GsFFTOosO/5WHfOL8UH802045HK13itBMzbmUiLQWIORuXO mfxM7oPw5FU+6R7cC2rPl59E3Ymu2m7rCVGorp5AWnkSKqLDRLr5UmZFNAj0TTSOrXEO QPlcZ6DDFZ0Dz5rArOekM67soXl6Q3WNVHWqKOQfXlCQ4YqD6AxFNSViPTX1SRUAqRFD pmTg== X-Gm-Message-State: AHPjjUgyNt/ELKGniHZ3pWw3r+gdbSwHVK/MDml9cbHQTdHeeR2G+P8I DdGtuTk+nDHdSJgf X-Google-Smtp-Source: AOwi7QBIziH6FMk5BqeYcuu7tmhfXAVZh2kFb4Y3RNKSMguw6wIqJ9/yoh6/ou28TGz3LRzU9Q2wUw== X-Received: by 10.176.30.129 with SMTP id o1mr9513579uak.170.1505514007239; Fri, 15 Sep 2017 15:20:07 -0700 (PDT) Received: from localhost.localdomain ([12.145.98.253]) by smtp.gmail.com with ESMTPSA id q64sm399435uaq.13.2017.09.15.15.20.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Sep 2017 15:20:06 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/7] KVM: arm/arm64: Don't cache the timer IRQ level Date: Fri, 15 Sep 2017 15:19:50 -0700 Message-Id: <1505513994-77939-4-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505513994-77939-1-git-send-email-christoffer.dall@linaro.org> References: <1505513994-77939-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170915_152030_775353_76FC6A9A X-CRM114-Status: GOOD ( 16.13 ) 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 , kvm@vger.kernel.org, Christoffer Dall 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 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 on every entry to the guest, and the VGIC can ignore notifications using its validate mechanism. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- virt/kvm/arm/arch_timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 8e89d63..2a5f877 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -219,9 +219,10 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level, int ret; timer_ctx->active_cleared_last = false; + if (timer_ctx->irq.level != new_level) + trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_ctx->irq.irq, + new_level); timer_ctx->irq.level = new_level; - trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_ctx->irq.irq, - timer_ctx->irq.level); if (likely(irqchip_in_kernel(vcpu->kvm))) { ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, @@ -241,6 +242,7 @@ 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 userspace modified the timer registers via SET_ONE_REG before @@ -251,11 +253,11 @@ static void kvm_timer_update_state(struct kvm_vcpu *vcpu) if (unlikely(!timer->enabled)) return; - if (kvm_timer_should_fire(vtimer) != vtimer->irq.level) - kvm_timer_update_irq(vcpu, !vtimer->irq.level, vtimer); + 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); + level = kvm_timer_should_fire(ptimer); + kvm_timer_update_irq(vcpu, level, ptimer); } /* Schedule the background timer for the emulated timer. */