From patchwork Thu Apr 12 11:11:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 133231 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1572659ljb; Thu, 12 Apr 2018 04:13:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48A8O/xrl9US8lL5M3JBQKT3pS52ONh6KsReu1SoZ8uqg2Um9a+RtT4wHWgFO3vjQO64waf X-Received: by 10.99.153.17 with SMTP id d17mr392552pge.62.1523531625818; Thu, 12 Apr 2018 04:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531625; cv=none; d=google.com; s=arc-20160816; b=poWRINlFzUm9DtjcdO6sOgIJ6SuQGmfemzjXH9ApFcC1q0R7zbnLyTRmW/7++qR6RX arqYHvfuLx/svpkC6TVRa8uLN0v+OdL64y8/d8VjSpSDpJz1tlbkcVUn8QqulV1++u1H Spv1qIcJs9Ym0MgrhPe8EU+CtFTDdF1nxqedLEmEF/6LD7OxjuQ5VfNpmAgJkY3M2UaP uMtPyR63OGMdwHHSVET1UM1Jp/1T6o+eRj7dThc6Gx8rwL8sHhZK3kjemcog65VvCdxJ yZKX32GkUfLwOibJ8utLa5uTPTdZjouOhpWwH7LtcFDEMOhzRrsL/53XRePOFA8/lYO+ dLmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=vHUyCLlcPoOpHL3tCoTHdQCpPdoCSRe76xgqy8XMII4=; b=t5g0JPzQ6dkniFZAc/K5DwPFYRzP8pVewgQkfn2DNX3Q+T2W/pjQGQ9YgIGPiQERd5 9jPbNaWdwkP+SiVogumA59LnJW2EKGxVeVPYITiCskqMwsFgM5ygFeCd0Gyty2Fme+iq xfZQZTVE/O2YjeRN5iCcC8griDZ9i33/zLc+nbWxpYEUHOsZ6q872FSnvH3RGDZXgQ9l eVtpW4fIg7+ysgm9MwcoV/J3mx5fj0mIDi8nyzDEqfnisUJubBbAPiGzgnwqhOgEgAvo 8I/2LhCy/96eQ9Gqqe9vVcBB0O9fI/h063wh55b1SmHYUi+1Hruii4ifiUeYfJK534Un /ifg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v23si2494850pfk.116.2018.04.12.04.13.45; Thu, 12 Apr 2018 04:13:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752973AbeDLLNo (ORCPT + 11 others); Thu, 12 Apr 2018 07:13:44 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59646 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752966AbeDLLNo (ORCPT ); Thu, 12 Apr 2018 07:13:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7170980D; Thu, 12 Apr 2018 04:13:44 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C330F3F24A; Thu, 12 Apr 2018 04:13:42 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.brown@linaro.org, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, ghackmann@google.com, shankerd@codeaurora.org Subject: [PATCH v4.9.y 36/42] arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Date: Thu, 12 Apr 2018 12:11:32 +0100 Message-Id: <20180412111138.40990-37-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180412111138.40990-1-mark.rutland@arm.com> References: <20180412111138.40990-1-mark.rutland@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Marc Zyngier commit f72af90c3783d924337624659b43e2d36f1b36b4 upstream. We want SMCCC_ARCH_WORKAROUND_1 to be fast. As fast as possible. So let's intercept it as early as we can by testing for the function call number as soon as we've identified a HVC call coming from the guest. Tested-by: Ard Biesheuvel Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/kvm/hyp/hyp-entry.S | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index 4e92399f7105..4e9d50c3e658 100644 --- a/arch/arm64/kvm/hyp/hyp-entry.S +++ b/arch/arm64/kvm/hyp/hyp-entry.S @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -79,10 +80,11 @@ alternative_endif lsr x0, x1, #ESR_ELx_EC_SHIFT cmp x0, #ESR_ELx_EC_HVC64 + ccmp x0, #ESR_ELx_EC_HVC32, #4, ne b.ne el1_trap - mrs x1, vttbr_el2 // If vttbr is valid, the 64bit guest - cbnz x1, el1_trap // called HVC + mrs x1, vttbr_el2 // If vttbr is valid, the guest + cbnz x1, el1_hvc_guest // called HVC /* Here, we're pretty sure the host called HVC. */ ldp x0, x1, [sp], #16 @@ -101,6 +103,20 @@ alternative_endif 2: eret +el1_hvc_guest: + /* + * Fastest possible path for ARM_SMCCC_ARCH_WORKAROUND_1. + * The workaround has already been applied on the host, + * so let's quickly get back to the guest. We don't bother + * restoring x1, as it can be clobbered anyway. + */ + ldr x1, [sp] // Guest's x0 + eor w1, w1, #ARM_SMCCC_ARCH_WORKAROUND_1 + cbnz w1, el1_trap + mov x0, x1 + add sp, sp, #16 + eret + el1_trap: /* * x0: ESR_EC