From patchwork Tue Nov 7 10:47:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10046335 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 A47BC60360 for ; Tue, 7 Nov 2017 10:48:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 816CB2846F for ; Tue, 7 Nov 2017 10:48:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7657F29D1B; Tue, 7 Nov 2017 10:48:39 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 1ED672846F for ; Tue, 7 Nov 2017 10:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757381AbdKGKsg (ORCPT ); Tue, 7 Nov 2017 05:48:36 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54813 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753411AbdKGKsW (ORCPT ); Tue, 7 Nov 2017 05:48:22 -0500 Received: by mail-wm0-f66.google.com with SMTP id r68so2830393wmr.3 for ; Tue, 07 Nov 2017 02:48:22 -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=u4ItikNZsLOCbUC5ApofQ39TyxXzQ7zBKps26Qop5fo=; b=idyPkehHigLqdbODhXBrKKhHbF5efq7UBbQXECnRtB+3e5ykbnMv77UlJ0oYwjLF5r aNUPEnYZF4syvrlXYk/wpQb5s1X3t9fsU+LCzM9i562qHHtw8rceTTSe1Fq5ZPylbtVa EUqMuLdEARFoLvPU3nPOPXNsSGGblSmKLQhfg= 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=u4ItikNZsLOCbUC5ApofQ39TyxXzQ7zBKps26Qop5fo=; b=CXe9bo7UHr7IIu5FOojc94956nWx/EtdfhytMiYdM0+8RY2BZZXYyC8cnpZYMfQG7H rL6XygcFSa9j4gJfdMV0xBiwRMXTZJb13fj3xeBEIdBW/NcrRSnHBjw/qgfEGL/WVqjF wJuAWmD5WbZyiv9oJcAMGlvJLT5mYxVtTZnOZOMU5o+U/jVSnZaxHka8SVrisry/z6HS zZasqnMjCa1CtIj0KJXGmAs7Tlu0MEhWfm4FHPJghYreZSas+Qok/QcpIGRvX9zjwoIU zQHRXb2ol+qGhmBwjzvkb+oHzY4DBK+yto03VuZMjhbo0zTb43XX1GIigJLIP6hcHb5i zAMw== X-Gm-Message-State: AMCzsaVG5yWIwMuPXNRjq9LKTbM2ep0mRV8ho/al/1/xoqtCEOJkDqH3 MGwknjxtX2c09aJ4TsRgz3YZTg== X-Google-Smtp-Source: ABhQp+QgHfTOy1bh6RkNRHy9MWk+F0UCgEB1A4ns0miO+Kx+inoqyqZTgLDubnBnw0MPsZZO6iVaaA== X-Received: by 10.80.169.78 with SMTP id m14mr24058870edc.118.1510051701513; Tue, 07 Nov 2017 02:48:21 -0800 (PST) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id q12sm1044958edj.29.2017.11.07.02.48.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Nov 2017 02:48:20 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall Subject: [PULL 08/26] KVM: arm/arm64: Move timer/vgic flush/sync under disabled irq Date: Tue, 7 Nov 2017 11:47:41 +0100 Message-Id: <20171107104800.30021-9-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171107104800.30021-1-christoffer.dall@linaro.org> References: <20171107104800.30021-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 From: Christoffer Dall As we are about to play tricks with the timer to be more lazy in saving and restoring state, we need to move the timer sync and flush functions under a disabled irq section and since we have to flush the vgic state after the timer and PMU state, we do the whole flush/sync sequence with disabled irqs. The only downside is a slightly longer delay before being able to process hardware interrupts and run softirqs. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- virt/kvm/arm/arm.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index b9f68e4add71..27db222a0c8d 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -654,11 +654,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) kvm_pmu_flush_hwstate(vcpu); + local_irq_disable(); + kvm_timer_flush_hwstate(vcpu); kvm_vgic_flush_hwstate(vcpu); - local_irq_disable(); - /* * If we have a singal pending, or need to notify a userspace * irqchip about timer or PMU level changes, then we exit (and @@ -683,10 +683,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) if (ret <= 0 || need_new_vmid_gen(vcpu->kvm) || kvm_request_pending(vcpu)) { vcpu->mode = OUTSIDE_GUEST_MODE; - local_irq_enable(); kvm_pmu_sync_hwstate(vcpu); kvm_timer_sync_hwstate(vcpu); kvm_vgic_sync_hwstate(vcpu); + local_irq_enable(); preempt_enable(); continue; } @@ -709,6 +709,16 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) kvm_arm_clear_debug(vcpu); + /* + * We must sync the PMU and timer state before the vgic state so + * that the vgic can properly sample the updated state of the + * interrupt line. + */ + kvm_pmu_sync_hwstate(vcpu); + kvm_timer_sync_hwstate(vcpu); + + kvm_vgic_sync_hwstate(vcpu); + /* * We may have taken a host interrupt in HYP mode (ie * while executing the guest). This interrupt is still @@ -732,16 +742,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) guest_exit(); trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), *vcpu_pc(vcpu)); - /* - * We must sync the PMU and timer state before the vgic state so - * that the vgic can properly sample the updated state of the - * interrupt line. - */ - kvm_pmu_sync_hwstate(vcpu); - kvm_timer_sync_hwstate(vcpu); - - kvm_vgic_sync_hwstate(vcpu); - preempt_enable(); ret = handle_exit(vcpu, run, ret);