From patchwork Thu Feb 15 21:03:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10223721 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 9355C601D7 for ; Thu, 15 Feb 2018 21:31:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 818622953E for ; Thu, 15 Feb 2018 21:31:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75C5F29541; Thu, 15 Feb 2018 21:31:47 +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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 007B02953F for ; Thu, 15 Feb 2018 21:31:46 +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=A7wXlu+lwK+/lsWwWirCKTq0rsfquokuekIg3hKFgqM=; b=pMb90zywYk94e6SmC5z017AFzt 1biF6eAYrK1xJyFmFrU8r3kXk93NmOJwuVU8DN4Aoysm3tMJv0Yu6oYLyajEK4t0DPL+LVY3EhU4y J70ysgYsPt3lawIbDnfOfEflFUSqYzwssqN0XJGVTbnaZbgLWt8kPTawDjWuMnD67mDZYnasU4dLX IEA5HuzkQdIHTEwUxiaFs5Yhyfn9Cgsnw/kv7mb9P1IkgedvI7AYa8kOnSKqTuPdo4XDF5At2qptk ENvmdTh1ziiwTJd+7H1U/NxdjVCLgfVf9nrFe4WuFTFo8EuDRkH81Ezhy59PVS6ZJoKNl4kZb2LUu mqTOruRw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1emR7o-0007IF-MQ; Thu, 15 Feb 2018 21:31:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1emQwd-0005MU-Dp for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Feb 2018 21:19:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OY2hkBh33UdIr/Y87sd/Q68g8ML3ivPGgPKty3ch5x0=; b=LZMfTAB6t8Rj1iOgLGtlo6C4W wdwO72Z9gfy2RrXDUKeGdIuMrPk6NyhIzdRJ4zescpIVDLbRPtEtx6iGKTmK+mviZMwCGYY9MzPYa M6SUxWnpiFpPMjY57eh4QKZQI4ZQoE6FPAYQrurYPzICuf/OJ5tMPu+bRRLmAqSGFqqJKpokqugvg s1aUkH5GJwK3svOJmQIqnb0H+0w5q9d3C+JDX5t3LeGSQFVxymcqIVwIMtkIJf+wO8PczfsAhEt/P dTDZAMfXoCawhlEyHghjz1IzguFXr+POceNYlWRZnKtMzJtIZquHM0XJqIcD9oAZsceoa3Zu0XOlh 9a15noHEA==; Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1emQiA-0004hm-R8 for linux-arm-kernel@lists.infradead.org; Thu, 15 Feb 2018 21:05:00 +0000 Received: by mail-wm0-x243.google.com with SMTP id k87so3314790wmi.0 for ; Thu, 15 Feb 2018 13:04:48 -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=OY2hkBh33UdIr/Y87sd/Q68g8ML3ivPGgPKty3ch5x0=; b=fTh4XIB5d2kHgTb/qqGa3YYiFdl6/LtS9ZfP6mOBjixw2ucK7bo5hCP5hWmE3GKDN1 hunkXLWBYcy0qxXmOQ8SVUsL4ubnlu4HvIyP/Jariyucq/1ajpQD68bctoYM1pkeqNiX cm+qcQlpskQMOelIf2E15g7mTHnnsghrapkc0= 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=OY2hkBh33UdIr/Y87sd/Q68g8ML3ivPGgPKty3ch5x0=; b=G/2YSoVO97WHgZfldLupX8EHiSOuuOa/Pt9VNyD75NA1dmeHcf3wcq86jvRIucBvWm faSMRIL/JSTyD/Qban+uBwUANaByEFhrhKhjyEwDnvs/2aYIPlcglytcbIWwAK5nY7qs iptHoag9aqzfTJSwi/8FnvHpvIkC6JqnFBLWM9Uc3ncuR26sa1d8YDvpruiYYIbV7sm0 4kRQYbivAdbtMSLJ1yaVB6A8u6p8JY6MURVvrywJMCU9/Nl1DKa1+jZwUBfM+H9zVxK9 qN9Oaner3/C3WOsXqSGrCH3sIOXjNdjB43ldOg51P5PJRDn4kfjPrAW9IBXgyU+FdxST rUww== X-Gm-Message-State: APf1xPAMgj1qyeckmaZKcJLBDf3hlHlhBjo4M0ZReeeZpvIyTrfR4UHc qkDUU1Eg9HN+N3kqLiacVyTyUg== X-Google-Smtp-Source: AH8x224+Lefn+G5SkSKeGkB/LUGRQTKiSDKlihDtYeV+7Zuwen4siwhni7D5ReOIHnb8m/IPCPdhvQ== X-Received: by 10.80.135.154 with SMTP id a26mr5141648eda.82.1518728687716; Thu, 15 Feb 2018 13:04:47 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id p55sm8220030edc.15.2018.02.15.13.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Feb 2018 13:04:46 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 38/40] KVM: arm/arm64: Handle VGICv3 save/restore from the main VGIC code on VHE Date: Thu, 15 Feb 2018 22:03:30 +0100 Message-Id: <20180215210332.8648-39-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180215210332.8648-1-christoffer.dall@linaro.org> References: <20180215210332.8648-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180215_210458_887354_ADD579A6 X-CRM114-Status: GOOD ( 19.69 ) 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: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Christoffer Dall , Dave Martin , 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 Just like we can program the GICv2 hypervisor control interface directly from the core vgic code, we can do the same for the GICv3 hypervisor control interface on VHE systems. We do this by simply calling the save/restore functions when we have VHE and we can then get rid of the save/restore function calls from the VHE world switch function. One caveat is that we now write GICv3 system register state before the potential early exit path in the run loop, and because we sync back state in the early exit path, we have to ensure that we read a consistent GIC state from the sync path, even though we have never actually run the guest with the newly written GIC state. We solve this by inserting an ISB in the early exit path. Signed-off-by: Christoffer Dall --- Notes: Changes since v2: - Added ISB in the early exit path in the run loop as explained in the commit message. arch/arm64/kvm/hyp/switch.c | 3 --- virt/kvm/arm/arm.c | 1 + virt/kvm/arm/vgic/vgic.c | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index cbafc27a617b..466cfcdbcaf3 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -399,8 +399,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) __activate_traps(vcpu); __activate_vm(vcpu->kvm); - __vgic_restore_state(vcpu); - sysreg_restore_guest_state_vhe(guest_ctxt); __debug_switch_to_guest(vcpu); @@ -414,7 +412,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) fp_enabled = fpsimd_enabled_vhe(); sysreg_save_guest_state_vhe(guest_ctxt); - __vgic_save_state(vcpu); __deactivate_traps(vcpu); diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 5bd879c78951..6de7641f3ff2 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -717,6 +717,7 @@ 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; + isb(); /* Ensure work in x_flush_hwstate is committed */ kvm_pmu_sync_hwstate(vcpu); if (static_branch_unlikely(&userspace_irqchip_in_use)) kvm_timer_sync_hwstate(vcpu); diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 12e2a28f437e..d0a19a8c196a 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "vgic.h" @@ -753,6 +754,8 @@ static inline void vgic_save_state(struct kvm_vcpu *vcpu) { if (!static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) vgic_v2_save_state(vcpu); + else if (has_vhe()) + __vgic_v3_save_state(vcpu); } /* Sync back the hardware VGIC state into our emulation after a guest's run. */ @@ -777,6 +780,8 @@ static inline void vgic_restore_state(struct kvm_vcpu *vcpu) { if (!static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) vgic_v2_restore_state(vcpu); + else if (has_vhe()) + __vgic_v3_restore_state(vcpu); } /* Flush our emulation state into the GIC hardware before entering the guest. */