From patchwork Wed Dec 13 10:46:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10109699 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 6C17B60327 for ; Wed, 13 Dec 2017 10:47:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E8D128E70 for ; Wed, 13 Dec 2017 10:47:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5330E28F0E; Wed, 13 Dec 2017 10:47:23 +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 EFE7E28E70 for ; Wed, 13 Dec 2017 10:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752357AbdLMKrU (ORCPT ); Wed, 13 Dec 2017 05:47:20 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:45175 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752565AbdLMKqs (ORCPT ); Wed, 13 Dec 2017 05:46:48 -0500 Received: by mail-wm0-f67.google.com with SMTP id 9so4047003wme.4 for ; Wed, 13 Dec 2017 02:46:47 -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=BoXNK2lQArIM5aVV1recWGxAFSNggwqSmEyjntZ+Exo=; b=MVdbC3Qfp18+O2GGPdiDemCFn/0fn2CNmh8EJKcmgVnWJxvPuG0pVT63aAwdOzqLsM oIFxYCa1hHY0z1yvCqLD5YdnGcp+Jv5WWvMN0Bdo4FNXGha2epkeget2HfX+WCwUzTgT PKvAKJRtFczJnJg80d7m2tG6LU/8FkQ48rAOw= 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=BoXNK2lQArIM5aVV1recWGxAFSNggwqSmEyjntZ+Exo=; b=l+ORLuE4Wx5c+fR0ve4F56zg0QsZ7Qf4ksCKVweiVw8RjjLIMl9G/nvsTTJa/+xUo/ u6WvzE5nK1cDsObPR1j9dl88kPpK+SrajEA86oa5rpWPwoVSLNBFiqSl7ram7exWvSEg /iWIt8LxoBoOoztgMTG0rf61giS5oeagfMvokIUN9boQhWGj6Z5xpVd9PoftH05uAfNi e87Xh0vVC0mWfaM2NHx9lTdL0bCcYvShAuNNcDe3zH2NzUtKC+0/U4xNujZj4z/SQYs3 6IdhUfpit4DKN2lM9LNIAkqsdljl6aHiqlV8rnSpc2bTRYVGw9JurftXuwhX69XnTVYV mRcw== X-Gm-Message-State: AKGB3mKOWs+XGEBt9T5qF8dRVW+l0OxdSNMmZE60G1Twf2YNdDR/9LHr cDxzZNpS6tIybxTJTUvl1DyOxg== X-Google-Smtp-Source: ACJfBouE/K7K912gmlzQgFDzPTASY/oRi2VbNcTvNjzw6sIkTVIoSyNV7ka+LIKkL7GjhLAcnRXs3w== X-Received: by 10.80.244.141 with SMTP id s13mr7160877edm.222.1513162006779; Wed, 13 Dec 2017 02:46:46 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id d92sm1079682edd.21.2017.12.13.02.46.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Dec 2017 02:46:45 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Christoffer Dall Subject: [PATCH v8 8/9] KVM: arm/arm64: Avoid work when userspace iqchips are not used Date: Wed, 13 Dec 2017 11:46:01 +0100 Message-Id: <20171213104602.16383-9-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171213104602.16383-1-christoffer.dall@linaro.org> References: <20171213104602.16383-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. Reviewed-by: Eric Auger 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 f8d09665ddce..73d262c4712b 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); @@ -562,7 +564,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) @@ -767,6 +770,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) @@ -819,8 +824,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;