From patchwork Mon Feb 26 08:20:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129605 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3361476lja; Mon, 26 Feb 2018 00:30:15 -0800 (PST) X-Google-Smtp-Source: AH8x225aLOANYlIu3DXePd2dvlOgdsimffC4k0N8aTOyf4LP9QXZ0EwDWWM7JuGxbIgHVu1LqjLl X-Received: by 10.99.103.195 with SMTP id b186mr7818540pgc.446.1519633815179; Mon, 26 Feb 2018 00:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633815; cv=none; d=google.com; s=arc-20160816; b=n3BQWdKwAWbJOiA+JP6+YGO2d1cnTFNMD46q0r3Of1TkTsmLEZmqHvEgue/+Xou66R nYEGiydhqhJGj/YiJtQsPt/50M7EXDazjsEse0kiOHipU8T0TLFWtsy5RRdQ1LB6h2NX DzL+/m/FIF6vYIQ0ZrgR4lykLDwGbEt9Buf3pf7oIKejAYVQjBPJ43RG72N6rQBivUbk j02bsAGc8u2vjcOZtf4Fb3pzBNmsBfxlnW7A3g4Fc55vfrgruC1FcdxhTjI5iSh+/Sh9 zHwCfC0bsJ0eg2jHRGr8+b86ajBTPi4kM5VTMTT1vTeZXPtDPDoIKTx77u2dUHQDCJew v2NA== 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:to:from:dkim-signature:arc-authentication-results; bh=Jl8J60UuHWw6QycIueIONGAI64GFje0f/SkXAPYopdo=; b=Q4srWKhQmzakL386X3i/07Ryr3OxnebsQneBfbWxx7tmBanpHEbbNTafmqR0P4agwm GYok/eaLEbZhGitP0MTHCM/BfVn5XCwPuN2hWDeZz3UVKC2jmzx7R8fW16YWbInqEpQm W78MW2yPUIlyXwywsdgN83FW7N7TEqTtv4cWRDndlqxgNPdkvkANC/QMe7MCmqtoZqge LPIuXyaFaMdoX22fyflzvPDyu9LxqPL6qHgtYnnaBlNeJKQDppkwrz/MK4wByYqIRcXk RbpwewYsIn2yu6Uw2XMunHvxBqc3jxwVlMNx/Vh4QSbnjGaugR5gvl0RTKbw5VDoZ4qX aWRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CYKbZ8pn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i130si1118048pgc.460.2018.02.26.00.30.14; Mon, 26 Feb 2018 00:30:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CYKbZ8pn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752731AbeBZI0Y (ORCPT + 28 others); Mon, 26 Feb 2018 03:26:24 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:32913 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752391AbeBZI0O (ORCPT ); Mon, 26 Feb 2018 03:26:14 -0500 Received: by mail-pg0-f68.google.com with SMTP id g12so5913663pgs.0 for ; Mon, 26 Feb 2018 00:26:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=Jl8J60UuHWw6QycIueIONGAI64GFje0f/SkXAPYopdo=; b=CYKbZ8pnDKagzMCcokfegFOCOhRYPmf2YAjOPU029FgdAmQX73CpGyxaer6cII0oaS voEFKNYHIDz87nM5+wC7Gxn/nncRUADnG1v+jkzMK5FplMC2Q62zdZUhN65W5J3u89pA 5gop4xM+s89hQGsTahh2hI7y/QvemIodSnaoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Jl8J60UuHWw6QycIueIONGAI64GFje0f/SkXAPYopdo=; b=pOBnsCW1dLcDTqq//nvtREVa9PnisjvCSGfKrdUuTZfhL9HwX9wqSxzT2iqSC0WmsX n5XpbiTf6EKg7t8oj7FfLgtBvWhdOSH7vCUUo955OtXdCGRph9BF012pj3+07Y8h3478 iKD+13f4hZvZryDid583KRdomMOXv8wRVkKHTGQOL8dFQRep5fpnc22Ymju3ggHKMuFg V8SsRRPgY9hNXkRn+kaa324SeLWtfyEF23yboVKNhI4/0ECn+XXsZsl+q1D9P+6wLHgJ A1O1CK8O9+6RT5HgjQ3bENn0NpcgF3O1yfTpJgKTR82MWOokj7cPRUtZSAb2QapAv4YU kqpA== X-Gm-Message-State: APf1xPAKU3gOpRrXnKZcuIik5I+sr/AjDbyOu+Z5xsodw37vjNJTqp/e aqN1Pld3HOXOfkQL4ewqNdaOYg== X-Received: by 10.99.121.203 with SMTP id u194mr8076290pgc.232.1519633573562; Mon, 26 Feb 2018 00:26:13 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.26.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:26:13 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, Christoffer Dall , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , linux-arm-kernel@lists.infradead.org (moderated list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)), kvmarm@lists.cs.columbia.edu (open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)), kvm@vger.kernel.org (open list:KERNEL VIRTUAL MACHINE (KVM)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 39/52] arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Date: Mon, 26 Feb 2018 16:20:13 +0800 Message-Id: <1519633227-29832-40-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit f72af90c3783 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: Will Deacon Signed-off-by: Alex Shi --- arch/arm64/kvm/hyp/hyp-entry.S | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index 4e92399..4e9d50c 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