From patchwork Thu Mar 1 12:54:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251345 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 07920602B5 for ; Thu, 1 Mar 2018 13:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6F3B20700 for ; Thu, 1 Mar 2018 13:23:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9E3520952; Thu, 1 Mar 2018 13:23:18 +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 0A1FE209CC for ; Thu, 1 Mar 2018 13:23:17 +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=Gh91TWoTtJW/rhq9Md+RufHjtXL+GJn710eLVGgAEuA=; b=lKB/AI3vH9Xu4z/N953K/N9SAu ZxJR032+pnh/fMk55hm9dclfJ4r3pCeHzl/MXAFPI19T75y0VBcw1+HZjJWq1MMg5T0xPstGEXSqP OmW5eI79HrKbCqnZoeBVRlVsoSxb1yX6tBgjyc9qQh02t9L59cnQz4P8uvhon9BS553snEOhb7sTJ ZkbUELUGcQTm69jykCVAYUT6xXTujs/Ujqg4/qwJWxzBN7YekOcF9G7l57xQmRkWTubOhlRyggtTE YNBf41ECBulu1/4Ieb1ntRYxhB+eWpYEl8Q4NTDE+0M7WcljnRWn9nn4wUNCaAmDhwrsUzrg7d5q6 55UdciFw==; 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 1erOAu-0005GY-0s; Thu, 01 Mar 2018 13:23:08 +0000 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNpG-0004vL-9O for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:02:31 +0000 Received: by mail-pl0-x243.google.com with SMTP id y8-v6so3582809pll.13 for ; Thu, 01 Mar 2018 05:00:35 -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=Jl8J60UuHWw6QycIueIONGAI64GFje0f/SkXAPYopdo=; b=gD/uH45gJQjkdY3z8SkrUQfQi7/JGBkpWDviFFCxtDiNpFSn2DftipKVeDNFfxnx0j XjwYO8uDP/ncXEdrz77Rk7lXHvN4pUIKPhYJ/1DqChxlxEJAPlddN9iceNqp98Ueqyy3 S7jqfFEl2X14rc9fKk1R0ulLD488F7ag31+kA= 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=Jl8J60UuHWw6QycIueIONGAI64GFje0f/SkXAPYopdo=; b=d6grKcgaF2XcA7GK7UI+YtW0YzZ3zbuuS92yjTZnxuXVqK6e3UgvCCyqkqVmlkGTu+ g5sE4PnBcghFWpzQhe9FvkzkR8b3iQwOpLf0/2L/hs5bvdwo521CnefnKL0XcBMoOe/a v6KA+SCMocl52PMoX3nkZkurWT5qQPQjiv5AyuVTQ3x2wKgvbqfnvezz7uONf0mE3WkF rVGWvf2PFW87aGujE3QZKb+4keQsQ0R+KZAzkZFT1WLStFvbaeMaBI4BCmUvseL/A/7M xlZwXIVareFleeLjFjKB0/RLe9ogXC4KlBcwVu9zsDaI7yKh1Azrwxhpd7XQEQ6mXnWm 7cxA== X-Gm-Message-State: APf1xPDrTZ5MJvPwqMwENHBSWouJ0bUs2Ji14DHMDALC1gCSK25uYgt7 /upnlacFaxiZMoZ9emDistLIrQ== X-Google-Smtp-Source: AG47ELtS8FjouI8EH3/kb1o1Sfvd/osyFgXqGmtvWQKB5ZGqm4bL0ym578GrYRSG054K81mIMEljFw== X-Received: by 2002:a17:902:9882:: with SMTP id s2-v6mr1918937plp.196.1519909235300; Thu, 01 Mar 2018 05:00:35 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.05.00.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 05:00:34 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 39/45] arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Date: Thu, 1 Mar 2018 20:54:16 +0800 Message-Id: <1519908862-11425-40-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_050047_132267_2CFC877C X-CRM114-Status: GOOD ( 13.10 ) 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: Alex Shi 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