From patchwork Fri Jan 12 12:07:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160679 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 E6599602D8 for ; Fri, 12 Jan 2018 12:44:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D50B9289E0 for ; Fri, 12 Jan 2018 12:44:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA00E289E2; Fri, 12 Jan 2018 12:44:37 +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 6F492289E0 for ; Fri, 12 Jan 2018 12:44:36 +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=Qsr374A+saxmNlMum6weop4XO/XlL+JJLCRl/JQXG9w=; b=FORcGcamZG1O1NOG04QnA8buw9 rypE+EdTRjYn9Ep/I4wJ717MNSJTl7dhf+79dDQqVOuNWoVwcQLH6ddZmnoQGxKLu7pjL/l2M5LLJ wKoDB1IYFJutYwSn7bvAjBmPZ2HL6DatYL9wqJ6hz803p3f7cjMNq8MMAUMTIIQgrIDr8x4t09PTM kJpF9mFt93nijwEpC1jURCSmSCDthSV/ySzW7zaLdOU4cVWjFkWq6P9SNuZAsWIeh9SVNS/WQq2u1 wvW68X6at/vUrSH96SUPAAF4jHqDvZxWmIP/NOR+MczXBtzZQSf7iusf7Xbn+QpoWbTHYB6G8xtnd xbaw9OUg==; 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 1eZyhE-0008F9-5I; Fri, 12 Jan 2018 12:44:32 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZyhC-0008Eu-8A for linux-arm-kernel@bombadil.infradead.org; Fri, 12 Jan 2018 12:44:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=yiirL/AUx5B/ulI7m1PnG+Lsm8x8MhKo1yuzSTtiB3I=; b=CUjDYK4Q/uorLuRa0ObSZGoV2 n1mgoGWqoHufE+Kxn6+njR2pP4d6DtmR93jdnlqWmAcAVkWg7x+0avy8el19zCdhRQPGlApaYieeq b0nCkXknZEQ5aDsXhKNw94JbukrWM4nf/YhZ221MMR4PDOUWNtxG0shiCUlH4yjVjnzkYOCC99q+p gyn9uluE7qBGzo3OFKc9bEZ/nGuiZUmpfNWJEFpmwPLtDzNvDwIZlUqmmjSQdsqYIyrteQ/AQ5Fpf nHj1B2h8J8DFQvmPzeWVuuy+2sQiGWQaBQI5duq9NvTzBjW6ElQLSwQGeWTd1HaFBC8a2lo9/OU0v IO3KPXqDQ==; Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZy8g-0003LO-QQ for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:08:51 +0000 Received: by mail-wm0-x243.google.com with SMTP id v123so2213532wmd.5 for ; Fri, 12 Jan 2018 04:08:40 -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=yiirL/AUx5B/ulI7m1PnG+Lsm8x8MhKo1yuzSTtiB3I=; b=FKD6sjNRiykn+JSK2ZHnZtSqUivzI0g8e3nvhB2uHrzJJ8FtsUZ0uZD43fQo0q1WJl Cb8PtZJ5iLpmua+bvmoapZXZjK+DNtfSfDmLdwk6KEhtFQL/zkvvnmTvBxvt3/CPSuMR L9LRHmUNafkuxTdAHzCZCtlLiKmqLJrvJzOTA= 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=yiirL/AUx5B/ulI7m1PnG+Lsm8x8MhKo1yuzSTtiB3I=; b=reUAv+uZJAxPEIGAq8irV7YiAubbFygJkSccJPxbJF33adr63lXm6tA8Y6QNMt8mAn YLMwVm6NeXTJ/YlRaSW+Xk4NtHwIM0o5TJC3iskIltY3lQiV/3x+GQqY08dR2LElnpY3 yXPPhFM0kzC2b6hmK/F7jTDgr8bburBhY/CRe4jB128rh0NNU+zVEcVpgFff3HIoziim ISExqEV/AZnAAoLXMjLKOVpC/1GsZNEJA6c4893m8+e/qHunSI9AzBkbbeCSmO9J7MJ1 Klg1x8sM3xgyWLkc8poAjwKHpZ2N5PUTMeowVbfBcvji5pGVQlhx7L8mwNwFuZvi7ens XsZA== X-Gm-Message-State: AKwxytfmFVIc+Ao7Z6mc91gCkW+5LNXslV4o7XJsuL+ocU0SCOdGfPe8 +RfQtcXO3yJ2B7htlrEZ0WdB3Q== X-Google-Smtp-Source: ACJfBotPo15y4ckEcO677rDFE03Mgrd+9kHc/PlIgMQuhMLZdoZZk4CWHx8RojjrlwMfnjwZCWcDeQ== X-Received: by 10.80.165.243 with SMTP id b48mr16049117edc.201.1515758918702; Fri, 12 Jan 2018 04:08:38 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:37 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 31/41] KVM: arm64: Defer saving/restoring 32-bit sysregs to vcpu load/put Date: Fri, 12 Jan 2018 13:07:37 +0100 Message-Id: <20180112120747.27999-32-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-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 When running a 32-bit VM (EL1 in AArch32), the AArch32 system registers can be deferred to vcpu load/put on VHE systems because neither the host kernel nor host userspace uses these registers. Note that we can no longer save/restore DBGVCR32_EL2 conditionally based on the state of the debug dirty flag on VHE, but since we do the load/put pretty rarely, this comes out as a win anyway. Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp/switch.c | 6 ------ arch/arm64/kvm/hyp/sysreg-sr.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 2e04d404ac82..05f266b505ce 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -355,11 +355,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) __vgic_restore_state(vcpu); - /* - * We must restore the 32-bit state before the sysregs, thanks - * to erratum #852523 (Cortex-A57) or #853709 (Cortex-A72). - */ - __sysreg32_restore_state(vcpu); sysreg_restore_guest_state_vhe(guest_ctxt); __debug_switch_to_guest(vcpu); @@ -371,7 +366,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) } while (fixup_guest_exit(vcpu, &exit_code)); sysreg_save_guest_state_vhe(guest_ctxt); - __sysreg32_save_state(vcpu); __vgic_save_state(vcpu); __deactivate_traps(vcpu); diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index eabd35154232..d225f5797651 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -195,7 +195,7 @@ void __hyp_text __sysreg32_save_state(struct kvm_vcpu *vcpu) sysreg[DACR32_EL2] = read_sysreg(dacr32_el2); sysreg[IFSR32_EL2] = read_sysreg(ifsr32_el2); - if (vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) + if (has_vhe() || vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) sysreg[DBGVCR32_EL2] = read_sysreg(dbgvcr32_el2); } @@ -217,7 +217,7 @@ void __hyp_text __sysreg32_restore_state(struct kvm_vcpu *vcpu) write_sysreg(sysreg[DACR32_EL2], dacr32_el2); write_sysreg(sysreg[IFSR32_EL2], ifsr32_el2); - if (vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) + if (has_vhe() || vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) write_sysreg(sysreg[DBGVCR32_EL2], dbgvcr32_el2); } @@ -242,6 +242,13 @@ void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) __sysreg_save_user_state(host_ctxt); + /* + * Load guest EL1 and user state + * + * We must restore the 32-bit state before the sysregs, thanks + * to erratum #852523 (Cortex-A57) or #853709 (Cortex-A72). + */ + __sysreg32_restore_state(vcpu); __sysreg_restore_user_state(guest_ctxt); __sysreg_restore_el1_state(guest_ctxt); @@ -280,6 +287,7 @@ void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) __sysreg_save_el1_state(guest_ctxt); __sysreg_save_user_state(guest_ctxt); + __sysreg32_save_state(vcpu); /* Restore host user state */ __sysreg_restore_user_state(host_ctxt);