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: 166776 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1506373ilk; Thu, 13 Jun 2019 20:13:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFYgQe9RsWumDdfFIs5H37FxNGxu90vqz5N77Rqbzf4+TZTGzB8orJBGqQMp2z7jbRjxz3 X-Received: by 2002:a62:6083:: with SMTP id u125mr19294584pfb.208.1560482015864; Thu, 13 Jun 2019 20:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560482015; cv=none; d=google.com; s=arc-20160816; b=JAQTyAQY1APTkRNPGv8BkagvSzXzEXbWC+a3/i+py/uSifFHc0MLEbAcQfuySGKjw7 bvsXjxmGlAqbTredr8pZ1nkBd2/T1fAUULKlgkow2BB80BHXSoeGxKo2+q6CKd96D2v9 6WSN6KSeKQvVxi5DsBOTPtFrgikQvVxCrTdv4Ki09BRz2F9qYl9X4uS84WbBTBwTzRxy jLXK3/5E7xnj4Vl+2gPlHLK3BA1q6hq9iZRuxZwF1Wt1R3r7cWpg93DN4OW1DEpS1wQU DnGsIGSCd6PBOOLjpl58JdCvGa5hx8BnkbbTBgg8nRErUj9TwP8qvTVdxIRHX0G4+K3g TtBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Jfnhx8qRw0jZ5LbGeW1WuYGyQJR2HfAomwQkRmg+oIk=; b=j1b60IulW+IYrIiRzkIlCty/l1UC1YG6gHZNussNqFmN87HFWtjp10fF68UoIa6gGF GL/FpcZIm+ytNm/+jeTuc/3aB0AA6QYI6konWkhQBb1NS9sgqv2LEJZUMuggfjEfQgvx cL+5wpYfs9YMeH3J42GbYDTt6rR+Z8AAo+2RqnGPgJL9J08biR7TYyKlGenUILy+CKfk DUq8VhbWKnGTsLrNl3W5lkkKs3QBXbzk2827AOF6/Q2GB8D4xWw/k4MQbYzPr/gvAgJb 5leVQnDl6Zlutw5cuEpgS2h8UO6C4jdqCEpqcGcsVrAApy4s04KTySuWnlAX2vI25OcV 8u2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qJNBo0b4; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e8si1073936plb.420.2019.06.13.20.13.35; Thu, 13 Jun 2019 20:13:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=qJNBo0b4; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1726743AbfFNDNf (ORCPT + 14 others); Thu, 13 Jun 2019 23:13:35 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39758 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbfFNDNf (ORCPT ); Thu, 13 Jun 2019 23:13:35 -0400 Received: by mail-pf1-f195.google.com with SMTP id j2so494514pfe.6 for ; Thu, 13 Jun 2019 20:13:34 -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=mqbVeCwaen30ubVDCShVLTX+d4MPcYCUBe9Zl9itXg9ujtLvE5DY/h/1x/tUhxYbyS ePBGxDr22SQkiy6wyWZ2VMGVhuwM3GVt3Qlfc9Se/7BhxUzMPBwt3FaU3u4qJCQ83Pzx jXw/c2Hqegd9N/IbkH2+e7tSEFqEtezTnYtoHB/pWsckm/DPW0ZB5qd4hmcfJ8LJCpGD YpNMvPEtK9LUiowP9XWo1cNL9PqY5tmIr9+kT8x8oFeKQUoOc5nf904Qd7UYJgNwNCqS LgCnde6OEoswQch43exegc0y4DZEvG00xBLFNedIaT5LWQFIwkQxcu0ccV+nQ8W6/dOu fnVQ== X-Gm-Message-State: APjAAAWandQJpw6BwlDWT5wPrFPX/JNvRbaQ5e8uRwJ0HUavOKDvXESY 1KpcWlTmGSnZoRA+BrsXtXgU9A== 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 Cc: Viresh Kumar , stable@vger.kernel.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com 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 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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(-) -- 2.21.0.rc0.269.g1a574e7a288b 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