From patchwork Fri Jan 12 12:07:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160653 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 E494960327 for ; Fri, 12 Jan 2018 12:27:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCFA9289D3 for ; Fri, 12 Jan 2018 12:27:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C02E0289D7; Fri, 12 Jan 2018 12:27:24 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable 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 1B906289D3 for ; Fri, 12 Jan 2018 12:27:24 +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=ZRuiYUIW9XA3ueDKqduImGmVXsrzWcZ6Rty6y4bNeWA=; b=p0AGNFnQKunhJKyT9J+42nAkS3 TEd0dKRSyQX88Ir2D2e5s3wrE6NTM9WLjHb98vqkNyYAej0Mq7v9fxxG1fEBE8mnxPyz2UYJ9Cf5N gTLu39PpEifEpk7N35rvH2IPqOWw7sv7HRpTwdyxeVIANVC3fp9MiERK0ad+6naQjz26Niu6a24e8 wDI4CmZutl2My13OgUXEc0CJvK6LEzAIblkjm95FWr62CovFjnmi+446u6867dEa/cBfG5itNB0Nj eO3umwHbpuwABgbikop7NE97eJVn6NK1/kyCe0lOqCRsdN29dveqkL0PSXP+/O4UpoVtOBj4t6l6b 8HqHzVng==; 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 1eZyQc-0004f3-83; Fri, 12 Jan 2018 12:27:22 +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 1eZyNt-0007Yb-Kt for linux-arm-kernel@bombadil.infradead.org; Fri, 12 Jan 2018 12:24:33 +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=iHVwBD4V3g4FvBzIYDb39UZN322nvbg00ZfXyQ5nUX8=; b=rfaHk/ZmQ0alV/xTgmV1fBl8P /gJ26A04RxLCJs9LktgRHdCxwAI1jvaegtUza3/UQj0mSP1j+Tv19unIsb0wpHXLH/SL0fNgDfZiM sIFROtKub9cpmJKJEfHTPnu3v6A6OqG6FjOCrOhIKhmtqQ/4tDlQ2wK2Z5qKZzPn5uYe8vlYq8yoO Xx+sOaJBmSY7FdLDN15Um6Xei5BI1j1OrLHT1JG9ja8+3cxtgOZAHrBhryPgXAVJ+5BUbWZQChNWK fEbgNtLwJKuPmi7yNync/B4ePSVPjC8LpJFOJkXvrLanLraWgS5ow3d30oIYG3C8a0ObjvQxuSbbR z1+yZRiug==; 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 1eZy8i-0003As-Py for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:08:56 +0000 Received: by mail-wm0-x243.google.com with SMTP id 141so11316971wme.3 for ; Fri, 12 Jan 2018 04:08:51 -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=iHVwBD4V3g4FvBzIYDb39UZN322nvbg00ZfXyQ5nUX8=; b=eJRHqwJDGEC+t07daBHSqzLCbfVUBkvHvzk+Xq6PTVpddp+tGSytkMpqHlxCj5Wulx 0YkKxxeaUQRK7xX5QhPyoWScHZzmPCNG7yemanumU34uCZIztpL1NYkOMLu9Et05/Ejx RwQJ6n0fX3ynjYP+QBZxHoxpVq6cMZ9RB0fQ8= 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=iHVwBD4V3g4FvBzIYDb39UZN322nvbg00ZfXyQ5nUX8=; b=tm4BGykc8Gzm/3DlL3t7eAsoLbt+Qe/KDA9EjT5qpwZJkHv9/w1CvNGhjB5BmIQ5xT XYkPeDxGp3g4EBHoyOL5d4UtyFYQGOubJ1YiKlabM+3XlpNUY9Mv/2h9jCP08uGl8Zq7 mysy2mKlgV8F9ZDWKyITD9gFBQevx4Ffv19ZEbjc7vcYUDfVa49tuI8JgLFppV5NidvK Z/adpiHxuYcyostcR5ecD80p9sGPuS0q4Apx1FcknGaHQ5k5mQhYCDI7aIb8DeBeLfr3 TUISdC7Sdd0jPydboZLZOpVeBD399ew9Arz4uxZJxYV4CCrk0pj/Kc1Y7VFj9dnSj31W dmwA== X-Gm-Message-State: AKwxytdAVU8cX7g4ptS15RQxmnG7SivsDe2MsGOLMMzdKveLEl2W7/Jy v4Y5VSW6U+3aIrRIb9B6setFkw== X-Google-Smtp-Source: ACJfBovIKl0sFvtxxFtBbCJDoZLoGr9X7g8WUH2LITyyDJ7hN+G9di2nduNU6kC+DbyfFoMZCH9ylw== X-Received: by 10.80.136.85 with SMTP id c21mr2329961edc.259.1515758930233; Fri, 12 Jan 2018 04:08:50 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f16sm13489705edj.65.2018.01.12.04.08.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:49 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 39/41] KVM: arm/arm64: Handle VGICv3 save/restore from the main VGIC code on VHE Date: Fri, 12 Jan 2018 13:07:45 +0100 Message-Id: <20180112120747.27999-40-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180112120747.27999-1-christoffer.dall@linaro.org> References: <20180112120747.27999-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180112_120852_883083_C0518524 X-CRM114-Status: GOOD ( 19.05 ) 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: Marc Zyngier , Andrew Jones , Christoffer Dall , Shih-Wei Li , kvm@vger.kernel.org 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 --- 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 74b7d7598a51..9187afca181a 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -395,8 +395,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) activate_traps_vhe(vcpu); __activate_vm(vcpu->kvm); - __vgic_restore_state(vcpu); - sysreg_restore_guest_state_vhe(guest_ctxt); __debug_switch_to_guest(vcpu); @@ -408,7 +406,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) } while (fixup_guest_exit(vcpu, &exit_code)); sysreg_save_guest_state_vhe(guest_ctxt); - __vgic_save_state(vcpu); deactivate_traps_vhe(vcpu); diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 6bce8f9c55db..7aad3aa43dc9 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -716,6 +716,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. */