Received: by 10.223.176.5 with SMTP id f5csp953462wra; Tue, 6 Feb 2018 10:02:08 -0800 (PST) X-Google-Smtp-Source: AH8x224Qj0HatmhF9KwDNfvlEo8ILN5vvFElj2Fbyb4y58vmn9IdmR3oR1nWKuGu2MCCKrGuAPxU X-Received: by 10.99.103.129 with SMTP id b123mr2555590pgc.177.1517940128566; Tue, 06 Feb 2018 10:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517940128; cv=none; d=google.com; s=arc-20160816; b=vn0H/YFBfg0BK7Vb5ZuxzDzGfVcwykKUuSvM4xxEuA0/IhnNKV8dQGlnfAYNjG/zsH kz+FkxsVqxNZwuIz65OzucjV+kApdyY/kM5NoS0P3gytesE2bBLknWMJinQQ0MJrRz+b LR6W2mgRARdFqM71ZNv8OoVA/w/c3Zwbp+qO4GFCwy+obrxjTnf6fL2h4A43SBVYG0kE krwmISun7oOwS0byNN4yxpTUnpE8aqbFziyqvxAE4PllXB+5lTJ6vlnf9VZXcJPcPX6u +uv/8ND1e+oFPQ7ICgx6jwu+FFQsgJsJjYbXOoK8N15cauJ89+fHqu3m7RlJStoQBRyI GcfQ== 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=02lOYbGJR2Oo67r96QxSCI31EE7vEFSaeGEod1Y0rKA=; b=s3K4wwn6qt8IIaAh2m9ksaHoPJTkFkZiRMLx9fsvRyy7azNYAiOOakOm5P1vNEavqJ haJIZFemzqNG2lI9sexFcoNQfDo6/LEBNlvtSlehdTuQKh7zI2/J/tWfYAKxlKnfGHPU nAlv/trzE4walxJBWas7nlmnEkEaJwS3f68GeCKqWL1jjO6tR3wZ8LgzbLfZy82O5TXW ZEcWCi3KQtx4W4o5+iD+a/5RoK47iCD3W4xHBhKOiXg/3ThY7zPtsXcVcMNEAw/lFyTF 6dv1NS1cDNSjzNpcoy+oVwE8gtFppvlPmSsL25Aj9mJWDM8PNqHX35ZBQDjq6FAqwM1H 8peA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba12-v6si2741902plb.352.2018.02.06.10.01.54; Tue, 06 Feb 2018 10:02:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753058AbeBFR6f (ORCPT + 99 others); Tue, 6 Feb 2018 12:58:35 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41134 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752819AbeBFR5T (ORCPT ); Tue, 6 Feb 2018 12:57:19 -0500 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 C30AD1650; Tue, 6 Feb 2018 09:57:18 -0800 (PST) Received: from approximate.cambridge.arm.com (approximate.cambridge.arm.com [10.1.207.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 21C913F25C; Tue, 6 Feb 2018 09:57:15 -0800 (PST) From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Catalin Marinas , Will Deacon , Peter Maydell , Christoffer Dall , Lorenzo Pieralisi , Mark Rutland , Robin Murphy , Ard Biesheuvel , Andrew Jones , Hanjun Guo , Jayachandran C , Jon Masters , Russell King - ARM Linux Subject: [PATCH v4 11/17] arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Date: Tue, 6 Feb 2018 17:56:15 +0000 Message-Id: <20180206175621.929-12-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180206175621.929-1-marc.zyngier@arm.com> References: <20180206175621.929-1-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/kvm/hyp/hyp-entry.S | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index e4f37b9dd47c..f36464bd57c5 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 @@ -64,10 +65,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 @@ -100,6 +102,20 @@ alternative_endif 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 -- 2.14.2