From patchwork Thu Dec 7 10:54:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10098455 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 2BD2D60329 for ; Thu, 7 Dec 2017 11:05:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18F9F2921A for ; Thu, 7 Dec 2017 11:05:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B9F9292CE; Thu, 7 Dec 2017 11:05:14 +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 BCA662921A for ; Thu, 7 Dec 2017 11:05:13 +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=2MztsYOg0aGwWVEUEyZpn8LpureoO1SJdTwvh8wNf3Q=; b=bHh9VKERYn59LHKYH8luZjpwoc vBUWFxvjN/+GMfrfqdk4aYBNJ6vivCSDE3HIE4jygceF0qMTObRjwY+ZJxb89FUeABqCxEu+HqmW5 RBi9g6GbJHYbDx8VsElpKOTEr81mI+NH0N8oO760zCaGLZlYG9BjkU7YwTOpJ52NVW2kVV6TegVms AlzQUpCiaXRGSYoHrDIHht9y5s2YITsu0vdu5DOQECj6Ws6QIVgAc+Fxwnt03hdmYx01xzh/H9aY2 8B/IXuVjiK+X/4azM4cn/GV0gQDILeXcWh2ISXaKbDpr+1kMa3Zz9bJ8EUfU3tL21vkw4P0DZDyao /CrjmoGg==; 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 1eMtzM-0000gJ-Ia; Thu, 07 Dec 2017 11:05:12 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMtpT-0000Bs-No for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 10:55:12 +0000 Received: by mail-wm0-x241.google.com with SMTP id b76so12164850wmg.1 for ; Thu, 07 Dec 2017 02:54:42 -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=jWHL37U5VB4LN1IJfTqLdTgfZNG8emCXf0W4nnuQTRI=; b=Q2b/+dyZkC5jd3y/9M0XhWnOsrrTk9RKT8QtokuAm9C04SOb7B8DL0PsNVMFzNHkAS aco293nK77oPICNM2hdZmkJJQXD62myBAMVr3bETQ6Qo2NtcY/cLpuBhd/uOxK8Pl3eb IcjBJJUrP3KKMJmlo6o6Dn0IdqQvd9GJXoivw= 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=jWHL37U5VB4LN1IJfTqLdTgfZNG8emCXf0W4nnuQTRI=; b=aEdx3w+e0zkehvkP8BZKSTRnsSC/y2iojS+oPaEd6MJQfsdGna1mS7WN9hLO/TGHSh 3oqH+wa2Z1jkV+tZhLnW7sFv/lcmO8XqdroI/MG3ChcziB3uigAGDxJbuO6TddbBFKfa T4DhuHz5lEfKzDexRpuZ/JK8VTiUJLGPGPBX6m3bEiHTTWIFp5NJyhQdjMoQxdSU0IfA T1hVfGyXrSjjZUu06AaQ5dObX02Oe2U6MdS4Plq6MihYY4msYhQyt6H+O7TfiI5Fz6D9 oiR3di27jmHdo8RNnTMQU4rnzRYa5/LzeF1SQPP+YWyjcutaKk/Fg84KviUUlX4yloX8 n0+w== X-Gm-Message-State: AJaThX4I227KWlGMAfll8UXgWnVCVUwa4tH+ID5Q3OnC8YNIW5N9gSd2 l2BypLi5Fo3croJie69pO8K/8g== X-Google-Smtp-Source: AGs4zMZY1lFHNEKNmVVJJwR6s4vKVhPjCrkGLlTc2O2oMWxR6Ys5vgj9pBH7jIkpyZHt0k04MHcaNQ== X-Received: by 10.80.195.12 with SMTP id a12mr45127462edb.142.1512644081097; Thu, 07 Dec 2017 02:54:41 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id t23sm2233671edb.70.2017.12.07.02.54.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 02:54:40 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v7 8/8] KVM: arm/arm64: Avoid work when userspace iqchips are not used Date: Thu, 7 Dec 2017 11:54:18 +0100 Message-Id: <20171207105418.22428-9-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207105418.22428-1-christoffer.dall@linaro.org> References: <20171207105418.22428-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171207_025500_038688_387F1AA4 X-CRM114-Status: GOOD ( 15.42 ) 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: kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , linux-arm-kernel@lists.infradead.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 We currently check if the VM has a userspace irqchip on every exit from the VCPU, and if so, we do some work to ensure correct timer behavior. This is unfortunate, as we could avoid doing any work entirely, if we didn't have to support irqchip in userspace. Realizing the userspace irqchip on ARM is mostly a developer or hobby feature, and is unlikely to be used in servers or other scenarios where performance is a priority, we can use a refcounted static key to only check the irqchip configuration when we have at least one VM that uses an irqchip in userspace. Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- virt/kvm/arm/arch_timer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 82d4963f63b8..df21451e7654 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -51,6 +51,8 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level, struct arch_timer_context *timer_ctx); static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx); +static DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); + u64 kvm_phys_timer_read(void) { return timecounter->cc->read(timecounter->cc); @@ -569,7 +571,8 @@ static void unmask_vtimer_irq_user(struct kvm_vcpu *vcpu) */ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) { - unmask_vtimer_irq_user(vcpu); + if (static_branch_unlikely(&userspace_irqchip_in_use)) + unmask_vtimer_irq_user(vcpu); } int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) @@ -774,6 +777,8 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) soft_timer_cancel(&timer->bg_timer, &timer->expired); soft_timer_cancel(&timer->phys_timer, NULL); kvm_vgic_unmap_phys_irq(vcpu, vtimer->irq.irq); + if (timer->enabled && !irqchip_in_kernel(vcpu->kvm)) + static_branch_dec(&userspace_irqchip_in_use); } static bool timer_irqs_are_valid(struct kvm_vcpu *vcpu) @@ -826,8 +831,10 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu) return 0; /* Without a VGIC we do not map virtual IRQs to physical IRQs */ - if (!irqchip_in_kernel(vcpu->kvm)) + if (!irqchip_in_kernel(vcpu->kvm)) { + static_branch_inc(&userspace_irqchip_in_use); goto no_vgic; + } if (!vgic_initialized(vcpu->kvm)) return -ENODEV;