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: 10241689 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 605F360208 for ; Mon, 26 Feb 2018 08:54:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5777429D69 for ; Mon, 26 Feb 2018 08:54:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B08729D6C; Mon, 26 Feb 2018 08:54:42 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 A66972945A for ; Mon, 26 Feb 2018 08:54:41 +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:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gh91TWoTtJW/rhq9Md+RufHjtXL+GJn710eLVGgAEuA=; b=A0zjA0Zuk28SbE HLxc494f2Zg/IE98+SV+g8O7kPqsSIGspMgMj08iQ/CBTnyw8A4bFaXuRqJnd4w81FHwgQxZx8OFr XweQxaMjTD4lsPB84sK866EYJiIJIAKPoh6nHNt6Wd2zyhtEH0hFEuNFn8xXyUWiO7+142v8ZPCGH 9jY9aaHbeNKadk6rCVBlTXXZNQ6h3SFGUlZSDNVIs00Nxx9XuZ69wIQAplHPj5i6kDf7J0Su7dCQ0 Es/D237f2abLAj6mEaCz6HM3YTixhMuwtqMKqletSOh37/Y87TG12yiq9ziuFpyBdtDTF8izqZB0z qoAXG7tfb8XIt0wQE+5g==; 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 1eqEYO-0000a2-UT; Mon, 26 Feb 2018 08:54:36 +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 1eqEJp-000574-JF for linux-arm-kernel@bombadil.infradead.org; Mon, 26 Feb 2018 08:39: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:To:From:Sender:Reply-To:Cc: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=Jl8J60UuHWw6QycIueIONGAI64GFje0f/SkXAPYopdo=; b=aDK4ww3FQcO4dDDE0O7rpize7 epQKZ/ZPePafhAG5kVGg4JDWJ0VXJO4ScqyKsMESJLnBSA5w6aaN3E2LEHUPHtEnsqyzVjL+6z9Jh E2Twt8KSVrUWY+RQRcITassmFVSPcZD8PgbKV/NXbAuf1wRSJa9NDum2YqC0jg1dqM0Pff/HHxH1R IDil/W5+QCX9bejPtU6T8rWUoK2tutzvZYaE60nEVt/m0miJfFVqn95IZZm76i71sSsUixhrHrh1D i/TL2NtMdGvp/6QVmsD/yoBwuoalZZ3JUszZvh1zq/a5rBsjx9KYOjozTcrWKgY+v3pEMjQbkEjhK SUSyhrw3A==; Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE77-0006KK-AQ for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:26:27 +0000 Received: by mail-pg0-x243.google.com with SMTP id q27so4313282pgn.8 for ; Mon, 26 Feb 2018 00:26:15 -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=pArCoY4kdsA0i5Sz33DCkaLGt5FpFrWG9eSAGP2qQDsEi4fVSdqVqVgjGnQhY5LC/h 8mRWBYqpUW0JvUkp6tpAm2iRyPqdjFhBCQcGsQ6lGmP0caG0HD66OYWborOUHYPBgQBe Gn0yRnzyGWLoQJroQwMyMXhSKrgRX0ACwl8mGrk1BY48N693J3BnQGhdMRz+lnysaRig 7p4p+AytZb6SdZT1vudWW3Jw3Mlk5J4SB94+2zxArlvz9JjT80I7r8uP0W2+a6bzj7Nd LPUuZPuaeyPG77KMxt4uhihzCoHBDxFWZKIbj9aK5TYat6O8OHQDOX3DSt2owlmnvxF7 r+5g== X-Gm-Message-State: APf1xPC0KuZoaeUaeivSL/uJzB9CN9B1CYfPAwnUamp6+NvutLzIU56J A5CC3aJ4xTSRr1wY/R0iLp4akg== X-Google-Smtp-Source: AH8x2273gMUXq20mOOl9grct66Q97irrmCFSN9HTm4/26X8xfX5s382LxInmDUcSkxqPUNergVxd5Q== 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?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_082625_360436_2D0DDA43 X-CRM114-Status: GOOD ( 14.67 ) 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: , 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 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(-) 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