From patchwork Mon Mar 20 10:58:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9633745 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 7961D601E9 for ; Mon, 20 Mar 2017 10:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B96627F17 for ; Mon, 20 Mar 2017 10:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6077127F94; Mon, 20 Mar 2017 10:59: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham 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 EDFB227F17 for ; Mon, 20 Mar 2017 10:59:22 +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=WF+s0ECn0skXoJcUxq0cJWV4lJS5OmUFUFKpfliMB6o=; b=XMX6j6yISqFG8gXFdto/2xNtQC MqTxIYnP+bdlX30NF3FvPHKczmmxuO5ohl0GJasdD1+fnlXxkkzl2kexHz6jdhBuCp4ySIhCRRkuH oysMx/dIJw2Z0TqtCKEfWVr0fkZQPy4wzk3VYil3gGbe41DD4f+hhMYhqahBEquTvGPX3DdEiGtma ybp/ZTqRTYigISgMq7EKKCvbk6JUbTapddlI0TG8Zwgegpz0Tg32q1sUGMYs1JawAlb0eN0wge/ds oJlmz5aneCFJfK1PDuD/Gauc8ndHA4q7u2fb4dtmge4nrCWTIzfeRjTrVwpxMDzeA1bowyOnuyAjU emalUDOA==; 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 1cpv1y-0006n4-Mo; Mon, 20 Mar 2017 10:59:18 +0000 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cpv1U-00066t-DG for linux-arm-kernel@lists.infradead.org; Mon, 20 Mar 2017 10:58:52 +0000 Received: by mail-wr0-x234.google.com with SMTP id u48so89500195wrc.0 for ; Mon, 20 Mar 2017 03:58:27 -0700 (PDT) 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=5sk6JScLhWReZRAIZNokFeIGmSgSIVYOte1lrHpoKMg=; b=N6TKV5Hf/f+8jzdVVxpxYAMCUMBO0PUQuybXcCcJGFPU4kQwLIapPwFsIwr3P0bE6W zQcpS3n4I3KQ9f+NCVUKffHn9wONvU+wwSnlCoeUcXfMMwTbYkFSFgETIywHmP+NdoLk tRr2zO54cgwyiskc/ACpoomnbpP4MagNmmN7I= 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=5sk6JScLhWReZRAIZNokFeIGmSgSIVYOte1lrHpoKMg=; b=ScmCEg0TOj+oXDVy7ivrnu4+C+7C+eK2wtMpNEpn3CreihmnOtL4Ef4QYYDWD8MpNw azGp2xkAFt0w7WELMaODxJ8oeSGp4qF56VbrJqoKIqKin91QDggiUmUfZsCRP6Nq/y7s WzGJwXEsWynhZ/lsfvEriCBSnCSjs6z8ZAEEE2sQicGPxOsldmLTaheEN3QMVUzo5BDx qUgFbu3gbIbhFSbTFjO8d7byeum5haqmzqSU2i57SJwd5lb+DkRe6i2+3UOeg4tsgi28 SPwyvj6e2KsbEk6+812Fbcoe4K3SNfG13YyzxfbhZbKkmTZsJDvqOlPF+EohDoc0//H1 7+Sg== X-Gm-Message-State: AFeK/H0AjqY6pVln59f03U3rcIy8UIjk1Z59JCb5PfO9qpccem9DrfSeTQMVJEW/AEiZUpXl X-Received: by 10.223.176.143 with SMTP id i15mr26139034wra.136.1490007506534; Mon, 20 Mar 2017 03:58:26 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id q1sm10372065wra.65.2017.03.20.03.58.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 03:58:23 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/9] KVM: arm/arm64: vgic: Avoid flushing vgic state when there's no pending IRQ Date: Mon, 20 Mar 2017 11:58:11 +0100 Message-Id: <20170320105818.20481-3-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170320105818.20481-1-cdall@linaro.org> References: <20170320105818.20481-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170320_035848_744988_D6CD0B00 X-CRM114-Status: GOOD ( 12.42 ) 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: Christoffer Dall , kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Shih-Wei Li 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: Shih-Wei Li We do not need to flush vgic states in each world switch unless there is pending IRQ queued to the vgic's ap list. We can thus reduce the overhead by not grabbing the spinlock and not making the extra function call to vgic_flush_lr_state. Signed-off-by: Shih-Wei Li Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 2ac0def..1436c2e 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -637,12 +637,17 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu) /* Sync back the hardware VGIC state into our emulation after a guest's run. */ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) { + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + if (unlikely(!vgic_initialized(vcpu->kvm))) return; vgic_process_maintenance_interrupt(vcpu); vgic_fold_lr_state(vcpu); vgic_prune_ap_list(vcpu); + + /* Make sure we can fast-path in flush_hwstate */ + vgic_cpu->used_lrs = 0; } /* Flush our emulation state into the GIC hardware before entering the guest. */ @@ -651,6 +656,9 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) if (unlikely(!vgic_initialized(vcpu->kvm))) return; + if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) + return; + spin_lock(&vcpu->arch.vgic_cpu.ap_list_lock); vgic_flush_lr_state(vcpu); spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock);