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: 10098423 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 4202660325 for ; Thu, 7 Dec 2017 10:54:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C0332A417 for ; Thu, 7 Dec 2017 10:54:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20DF22A419; Thu, 7 Dec 2017 10:54:53 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 AC8C02A417 for ; Thu, 7 Dec 2017 10:54:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753119AbdLGKyt (ORCPT ); Thu, 7 Dec 2017 05:54:49 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:40373 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753102AbdLGKym (ORCPT ); Thu, 7 Dec 2017 05:54:42 -0500 Received: by mail-wm0-f65.google.com with SMTP id f206so12020686wmf.5 for ; Thu, 07 Dec 2017 02:54:41 -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=pNDW6379iFW9OPw+ofzf9tHcaSZ/G+dSdU/6txxWM0NxE7McPTTDA66DV8cBsv3gGs 0Zw0zxC0PKHa0LLckp/4MQ8hBOS9FeIA5eH91+D5p3SOjXi9q8P/Ssyxbr6lIz0YA6B3 3c+RDMvy3vUoaHS/s1KMevt4q1gGMcIA3ACJU/HL7QyEki9HW0id2YX+8ZXn/bdclHr7 SR/yoiILkbQ6oThiat26LPSwrkGGDd2vEn7WsccBxk8uOf/DGUc3nVAT/zNQtpw9SO+S kKPnbjixaE7zjNcSbMkS14yeZ/3sH3lLudAtdEba8C6ij4iAaV8k6ftWLXygjYlWzLT5 dF9w== X-Gm-Message-State: AJaThX6w83+BwCT41G/B9KpLXT6B8fccU6si2Mb8/ob+gnFIXNtraJLZ affuYf1KOjFU9ORBHfPxXgEfgA== 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 Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Christoffer Dall 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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;