From patchwork Mon Sep 4 10:24:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9936953 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 9F3AD60237 for ; Mon, 4 Sep 2017 10:25:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FE98287B8 for ; Mon, 4 Sep 2017 10:25:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84B9D287BA; Mon, 4 Sep 2017 10:25:16 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 7AB2E287B8 for ; Mon, 4 Sep 2017 10:25:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753411AbdIDKZK (ORCPT ); Mon, 4 Sep 2017 06:25:10 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35951 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753371AbdIDKZH (ORCPT ); Mon, 4 Sep 2017 06:25:07 -0400 Received: by mail-wm0-f46.google.com with SMTP id i145so2185035wmf.1 for ; Mon, 04 Sep 2017 03:25:07 -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=lqafpuMGG1uLdP0yI1kXtklV1aWB62cc8H7kMTyoVHg=; b=KiKM+vtxa3xcVPR/Srm1Zw2/ptB8/ioTLdOVMhCURYoTz5qj86vCJA32Xr+lIzq2Ry 7iXB4w92J1ojBeTXiPMEj/t1I1lKPemwjMZWs3RlOlA+BpAyfa5IyYjUWhUmMHFlJHiq 1kTxpiO+Y1PL5MkeQGcDAHG/VWT/mq+hNjBtg= 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=lqafpuMGG1uLdP0yI1kXtklV1aWB62cc8H7kMTyoVHg=; b=hl4QSJxdiOG71unHy/TL/+jG1ErBNcVLzWD+QCvnWvVkTkn82E65o/f8GQvNP+0Kib 0T7Oy3Zml2lti3WdyqFU45cvkPEgLiGULTMJuUBIdcXBV7wsbBPMbMCVnBlYBTa46Dd6 8CN53OO4KBkvkGb2fhnCPnXARm2Adhbg3CwvpwEW1GPtyWV8jV56ryEuDGd63Z6EeQFw JjzYUZwEKiuGnsyYozm/KCXGjwKn2BN4/L1ytRotskNOXGCXsIThNHP9Yxa/Ub5tUUd/ ShUW2q1Zc8AxJls0jOp1k5qQ5yVhnHl8Od4qVBkH31+ixjYMY8HFYHdfMPwHpBO04Yxk C8sg== X-Gm-Message-State: AHPjjUimL4XASK2E2EmwQpt9Rj/ECKWTyGAOcf0mQHdvJGbuTwx3PIP/ n2MM/3sOgFV4WrB7 X-Google-Smtp-Source: ADKCNb6JW196HOtk39lrxvzhrH1LDB3qTHWKQU2zZG53elBfD9rJ0FIuDY4T0zJ+7qcaSJl2rlkruw== X-Received: by 10.80.183.5 with SMTP id g5mr108160ede.121.1504520706672; Mon, 04 Sep 2017 03:25:06 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id h64sm3406924edc.67.2017.09.04.03.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 03:25:06 -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 v2 1/6] KVM: arm/arm64: Don't cache the timer IRQ level Date: Mon, 4 Sep 2017 12:24:51 +0200 Message-Id: <20170904102456.9025-2-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170904102456.9025-1-cdall@linaro.org> References: <20170904102456.9025-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 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 --- 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. */