From patchwork Fri Jun 14 03:08:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10994219 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BC0013AD for ; Fri, 14 Jun 2019 03:25:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B15D2793B for ; Fri, 14 Jun 2019 03:25:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ECFD27C05; Fri, 14 Jun 2019 03:25:32 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 0CA8C27D16 for ; Fri, 14 Jun 2019 03:25:32 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=8Mnj7cjL5xrqpyGoAxqn17DLmVnWv+waojwXBq6Ns/Y=; b=rn7B7o2Tc3D58o IFzSA9msP58pQCO3pBfE1fbt5lHbL1+6Xlx+hSdIFWcmlEGX6K135/Xel24XSCpzISN59tgd6eYiC qCcRpP9BL1+4XIGUPu62uBnUF9AEC6yFlSyuy8oB6VvOD7c9L+fW6qIIob7RCzOuHHMoGaGdJn/yu OWjJGe5jRwEK282nBLITBRgjRP/gDBnBM7xa4SqYhi3V6rgRHcEE3dd3aTP1rhugAJc+HLAKuXmxV XEOt6vLYLSCN0P2eiZy4C/QLaBGwbMQfaHIW74I3CiE2cj///145A0kxcTkvsgMYv3mDVJgvp2J4e nLjgB8PvJtkbNiHuMw+w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbcqA-0006HZ-Rx; Fri, 14 Jun 2019 03:25:22 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbcel-00013x-JI for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 03:13:37 +0000 Received: by mail-pg1-x541.google.com with SMTP id s21so656671pga.12 for ; Thu, 13 Jun 2019 20:13:35 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Jfnhx8qRw0jZ5LbGeW1WuYGyQJR2HfAomwQkRmg+oIk=; b=qJNBo0b4V/Cci6PjOFqtp7KxCk67ZIcnOyB16a8gon1qTpdr5xVxqrLnuWhqdFNwaM 4IEiF02Kn66h2IT/dqtvYoVprY7kDlQ3auUSd+gCtWOisbg3BgIPgILlxtw7cDwDr6+5 g3nUolw2TIhK6XAkhpzGrNxgTZe7gE4zG9rEHDINQZN8VA4O0bincWY61fE2whJrQnSy lLQ/VStv4avbGajJPyQab9L+Oae6AfdvNq2E4BHs1JvdYc45Qqpn5w+RI8Lr12aKqcpx jFPB4dwrBlFEulIsMgEH65dAPjlFyGx0mSWMJ2ZfixT02mGRRFp71hURgCO3Re6U5FoX 6WNA== 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:mime-version:content-transfer-encoding; bh=Jfnhx8qRw0jZ5LbGeW1WuYGyQJR2HfAomwQkRmg+oIk=; b=oL0Al3eHIziJGNdMDzlm+lf1Ef/rTVvFaQNlicoCyoBn+fFrHwg7+93Vj3y9KKG4SI aimYGt0nP57tQOoi8GoCBB0WEPd7Y4N1UuNhIJm4DfMbxFaNz8KJrM0LV7WwM82DL42s f5O9Qz4YJAR1PQ7MK2VOkeuzH1j6LhChF1Zmc4awUkExUeF+ffVYzKZnV28kSMHj2kAa vLAh/ZgcbzwUJGhv+cdZu30zQBhuaHXfKKIB+K7po/eUE8RmukEf4SnR/EBaWlAhlfYJ QWTjUmrOye45RQ2qFy/J4CrQqgXsG2wDh/H5gT6MDdNWv1UgWefm4OItLAwqwTSkcS29 7wXg== X-Gm-Message-State: APjAAAUbkYj1Pequ2hthidjugsieGMVGDPG7oHaeEHY0gAxB0qn4zSKx e5XCPXyiASNLjl4fAH9kbMQOr8zmhOs= X-Google-Smtp-Source: APXvYqy15f2JPOdFqBo2EZqq1Wijt1qcjXvFmXzWd9/Lc9RNPpfHv8WWo29ohtqmAJjjp8ci4qcIow== X-Received: by 2002:a65:6295:: with SMTP id f21mr34672569pgv.416.1560482014249; Thu, 13 Jun 2019 20:13:34 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id j8sm999110pfi.148.2019.06.13.20.13.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 20:13:33 -0700 (PDT) From: Viresh Kumar To: linux-arm-kernel@lists.infradead.org, Julien Thierry Subject: [PATCH v4.4 38/45] arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Date: Fri, 14 Jun 2019 08:38:21 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190613_201335_857078_A29AEA78 X-CRM114-Status: GOOD ( 12.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Marc Zyngier , Viresh Kumar , Will Deacon , stable@vger.kernel.org, mark.brown@arm.com, Catalin Marinas , Russell King 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 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 [ v4.4: Made changes to hyp.S instead and fixed registers ] Signed-off-by: Viresh Kumar --- arch/arm64/kvm/hyp.S | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index 8d3da858c257..8aa2ede8c999 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -974,10 +975,11 @@ el1_sync: // Guest trapped into EL2 lsr x2, x1, #ESR_ELx_EC_SHIFT cmp x2, #ESR_ELx_EC_HVC64 + ccmp x2, #ESR_ELx_EC_HVC32, #4, ne b.ne el1_trap - mrs x3, vttbr_el2 // If vttbr is valid, the 64bit guest - cbnz x3, el1_trap // called HVC + mrs x3, vttbr_el2 // If vttbr is valid, the guest + cbnz x3, el1_hvc_guest // called HVC /* Here, we're pretty sure the host called HVC. */ pop x2, x3 @@ -1003,6 +1005,20 @@ el1_sync: // Guest trapped into EL2 pop lr, xzr 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: /* * x1: ESR