From patchwork Mon Dec 4 20:05:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10091449 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 5F4D66035E for ; Mon, 4 Dec 2017 20:08:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5029F2877F for ; Mon, 4 Dec 2017 20:08:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 417F62904D; Mon, 4 Dec 2017 20:08:26 +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 C8F412877F for ; Mon, 4 Dec 2017 20:08:25 +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=8P7b1RgXxZ5s2HzVxKZBgGoZs1mBRuxtxW0RhkSkU+A=; b=i6/kSVCYHHDiQZHL/lgzVC55nd 1wR7jCU7FBR6a+/pzDsmV3DgQI4lxAnQGSFPp2T8wxau63i0pGESvQ3qCqw787cMktUn+Lik6rf0W 5RMA6U+r47LcaW7mHUmc3e/Xd5MwtmK0hWAmkAP+G0wU9QvtR7HptZXRi1isRisL6rSyLhe6omzlE pke7w0SlYANEpEXIgJmjKuWgNxUgvv5Mkm+NQQYi1r437CjG2pPfkQc6JE+mDt4cTvq2PXuigtpoc 88cb5qzmAef9lrnJTl3hVbCCawBHIwFVF2ADbNgvJVNjbBA+1G9BhLbjSoArp6tw6x+3RC8SCjv+M j0i55BRQ==; 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 1eLx2H-00050Z-Bi; Mon, 04 Dec 2017 20:08:17 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLwzg-0002SU-Vd for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 20:05:39 +0000 Received: by mail-wm0-x243.google.com with SMTP id y82so16059887wmg.1 for ; Mon, 04 Dec 2017 12:05:21 -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=5CgN0r0qUXWZitTgE5e43QSm/8eWymDyDlwshDZJrL4=; b=JirWCQ/dmJAu1qCpwMXNX4kgEOtPkkpYjPlgD8dov/EHwmwvdRHNr/qKW5mGBbaqZE j1yBxYrIZ5z2xKYlkKJm2Cg9IeUv/uOVfCwMFsJhsll8W7JznkP9SIqqM3u9caIasV6o KbzH112DUz5qAhOIIQqh7dXmkjgcS8l2+R1fl6ZXV2pVciZ0Yfam79jWMnvKciG/Rdfc jQnkrKzpGHMrw2cpe6yIs27SACHnLj9fK0Ye+WV3xkz7nkdhT3hGBARY0WJebWZdLIYB zu52bkQQHHSuN8/gIIPK+a7udyCIhl0VfFTTdNtoX6HiagUuYCe1NWEfq5413ynl4Rub Va8A== 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=5CgN0r0qUXWZitTgE5e43QSm/8eWymDyDlwshDZJrL4=; b=OEU/NVIvL3u9g1YtqtilOwjQl3bVy0Ye38resvJQ5XIBkFJqpr4Ry3hHf2RyrkdDDa 47vLkzhKrjrycvCMtHlpOODh0HUJVhH+VWPEgKtyH+kJbOq/WiFby631Ow5vMLkieLnj P/3sDk+a6bq8B066cYk0wmDpNBCvt3nABWvD60C+lPmu5Trh49tih1OLVkHi6HVCthgk Q8ulzgfNVP5ei66/STGX5IuQDQLAECnnfOmrHRPSkHDJLO55tTIA5d9w/QqyngGkBbJ1 20T44xV5viJCVbBgTiDk2njp0OpxD9WbxRWh3NRfRPoxPklIm6zGiXxMJSOQb/yL0nK3 kikw== X-Gm-Message-State: AJaThX5QJdHPWaUCIOhEEvQxyndec9QBKxKqJ1/jyTi/FswQv9rHhB2l 2urrA2+YVbi0QPBGuzMj/cXwSh/6tMA= X-Google-Smtp-Source: AGs4zMYp4fhFU0fHTTgIMRpQ81Kgm4xgk0CcWxwZY5jmrQD5nChYKx9s4FnKpc9VagMgBKLecwgO7w== X-Received: by 10.80.145.81 with SMTP id f17mr32585501eda.215.1512417920166; Mon, 04 Dec 2017 12:05:20 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 12:05:19 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v6 8/8] KVM: arm/arm64: Avoid work when userspace iqchips are not used Date: Mon, 4 Dec 2017 21:05:06 +0100 Message-Id: <20171204200506.3224-9-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_120537_269194_0BCBB768 X-CRM114-Status: GOOD ( 14.97 ) 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 From: Christoffer Dall 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 --- 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;