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: 10091437 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 9CBA66035E for ; Mon, 4 Dec 2017 20:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EDD528EC3 for ; Mon, 4 Dec 2017 20:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82A142904D; Mon, 4 Dec 2017 20:05:49 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 03C0628EC3 for ; Mon, 4 Dec 2017 20:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752258AbdLDUFc (ORCPT ); Mon, 4 Dec 2017 15:05:32 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:38257 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752166AbdLDUFV (ORCPT ); Mon, 4 Dec 2017 15:05:21 -0500 Received: by mail-wm0-f67.google.com with SMTP id 64so16446146wme.3 for ; Mon, 04 Dec 2017 12:05:20 -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=TPnv7Zbq5+uN1eKyyK1InBQyxZPR10nyO24TZ1woLCR9h79y8ahJHPK3x4zIvbM8th LhHWRXS6XpsJ8DRrgahLztwBiaFndb7aSjSSfAJnUT3lYBcA9QKeJIyL3xDm80dGBdkf pChfNulpgymIN1ioM2he6ui+C7z4Hz0aHZ8OHxwyxb6ZA2oIAicVeh3pb5zfyRGIaLSe E51A3/zmPc+MAMnyzOAyxdhmb3dNPE+y4jcY6L9oxvoBIAP5CnXoiy7B+DrWloDZe1jU 0nmZjycRmQdaT0+M7hHicZDm9XgtVKMGemxlhA8KaAqbZPYeHBep9yPjT89KZ8yrDoEV gJLw== X-Gm-Message-State: AJaThX40JUiLKUYY5pFKBvK23em/q0h13KDWcleoysKIV3yFSR3m3gHQ zpH7YKtQvZvs3CXXzC+c6y/Vow== 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 Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Christoffer Dall 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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;