From patchwork Mon Nov 20 19:16:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10067077 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 3A436602B7 for ; Mon, 20 Nov 2017 19:17:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BE2029096 for ; Mon, 20 Nov 2017 19:17:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20B2C2935D; Mon, 20 Nov 2017 19:17:01 +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 9A1D629096 for ; Mon, 20 Nov 2017 19:17:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbdKTTQ7 (ORCPT ); Mon, 20 Nov 2017 14:16:59 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:39767 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752516AbdKTTQ5 (ORCPT ); Mon, 20 Nov 2017 14:16:57 -0500 Received: by mail-wr0-f196.google.com with SMTP id 11so5741113wrb.6 for ; Mon, 20 Nov 2017 11:16:57 -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=fOfUzEwcxJ1X37evDsv2vZhSDurJs2+nQ7SZ4k7MHSI=; b=aBPTTW3giTsG1czFbAkswx81THD3H6J8Ue3g1Wd31HehCTH6d4uxBpvR06E2FqrYh7 fSrV/nl/122uni06l8Mzi3kcaJOo0A6d3JrDgRFrsvK5FFK0BnL3hGieA0HeGVY5+dfq pa3V5yck6qCSqN4rkqo1jUpr4bN9xfS9Hpv+g= 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=fOfUzEwcxJ1X37evDsv2vZhSDurJs2+nQ7SZ4k7MHSI=; b=hZ2AARqdHYQGqjiAioaMVHJibPoaeJSICXMdpy5A4RgdfF1OmvWKsEQF1TYUkHBhld Wbte/IDyDjMBaB2lSu5VNi0cEbO9iboSf9EbWwalld3KEaKsgGGm1nIqKcuoh0cbcebU 52tWrGC4p6Cz4bWGql6BqID+cDJa2oVzH19a4XghCuHQNSDNeqy52uv3UDFhusRsYIQH GrHtWLTkz6H3kIv3lhVpTdwvDjesGWStt8bz0iRcwKmV/e83JMHuCxVzKn7vhoARClgF c9NBXeYUgEnQVjbQ0ehENRDheOaim2vn4zVKMC26AQlnnMxWFXUqwWV0qltInQSddJ5m kZPA== X-Gm-Message-State: AJaThX77RPGNQyVke0vktAqIxMkR6dnd4q/+hBt4wG5N6y+vMBEZeKpG tJwwdUj42zC0iIm7z8fRJPwRkJXqgqw= X-Google-Smtp-Source: AGs4zMbxvGl/7N4EDdtN9/1oak4zsZtpwysfJJSB8naVCT+6NsYOfV6s1pI3vE6/Wm2+jq9rSRJaSA== X-Received: by 10.223.163.22 with SMTP id c22mr3268591wrb.145.1511205416607; Mon, 20 Nov 2017 11:16:56 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f132sm3726885wmf.17.2017.11.20.11.16.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Nov 2017 11:16:55 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Eric Auger , Andre Przywara , Christoffer Dall Subject: [PATCH v5 8/8] KVM: arm/arm64: Avoid work when userspace iqchips are not used Date: Mon, 20 Nov 2017 20:16:49 +0100 Message-Id: <20171120191649.17290-9-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171120191649.17290-1-christoffer.dall@linaro.org> References: <20171120191649.17290-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 --- 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 bcde6bb99669..7b27316d4c3f 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); @@ -563,7 +565,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) @@ -768,6 +771,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) @@ -821,8 +826,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;