From patchwork Thu Aug 1 08:15:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070253 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 50D601395 for ; Thu, 1 Aug 2019 08:19:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4039428481 for ; Thu, 1 Aug 2019 08:19:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33829284A3; Thu, 1 Aug 2019 08:19:54 +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 9D55F28481 for ; Thu, 1 Aug 2019 08:19:53 +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=kwqEdcOW8F84CkBtWM4h/3ZD8vVgctmG7jqXz1ChBK0=; b=NPCOqxTaohhDEF e9VuDu3fVedR3xNvjtqDMVZuV34xTJdfDixSbNEq+QtZ6e8PqbD8s1f3smEXvSk/bk5xPteOtJYtd 2ydQY6MoMMlakROilFEmf/jeG9pXibOpYqVxIdHCJL13QgNtW45Jt5EsRk42JvTcyKJogTr2c3+aG 4kNMu1um4J96MAhpONQtbPru9/V1S7xDlQo9KmjK+pz2j5xh6VLzpToKOSh1HcttWPQFxNtL30sGe jAfc+MOEQ8ZKo2w0lpnAZc6Pb1OjgG+wkUjf/wzA8fifqtQ7sPjZQQ2BEltObasCzqc+E3S3onU1z UjExytqIcKpj+PnhU1aA==; 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 1ht6JU-0000NW-Cb; Thu, 01 Aug 2019 08:19:52 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6JH-00009i-KN for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:41 +0000 Received: by mail-pl1-x643.google.com with SMTP id w24so31861094plp.2 for ; Thu, 01 Aug 2019 01:19:38 -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=yC2M+WqtpDn8WEqkn0+0Dw3Z53HTrfg3c6ZZe0WXdnU=; b=d3x4fDlKvawzWe9SM/hXbJjH0xa2FdWDAb+Q1xG4XXXFjcwqAj01I6oNP+ixKaTvOG r1uM2XDjSkYI4uxtL0fgwqHxF8KjG25ICOelKht4h1FTz60e3olLaOgI1yWgKCKu4gfJ +l5ujKt2riwQxCc/TLA92//Na186jC3Klft3HOTziXCeDW/FOFRGrmv6ua9qRYdfhu+X Fa8AAaeHBKkLKZID6jDTGHEOBAerlARYuCXkbCVbgeRQ9KBtTkhr2YXOqBD7PusHXUo0 ZLXtFbYqRUUHdlbdujXYPHJx0wuICOydTANirYlhyo8Odonfpf9VDUtO5jWGurCAYFnq JZ9w== 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=yC2M+WqtpDn8WEqkn0+0Dw3Z53HTrfg3c6ZZe0WXdnU=; b=ThaBRCqAzP/lGp6CCnyqpV3Y6qQ7AV8T+tM5tvrXUWLykJj15nuiU+W/cmbWqNrVuX 9CTRCtvGByCPYqCDRrYX3mOXwPqfidPjKZt8bxbZBzrlGFnjUeMASGbujBwjYN9mrqJh o1cfJy/uzndNCtWSmZFzUSwbV2owYhSTX2bsEbO8WGv1GgI1t3Qd9Im0nmMa+YXDJ6HG C8hRKexotJUiGFUodppWDG4L8hi4wVdRpnprAc2w9wdpIIDWEdvV7cznjvmJiwO3WdlN +1otsMr2Qbh54l/k2fWqMtRkOFK3G3wiV09xAL+T++gzr/vcW1UX3aPAO7obBSZhOEue axgw== X-Gm-Message-State: APjAAAUgASFme96Ij0ljXt+mYfSM9M6qcITB/4K8hmGd3C6ud957zcqt /njz/F+IHEMveYtqTi4HOmCBRQ== X-Google-Smtp-Source: APXvYqzJAo69vZ3JH7JwAR/fPsAL+lyupaWVU9RujkEEaWknbsrxN/mWgzl3Di7ojOgcBbQHCSy0Vg== X-Received: by 2002:a17:902:1e2:: with SMTP id b89mr17081410plb.7.1564647578418; Thu, 01 Aug 2019 01:19:38 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id n185sm53001398pga.16.2019.08.01.01.19.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:37 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 01/47] ARM: 8478/2: arm/arm64: add arm-smccc Date: Thu, 1 Aug 2019 13:45:45 +0530 Message-Id: <5159d5da6d24267d412df97131045996b5e06b45.1564646727.git.viresh.kumar@linaro.org> 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-20190801_011940_004067_3A2896EB X-CRM114-Status: GOOD ( 19.65 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Jens Wiklander commit 98dd64f34f47ce19b388d9015f767f48393a81eb upstream. Adds helpers to do SMC and HVC based on ARM SMC Calling Convention. CONFIG_HAVE_ARM_SMCCC is enabled for architectures that may support the SMC or HVC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform. This patch doesn't provide an implementation of the declared functions. Later patches will bring in implementations and set CONFIG_HAVE_ARM_SMCCC for ARM and ARM64 respectively. Reviewed-by: Lorenzo Pieralisi Signed-off-by: Jens Wiklander Signed-off-by: Russell King [ v4.4: Added #ifndef __ASSEMBLY__ section to fix compilation issues ] Signed-off-by: Viresh Kumar --- drivers/firmware/Kconfig | 3 ++ include/linux/arm-smccc.h | 107 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 include/linux/arm-smccc.h diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index cf478fe6b335..49a3a1185bb6 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -173,6 +173,9 @@ config QCOM_SCM_64 def_bool y depends on QCOM_SCM && ARM64 +config HAVE_ARM_SMCCC + bool + source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h new file mode 100644 index 000000000000..611d10580340 --- /dev/null +++ b/include/linux/arm-smccc.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015, Linaro Limited + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#ifndef __LINUX_ARM_SMCCC_H +#define __LINUX_ARM_SMCCC_H + +#include +#include + +/* + * This file provides common defines for ARM SMC Calling Convention as + * specified in + * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html + */ + +#define ARM_SMCCC_STD_CALL 0 +#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_TYPE_SHIFT 31 + +#define ARM_SMCCC_SMC_32 0 +#define ARM_SMCCC_SMC_64 1 +#define ARM_SMCCC_CALL_CONV_SHIFT 30 + +#define ARM_SMCCC_OWNER_MASK 0x3F +#define ARM_SMCCC_OWNER_SHIFT 24 + +#define ARM_SMCCC_FUNC_MASK 0xFFFF + +#define ARM_SMCCC_IS_FAST_CALL(smc_val) \ + ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT)) +#define ARM_SMCCC_IS_64(smc_val) \ + ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT)) +#define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK) +#define ARM_SMCCC_OWNER_NUM(smc_val) \ + (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK) + +#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \ + (((type) << ARM_SMCCC_TYPE_SHIFT) | \ + ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \ + (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \ + ((func_num) & ARM_SMCCC_FUNC_MASK)) + +#define ARM_SMCCC_OWNER_ARCH 0 +#define ARM_SMCCC_OWNER_CPU 1 +#define ARM_SMCCC_OWNER_SIP 2 +#define ARM_SMCCC_OWNER_OEM 3 +#define ARM_SMCCC_OWNER_STANDARD 4 +#define ARM_SMCCC_OWNER_TRUSTED_APP 48 +#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49 +#define ARM_SMCCC_OWNER_TRUSTED_OS 50 +#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 + +#ifndef __ASSEMBLY__ + +/** + * struct arm_smccc_res - Result from SMC/HVC call + * @a0-a3 result values from registers 0 to 3 + */ +struct arm_smccc_res { + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; +}; + +/** + * arm_smccc_smc() - make SMC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This function is used to make SMC calls following SMC Calling Convention. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the SMC instruction. The return values are updated with the content + * from register 0 to 3 on return from the SMC instruction. + */ +asmlinkage void arm_smccc_smc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, unsigned long a4, + unsigned long a5, unsigned long a6, unsigned long a7, + struct arm_smccc_res *res); + +/** + * arm_smccc_hvc() - make HVC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This function is used to make HVC calls following SMC Calling + * Convention. The content of the supplied param are copied to registers 0 + * to 7 prior to the HVC instruction. The return values are updated with + * the content from register 0 to 3 on return from the HVC instruction. + */ +asmlinkage void arm_smccc_hvc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, unsigned long a4, + unsigned long a5, unsigned long a6, unsigned long a7, + struct arm_smccc_res *res); + +#endif /*__ASSEMBLY__*/ +#endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Thu Aug 1 08:15:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070255 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 95F5C1395 for ; Thu, 1 Aug 2019 08:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89A53284C8 for ; Thu, 1 Aug 2019 08:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DDDD284D1; Thu, 1 Aug 2019 08:20:16 +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 C0112284D4 for ; Thu, 1 Aug 2019 08:20:09 +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=omxFKkPj3yeX66G+BQ9myurZnQJtPMEODMip6b24S9U=; b=fSDHWaNFB1W7UX 6bPi7omHvRi2h32sHhcv+v+MbnDATf6CanR6GyyJU37B3gnKfrVLtDogcOJ8D8Cf4KjeBgfnm8Vkm o0Inz3kiYXGjw6A1CgUY6/U7WH/xxgbndZ3Ynk8GaATdP/eAmjXHH8u5w0/9ePiSMpOH/H9AuL3g3 yq1ciweubY5tiSrLZMwJ9xyIxdYB1f6I3snzSBwGB0eRxWuxfBPac9tu3i9vC9XYHfX9CsSkJcHHM kpE6ar+XC4TSESole4GnSFSGda8wyUELhTHMXXWEcgZf6IaTkN3DHHnMT9VLmWnXjN+4fcJL3gjN7 Mz+PuoPvhvOW7SaMi4AQ==; 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 1ht6Jl-0000dN-2q; Thu, 01 Aug 2019 08:20:09 +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 1ht6JK-0000Ai-6Q for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:43 +0000 Received: by mail-pg1-x541.google.com with SMTP id o13so33715234pgp.12 for ; Thu, 01 Aug 2019 01:19:41 -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=FDb8snX7fHtHRXPBtLwcic7/q7BlhqslXapsBvvT9m4=; b=lj9Gf1glakTXRPzaABcp+dSTirE8tmaZ6Td74cA3BogQQOFnDfrZx9oEj0Hnu8zmf7 I54TfGtBNyKO+fzt/7SB7xyYp1p4K8QLFUWbHq2Go+7iSwTcEIBwjplWtA/b6ot5RZGD 7Ejsf7yCr1FZcsZOTEXCXfaLdFA2Ee/138F9K3VmN6GopU0+0ZREjPK+4GNwcUa4QIpo n0qcmsR2ExwcIsWajm8cidxMF4XetBAN/apkVA+G1DBoLILahesp6c9blZQkIM3Azh4S 2LRU0HSJJAZfiApfsG1OijZOdJzf2a4NKzlEumfazVW8XkjdyZFVaHxoXrZvSRpZ3mvp eSlw== 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=FDb8snX7fHtHRXPBtLwcic7/q7BlhqslXapsBvvT9m4=; b=EgAI2OOVYP+RQ5xMm5ENmgwAJ4B91qBShbkvv6Xpc7QgLejiXSR4hKB8eKhFE7H6q8 ifpYc8XATL4HXvn75NbgVxIDmdlnrDl8vfRvidO6QKm05ygbqztZ4FmhPUwwkx7IQyF/ 9dOyTxS6ywISjo+LcDrRYJkHYVxOuJLTowKeQtUsfrykmVwRPq7HWkj4OutwMWdt5Y7i hF4HaGAYJLwUUhmMo4wyxqH8GY5EsiOjrZht22fry81tKIIevfuIiRaKlMGreDW+n5NX c4xR/dsAScH5J6qcwV6UOLyY1qRCb7HUGWOOs/fsMpqMFO0AZnhYMu103Z1DAa6kjtGI vv+A== X-Gm-Message-State: APjAAAXRDfXJ1JsvYrBpnxtiY00+S7wHW2FZkUSDP5fXi94L79oqbA9L ZqUMo3qWOVDYKB+KFnBtpfQR3w== X-Google-Smtp-Source: APXvYqz75WheTZoQVD/460prqttSQRePB4YDUm2PEp53etTwQK58Z/AF5zDWQURXBRL/9/WSyqVsVg== X-Received: by 2002:a62:750c:: with SMTP id q12mr53419702pfc.59.1564647581009; Thu, 01 Aug 2019 01:19:41 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id u1sm67243723pgi.28.2019.08.01.01.19.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:40 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 02/47] arm/arm64: KVM: Advertise SMCCC v1.1 Date: Thu, 1 Aug 2019 13:45:46 +0530 Message-Id: <9f53c355f58717a810f74b72ab6982d723fb621c.1564646727.git.viresh.kumar@linaro.org> 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-20190801_011942_291751_F70A55D6 X-CRM114-Status: GOOD ( 10.60 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 09e6be12effdb33bf7210c8867bbd213b66a499e upstream. The new SMC Calling Convention (v1.1) allows for a reduced overhead when calling into the firmware, and provides a new feature discovery mechanism. Make it visible to KVM guests. Tested-by: Ard Biesheuvel Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas [ Viresh: Picked only arm-smccc.h changes ] Signed-off-by: Viresh Kumar --- include/linux/arm-smccc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 611d10580340..da9f3916f9a9 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -60,6 +60,19 @@ #define ARM_SMCCC_OWNER_TRUSTED_OS 50 #define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 +#define ARM_SMCCC_VERSION_1_0 0x10000 +#define ARM_SMCCC_VERSION_1_1 0x10001 + +#define ARM_SMCCC_VERSION_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0) + +#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 1) + #ifndef __ASSEMBLY__ /** From patchwork Thu Aug 1 08:15:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070257 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 4DF82186E for ; Thu, 1 Aug 2019 08:20:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40BAD28481 for ; Thu, 1 Aug 2019 08:20:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 344DB284B5; Thu, 1 Aug 2019 08:20:22 +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 C2E5128481 for ; Thu, 1 Aug 2019 08:20:21 +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=UbGw2Z0SAnNn5mN3/FzeLpCQGz32aKJ/L+1xY+rI7a4=; b=TB65AeZ3C8LNlG foVaS37w2NDT/B4+cgrOg3VXiadKXHZmHYoiY2sH0OJ38IwlZM4r3kAFy3nPOMrxXEOkk774ZUL7F hTk8nSQi9fcY1/9e3t0/2ms/r3ZHV4ZW+37V/JwbdlyTSOPbnsKfLVbWU1kCmgFXgj7jGuCSHeTlf UMU8HN8okXAieTlYUEX+YIXWX/ciGYYsfXwp4Wv38cYESQ6PIGxZB3BsU/U7yUHwezH/EhClZ9oSc GUHOQxM+jdk0QdoMDN8uK3Q47UmwgUcbu3TrrhyK7dEPnFGFJ/AdG4N08ZqIsR6e/3b7e9lGD6GBf sEdMMRbLTn4UYztQ+SzA==; 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 1ht6Jw-00026H-Mt; Thu, 01 Aug 2019 08:20:20 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6JM-0000Dg-M5 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:46 +0000 Received: by mail-pf1-x443.google.com with SMTP id g2so33611356pfq.0 for ; Thu, 01 Aug 2019 01:19:43 -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=z7GSqiJ6aBNFVvBBcZiH2v3S1Pbs9vo106t8SFNGIe4=; b=cYaRmjxpRpihR3ST0Z43FI6gGebPhfoWhCbpU+IMiA14zAmRrIrwHkLNPGxQbO3dwQ GKIF1ls+9uq+hNUdROGeAa0AknTV9vYQ5TFKVHdwI/2EmvyukmhMRTDGiva55cX2FenL aGDOJ5qzMHxinEWIcGbZyYj1dw2pxHV/LjncanSzzQL3S6e2pW5AVum+1MNUj63YHMgI N3LCp/eNbnqtm6aGhrAr6JZ+sPtBGtd3EyRopNtHb2rYD6dzl/Nm03uWLQROVJdNpWp7 tXl7No6eYiHWr+8KJFDPN8JbC84yPGs9/3Latvd+MfH6CI93+nX4fYz1N+Wls25RH5UP oHBw== 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=z7GSqiJ6aBNFVvBBcZiH2v3S1Pbs9vo106t8SFNGIe4=; b=ui6XKWEFUdYtmmYvaT14N4JTdsNRecXcYtRy45yPJjE3Wm8OZkfgxWa/KKjZ/Rci0B J99eK9WK2N/7mrbwZ5HUlOzjK9ZrK/tzUsDSYORiddf3KAM6vxfn33lGVPewhcsyTfVh mSc3hm689K8vOeX7cGN7BjN2C50z9lLt2ApzsokQXD3ocva2TKyQ+hucmCf8ZBBsXZVx AZ7eqtCt4TftMeITZIqav9Sl5IkgwWNieDo0F+Gpb0ogZfCjq1a+xrxyZUnJ2jNh8CJJ NgaON3W2ghDdD92GiKI2D2xUJeQZCpAF1+fkTE2tH5FrkPqKSv/mkFos72l5P3HR8GUy PxZQ== X-Gm-Message-State: APjAAAXN3lGEiZ88ZuMfeWr+oSHuqFOod37FEcdm9gMEoNVDbyjRMYrQ 2i/WszXsmDGt5c8FopH6wvxbtw== X-Google-Smtp-Source: APXvYqy+r/ZBXTixIjv/M9S1DYk3sEBpMLeC+4UwOYm9t+/UkhM1ETIyQn3yLY+cECisdJqFRi6T/A== X-Received: by 2002:a62:3c3:: with SMTP id 186mr51852915pfd.21.1564647583498; Thu, 01 Aug 2019 01:19:43 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id l1sm91579706pfl.9.2019.08.01.01.19.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:43 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 03/47] arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Thu, 1 Aug 2019 13:45:47 +0530 Message-Id: <62376918dc348842e21f6eb62235220f53d35cdb.1564646727.git.viresh.kumar@linaro.org> 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-20190801_011944_735279_9FF497D1 X-CRM114-Status: GOOD ( 11.30 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 6167ec5c9145cdf493722dfd80a5d48bafc4a18a upstream. A new feature of SMCCC 1.1 is that it offers firmware-based CPU workarounds. In particular, SMCCC_ARCH_WORKAROUND_1 provides BP hardening for CVE-2017-5715. If the host has some mitigation for this issue, report that we deal with it using SMCCC_ARCH_WORKAROUND_1, as we apply the host workaround on every guest exit. Tested-by: Ard Biesheuvel Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas [ Viresh: Picked on only arm-smccc.h changes ] Signed-off-by: Viresh Kumar --- include/linux/arm-smccc.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index da9f3916f9a9..1f02e4045a9e 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -73,6 +73,11 @@ ARM_SMCCC_SMC_32, \ 0, 1) +#define ARM_SMCCC_ARCH_WORKAROUND_1 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0x8000) + #ifndef __ASSEMBLY__ /** From patchwork Thu Aug 1 08:15:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070259 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 C828513AC for ; Thu, 1 Aug 2019 08:20:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA50C28485 for ; Thu, 1 Aug 2019 08:20:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE311284C5; Thu, 1 Aug 2019 08:20: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 489B728485 for ; Thu, 1 Aug 2019 08:20: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=T7e+eJi4s9KVLZ8DuWfzK4MJ1almm9M0BRCRnGc95xw=; b=lOhZ2uFI5Rr6xt DM6OsUdso3b1aUbE9K24r7KxF5KjzaHizz+s4n3g8Ywm23XoV2lJZz5H5RxyadxIKk0nq6Yendux6 Xwr/aM308Nc+hr0qzByv8yOIB2t7RQsxkIEV4aSYB5uKgg1JInQ3f3NiJriJO+nO0cJinEFZK5iIS qHSLMBhWceZR1G1Ws1vEsomDONyV13CO0cHzqwGnrDda4/TVwajZvbKC4+ozucgJIQqk9Z/8WM4gc zOk/OaeMOBs639Vp1Ib4bP+HEucGmZpTdhwktfgtLaeb0M9WbkAl1qPTudwI9bxZAo7pvvcV0q+1f pcyUhMkEJp8fsp+dHbGg==; 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 1ht6K7-0002Lz-Oh; Thu, 01 Aug 2019 08:20:31 +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 1ht6JO-0000HO-II for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:48 +0000 Received: by mail-pg1-x541.google.com with SMTP id u17so33734993pgi.6 for ; Thu, 01 Aug 2019 01:19:46 -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=tUK8ETga6k61l9Q+/z8rY6SIV6XG+DcjRuCd/1NWAIQ=; b=Y4Z6CBElGedbCLchp/1U5zm7RwIzsZW7sSPLelgGoB0UAR3fmAUIaWPRqbBzItY+SU dFonmxxfBMwagZLJREXeHezpHMh1Y3Qa90lYmEqpzmwy29/QR4lMPJUVtQqcTlzsoblx YvUQeTrTR+Rrgn6wBdIS/56xvJGBvX6qMt3nWeY6Yf+7kSNhghxr4XIm9GLXOVwOTBSx bMwSdkvjuTyiv2KCbxqdBmearRidRn1z3nSssV2qaK3kQU+stZQ6DIV2/gHkdIaGZ1iJ d0MueB6aYPyB3wiVuCenso27YAaY7cBchl80Fj6Qc729nXHTSmJRi2P+ieiXaWhAkbNl +6jQ== 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=tUK8ETga6k61l9Q+/z8rY6SIV6XG+DcjRuCd/1NWAIQ=; b=mJ7Sk1V1AkKOBl7idAOZdVTHX7Wn79LC9vj4hCAn1gc4SonHSSWXDSsv3E/lJfAjJX Z0Ju730gyDre0jM0X1N0CfDVSa8fA3YZAPblGOQz208nvjUnhRwOXzSx3va7iCVh+IBu uARCY/Cn6/TuUGIEsIDR9Qt8yLNGUk0C6i+1o4GNHqkwHHzDntoyy2HUI8BQIvvT1y5h YxpmoUuC8qUNr2UzicvOGoUSu9ojVZibPJuCedj4UTrQkyEpFIoI/JAkJ2B/z73/wgT3 3U8NxKTiuBotsb4IfXPbEJ4l2wx7qAp1u/4AZoccOjT3WIuT8YNEBDE9Lfwcmpf7Q1ZC 6aBA== X-Gm-Message-State: APjAAAV9CEEd/NIa8NzMKM1IBUpxMoG128rAzCS2E8OubWxWd0h4F9J7 y0RjDuLMQxfHV27ZuWLCrKSbgQ== X-Google-Smtp-Source: APXvYqwBGdeJip4Cl0RM0Gp+T+ODw9bU7Zw9CWW60KiajPbXAE1SchPFqPiYgxpHdrwW0IJ2FkUxCQ== X-Received: by 2002:a63:d34c:: with SMTP id u12mr103456545pgi.114.1564647585962; Thu, 01 Aug 2019 01:19:45 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id y23sm72885680pfo.106.2019.08.01.01.19.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:45 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 04/47] drivers/firmware: Expose psci_get_version through psci_ops structure Date: Thu, 1 Aug 2019 13:45:48 +0530 Message-Id: <64c1d3d45f10e811674aad1f583b346fcf3a8707.1564646727.git.viresh.kumar@linaro.org> 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-20190801_011946_620338_176B25D1 X-CRM114-Status: GOOD ( 12.16 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Will Deacon commit d68e3ba5303f7e1099f51fdcd155f5263da8569b upstream. Entry into recent versions of ARM Trusted Firmware will invalidate the CPU branch predictor state in order to protect against aliasing attacks. This patch exposes the PSCI "VERSION" function via psci_ops, so that it can be invoked outside of the PSCI driver where necessary. Acked-by: Lorenzo Pieralisi Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Viresh Kumar --- drivers/firmware/psci.c | 2 ++ include/linux/psci.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index ae70d2485ca1..290f8982e7b3 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -305,6 +305,8 @@ static void __init psci_init_migrate(void) static void __init psci_0_2_set_functions(void) { pr_info("Using standard PSCI v0.2 function IDs\n"); + psci_ops.get_version = psci_get_version; + psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_FN_NATIVE(0_2, CPU_SUSPEND); psci_ops.cpu_suspend = psci_cpu_suspend; diff --git a/include/linux/psci.h b/include/linux/psci.h index 12c4865457ad..04b4d92c7791 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -25,6 +25,7 @@ bool psci_power_state_loses_context(u32 state); bool psci_power_state_is_valid(u32 state); struct psci_operations { + u32 (*get_version)(void); int (*cpu_suspend)(u32 state, unsigned long entry_point); int (*cpu_off)(u32 state); int (*cpu_on)(unsigned long cpuid, unsigned long entry_point); From patchwork Thu Aug 1 08:15:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070261 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 0FD8B1395 for ; Thu, 1 Aug 2019 08:20:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0193E283A8 for ; Thu, 1 Aug 2019 08:20:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E911E283A6; Thu, 1 Aug 2019 08:20:45 +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 79FB82839C for ; Thu, 1 Aug 2019 08:20:45 +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=4Tb6lLJaz2ZVakSy4Knqmqaad25btOTIJa6H1Qs7XH4=; b=rJc/UZVHN8Z6JS yF1122lGO2baGXWPWATlcPWIguB/yc3pOwINqrVqOoHl2xNmIf055pgSwWIl1419hreuZ7NsKOZCi IzYTUpqlF9kjJu/FPXczbPvAd6GEyWP0MoswiRm4VMHUBvkgeogLsAiKtEd/spd8pcGRewzLYNfTU woK0mU4LFVbQaI7OUoeqRjO0jb8EX0/q+9mpuvCQKXr/rEGnEXjasaDtcnMdbQ4hnNv5SH3FYE4YI eUvJrzucJo+F3taIdtHTzvUtb6CpuPaTOAgEMJ8IDoZEiOyvBXWq5OmPkdDCRJyIOJnW7+4I8YDnr XriZlIt9Egco35jEjYLQ==; 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 1ht6KL-0002av-3s; Thu, 01 Aug 2019 08:20:45 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6JR-0000Ke-TV for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:51 +0000 Received: by mail-pf1-x441.google.com with SMTP id i189so33607155pfg.10 for ; Thu, 01 Aug 2019 01:19:49 -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=lhetsf/v1WHqsODDPiuS8lCaAlBwJqZTnWnIuf4OhuE=; b=IeSrybNXM1FIuaHjdY8UGbg00YzSWruFMn1J7qNAW3drOxKc0UR8dxZDM5PD/UwY9x crfCdf8Q/xTPuaVROFU/r8eIsG9JXSdJGbjUk2DQH+rIPUUK8C3VNg2wcYriMmtqGNJT 7j4NI63W+dSuf3NJWh0T7mG2Cw8wSakGtzWws8D97SnvRP6mpWDaG62Q8ukYZh3xNWAS bHT+s5u0WQ5XjcbNpFziJfAkntmqjT2wtaDVQ0RzER6/blMnFCrZhvS1x/2b6IzqPe2o t8qPEVYRxsRguSB7/QUcvmTdeatQF8Of3ll29ZRRZ4t3FmlNSiDoNElGjxoS23J1Irhp k1wQ== 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=lhetsf/v1WHqsODDPiuS8lCaAlBwJqZTnWnIuf4OhuE=; b=FQPli0i3BCATbkih1PIsKeF6TMM32qHYXCbH4HRwliXgZGA4WlZeuWZlo2vp/bXAdm oIXNOzCaUtdrYHXzmcCXVKgajQdmgE69viLIrkSrOaQqF76ozrj2Rfxrnbl3eu48iGL/ tWgYjJUvFBCS02PhRByuwQPsJdetPOk30cpG4t5lkyvdrYbTg6uqBAzktCKVreO+KBAY IrAffUd9mWtIlW62CX2mS8p5q3ZFwOP/3Z+HzccOZ/eNFWP6WjuGjEJClAgQx3wN+nZH 2+P+X2I8PEKkP3tWp2WKfPhZNrYA/kczSs7GmtWAvvbYFmw1yrUGETuRmo9rXr/hhRe7 KSbA== X-Gm-Message-State: APjAAAVqFivsARn/dHr+Q6mbY2VnU2JA5wBiaBUAXr7QQVJ+Lc8DG5w0 tQn12QVZkF5KVysPTvZQJ5OdYw== X-Google-Smtp-Source: APXvYqzwaezWIvdwv0H5ugpgJ6JrKb46pj+oO7T+aNheVkzhLn/9E35sO38a1NI/m7ezUfYyfu5Mhw== X-Received: by 2002:a17:90a:1ac5:: with SMTP id p63mr7090797pjp.25.1564647588607; Thu, 01 Aug 2019 01:19:48 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id f64sm74385803pfa.115.2019.08.01.01.19.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:48 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 05/47] firmware/psci: Expose PSCI conduit Date: Thu, 1 Aug 2019 13:45:49 +0530 Message-Id: <9af0ed2a4a54549532931e98643daa5ed274ac8f.1564646727.git.viresh.kumar@linaro.org> 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-20190801_011950_000333_8C736BFA X-CRM114-Status: GOOD ( 13.48 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 09a8d6d48499f93e2abde691f5800081cd858726 upstream. In order to call into the firmware to apply workarounds, it is useful to find out whether we're using HVC or SMC. Let's expose this through the psci_ops. Acked-by: Lorenzo Pieralisi Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Viresh Kumar --- drivers/firmware/psci.c | 28 +++++++++++++++++++++++----- include/linux/psci.h | 7 +++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index 290f8982e7b3..7b2665f6b38d 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -54,7 +54,9 @@ bool psci_tos_resident_on(int cpu) return cpu == resident_cpu; } -struct psci_operations psci_ops; +struct psci_operations psci_ops = { + .conduit = PSCI_CONDUIT_NONE, +}; typedef unsigned long (psci_fn)(unsigned long, unsigned long, unsigned long, unsigned long); @@ -187,6 +189,22 @@ static unsigned long psci_migrate_info_up_cpu(void) 0, 0, 0); } +static void set_conduit(enum psci_conduit conduit) +{ + switch (conduit) { + case PSCI_CONDUIT_HVC: + invoke_psci_fn = __invoke_psci_fn_hvc; + break; + case PSCI_CONDUIT_SMC: + invoke_psci_fn = __invoke_psci_fn_smc; + break; + default: + WARN(1, "Unexpected PSCI conduit %d\n", conduit); + } + + psci_ops.conduit = conduit; +} + static int get_set_conduit_method(struct device_node *np) { const char *method; @@ -199,9 +217,9 @@ static int get_set_conduit_method(struct device_node *np) } if (!strcmp("hvc", method)) { - invoke_psci_fn = __invoke_psci_fn_hvc; + set_conduit(PSCI_CONDUIT_HVC); } else if (!strcmp("smc", method)) { - invoke_psci_fn = __invoke_psci_fn_smc; + set_conduit(PSCI_CONDUIT_SMC); } else { pr_warn("invalid \"method\" property: %s\n", method); return -EINVAL; @@ -463,9 +481,9 @@ int __init psci_acpi_init(void) pr_info("probing for conduit method from ACPI.\n"); if (acpi_psci_use_hvc()) - invoke_psci_fn = __invoke_psci_fn_hvc; + set_conduit(PSCI_CONDUIT_HVC); else - invoke_psci_fn = __invoke_psci_fn_smc; + set_conduit(PSCI_CONDUIT_SMC); return psci_probe(); } diff --git a/include/linux/psci.h b/include/linux/psci.h index 04b4d92c7791..e071a1b8ddb5 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -24,6 +24,12 @@ bool psci_tos_resident_on(int cpu); bool psci_power_state_loses_context(u32 state); bool psci_power_state_is_valid(u32 state); +enum psci_conduit { + PSCI_CONDUIT_NONE, + PSCI_CONDUIT_SMC, + PSCI_CONDUIT_HVC, +}; + struct psci_operations { u32 (*get_version)(void); int (*cpu_suspend)(u32 state, unsigned long entry_point); @@ -33,6 +39,7 @@ struct psci_operations { int (*affinity_info)(unsigned long target_affinity, unsigned long lowest_affinity_level); int (*migrate_info_type)(void); + enum psci_conduit conduit; }; extern struct psci_operations psci_ops; From patchwork Thu Aug 1 08:15:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070263 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 D9BF913AC for ; Thu, 1 Aug 2019 08:20:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC607283A6 for ; Thu, 1 Aug 2019 08:20:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0219283AF; Thu, 1 Aug 2019 08:20:59 +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 58008283A6 for ; Thu, 1 Aug 2019 08:20:59 +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=HNx7+VLLYM9naswiHW8erBj+S6i3EnRSZLR37q7YcEA=; b=CqC4MSaVPNnslC w5wUxBCT2V7TcVNvjBMNiPZkJtPeh4QPXwRe5Y/3FtewgIDdm69kAu08CuUM08hpt87F2C+c2e2nW 7Zln9TssLSDvMHv78iVJjmrid86PdRheJMi7MHeDStjhyfi9Hh0qf+AqPA5OIuQMgNrNpCtTbjrJT ZMLStVtOCGtNuk48pvq4vpt4kkckdBw44GW3AYd4TLJAA16LIFaWbUEzEyBJCYMwHU4WhaPBAOig+ q9F49FRDWLu3w+MB47NY1SwoKPAzQYrPjNJRz3GQZBcgU3oLTSdk3QDVT/y8T2AyrSuXQrMMDT1l4 FecyAxUaxdbf4tyOS1gA==; 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 1ht6KY-0002xO-BN; Thu, 01 Aug 2019 08:20:58 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6JU-0000OU-C6 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:54 +0000 Received: by mail-pl1-x641.google.com with SMTP id b3so31882446plr.4 for ; Thu, 01 Aug 2019 01:19:51 -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=8FgYZ0lVoh76yEFRGdkiTuXxRHgDjc15a9Db0UAG0RM=; b=U2pFy8zplP29YpsCH8W5CImqW9kDRTXequpz5TZjdTd/cKjWqInrw3Uwd1AL2uD6lU qbZ/TwswNmotIc7tfzAT06bNLn3+R8t/4ayZ3lv6smnADiIqJ77U8FH5+ntKrSwXrMCf XkgfLzlAC8TJa9x6Elq24iJrBFMA2SC0pp/liR93dQ4TUU8E2GuBBHp6WlVS6LSJhNao ImLUvMYM8Id3R/lKhgjC7TaPnfvasBP4OyyrDRFHP8oH957QYy7TLvliiwmwD+dQAitC aEVWiulUEAtHO7t4spHHwYrNSMz+RgEFMpvh3JV3t4gQZMGjxPO20KwIbAnbo9bsihGo c+7A== 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=8FgYZ0lVoh76yEFRGdkiTuXxRHgDjc15a9Db0UAG0RM=; b=TskpWY11/SkFPW8eNkkSolZqCDdO+d/+I0aUisc7Vbqo0qafxHUaClH1+DQpX4EfgK IDurxJi9D4bvbocJVAJ15KwFs8Idnu1pXU7nS1h4GY3barARzHkWQy3C5MCcWH5kMcLi 2nv1dWQQ25k8Akl00/yl4BBlAyzzsgVgiDneN6Vm+lXMXsMue2QD4XVJba+7flgqNdDZ 4KtLauMlxGTviS3YEyZoS08NF1we68CuzUDv8N1LcFYSSYmQcRGysTybWDWlN8OBJ/te 8Q/Xb47Sy0mAkUuTuPYyuGq+6Xk6BqmzBNS4ZZ0yzqAxMx5FGaPwZsNSVQFyqttFjdHY FkaA== X-Gm-Message-State: APjAAAW1oPVhomAWL/WwEg6PA5Mh0iJg8XNbFBSSQX5cX8MQcX2S7Ymf +a5bqKFDr5amIzjGcYcsdrOMaw== X-Google-Smtp-Source: APXvYqzSgtxQ3JDCBf442PLtZn52NA1MhiDih6RwxeLZMFxUsFnDqNuIiXEcBuC3C4LEZKGa4aagUQ== X-Received: by 2002:a17:902:ff05:: with SMTP id f5mr120452352plj.116.1564647591056; Thu, 01 Aug 2019 01:19:51 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id l6sm71842795pga.72.2019.08.01.01.19.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:50 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 06/47] firmware/psci: Expose SMCCC version through psci_ops Date: Thu, 1 Aug 2019 13:45:50 +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-20190801_011952_522830_D4A01C20 X-CRM114-Status: GOOD ( 14.91 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 e78eef554a912ef6c1e0bbf97619dafbeae3339f upstream. Since PSCI 1.0 allows the SMCCC version to be (indirectly) probed, let's do that at boot time, and expose the version of the calling convention as part of the psci_ops structure. Acked-by: Lorenzo Pieralisi Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas [ v4.4: Included arm-smccc.h ] Signed-off-by: Viresh Kumar --- drivers/firmware/psci.c | 28 ++++++++++++++++++++++++++++ include/linux/psci.h | 6 ++++++ 2 files changed, 34 insertions(+) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index 7b2665f6b38d..0809a48e8089 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -13,6 +13,7 @@ #define pr_fmt(fmt) "psci: " fmt +#include #include #include #include @@ -56,6 +57,7 @@ bool psci_tos_resident_on(int cpu) struct psci_operations psci_ops = { .conduit = PSCI_CONDUIT_NONE, + .smccc_version = SMCCC_VERSION_1_0, }; typedef unsigned long (psci_fn)(unsigned long, unsigned long, @@ -320,6 +322,31 @@ static void __init psci_init_migrate(void) pr_info("Trusted OS resident on physical CPU 0x%lx\n", cpuid); } +static void __init psci_init_smccc(void) +{ + u32 ver = ARM_SMCCC_VERSION_1_0; + int feature; + + feature = psci_features(ARM_SMCCC_VERSION_FUNC_ID); + + if (feature != PSCI_RET_NOT_SUPPORTED) { + u32 ret; + ret = invoke_psci_fn(ARM_SMCCC_VERSION_FUNC_ID, 0, 0, 0); + if (ret == ARM_SMCCC_VERSION_1_1) { + psci_ops.smccc_version = SMCCC_VERSION_1_1; + ver = ret; + } + } + + /* + * Conveniently, the SMCCC and PSCI versions are encoded the + * same way. No, this isn't accidental. + */ + pr_info("SMC Calling Convention v%d.%d\n", + PSCI_VERSION_MAJOR(ver), PSCI_VERSION_MINOR(ver)); + +} + static void __init psci_0_2_set_functions(void) { pr_info("Using standard PSCI v0.2 function IDs\n"); @@ -368,6 +395,7 @@ static int __init psci_probe(void) psci_init_migrate(); if (PSCI_VERSION_MAJOR(ver) >= 1) { + psci_init_smccc(); psci_init_cpu_suspend(); psci_init_system_suspend(); } diff --git a/include/linux/psci.h b/include/linux/psci.h index e071a1b8ddb5..e5c3277bfd78 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -30,6 +30,11 @@ enum psci_conduit { PSCI_CONDUIT_HVC, }; +enum smccc_version { + SMCCC_VERSION_1_0, + SMCCC_VERSION_1_1, +}; + struct psci_operations { u32 (*get_version)(void); int (*cpu_suspend)(u32 state, unsigned long entry_point); @@ -40,6 +45,7 @@ struct psci_operations { unsigned long lowest_affinity_level); int (*migrate_info_type)(void); enum psci_conduit conduit; + enum smccc_version smccc_version; }; extern struct psci_operations psci_ops; From patchwork Thu Aug 1 08:15:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070265 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 76D1F13AC for ; Thu, 1 Aug 2019 08:21:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68B7E28481 for ; Thu, 1 Aug 2019 08:21:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C9832842A; Thu, 1 Aug 2019 08:21:13 +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 F35DA28068 for ; Thu, 1 Aug 2019 08:21:12 +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=SN6CbOE6sJwLsMZWWfqvuVy/FQqu158LBIK0N6r25TE=; b=QVRRZh410mB1KU dCLXRjHY026xWDb2iHaNTFvT3Wn5EY+FK7vhHXjNi+rI84MATRJ7nuLtsfOP08EV8N9hsbLOV87BS WRorXX8BHlTxve7acF7xQtiBKY20o75VmBoLr1yLn3d6fFL27kdNZ6Rof/ufcLYrWwbHSfgOYKEQD SO58XyBjgPzqlHacYb6Lw6rLg4rSiqFhPGQ9MqX/1JzdFE2ybv3TJ2qpY+joYSN8n02DeYnM6bxby c18veMS1eltovSS7aoiSkDvqk7rDxMOJttJ69GTtyfJgNgfeYqboG1VwKGynpGDQW+eyo0IqbQRtt ij/e0H1pNDp/Qj4Dxu5g==; 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 1ht6Km-0003Gu-7t; Thu, 01 Aug 2019 08:21:12 +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 1ht6JW-0000Sq-9h for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:19:56 +0000 Received: by mail-pg1-x541.google.com with SMTP id o13so33715570pgp.12 for ; Thu, 01 Aug 2019 01:19:54 -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=QAkAWOSid7lK0+CYFipQ6VxUVVXehQyD0WFI7UyGT+o=; b=VbI6KvBYoAleWdpoNuid44aSrwYNmD6XVjYIU7cCDTWY4VDquc62cFzYoqAjoNU4c6 nZdCxO4QKpSqcfDfWapRYMgqaUzdTVFD6QEiTM4dIJb0ZM1ABvlyVKKWWtNPpds1G3lU 4p92/NPa79XeTp/RqJA3evytYoQgQIeWoUDGGWbUFJL5yJfeteKwslbEPL6XJ81zlmu4 mqBei4tEDuRtTA5ILbqgU4DBk8LIhWRf6SJUr11/UyQJ9nEkk3ZEB73W/A5g/oRFW5pC orshzn6ourcm7mrF/MHU430GQUWbheLftyEwlurTTVsAnK2IQGUQJyEuSSSvo2QsVTeB QOfw== 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=QAkAWOSid7lK0+CYFipQ6VxUVVXehQyD0WFI7UyGT+o=; b=WXi3x+OsJBEa2Lu4GjIe5w+6zVOC6Czfb5wKtcw+shH+uuYahCcyl85IwWcJ828Sw8 6EBQZMNwX0K0HATLuvRxFH1PpDJK3vA7Q/UfrxmWrnElDK2ALgj22YG68PZ4+P8pN0lb IjEmKrGr7MeMEQ+x/2+W5qcHxkPaB37VnkYZPDRH2ntX9OL48WGa+fYYp4vtmMGUCLAF t/ABrYL2PGgysiA5hLqOXL1Epkmlmw3J3NoAWH0UUmAYnmVfZhVx+jCxReSbW/cARoeQ UmxaO88al1K3KCw0Y5lbD2F4PN6dQr7ex+iNscxlzdpt+dMKkjPb5DNp7uicFPGwSJLs ULEw== X-Gm-Message-State: APjAAAVy1Z4V3bN9yslN5RnY9PIx61EDJVUc54KCUwGwzq+EbQ0Sde3w I10qT2t6A624d85NA52TEZ0Hrg== X-Google-Smtp-Source: APXvYqyqiLsABmsuD8RnlguGwZ949r9n3nBGRbVHcg6v9Qt8z+FIGNp5TN9mJ/k6FWKJWLIPv1k4Ag== X-Received: by 2002:a63:5162:: with SMTP id r34mr686278pgl.229.1564647593609; Thu, 01 Aug 2019 01:19:53 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id u24sm10002220pgk.31.2019.08.01.01.19.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:53 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 07/47] arm/arm64: smccc: Make function identifiers an unsigned quantity Date: Thu, 1 Aug 2019 13:45:51 +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-20190801_011954_381169_01328B04 X-CRM114-Status: GOOD ( 12.07 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 ded4c39e93f3b72968fdb79baba27f3b83dad34c upstream. Function identifiers are a 32bit, unsigned quantity. But we never tell so to the compiler, resulting in the following: 4ac: b26187e0 mov x0, #0xffffffff80000001 We thus rely on the firmware narrowing it for us, which is not always a reasonable expectation. Cc: stable@vger.kernel.org Reported-by: Ard Biesheuvel Acked-by: Ard Biesheuvel Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Viresh Kumar --- include/linux/arm-smccc.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 1f02e4045a9e..4c45fd75db5d 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -16,6 +16,7 @@ #include #include +#include /* * This file provides common defines for ARM SMC Calling Convention as @@ -23,8 +24,8 @@ * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html */ -#define ARM_SMCCC_STD_CALL 0 -#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_STD_CALL _AC(0,U) +#define ARM_SMCCC_FAST_CALL _AC(1,U) #define ARM_SMCCC_TYPE_SHIFT 31 #define ARM_SMCCC_SMC_32 0 From patchwork Thu Aug 1 08:15:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070267 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 AE39E1395 for ; Thu, 1 Aug 2019 08:21:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0AE8283A8 for ; Thu, 1 Aug 2019 08:21:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9496828481; Thu, 1 Aug 2019 08:21:22 +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 D6D7828306 for ; Thu, 1 Aug 2019 08:21:21 +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=rl9R92uY08q5DL/+qpS8+V7uNIFAS7xFfNPq0hfE2mM=; b=NENonc6+yljVH5 UXAwdsAt6f5iBioHIh6v18kpQ/pk0ES8OMsyyT6nXhxXu4WTaMUbaCDxpmZFEDkMJzlPF2ksTePRk RBczHXD9oi23Mh+XVi1slvKN8LYTVIf8McGrKJvFSBEHZo+PnUQDxHeMguIE+MZYtHx3aMABhwHnH 4T3VrKk3EaLlXypFFh9ZtkhlIlSQthAhpptwMRNXTm59GeDn0ufCvowaJ3lAXDRAb1ApbAcXzRTXZ rtaB+vKBi+KdMpUV2/KO4mKcQgmmIsBEZ0fD0dLjR6B53fwCMxocbdQWkPkan1gylOKLXmQueMmwA IZnzIxVeN+qxq9vkxzug==; 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 1ht6Kv-0003Yd-5A; Thu, 01 Aug 2019 08:21:21 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jc-0000Wq-M1 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:04 +0000 Received: by mail-pg1-x544.google.com with SMTP id w10so33738247pgj.7 for ; Thu, 01 Aug 2019 01:19:56 -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=kulBovnYLz4YjgSJ0sOniJhX8Qcc8ljUXoag6+mJQMI=; b=neGmzSpV9c10RXeRmHvS3wtU+YOChR6vVVa7bFABnNxRBXpWpg59bG6VB4CB5sMp9u FhfBeZ5ASzEClrF62JZxBQBWIRuetSSbJtsT8SvGAkcgb8Ingpygb97sGCHM7A8gIObj 7vl8EJSxYKKYi8dUiQtPeKFeJP9Zuf+GQ3Kf8GRGlTcmSn8D/Jx1NKLDlGnoOoRp5N35 4DGMTXyfBuGk0OnMk9O9B2r7V6L3FE4PN247GpREoXR1sw1WrcTV9uYWW/yD+iCtm/8s VNLM7FAWakHBNBZwUvhs2JBWRPLJ2OkcA2ZZjEc7DrUPAZipe68TZd9XqMbZ5SGaK27y UrWw== 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=kulBovnYLz4YjgSJ0sOniJhX8Qcc8ljUXoag6+mJQMI=; b=Ul4XER7ofYrK5xkcE9h9a2Z2Us0+QERz7eUzh7LtUX1D4dcjtyYkTa4jfb6cA+4lEm LZ8MxDYsoOjBzPudzuyuLue/EhIT6/imAoBfIcwizIdwpx83/uGAW1MTIFnO8vAt3mZI nwfh8GQhxhyaS7eh0ZKQiaiHhQg/hOLc9NTM8X127G++v559e72JUkghxsUcTTxosrJ2 7HLuSfO4Atw3k91ojBajS4jp2YGk+O316L7XvkmrNQiv0MuEHaxrY2bpRjE7ml1kDuNJ 1AxHxgAlkb7TJSx+xB/+LgnwJ3SSvfPENxHbPRciQbYxSkDUMZcnwfqUO8xenBvoHMO4 To1Q== X-Gm-Message-State: APjAAAUtOSeMe1IzUbdjHdHHHtbUzheZMnluu8m92LFGFEfKYEWVfwoQ Pz/snilUGac4on99ISqiian2dg== X-Google-Smtp-Source: APXvYqzSHH0fLnM1OEVH9g2dwjO+UrubetdMq6FaTC/+d077v0da+UBWOXUJw82D1L00pRz0dLiiAA== X-Received: by 2002:aa7:9254:: with SMTP id 20mr53661464pfp.212.1564647596176; Thu, 01 Aug 2019 01:19:56 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id g2sm83127276pfi.26.2019.08.01.01.19.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:55 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 08/47] arm/arm64: smccc: Implement SMCCC v1.1 inline primitive Date: Thu, 1 Aug 2019 13:45:52 +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-20190801_012000_773519_CE1BC6F8 X-CRM114-Status: GOOD ( 14.94 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 f2d3b2e8759a5833df6f022e42df2d581e6d843c upstream. One of the major improvement of SMCCC v1.1 is that it only clobbers the first 4 registers, both on 32 and 64bit. This means that it becomes very easy to provide an inline version of the SMC call primitive, and avoid performing a function call to stash the registers that would otherwise be clobbered by SMCCC v1.0. Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Viresh Kumar --- include/linux/arm-smccc.h | 141 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 4c45fd75db5d..60c2ad6316d8 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -122,5 +122,146 @@ asmlinkage void arm_smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a5, unsigned long a6, unsigned long a7, struct arm_smccc_res *res); +/* SMCCC v1.1 implementation madness follows */ +#ifdef CONFIG_ARM64 + +#define SMCCC_SMC_INST "smc #0" +#define SMCCC_HVC_INST "hvc #0" + +#elif defined(CONFIG_ARM) +#include +#include + +#define SMCCC_SMC_INST __SMC(0) +#define SMCCC_HVC_INST __HVC(0) + +#endif + +#define ___count_args(_0, _1, _2, _3, _4, _5, _6, _7, _8, x, ...) x + +#define __count_args(...) \ + ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0) + +#define __constraint_write_0 \ + "+r" (r0), "=&r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_1 \ + "+r" (r0), "+r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_2 \ + "+r" (r0), "+r" (r1), "+r" (r2), "=&r" (r3) +#define __constraint_write_3 \ + "+r" (r0), "+r" (r1), "+r" (r2), "+r" (r3) +#define __constraint_write_4 __constraint_write_3 +#define __constraint_write_5 __constraint_write_4 +#define __constraint_write_6 __constraint_write_5 +#define __constraint_write_7 __constraint_write_6 + +#define __constraint_read_0 +#define __constraint_read_1 +#define __constraint_read_2 +#define __constraint_read_3 +#define __constraint_read_4 "r" (r4) +#define __constraint_read_5 __constraint_read_4, "r" (r5) +#define __constraint_read_6 __constraint_read_5, "r" (r6) +#define __constraint_read_7 __constraint_read_6, "r" (r7) + +#define __declare_arg_0(a0, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register unsigned long r1 asm("r1"); \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_1(a0, a1, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_2(a0, a1, a2, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register unsigned long r3 asm("r3") + +#define __declare_arg_3(a0, a1, a2, a3, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register typeof(a3) r3 asm("r3") = a3 + +#define __declare_arg_4(a0, a1, a2, a3, a4, res) \ + __declare_arg_3(a0, a1, a2, a3, res); \ + register typeof(a4) r4 asm("r4") = a4 + +#define __declare_arg_5(a0, a1, a2, a3, a4, a5, res) \ + __declare_arg_4(a0, a1, a2, a3, a4, res); \ + register typeof(a5) r5 asm("r5") = a5 + +#define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res) \ + __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ + register typeof(a6) r6 asm("r6") = a6 + +#define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res) \ + __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ + register typeof(a7) r7 asm("r7") = a7 + +#define ___declare_args(count, ...) __declare_arg_ ## count(__VA_ARGS__) +#define __declare_args(count, ...) ___declare_args(count, __VA_ARGS__) + +#define ___constraints(count) \ + : __constraint_write_ ## count \ + : __constraint_read_ ## count \ + : "memory" +#define __constraints(count) ___constraints(count) + +/* + * We have an output list that is not necessarily used, and GCC feels + * entitled to optimise the whole sequence away. "volatile" is what + * makes it stick. + */ +#define __arm_smccc_1_1(inst, ...) \ + do { \ + __declare_args(__count_args(__VA_ARGS__), __VA_ARGS__); \ + asm volatile(inst "\n" \ + __constraints(__count_args(__VA_ARGS__))); \ + if (___res) \ + *___res = (typeof(*___res)){r0, r1, r2, r3}; \ + } while (0) + +/* + * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call + * + * This is a variadic macro taking one to eight source arguments, and + * an optional return structure. + * + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This macro is used to make SMC calls following SMC Calling Convention v1.1. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the SMC instruction. The return values are updated with the content + * from register 0 to 3 on return from the SMC instruction if not NULL. + */ +#define arm_smccc_1_1_smc(...) __arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__) + +/* + * arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call + * + * This is a variadic macro taking one to eight source arguments, and + * an optional return structure. + * + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This macro is used to make HVC calls following SMC Calling Convention v1.1. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the HVC instruction. The return values are updated with the content + * from register 0 to 3 on return from the HVC instruction if not NULL. + */ +#define arm_smccc_1_1_hvc(...) __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__) + #endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Thu Aug 1 08:15:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070271 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 2D8541395 for ; Thu, 1 Aug 2019 08:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5CB28485 for ; Thu, 1 Aug 2019 08:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 133ED28481; Thu, 1 Aug 2019 08:21:49 +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 AC3BE283A8 for ; Thu, 1 Aug 2019 08:21:48 +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=zx8Z0n/2YYvilAQurRgMuBinsQX9muiqo5CgJoevMBQ=; b=uFKAYr+X3pSQY6 EAyYE3GMuPSkwPfSKrz1hFVEGpqYQqSKRaEB8IOmenxytA04VaAkkLFHr7zLXEalfGqLay0r/SOTG QM2/GO9H15vHE9KjSJUFmtXRXXgoMH/Z7ZReEDedBmHDqY5ymxda5saivz1ccYfkj+mJSGofjoTM3 sVyQKyz5i7jBXZkbSvGtuOyfSebPo5+1ls4KqiQ+bjor082ln+eqfZAK/oCDsKRA1sV8Oen9PGDKe 7oll2ycgraHLpSGrJ9kDonU9JN1NVLD8ichdMH1ROO72JwyLOVp/MmVOD4ibyanIXeRzaGLbNN5tr B4H9Q+VV2OWb/61L80OQ==; 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 1ht6LG-00044D-Tz; Thu, 01 Aug 2019 08:21:42 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jc-0000Zb-Ud for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:04 +0000 Received: by mail-pl1-x644.google.com with SMTP id 4so24862496pld.10 for ; Thu, 01 Aug 2019 01:19:59 -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=2QHSmiN7bxUJS4+X9m2RMygxyxd4x6cpBibWrQPbZA4=; b=gyCpFTJuLM7MvHrK8TfXUg8OQIEf7DynnCZ6YICKbZ9EiGi8EM99TONAPxKGNc6kQm 3hFuJY62i5Ew+NEtv8tSafNG/qzhe+cjGbtSARPHQUEgyKa7zHEXbRZAV4BDT2ZJm6vJ jsLinmkCLSYDBM41ms3BOPj8dWBOwQy+qV8V5vfjzLG2LWvD7CT76RgDp7eQxoUPllQP vB6D8S6tyncSIKwqOQTMSKQsjlWIlrO3dpDkeEEquvQuhJq8dk9JzFU9i1ub9dz0xX/t usBd+1LWn0IdleXWHo43HxgyU9wCR0JTA+VhNBKRy+wm9IC1f13K/7l7mVnHPaBOBMZd 3YAg== 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=2QHSmiN7bxUJS4+X9m2RMygxyxd4x6cpBibWrQPbZA4=; b=D0cz33WbknXVxGhlriA/qk6wBmAuW59uB3tEHNnsGVPTxLw7AMLeaweUBsEMBH+Zh8 sRAKK8q3Z9l6rVr3K6ATSxEEsOVWA7J+FR8C0W2xADW54RvUe/bmK0tff3ojgmt4SCKP iBtRzTyNEQL2RCbOLKbXKRv7OlapAmIDEbC0U1r1y+FpoFiZNd9PsxDQdulTNfdnqf8Q gLDWTxuEjtabAnIKZq9YUa7mtW0UKcjsXHXNuzEac6btYvp3IYuJZHSyk99HixkbLrZg TsqfB55prVar8jAn+/M+he6+79iXJbNm6pxTsPF3LflljPDrTbZpxr89OcsAL6PoZlmD v07Q== X-Gm-Message-State: APjAAAXccq5NouO2CkH5huJsbHF5yR89hKOCpjm0clK1WXZci2iHF5Tw yRrxCyWDeMGOSYDTayJmA2J4Zg== X-Google-Smtp-Source: APXvYqyVg3JM0Xy4ecN/+7+J9RLJ0NX9tIxjkO6xCJk1Yj66fP0gTNTIsUc9HEVBU4hgAjikmydkbw== X-Received: by 2002:a17:902:968d:: with SMTP id n13mr77405641plp.257.1564647598670; Thu, 01 Aug 2019 01:19:58 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id l1sm91580486pfl.9.2019.08.01.01.19.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:19:58 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 09/47] ARM: add more CPU part numbers for Cortex and Brahma B15 CPUs Date: Thu, 1 Aug 2019 13:45:53 +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-20190801_012001_061971_288D588D X-CRM114-Status: GOOD ( 10.33 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit f5683e76f35b4ec5891031b6a29036efe0a1ff84 upstream. Add CPU part numbers for Cortex A53, A57, A72, A73, A75 and the Broadcom Brahma B15 CPU. Signed-off-by: Russell King Acked-by: Florian Fainelli Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/cputype.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/include/asm/cputype.h b/arch/arm/include/asm/cputype.h index e9d04f475929..76bb3bd060d1 100644 --- a/arch/arm/include/asm/cputype.h +++ b/arch/arm/include/asm/cputype.h @@ -74,8 +74,16 @@ #define ARM_CPU_PART_CORTEX_A12 0x4100c0d0 #define ARM_CPU_PART_CORTEX_A17 0x4100c0e0 #define ARM_CPU_PART_CORTEX_A15 0x4100c0f0 +#define ARM_CPU_PART_CORTEX_A53 0x4100d030 +#define ARM_CPU_PART_CORTEX_A57 0x4100d070 +#define ARM_CPU_PART_CORTEX_A72 0x4100d080 +#define ARM_CPU_PART_CORTEX_A73 0x4100d090 +#define ARM_CPU_PART_CORTEX_A75 0x4100d0a0 #define ARM_CPU_PART_MASK 0xff00fff0 +/* Broadcom cores */ +#define ARM_CPU_PART_BRAHMA_B15 0x420000f0 + #define ARM_CPU_XSCALE_ARCH_MASK 0xe000 #define ARM_CPU_XSCALE_ARCH_V1 0x2000 #define ARM_CPU_XSCALE_ARCH_V2 0x4000 From patchwork Thu Aug 1 08:15:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070269 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 E6D5F13AC for ; Thu, 1 Aug 2019 08:21:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC062842A for ; Thu, 1 Aug 2019 08:21:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE79B2847E; Thu, 1 Aug 2019 08:21:36 +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 AFFB8284B5 for ; Thu, 1 Aug 2019 08:21: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=MgSQUTL743sF1vPHkgqYn0ScdVxPTuszdDkPUoA/eoc=; b=sicwlGqgMeEGw6 T1zmIG7BWqeb5k/hSk5RwLdmZOa6IXMW8r9UvWIAv+FpDv+vBtplJni+BSRZhyadIJ91A6ieBoV/6 qmdSgIFol981VRFH6RwUz9A5RB2al1aUbOB/W4/ghe1f8+qYqr3k/v/WEN5egY8iBl7fcG+KdQYjE EF9oeDc52/PV82NIVI6sGh++cWjkcjrPStmT8ziZKoVwdDn9hypgxVGuebjTqn3ECieep1KwkV6y2 z1SHMGLrms0TflbWhiXhD6tYDhaWFC2nJWft7zBT2pH7s5rMZNl9e7rAHX6R3yaOjK1hgys5ro7XH AmoovvOdMqRpQAqwH9Bg==; 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 1ht6L3-0003mx-Ut; Thu, 01 Aug 2019 08:21:29 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Je-0000dI-P6 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:06 +0000 Received: by mail-pl1-x644.google.com with SMTP id m9so31739336pls.8 for ; Thu, 01 Aug 2019 01:20:01 -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=2ThYg/2PcaE2XPc0i5Ecb1/dXdxeDGNU8nmJ2xJHUWI=; b=qgyOciaZcnLJ+ScinWgYbGi83v03wFAdwHmCXOCF3q0l+t90McwWECzJNQCizBct0B InVe2nVLoCD9H0AnZ/kurROlNkLnrqZihINvdtTgq+jfMdHAUnuDVUAiZ3afxOI4dPC6 ylEeHV6fkGaTE+dmiReo1opsGMKACSLNHUF+kT6wWe4VB3YKMGXo1CaKyR4hTD5izZYm xGoZBt+jJuG7OOJfsUpSANOWnaHZw7qFL1R1VybKfR4mnst6IwhzLyCNhEbavZBguJPM GZR8M7SHdrjtWcLdpEqNImqQBPZXnTSxFQKwzZ7LoZi+FD9QrMGi6RuvxJeUk9BFFQLz /Ppw== 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=2ThYg/2PcaE2XPc0i5Ecb1/dXdxeDGNU8nmJ2xJHUWI=; b=ivk+M3ON6UDD6RM1w/HNhuJ50a7lKcdCmc1fjGEoGYpZqg3mJ9YcmyIzoFMsFnFNKI 25Z5asWycex99ezFHH9QqUWra4P4ulyptEXM6zukYDKPhUyit2yvFVrgEyEFxpHEYiaP U1h7Af5lF4+ShjXSqhj/XkPooMkrKkNNDW/E0HVw5UVmZ4wiDOoJbGHZC83+wNpitnkR SnDLN1W2aa58WVfOS6aFd8mMgEBE3/LrJ6RPkmfmUQKSvrj7d9skOBhyXrLGBfgtHkNA IyVY4oosa9EFnssYPfqpVeszLCk0lMUGgbsPX8zYDbiEmDjudupcUqmx28QNYbmRv3/b WsGw== X-Gm-Message-State: APjAAAUO4yRIPlsojZmh3LdDrjl5emsvP0Pow98+KHkhsxkCgwIkQu8x kqrsdRIhtC2XECQPL+SJZXORCg== X-Google-Smtp-Source: APXvYqx1QQ7xXlLGULtzj9QyhS4Rr6IH3S1/6j0ENAHznJBWvqCZRhX84aieeJqPGOpKRufRa0gQkg== X-Received: by 2002:a17:902:2a27:: with SMTP id i36mr122339377plb.161.1564647601352; Thu, 01 Aug 2019 01:20:01 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id cx22sm3895076pjb.25.2019.08.01.01.20.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:00 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 10/47] ARM: bugs: prepare processor bug infrastructure Date: Thu, 1 Aug 2019 13:45:54 +0530 Message-Id: <31d400e2535e6502cfa192169c054a02c3385185.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012003_099333_6639C141 X-CRM114-Status: GOOD ( 13.49 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit a5b9177f69329314721aa7022b7e69dab23fa1f0 upstream. Prepare the processor bug infrastructure so that it can be expanded to check for per-processor bugs. Signed-off-by: Russell King Reviewed-by: Florian Fainelli Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/bugs.h | 4 ++-- arch/arm/kernel/Makefile | 1 + arch/arm/kernel/bugs.c | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 arch/arm/kernel/bugs.c diff --git a/arch/arm/include/asm/bugs.h b/arch/arm/include/asm/bugs.h index a97f1ea708d1..ed122d294f3f 100644 --- a/arch/arm/include/asm/bugs.h +++ b/arch/arm/include/asm/bugs.h @@ -10,10 +10,10 @@ #ifndef __ASM_BUGS_H #define __ASM_BUGS_H -#ifdef CONFIG_MMU extern void check_writebuffer_bugs(void); -#define check_bugs() check_writebuffer_bugs() +#ifdef CONFIG_MMU +extern void check_bugs(void); #else #define check_bugs() do { } while (0) #endif diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index 3c789496297f..f936cec24f72 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -30,6 +30,7 @@ else obj-y += entry-armv.o endif +obj-$(CONFIG_MMU) += bugs.o obj-$(CONFIG_CPU_IDLE) += cpuidle.o obj-$(CONFIG_ISA_DMA_API) += dma.o obj-$(CONFIG_FIQ) += fiq.o fiqasm.o diff --git a/arch/arm/kernel/bugs.c b/arch/arm/kernel/bugs.c new file mode 100644 index 000000000000..88024028bb70 --- /dev/null +++ b/arch/arm/kernel/bugs.c @@ -0,0 +1,9 @@ +// SPDX-Identifier: GPL-2.0 +#include +#include +#include + +void __init check_bugs(void) +{ + check_writebuffer_bugs(); +} From patchwork Thu Aug 1 08:15:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070273 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 B11041395 for ; Thu, 1 Aug 2019 08:21:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A31DC28068 for ; Thu, 1 Aug 2019 08:21:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96B4E2842A; Thu, 1 Aug 2019 08:21:56 +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 2B700283A8 for ; Thu, 1 Aug 2019 08:21:56 +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=DY/aL89vvATAFb7pwcAdJAZSKAVFaTbbDB6CbhdWvxA=; b=RqJi3NJKqcenG4 duuuCVETnFZxhUjRsPHgqNwuUAfqO7vghWwr+lWyc2SUu/scuPORFg6XC+lH4KFXaWEEwIuMZwsBX TJEkSEUAC9ZPeRD04bgaQyupZmdt/MOkXR8ZJu79wqFi/MMZ8uVYJAFGToLcPKK9erJPAHXTXFA6l 5bC4Wv2NsuyOrN/Vrzro9HLPjNXi7QSYQwwmhKmfODAtXw1YYk9d7xCV6mH+wtzlr2i7D8U1GGS2q rJD58e6o7NQOXlzNSrOR6g3KSiSrDoa2CrK9p1b5QTpviEcY3oWRsY0dALE/OB+5AejSms/D5NnCO 4P3F52RhajRAYT4dO3aw==; 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 1ht6LT-0004Mq-Ov; Thu, 01 Aug 2019 08:21:55 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jh-0000qP-DB for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:08 +0000 Received: by mail-pg1-x543.google.com with SMTP id o13so33715818pgp.12 for ; Thu, 01 Aug 2019 01:20:04 -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=X5q/embD7eXIzs5RT/nIptjidKOY81lXVOsi7bVlsas=; b=h+PuW0lEZY8T/ZZSwYcmqS9Be9NSD84V+yeP0216GYwk6bRO15/K6tS+k7m+kmYupA 0JtVTHhkqr4MqThyhhe15Tr/RvX0NBStrad4AO09QPjN1W0Fpnb3vcGKhTbnFWmwhkVf PDXheBxfY+SrGqDbQn69QmYa0oDZMcsCwhpPLa2+3aAp1x0fFWwErRzhlY7xYLIAbovm oNrcN0Dx7h8cx112E5tWi4qqCX8rXkANYfSrxrZOcrqENPoXmPGPkdutnFSJrTg2uE6F qt1AuXCict0LQkqKiIc/thfAcWghJFlIq836lYmT9Twij6OOzf0xZnJxVWARLqbXJ8Xu rhKw== 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=X5q/embD7eXIzs5RT/nIptjidKOY81lXVOsi7bVlsas=; b=TR7i5NPUOuWZHbhDgLPNtTiyBedcrNtT7ssbl3K9RTHDt9AXk/i+s9hlLJNoancVe4 RqpgdDqN5JDc0mmhDQnJKiK7K4q4DuV5v3PI4wDb36q3xdiO6OPSl6ectgtNC5OOx+r1 w8oesMUAGaE/r624goVP2TU3NdiErwLj8y+E6KkZfl27UA2Lb1KkSr7HCyVIxoAEasNs ZBE0WqxB2el+DMnKPIRO8eHGCVX9pnRzt+Sf+yavmbVBotQmmVxMAg8J/14NbOhcgb5p NgZP1n1zr3k7b+4PVfjjy9cpTpkMdCqcV/6nLgUJEgb7CxqUGyFWvVFO+Ba/O6tuZQOH tgXg== X-Gm-Message-State: APjAAAWVQ/jbt3wq7do/wktbymqAukE/p61jvKsAor7wkS4Q4F54uWi+ jO9/JDhyzO31LVYg/R/ta0P1/w== X-Google-Smtp-Source: APXvYqyWK08+WjQP1VLDl7IvK9pwIh19X0SAufMgR31Cy7cJh22fhyV6le/+wCVq0ulNjX8HRd37MQ== X-Received: by 2002:a17:90a:d343:: with SMTP id i3mr7511467pjx.15.1564647603787; Thu, 01 Aug 2019 01:20:03 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id s22sm78451239pfh.107.2019.08.01.01.20.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:03 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 11/47] ARM: bugs: hook processor bug checking into SMP and suspend paths Date: Thu, 1 Aug 2019 13:45:55 +0530 Message-Id: <98b601c1241fbdfff7d7f1e30de696055441d24b.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012005_488736_E67EDA62 X-CRM114-Status: GOOD ( 12.25 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 26602161b5ba795928a5a719fe1d5d9f2ab5c3ef upstream. Check for CPU bugs when secondary processors are being brought online, and also when CPUs are resuming from a low power mode. This gives an opportunity to check that processor specific bug workarounds are correctly enabled for all paths that a CPU re-enters the kernel. Signed-off-by: Russell King Reviewed-by: Florian Fainelli Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/bugs.h | 2 ++ arch/arm/kernel/bugs.c | 5 +++++ arch/arm/kernel/smp.c | 4 ++++ arch/arm/kernel/suspend.c | 2 ++ 4 files changed, 13 insertions(+) diff --git a/arch/arm/include/asm/bugs.h b/arch/arm/include/asm/bugs.h index ed122d294f3f..73a99c72a930 100644 --- a/arch/arm/include/asm/bugs.h +++ b/arch/arm/include/asm/bugs.h @@ -14,8 +14,10 @@ extern void check_writebuffer_bugs(void); #ifdef CONFIG_MMU extern void check_bugs(void); +extern void check_other_bugs(void); #else #define check_bugs() do { } while (0) +#define check_other_bugs() do { } while (0) #endif #endif diff --git a/arch/arm/kernel/bugs.c b/arch/arm/kernel/bugs.c index 88024028bb70..16e7ba2a9cc4 100644 --- a/arch/arm/kernel/bugs.c +++ b/arch/arm/kernel/bugs.c @@ -3,7 +3,12 @@ #include #include +void check_other_bugs(void) +{ +} + void __init check_bugs(void) { check_writebuffer_bugs(); + check_other_bugs(); } diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 0f1c11861147..bafbd29c6e64 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -396,6 +397,9 @@ asmlinkage void secondary_start_kernel(void) * before we continue - which happens after __cpu_up returns. */ set_cpu_online(cpu, true); + + check_other_bugs(); + complete(&cpu_running); local_irq_enable(); diff --git a/arch/arm/kernel/suspend.c b/arch/arm/kernel/suspend.c index 9a2f882a0a2d..134f0d432610 100644 --- a/arch/arm/kernel/suspend.c +++ b/arch/arm/kernel/suspend.c @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) cpu_switch_mm(mm->pgd, mm); local_flush_bp_all(); local_flush_tlb_all(); + check_other_bugs(); } return ret; From patchwork Thu Aug 1 08:15:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070277 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 D9CF61395 for ; Thu, 1 Aug 2019 08:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9A53283A6 for ; Thu, 1 Aug 2019 08:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE027284B5; Thu, 1 Aug 2019 08:22:16 +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 D54CA283A6 for ; Thu, 1 Aug 2019 08:22:15 +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=k4sdb3m3YsPvZhgvzKrb1gzLiZsysdL1ftEiJLvwzok=; b=OaaJ2E/YSGNJQy 4geplMCBcKH+6JbqbruLtxlcwhVorvKtMnBfR/lrb316r78OvNajAT84pLxybPtfLo+Xl6ftVKAEp MGWWemX6Fh3KMmL+kMkdDoaw20//TnQ7UT7KdeiZ/E3OGOadBN9LPMWdUq/EPV6fVbh5uGW/F4d5Y 8ZxCLuXFz1MrZvM8+T8o/knD5LP5gT/bJTGKqEQL+XMgYRWum2aubMdxzjWbqm1/fETptvtFVn8p8 DeFBWjKxnixle2wXpPZe+bHa5mxjjXwJwXLq3hVhkWNB4u+sSGlv0O7eKg9Fl0D+8UeY2JfP2U2Ia 18x4BvPDDoHIPJylDBxQ==; 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 1ht6Lm-0004oQ-6m; Thu, 01 Aug 2019 08:22:14 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jl-0001Cm-5v for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:10 +0000 Received: by mail-pf1-x444.google.com with SMTP id r1so33597258pfq.12 for ; Thu, 01 Aug 2019 01:20:07 -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=TdEXa/ACn7xvRmbVhm+K3Nf7xZB7iBxOAU/Z5YPY+9w=; b=Yc1AA1CJGqSJYLBpPb6+g8zXpFF097IJpE/ujUlSotcolHoh6Y10BNwwJfWdTdJKMs /Dlw2wfdWh9TVJ7mGv2zsjbrtaGgR+O375wcrQ5HyBRwIuUBJQf4xfWEonF0z8yGsZ1U HzxbcfvgC6DxgjV9aRwgvrwmlM49P4J92MjZ1wPS/8wlr5s+nfyFCM2g+ZLaRbWIjYtE txZOPZGuFVQsutVx5gwoLFl/60jilYmI/fOWrIiD7kMj6BT9jRZV2mlzAGt43nPdY85c IDRrxRIGx84kE4fcqmVqCPx2MicByt81b5TcVBrsEIWo+MqvzZrp578iEhPlN0HpxEsw f0jA== 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=TdEXa/ACn7xvRmbVhm+K3Nf7xZB7iBxOAU/Z5YPY+9w=; b=YIPAAC3m0iqdPXNNEckOGl501tkA28ZSc4DU/3NA2HUkhPSm3AHgR8ZgvbkdQwCEY/ 5ShlCaI1hc/GooewNWWETTrqngLPh/IwahQKl9nsOeYxDt+2M9GmDqJAxab4IXpxwfoc JJdCDvmUOnLVgujgSc0cbmgj3HHrD6zhCe2cgm9k0Fi+D7dObKy2Av6aZk9R4Lxqh2pL BDV0nLF0OdpS9O1IIPs87eggP7J8NZzI91UPTiOL8YBajk09WXGD618jgorsNj6/Adg2 T4x5gZM+bLCmkYK6IcrZembP6DxSv2zN14psi8MQHeMiE+Mqe+48Yh8kJxppVYwOUbZV OFTg== X-Gm-Message-State: APjAAAWunMAOx9bsvq8k+wDxa1ECur0oRxJuOOf94eWT9WmtJmG8cYFr rjyt7rOrlK9C4W4HgStBlYFPAHyB8t4= X-Google-Smtp-Source: APXvYqzg+k1IMsuY/0YlKSVfy0FSYlyP0aAAvifk3LfPZy6nOREz9peYXx0wqLLpaox0jbRn5W145Q== X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr7231563pjs.119.1564647606812; Thu, 01 Aug 2019 01:20:06 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id a15sm94846475pfg.102.2019.08.01.01.20.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:06 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 12/47] ARM: bugs: add support for per-processor bug checking Date: Thu, 1 Aug 2019 13:45:56 +0530 Message-Id: <812038dccaf90fed1b1331878beb0354e7e4c1d1.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012009_252412_4FD40EF2 X-CRM114-Status: GOOD ( 14.41 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 9d3a04925deeabb97c8e26d940b501a2873e8af3 upstream. Add support for per-processor bug checking - each processor function descriptor gains a function pointer for this check, which must not be an __init function. If non-NULL, this will be called whenever a CPU enters the kernel via which ever path (boot CPU, secondary CPU startup, CPU resuming, etc.) This allows processor specific bug checks to validate that workaround bits are properly enabled by firmware via all entry paths to the kernel. Signed-off-by: Russell King Reviewed-by: Florian Fainelli Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/proc-fns.h | 4 ++++ arch/arm/kernel/bugs.c | 4 ++++ arch/arm/mm/proc-macros.S | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index 8877ad5ffe10..f379f5f849a9 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h @@ -36,6 +36,10 @@ extern struct processor { * Set up any processor specifics */ void (*_proc_init)(void); + /* + * Check for processor bugs + */ + void (*check_bugs)(void); /* * Disable any processor specifics */ diff --git a/arch/arm/kernel/bugs.c b/arch/arm/kernel/bugs.c index 16e7ba2a9cc4..7be511310191 100644 --- a/arch/arm/kernel/bugs.c +++ b/arch/arm/kernel/bugs.c @@ -5,6 +5,10 @@ void check_other_bugs(void) { +#ifdef MULTI_CPU + if (processor.check_bugs) + processor.check_bugs(); +#endif } void __init check_bugs(void) diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S index c671f345266a..212147c78f4b 100644 --- a/arch/arm/mm/proc-macros.S +++ b/arch/arm/mm/proc-macros.S @@ -258,13 +258,14 @@ mcr p15, 0, ip, c7, c10, 4 @ data write barrier .endm -.macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0 +.macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0, bugs=0 .type \name\()_processor_functions, #object .align 2 ENTRY(\name\()_processor_functions) .word \dabort .word \pabort .word cpu_\name\()_proc_init + .word \bugs .word cpu_\name\()_proc_fin .word cpu_\name\()_reset .word cpu_\name\()_do_idle From patchwork Thu Aug 1 08:15:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070275 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 2DC2B1395 for ; Thu, 1 Aug 2019 08:22:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2172F28481 for ; Thu, 1 Aug 2019 08:22:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1552B284B5; Thu, 1 Aug 2019 08:22:07 +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 A4E4028481 for ; Thu, 1 Aug 2019 08:22:06 +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=mrXlPMMC0YCO1JNjj7t0Tmebgc1CAzyPUwoueOdWxOk=; b=i6XoOspzkj6VE0 fxGOsD8XTUr9kUOiJ6rhzBeGeOs7DiBuhXTVfWiEwMp4uNULl7czWccG++j6/l9hlzvuTZ/wYDhxI +FQvz67zz2QMhagMBNscRA1Rvf+NWqc4w8VK7YbLiNGZV8oPMU4UT7TlvaAuWgT9XxidSDnrfQbMu hRGz7ufQQcxr5qc1rvUIcpZgjX131uXy/FnjFS7FjbXm7EPJuU214EvXTJm0cPppCesMkUpCH6ElP H9dRD+YcHhKKn5sAim1/xaMeIKKaGVPIyeI6W+2DLcr3J0t7GnsseXwj+h/ZuBv4wSZnimnRE2UJv GCulnIC0i4KKWnGNVSnQ==; 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 1ht6Ld-0004ZY-VA; Thu, 01 Aug 2019 08:22:06 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jm-0001XT-Nb for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:12 +0000 Received: by mail-pf1-x442.google.com with SMTP id u14so33623130pfn.2 for ; Thu, 01 Aug 2019 01:20:09 -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=QZrcuQ9yf2dvoM/LK+86CRpxpDI5KmyMnFr+EN3SZok=; b=JQrn7jF9JWShYAafGE5jWBSK5tUub+i5d0k3JeBjKeEx25TQaSaJbJslZkhkHNb+bK QKBOKxd3TZf8QMlTT4Qt5XYcG6u0gxoFzgJwT9QQslAj+EWH0213vShsW2zuWb6VnBN2 H5nqpJQeFu8GwiuN5I9rEppi/LrPVQJLiPhzqWaMCg/XjRiHSzSHb+auX92vT2NvMfSj MBoOodjo+7SKXPMXm4C0zwbxomguH+XuMK4Ymqb3IImOa3xZSQsAVjfb1NvQn7qr7Flb UZDtChpZwh8Tl7v7Epe01QEqJaX1ymTnLN21DjAv3mfSq78I++NgjpoX8yq7M2x/pldO gZIQ== 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=QZrcuQ9yf2dvoM/LK+86CRpxpDI5KmyMnFr+EN3SZok=; b=lU0qCGUDQGWU2jwejP3VnlulOLU09xWBGKjyCyytU4C5OoPQksiH3yYwjAT0Y1NrYI jg18ZuNBnHwxFyZGjDqCgkpzgpioZkofrjL4R/iuczerqKDE55AfkMRA+f/DVGaVd4wy rP6fhnA5Sn7s+36pnVeMOyB7xXSO0bEl0frZCOL93xl/7aiWCXPQbbC98FGE5QoYNPFd vc0GzpT6pmgtpvS2+TP7Ak/2wai7mVdOKxPJhDCTBhLt3VGdypEIy6Hpo7L3sct7cocE dvP2RPw22u/HCP7CjxdmOXgvLZwty88MHfmbW2hZhQPi0E9Ym8k4lHG+jm9B0OdEci8U 1BRg== X-Gm-Message-State: APjAAAWOJfJqn/z1KImKo+ndhZ+zGUn4wIyMyyUxPwNPx1tXFX1A3DgL C9UDdp1SLh8dEXXP7oRUpiC3Aw== X-Google-Smtp-Source: APXvYqyrGUQC1ZAWht9Zoam/7t7fuGAI9uez8mB6s7RyA4jBJrQHQZxRXtFNqsg6bkVFghKXE90Eug== X-Received: by 2002:a65:518a:: with SMTP id h10mr116068175pgq.117.1564647609294; Thu, 01 Aug 2019 01:20:09 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id u16sm4035318pgm.83.2019.08.01.01.20.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:08 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 13/47] ARM: spectre: add Kconfig symbol for CPUs vulnerable to Spectre Date: Thu, 1 Aug 2019 13:45:57 +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-20190801_012010_794065_0CCA9321 X-CRM114-Status: GOOD ( 10.32 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit c58d237d0852a57fde9bc2c310972e8f4e3d155d upstream. Add a Kconfig symbol for CPUs which are vulnerable to the Spectre attacks. Signed-off-by: Russell King Reviewed-by: Florian Fainelli Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/mm/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig index 41218867a9a6..7ef92e6692ab 100644 --- a/arch/arm/mm/Kconfig +++ b/arch/arm/mm/Kconfig @@ -396,6 +396,7 @@ config CPU_V7 select CPU_CP15_MPU if !MMU select CPU_HAS_ASID if MMU select CPU_PABRT_V7 + select CPU_SPECTRE if MMU select CPU_TLB_V7 if MMU # ARMv7M @@ -793,6 +794,9 @@ config CPU_BPREDICT_DISABLE help Say Y here to disable branch prediction. If unsure, say N. +config CPU_SPECTRE + bool + config TLS_REG_EMUL bool select NEED_KUSER_HELPERS From patchwork Thu Aug 1 08:15:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070281 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 4C09B1395 for ; Thu, 1 Aug 2019 08:22:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D05C2839C for ; Thu, 1 Aug 2019 08:22:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 319E82847E; Thu, 1 Aug 2019 08:22:44 +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 F32DF2842A for ; Thu, 1 Aug 2019 08:22:42 +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=0dIbpj3Fg6KGUdh6aO5LTriCvmIxQ8OvUE6jtUqKMdw=; b=WmmEC7VCFgkO6v bxfwwXXZjhlBcXarGy+fUGmQvXYaEoV3ReEf21S+wZ8mRH5K23BKTuI02JVsLr4stKsvyYhjZwdE5 bSIauX8g8/nYFXNiY2PH8bEPcaPpchVXsOHpSeBrL64FCqLcdaU2+uBS4RlqmVRpLgISfNVn8RKr4 mhmh3//H/ufsg5ehzCvu8MkSPzuGD3Z5LlwXxwcGxm+frZUfyt89lER9/f8vKmP4qCO+EeDQDKuv9 tqw5I5o+HyGRSTk37qE4D1aI4nHREdcA5PPVF+nzYfXdGuq6le/cwZOv+LIMBoBp+jYb4nOul0OdR LtZyZZbliqliMfiFQ4nQ==; 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 1ht6M7-0005I7-J4; Thu, 01 Aug 2019 08:22:35 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jp-0001v3-Ez for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:18 +0000 Received: by mail-pf1-x443.google.com with SMTP id f17so29613188pfn.6 for ; Thu, 01 Aug 2019 01:20:13 -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=CrIyupKIrKrrK5tgrFteGLmJmhdaioApkHetxHZMz8k=; b=K2QIFbnpoc/R2ENh2TKGCsFcdFyStNxdhOUBETp/w3HK5Cr3AJzziEkhY08G5SmFvp 9DW3KJFxLda1K2NqOTmVrhHWcVX7Ze04pTddVzCrPvT/LjMJgI9Zj+QAL1NwCGr986Hw Jnv8rhNqSrjdgMzPo/Y11bwWtyDynsS7bMG0MWIX2uPkaNBEF9AWwmrXuLm8EgLEoV6F tvL62G3MoIRCZQ76xXF8OkGAu/X8usgZEp/Wo7RoYEeTeCu8736ZEp54gUg0mPRq41vF wmQkV3jXo+j3dt6FdHT0Ei9Jy9jKGJ5bnMtMTsmUa0jSPuqCDiLLkPeWOKIbDFMJt1Y1 c1Cg== 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=CrIyupKIrKrrK5tgrFteGLmJmhdaioApkHetxHZMz8k=; b=VWLPb2fSix6vUO2S0hAeNGFZGLihjWqk42/q2y3BfE08XvZp8deMjl3C6Um+7t8NlL 0WlNYZLb+B7ESIW95xxOEah1J5zEkYrT2h63rq2aOL7jLNCkvEc7VYN8vcZhR/dfDyK9 mGB6hny58CADuhZzGH1lYLIRRIlEvo6oYuolW4wWXsihcFDxOwjAvNsdGlUHL7PTmAI5 A4eX2llHqYePorNfQTJ0XANLVnTF6AkA+LiTW/DwJqN4o9nqd60Qi7Ioo8CT7xn7w7ij 6IeVOZ/Lw5SZBKu+816ZhYBHTPySAU9gA92DtdE+a9dwca2oSHv3zbI5r1tLtDC19bsi 0ycA== X-Gm-Message-State: APjAAAWhh02BrRddXtyztxBEC4Mh0N3wIe2kwLiSMwM3vR/5yjYXplG1 H2Sab8yylftDRtLcfFsqELjISg== X-Google-Smtp-Source: APXvYqw+CzsQ+SZ8hDVlYOUPmmc6b3UUlcGfgnHiWnG0Ovf1Q+L+bVHRTWI6+vzkaXwtkhiU7JIhKA== X-Received: by 2002:a63:b555:: with SMTP id u21mr119771811pgo.222.1564647612337; Thu, 01 Aug 2019 01:20:12 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id i14sm109861236pfk.0.2019.08.01.01.20.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:11 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 14/47] ARM: spectre-v2: harden branch predictor on context switches Date: Thu, 1 Aug 2019 13:45:58 +0530 Message-Id: <88ddb8ae0ac1c0575d719e609c418b7a79f49853.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012013_563476_B1D99BC2 X-CRM114-Status: GOOD ( 14.31 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 06c23f5ffe7ad45b908d0fff604dae08a7e334b9 upstream. Required manual merge of arch/arm/mm/proc-v7.S. Harden the branch predictor against Spectre v2 attacks on context switches for ARMv7 and later CPUs. We do this by: Cortex A9, A12, A17, A73, A75: invalidating the BTB. Cortex A15, Brahma B15: invalidating the instruction cache. Cortex A57 and Cortex A72 are not addressed in this patch. Cortex R7 and Cortex R8 are also not addressed as we do not enforce memory protection on these cores. Signed-off-by: Russell King Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/mm/Kconfig | 19 ++++++ arch/arm/mm/proc-v7-2level.S | 6 -- arch/arm/mm/proc-v7.S | 125 +++++++++++++++++++++++++++-------- 3 files changed, 115 insertions(+), 35 deletions(-) diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig index 7ef92e6692ab..71115afb71a0 100644 --- a/arch/arm/mm/Kconfig +++ b/arch/arm/mm/Kconfig @@ -797,6 +797,25 @@ config CPU_BPREDICT_DISABLE config CPU_SPECTRE bool +config HARDEN_BRANCH_PREDICTOR + bool "Harden the branch predictor against aliasing attacks" if EXPERT + depends on CPU_SPECTRE + default y + help + Speculation attacks against some high-performance processors rely + on being able to manipulate the branch predictor for a victim + context by executing aliasing branches in the attacker context. + Such attacks can be partially mitigated against by clearing + internal branch predictor state and limiting the prediction + logic in some situations. + + This config option will take CPU-specific actions to harden + the branch predictor against aliasing attacks and may rely on + specific instruction sequences or control bits being set by + the system firmware. + + If unsure, say Y. + config TLS_REG_EMUL bool select NEED_KUSER_HELPERS diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S index c6141a5435c3..f8d45ad2a515 100644 --- a/arch/arm/mm/proc-v7-2level.S +++ b/arch/arm/mm/proc-v7-2level.S @@ -41,11 +41,6 @@ * even on Cortex-A8 revisions not affected by 430973. * If IBE is not set, the flush BTAC/BTB won't do anything. */ -ENTRY(cpu_ca8_switch_mm) -#ifdef CONFIG_MMU - mov r2, #0 - mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB -#endif ENTRY(cpu_v7_switch_mm) #ifdef CONFIG_MMU mmid r1, r1 @ get mm->context.id @@ -66,7 +61,6 @@ ENTRY(cpu_v7_switch_mm) #endif bx lr ENDPROC(cpu_v7_switch_mm) -ENDPROC(cpu_ca8_switch_mm) /* * cpu_v7_set_pte_ext(ptep, pte) diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index 8e1ea433c3f1..c2950317c7c2 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -87,6 +87,17 @@ ENTRY(cpu_v7_dcache_clean_area) ret lr ENDPROC(cpu_v7_dcache_clean_area) +ENTRY(cpu_v7_iciallu_switch_mm) + mov r3, #0 + mcr p15, 0, r3, c7, c5, 0 @ ICIALLU + b cpu_v7_switch_mm +ENDPROC(cpu_v7_iciallu_switch_mm) +ENTRY(cpu_v7_bpiall_switch_mm) + mov r3, #0 + mcr p15, 0, r3, c7, c5, 6 @ flush BTAC/BTB + b cpu_v7_switch_mm +ENDPROC(cpu_v7_bpiall_switch_mm) + string cpu_v7_name, "ARMv7 Processor" .align @@ -152,31 +163,6 @@ ENTRY(cpu_v7_do_resume) ENDPROC(cpu_v7_do_resume) #endif -/* - * Cortex-A8 - */ - globl_equ cpu_ca8_proc_init, cpu_v7_proc_init - globl_equ cpu_ca8_proc_fin, cpu_v7_proc_fin - globl_equ cpu_ca8_reset, cpu_v7_reset - globl_equ cpu_ca8_do_idle, cpu_v7_do_idle - globl_equ cpu_ca8_dcache_clean_area, cpu_v7_dcache_clean_area - globl_equ cpu_ca8_set_pte_ext, cpu_v7_set_pte_ext - globl_equ cpu_ca8_suspend_size, cpu_v7_suspend_size -#ifdef CONFIG_ARM_CPU_SUSPEND - globl_equ cpu_ca8_do_suspend, cpu_v7_do_suspend - globl_equ cpu_ca8_do_resume, cpu_v7_do_resume -#endif - -/* - * Cortex-A9 processor functions - */ - globl_equ cpu_ca9mp_proc_init, cpu_v7_proc_init - globl_equ cpu_ca9mp_proc_fin, cpu_v7_proc_fin - globl_equ cpu_ca9mp_reset, cpu_v7_reset - globl_equ cpu_ca9mp_do_idle, cpu_v7_do_idle - globl_equ cpu_ca9mp_dcache_clean_area, cpu_v7_dcache_clean_area - globl_equ cpu_ca9mp_switch_mm, cpu_v7_switch_mm - globl_equ cpu_ca9mp_set_pte_ext, cpu_v7_set_pte_ext .globl cpu_ca9mp_suspend_size .equ cpu_ca9mp_suspend_size, cpu_v7_suspend_size + 4 * 2 #ifdef CONFIG_ARM_CPU_SUSPEND @@ -490,10 +476,75 @@ ENDPROC(__v7_setup) @ define struct processor (see and proc-macros.S) define_processor_functions v7, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR + @ generic v7 bpiall on context switch + globl_equ cpu_v7_bpiall_proc_init, cpu_v7_proc_init + globl_equ cpu_v7_bpiall_proc_fin, cpu_v7_proc_fin + globl_equ cpu_v7_bpiall_reset, cpu_v7_reset + globl_equ cpu_v7_bpiall_do_idle, cpu_v7_do_idle + globl_equ cpu_v7_bpiall_dcache_clean_area, cpu_v7_dcache_clean_area + globl_equ cpu_v7_bpiall_set_pte_ext, cpu_v7_set_pte_ext + globl_equ cpu_v7_bpiall_suspend_size, cpu_v7_suspend_size +#ifdef CONFIG_ARM_CPU_SUSPEND + globl_equ cpu_v7_bpiall_do_suspend, cpu_v7_do_suspend + globl_equ cpu_v7_bpiall_do_resume, cpu_v7_do_resume +#endif + define_processor_functions v7_bpiall, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + +#define HARDENED_BPIALL_PROCESSOR_FUNCTIONS v7_bpiall_processor_functions +#else +#define HARDENED_BPIALL_PROCESSOR_FUNCTIONS v7_processor_functions +#endif + #ifndef CONFIG_ARM_LPAE + @ Cortex-A8 - always needs bpiall switch_mm implementation + globl_equ cpu_ca8_proc_init, cpu_v7_proc_init + globl_equ cpu_ca8_proc_fin, cpu_v7_proc_fin + globl_equ cpu_ca8_reset, cpu_v7_reset + globl_equ cpu_ca8_do_idle, cpu_v7_do_idle + globl_equ cpu_ca8_dcache_clean_area, cpu_v7_dcache_clean_area + globl_equ cpu_ca8_set_pte_ext, cpu_v7_set_pte_ext + globl_equ cpu_ca8_switch_mm, cpu_v7_bpiall_switch_mm + globl_equ cpu_ca8_suspend_size, cpu_v7_suspend_size +#ifdef CONFIG_ARM_CPU_SUSPEND + globl_equ cpu_ca8_do_suspend, cpu_v7_do_suspend + globl_equ cpu_ca8_do_resume, cpu_v7_do_resume +#endif define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + + @ Cortex-A9 - needs more registers preserved across suspend/resume + @ and bpiall switch_mm for hardening + globl_equ cpu_ca9mp_proc_init, cpu_v7_proc_init + globl_equ cpu_ca9mp_proc_fin, cpu_v7_proc_fin + globl_equ cpu_ca9mp_reset, cpu_v7_reset + globl_equ cpu_ca9mp_do_idle, cpu_v7_do_idle + globl_equ cpu_ca9mp_dcache_clean_area, cpu_v7_dcache_clean_area +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR + globl_equ cpu_ca9mp_switch_mm, cpu_v7_bpiall_switch_mm +#else + globl_equ cpu_ca9mp_switch_mm, cpu_v7_switch_mm +#endif + globl_equ cpu_ca9mp_set_pte_ext, cpu_v7_set_pte_ext define_processor_functions ca9mp, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 #endif + + @ Cortex-A15 - needs iciallu switch_mm for hardening + globl_equ cpu_ca15_proc_init, cpu_v7_proc_init + globl_equ cpu_ca15_proc_fin, cpu_v7_proc_fin + globl_equ cpu_ca15_reset, cpu_v7_reset + globl_equ cpu_ca15_do_idle, cpu_v7_do_idle + globl_equ cpu_ca15_dcache_clean_area, cpu_v7_dcache_clean_area +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR + globl_equ cpu_ca15_switch_mm, cpu_v7_iciallu_switch_mm +#else + globl_equ cpu_ca15_switch_mm, cpu_v7_switch_mm +#endif + globl_equ cpu_ca15_set_pte_ext, cpu_v7_set_pte_ext + globl_equ cpu_ca15_suspend_size, cpu_v7_suspend_size + globl_equ cpu_ca15_do_suspend, cpu_v7_do_suspend + globl_equ cpu_ca15_do_resume, cpu_v7_do_resume + define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 #ifdef CONFIG_CPU_PJ4B define_processor_functions pj4b, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 #endif @@ -600,7 +651,7 @@ ENDPROC(__v7_setup) __v7_ca12mp_proc_info: .long 0x410fc0d0 .long 0xff0ffff0 - __v7_proc __v7_ca12mp_proc_info, __v7_ca12mp_setup + __v7_proc __v7_ca12mp_proc_info, __v7_ca12mp_setup, proc_fns = HARDENED_BPIALL_PROCESSOR_FUNCTIONS .size __v7_ca12mp_proc_info, . - __v7_ca12mp_proc_info /* @@ -610,7 +661,7 @@ ENDPROC(__v7_setup) __v7_ca15mp_proc_info: .long 0x410fc0f0 .long 0xff0ffff0 - __v7_proc __v7_ca15mp_proc_info, __v7_ca15mp_setup + __v7_proc __v7_ca15mp_proc_info, __v7_ca15mp_setup, proc_fns = ca15_processor_functions .size __v7_ca15mp_proc_info, . - __v7_ca15mp_proc_info /* @@ -620,7 +671,7 @@ ENDPROC(__v7_setup) __v7_b15mp_proc_info: .long 0x420f00f0 .long 0xff0ffff0 - __v7_proc __v7_b15mp_proc_info, __v7_b15mp_setup + __v7_proc __v7_b15mp_proc_info, __v7_b15mp_setup, proc_fns = ca15_processor_functions .size __v7_b15mp_proc_info, . - __v7_b15mp_proc_info /* @@ -630,9 +681,25 @@ ENDPROC(__v7_setup) __v7_ca17mp_proc_info: .long 0x410fc0e0 .long 0xff0ffff0 - __v7_proc __v7_ca17mp_proc_info, __v7_ca17mp_setup + __v7_proc __v7_ca17mp_proc_info, __v7_ca17mp_setup, proc_fns = HARDENED_BPIALL_PROCESSOR_FUNCTIONS .size __v7_ca17mp_proc_info, . - __v7_ca17mp_proc_info + /* ARM Ltd. Cortex A73 processor */ + .type __v7_ca73_proc_info, #object +__v7_ca73_proc_info: + .long 0x410fd090 + .long 0xff0ffff0 + __v7_proc __v7_ca73_proc_info, __v7_setup, proc_fns = HARDENED_BPIALL_PROCESSOR_FUNCTIONS + .size __v7_ca73_proc_info, . - __v7_ca73_proc_info + + /* ARM Ltd. Cortex A75 processor */ + .type __v7_ca75_proc_info, #object +__v7_ca75_proc_info: + .long 0x410fd0a0 + .long 0xff0ffff0 + __v7_proc __v7_ca75_proc_info, __v7_setup, proc_fns = HARDENED_BPIALL_PROCESSOR_FUNCTIONS + .size __v7_ca75_proc_info, . - __v7_ca75_proc_info + /* * Qualcomm Inc. Krait processors. */ From patchwork Thu Aug 1 08:15:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070279 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 1509E13B1 for ; Thu, 1 Aug 2019 08:22:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 078D32839C for ; Thu, 1 Aug 2019 08:22:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFE3E284BD; Thu, 1 Aug 2019 08:22:29 +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 2BF642839C for ; Thu, 1 Aug 2019 08:22:28 +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=tL2Fvzy5a5AtNGz1Ea+5LOM10zpkoYjVjrxWTL3M5Rk=; b=BHhAZsYs+eRR7t KDMrzkW+Q8+KNxKr1yJV6YseOYpWGHoXx2mGWlX2tHnOiOcr0+YenMr6rh1HJTVEhk7tyanCQFWny aQ1UpNakgddxH9/pzRuSIctopz/8mQWvuVqWfVDpPmnn6KwRwK3PXg491FWiEUjTDnPyb6LQTq/+i JuSPPdK0rHCZE+XRDIbaFszqA42nJo+MalOpi9/oBMDZyJS5uBwNW3wpGtay5cPACWLTuX+spcz5V cBhrTvVgq6hXpwdmlGbgdYPsi37p5E2mLP7F4DMDmC6w32gPougH2FgWaxKZnxsuF4ZEt94lLmznP Kf0gJ7wZxdRzCJ+BcRFg==; 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 1ht6Ly-00053t-MZ; Thu, 01 Aug 2019 08:22:26 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Js-00020U-5A for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:18 +0000 Received: by mail-pg1-x544.google.com with SMTP id l21so33729480pgm.3 for ; Thu, 01 Aug 2019 01:20:15 -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=Arpm02aGI6YJCtpiPBRj6TsiybDi8jaAFcwPdh06aYE=; b=KFNcIvSPhxIo/odZ9ybPsb9qMK2cpgoaVZ8iH84d7RPdUFNek/1EEwSu9tw1iYMp+8 t2bFOAkHVWg0hLqefH+McTYk9uLnPdwSNnfqVlQ9PHp3BCyUizQDCgGuuVIPQG17SlNg ycG0TRW4fcgFqkP6bWg44knQmV3arFqIJ03dRbjiM9rBG7mD7gBwjfBoME/qB8E2Whqa EdDkt9c955THlC0GL2hBqmmPTGw2rKKIkXiozQzic18cUfkXQvO2b+El/HmOK2wKEiBm WSuElSHgMmE9x0wz3ndbhJemenycSSwxXshFkg2hjJvBRRPDrKzTYeag28MFkyj/Fbc7 mI5Q== 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=Arpm02aGI6YJCtpiPBRj6TsiybDi8jaAFcwPdh06aYE=; b=ZKUGvoiMc/WDcy486gCTA7BEIlOiC08nXiFGXyrZDOfKYzWIXMo8JXUK9J7XwA6bPS SmXWqjto5/0IpU/5qCDUqUQF2ggXVvVK2qPdzs4Td5wsO4h9BgqZCEBB/SAcCr7k4m3N ttNR6gsMn66EoA7TY89+2d0hVnR1mT8wuRszJH46hNxOpd3lvdEwR8sf4aneQKH51zX5 splvyNQLHls0+J1pYy6DOtP3ujQPCSTfIhQyQj6cjfGMFubxAMaLe9XksghdtlQSjmGW 2q5ZPFTgudrnft68kvQ24K1DCy+BftQ/o4cCCHy1uIBuFzRgMgHXGHqO88qblrmPGqt+ cDZg== X-Gm-Message-State: APjAAAXa7gkcmzd/MfzElF30gbxzEuj5yFvsdSyN0QcydPuJDqN8ObGV JFX05enIlInYyn9UgANFoE8cdw== X-Google-Smtp-Source: APXvYqwbu12n3uYWy4e6tAr7Volxz6tobUd7+JfG5OBzuqilJ86eVfILw5p8mwxbJriX300JBmLYSQ== X-Received: by 2002:a17:90a:3ac2:: with SMTP id b60mr7327890pjc.74.1564647614913; Thu, 01 Aug 2019 01:20:14 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id b26sm80003500pfo.129.2019.08.01.01.20.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:14 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 15/47] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit Date: Thu, 1 Aug 2019 13:45:59 +0530 Message-Id: <9a610b2709bb86b37ec86270f023f5a3e18d3a7c.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012016_527615_ACB539A9 X-CRM114-Status: GOOD ( 15.75 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit e388b80288aade31135aca23d32eee93dd106795 upstream. When the branch predictor hardening is enabled, firmware must have set the IBE bit in the auxiliary control register. If this bit has not been set, the Spectre workarounds will not be functional. Add validation that this bit is set, and print a warning at alert level if this is not the case. Signed-off-by: Russell King Reviewed-by: Florian Fainelli Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/mm/Makefile | 2 +- arch/arm/mm/proc-v7-bugs.c | 36 ++++++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 4 ++-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mm/proc-v7-bugs.c diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile index 7f76d96ce546..35307176e46c 100644 --- a/arch/arm/mm/Makefile +++ b/arch/arm/mm/Makefile @@ -92,7 +92,7 @@ obj-$(CONFIG_CPU_MOHAWK) += proc-mohawk.o obj-$(CONFIG_CPU_FEROCEON) += proc-feroceon.o obj-$(CONFIG_CPU_V6) += proc-v6.o obj-$(CONFIG_CPU_V6K) += proc-v6.o -obj-$(CONFIG_CPU_V7) += proc-v7.o +obj-$(CONFIG_CPU_V7) += proc-v7.o proc-v7-bugs.o obj-$(CONFIG_CPU_V7M) += proc-v7m.o AFLAGS_proc-v6.o :=-Wa,-march=armv6 diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c new file mode 100644 index 000000000000..e46557db6446 --- /dev/null +++ b/arch/arm/mm/proc-v7-bugs.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +static __maybe_unused void cpu_v7_check_auxcr_set(bool *warned, + u32 mask, const char *msg) +{ + u32 aux_cr; + + asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (aux_cr)); + + if ((aux_cr & mask) != mask) { + if (!*warned) + pr_err("CPU%u: %s", smp_processor_id(), msg); + *warned = true; + } +} + +static DEFINE_PER_CPU(bool, spectre_warned); + +static void check_spectre_auxcr(bool *warned, u32 bit) +{ + if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR) && + cpu_v7_check_auxcr_set(warned, bit, + "Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable\n"); +} + +void cpu_v7_ca8_ibe(void) +{ + check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(6)); +} + +void cpu_v7_ca15_ibe(void) +{ + check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(0)); +} diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index c2950317c7c2..1436ad424f2a 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -511,7 +511,7 @@ ENDPROC(__v7_setup) globl_equ cpu_ca8_do_suspend, cpu_v7_do_suspend globl_equ cpu_ca8_do_resume, cpu_v7_do_resume #endif - define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_ca8_ibe @ Cortex-A9 - needs more registers preserved across suspend/resume @ and bpiall switch_mm for hardening @@ -544,7 +544,7 @@ ENDPROC(__v7_setup) globl_equ cpu_ca15_suspend_size, cpu_v7_suspend_size globl_equ cpu_ca15_do_suspend, cpu_v7_do_suspend globl_equ cpu_ca15_do_resume, cpu_v7_do_resume - define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_ca15_ibe #ifdef CONFIG_CPU_PJ4B define_processor_functions pj4b, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 #endif From patchwork Thu Aug 1 08:16:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070283 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 1358C13AC for ; Thu, 1 Aug 2019 08:22:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05BB027FC0 for ; Thu, 1 Aug 2019 08:22:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDF182839C; Thu, 1 Aug 2019 08:22:50 +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 351E2284D4 for ; Thu, 1 Aug 2019 08:22:50 +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=d8UywgPiAoh8fumx15td8UY4r4pZT9poGdtlHeCyQjk=; b=h/MjXMb1sggEGe AFVsJKbLyq3pOjZoJgaz1UTGAe2awwyqx5ZtQrpeODTCDj20kA09MWhiubrJqbVgUGpLfSiD5WGLR I2CX6Jmd7ZELrq5bkbV+hkv72qgnBWrvjZ54XSPH2IoPCEWQI3i1QTTuIu/x6pbt/HE8pN3+Z3950 OSX/qp1LWvoFlL+wZZ9rsMuEJG+A7um0+clslGTkpaL8uAZCx3Doanq+bBM4q//lFcr6pkpAl7hrZ SNduLX1MTHH/yqo6o2pxHAkwVCg1w+OpLntSiskguAzHdZtSAF5nn3xZ0W9hBUGhra9X7OUjAsSE0 pFXaCWSbtQJc7lRMfK8A==; 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 1ht6MK-0005aS-UK; Thu, 01 Aug 2019 08:22:48 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Ju-00023a-3b for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:20 +0000 Received: by mail-pf1-x442.google.com with SMTP id q10so33592106pff.9 for ; Thu, 01 Aug 2019 01:20:18 -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=GWBuoPEcurWKDak0e2m8FiUiWeWYmr8zikb3n4XMh3U=; b=q7HiAZVZ6w5XCi6JSITNXUus7qf13R3ZdtvYRfcXZcnyLiUbMa19jlxI+YQsssbQnp dTSvKRuCi+Tj09bq1F9qTFCXl81fsijJJ7N1pq02NN5s/rQIhPKVtXdlhGGEuuQgDv2z rMwg9oNemkqd5GDkC3rGmX8Z09VgYs4QjyHL13/AUnpgmcuhOCC0kMCl9TT/wQ3Vl8Pw lZc6ThzJ/QKqYZ0P5viIspI3Z1XT1SuUy9ZrBAk5OgSL5u8lqem2enkByuCLX+aRf5nj sj1rXj/CTfB9ex5rzvzWOFBuaYHdRi7IhozL3jsKrYve0lC8PeNBaQ7UbfuUUltJ+okf qk6Q== 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=GWBuoPEcurWKDak0e2m8FiUiWeWYmr8zikb3n4XMh3U=; b=YucPNbmMjNRbicEj4AqGF6WT2F8RFvC366znYV28hw9X7Q7j8OB41enTwigGInrYmY mNzMfGzvgnk2CW9OmF0cpkLE4/k9LWTcF7Kaw8VbDlIVag9JuaFHwAHyr7ujZ+Qreme0 1GfcPEXKeqWj1SKuv6lHV8nPQqzYLi1gqn5CNbNGsZZiLiKUQ2Yi3hibLYGc4B0X2J5l ME2H2FupSzg31kRr9XOpJ7XYYxBzrFhksJ/sBPItBxXq/SevK3Uj+bzyeoiDAcGRRYVv hZ+U2cfLB8y6ODEeUX07hM/kEhgI3Y8tkAZyNPNZuKk80JH3IqVqgbpPq6v5fk0iyPig GAsQ== X-Gm-Message-State: APjAAAV6A/q9f9Dk+fDuf4GbZWg67hbU/3nN+B+NGamCikm2KcU4U7FH l11sVZZiBsddoHyKMSwDDolzsw== X-Google-Smtp-Source: APXvYqzUs6xXAR8vli7Y6u/duOBSv+NXtmY1ZNerLWGK1KQ3lzsmuL+hJxb/eg8xSZb4AkZnl877/w== X-Received: by 2002:a62:1ac8:: with SMTP id a191mr51954060pfa.164.1564647617513; Thu, 01 Aug 2019 01:20:17 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id i7sm3393542pjk.24.2019.08.01.01.20.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:17 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 16/47] ARM: spectre-v2: harden user aborts in kernel space Date: Thu, 1 Aug 2019 13:46:00 +0530 Message-Id: <2c11c43187dae2179ccb3bb4cf9e1b8040a01bc5.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012018_181989_71F01E56 X-CRM114-Status: GOOD ( 17.67 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit f5fe12b1eaee220ce62ff9afb8b90929c396595f upstream. This required some additional defines be brought back. In order to prevent aliasing attacks on the branch predictor, invalidate the BTB or instruction cache on CPUs that are known to be affected when taking an abort on a address that is outside of a user task limit: Cortex A8, A9, A12, A17, A73, A75: flush BTB. Cortex A15, Brahma B15: invalidate icache. If the IBE bit is not set, then there is little point to enabling the workaround. Signed-off-by: Russell King Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Signed-off-by: Florian Fainelli Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/cp15.h | 18 ++++++++ arch/arm/include/asm/system_misc.h | 15 ++++++ arch/arm/mm/fault.c | 3 ++ arch/arm/mm/proc-v7-bugs.c | 73 ++++++++++++++++++++++++++++-- arch/arm/mm/proc-v7.S | 8 ++-- 5 files changed, 109 insertions(+), 8 deletions(-) diff --git a/arch/arm/include/asm/cp15.h b/arch/arm/include/asm/cp15.h index c3f11524f10c..b74b174ac9fc 100644 --- a/arch/arm/include/asm/cp15.h +++ b/arch/arm/include/asm/cp15.h @@ -49,6 +49,24 @@ #ifdef CONFIG_CPU_CP15 +#define __ACCESS_CP15(CRn, Op1, CRm, Op2) \ + "mrc", "mcr", __stringify(p15, Op1, %0, CRn, CRm, Op2), u32 +#define __ACCESS_CP15_64(Op1, CRm) \ + "mrrc", "mcrr", __stringify(p15, Op1, %Q0, %R0, CRm), u64 + +#define __read_sysreg(r, w, c, t) ({ \ + t __val; \ + asm volatile(r " " c : "=r" (__val)); \ + __val; \ +}) +#define read_sysreg(...) __read_sysreg(__VA_ARGS__) + +#define __write_sysreg(v, r, w, c, t) asm volatile(w " " c : : "r" ((t)(v))) +#define write_sysreg(v, ...) __write_sysreg(v, __VA_ARGS__) + +#define BPIALL __ACCESS_CP15(c7, 0, c5, 6) +#define ICIALLU __ACCESS_CP15(c7, 0, c5, 0) + extern unsigned long cr_alignment; /* defined in entry-armv.S */ static inline unsigned long get_cr(void) diff --git a/arch/arm/include/asm/system_misc.h b/arch/arm/include/asm/system_misc.h index a3d61ad984af..1fed41440af9 100644 --- a/arch/arm/include/asm/system_misc.h +++ b/arch/arm/include/asm/system_misc.h @@ -7,6 +7,7 @@ #include #include #include +#include extern void cpu_init(void); @@ -14,6 +15,20 @@ void soft_restart(unsigned long); extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd); extern void (*arm_pm_idle)(void); +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +typedef void (*harden_branch_predictor_fn_t)(void); +DECLARE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn); +static inline void harden_branch_predictor(void) +{ + harden_branch_predictor_fn_t fn = per_cpu(harden_branch_predictor_fn, + smp_processor_id()); + if (fn) + fn(); +} +#else +#define harden_branch_predictor() do { } while (0) +#endif + #define UDBG_UNDEFINED (1 << 0) #define UDBG_SYSCALL (1 << 1) #define UDBG_BADABORT (1 << 2) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 0d20cd594017..afc8d7cf7625 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -163,6 +163,9 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr, { struct siginfo si; + if (addr > TASK_SIZE) + harden_branch_predictor(); + #ifdef CONFIG_DEBUG_USER if (((user_debug & UDBG_SEGV) && (sig == SIGSEGV)) || ((user_debug & UDBG_BUS) && (sig == SIGBUS))) { diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c index e46557db6446..85a2e3d6263c 100644 --- a/arch/arm/mm/proc-v7-bugs.c +++ b/arch/arm/mm/proc-v7-bugs.c @@ -2,7 +2,61 @@ #include #include -static __maybe_unused void cpu_v7_check_auxcr_set(bool *warned, +#include +#include +#include + +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +DEFINE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn); + +static void harden_branch_predictor_bpiall(void) +{ + write_sysreg(0, BPIALL); +} + +static void harden_branch_predictor_iciallu(void) +{ + write_sysreg(0, ICIALLU); +} + +static void cpu_v7_spectre_init(void) +{ + const char *spectre_v2_method = NULL; + int cpu = smp_processor_id(); + + if (per_cpu(harden_branch_predictor_fn, cpu)) + return; + + switch (read_cpuid_part()) { + case ARM_CPU_PART_CORTEX_A8: + case ARM_CPU_PART_CORTEX_A9: + case ARM_CPU_PART_CORTEX_A12: + case ARM_CPU_PART_CORTEX_A17: + case ARM_CPU_PART_CORTEX_A73: + case ARM_CPU_PART_CORTEX_A75: + per_cpu(harden_branch_predictor_fn, cpu) = + harden_branch_predictor_bpiall; + spectre_v2_method = "BPIALL"; + break; + + case ARM_CPU_PART_CORTEX_A15: + case ARM_CPU_PART_BRAHMA_B15: + per_cpu(harden_branch_predictor_fn, cpu) = + harden_branch_predictor_iciallu; + spectre_v2_method = "ICIALLU"; + break; + } + if (spectre_v2_method) + pr_info("CPU%u: Spectre v2: using %s workaround\n", + smp_processor_id(), spectre_v2_method); +} +#else +static void cpu_v7_spectre_init(void) +{ +} +#endif + +static __maybe_unused bool cpu_v7_check_auxcr_set(bool *warned, u32 mask, const char *msg) { u32 aux_cr; @@ -13,24 +67,33 @@ static __maybe_unused void cpu_v7_check_auxcr_set(bool *warned, if (!*warned) pr_err("CPU%u: %s", smp_processor_id(), msg); *warned = true; + return false; } + return true; } static DEFINE_PER_CPU(bool, spectre_warned); -static void check_spectre_auxcr(bool *warned, u32 bit) +static bool check_spectre_auxcr(bool *warned, u32 bit) { - if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR) && + return IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR) && cpu_v7_check_auxcr_set(warned, bit, "Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable\n"); } void cpu_v7_ca8_ibe(void) { - check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(6)); + if (check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(6))) + cpu_v7_spectre_init(); } void cpu_v7_ca15_ibe(void) { - check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(0)); + if (check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(0))) + cpu_v7_spectre_init(); +} + +void cpu_v7_bugs_init(void) +{ + cpu_v7_spectre_init(); } diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index 1436ad424f2a..f6a4589b4fd2 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -474,8 +474,10 @@ ENDPROC(__v7_setup) __INITDATA + .weak cpu_v7_bugs_init + @ define struct processor (see and proc-macros.S) - define_processor_functions v7, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions v7, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_bugs_init #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR @ generic v7 bpiall on context switch @@ -490,7 +492,7 @@ ENDPROC(__v7_setup) globl_equ cpu_v7_bpiall_do_suspend, cpu_v7_do_suspend globl_equ cpu_v7_bpiall_do_resume, cpu_v7_do_resume #endif - define_processor_functions v7_bpiall, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions v7_bpiall, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_bugs_init #define HARDENED_BPIALL_PROCESSOR_FUNCTIONS v7_bpiall_processor_functions #else @@ -526,7 +528,7 @@ ENDPROC(__v7_setup) globl_equ cpu_ca9mp_switch_mm, cpu_v7_switch_mm #endif globl_equ cpu_ca9mp_set_pte_ext, cpu_v7_set_pte_ext - define_processor_functions ca9mp, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions ca9mp, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_bugs_init #endif @ Cortex-A15 - needs iciallu switch_mm for hardening From patchwork Thu Aug 1 08:16:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070285 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 B861213AC for ; Thu, 1 Aug 2019 08:23:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A92262850F for ; Thu, 1 Aug 2019 08:23:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D550284C8; Thu, 1 Aug 2019 08:23:00 +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 1BCC62847E for ; Thu, 1 Aug 2019 08:23:00 +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=LmqyFnmIw+JGpTkJn+hx6TmEufbugWhDO0uENFM32Do=; b=YGPGHCI9BVWfRl tM+ygPO+9u/AVeOpO/OzfaOM9s42eMwQPpGNsbaUlqrFXqsGwtTaM4QN4Kbnt+hPLeX7ScKUDb1AQ Gt3lfttEKArqCPBG+T+2RzR/E7wmc6q3+kBDarO5lWQkWNe2L8m1P+mxeoSQC5W2Vgo9gWITUVKeC 8+M7V7rZt3sdSUTUPUXT/yyFH3yJtu+InxfEKW3ifOGukq6rOK7E9T/q3Ed474hDgl58wCLg67a13 wWkL3ffYE394DMm+OY4uhFYdDAWFGb/Be+CNz71tvmbKh4m8x1n6VQzhRssQ8Whvc4qNt7DylrTg3 M1LmOO8/5AJiLlBIMqSg==; 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 1ht6MV-0005pz-Dv; Thu, 01 Aug 2019 08:22:59 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jw-00027W-QR for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:22 +0000 Received: by mail-pl1-x644.google.com with SMTP id t14so31834054plr.11 for ; Thu, 01 Aug 2019 01:20:20 -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=T4YEDbPBCBlX8lcfFrAFFzcqkBiIDW1BWpR/22wpzUw=; b=j+wIxaf24e0CpzIKK/5HFWFDaO9nWV4kFtijIqRGeIL2oUs1CUsdiqkS5A/yCZlznp FBWXMrdDWPL9t6x5kGS+637YjSCJIFmH2M72EazCBWjyx8chTwT7jj3ddbDQ8xoytiap Xyixz9QuVGvPDPLbaW1FkXwVDuJntjk6ZKja8N9BLyW//7ds0FSvKwUU8GrlQod9JtCd V2FPQDGImA2xcsiMbnY+qvK98JbLFurgS2qomwRcBgbnvyeKNObnco6sauHu+jDF9KWs ZkVqY0ZwfH9K9Rlt+sWgf2ri0qT3m+PebuXwU8wXimcvBHKDa8+C8rfE0c3IxdVXmjk2 vADg== 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=T4YEDbPBCBlX8lcfFrAFFzcqkBiIDW1BWpR/22wpzUw=; b=MtHlf3MTnjtWxnLxPrhba6kTvoFan97rBpTBTyMzG2Mw/RAFx+zeCVqny7NlfXnwp4 Uc+ndmfvnsXEBWFiLBA+GHiopLxcXyztfppXRD1JCy4y8/swxq7MZ/1ksL4HVsLBPrlx /Zz0IHx7H4NyQs40lNEHu82SiEvJmZuIUGQF5bnQr3wGtCLKQYLx2XYpScCDUfaE5oai lU15LUmzHjwjcRlFNoFr2DgztDd8cqlcTZsmsRpzGj1KErZiPsyfgIRCTSev2wlIePRR uNSujTSTE8vKeM+1UyMnfD8gDrGF4Iu2KGnh0DVvStbXv+NmJ36O5pz+qiFhsRx8xI/A ct8w== X-Gm-Message-State: APjAAAV7AbYKnaexsKiN/eK1e0XFp1lRudID0NntaCArp69Bl8QklrWP VIuSnZz/Jlzp7XvIuO4P2uR8fw== X-Google-Smtp-Source: APXvYqyaDMWnJL02FD2X1zz40Bno2tCIMohJgbzKMFoWBZQF5MuGor1DLTLPD9pXq/pUZnEilZYUyQ== X-Received: by 2002:a17:902:4222:: with SMTP id g31mr50424956pld.41.1564647620067; Thu, 01 Aug 2019 01:20:20 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id 135sm73497554pfb.137.2019.08.01.01.20.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:19 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 17/47] ARM: spectre-v2: add firmware based hardening Date: Thu, 1 Aug 2019 13:46:01 +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-20190801_012020_948692_5C8E8FD5 X-CRM114-Status: GOOD ( 13.57 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 10115105cb3aa17b5da1cb726ae8dd5f6854bd93 upstream. Add firmware based hardening for cores that require more complex handling in firmware. Signed-off-by: Russell King Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Reviewed-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/mm/proc-v7-bugs.c | 60 ++++++++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 21 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c index 85a2e3d6263c..da25a38e1897 100644 --- a/arch/arm/mm/proc-v7-bugs.c +++ b/arch/arm/mm/proc-v7-bugs.c @@ -1,14 +1,20 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include #include #include #include +#include #include #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR DEFINE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn); +extern void cpu_v7_smc_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); +extern void cpu_v7_hvc_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); + static void harden_branch_predictor_bpiall(void) { write_sysreg(0, BPIALL); @@ -19,6 +25,16 @@ static void harden_branch_predictor_iciallu(void) write_sysreg(0, ICIALLU); } +static void __maybe_unused call_smc_arch_workaround_1(void) +{ + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); +} + +static void __maybe_unused call_hvc_arch_workaround_1(void) +{ + arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); +} + static void cpu_v7_spectre_init(void) { const char *spectre_v2_method = NULL; @@ -45,7 +61,51 @@ static void cpu_v7_spectre_init(void) harden_branch_predictor_iciallu; spectre_v2_method = "ICIALLU"; break; + +#ifdef CONFIG_ARM_PSCI + default: + /* Other ARM CPUs require no workaround */ + if (read_cpuid_implementor() == ARM_CPU_IMP_ARM) + break; + /* fallthrough */ + /* Cortex A57/A72 require firmware workaround */ + case ARM_CPU_PART_CORTEX_A57: + case ARM_CPU_PART_CORTEX_A72: { + struct arm_smccc_res res; + + if (psci_ops.smccc_version == SMCCC_VERSION_1_0) + break; + + switch (psci_ops.conduit) { + case PSCI_CONDUIT_HVC: + arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_ARCH_WORKAROUND_1, &res); + if ((int)res.a0 != 0) + break; + per_cpu(harden_branch_predictor_fn, cpu) = + call_hvc_arch_workaround_1; + processor.switch_mm = cpu_v7_hvc_switch_mm; + spectre_v2_method = "hypervisor"; + break; + + case PSCI_CONDUIT_SMC: + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_ARCH_WORKAROUND_1, &res); + if ((int)res.a0 != 0) + break; + per_cpu(harden_branch_predictor_fn, cpu) = + call_smc_arch_workaround_1; + processor.switch_mm = cpu_v7_smc_switch_mm; + spectre_v2_method = "firmware"; + break; + + default: + break; + } } +#endif + } + if (spectre_v2_method) pr_info("CPU%u: Spectre v2: using %s workaround\n", smp_processor_id(), spectre_v2_method); diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index f6a4589b4fd2..b6359ce39fa7 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -9,6 +9,7 @@ * * This is the "shell" of the ARMv7 processor support. */ +#include #include #include #include @@ -87,6 +88,26 @@ ENTRY(cpu_v7_dcache_clean_area) ret lr ENDPROC(cpu_v7_dcache_clean_area) +#ifdef CONFIG_ARM_PSCI + .arch_extension sec +ENTRY(cpu_v7_smc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + smc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) + .arch_extension virt +ENTRY(cpu_v7_hvc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + hvc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) +#endif ENTRY(cpu_v7_iciallu_switch_mm) mov r3, #0 mcr p15, 0, r3, c7, c5, 0 @ ICIALLU From patchwork Thu Aug 1 08:16:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070287 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 91B351395 for ; Thu, 1 Aug 2019 08:23:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83D36284BD for ; Thu, 1 Aug 2019 08:23:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78428284BE; Thu, 1 Aug 2019 08:23:15 +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 09654284B5 for ; Thu, 1 Aug 2019 08:23:15 +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=x4uANliL6eKNkW7GxPGozrm3gwieWt5BVzEAkiE9WZY=; b=p5M/sMWYDZ2DP1 MMGNWBZrEThXu7SqyAUkMtKisQUTCD3is7JFm9zKIRyCBm0qKwWZbv8CRU3wXTxkgjpeyPj8agnxe Xi+Qi+9qzFscTzm+y34cwAU0kMyV4uqTWm5p/4Xn2e4GMCix+bVwmK/e+fW/19WX9yb7+dLul+rG2 GiY4weGvDGE7c9OV4kj7sY/4mL4n0H7OqZUYR9vVJjLA4ECx4fnAdV/6VOg703wVRWpaIEOCpxToG eSSRePhEoxr+2NM+mHpfONC1uj1DiCLwsZKyIwMD8M6g0VeL3YCIC9obXo+6ygjmy0WrzUSjALbJ+ S/xbgI3Szk+zfDDAMnoQ==; 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 1ht6Mj-000671-Km; Thu, 01 Aug 2019 08:23:13 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Jz-0002Ba-No for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:25 +0000 Received: by mail-pg1-x544.google.com with SMTP id i18so33734317pgl.11 for ; Thu, 01 Aug 2019 01:20:23 -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=9VABKBorQUfKeR09TGNvFzk8y3IzwO2qu0Xfufvbef4=; b=DQ933P7SMaIFNCoCn0GqwaK/0IZY/MQGe032YpW1qdQHOrKfg4wKeqsXlDQVKZp0cc 81qb/0UgC76sCT2JV07Le889UA4G/BvPP0vlB2dVbTJQNW1Jh7czJEybCFtWFUPPacTG 439AI1hpjbQILEDhSvJDccyEBpTNNNiZqDOeRMdrB0xXQVEYu3GYesW+xQ0RKiBDbGLv SPH7LTUJrXZ2f1YThMR+WzDzaoLiaDI57SdlpXgEJfRa4nG/ej87gKdtE/SSsq3svfnR Kh/fsSvWO5ZqhBj8Hg0Ee44Rx8z7AD6NZx/Izoca3CxQFzSiJeU6vM7DnJnSWFQPFw6o pfGw== 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=9VABKBorQUfKeR09TGNvFzk8y3IzwO2qu0Xfufvbef4=; b=BsmktaJoip/Lji4pn0wQJAMdGD3BIZT4U5hUCqWTU5ZKhBMOacs/TR1gQ1RmZwmzq+ 8o6vHWkoOZKt7MPwG+wXsvdKaD84BnB6YZuo22USRzBs/dK7eQyoOgZf29sKv7bnpJU8 IqVZkScma0976utAGekg4k4cyHWH/fqQAgE0HrbHxyDW4FfRNsRdO52Yg0parzesUzRD FKbpSRYBc1ez4hMQQQMgQe/FERcnKv7m5aBLoAYtBYfKLG3laJZOkWcRZXSbdXGmYYrK GC/vkpOmqL6j+POtgUNkpT3TN4tXHtba+5vJtakp07Mh5zXgYBb+Qo5P96yfry0FD9A0 F1HQ== X-Gm-Message-State: APjAAAX0VXD85x3msVTAd3F0OAtzT/TL1BSKaFLC4E9k1zQ51O2eNX5V N4X4YFryGSld6bGFHdFcwfx9Jg== X-Google-Smtp-Source: APXvYqw+DyMm0xB//RzNX38fJJ8GmnaUVfpXzbcLL1yA8V1oXi2z/rLKYj8PHIKkXmcxU7xY6RKPXA== X-Received: by 2002:a65:6546:: with SMTP id a6mr64618724pgw.220.1564647622525; Thu, 01 Aug 2019 01:20:22 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id i14sm109862834pfk.0.2019.08.01.01.20.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:22 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 18/47] ARM: spectre-v2: warn about incorrect context switching functions Date: Thu, 1 Aug 2019 13:46:02 +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-20190801_012023_845044_A5F5056C X-CRM114-Status: GOOD ( 11.10 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit c44f366ea7c85e1be27d08f2f0880f4120698125 upstream. Warn at error level if the context switching function is not what we are expecting. This can happen with big.Little systems, which we currently do not support. Signed-off-by: Russell King Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/mm/proc-v7-bugs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c index da25a38e1897..5544b82a2e7a 100644 --- a/arch/arm/mm/proc-v7-bugs.c +++ b/arch/arm/mm/proc-v7-bugs.c @@ -12,6 +12,8 @@ #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR DEFINE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn); +extern void cpu_v7_iciallu_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); +extern void cpu_v7_bpiall_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); extern void cpu_v7_smc_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); extern void cpu_v7_hvc_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); @@ -50,6 +52,8 @@ static void cpu_v7_spectre_init(void) case ARM_CPU_PART_CORTEX_A17: case ARM_CPU_PART_CORTEX_A73: case ARM_CPU_PART_CORTEX_A75: + if (processor.switch_mm != cpu_v7_bpiall_switch_mm) + goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = harden_branch_predictor_bpiall; spectre_v2_method = "BPIALL"; @@ -57,6 +61,8 @@ static void cpu_v7_spectre_init(void) case ARM_CPU_PART_CORTEX_A15: case ARM_CPU_PART_BRAHMA_B15: + if (processor.switch_mm != cpu_v7_iciallu_switch_mm) + goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = harden_branch_predictor_iciallu; spectre_v2_method = "ICIALLU"; @@ -82,6 +88,8 @@ static void cpu_v7_spectre_init(void) ARM_SMCCC_ARCH_WORKAROUND_1, &res); if ((int)res.a0 != 0) break; + if (processor.switch_mm != cpu_v7_hvc_switch_mm && cpu) + goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = call_hvc_arch_workaround_1; processor.switch_mm = cpu_v7_hvc_switch_mm; @@ -93,6 +101,8 @@ static void cpu_v7_spectre_init(void) ARM_SMCCC_ARCH_WORKAROUND_1, &res); if ((int)res.a0 != 0) break; + if (processor.switch_mm != cpu_v7_smc_switch_mm && cpu) + goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = call_smc_arch_workaround_1; processor.switch_mm = cpu_v7_smc_switch_mm; @@ -109,6 +119,11 @@ static void cpu_v7_spectre_init(void) if (spectre_v2_method) pr_info("CPU%u: Spectre v2: using %s workaround\n", smp_processor_id(), spectre_v2_method); + return; + +bl_error: + pr_err("CPU%u: Spectre v2: incorrect context switching function, system vulnerable\n", + cpu); } #else static void cpu_v7_spectre_init(void) From patchwork Thu Aug 1 08:16:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070289 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 A6D3113AC for ; Thu, 1 Aug 2019 08:23:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B04C28485 for ; Thu, 1 Aug 2019 08:23:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F333284B5; Thu, 1 Aug 2019 08:23:25 +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 2987A284A3 for ; Thu, 1 Aug 2019 08:23:25 +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=Hjb9eKkHdqy2UUc8rCUyp1iGJRzHDWUHCYJwvCG2yQA=; b=GhxfQSMItoObBu z5lMdaDhfIqGwv4EEhVfTrCVf5j9RqtCn+UiARjv5S8/U+k/YDGUIRgYYm14lS3POIy5QW/skUxaE 9qR1EF52+WBrX1mDXaOLZ6kqCQCvE+y1cjKUIV3PZHb3Qr8+5uYFhNrU6xPdH0YNWJXbVXUL72fks U8e/AP8i/VhNqHrH57Zw3T4yyUx6/8yJsdn4alsleVaHeZMZq8Cby6O1drHH9tB6LIrTvYbE9GEpd IbE6rKl1xMniFvAnq3n0YRborTm6WUrdT7qbXG29BSb2uusOalsbryuoQ+mLpI4D0aH+O3KlbbHQH Y6zkmTbzjAWOvh8jojLw==; 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 1ht6Mt-0006Ll-Ri; Thu, 01 Aug 2019 08:23:23 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6K1-0002G3-Tt for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:27 +0000 Received: by mail-pl1-x644.google.com with SMTP id 4so24862999pld.10 for ; Thu, 01 Aug 2019 01:20:25 -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=prTlbc1VpFmNDiAv6vpTx2HEDdjE/0SlqakQ6arRd2E=; b=pbXyYpmTiStLC+WXk8GWN6yEJYVgh2FpjiErFCzKkXxkB1pBJcEXcc75DiLneqvzzc 8z79YlSLW/ldIPd5tG1rx3/mCh+xw1q2xLPneNgxxKVYAUQWplhJVnS0kYoFQ3Q1Cwcg ttNvgYIMN8Z8jVa4ltnxf0l2xhbpMT01WiYIHKdTFrD5DFGhcGcZBs5vHQZKRK0RfmKb 91s2s8e3sC3bL+FC0EcF4YmYy7M65uashW3RfI8MeENkxMgDEMLYcby9nU39dNCzp5AP KdDPjT/L8DVLyQvnkdjcXKfkfws6lVhxqRQN+ul7L8YkTKojUjQPmd7gR488fo2+aisT dIhQ== 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=prTlbc1VpFmNDiAv6vpTx2HEDdjE/0SlqakQ6arRd2E=; b=aH9hEXbUzpz3iEmRoaXP4XT8UyQu85n2cqZZ3y7yN32PxI8o7ocYV2rqGAzEHNM+4d 67Dvl0nLrIBWCMQv++XNf5Hh0j7LFzPH6lQl5tBVPVx7L2cazWoZzi8UD8lCO1cLF4Rk xUBit2XZEEazybRxNbBBGxoBFDM6KREz7ldRLPCxxqcgYCZxRIW7blnjG9JEOyZ0ew5+ M3GAzYctwlg0rrZiN5RYplusXKLc+NTGs3zKeVuT3o8Iz/QDxtwWl2hOSY40HRRVPtMc oXCZa9BFhONtXiYFlLYNUgZW7Rc+wO6TMqUZlI1HO2Dojhk3X13BBFDH9u86BpnKnM3B 5pLg== X-Gm-Message-State: APjAAAWVstNN39RHPAVZCobQMWkwwwECcCC8H96gPZkAfL87bRfXZ+KL 0yITjXCZhCxTIzhWjr5t/5635A== X-Google-Smtp-Source: APXvYqxgkwMio4dYGApew0KsOZeBgdbSqaR1/0IhQU8wiu2DhH6nWHkofViU7CZGIB6GMjSqXFTZnA== X-Received: by 2002:a17:902:9f8e:: with SMTP id g14mr78883845plq.67.1564647625311; Thu, 01 Aug 2019 01:20:25 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id 21sm3764096pjh.25.2019.08.01.01.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:24 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 19/47] ARM: spectre-v1: add speculation barrier (csdb) macros Date: Thu, 1 Aug 2019 13:46:03 +0530 Message-Id: <980958de54ce29412a4e03e2de197e7ceb34e0a0.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012025_985588_AE5B16FD X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit a78d156587931a2c3b354534aa772febf6c9e855 upstream. Add assembly and C macros for the new CSDB instruction. Signed-off-by: Russell King Acked-by: Mark Rutland Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/assembler.h | 8 ++++++++ arch/arm/include/asm/barrier.h | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 4a275fba6059..307901f88a1e 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -441,6 +441,14 @@ THUMB( orr \reg , \reg , #PSR_T_BIT ) .size \name , . - \name .endm + .macro csdb +#ifdef CONFIG_THUMB2_KERNEL + .inst.w 0xf3af8014 +#else + .inst 0xe320f014 +#endif + .endm + .macro check_uaccess, addr:req, size:req, limit:req, tmp:req, bad:req #ifndef CONFIG_CPU_USE_DOMAINS adds \tmp, \addr, #\size - 1 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h index 27c1d26b05b5..edd9e633a84b 100644 --- a/arch/arm/include/asm/barrier.h +++ b/arch/arm/include/asm/barrier.h @@ -18,6 +18,12 @@ #define isb(option) __asm__ __volatile__ ("isb " #option : : : "memory") #define dsb(option) __asm__ __volatile__ ("dsb " #option : : : "memory") #define dmb(option) __asm__ __volatile__ ("dmb " #option : : : "memory") +#ifdef CONFIG_THUMB2_KERNEL +#define CSDB ".inst.w 0xf3af8014" +#else +#define CSDB ".inst 0xe320f014" +#endif +#define csdb() __asm__ __volatile__(CSDB : : : "memory") #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6 #define isb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \ : : "r" (0) : "memory") @@ -38,6 +44,13 @@ #define dmb(x) __asm__ __volatile__ ("" : : : "memory") #endif +#ifndef CSDB +#define CSDB +#endif +#ifndef csdb +#define csdb() +#endif + #ifdef CONFIG_ARM_HEAVY_MB extern void (*soc_mb)(void); extern void arm_heavy_mb(void); From patchwork Thu Aug 1 08:16:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070291 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 5D83E13AC for ; Thu, 1 Aug 2019 08:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FD0B283A8 for ; Thu, 1 Aug 2019 08:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4402E284A3; Thu, 1 Aug 2019 08:23:37 +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 D5450283A8 for ; Thu, 1 Aug 2019 08:23:36 +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=bJyVqD7k+H+Khzgr4zQbVlfJoS6jpdyAQbOhHnQKnWU=; b=r2M99ncizPKKUV eVz0FTVSgKjzxlUMa0B1eHlkgMDaIFmtd2O2Jx1/oRO/TtDxqIEynex9OzyyICU1MWxNUPLIur2wE +n/jtp+SdzIR2B8XjeA9iwZ9I27hnABKYjnweEKlgZkacJJPdDNIEkukRj7L9eArxrFw1lDYy5yrH t05LAy6fh3ewoObkfcq8SeB/17Wm/5Xr1AIY/sZh8xumSLuyagW2WEx5988MzZHQiiKkMA42AaRgW UHwSr1G6PNnzTZ9E+esNF6CBMTa9HD+hLJgkufwtwJocbbpwE1eEqTnd6rr9hbgyGkRS53DYxynfu 2Odnkvg2+k4VXoPuAEEA==; 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 1ht6N6-0006ak-0U; Thu, 01 Aug 2019 08:23:36 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6K5-0002JU-2Y for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:30 +0000 Received: by mail-pl1-x642.google.com with SMTP id y8so31875777plr.12 for ; Thu, 01 Aug 2019 01:20:28 -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=Ws1lkPqBsn87EY7GxNn+AzRrtY/P0vuzwO4T5yjsQK0=; b=vibnYP12Yj8WtQhINzxmLEByeOMlswC0F2GsMI8dE21QSoRhhqbMo+P7AxcGVojRUA /hT+AkEZH0AS115dCqaaXUuSv0k+4joEOreBP/68Gjb0QidyVKyPg0W89H6SlBkzcfcp +cgas23ax3Ib54qSLu3Dip6Am24mT5q2SQImorxH2sBLXwAJweYLO4iBosEvBRd4DZrN efKdS/jHbZT1/UT+qeOxf/oohBhdIpK1I7/N7ZoMU/QH/q6/zPpQlJjvHkjPsQK66OCr FiBeYSXRrQraypOAvPkKR35SP+Z/gRLeDjKA3IcMFJn1qq0vSD4pyg4aIYuWEK11NbbJ rqEg== 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=Ws1lkPqBsn87EY7GxNn+AzRrtY/P0vuzwO4T5yjsQK0=; b=fRMRLRVib73zkVQ9zpxCjvaLCPp3I1QrTdqfXqBWRniEeTfurGNquUu6jyTJ9ge6ul 8tgdlvrnwNI+5UEp2+JK4MnvfmD9BqyiyqylBTFhUNuxYbzTzxytx39p4nmanc+5Ei0f 7lqiH15hDKCfMZQi0IxvlDwzN5vpiABcpABGjWIGDRiTr5r3zFQcnrouBdC58V2y0vHs uFRTjRdBvoEvhWBpM+HjndeqzUCcBsyLgKmXzoWj2WAOqrZVZOC5+z0CBDpO1MD0xsGy YZvSfTR6Y4IRn9KRcugcXWFmhUiVyUe9O/yLs+AAgNokUy0A7NCLuoDWQ9sHfOj9eiE7 /IHg== X-Gm-Message-State: APjAAAWyp37SYnXbGYkGSCgskR8VM4D/wALIfsWrB+gGjr3u/dUqDZ6X eYlFAIxYUUVsG7l/ofYwkJwNAQ== X-Google-Smtp-Source: APXvYqx1oIG3Ac36vr5PTQduzADZMjARqFq2CKsmLOvD+dcJcvRucBlmCQDJEBuv0oww4PyrxKWUqw== X-Received: by 2002:a17:902:7043:: with SMTP id h3mr97891950plt.10.1564647627732; Thu, 01 Aug 2019 01:20:27 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id y194sm47237763pfg.116.2019.08.01.01.20.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:27 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 20/47] ARM: spectre-v1: add array_index_mask_nospec() implementation Date: Thu, 1 Aug 2019 13:46:04 +0530 Message-Id: <68b8f200fef6b51b5a140ef541fd4455ef704294.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012029_134012_B0C27F7F X-CRM114-Status: GOOD ( 10.75 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 1d4238c56f9816ce0f9c8dbe42d7f2ad81cb6613 upstream. Add an implementation of the array_index_mask_nospec() function for mitigating Spectre variant 1 throughout the kernel. Signed-off-by: Russell King Acked-by: Mark Rutland Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/barrier.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h index edd9e633a84b..744d70e1d202 100644 --- a/arch/arm/include/asm/barrier.h +++ b/arch/arm/include/asm/barrier.h @@ -108,5 +108,24 @@ do { \ #define smp_mb__before_atomic() smp_mb() #define smp_mb__after_atomic() smp_mb() +#ifdef CONFIG_CPU_SPECTRE +static inline unsigned long array_index_mask_nospec(unsigned long idx, + unsigned long sz) +{ + unsigned long mask; + + asm volatile( + "cmp %1, %2\n" + " sbc %0, %1, %1\n" + CSDB + : "=r" (mask) + : "r" (idx), "Ir" (sz) + : "cc"); + + return mask; +} +#define array_index_mask_nospec array_index_mask_nospec +#endif + #endif /* !__ASSEMBLY__ */ #endif /* __ASM_BARRIER_H */ From patchwork Thu Aug 1 08:16:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070293 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 180031395 for ; Thu, 1 Aug 2019 08:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 098EE283A8 for ; Thu, 1 Aug 2019 08:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F18E52839C; Thu, 1 Aug 2019 08:23:46 +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 81BB3283A8 for ; Thu, 1 Aug 2019 08:23:46 +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=ByAGHA+wxBuzKQfHyhx0pEbb03rWtx65anCFcgkOjUI=; b=UPw/ZBZP8/AfS2 ygUc5UmZ8zv9lgaPCHz4o3uFLif5BJomiIxjz9V9PL6VikCClNKF2NfMN/gfCp44U//czIv/C/cG3 TBgg4XDiZdc8YFK4OxzZtIw3d/OcGj0G+dwiYBZ29dPLUvH0b5zoN2+H8F5OqG9lGMjK3O5WoXFLL vR63DkogpCeSRlOAf9bkYKvgzbASuy7bR8ieSGGUELstCD24uR3pZSBbHZH6SFj/+QAYAn2NLwNaJ wAnzLQPmPd2APIB5CKLb5YqTseUMlozn6fk8FUMFTuTvLoYn1hZQ0X0rAvgMwdaJw8a4gOe/MI3Bv /o1ZZl9UQUyKp9OOq39w==; 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 1ht6NE-0006nB-VG; Thu, 01 Aug 2019 08:23:44 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6K6-0002Mu-VE for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:32 +0000 Received: by mail-pf1-x441.google.com with SMTP id b13so33608445pfo.1 for ; Thu, 01 Aug 2019 01:20:30 -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=kLSGaDTr3EMSfGVKyIoCGH7cLmpO8I4it2r2qsg5/0U=; b=S4Wz6HsrBZ4tFip1H1Xoh71BhAkngC7SSsG3Z60MGcWvZ1nYmLBFkZTCNc/gGBmYqp IvV13zZFKByRQ8qi8CH0XXNBfuFpCJIJLwbTMKFqjgMGKK/Q4D/xvBcx878dgpzncKb2 I0T8P4TIuMTI9CQMhnwtBZulf8EcnVFJrTMqHvdD90TUaF6WWzyoL6U9mkF7srlQQjFa jrrGAfvzswQqiIE12EfSt7xGgA6uDsQhoKBwYmwaCADnasmiqQOzxOV2+9PQBa/QRjk8 skcU3J2/Dw8xQoAvBxZXQBYWI3VkPxRydxL9jSpqww1lQY8LN2GiMi62LdIm56nUincD Senw== 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=kLSGaDTr3EMSfGVKyIoCGH7cLmpO8I4it2r2qsg5/0U=; b=HvtzOMI9Td3aHmySQI1q5kVFGwQR8/90mzBXAiZKzyiDqr0dN6uoXepJkuiTNNbxR+ cyFMDLoIscAubdADYJ+IzsTC5rEC4JrbWVj1IgTKQStw8UXa7jJZ4ffomXLVwW+ZHgo8 uXwSPPPS0LWVo+igHcy2togaVfUWm5+D++tL4fWeq7x0GStmczixTWYXHbHp6sIL5W/P JXdF5H3B7BRAtBsqDuhGP/VOcizk39+tffXu741ykuDoed1fFmGVqyUePxH2sWUSYVLz K6ZlDh5UOXD3mhnBIr3Egaw42OcdDH4dj+uPeiUI2rJEdcPiVpqgIV058LZm4uZ8mpZy B3lA== X-Gm-Message-State: APjAAAWqvppx1BPkG5740oJPfBmgX6u8on8/15xmjOdelv/yXD57pEzK RgIlmu2pq5FvcA4nw16qw4GM2FfT6Vw= X-Google-Smtp-Source: APXvYqyE9scLeqfx5PxPM5uNMJWNAFC88KUToiImqlb+NU/VvG6/SwuL9DS//GEOKNt+2/e831kPFA== X-Received: by 2002:a63:db47:: with SMTP id x7mr117148117pgi.375.1564647630247; Thu, 01 Aug 2019 01:20:30 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id v185sm80565687pfb.14.2019.08.01.01.20.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:29 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 21/47] ARM: spectre-v1: fix syscall entry Date: Thu, 1 Aug 2019 13:46:05 +0530 Message-Id: <64408fb0ea37930f27bb2135b8c7f11a3d16fe7a.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012031_008164_0688AD6A X-CRM114-Status: GOOD ( 13.30 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 10573ae547c85b2c61417ff1a106cffbfceada35 upstream. Prevent speculation at the syscall table decoding by clamping the index used to zero on invalid system call numbers, and using the csdb speculative barrier. Signed-off-by: Russell King Acked-by: Mark Rutland Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/kernel/entry-common.S | 18 +++++++----------- arch/arm/kernel/entry-header.S | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 30a7228eaceb..e969b18d9ff9 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -223,9 +223,7 @@ ENTRY(vector_swi) tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? bne __sys_trace - cmp scno, #NR_syscalls @ check upper syscall limit - badr lr, ret_fast_syscall @ return address - ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine + invoke_syscall tbl, scno, r10, ret_fast_syscall add r1, sp, #S_OFF 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) @@ -258,14 +256,8 @@ ENDPROC(vector_swi) mov r1, scno add r0, sp, #S_OFF bl syscall_trace_enter - - badr lr, __sys_trace_return @ return address - mov scno, r0 @ syscall number (possibly new) - add r1, sp, #S_R0 + S_OFF @ pointer to regs - cmp scno, #NR_syscalls @ check upper syscall limit - ldmccia r1, {r0 - r6} @ have to reload r0 - r6 - stmccia sp, {r4, r5} @ and update the stack args - ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine + mov scno, r0 + invoke_syscall tbl, scno, r10, __sys_trace_return, reload=1 cmp scno, #-1 @ skip the syscall? bne 2b add sp, sp, #S_OFF @ restore stack @@ -317,6 +309,10 @@ ENTRY(sys_call_table) bic scno, r0, #__NR_OABI_SYSCALL_BASE cmp scno, #__NR_syscall - __NR_SYSCALL_BASE cmpne scno, #NR_syscalls @ check range +#ifdef CONFIG_CPU_SPECTRE + movhs scno, #0 + csdb +#endif stmloia sp, {r5, r6} @ shuffle args movlo r0, r1 movlo r1, r2 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 6d243e830516..86dfee487e24 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -373,6 +373,31 @@ #endif .endm + .macro invoke_syscall, table, nr, tmp, ret, reload=0 +#ifdef CONFIG_CPU_SPECTRE + mov \tmp, \nr + cmp \tmp, #NR_syscalls @ check upper syscall limit + movcs \tmp, #0 + csdb + badr lr, \ret @ return address + .if \reload + add r1, sp, #S_R0 + S_OFF @ pointer to regs + ldmccia r1, {r0 - r6} @ reload r0-r6 + stmccia sp, {r4, r5} @ update stack arguments + .endif + ldrcc pc, [\table, \tmp, lsl #2] @ call sys_* routine +#else + cmp \nr, #NR_syscalls @ check upper syscall limit + badr lr, \ret @ return address + .if \reload + add r1, sp, #S_R0 + S_OFF @ pointer to regs + ldmccia r1, {r0 - r6} @ reload r0-r6 + stmccia sp, {r4, r5} @ update stack arguments + .endif + ldrcc pc, [\table, \nr, lsl #2] @ call sys_* routine +#endif + .endm + /* * These are the registers used in the syscall handler, and allow us to * have in theory up to 7 arguments to a function - r0 to r6. From patchwork Thu Aug 1 08:16:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070295 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 4373F1395 for ; Thu, 1 Aug 2019 08:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 330FA283A6 for ; Thu, 1 Aug 2019 08:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2734B2842A; Thu, 1 Aug 2019 08:23:55 +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 B0634283A6 for ; Thu, 1 Aug 2019 08:23:54 +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=PquvtoTqs5PA+fFvboo3kmw97cVXyrScFtGCLLdiRKw=; b=hHNNasULoFrkfV v7jF2X3hTF6+aGdSpGa7V/1oILdQZsUs70jad/vcGTiC+xHWxyrrvkGW+VRLCKBfv3rAWURKCZ+wU L/Yt9tRpYHtEvTAyE9rehAcFm5BJqgG20iF6qNFcHi6mnc//OsenBPtHOowVsGGRYo4MJcE9EmEsi H5Gt3MGQviRBW5OKTmM9lgIAegbz6sBWVdsk44frzSHItbkq8iTF8ksbTc1lUUhTBOv3Njo2Skv5L dk4qd8X3SHDO9SmxSdq2ir5ZoLAZcAa5A+S/j7yf7br4uGCCmnZiTjEdFezMv704LDHU3xcPkSWdt GQNUYTvqLJdmXbEW2fCQ==; 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 1ht6NO-000713-41; Thu, 01 Aug 2019 08:23:54 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6K9-0002Rp-QA for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:35 +0000 Received: by mail-pf1-x441.google.com with SMTP id r1so33597944pfq.12 for ; Thu, 01 Aug 2019 01:20:33 -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=8Q63Doa+cYNUasTyoI6bAijjzbaGR6LEUpU/vkgXczo=; b=OnsdO7izQSNVnwcP+XktL4K50wNOnqx0WIs3j/4fZwBlbC1vL8Vgb2fIiI3F0DZ352 hDXCHjiY36jcTMB5mAKJuG2ykd6K+l269e6V9AuhxQJ+QwNN46c9FcYNT2PRs7Ux8dyw dawW6e6Gip/Dh+pab1P/lzDYfZeOBGdM9VDiD9nFqowBMCClAN46ML417pHVVHLcAImZ Jj1R+5+//GzwB447sGneYtYUYUM0RaREDKbuGh9+mZWdlnt3ILrFgEszu/ioySwcYlul hEMRvjyIbc7eIJdA/WwhNrZjD3lSGwnOGnRPtMo3p3ayQkKuAkwMog4XZK9aT4zdelH4 k/LQ== 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=8Q63Doa+cYNUasTyoI6bAijjzbaGR6LEUpU/vkgXczo=; b=CEjJ9vZeFzX+5xxh2JNXIsC0YqcD2FcW/24r+Jj+xy4vZ/gUUkvfqJn8cApNQ8Zy9Q 8uy0zqXFjRyG8J9XVyKTgNGpSWVk35HEmn3q0jycTMdJNRnpdh4OIyCob+Tu9KhZxzDq wzX5zF423jus/wFEPxyWa0NQPK/Do0Vd/lA5krOYeWhXM6KIx6cGDP4pBavuMU4HomcJ uHKKk0JAeloXR4jq8x7lnJ1tbIJcMDFVhKm3jMB9pgelQLq94j3cte7gEXZaGJ14EK/o bXScWgTZ3SUFAbEyNq4Ctb2MoCFTuQ3fgVRe4o3Nzq8V2omW2LOfcwCn84PDc1+AzUHi vX5A== X-Gm-Message-State: APjAAAVGLmyEyNJfmhRUHC2NNMLOupR3UbC6M7BiY9B4ZwyCk52YOYRg 5CNS0BDppbOsv/fetoQS5jzviA== X-Google-Smtp-Source: APXvYqwvOhOWgRG5Ry6TKP2Km/uijYOKs0rlPuA0mCCWOxKbLEYDS5Z6VWPpRcaMDl4E8jVLeWoZuQ== X-Received: by 2002:a63:ee08:: with SMTP id e8mr64308403pgi.70.1564647633016; Thu, 01 Aug 2019 01:20:33 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id o24sm135619457pfp.135.2019.08.01.01.20.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:32 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 22/47] ARM: signal: copy registers using __copy_from_user() Date: Thu, 1 Aug 2019 13:46:06 +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-20190801_012033_936954_BAB62281 X-CRM114-Status: GOOD ( 13.81 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit c32cd419d6650e42b9cdebb83c672ec945e6bd7e upstream. __get_user_error() is used as a fast accessor to make copying structure members in the signal handling path as efficient as possible. However, with software PAN and the recent Spectre variant 1, the efficiency is reduced as these are no longer fast accessors. In the case of software PAN, it has to switch the domain register around each access, and with Spectre variant 1, it would have to repeat the access_ok() check for each access. It becomes much more efficient to use __copy_from_user() instead, so let's use this for the ARM integer registers. Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/kernel/signal.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 7b8f2141427b..a592bc0287f8 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -141,6 +141,7 @@ struct rt_sigframe { static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) { + struct sigcontext context; struct aux_sigframe __user *aux; sigset_t set; int err; @@ -149,23 +150,26 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) if (err == 0) set_current_blocked(&set); - __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err); - __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err); - __get_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err); - __get_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err); - __get_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err); - __get_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err); - __get_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err); - __get_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err); - __get_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err); - __get_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err); - __get_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err); - __get_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err); - __get_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err); - __get_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err); - __get_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err); - __get_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err); - __get_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err); + err |= __copy_from_user(&context, &sf->uc.uc_mcontext, sizeof(context)); + if (err == 0) { + regs->ARM_r0 = context.arm_r0; + regs->ARM_r1 = context.arm_r1; + regs->ARM_r2 = context.arm_r2; + regs->ARM_r3 = context.arm_r3; + regs->ARM_r4 = context.arm_r4; + regs->ARM_r5 = context.arm_r5; + regs->ARM_r6 = context.arm_r6; + regs->ARM_r7 = context.arm_r7; + regs->ARM_r8 = context.arm_r8; + regs->ARM_r9 = context.arm_r9; + regs->ARM_r10 = context.arm_r10; + regs->ARM_fp = context.arm_fp; + regs->ARM_ip = context.arm_ip; + regs->ARM_sp = context.arm_sp; + regs->ARM_lr = context.arm_lr; + regs->ARM_pc = context.arm_pc; + regs->ARM_cpsr = context.arm_cpsr; + } err |= !valid_user_regs(regs); From patchwork Thu Aug 1 08:16:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070297 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 94B1713AC for ; Thu, 1 Aug 2019 08:24:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86F102842A for ; Thu, 1 Aug 2019 08:24:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B60928481; Thu, 1 Aug 2019 08:24:13 +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 0069E2847E for ; Thu, 1 Aug 2019 08:24:12 +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=HjLPW3Afb5N85W9EhBpofx9bjTwcNmFH0Hv9JWyH8y0=; b=Mo/fBq2sf0ajyL QbVdc7XLlBlmZx0gBt+GvDzMUFhc1dRZqekZjCzgee4YJXDRNj/whdNhuOFz6Ma5HTTYgcnHoxPjU H64OwzENxevgShB5TvkZftLi/6PdxYOsAjm+T41i4RvTHsTMgEH59Gn8jAf/yhriVj7jFNhdbnFDe 6lJd0g0XuxaXn8Rp0Nsx/g3pVTxpGBncXYsB6GidlZiWZSC5AqLWcnoTgijmIUoJzn6AlE4nGb3kS fKfRV0TuS9aj6sBp57MNarTh/DxDQ+AKAhqsCX/+/Nxo5uMeoYZCvlqNMCil0UxeqNRgm02IcZ5ri s5NSc7TyW359NYCMSR9w==; 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 1ht6Nf-0007Mb-1u; Thu, 01 Aug 2019 08:24:11 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KD-0002X3-5m for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:38 +0000 Received: by mail-pf1-x442.google.com with SMTP id u14so33623822pfn.2 for ; Thu, 01 Aug 2019 01:20:37 -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=uRyk3zcBxn+kArv7clzkKBJGfRbp0pIX9juxiKGvE2U=; b=b2McCC/WCcGBPzkhtxUUkoJMeMcdJguyRODCBJ0WTu/VoS9DEEque4sOadkrF9Nbft lPCrVhWn8e8vlLv2WWnVQZJRuv3ttph1yCzYhXrPNBvES/oMHX2J1WpCdT1oG9MQMP+D Jt/0F9x460JOvtbf5koGqj6pES0Ec3SdobEldPLHFvYJvGZET5aHonfh2gMfP5ZT/VLg EJFEuXzxVGFfmlErLRbS0l/WPAPQuTGoCIH/i0Z5vanbDpw4ZjXJQREgsoYvtVVpVzbM eVc3rMqWzX0hfKrrk3QsXMlXzD6NdG5EZbR19l0oj43J9RBgyjDLk2+iB6/q7m5FMEvc 9xtA== 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=uRyk3zcBxn+kArv7clzkKBJGfRbp0pIX9juxiKGvE2U=; b=sfPnC+ignTfNsOX3aOtFgyqgPbrpRujouSvqf0SuYVAJ3WEmxrpFuOIlSr1Wb2xEtT Y5I/gfo+WCJRKNoRjsmallzTg3BGnkKJNUBb7wJF2lhSUTjBkdVd3eCpl2J3QvUsbPzb f6Ql5u9kyeOnlSzyfZ0/hvv0lJ+AKJNuHpRHcWTbTY9z70qeekI/yQrAeqpYPwN36UUT qYDCPfc1TjHHsERK9FhH3z1cCsAvodgi5hBbo3pVNVrWVtsLieIXh5GWZhJWtyew5PTl vbB3jes0FxCgt4PcwIt1veuYuVFeenUzLCdE0AdMegTu041I3ubzr4D0Nh8vVIigezFQ Ibfg== X-Gm-Message-State: APjAAAXIH26EYkxVCnTvJmLKXrc52lH/z3sKIfMP+YPzVOdbNiwLGpUU LvUikXomlhLhVgEYGDTB6/8qjQ== X-Google-Smtp-Source: APXvYqxL4re/D71PbEnnmwmOeprKRJUhUxiAc8Bj8thOBjsQS5N86j2M8Po5fkRwLg7hw8Lweus4EA== X-Received: by 2002:aa7:9dcd:: with SMTP id g13mr53047380pfq.204.1564647635649; Thu, 01 Aug 2019 01:20:35 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id n17sm74761757pfq.182.2019.08.01.01.20.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:35 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 23/47] ARM: vfp: use __copy_from_user() when restoring VFP state Date: Thu, 1 Aug 2019 13:46:07 +0530 Message-Id: <8476fc23988444fda761ae9d99563cea0b21c191.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012037_243261_4E8F98AD X-CRM114-Status: GOOD ( 17.40 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 42019fc50dfadb219f9e6ddf4c354f3837057d80 upstream. __get_user_error() is used as a fast accessor to make copying structure members in the signal handling path as efficient as possible. However, with software PAN and the recent Spectre variant 1, the efficiency is reduced as these are no longer fast accessors. In the case of software PAN, it has to switch the domain register around each access, and with Spectre variant 1, it would have to repeat the access_ok() check for each access. Use __copy_from_user() rather than __get_user_err() for individual members when restoring VFP state. Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/thread_info.h | 4 ++-- arch/arm/kernel/signal.c | 18 ++++++++---------- arch/arm/vfp/vfpmodule.c | 17 +++++++---------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index 776757d1604a..57d2ad9c75ca 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -126,8 +126,8 @@ struct user_vfp_exc; extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *, struct user_vfp_exc __user *); -extern int vfp_restore_user_hwstate(struct user_vfp __user *, - struct user_vfp_exc __user *); +extern int vfp_restore_user_hwstate(struct user_vfp *, + struct user_vfp_exc *); #endif /* diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index a592bc0287f8..76f85c38f2b8 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -107,21 +107,19 @@ static int preserve_vfp_context(struct vfp_sigframe __user *frame) return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc); } -static int restore_vfp_context(struct vfp_sigframe __user *frame) +static int restore_vfp_context(struct vfp_sigframe __user *auxp) { - unsigned long magic; - unsigned long size; - int err = 0; - - __get_user_error(magic, &frame->magic, err); - __get_user_error(size, &frame->size, err); + struct vfp_sigframe frame; + int err; + err = __copy_from_user(&frame, (char __user *) auxp, sizeof(frame)); if (err) - return -EFAULT; - if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE) + return err; + + if (frame.magic != VFP_MAGIC || frame.size != VFP_STORAGE_SIZE) return -EINVAL; - return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc); + return vfp_restore_user_hwstate(&frame.ufp, &frame.ufp_exc); } #endif diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 2a61e4b04600..7aa6366b2a8d 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -601,13 +601,11 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp, } /* Sanitise and restore the current VFP state from the provided structures. */ -int vfp_restore_user_hwstate(struct user_vfp __user *ufp, - struct user_vfp_exc __user *ufp_exc) +int vfp_restore_user_hwstate(struct user_vfp *ufp, struct user_vfp_exc *ufp_exc) { struct thread_info *thread = current_thread_info(); struct vfp_hard_struct *hwstate = &thread->vfpstate.hard; unsigned long fpexc; - int err = 0; /* Disable VFP to avoid corrupting the new thread state. */ vfp_flush_hwstate(thread); @@ -616,17 +614,16 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp, * Copy the floating point registers. There can be unused * registers see asm/hwcap.h for details. */ - err |= __copy_from_user(&hwstate->fpregs, &ufp->fpregs, - sizeof(hwstate->fpregs)); + memcpy(&hwstate->fpregs, &ufp->fpregs, sizeof(hwstate->fpregs)); /* * Copy the status and control register. */ - __get_user_error(hwstate->fpscr, &ufp->fpscr, err); + hwstate->fpscr = ufp->fpscr; /* * Sanitise and restore the exception registers. */ - __get_user_error(fpexc, &ufp_exc->fpexc, err); + fpexc = ufp_exc->fpexc; /* Ensure the VFP is enabled. */ fpexc |= FPEXC_EN; @@ -635,10 +632,10 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp, fpexc &= ~(FPEXC_EX | FPEXC_FP2V); hwstate->fpexc = fpexc; - __get_user_error(hwstate->fpinst, &ufp_exc->fpinst, err); - __get_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err); + hwstate->fpinst = ufp_exc->fpinst; + hwstate->fpinst2 = ufp_exc->fpinst2; - return err ? -EFAULT : 0; + return 0; } /* From patchwork Thu Aug 1 08:16:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070299 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 4AB5113AC for ; Thu, 1 Aug 2019 08:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E32E283A8 for ; Thu, 1 Aug 2019 08:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3272E28481; Thu, 1 Aug 2019 08:24:23 +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 CE48D2842A for ; Thu, 1 Aug 2019 08:24:22 +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=rVnfQvCWYfdtib91pCW9lo9JKOAndyznDwNS87BSLLo=; b=tD3n5efzvrYmTS A3LEREcGwpfulyl0THUoUANxhuWv6oFEyDu56hBtxSsbOhzPzJLn0H0rO3fkge6/BHf+WQJ9L8Iij OUoNKYnNoCoZETHP4xV8hSZcpI2kJBWPOFtkRK4UMY3piMGQx634JEQWy9AUDG1yGJAY6qnDANFG0 /oMSG8onD8UDVoNnGiSYYagG4oM+BepT9xPZIbQZAX0HV7Apq16bLQOSn/XIf8pd5+qBYaHW9tjQk Rx+mDv0wBlfXr2HPpV/1X+CkDRxpgjVcjp4xyWqwc3KDWX8HamMUBBit+dSDZqGGRuqityLjM68r4 1UrswaW1MfsPfHRoAh3A==; 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 1ht6Nq-0007Zb-5T; Thu, 01 Aug 2019 08:24:22 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KE-0002ZY-Ly for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:40 +0000 Received: by mail-pf1-x444.google.com with SMTP id q10so33592627pff.9 for ; Thu, 01 Aug 2019 01:20:38 -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=cd+CJgxpyw48wYexEQLN0Ryuy346dGX9j+MO3rZWGCA=; b=Z2hoeeYKddLvWgzkdCUEz+2ekNkZhKgcRMApcaKIJ7G2CIMAm1cubhuNLH0vwcT8P8 DmxIMWPwhRX603RJVjktdRBeAM4BzKt+1c16yhRSV52OElcwQ2L6MNZDgJZKJ2XoR/Vr qgiyoHQNvVUb7Nc+j7L1Iqm1RRpCH+xuPcVYNz1OUQYngmWAZuAlPcPICZa557bjJoeQ 30kRgnzcmBqKpvWjBhMv9oMvtu6dj7gKLZofh36CdRU9/n0nfWQvp2xA3iJPXLxub6cc 3Db/fga6lj3CgKI85yaJQhvd5i4Z9vn/+aPJLHb392RWMyFDVdH5e/2+Gp5+p1LbBpvR 4qMQ== 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=cd+CJgxpyw48wYexEQLN0Ryuy346dGX9j+MO3rZWGCA=; b=ZaevSJpGpybIbbiN5VSOktr6Pl5R0Nr78awu1oFZLEh0bddiqDeARYGjicedq2LVGP NSdTvQC457YajvS51AWEH/Gr73G64QvGT1dwI5Bv/B0Gzt7d0IOqJBOEd1xzS6E5mYqf yaPqHu0v2fbkSphIL0eLSnNlSyDYyo14vd5cMrJA0D3WKNKT5tMLtf1s7kABLId2+XTJ 6+n5x8Cgv4MNE4nHhkw3yoJUQyMHjt5RQDyYRoLGNHUogx1NlxDn4I1ZRsHPre8UrCqy ScMj/aKVsjw4TMmslvtWlxCQxcf6x14IMqMdwp4Y86yJgZY5e2HTA4Zd6H2mBWPBUJqW KvJw== X-Gm-Message-State: APjAAAWgjIeJ5Vtivv/dOjTwROuU5UvT3xGdmadD7cL8NtPHD52U1ZLN 8WHGb6dyR1heIPKU9qLufPZ8lw== X-Google-Smtp-Source: APXvYqwtcDCmIxl5mkdh/47SacWqkNbX1MQ0IltsOO1s27+NiUNuJFRU7Slh4TpJoMf4kw0ZVjpeAw== X-Received: by 2002:a63:1046:: with SMTP id 6mr120820447pgq.111.1564647638075; Thu, 01 Aug 2019 01:20:38 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id e189sm56924368pgc.15.2019.08.01.01.20.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:37 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 24/47] ARM: oabi-compat: copy semops using __copy_from_user() Date: Thu, 1 Aug 2019 13:46:08 +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-20190801_012038_788384_AAD4F722 X-CRM114-Status: GOOD ( 13.45 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 8c8484a1c18e3231648f5ba7cc5ffb7fd70b3ca4 upstream. __get_user_error() is used as a fast accessor to make copying structure members as efficient as possible. However, with software PAN and the recent Spectre variant 1, the efficiency is reduced as these are no longer fast accessors. In the case of software PAN, it has to switch the domain register around each access, and with Spectre variant 1, it would have to repeat the access_ok() check for each access. Rather than using __get_user_error() to copy each semops element member, copy each semops element in full using __copy_from_user(). Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/kernel/sys_oabi-compat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index 5f221acd21ae..640748e27035 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -328,9 +328,11 @@ asmlinkage long sys_oabi_semtimedop(int semid, return -ENOMEM; err = 0; for (i = 0; i < nsops; i++) { - __get_user_error(sops[i].sem_num, &tsops->sem_num, err); - __get_user_error(sops[i].sem_op, &tsops->sem_op, err); - __get_user_error(sops[i].sem_flg, &tsops->sem_flg, err); + struct oabi_sembuf osb; + err |= __copy_from_user(&osb, tsops, sizeof(osb)); + sops[i].sem_num = osb.sem_num; + sops[i].sem_op = osb.sem_op; + sops[i].sem_flg = osb.sem_flg; tsops++; } if (timeout) { From patchwork Thu Aug 1 08:16:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070301 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 25CFF1395 for ; Thu, 1 Aug 2019 08:24:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13524284A3 for ; Thu, 1 Aug 2019 08:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 082E3284C8; Thu, 1 Aug 2019 08:24:34 +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 9F5A8284A3 for ; Thu, 1 Aug 2019 08:24:33 +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=HzqiVL4grOwwPyNB3bjAXfOWwrZmXBmdWHtJRPYISFM=; b=uKNuY/bNNY3K4h YGrb39xR5YDx/kR2czQJ+1w4n3VN0axfLMEGxTZJL7RoE6mYeiFTpZ2gL1pWDJGo9FgiYozXFnvM/ fALXoWXzhDRzMph83SWX4HuEbWZmgl0+5AYz+N/YpXkbdl79XdZafB0xg6/bbl4KRwhK3Eo3vxAEq 8g+LIRQceI08oBG3kE8wTV5F5l7mRUWN22zTYCVniOuGp0hkE1sSv8+kM3J3S+0+od/jr+m0O15AU 8sgnY10EeQTdyrjg9X2f/T2/ITY7deFEngFenwXxf2aWISm1UhTfbE9GcOHDvAz1reNNl1LrcsB0k Gq28PcV/zVX04EeqRAwg==; 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 1ht6Nz-0007nU-A7; Thu, 01 Aug 2019 08:24:31 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KH-0002cX-Br for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:43 +0000 Received: by mail-pl1-x641.google.com with SMTP id k8so31880290plt.3 for ; Thu, 01 Aug 2019 01:20:41 -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=fgFpO2t01PxhbBlSjah6QrAfkGefLJP0TJCP7weC9qM=; b=byvD1gfBsJYYwf5gTuTCDAMb2Ei2f+ddF+FWpNZAOA2FK8nZ3lY/xQ3L6+pqLTCQWx S419flQUmSiXQRBMEvOXH7UV/bgf26Xjr0Bt+Am7fJ2KQSVDpuC503n96UEm94uFhX5O w9XiAi3qq8Get9zzs1H4q/KVzXYGYhWxOZUJtDPKKBoCMRYrKGT6sVqC8rJX2m6SGbCw HJN0yK5KZua6FArn2rWUtxg2hKobGdHn/QAUGFWTZcAThBEitj76Ohj1/xZX1NGznLVu bQeaVIEiM0eIDVmu+2/51NGFyncA1KEPNvWvA8OCSS4LQiFKYDINluM5u+BuLJanTATJ Pezw== 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=fgFpO2t01PxhbBlSjah6QrAfkGefLJP0TJCP7weC9qM=; b=WvLaFVpHRm1cmT0ujByaZVT8CNLloSwfeCfgXl2aQPnrwhIgyxFzkOf/1seexZe7A8 wRPU2JwqSO8sHsc4TqkpFgdF5UZmsW2H14MgzY9hhm78s/Gk+f4eOtd0EyOGF5632mBE M3H8rMucrWJfaI2oz+uem9E2La3Ouaj5KCUmwu5gBzkPOJsj5au9/ipd1yM+ZxWUcRHa QYV6kXv43uGkuviyl7SwKoIvHjv8F466fRruZErZqpZ/EXHjxR5YB8+hpksvY42rG/Ha WeHTnI38tFyEGF6Y6mxXSQ1cZI6rB13qsRwvq9kEOrofVmidd3tsppuZtXqJtZu6jvFH ulhw== X-Gm-Message-State: APjAAAWI1xnlSfTk3Bt6fl+ean5D/vYhoOh0oWbnSSq1yKUGdd9nrI/j +LdntW/a2zjNJt+317qv1Ttfdw== X-Google-Smtp-Source: APXvYqx0aQyv9uox76KcN8c63PWcRqTbkztruBFEgMQ41KRiCS37kpJSbzgLdlWeCGAHkE+43u5UdQ== X-Received: by 2002:a17:902:a9ca:: with SMTP id b10mr49835975plr.69.1564647640760; Thu, 01 Aug 2019 01:20:40 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id v12sm3709247pjk.13.2019.08.01.01.20.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:40 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 25/47] ARM: use __inttype() in get_user() Date: Thu, 1 Aug 2019 13:46:09 +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-20190801_012041_429034_58C25516 X-CRM114-Status: GOOD ( 12.99 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit d09fbb327d670737ab40fd8bbb0765ae06b8b739 upstream. Borrow the x86 implementation of __inttype() to use in get_user() to select an integer type suitable to temporarily hold the result value. This is necessary to avoid propagating the volatile nature of the result argument, which can cause the following warning: lib/iov_iter.c:413:5: warning: optimization may eliminate reads and/or writes to register variables [-Wvolatile-register-var] Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/uaccess.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index cd8b589111ba..968b50063431 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -122,6 +122,13 @@ static inline void set_fs(mm_segment_t fs) : "cc"); \ flag; }) +/* + * This is a type: either unsigned long, if the argument fits into + * that type, or otherwise unsigned long long. + */ +#define __inttype(x) \ + __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) + /* * Single-value transfer routines. They automatically use the right * size if we just have the right pointer type. Note that the functions @@ -191,7 +198,7 @@ extern int __get_user_64t_4(void *); ({ \ unsigned long __limit = current_thread_info()->addr_limit - 1; \ register const typeof(*(p)) __user *__p asm("r0") = (p);\ - register typeof(x) __r2 asm("r2"); \ + register __inttype(x) __r2 asm("r2"); \ register unsigned long __l asm("r1") = __limit; \ register int __e asm("r0"); \ unsigned int __ua_flags = uaccess_save_and_enable(); \ From patchwork Thu Aug 1 08:16:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070303 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 AA29113AC for ; Thu, 1 Aug 2019 08:24:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B9C128306 for ; Thu, 1 Aug 2019 08:24:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FA0828481; Thu, 1 Aug 2019 08:24:45 +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 1497528306 for ; Thu, 1 Aug 2019 08:24:45 +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=qH8THBL+9QTlla6ROXa5PvqGEYd7Nyz+glrTDx6XX2A=; b=Hg8N0w2QYb/UbD X3X56mcxp/xHMwJJPjmOFDMTPfAz/QUBOfE4EcTfuqkkRYqTHPzd8ydGhos37MhMS7I5kmNkZgGa3 NoxtGaZC/z3rBDJRkD66dD6CD3UYI3lJt57nRdnb/b/OeXbUl7VFxM2/8uSQTVGbdD1FT3S2yQoRj ON2MeRRk8BZDWQdgAw5buEmQFefTPOy0PsfrydqpQNRLMde+OqoM/9Q17bCD2GIeS246zGtIaao3d tfBJFull6/ypRb44aGGUrEFxA1ggIwR+LPxb2E2FHkpgfsvHsPlxsZTv4eI5IVntQb6T7FITUVOjG Q2gEdUnX9QDQgxynpLgw==; 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 1ht6OB-00082H-K9; Thu, 01 Aug 2019 08:24:43 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KK-0002fD-89 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:45 +0000 Received: by mail-pl1-x641.google.com with SMTP id b7so31902365pls.6 for ; Thu, 01 Aug 2019 01:20:44 -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=38pdn6yMPIMVV02QHWSD6x84Nqpn4d6LkQlpQyJb38o=; b=hpj8rFpqrv5qQhzotiE9gMdgzeeBBY56JsYcX7mov2k4sLQED6mYGWck9/YlmIsNte CvgNOeTzEU/dOYJodtSCB/QqdhAWuKaWfHbSDifhT7uswu3+TXhLyYcJMnYSklDo2R65 naU69OUI9lfGVslVSxJiiwfCNGn62aCu3lwlJIh7Tf55NYlFiUfpB+YQzce5TrXsjSLr q74/ypxEdtW3UDTY+0ssOk3V4RqaK1kmHYGv+j9E0+masU4wpX5nCLSroLSz1wwvgmZt PJaWq6BASd5p7zAoOmB4CddaIgIFG2/7658BQH6TXT/Y8J+l1bk9aXHhozn7zAhQmTsX swMw== 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=38pdn6yMPIMVV02QHWSD6x84Nqpn4d6LkQlpQyJb38o=; b=GX7HZtBx8hBGW8CKjwT/5898iNJmAaXmHx2Mz9BsHyLAY7UudJ6zqF4zpXWs2pGVk2 ZCMD03apG2L9cdFTjfjlvk0PI5hPm6yC03hVDDGWjRurbGReycILeN24SjYIYqBlNjVX S2z3nuAc+sTmAOJtla5kAdgM64h9Udq+FaN8U1vpArsz+iRA5RtCJ3ZHq0AqE/8c3v+z 4wL+oxXbbT+3AdSGBLrvWDVKhUl91b0aXFga7SxdStZnj2fuOQ+AWsVtfyHIkJJP/6pg +QQQ572QLw9mQFbslbWB4dHA19juy4l0uwwtLfV1obzjTlsdFay54EAZYGnZFY7J+ZxD rZ5w== X-Gm-Message-State: APjAAAWTrdGC9pEqYS/wKM2QgYB9TD+NI6T1fpggIpNy9d4annqftuFv yERcN213I7TFkDdfphdrJzqJxA== X-Google-Smtp-Source: APXvYqzFqEhG8iSDqc8c1Fwl0FFlxIe0jTCk/Jowo/7z3bJOap5hms2k/E0l9VfM/kV7WHN07BlFyg== X-Received: by 2002:a17:902:2a69:: with SMTP id i96mr123097817plb.108.1564647643267; Thu, 01 Aug 2019 01:20:43 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id t7sm67895102pfh.101.2019.08.01.01.20.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:42 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 26/47] ARM: spectre-v1: use get_user() for __get_user() Date: Thu, 1 Aug 2019 13:46:10 +0530 Message-Id: <092598d625ced1af31bac019a567319e189cb1ea.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012044_339707_DEB840E7 X-CRM114-Status: GOOD ( 13.12 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit b1cd0a14806321721aae45f5446ed83a3647c914 upstream. Fixing __get_user() for spectre variant 1 is not sane: we would have to add address space bounds checking in order to validate that the location should be accessed, and then zero the address if found to be invalid. Since __get_user() is supposed to avoid the bounds check, and this is exactly what get_user() does, there's no point having two different implementations that are doing the same thing. So, when the Spectre workarounds are required, make __get_user() an alias of get_user(). Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/uaccess.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index 968b50063431..ecd159b45f12 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -314,6 +314,15 @@ static inline void set_fs(mm_segment_t fs) #define user_addr_max() \ (segment_eq(get_fs(), KERNEL_DS) ? ~0UL : get_fs()) +#ifdef CONFIG_CPU_SPECTRE +/* + * When mitigating Spectre variant 1, it is not worth fixing the non- + * verifying accessors, because we need to add verification of the + * address space there. Force these to use the standard get_user() + * version instead. + */ +#define __get_user(x, ptr) get_user(x, ptr) +#else /* * The "__xxx" versions of the user access functions do not verify the * address space - it must have been done previously with a separate @@ -330,12 +339,6 @@ static inline void set_fs(mm_segment_t fs) __gu_err; \ }) -#define __get_user_error(x, ptr, err) \ -({ \ - __get_user_err((x), (ptr), err); \ - (void) 0; \ -}) - #define __get_user_err(x, ptr, err) \ do { \ unsigned long __gu_addr = (unsigned long)(ptr); \ @@ -395,6 +398,7 @@ do { \ #define __get_user_asm_word(x, addr, err) \ __get_user_asm(x, addr, err, ldr) +#endif #define __put_user(x, ptr) \ ({ \ From patchwork Thu Aug 1 08:16:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070305 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 AD3821395 for ; Thu, 1 Aug 2019 08:24:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DF63284A3 for ; Thu, 1 Aug 2019 08:24:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91BC3284C5; Thu, 1 Aug 2019 08:24:55 +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 2167F284B5 for ; Thu, 1 Aug 2019 08:24:55 +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=n8Rh2IjMRNBLdaFleibWrz+RFEnst/UFAlD6Cwe9ba0=; b=OZW/g6XZi6Qqtn piTTETFpPq9AISas1SiG/LGtv7fNk6XQC+fuiy9Fgm5M3pyY0AHD7z6K8T0Eemv9DJ67q7sgrPiBQ C8TI14Vt1aKZ7r2I9nEXwQ05lOvDePEtv/DbJaUozQaFbNEd88RvoOAKsJh7COqp9ljz62JOvNVlS hRc8sN/itT/4lZOGON2HJTVGJKaazW5PKxkwYjRqRwBL7yvAy4+DzjsqTK5h8y5YKugqO/1fhhiKS B0jFWL2a9za7tivzTUpP26ktKhWFx4DWqInzlTDi+VaZ+WLPANqQ5SOuXL98lD1ropfrnLrY4pOzQ HGEskVbqrc1SNR0PRWhg==; 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 1ht6OM-0008E6-8g; Thu, 01 Aug 2019 08:24:54 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KM-0002io-78 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:47 +0000 Received: by mail-pf1-x442.google.com with SMTP id p184so33599812pfp.7 for ; Thu, 01 Aug 2019 01:20:46 -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=q3Hwoo9R0gf8T8wycN6BweSX3iAbrjmdi48iA1QA7vM=; b=v8tPuBm6a8N9wJvJ6WAtxxYn28Qs2iZZ+IRbRYjgYx4IpcRLyS8mfcmqz0ytzoCpos jv/ffuYFA83lpwHniP5fhlZ/kXp4M11tAuygaRg5myeIMrI0qD/rxAxB27MRhzupZe+M ztLh+JDQ8NvxiNwGo4nApbsJ7fy4V8q8kKKPaKdaoGsGu/zjSHMfybem2XwIWx7RPEKg 54NjDRDdLSpZw1taU2sXbgFmkRC/GEk0bCDtAIIXIb4BUwKjQYprsIXx9A6faIcBhh01 LX4ZbPwaUAG4xSFQoW/swck/IwVK0wLaGDiUB0fZN0idxlNoOdpYJqsxB8SjDJV4oO5t QY4g== 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=q3Hwoo9R0gf8T8wycN6BweSX3iAbrjmdi48iA1QA7vM=; b=EvUzGsqBDjUOHsSRkylF0HrQc5du0ap81fxqae7az5VFw/YKvsrrEkuGdWNtA9/y3A GPMMvcH4B3D8Cqw2mMoIDfCvI0L39S7Y33FvfdeOBV5lTKQOIKL696ck9F6E3hSK+hZ5 AKzyO6D7lUyJ52e3FdrCo1BH8Ip8khzv53pqrjYbb0DHgzGLWRkhyRzPnSswKlAmHSQq Lf8VApbOSJRrVzMSwrVbvCOuD3PzpcVWz9Y9eBYo1EWULhU0a3lnDC6r8Rn6hyV3WMeW dTncT7Xpw0ThUHhcxbs/hyM/r2gl3ikA0w+tUcNBR0DNmznSIcnF9dKCI8PQec640AYm +DtA== X-Gm-Message-State: APjAAAUUT+Xv1Kfh2otK91k4Om6ZALrdwSd7aX7ITjj0fLdArbAdi+oB RwXUS3Sdwo1XyUgk+dnPmS5+eA== X-Google-Smtp-Source: APXvYqw8AMtygXdme66bHjkErIZoCNT+9NxIrlMt51jVywqWqjAheNw422/KO4VB26xRqouz4epcaA== X-Received: by 2002:a62:f20b:: with SMTP id m11mr52253396pfh.125.1564647645675; Thu, 01 Aug 2019 01:20:45 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id n98sm4013483pjc.26.2019.08.01.01.20.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:45 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 27/47] ARM: spectre-v1: mitigate user accesses Date: Thu, 1 Aug 2019 13:46:11 +0530 Message-Id: <86231c8cbaacc44285a235db704e1029ae8ec64a.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012046_287291_173A84DE X-CRM114-Status: GOOD ( 13.43 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit a3c0f84765bb429ba0fd23de1c57b5e1591c9389 upstream. Spectre variant 1 attacks are about this sequence of pseudo-code: index = load(user-manipulated pointer); access(base + index * stride); In order for the cache side-channel to work, the access() must me made to memory which userspace can detect whether cache lines have been loaded. On 32-bit ARM, this must be either user accessible memory, or a kernel mapping of that same user accessible memory. The problem occurs when the load() speculatively loads privileged data, and the subsequent access() is made to user accessible memory. Any load() which makes use of a user-maniplated pointer is a potential problem if the data it has loaded is used in a subsequent access. This also applies for the access() if the data loaded by that access is used by a subsequent access. Harden the get_user() accessors against Spectre attacks by forcing out of bounds addresses to a NULL pointer. This prevents get_user() being used as the load() step above. As a side effect, put_user() will also be affected even though it isn't implicated. Also harden copy_from_user() by redoing the bounds check within the arm_copy_from_user() code, and NULLing the pointer if out of bounds. Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long Signed-off-by: Viresh Kumar --- arch/arm/include/asm/assembler.h | 4 ++++ arch/arm/lib/copy_from_user.S | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 307901f88a1e..483481c6937e 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -454,6 +454,10 @@ THUMB( orr \reg , \reg , #PSR_T_BIT ) adds \tmp, \addr, #\size - 1 sbcccs \tmp, \tmp, \limit bcs \bad +#ifdef CONFIG_CPU_SPECTRE + movcs \addr, #0 + csdb +#endif #endif .endm diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S index 1512bebfbf1b..d36329cefedc 100644 --- a/arch/arm/lib/copy_from_user.S +++ b/arch/arm/lib/copy_from_user.S @@ -90,6 +90,15 @@ .text ENTRY(arm_copy_from_user) +#ifdef CONFIG_CPU_SPECTRE + get_thread_info r3 + ldr r3, [r3, #TI_ADDR_LIMIT] + adds ip, r1, r2 @ ip=addr+size + sub r3, r3, #1 @ addr_limit - 1 + cmpcc ip, r3 @ if (addr+size > addr_limit - 1) + movcs r1, #0 @ addr = NULL + csdb +#endif #include "copy_template.S" From patchwork Thu Aug 1 08:16:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070307 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 176121395 for ; Thu, 1 Aug 2019 08:25:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 084F628481 for ; Thu, 1 Aug 2019 08:25:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F020928485; Thu, 1 Aug 2019 08:25:14 +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 7DFE42847E for ; Thu, 1 Aug 2019 08:25:14 +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=3Lt8ko4SWwSUErhIUvts/ntS56hHrOSWXG5r4MDGjS8=; b=ONN8kN0s/WifRz V66oK2vHIRNhM9v/c24vSeUKPvo95JpKQi74aCMiFnboi9EKsdiBKgr/RmYuLsTJ9Oh9UROyVjRLI q6Yfx+Sa2yszGxo2YK6DnQo7b0O/81l9KvKOJ/NFx1TAZwTV4dt+UXMlYxyXo/zQFBvI8aSmHZFif eex8Et6AJx/X8w4O00550SshckpD0YjoRvtJqlZDL9ITZRLJU8PNDF9iPBrUip/Ke3x6VLT4e4NAW Pt5gAjoAgFY/xPjn7r4FdDhCltsAGISgeXZlLdqns1RRg+zxTKHgy3Db1EPBOp7iHDN5voUGk4pbD 3XzTS/fTTiDyCBVuJqsQ==; 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 1ht6Of-0001Gf-5f; Thu, 01 Aug 2019 08:25:13 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KP-0002mQ-0v for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:50 +0000 Received: by mail-pl1-x644.google.com with SMTP id t14so31834681plr.11 for ; Thu, 01 Aug 2019 01:20:48 -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=MgdKvQC/PG/qzasZyBmDzAkccfxFwFqJHdwmPruVads=; b=M/W0Na2Zy7+HBEvHxxb6P/FPKdVkMATRN4C9Zb77vqKqQhL6z7bpMb1EeSx6PCKSXP WIpm09ydesGuVwKMj+W1yik9OCyQfN6plQEwk4acdSnuulENxPHSU0NaxsqQRRX0OI7Q CJ0tqIjPLDjnBIOWX5BruNZGIu9Qcme1K2e3M+sHqvXxw5u8OHzx11C0FhOuZ3LDh7OG Chz2+U3DN9zgQWBVGzmzxpJA5H8T8XIB//yeb10FYl9FV1Dimc13X4LokQdTvFyqY6vp ivz+ZoapG/08jHgX0zsH7JhOVAEay8pOIsb6pQiJUTzbVriQoqreFrBxWT58hO5m/UO3 cJbg== 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=MgdKvQC/PG/qzasZyBmDzAkccfxFwFqJHdwmPruVads=; b=V9wVc32eJv4hY5813mky7/p1WCuKydrJTWxYAlKuFN5LN9Qwsa+DAtAqxJ3x62zmiv 6QfTrFxEztJAGQn3xm5+4F/Xi6Y0WTD8+Otg6wlyDG0loqExNeNb56t/VJzOQHzBd0iw /Z2uQWxw5c6HP5YV/5kZFRdvLUJOFPFEeCXFIjPQDbGqYFnq8hoHQCGeWsQvtth2SqJB ykyPJFrBFGitbZDSK+P4GxJOAa0RY8VPNyENILe66Oty8gAS3CV0g3nVA+wNU3+pafpC p3HaUGdH/JhjrBtshp126qI2v9+c5LUT71Mlm4gwKyYsRwdFh+jkmjYI913OwdyZKZ81 uM5Q== X-Gm-Message-State: APjAAAV7PRudXoB22TZlib2GMMjubHuaBci8JnL52AA0ZyOxC1Wtf6cZ O9IQbwQNyGjIBweFZggg2DB/3w== X-Google-Smtp-Source: APXvYqwtnX5haa3mjsJZEuPJitXn8/aU61HgK/ZxG2IVG2xywq2bD6FMIeoJyjny8aFcR2dHWhALVw== X-Received: by 2002:a17:902:f095:: with SMTP id go21mr126863136plb.58.1564647648095; Thu, 01 Aug 2019 01:20:48 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id z12sm52519280pfn.29.2019.08.01.01.20.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:47 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 28/47] ARM: 8789/1: signal: copy registers using __copy_to_user() Date: Thu, 1 Aug 2019 13:46:12 +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-20190801_012049_077024_98ED3FDC X-CRM114-Status: GOOD ( 11.38 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 5ca451cf6ed04443774bbb7ee45332dafa42e99f upstream. When saving the ARM integer registers, use __copy_to_user() to copy them into user signal frame, rather than __put_user_error(). This has the benefit of disabling/enabling PAN once for the whole copy intead of once per write. Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/kernel/signal.c | 49 ++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 76f85c38f2b8..98685e2523bf 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -255,30 +255,35 @@ static int setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set) { struct aux_sigframe __user *aux; + struct sigcontext context; int err = 0; - __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err); - __put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err); - __put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err); - __put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err); - __put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err); - __put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err); - __put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err); - __put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err); - __put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err); - __put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err); - __put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err); - __put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err); - __put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err); - __put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err); - __put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err); - __put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err); - __put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err); - - __put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err); - __put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err); - __put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err); - __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err); + context = (struct sigcontext) { + .arm_r0 = regs->ARM_r0, + .arm_r1 = regs->ARM_r1, + .arm_r2 = regs->ARM_r2, + .arm_r3 = regs->ARM_r3, + .arm_r4 = regs->ARM_r4, + .arm_r5 = regs->ARM_r5, + .arm_r6 = regs->ARM_r6, + .arm_r7 = regs->ARM_r7, + .arm_r8 = regs->ARM_r8, + .arm_r9 = regs->ARM_r9, + .arm_r10 = regs->ARM_r10, + .arm_fp = regs->ARM_fp, + .arm_ip = regs->ARM_ip, + .arm_sp = regs->ARM_sp, + .arm_lr = regs->ARM_lr, + .arm_pc = regs->ARM_pc, + .arm_cpsr = regs->ARM_cpsr, + + .trap_no = current->thread.trap_no, + .error_code = current->thread.error_code, + .fault_address = current->thread.address, + .oldmask = set->sig[0], + }; + + err |= __copy_to_user(&sf->uc.uc_mcontext, &context, sizeof(context)); err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); From patchwork Thu Aug 1 08:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070309 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 4DF371395 for ; Thu, 1 Aug 2019 08:25:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F46F2624C for ; Thu, 1 Aug 2019 08:25:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32D132839C; Thu, 1 Aug 2019 08:25:24 +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 B56892624C for ; Thu, 1 Aug 2019 08:25:23 +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=qJTAE0KtS0m1+4MIlUNE9TJ3EG1ESAzOCDd9DhFAtmA=; b=XpOP49GtX0lwxI uYYTyK9VFS5c0Ml3w/88pUyS5U49Ac0hmIgWhL4JCXfeEV7b/OHB3wkeqThYfvgM2TYHRWzuQjb3t 49qxH2SXBiU9BN4z+XpxWFTpMVMI+ryjxngMUGAP+uBO0qrEZ6Oz5PjlFS6hXK8VyDWuJjHFdZ8h0 /InSrllL8a5aRE20ZkTc8avQShBn77ut3NaCPsklCuMvZ+KEJnsimHj2vbXTfLpXupMDCI5y8Heo/ 7wpS7TIVrKUtkG6tDqJR+8G6M0AL8CEWPetco5yo/0CA4RcrE5B9I+ayFFRmM6Q/c7Vy6B+ClBUnQ ltQeXvhaeuLp2dU2yACg==; 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 1ht6Op-0001WV-7a; Thu, 01 Aug 2019 08:25:23 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KR-0002pw-GG for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:53 +0000 Received: by mail-pl1-x644.google.com with SMTP id c14so31784375plo.0 for ; Thu, 01 Aug 2019 01:20:51 -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=Z+TjXjo63OoUiebA/nVcgaugef8flgCeXLGArxWolNY=; b=oDNzbpMHyWtAAuk+AA4TcYZ78EFl6JZ8Iti4SxiMfcc1O4tW8ZWErsVrUli0VkjSyU gbbCeDO8IUVJM3KzRMXnLfyV7K2WXU1VefHyR3ecG0nA8y1nsg5+Xlfc887ahn4H1Byc +BYB9inFuFPtPDhosjBWG/yyDYD7VORs/yyAR1dxfLR5dSqdQV+dVYdJ0RBCK5mu2SfH C42c5TNvpduhj/hH8fJJ+xzNepluUbsqr9+i8yJnK9GprLx/a+6C7HfY8bw+f3JOZCIF TKwAxaImzi2zOZxFBvoubmrXlKftUrKsjOu8Av2BGbQj8UjqcAB4Cp9gLyWlUgzaFssA 5V1w== 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=Z+TjXjo63OoUiebA/nVcgaugef8flgCeXLGArxWolNY=; b=cmhJ9Hk+h17msixkDt8VkicaQWRbKcHSZrzpBpAuSJ0K+LzE5ckIGTwMh8KXTbDYdy d+8TeH2battR7Js51S76N54rniGwSWH9WhCPY46rckq03TmsTYCmMTh7W22eEODXK3un ZnDEzXhAOP44D8NPkyzBGNaghL9zF0SeLYxOD1Z7MNo1RbsLARjq5y2SYk5xBSMjZO3e YKsACylWkEF5cQ4eikM0Z764TDmSizXC0Xu0GFscC8hkIiHS89z1MEHN7WaorChQKMTh iH/VCkjoMLikO4W8ItdOd1r4AFRUGiDAlmJcFriMu7kSUlF6d/IQcZFYCLWWtGT/hnqx ZU8A== X-Gm-Message-State: APjAAAWoMOnF4dt/4uwkisscgiuuRoQv5WxE4DK7ByGIzgujdb+t7+bb QtehwfarEY+vkp9UeufYqt8Zqg== X-Google-Smtp-Source: APXvYqwq0rBdTlx8rRlkb567BcZlJ5ZxpRAejULO4h/mIBdO4VwR7jouOb86/HafLUYLWLXS4CJF8A== X-Received: by 2002:a17:902:d917:: with SMTP id c23mr124580913plz.248.1564647650566; Thu, 01 Aug 2019 01:20:50 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id g8sm77853763pgk.1.2019.08.01.01.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:50 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 29/47] ARM: 8791/1: vfp: use __copy_to_user() when saving VFP state Date: Thu, 1 Aug 2019 13:46:13 +0530 Message-Id: <34c32a770df4c8d2630390fdfe3e4ec6047f721c.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012051_585559_6CD7787D X-CRM114-Status: GOOD ( 15.15 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 3aa2df6ec2ca6bc143a65351cca4266d03a8bc41 upstream. Use __copy_to_user() rather than __put_user_error() for individual members when saving VFP state. This has the benefit of disabling/enabling PAN once per copied struct intead of once per write. Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/thread_info.h | 4 ++-- arch/arm/kernel/signal.c | 13 +++++++------ arch/arm/vfp/vfpmodule.c | 20 ++++++++------------ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index 57d2ad9c75ca..df8420672c7e 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -124,8 +124,8 @@ extern void vfp_flush_hwstate(struct thread_info *); struct user_vfp; struct user_vfp_exc; -extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *, - struct user_vfp_exc __user *); +extern int vfp_preserve_user_clear_hwstate(struct user_vfp *, + struct user_vfp_exc *); extern int vfp_restore_user_hwstate(struct user_vfp *, struct user_vfp_exc *); #endif diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 98685e2523bf..6f0bd90f6d93 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -94,17 +94,18 @@ static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame) static int preserve_vfp_context(struct vfp_sigframe __user *frame) { - const unsigned long magic = VFP_MAGIC; - const unsigned long size = VFP_STORAGE_SIZE; + struct vfp_sigframe kframe; int err = 0; - __put_user_error(magic, &frame->magic, err); - __put_user_error(size, &frame->size, err); + memset(&kframe, 0, sizeof(kframe)); + kframe.magic = VFP_MAGIC; + kframe.size = VFP_STORAGE_SIZE; + err = vfp_preserve_user_clear_hwstate(&kframe.ufp, &kframe.ufp_exc); if (err) - return -EFAULT; + return err; - return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc); + return __copy_to_user(frame, &kframe, sizeof(kframe)); } static int restore_vfp_context(struct vfp_sigframe __user *auxp) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 7aa6366b2a8d..f07567eedd82 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -558,12 +558,11 @@ void vfp_flush_hwstate(struct thread_info *thread) * Save the current VFP state into the provided structures and prepare * for entry into a new function (signal handler). */ -int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp, - struct user_vfp_exc __user *ufp_exc) +int vfp_preserve_user_clear_hwstate(struct user_vfp *ufp, + struct user_vfp_exc *ufp_exc) { struct thread_info *thread = current_thread_info(); struct vfp_hard_struct *hwstate = &thread->vfpstate.hard; - int err = 0; /* Ensure that the saved hwstate is up-to-date. */ vfp_sync_hwstate(thread); @@ -572,22 +571,19 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp, * Copy the floating point registers. There can be unused * registers see asm/hwcap.h for details. */ - err |= __copy_to_user(&ufp->fpregs, &hwstate->fpregs, - sizeof(hwstate->fpregs)); + memcpy(&ufp->fpregs, &hwstate->fpregs, sizeof(hwstate->fpregs)); + /* * Copy the status and control register. */ - __put_user_error(hwstate->fpscr, &ufp->fpscr, err); + ufp->fpscr = hwstate->fpscr; /* * Copy the exception registers. */ - __put_user_error(hwstate->fpexc, &ufp_exc->fpexc, err); - __put_user_error(hwstate->fpinst, &ufp_exc->fpinst, err); - __put_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err); - - if (err) - return -EFAULT; + ufp_exc->fpexc = hwstate->fpexc; + ufp_exc->fpinst = hwstate->fpinst; + ufp_exc->fpinst2 = ufp_exc->fpinst2; /* Ensure that VFP is disabled. */ vfp_flush_hwstate(thread); From patchwork Thu Aug 1 08:16:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070311 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 AF9C51395 for ; Thu, 1 Aug 2019 08:25:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF012623D for ; Thu, 1 Aug 2019 08:25:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9110126D08; Thu, 1 Aug 2019 08:25:38 +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 2C508262AE for ; Thu, 1 Aug 2019 08:25:38 +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=maqIrOrzBhoLpo+JdH6pRvSTUSnuPHvn5eYJbs/nNEo=; b=WWcs96TmtJmdEA 9Q5UMDk37B2rtQ+cwIDmiRgqyG3dVB6YwfqlelMAnKwJxArnwric2RXVV0tkLCw/9NvzZAgRtgdWd mDfe3KIMJTxU0hbEzEVPV9HE80IOO1mzQt77Ophu9od4/lr2xc2J3JvIdMrBLxSi3CEeiukSH2yxa OzUS+/Ynxz8xcFDHyxJ1t7EncXwasBEvZBdA/K2IHd8StXrd9uNDrlOjOK5nSpTwTxtA70QsU1ign bqn079fRlLQwJKD0+EPdDsldzGrtHidUbs9/ff/dkLiNMFsR2SuLUV+JwNSVBEt5BuU0J+MT+FM1a c0YYb9IpdfFeUvFi+G8g==; 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 1ht6P3-0001mS-Ha; Thu, 01 Aug 2019 08:25:37 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KT-0002sK-KU for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:55 +0000 Received: by mail-pf1-x444.google.com with SMTP id q10so33593011pff.9 for ; Thu, 01 Aug 2019 01:20:53 -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=PM+p9F/paBphnvI0O8YGjV0kMD9bw/jop01RC1tBzqU=; b=o0bXhyKqYt8kp2xyqrJN+d5+L6zWOZoysvGTEc4rppHnRpkoPu+T4rnS3m4Jm+aRvI sQXJ7oKpn5ETzHEMDgshVmw84/LTRr+AG+d5lPhYx3vl/8kjEcoUyTb+f9Z/tE7ck1xs 7gTkMJKkIt5Gx64KSQCHK+McwRAZN35KWlv8Vp1mb2L75q5NBI1Dan3JB+63h+6B54iV 4ZSBYc8+5DRo4yXMnBg4TH9/kpVbi9ZyAJwa3DEeIQ25dhha1DKlODyU2IetZUpvOG+n DfzIRtDFj4vaEK47flZLyQXsqnbGm9K47CBqs2fPmZj8wswO1/GL3Dn4eFaSjhCw6PAR y49Q== 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=PM+p9F/paBphnvI0O8YGjV0kMD9bw/jop01RC1tBzqU=; b=m1TopebXncqxyjKxQw1vl8dA6AaV547P01I19G5QuYKYfVotxbbmY62KHvuXwcwxAU Uf1r3lJj0ruaUg8qMrJ6w1utb6gvsZ5jv4vtfKvytmnIjOhfEEald7GO2gEoTr1Gkold n/diGr56hRrWaq7XfFNMvgpP+X6XylbPztg4bN54WfxbVb9ClXkLAyUiaFfRErtg8oqu A9H5WiKCk2qjW0MJ3pY5UAnqfbQ8JM3QRzMGriYXrSKB+QaKlHqfmUxQAeAT0txYY83I A/rploSx9T7D4SGa9bScKabXx3y0SgXkRqHlR+HGEKiyECD7THurYN1F+GsMjrsf+Urh 1z6Q== X-Gm-Message-State: APjAAAX9eFKNExo91C2OJ1FoT2I9n4EUkhmY/4dIDpE8UToCoE9/oB8N 35ebAUuOgxFrlF5FSHEIwnQFmw== X-Google-Smtp-Source: APXvYqz3GWx2N/m/nhcWkCouY4H1qYVElKKIkdNdyN42eDSqTyXd8YO3BZzcYLEcjj5aC3TXCQvy/A== X-Received: by 2002:a62:7552:: with SMTP id q79mr52190761pfc.71.1564647652996; Thu, 01 Aug 2019 01:20:52 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id o14sm4069908pjp.29.2019.08.01.01.20.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:52 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 30/47] ARM: 8792/1: oabi-compat: copy oabi events using __copy_to_user() Date: Thu, 1 Aug 2019 13:46:14 +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-20190801_012053_882950_0E2C0AEE X-CRM114-Status: GOOD ( 12.01 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 319508902600c2688e057750148487996396e9ca upstream. Copy events to user using __copy_to_user() rather than copy members of individually with __put_user_error(). This has the benefit of disabling/enabling PAN once per event intead of once per event member. Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/kernel/sys_oabi-compat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index 640748e27035..d844c5c9364b 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -276,6 +276,7 @@ asmlinkage long sys_oabi_epoll_wait(int epfd, int maxevents, int timeout) { struct epoll_event *kbuf; + struct oabi_epoll_event e; mm_segment_t fs; long ret, err, i; @@ -294,8 +295,11 @@ asmlinkage long sys_oabi_epoll_wait(int epfd, set_fs(fs); err = 0; for (i = 0; i < ret; i++) { - __put_user_error(kbuf[i].events, &events->events, err); - __put_user_error(kbuf[i].data, &events->data, err); + e.events = kbuf[i].events; + e.data = kbuf[i].data; + err = __copy_to_user(events, &e, sizeof(e)); + if (err) + break; events++; } kfree(kbuf); From patchwork Thu Aug 1 08:16:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070313 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 5784313AC for ; Thu, 1 Aug 2019 08:25:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48C962624C for ; Thu, 1 Aug 2019 08:25:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CEA126D08; Thu, 1 Aug 2019 08:25:51 +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 B6F7B2624C for ; Thu, 1 Aug 2019 08:25:50 +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=XvduuFibURvXSSVz5CXmEiI7sSqas1PjCRMjRIM+K/0=; b=Gy6XGGwQwKrKwA fr1SupGmqX4DX1CRPeskSR8RK9uNjXZ/s8SE0efY6com8MdwxwtMw8viTFbxz6hbF2fS+XNDba6aK nzyRoVtBUBnRFw8EF+l4FPj5gpmrXwStm60l9yKXMFYoLFRhxKz5Q19uxEPYdZ/z7STDXo1UkbtsP pqeY512jDxVUk8VQyFyyJxq7QAHnroUsDRGXVuDf/KBcFx2H+9tEP0fxAlKdhxCXEJi2xGhay/o4I dXOWhcLKPrWkzf/Q/k71zVYRkQDfGMvxYeU2sfajNl8gkrnvqBWprAEL6Qb0QWMjxolyPKNu9lLfa QBT3ZpCH7xbdIydDYsdg==; 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 1ht6PF-0001yr-A7; Thu, 01 Aug 2019 08:25:49 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KW-0002vh-6f for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:20:57 +0000 Received: by mail-pg1-x544.google.com with SMTP id w10so33739811pgj.7 for ; Thu, 01 Aug 2019 01:20:56 -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=+tEIHvT2/jri72b3g9sp066ia6oUWHcxPpBllqXMUPw=; b=zstarAAhY7wWmMaGY6D6L8D4JUjQWl1LpQDoGnw+W3hdCIJFeJzHRMBiPHafBsJN9l eZzvWMX/PZj6qV0aTkXMvuu43Wh3x673EnQCOEqPk197LcpNJFabikbGb65LoN4kOhsx WP8ba6yc2hAueRfZnHaWcCbYiVJiL13J4NUyBdoWUvmrtKDhtXrlXNWbiiOfVNIyZM1y /vNp/Yte3Jw4v6bpd1KDd53erL5yT9SmyfuxiqQAeLn/V5g/OTR1qSREfhWIZH/aBV/k qU8xqXAtcEchEEN/j5oB4C/dILnMiiNADOiXy9RhZkxWQGvOMs8ISwdONHMl0lypJqzS V+Sg== 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=+tEIHvT2/jri72b3g9sp066ia6oUWHcxPpBllqXMUPw=; b=VZafZr8n0iNxFon1WzqRnHeXVKXLMg/cU3t8a0l9NuBSOcnY4V8A8QSGLq9N1nWP/Y eH/wZ10U7y5YSuhzD7NT+o547viXkzeP9eoNP35n0TjD9TAMOE4GMwsb7kLr6dI9U9ZF SwHePFXs5/dmFw2UH4rGAL6wHiiSHyzcnxaM1C9pC2zqF8pjnhdNjQrRT5VrFGbdBEc9 feQMcQe4KxfrEqQhFdwrNhihDbmDz/DBdouGdswNTbVG0iNEqPtf5dvy88tUJYamT57w zCBK0oi/kxoW7euvpLIB3QMNNL6V3rKhk7aYqrMazCDqNarK71B2kDihdl0Vzir+hde+ sDuQ== X-Gm-Message-State: APjAAAW1sSj6oAcYDAG7yKVxXBJsG66I/5T/nuVmONw544rG0kv1iSju nn7Qbu5HRLzIQHTvKIDE/pqpyg== X-Google-Smtp-Source: APXvYqxf8BTnCquHpLYCvNUaNkn8x4u4LXcuJcRGMZOEAmDPdYlWD3TQ4h+IWrvNS6AN8KeE4afqWw== X-Received: by 2002:a17:90a:8c06:: with SMTP id a6mr7401352pjo.45.1564647655514; Thu, 01 Aug 2019 01:20:55 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id 5sm2004064pgh.93.2019.08.01.01.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:55 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 31/47] ARM: 8793/1: signal: replace __put_user_error with __put_user Date: Thu, 1 Aug 2019 13:46:15 +0530 Message-Id: <8aaea1bd07c7c54db7efc732ac3a041c32d3bb4a.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012056_371808_89134DDD X-CRM114-Status: GOOD ( 10.78 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 18ea66bd6e7a95bdc598223d72757190916af28b upstream. With Spectre-v1.1 mitigations, __put_user_error is pointless. In an attempt to remove it, replace its references in frame setups with __put_user. Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/kernel/signal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 6f0bd90f6d93..4a4ab72d27ba 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -301,7 +301,7 @@ setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set) if (err == 0) err |= preserve_vfp_context(&aux->vfp); #endif - __put_user_error(0, &aux->end_magic, err); + err |= __put_user(0, &aux->end_magic); return err; } @@ -433,7 +433,7 @@ setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) /* * Set uc.uc_flags to a value which sc.trap_no would never have. */ - __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err); + err = __put_user(0x5ac3c35a, &frame->uc.uc_flags); err |= setup_sigframe(frame, regs, set); if (err == 0) @@ -453,8 +453,8 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) err |= copy_siginfo_to_user(&frame->info, &ksig->info); - __put_user_error(0, &frame->sig.uc.uc_flags, err); - __put_user_error(NULL, &frame->sig.uc.uc_link, err); + err |= __put_user(0, &frame->sig.uc.uc_flags); + err |= __put_user(NULL, &frame->sig.uc.uc_link); err |= __save_altstack(&frame->sig.uc.uc_stack, regs->ARM_sp); err |= setup_sigframe(&frame->sig, regs, set); From patchwork Thu Aug 1 08:16:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070315 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 F26091395 for ; Thu, 1 Aug 2019 08:25:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E387127F3E for ; Thu, 1 Aug 2019 08:25:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D512827CF3; Thu, 1 Aug 2019 08:25:59 +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 7DA832624C for ; Thu, 1 Aug 2019 08:25:59 +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=bi4ewPtLKTBcimYIKpRdEUQKGor8SYwZxaAAcPy9vcM=; b=kElg/6lRJwmBwL 4AbjT/z9Qbujxk/WRyJiz1f1GWXZkvID15epD5fR/DncDjK/NowgJsk1LwaVkursEzVVQfxE1LG58 caoPyKcSB0Gc+nz56uijEUAsn0wuc8XlAu2esm3+YZj7lR15Xd/0Ee6Wk6TMfr8+A2iliRDZXbSyP oaLjj7NuF4mhRe0oZY1VFfkA/hgK5tybR7rMxPD2gtIwsCIxhQXY0oCwt4ne+yKWIGQ1dmGU7jjLF FMttt58KSiduNYQsBK93hkb0HjPTIx6IG8caABomG3+fFxM91zO4okoFepo/2UsXMSDAomKw7RWjF IDwuBAu1xxWF6KWAUSGw==; 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 1ht6PP-0002Ab-3B; Thu, 01 Aug 2019 08:25:59 +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 1ht6KZ-0002zu-Dl for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:00 +0000 Received: by mail-pg1-x541.google.com with SMTP id n9so27509866pgc.1 for ; Thu, 01 Aug 2019 01:20:58 -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=83Q5DLuQYSva53SfstGNLwQ+WusgochK7tEX54DLnZk=; b=rI4dN04PCrS8oEfhhu1FimQvBZ8VBzO1CvaxoGD0C6HzZI6J1xXoWDHX2NESLp/Gu7 7/G8HfBb07K3/rgxPknRTOvB3aLF023teB3bfyIRyAR+J8H4K9LaMWtxu70jFDgK74EX d5yKiB/4rRbxtd1QdEtqb0PY9C3bjQM4DYhFHaErCxKRZDpe+KlfB4THeuDtUHgMKne0 tAcVx3VWyyaYMIEQmAFWy51kwzUYHaZxrC4iPgcfUez/yyp4OS9lBBifrZ0sEM4m2uBe HN9oapm4F9z9UV++zkll/G0/DnOcFJFTYG1xzjUUiBgS5qLQw/8M46c9Qq8EW4MJ4sTk pdDg== 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=83Q5DLuQYSva53SfstGNLwQ+WusgochK7tEX54DLnZk=; b=drUiJ5h2JQSIlhc0/k89kS+KQcDgYalVGUglGDjBouD4UJr8VzeBIBjPKwKQcx1Vub NBM1xxc8szQS8DGxfOaV1W8JbTJ+rjnvozGbPnguRYh8DjspNnWoq99lKkjOhuk1iMCo uE1JXNUIvWk9yEQP+h8D86liCm+jVBIlOCZVuzO9s+AgcAOXwWiDgZmtcGAfwCPsdSyl HzMCzkZTn4iesbDiV1K+Q5cuAWivYjnOpOAuAlkeIzGb8rCJEmTJIjn16UBTkVyeuVDx 5Gvu/osrGcjNmonQfAKbiXbHQsADJbmyXzaeEa5htD6nr2HN6xp5oEwssfQDZEV9K197 XoXQ== X-Gm-Message-State: APjAAAVEtYPIBcGbz9kflYvLPxufawQol4NyHZUWvUAjBWtOHe97H9P7 eWSI0NEcX47EEMnNADUz7D47pg== X-Google-Smtp-Source: APXvYqzngxuyD04VCRkFZTzoAlqHmHgivTldcuqpxXRziSfFGEKiXB/CnfRGlITASbXm+JzerEuOIA== X-Received: by 2002:a62:14c4:: with SMTP id 187mr50562879pfu.241.1564647658137; Thu, 01 Aug 2019 01:20:58 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id j1sm95276210pgl.12.2019.08.01.01.20.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:57 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 32/47] ARM: 8794/1: uaccess: Prevent speculative use of the current addr_limit Date: Thu, 1 Aug 2019 13:46:16 +0530 Message-Id: <74663c62c712201d35d012eba43ad611b6c5a3fe.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012059_483825_2659E109 X-CRM114-Status: GOOD ( 11.85 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 621afc677465db231662ed126ae1f355bf8eac47 upstream. A mispredicted conditional call to set_fs could result in the wrong addr_limit being forwarded under speculation to a subsequent access_ok check, potentially forming part of a spectre-v1 attack using uaccess routines. This patch prevents this forwarding from taking place, but putting heavy barriers in set_fs after writing the addr_limit. Porting commit c2f0ad4fc089cff8 ("arm64: uaccess: Prevent speculative use of the current addr_limit"). Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/uaccess.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index ecd159b45f12..a782201a2629 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -99,6 +99,14 @@ extern int __put_user_bad(void); static inline void set_fs(mm_segment_t fs) { current_thread_info()->addr_limit = fs; + + /* + * Prevent a mispredicted conditional call to set_fs from forwarding + * the wrong address limit to access_ok under speculation. + */ + dsb(nsh); + isb(); + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER); } From patchwork Thu Aug 1 08:16:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070317 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 1AF0613AC for ; Thu, 1 Aug 2019 08:26:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B0AA2839C for ; Thu, 1 Aug 2019 08:26:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1A96283C3; Thu, 1 Aug 2019 08:26:16 +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 6640B2839C for ; Thu, 1 Aug 2019 08:26:16 +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=rq8lEdHD5hULtpf+3j1GZIOuXou69c/+TBsCDtWTVQ4=; b=trVpPNVxXAc459 z6q9iWHwZvDRcsTEXauyzMzDNcMiqByvY9WNgY4kB9v4LRuIdWXiPA2opb/EcsuIRX/WuqotzksK4 56U8IfVs83PxlJ9nHpZo+/ZtPiOqUbWA/RtPWeOs6F+lA4Q2Z5z6AEZzIfAk3RA9b1EhZO4VZrLlA baXAEz1sz6vXyOvS1Zly5gIUrYRFNppUM0SB94mCPoZ0sh1rteb8wDzMNdUrH4KQve2JLDDAyRvnP xK71FURcRn+yvmpONx3FsRjYcFn2sraKKK8H0y/FRxLsUfLBtlqK5Wm28UYnwGunPGqi0wULwMTK7 vG9G64+EmlH8q8rhfIRA==; 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 1ht6Pf-0002US-7v; Thu, 01 Aug 2019 08:26:15 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Kb-00034U-HY for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:03 +0000 Received: by mail-pg1-x543.google.com with SMTP id o13so33717333pgp.12 for ; Thu, 01 Aug 2019 01:21:01 -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=wHzU+tsn1pgRkzbIeM8fvpGsFHg5ebHOWm4gu/3Evbs=; b=rSAt52egga0c/9SEqscpsTeaeRsAwWlmYF0iaTkpWJoaWK26cLxh1XXD3+NxAq/QWX e51h9rVl9tyo1SrN4FSuHn+LzRPvxPmAHV0U4kBLerPw9KrfQoopYk5P3tGth+es5E0Y YBWVssklLvqnj1o7gKAxxhzEdoSSG+BAZ8ZmLMUZ4DEguwsJ5rpIDTXGxDipk1+rl/XV c/4dWbmNolrf5BFUguxC80+PwGpxs65sg1LAZxJteThDQF1k36lH6Imic2YFyELTHcBm CFZ6AD07r38paUBn0ey5jIRShqphH8w0uSpcsCXs7KwRWjk742hItzwGw4+avKLlyJs4 +Fvw== 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=wHzU+tsn1pgRkzbIeM8fvpGsFHg5ebHOWm4gu/3Evbs=; b=IpUKkGat35UvycXu3qjUl7Q7rzu4sacZ5cEL3u8Oq0KFCTXwPzNmpxuUf8uxSyYYOa JB1nsZwW9Rzs4NK3WMNzm4TfxRTXLGyW0FIztcS55O+dMplyCfNVWPq9QqpCEa6E8HFB JCEgG6Zzh5ITCb+NS0x6CLueYcqZ2d/ouh7E92QfbZBBQ6lYXIMNIAcoHDlA+8/OJpdv OyeeQ4+F3rfst+nAf6axY/tEW0LEyRVC3QJMfRS/5KH0RiYKZeHcf+Zp8ZmBTH/es+Al gooyWhlsiMc/KXAmv+DbzdZA+6FU6qumBvl4lhT21zxhIUUqokAmysTlPKCzU/nv8JHk /ruA== X-Gm-Message-State: APjAAAVltb0Y6Qog4NnFNzxdgygcDx+O1aHyq3CyZ2dYY5PMf31JKD4+ 3AUyTD9w+cUpzn8YxfkHU57Zp9r6Vw0= X-Google-Smtp-Source: APXvYqwnwqiIvKejRHzstn3Je3SR7S3F9vIbsAZ8AdQb5YEbOGH5uf8ZF72xNnezn80fnlz56U48mg== X-Received: by 2002:a65:4489:: with SMTP id l9mr121289891pgq.207.1564647660710; Thu, 01 Aug 2019 01:21:00 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id 30sm6971178pjk.17.2019.08.01.01.20.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:00 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 33/47] ARM: uaccess: remove put_user() code duplication Date: Thu, 1 Aug 2019 13:46:17 +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-20190801_012101_704266_0D01DFC6 X-CRM114-Status: GOOD ( 13.77 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 9f73bd8bb445e0cbe4bcef6d4cfc788f1e184007 upstream. Remove the code duplication between put_user() and __put_user(). The code which selected the implementation based upon the pointer size, and declared the local variable to hold the value to be put are common to both implementations. Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/uaccess.h | 106 +++++++++++++++------------------ 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index a782201a2629..94b1bf53b820 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -253,49 +253,23 @@ extern int __put_user_2(void *, unsigned int); extern int __put_user_4(void *, unsigned int); extern int __put_user_8(void *, unsigned long long); -#define __put_user_x(__r2, __p, __e, __l, __s) \ - __asm__ __volatile__ ( \ - __asmeq("%0", "r0") __asmeq("%2", "r2") \ - __asmeq("%3", "r1") \ - "bl __put_user_" #__s \ - : "=&r" (__e) \ - : "0" (__p), "r" (__r2), "r" (__l) \ - : "ip", "lr", "cc") - -#define __put_user_check(x, p) \ +#define __put_user_check(__pu_val, __ptr, __err, __s) \ ({ \ unsigned long __limit = current_thread_info()->addr_limit - 1; \ - const typeof(*(p)) __user *__tmp_p = (p); \ - register typeof(*(p)) __r2 asm("r2") = (x); \ - register const typeof(*(p)) __user *__p asm("r0") = __tmp_p; \ + register typeof(__pu_val) __r2 asm("r2") = __pu_val; \ + register const void __user *__p asm("r0") = __ptr; \ register unsigned long __l asm("r1") = __limit; \ register int __e asm("r0"); \ - unsigned int __ua_flags = uaccess_save_and_enable(); \ - switch (sizeof(*(__p))) { \ - case 1: \ - __put_user_x(__r2, __p, __e, __l, 1); \ - break; \ - case 2: \ - __put_user_x(__r2, __p, __e, __l, 2); \ - break; \ - case 4: \ - __put_user_x(__r2, __p, __e, __l, 4); \ - break; \ - case 8: \ - __put_user_x(__r2, __p, __e, __l, 8); \ - break; \ - default: __e = __put_user_bad(); break; \ - } \ - uaccess_restore(__ua_flags); \ - __e; \ + __asm__ __volatile__ ( \ + __asmeq("%0", "r0") __asmeq("%2", "r2") \ + __asmeq("%3", "r1") \ + "bl __put_user_" #__s \ + : "=&r" (__e) \ + : "0" (__p), "r" (__r2), "r" (__l) \ + : "ip", "lr", "cc"); \ + __err = __e; \ }) -#define put_user(x, p) \ - ({ \ - might_fault(); \ - __put_user_check(x, p); \ - }) - #else /* CONFIG_MMU */ /* @@ -313,7 +287,7 @@ static inline void set_fs(mm_segment_t fs) } #define get_user(x, p) __get_user(x, p) -#define put_user(x, p) __put_user(x, p) +#define __put_user_check __put_user_nocheck #endif /* CONFIG_MMU */ @@ -408,36 +382,54 @@ do { \ __get_user_asm(x, addr, err, ldr) #endif + +#define __put_user_switch(x, ptr, __err, __fn) \ + do { \ + const __typeof__(*(ptr)) __user *__pu_ptr = (ptr); \ + __typeof__(*(ptr)) __pu_val = (x); \ + unsigned int __ua_flags; \ + might_fault(); \ + __ua_flags = uaccess_save_and_enable(); \ + switch (sizeof(*(ptr))) { \ + case 1: __fn(__pu_val, __pu_ptr, __err, 1); break; \ + case 2: __fn(__pu_val, __pu_ptr, __err, 2); break; \ + case 4: __fn(__pu_val, __pu_ptr, __err, 4); break; \ + case 8: __fn(__pu_val, __pu_ptr, __err, 8); break; \ + default: __err = __put_user_bad(); break; \ + } \ + uaccess_restore(__ua_flags); \ + } while (0) + +#define put_user(x, ptr) \ +({ \ + int __pu_err = 0; \ + __put_user_switch((x), (ptr), __pu_err, __put_user_check); \ + __pu_err; \ +}) + #define __put_user(x, ptr) \ ({ \ long __pu_err = 0; \ - __put_user_err((x), (ptr), __pu_err); \ + __put_user_switch((x), (ptr), __pu_err, __put_user_nocheck); \ __pu_err; \ }) #define __put_user_error(x, ptr, err) \ ({ \ - __put_user_err((x), (ptr), err); \ + __put_user_switch((x), (ptr), (err), __put_user_nocheck); \ (void) 0; \ }) -#define __put_user_err(x, ptr, err) \ -do { \ - unsigned long __pu_addr = (unsigned long)(ptr); \ - unsigned int __ua_flags; \ - __typeof__(*(ptr)) __pu_val = (x); \ - __chk_user_ptr(ptr); \ - might_fault(); \ - __ua_flags = uaccess_save_and_enable(); \ - switch (sizeof(*(ptr))) { \ - case 1: __put_user_asm_byte(__pu_val, __pu_addr, err); break; \ - case 2: __put_user_asm_half(__pu_val, __pu_addr, err); break; \ - case 4: __put_user_asm_word(__pu_val, __pu_addr, err); break; \ - case 8: __put_user_asm_dword(__pu_val, __pu_addr, err); break; \ - default: __put_user_bad(); \ - } \ - uaccess_restore(__ua_flags); \ -} while (0) +#define __put_user_nocheck(x, __pu_ptr, __err, __size) \ + do { \ + unsigned long __pu_addr = (unsigned long)__pu_ptr; \ + __put_user_nocheck_##__size(x, __pu_addr, __err); \ + } while (0) + +#define __put_user_nocheck_1 __put_user_asm_byte +#define __put_user_nocheck_2 __put_user_asm_half +#define __put_user_nocheck_4 __put_user_asm_word +#define __put_user_nocheck_8 __put_user_asm_dword #define __put_user_asm(x, __pu_addr, err, instr) \ __asm__ __volatile__( \ From patchwork Thu Aug 1 08:16:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070325 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 3902213AC for ; Thu, 1 Aug 2019 08:26:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D3332839C for ; Thu, 1 Aug 2019 08:26:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21C25283C3; Thu, 1 Aug 2019 08:26:37 +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 B3CA42839C for ; Thu, 1 Aug 2019 08:26:36 +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=RO+RtrXEnMGPyx5BtJIr9CLrSnzK8wqFPC3bSNybMi4=; b=E/jVbhzra0zzMA 63t+ZR/XIgL78ENURZBcR0HLM2hc6AGwfyMT+sUdL6x1cE+Oqhbvu4dRjMu9s0wgCMboIVy3nXJZN Q+7Ck46UkYEn/xPBh3bwth3rESccVORzIQNe8MHoF6b08UMwjT4b3syHSPj97ishjZEaAKI7o0DiM 7pCT/+hcpYBuPqvHz+eTKtuzN6EEEmfcYvC536TnsRyKZOGcQsWbRtB22lyurxlfKNEwO28rhfeaC AieQGgNNK0p8WCHUoqdLFydQatUjVPLnC5J/HyCgVRgX0IKNHmHfVVAhucsyeuUqPvPN5zPxStaml B0v5hPJe2Yvjg47x28FA==; 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 1ht6Q0-0002wU-1I; Thu, 01 Aug 2019 08:26:36 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Ke-00038T-3O for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:07 +0000 Received: by mail-pl1-x644.google.com with SMTP id m9so31740456pls.8 for ; Thu, 01 Aug 2019 01:21:04 -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=y5vIaM+vVchIZG6+Gh1WcpqO4yKh8TnPpANQdT1zWCg=; b=NpnvqtjK49HYBgbUiDGgi6xSJ03C6UtcvxRKF5TE0WHirWiIbnALLSZJY52O1CHNZK FenUuArNYNx5FObhoUmbuVHY9+TQhtb77eXZaTPvmLlDTDZeLOiYBkEwSAjK+oLv7sAo 9RDwz+ktZskTt9WhFVwRYsPJ4+JwH+AmkH6fTrFVQBH0oJfx9Wtx8PhUuFsqweiS5dqt 8x7HU+jAlADxbEjOdCPkC1PWXYO1E7Nee4cq2F4h1WH4JTuScbkwZbvCbxMXmRSomJwA heyhgkDjkxTvakUp5J31B8/EXj5YPr2HQVcwbMfT9pU3CxpqNiRy+OWbMVRomKzEExiO PIyA== 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=y5vIaM+vVchIZG6+Gh1WcpqO4yKh8TnPpANQdT1zWCg=; b=sCCvMR5Le2PdqqIbUAYCjt/WKa1fzLW3UWoYDk+pSXkiO9cLYyb6K0g3lqc7snfKYi YyZT7RKTpZWI/J6eplvsLTj8Za4+BWYeet3ln506v81nuS+dPwsUz5WQFbTuhQDRMCVk ECMuuYzjgKWQVZgP5fSsVFtJzW0U2mvb997af2RrIjz/UzQqAibl51FYT/ocmBCQdu0y pxCW6t7dw5M3Jy4Sy33rFs/IhmBtFVoAWnJa73nwxhBz0XEmqaTWGj9D924EkWqDduXS QKU3jDP+g55isozpqupNqvzzYPyA1g8Z49TqdbTXnWX2aVIDQEbXv1ZIis11yYIxUjaR iegQ== X-Gm-Message-State: APjAAAUUpyoycJljFPc1MjLPd931hoFIA31uednlfvg3dUNJZ61Kaf4P WTgfES9AEBwSXYsVV4voJVemYg== X-Google-Smtp-Source: APXvYqxHzo8Gha+mkvmGOss5j3RTk3imIHXq1nsnN4IBoKCBHaJe829TSCm3FiSqE9ZmAng+hLC2qw== X-Received: by 2002:a17:902:6b86:: with SMTP id p6mr127587221plk.14.1564647663394; Thu, 01 Aug 2019 01:21:03 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id z4sm111700635pfg.166.2019.08.01.01.21.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:02 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 34/47] ARM: 8795/1: spectre-v1.1: use put_user() for __put_user() Date: Thu, 1 Aug 2019 13:46:18 +0530 Message-Id: <89ae15bfdcc72b42ebacde01603f09fd5cd880b7.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012104_223168_B11C21FB X-CRM114-Status: GOOD ( 10.55 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit e3aa6243434fd9a82e84bb79ab1abd14f2d9a5a7 upstream. When Spectre mitigation is required, __put_user() needs to include check_uaccess. This is already the case for put_user(), so just make __put_user() an alias of put_user(). Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/uaccess.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index 94b1bf53b820..7f96a942d9a0 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -407,6 +407,14 @@ do { \ __pu_err; \ }) +#ifdef CONFIG_CPU_SPECTRE +/* + * When mitigating Spectre variant 1.1, all accessors need to include + * verification of the address space. + */ +#define __put_user(x, ptr) put_user(x, ptr) + +#else #define __put_user(x, ptr) \ ({ \ long __pu_err = 0; \ @@ -414,12 +422,6 @@ do { \ __pu_err; \ }) -#define __put_user_error(x, ptr, err) \ -({ \ - __put_user_switch((x), (ptr), (err), __put_user_nocheck); \ - (void) 0; \ -}) - #define __put_user_nocheck(x, __pu_ptr, __err, __size) \ do { \ unsigned long __pu_addr = (unsigned long)__pu_ptr; \ @@ -499,6 +501,7 @@ do { \ : "r" (x), "i" (-EFAULT) \ : "cc") +#endif /* !CONFIG_CPU_SPECTRE */ #ifdef CONFIG_MMU extern unsigned long __must_check From patchwork Thu Aug 1 08:16:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070331 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 1710513AC for ; Thu, 1 Aug 2019 08:26:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 091A22839C for ; Thu, 1 Aug 2019 08:26:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F01DE283C3; Thu, 1 Aug 2019 08:26:53 +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 6EB5F2839C for ; Thu, 1 Aug 2019 08:26:53 +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=sMIREO/3K9VQRXUcC5JUptMCtdp0U1531Bx5asBBiKQ=; b=oumFl8d2kOzn8d JsBWBeBe8gTNKHotfNubnsqeH3pYdaP107PB14Xy98KzZ2jqE7aIsliClQLIZj7NcCjh3wHe5o/4X KmttpxAESI4jkYB7NWCYD6Hmw8WHfnvsA0hrSjO5WIT8FT6NeQusLPzz7KLcwF3rDSPqSFxGWd4au pF79WBi8N8qy1p09ABS02aqp/5r6fNFonE+MuJpz6CyVSRXqSAboNRqvK5sDx2VhdHPG1iSi/yCC6 8CzVOIE6dtapUjDjMGRLnTDIjQPFxS2BGW7cVaPXw6Gn5XQEM8aK1bmFxClfrLbxXLxH3pmaIU5Uf lm1Fh+jbFoRDwA2IBGIw==; 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 1ht6QG-0003O7-TS; Thu, 01 Aug 2019 08:26:52 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Kh-0003Bv-1L for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:10 +0000 Received: by mail-pf1-x441.google.com with SMTP id i189so33609131pfg.10 for ; Thu, 01 Aug 2019 01:21:06 -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=QT52cSxWVIebfDc1oGBa7p8CuPEmaq03dkPYlQrFIZw=; b=pilV4a1PZ7oAn8kiAPyEMpIAXatrnWAY7F56eSYPB9vrKy4dh5U8N9TvLKEbGs/trC gCp08Y6foQq6IHiA6lZOSHoJ6GRRFGq9rri/60LMEZnonPys5z/6SoXnZNJl65mFs7ci JJmSUxzGYnlU1VdgyralvPmw6VwExqh6And5XbOEm19Y4zpQ8SRF02sImAKc6nW5yDiZ GxV3IOIraRaflGL69TuNQCaZhm8vxrZbqpITFaNwdJKixpvFTRCpAsy9bhn2OggnWT/L 3IaRBmLuHoo60PO01b2vc6dsTtslHml6G7AGm53sc8Nrlagct8eYTSp2XXwebHHH3mvI 26dQ== 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=QT52cSxWVIebfDc1oGBa7p8CuPEmaq03dkPYlQrFIZw=; b=Rnr4EHUVYythykTAOPcpI0aCJ0pY4BRK6eUbiN2WCJ2irAQirfsFQ4wUMU4zNKjrBK nTgBpfDLL4nK8MacvZsreop1ph7eqgCbjzC1BC+fBRjUf8vwNmF9t65Cq1Qm4bGYOPL7 2d43J+cpNlMj5qw3sipgblpeqTHFMh960naH+i+EFI+2OCIKiEAl8aaSMQo+TZFWcInY msVGJhOcV50N4yH9rQVSDeYeqfNsqSaNOyhG8DlVRyzpk+tUcvgGN4j7dZpfVWavkM4F gEncRNY5fwqSQPKWtsRoeTZh7OPoqhLD09+K/bB2hOipfhg65pmI3UW20aHdxiBndf/1 wcBQ== X-Gm-Message-State: APjAAAV2SmGZ7anaGksihPhstvsRWfDnFGdTQoQhbMfEa08Gj4RB3IEi Mp5alQhJOuXh2JgtaqMccQGg9XJxwf4= X-Google-Smtp-Source: APXvYqxw/r6K9JzFk05Y40bsfHjiFIbz6DEqzJ1Bn+TrAgnfGxSab1T57zF2H7EyzRKqi+mVFuyHHw== X-Received: by 2002:a63:a35e:: with SMTP id v30mr57674126pgn.129.1564647665858; Thu, 01 Aug 2019 01:21:05 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id p1sm76262663pff.74.2019.08.01.01.21.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:05 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 35/47] ARM: 8796/1: spectre-v1, v1.1: provide helpers for address sanitization Date: Thu, 1 Aug 2019 13:46:19 +0530 Message-Id: <56d194e7c07733a1cb99457e07067b6db64560ef.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012107_121224_5909E3C7 X-CRM114-Status: GOOD ( 14.11 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit afaf6838f4bc896a711180b702b388b8cfa638fc upstream. Introduce C and asm helpers to sanitize user address, taking the address range they target into account. Use asm helper for existing sanitization in __copy_from_user(). Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/assembler.h | 11 +++++++++++ arch/arm/include/asm/uaccess.h | 26 ++++++++++++++++++++++++++ arch/arm/lib/copy_from_user.S | 6 +----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 483481c6937e..f2624fbd0336 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -461,6 +461,17 @@ THUMB( orr \reg , \reg , #PSR_T_BIT ) #endif .endm + .macro uaccess_mask_range_ptr, addr:req, size:req, limit:req, tmp:req +#ifdef CONFIG_CPU_SPECTRE + sub \tmp, \limit, #1 + subs \tmp, \tmp, \addr @ tmp = limit - 1 - addr + addhs \tmp, \tmp, #1 @ if (tmp >= 0) { + subhss \tmp, \tmp, \size @ tmp = limit - (addr + size) } + movlo \addr, #0 @ if (tmp < 0) addr = NULL + csdb +#endif + .endm + .macro uaccess_disable, tmp, isb=1 #ifdef CONFIG_CPU_SW_DOMAIN_PAN /* diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index 7f96a942d9a0..9a3b6de2edac 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -137,6 +137,32 @@ static inline void set_fs(mm_segment_t fs) #define __inttype(x) \ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) +/* + * Sanitise a uaccess pointer such that it becomes NULL if addr+size + * is above the current addr_limit. + */ +#define uaccess_mask_range_ptr(ptr, size) \ + ((__typeof__(ptr))__uaccess_mask_range_ptr(ptr, size)) +static inline void __user *__uaccess_mask_range_ptr(const void __user *ptr, + size_t size) +{ + void __user *safe_ptr = (void __user *)ptr; + unsigned long tmp; + + asm volatile( + " sub %1, %3, #1\n" + " subs %1, %1, %0\n" + " addhs %1, %1, #1\n" + " subhss %1, %1, %2\n" + " movlo %0, #0\n" + : "+r" (safe_ptr), "=&r" (tmp) + : "r" (size), "r" (current_thread_info()->addr_limit) + : "cc"); + + csdb(); + return safe_ptr; +} + /* * Single-value transfer routines. They automatically use the right * size if we just have the right pointer type. Note that the functions diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S index d36329cefedc..e32b51838439 100644 --- a/arch/arm/lib/copy_from_user.S +++ b/arch/arm/lib/copy_from_user.S @@ -93,11 +93,7 @@ ENTRY(arm_copy_from_user) #ifdef CONFIG_CPU_SPECTRE get_thread_info r3 ldr r3, [r3, #TI_ADDR_LIMIT] - adds ip, r1, r2 @ ip=addr+size - sub r3, r3, #1 @ addr_limit - 1 - cmpcc ip, r3 @ if (addr+size > addr_limit - 1) - movcs r1, #0 @ addr = NULL - csdb + uaccess_mask_range_ptr r1, r2, r3, ip #endif #include "copy_template.S" From patchwork Thu Aug 1 08:16:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070333 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 0F50B13AC for ; Thu, 1 Aug 2019 08:27:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F18C72839C for ; Thu, 1 Aug 2019 08:27:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E52D3283C3; Thu, 1 Aug 2019 08:27:04 +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 418E62839C for ; Thu, 1 Aug 2019 08:27:04 +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=wsCy+2rj6hI3jksvkIwNpuRD5wN5hYx7HnsbFpU4T00=; b=Mbq9oK5RrgbPJk ddtqbSEwIY/7HrvSBp0tqhlnGEtZNEzAuQiUMrp55strvwhZoejvNJMc3rPn/CnPdZL2MkqmzoIzj 7QPsG0s/qdwaJPRqN85EZI0QPh8UQb+0AayWfndNVT2jVsR+m2ONxLCvCy5GR9GyAtJwkEdVHgRs8 nfPU7hK5cpwhd2YnUH/M/QvHqiADg125K6Q9zdX5ocxS4yrJKkOBXbnVzsYpfsP93YqyyIZescXdS m5vE81hyHVC+1HypOge+GjvlYPwfpCEPdI2M2NR0A40nXhr1XDXIyVIejNHeDsPkpo4/It5Tqplo/ nCDRexJ7WO0z96UGBfZA==; 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 1ht6QQ-0003jA-UY; Thu, 01 Aug 2019 08:27:02 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Kj-0003Ei-38 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:11 +0000 Received: by mail-pf1-x443.google.com with SMTP id r7so33607069pfl.3 for ; Thu, 01 Aug 2019 01:21:08 -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=K9TMbtUgLTyiUr1AVMR6X3v/Vfqpdps5jv4IrzU02gI=; b=u2IY36x0captMh4lU1M0wOFOAmston0O2MSPdh8WfOWDhEl6wCe1fHWEB302u0RLea ojVO3+6Uw8ngcEcpYwUKq96/4ZNyKwEJSwrmqBpTewb+1cTQJdgIBsGPrIcskcI3D/WE 5Eg2rHSAqdcoxT2Rx0APBgbNWmChW6h+Ch+VfBXwjDUY8xtjNpJh8eZCmXoMtYQOIAnB KDRBkaRJKx2tqjYEejnBltvZKwg1B+mta/JF1UVSfxbYY86SwBJDW+O9haVVpEQ7x9Ou qnTAXeFV4PukhvZIY1cb0Nqw3H7EhNmjHszAQmsiggMC3v6tFdCB8MczrpQKPRwPqCdj P4SQ== 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=K9TMbtUgLTyiUr1AVMR6X3v/Vfqpdps5jv4IrzU02gI=; b=PTfbAGlheYt0XhjxAeOoqEwS3PoXMMtfZYpah/qZNquEgJ41ewv28A/Y9pI8Kv42Lr MjwFuPQ3ByPR6gyJsP56Kui87ON983FE6B6Q0XDFabxQ784JVXFPr8odvj0Jb1DCCi/x bljfh3YtehpRBqsQALXIdZTUujQ65aTuttc97JShieNwXA+3FqnkGISE8IwJK94LG2Yj fVGV4XinI0l5ydanEty8cThQ135XUKKNrQkI3DFIwKKNS4By9DFCLjwCgjBkysYmYzOE iiMPIocTRDyfKlU1gfRRLs+5ctAE1+Mgoy6NSKhTymYPPlggWwvdIkkLLgVAa2MX6U4j 0W5g== X-Gm-Message-State: APjAAAUMvDXGVWirglI+k1+RMNDER6SNOzeGFGhu0BA7E+3/cjZ53TOF 8YsQ3x+rcKwDenOXxjTmukk2kQ== X-Google-Smtp-Source: APXvYqzf4Da2l4H3VbnCpzaG3Gl/2i8UZm2Ug4a/Qfb/Ei7T9vRFRA4QvB/43nQ/qYdiWxALcg224w== X-Received: by 2002:a62:e901:: with SMTP id j1mr52916707pfh.189.1564647668335; Thu, 01 Aug 2019 01:21:08 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id y194sm47244254pfg.116.2019.08.01.01.21.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:07 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 36/47] ARM: 8797/1: spectre-v1.1: harden __copy_to_user Date: Thu, 1 Aug 2019 13:46:20 +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-20190801_012109_238650_B121470F X-CRM114-Status: GOOD ( 11.68 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit a1d09e074250fad24f1b993f327b18cc6812eb7a upstream. Sanitize user pointer given to __copy_to_user, both for standard version and memcopy version of the user accessor. Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/lib/copy_to_user.S | 6 +++++- arch/arm/lib/uaccess_with_memcpy.c | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S index caf5019d8161..970abe521197 100644 --- a/arch/arm/lib/copy_to_user.S +++ b/arch/arm/lib/copy_to_user.S @@ -94,6 +94,11 @@ ENTRY(__copy_to_user_std) WEAK(arm_copy_to_user) +#ifdef CONFIG_CPU_SPECTRE + get_thread_info r3 + ldr r3, [r3, #TI_ADDR_LIMIT] + uaccess_mask_range_ptr r0, r2, r3, ip +#endif #include "copy_template.S" @@ -108,4 +113,3 @@ ENDPROC(__copy_to_user_std) rsb r0, r0, r2 copy_abort_end .popsection - diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c index 588bbc288396..0b4fe892d00b 100644 --- a/arch/arm/lib/uaccess_with_memcpy.c +++ b/arch/arm/lib/uaccess_with_memcpy.c @@ -153,7 +153,8 @@ arm_copy_to_user(void __user *to, const void *from, unsigned long n) n = __copy_to_user_std(to, from, n); uaccess_restore(ua_flags); } else { - n = __copy_to_user_memcpy(to, from, n); + n = __copy_to_user_memcpy(uaccess_mask_range_ptr(to, n), + from, n); } return n; } From patchwork Thu Aug 1 08:16: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: 11070335 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 75B5D1395 for ; Thu, 1 Aug 2019 08:27:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66CCD2839C for ; Thu, 1 Aug 2019 08:27:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AE6C283C3; Thu, 1 Aug 2019 08:27:20 +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 DD6E12839C for ; Thu, 1 Aug 2019 08:27:19 +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=kaCblxqdU0sULRQCbX5rPYVN7dG6cNNKO3A8tFLDDhE=; b=ck5/Bigjubzp+z HxW89FX/VJP8fclxmcM+0YFhFd7znThKPtoHoEZT1Lf4hLvQUOh/5uviRNP4eMAiBclXapA4+HCO2 RfkyQ2XPC4R7t/TT0qhDSP6G3EHw+vyw/eOqcTOg160mpN6x5pS3Y0pSX6KDF29JASWLUviZxw55R Lh10GrVJfd4RBC6mSqrDiYLJ5XQZWej0P6O1MpLjQGhWJO3a6tVUN7U+HLUuGc3gW1NMshyQOYfrr eSOKD2NrWuGjJE2BYcYmowlpRConlQza+ZMPNhO23vrkxaeBub49bZX4yO3eFy9k4zk8qq8IRfKsp 509eJFGwBWz8JQfHNX0w==; 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 1ht6Qg-00040X-L6; Thu, 01 Aug 2019 08:27:18 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Kl-0003Hn-Gh for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:13 +0000 Received: by mail-pg1-x544.google.com with SMTP id k189so14686966pgk.13 for ; Thu, 01 Aug 2019 01:21:11 -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=jbpvQKJEQu6FughKaepmre4Ek2Fg9qHsXyEHlW2kC7A=; b=nuPAxY96iM+XwKlBy8anITOo/610vyvWeiY88oH4WhEaRNHJ+4FpcKfNUOq6sORC1n bognKJBIWgQngLwGMhYvzwuGBzT4WIu2MfMf8wZwWkZari+WuthCl6e/xY85XPk1O9WS W4HJ2d3jp408eScQ9rXt/Og1AIxEp3+gEHIQ+m0RWksDj+hoyuWm7cqTTOVQdSMaDRnh QQbblfammaCkWIWdwB9jSxF/XD7zfcPy8fmeA0b3nXznGmJW8355BJcQ4Yb3fU+RSBtP xyQgP/CWI3bq3rP9YfrrackmXpNijHi+BWViX2RDCKnE+QVy/UZBD8wV3GkSzbEsMW+v EPUg== 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=jbpvQKJEQu6FughKaepmre4Ek2Fg9qHsXyEHlW2kC7A=; b=duBAf/T8E6ST6Xu7MJdl5gnWJG8pvH/G7k0HvvqkGYHLbxw/balsOgASFXcq7EimlP zqBhi7PKWSuktCFeoojt3fiYJ6yW10QJ95mR5KVw5E84xwaXzkNLQTzpqytaHhfV2Zuf lBOEvTj2hmY198R/ZlnQj3/oiyxbAyRS5Ze6lro1ppI4rh5Miub8i9i3Er/W2YEpfwEe YizTC80mqkJjpYKftYCTlToDPePGNviqh0K+5gDV559o7l/dzM6hAC9IO/iCROfMuOZQ 4G/JAaF/76WY1GLHnzcipVjrHU1dSn3ukaK4QhozBYf1Yl7m3qBek/ZPTZTm6j1DebCk 6ZJg== X-Gm-Message-State: APjAAAWHCP8SLC71Z5Krs85jd6dYz1Vmc5tYGxeR9ASLdwkKD939nsTg X7GeaPhrkvfdFjLejtzIYJKwoQ== X-Google-Smtp-Source: APXvYqzzclOnJ7hW5Cy9TmZm9TaesjMC0utzsTgWcOSVCJD9TpzTUtFt96KW/izuU1HOlYfsmURQtw== X-Received: by 2002:a65:53cb:: with SMTP id z11mr1365272pgr.200.1564647670832; Thu, 01 Aug 2019 01:21:10 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id w4sm90742508pfn.144.2019.08.01.01.21.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:10 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 37/47] ARM: 8809/1: proc-v7: fix Thumb annotation of cpu_v7_hvc_switch_mm Date: Thu, 1 Aug 2019 13:46:21 +0530 Message-Id: <41ffeadd36b1640c285d4d7b633696cd5ae4f03c.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012111_573172_4101D75C X-CRM114-Status: GOOD ( 15.01 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Ard Biesheuvel Commit 6282e916f774e37845c65d1eae9f8c649004f033 upstream. Due to what appears to be a copy/paste error, the opening ENTRY() of cpu_v7_hvc_switch_mm() lacks a matching ENDPROC(), and instead, the one for cpu_v7_smc_switch_mm() is duplicated. Given that it is ENDPROC() that emits the Thumb annotation, the cpu_v7_hvc_switch_mm() routine will be called in ARM mode on a Thumb2 kernel, resulting in the following splat: Internal error: Oops - undefined instruction: 0 [#1] SMP THUMB2 Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.18.0-rc1-00030-g4d28ad89189d-dirty #488 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 PC is at cpu_v7_hvc_switch_mm+0x12/0x18 LR is at flush_old_exec+0x31b/0x570 pc : [] lr : [] psr: 00000013 sp : ee899e50 ip : 00000000 fp : 00000001 r10: eda28f34 r9 : eda31800 r8 : c12470e0 r7 : eda1fc00 r6 : eda53000 r5 : 00000000 r4 : ee88c000 r3 : c0316eec r2 : 00000001 r1 : eda53000 r0 : 6da6c000 Flags: nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none Note the 'ISA ARM' in the last line. Fix this by using the correct name in ENDPROC(). Cc: Fixes: 10115105cb3a ("ARM: spectre-v2: add firmware based hardening") Reviewed-by: Dave Martin Acked-by: Marc Zyngier Signed-off-by: Ard Biesheuvel Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/mm/proc-v7.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index b6359ce39fa7..90cddff176f6 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -106,7 +106,7 @@ ENTRY(cpu_v7_hvc_switch_mm) hvc #0 ldmfd sp!, {r0 - r3} b cpu_v7_switch_mm -ENDPROC(cpu_v7_smc_switch_mm) +ENDPROC(cpu_v7_hvc_switch_mm) #endif ENTRY(cpu_v7_iciallu_switch_mm) mov r3, #0 From patchwork Thu Aug 1 08:16:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070337 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 C9E4813AC for ; Thu, 1 Aug 2019 08:27:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAC562839C for ; Thu, 1 Aug 2019 08:27:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEEB7283C3; Thu, 1 Aug 2019 08:27:28 +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 5D7242839C for ; Thu, 1 Aug 2019 08:27:28 +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=8h71XgfEtioumP1fHMToVE4ff4IYhWfRvTuamjCj2l0=; b=RBe5FrzIjmrNLt AJUf/1iugAN6Q0S/wHSNpWZVE7PLwOFLiXYwRk428PlG3xN0QShsPF6wjqrI1fD7b0YcAFaZMpCuu cjGj61A/Y1vLDwhvG/k3EhYUolOhu8Ae3HEff+E0xze5SnksPl2HXJo/3WwkoS/2ty1TmgEnFR8xD 8qqbKT/rqLIGYFiKVKwunZCUKomZv4Nb3hf9rXEZKjatUehSZEvQ9tuStWksxjAk+kpopLz/Jv0zp tuhpXv3K/4McpCnL4SKOBAl35zli95TmZPs/gbADIvjoEd4KvaugBxNkONeJu779eNVP3ScXuzR7d ZYXnwJWI66rgmm/Rr+GQ==; 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 1ht6Qp-0004Ey-No; Thu, 01 Aug 2019 08:27:27 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Ko-0003ME-4T for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:16 +0000 Received: by mail-pg1-x542.google.com with SMTP id f5so24916213pgu.5 for ; Thu, 01 Aug 2019 01:21:14 -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=/rNw3tnBxgbMcdBdzBneQcQUsRPBm5GaeGzxs7tkgFw=; b=oN+aQ42TkqS/ZeSiy3PDVQMFYJwaMygZDYjh2qN8hDnDvIcJXJV2xpqOJsfr2J87Vb HeXPSEp5GcxRtJuCXOKlcDE0H84nRUB/twMJAH4jd/ZRQ2XVQgi3URaW62kWUFpPqhvx VWkcO50KK0MHGygwXTdMFgPeTJlYbSSFLDzu1sgoU/zfeXdgQg51br4OgEkEcdJH7Lzk 5i4gx5frWTr2aRqQyJrFvT/4HICocdqzcTYe2qbKmjtEUEJkGpNm+nulY/vpSEPHBKFq F6bqs230Y4TzLP/JVePgx7etwDRWQKZEMwVpsDX3zL1VhLFRyfY4sqoDKQ1VqFNTrw1w JK+g== 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=/rNw3tnBxgbMcdBdzBneQcQUsRPBm5GaeGzxs7tkgFw=; b=rccieL4uhP27aVlZIh+KG6ZW7Xm6V7jHhX6HgE4pS13aNH0kOpLCeTaL6vCetGBNsS OSx5FlhX9rAJU0LsQ9ItMg5B/Z8mpAYgrNXf6yCWF9R30hf/6g2M/as67GVzbUPS9Wea hH6G/adJKr/DhhE2Ej9JcY5ncJmX/0g8z7gBCXIyslQtn8wgWQN9zj1o3yqZEe/qyGTU HPkzM4z69mLPIxBDJDfofMJ70CruhkEm9Pi5ZBAsP3r183oXGd9SIra7Mauccz0Mtjf7 2yRt8PLcROg8YxBWAy1xG90GNCFG9pCIGcCtSs6C3LBqPalbeNwkX9JP2YmlrcloQ1Qs o4cA== X-Gm-Message-State: APjAAAWQ2tD45dDtc29khEyE0PE8/cXYhZQ0F0VWswAmjD/AQ+87++jE dSzaxCAbeVPBeQE3sLfL1R5zMQ== X-Google-Smtp-Source: APXvYqyaed19XnqHQXWpNSnB4vgpCpEBf18uaExgzvHFuu8wKI9CVeBs5nx9R212iN+ptzJnz/i5ww== X-Received: by 2002:a63:c006:: with SMTP id h6mr83873722pgg.290.1564647673509; Thu, 01 Aug 2019 01:21:13 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id f7sm69426237pfd.43.2019.08.01.01.21.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:13 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 38/47] ARM: 8810/1: vfp: Fix wrong assignement to ufp_exc Date: Thu, 1 Aug 2019 13:46:22 +0530 Message-Id: <17ef1620483a77f70c7c27e64cba3ad1684626c7.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012114_693052_0D79CB6A X-CRM114-Status: GOOD ( 12.41 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 5df7a99bdd0de4a0480320264c44c04543c29d5a upstream. In vfp_preserve_user_clear_hwstate, ufp_exc->fpinst2 gets assigned to itself. It should actually be hwstate->fpinst2 that gets assigned to the ufp_exc field. Fixes commit 3aa2df6ec2ca6bc143a65351cca4266d03a8bc41 ("ARM: 8791/1: vfp: use __copy_to_user() when saving VFP state"). Reported-by: David Binderman Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/vfp/vfpmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index f07567eedd82..f9392fb060ea 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -583,7 +583,7 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp *ufp, */ ufp_exc->fpexc = hwstate->fpexc; ufp_exc->fpinst = hwstate->fpinst; - ufp_exc->fpinst2 = ufp_exc->fpinst2; + ufp_exc->fpinst2 = hwstate->fpinst2; /* Ensure that VFP is disabled. */ vfp_flush_hwstate(thread); From patchwork Thu Aug 1 08:16:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070339 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 23E0313AC for ; Thu, 1 Aug 2019 08:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1584D2839C for ; Thu, 1 Aug 2019 08:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09CF3283C3; Thu, 1 Aug 2019 08:27:41 +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 A9BB62839C for ; Thu, 1 Aug 2019 08:27:40 +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=UgYOtyaamy8Mpgwb9/bmtTK7wpwOw5QNyBGBayyTDk0=; b=BXxT9LCeCoEnWQ XPJ0mCnAUWUQK5Yoia6RZI8wtgTYvUnqImwsNt+Fv02dRW9+tz1gUnkV5/2AYfvyKzMYD7tatgzJt wxd005cEJhiipbvcfIqeskfbnVL/OpZ+Prg0P7sDBW0Nu/vENdwxjA2LEdbVS/Wzpznvx5PmHi9wq XFLguOIVXN/Aoj1/fmFnvU8lcBHC/Li0biTFIDc8qXkWplUa2Kv67aZT5JaJemUQ1parcnAFTG3Y/ XI7Fo33G9lY6unl9rTkfEQUZ4aYox9MLmfFatIwXUXy612pl9w08V60qo+ROd+IMALQdE84E7/Iz4 YtirYCLCH4MuQZ06EvFQ==; 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 1ht6R1-0004Y3-FR; Thu, 01 Aug 2019 08:27:39 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Kq-0003Pu-NG for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:18 +0000 Received: by mail-pf1-x441.google.com with SMTP id r1so33599032pfq.12 for ; Thu, 01 Aug 2019 01:21:16 -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=Ds/lGPMr1EeNlwL4g2s5u78S6SjnXx7V9zy6A/rndeo=; b=mrBLXFMWzLa/t7R+RAPTUBkuVhtuO0SSPUQKBcr4iUCBlgaEqHyhHd1/uFMJhGMS4H N7XjT/O08TzqMLeVggwfT1HkHWMoa9XZeUoJ2ULmHwCAkn2l0Y5Ub+4RWPx5FREjiOG3 xUhF0T115Bzb04sIYFubQM6mOq/14QvHEkB5h782l/RJNU1EKnLx/NMzfR0bgMV3We07 4zuE/xFl23PtDuJ0i3REzyBcqE3BaNSJTNyqxML7FsXc7LTY8qLCZ3zUH+TZ1ypTx/gE qFmHoJxAufo87ZLAQx8l988GrmSI8dpXGDOubdDWBDHk030J6NlJEpENvqm9TEq1OThR d0hQ== 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=Ds/lGPMr1EeNlwL4g2s5u78S6SjnXx7V9zy6A/rndeo=; b=P4mcD3L16K74/6PHB9q+9TMQVpKR9GrvCjNl+Q17ZZtkzT/HO2hg1xVI2ktiuT1hlo KRBha8PHi7M2Do3AiBN8mjpqPZi1UDw3gaoXly8FxDMB/syTRXVQnb87OkzPmtmLyBwf C8gCsRCXQaFkiTEdwWequhaGCa5Epmh9WFqsPQfrbY+ngEgzXYi59mzz6QB4IT9oNKY5 ES3CjNrrgATZkeByNkhbhycM6q9lMMnhkUou/pZ+0nJiAs9zEpPao8lxQo9XS2xOVJvl +4cG1FT96DvLsHzMXABzou0UllT3daIRcw5zF54ZP7l2iZzpu558pDnBNoymBjqCo3gC bcZA== X-Gm-Message-State: APjAAAVofXnB4sBlHSvA3I6KucCK3CQzsvtWlXpRJA4t3ED7wssWC0St Bf24vuayjPqiH/0bfaGyqAxRuH8j4ro= X-Google-Smtp-Source: APXvYqwtKxDMpgoZCbvREEE29QxNQP1W961hLJzisPedFonBaTo+teb/eU6GTFHq0O6jopgGgyalGg== X-Received: by 2002:a62:642:: with SMTP id 63mr52289837pfg.257.1564647676154; Thu, 01 Aug 2019 01:21:16 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id v18sm69519775pgl.87.2019.08.01.01.21.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:15 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 39/47] ARM: make lookup_processor_type() non-__init Date: Thu, 1 Aug 2019 13:46:23 +0530 Message-Id: <8571a7c6a6ff472e0d794311dda2ee4fb64f29eb.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012116_781641_B85B9C30 X-CRM114-Status: GOOD ( 12.56 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 899a42f836678a595f7d2bc36a5a0c2b03d08cbc upstream. Move lookup_processor_type() out of the __init section so it is callable from (eg) the secondary startup code during hotplug. Reviewed-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/kernel/head-common.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S index 8733012d231f..7e662bdd5cb3 100644 --- a/arch/arm/kernel/head-common.S +++ b/arch/arm/kernel/head-common.S @@ -122,6 +122,9 @@ ENDPROC(__mmap_switched) .long init_thread_union + THREAD_START_SP @ sp .size __mmap_switched_data, . - __mmap_switched_data + __FINIT + .text + /* * This provides a C-API version of __lookup_processor_type */ @@ -133,9 +136,6 @@ ENTRY(lookup_processor_type) ldmfd sp!, {r4 - r6, r9, pc} ENDPROC(lookup_processor_type) - __FINIT - .text - /* * Read processor ID register (CP#15, CR0), and look up in the linker-built * supported processor list. Note that we can't use the absolute addresses From patchwork Thu Aug 1 08:16:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070341 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 E7B7E1395 for ; Thu, 1 Aug 2019 08:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8CFE2839C for ; Thu, 1 Aug 2019 08:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCF14283C3; Thu, 1 Aug 2019 08:27:50 +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 6202D2839C for ; Thu, 1 Aug 2019 08:27:50 +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=n1mnnclUdgbgwUpmHvZMPA19laXFU6oU9v445hClwxM=; b=ZUwCaGEtE5oXyk WUOWI1RJXHAWUuGOdJ0Ov8gQt2Wg0OktWojc7jGaMJ43oUrYxGxpt1ZxkXLLAkePKzZcYSVxCmQjI eaasJ7KlxUACyZ1zuptzN36TvLm7EDrWg7DKP4auaFiCfHx4xSiqmA+vuQGmZLu14gSzwHeAAmOBl zQOGAAKI6J2MOERVEOwmgSwFsIqd0x+Jv1t3ccqEuA4qFOoyZVOpBjiYOHLxq+msqHkOMLshgDosb TOwslke8GHquRGt3Tjnreg0q7k+n7CrLjpew8yc9j4/z16vBa3DtvGtcpsMHcjB6DvMEvYu0dYj3q eKDS07rExQGRJdQbGuiA==; 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 1ht6RB-0004o9-Qp; Thu, 01 Aug 2019 08:27:49 +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 1ht6Kt-0003Y9-E7 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:21 +0000 Received: by mail-pg1-x541.google.com with SMTP id x15so23387712pgg.8 for ; Thu, 01 Aug 2019 01:21:19 -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=ea6sM+FtbjaUvKE8XTo8IrkOgZbBdosuDWN0NMu3JEA=; b=IqgMWC+doqxZ/x9SW9opxGfpwlsiAyQDTKWOiIlR0W4chV0hNWekn8EH67WIsJo7r7 tGHL37Y5GWbCA74ReUFqeSKAAs8gOSdGslZ0rY5riXYyM+Nmr7hjPiEr5XuQQuRdFNss rZr3eZ6x8gRF1jdGXT+WJo+5N1MHeZqMl25r6qJEsR1nFISh2pFEC/F29TkrwoJZ4mgU X4WGLXr6pcnpr/EmZWFfQORxn2Mr8rd0LF6yeeo0iQdI8GbACrwZkzeOP1Ffk6fQ+6xF U+0mJeTXirqYQdR0a7U1BQV/SOPMFILzWfKSe3nJbln8rg+OJDsEKuAZVfiORH1yci53 OmcA== 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=ea6sM+FtbjaUvKE8XTo8IrkOgZbBdosuDWN0NMu3JEA=; b=Wm2Ak6c3cesm5GCS/C02WYsd1749BHY3TVFJMjdSiASet5ztA1ooYQqLO5J5DvxiB4 HWlxnXzMZ8bhE2Mwa5ahlOU3DpQXIn/D9tWTE3VabqRkpkUguMyy3USr6HxvDKgtqupd kcFg4STYOiBJ18jrE+vRtD3Pq4jCuOIJNiUR1z2gdb6eeIgh4IHyj2iB6xcM971q7agm iZEEsg60k1gmjAdSDXs7S4ujvIQ7sWjZj9Vh9i7RbOPfTh3QqOVn6+p6NRyRF4gNQBnr p3NR2tNupKXrvT1BBv7dA2wZsSMRsQt8JElZnuzK4oZFBnpFhLy7k4QYueWisRuy2kyt tw4w== X-Gm-Message-State: APjAAAWyQGFeomqipbeCWSGbiNn8Ilcngy+lLb7K/V1RR/Q4qD+LSDLz WD1dD2qT/BA+3NYiUNM49ChXer+ZuuE= X-Google-Smtp-Source: APXvYqw0PAqPaGk4hWjyFbvlyejncVcUiQTq3n7cbWPXrKNvQoJaFsq4FxSG/OTM180Q3cX7bL1lpw== X-Received: by 2002:a17:90a:9905:: with SMTP id b5mr7468850pjp.70.1564647678567; Thu, 01 Aug 2019 01:21:18 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id y194sm47245954pfg.116.2019.08.01.01.21.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:18 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 40/47] ARM: split out processor lookup Date: Thu, 1 Aug 2019 13:46:24 +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-20190801_012119_518157_7C30DB9C X-CRM114-Status: GOOD ( 15.85 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 65987a8553061515b5851b472081aedb9837a391 upstream. Split out the lookup of the processor type and associated error handling from the rest of setup_processor() - we will need to use this in the secondary CPU bringup path for big.Little Spectre variant 2 mitigation. Reviewed-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/cputype.h | 1 + arch/arm/kernel/setup.c | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/arch/arm/include/asm/cputype.h b/arch/arm/include/asm/cputype.h index 76bb3bd060d1..53125dad6edd 100644 --- a/arch/arm/include/asm/cputype.h +++ b/arch/arm/include/asm/cputype.h @@ -93,6 +93,7 @@ #define ARM_CPU_PART_SCORPION 0x510002d0 extern unsigned int processor_id; +struct proc_info_list *lookup_processor(u32 midr); #ifdef CONFIG_CPU_CP15 #define read_cpuid(reg) \ diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 20edd349d379..5aa9c08de410 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -599,22 +599,29 @@ static void __init smp_build_mpidr_hash(void) } #endif -static void __init setup_processor(void) +/* + * locate processor in the list of supported processor types. The linker + * builds this table for us from the entries in arch/arm/mm/proc-*.S + */ +struct proc_info_list *lookup_processor(u32 midr) { - struct proc_info_list *list; + struct proc_info_list *list = lookup_processor_type(midr); - /* - * locate processor in the list of supported processor - * types. The linker builds this table for us from the - * entries in arch/arm/mm/proc-*.S - */ - list = lookup_processor_type(read_cpuid_id()); if (!list) { - pr_err("CPU configuration botched (ID %08x), unable to continue.\n", - read_cpuid_id()); - while (1); + pr_err("CPU%u: configuration botched (ID %08x), CPU halted\n", + smp_processor_id(), midr); + while (1) + /* can't use cpu_relax() here as it may require MMU setup */; } + return list; +} + +static void __init setup_processor(void) +{ + unsigned int midr = read_cpuid_id(); + struct proc_info_list *list = lookup_processor(midr); + cpu_name = list->cpu_name; __cpu_architecture = __get_cpu_architecture(); @@ -632,7 +639,7 @@ static void __init setup_processor(void) #endif pr_info("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n", - cpu_name, read_cpuid_id(), read_cpuid_id() & 15, + list->cpu_name, midr, midr & 15, proc_arch[cpu_architecture()], get_cr()); snprintf(init_utsname()->machine, __NEW_UTS_LEN + 1, "%s%c", From patchwork Thu Aug 1 08:16:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070343 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 BB5E213AC for ; Thu, 1 Aug 2019 08:28:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD1E42839C for ; Thu, 1 Aug 2019 08:28:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1631283C3; Thu, 1 Aug 2019 08:28:03 +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 3F0C42839C for ; Thu, 1 Aug 2019 08:28:03 +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=6I0uctwP3YSIFZ1v/mzNltXP+fJNkv4kRXoKcF/VMm4=; b=H9NZcgrs2lb+mX WEcUSlW3AbXCVIDItN7Kk+7odqBm1usLWD5K1kglMrtbzu/RCPuYdh9tlGDUezxI5v8udVHpFLvoW yTgcRPeOGVC9R+s2/PZrAIjvFp/xoLOikAvVfchwBN25BiSLIZbKBq0JdfvDFyqC15KXghWeZ9NXf 1Zt2oglclAOWhxz8h3ddFb9zT6Am4+TClXkbXltPn/KKjOOkZZiJX4XRz7f6oo5IiR3ULqKWbfRPy cOvkcaQf4WW3q/FHeuMSv0Zg45OMZlgoJf5w/IURiGvyl5SnABSInsTvBM7IMK/Cs2p6LPhbClkzb y4ZQWYrY2/JqeTLZJU1w==; 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 1ht6RN-0005BZ-Ps; Thu, 01 Aug 2019 08:28:01 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Kv-0003bb-H2 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:22 +0000 Received: by mail-pl1-x642.google.com with SMTP id k8so31880996plt.3 for ; Thu, 01 Aug 2019 01:21:21 -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=gEzBHKM5Yrnew5IgDE9VhKRrkovpTReWWDnzndMpTpo=; b=UN9wbT1c5Wx19ZD2dzkTJ0vzKrvZSwdLl/MoPaL7Bf5lgYTUbPsoGyZaiQxXofgkyN I9Ta0f5FCBMV/ZPClK1Ut66nIJg9T6CE9kwIi3O+VIixnsW+ZVIAXVzfRpelZyl2PfOV UQ2qf49OaqxnZw5UwF+H40gSMu5ka3TK3gzkPxSM+M04VEdd6jvD/ZUnXWE9zqktt1DC bfLwxwHqhXAhLi1gls5Aq9+gSGFeuIsSUu5sX/BfT3URFPW1pv/HgNwFqeXUojYz2mMe Tmo/OGFIq2GbvVBu0phLhNVYn/62935QkaI/dM2KpSkyMSvZTxnywcgXj/DwrSY7RWKD WgvA== 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=gEzBHKM5Yrnew5IgDE9VhKRrkovpTReWWDnzndMpTpo=; b=Qw4pjDLPDXeMCwdNjMrZ3KzpZCedXeWDEEFewMuxWK2voarJOezPCrPuQATIeseAxN E3xBZ7T7/z8hbUoaD8ryQ8ikNnFQ11id4rxdw1Di1lIV+ZcEmgMKQWXzgW40+/5Yg/50 UE6D7y9cNkVyxWwDKXm0eU+Ne+/PQX7l8wBF+CnGAj6NankXOw9oZ3P9cSCYhmGgfZ5G OTazwzUu+IFYQtiT1FKRRcKwOKYtVYP2xQQg8HEAxWaxQL0C6eWNLamHUCwoBRPuW49I 3w26QqjKpb5BbBCDby0GUqfXReaihz+5KZ+JOfmm9tYfDtt8A8LKshUxSFw1qHwILdEy nnVg== X-Gm-Message-State: APjAAAUyf3oGgVZGeTSjifYP0vp1wCMWZATU1oy7QtVvTgNlk7T+Xj9j Lpwc0RmRbQq/KrWhgG/Z25Siag== X-Google-Smtp-Source: APXvYqwb0TOHdBpq4vG3XgGwqBBj/UNlT/qteIlZUZg9wGkRaWIn9Bg0d24y471cMtkOLZx/GzPB8Q== X-Received: by 2002:a17:902:7c96:: with SMTP id y22mr127080149pll.39.1564647681003; Thu, 01 Aug 2019 01:21:21 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id j6sm10632447pjd.19.2019.08.01.01.21.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:20 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 41/47] ARM: clean up per-processor check_bugs method call Date: Thu, 1 Aug 2019 13:46:25 +0530 Message-Id: <33110a95761cf304c04b2837d8539553adde85b8.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012121_575818_9ED1CBE6 X-CRM114-Status: GOOD ( 13.75 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 945aceb1db8885d3a35790cf2e810f681db52756 upstream. Call the per-processor type check_bugs() method in the same way as we do other per-processor functions - move the "processor." detail into proc-fns.h. Reviewed-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/proc-fns.h | 1 + arch/arm/kernel/bugs.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index f379f5f849a9..19939e88efca 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h @@ -99,6 +99,7 @@ extern void cpu_do_suspend(void *); extern void cpu_do_resume(void *); #else #define cpu_proc_init processor._proc_init +#define cpu_check_bugs processor.check_bugs #define cpu_proc_fin processor._proc_fin #define cpu_reset processor.reset #define cpu_do_idle processor._do_idle diff --git a/arch/arm/kernel/bugs.c b/arch/arm/kernel/bugs.c index 7be511310191..d41d3598e5e5 100644 --- a/arch/arm/kernel/bugs.c +++ b/arch/arm/kernel/bugs.c @@ -6,8 +6,8 @@ void check_other_bugs(void) { #ifdef MULTI_CPU - if (processor.check_bugs) - processor.check_bugs(); + if (cpu_check_bugs) + cpu_check_bugs(); #endif } From patchwork Thu Aug 1 08:16:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070345 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 35CE01395 for ; Thu, 1 Aug 2019 08:28:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2757A2839C for ; Thu, 1 Aug 2019 08:28:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B959283C3; Thu, 1 Aug 2019 08:28:14 +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 9F7282839C for ; Thu, 1 Aug 2019 08:28:13 +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=uGQfTibfZS2bd+OMm5YUAkx0U13YfdFUHfqOp7uMM8o=; b=cBAsRMjYyyYhWg ahgdodOm61BIJNvqqizRorCAR3e6Hqy0+Nz9NHnbAzEh5Kujrf0rGUNdIJWfLubqYCi1/1yCRelzg I5/tBRv5qVIOphI3JXPSRB7zG4Tq1jp3ULroFx4p4Chqg+bJRTWjbbhm+tmrfQhaw+XPybDKae1rX 9mtP3fqqRJLU+iuj0/YZSxfBrNQHlH6TwEpZ6vO4DpcgTfX9pKPmnCDQ468eLJjHzWTv7i3Y5owzJ yHtqQPeaqQfoDovWQkiTRn3Ki3bejSWu9IahvPGOZJUrCj2tOuO4mbWbdQd/4B6U537UW0zlmLpwD Dt/sgxfiPW6GWxWkpapA==; 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 1ht6RY-0005Sl-Lv; Thu, 01 Aug 2019 08:28:12 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6Ky-0003gk-Ch for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:26 +0000 Received: by mail-pf1-x443.google.com with SMTP id y15so33617444pfn.5 for ; Thu, 01 Aug 2019 01:21:24 -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=bD+Nn9yJj6UL1BxkfmyNVyFE/Bkgh8dLgfivcvvulBg=; b=ANFP8g1p8JFQVKTJYFx6Vw0TW4voibG5DCIASdhkve+IYqSbpJ4pf1CPI/gRJ9yt9S Exd2NJ/005eJrvN/yD3fqP0TfCskg40yqFmckXx7hep+VMMYb4kaUeqZgNxjwXXFeGLC O3Ushag+gGUFO2uvKX4/gXf4FklbrwOHxejkTxQhoge9Yh0YBa9qCcs7TDt/NyGFFi4o gTbulqNmF52VLHNlryHUkhlrggT41FV0BmdZM6Tsypos2QcAO39GpCKgBwmqbDroqaal K618LSh+GSZQjXSoXrvv+ILwOFzCzenhlRDr2gjgi3/ik+gpk9I1T9beafOOAiHqpqDx BioQ== 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=bD+Nn9yJj6UL1BxkfmyNVyFE/Bkgh8dLgfivcvvulBg=; b=SMstGhJScO8O6pAdV4aReuYe6xRLuziNyulKhbwRlQfblkZQdXLisWKwTDoyTh6iHj WKHM7ymz6ce0Dcvl08epCA3qxw7BmujFqU0SFUaVSgk3K0NwRLpKwmgPztcJ+sE2kAGR 3LT6yvUTeRZGcCmNU31ovBmbJx1+nYbIH17Dmwm6E98kgn1h6/r6kbtneongRCPmSpPR qhBTltgq522C6v/Ds8XgRRV0v6nOZJMpVv1bRoeJrEClRc+Hwju/BHzYWNxDANB1+wAW nkcu21LjnLRVv4ijWQ67QqjCNdWffHHRGOd0GYux/VdIdV5DvSxVtNpGie8l539ovWHq NVGg== X-Gm-Message-State: APjAAAWxer1xpZa5erDgI0QJ77ab+TTqo0bDD26jx0uwbeJ/uy7E6pA+ l8o0vgizO38Z4C1h3IINqyE+pg== X-Google-Smtp-Source: APXvYqypoB0dNvIfWnZO4fN9gYvd+RKBGHdAxLgr2a8Ae+fHpzOWFZr7WBaSVZCjI7TMwOfX4wnj9g== X-Received: by 2002:a63:e20a:: with SMTP id q10mr115552737pgh.24.1564647683731; Thu, 01 Aug 2019 01:21:23 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id p13sm6487461pjb.30.2019.08.01.01.21.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:23 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 42/47] ARM: add PROC_VTABLE and PROC_TABLE macros Date: Thu, 1 Aug 2019 13:46:26 +0530 Message-Id: <888892dc104d817f590058687946b7f6078d328c.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012124_445746_FA91BCEF X-CRM114-Status: GOOD ( 13.99 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit e209950fdd065d2cc46e6338e47e52841b830cba upstream. Allow the way we access members of the processor vtable to be changed at compile time. We will need to move to per-CPU vtables to fix the Spectre variant 2 issues on big.Little systems. However, we have a couple of calls that do not need the vtable treatment, and indeed cause a kernel warning due to the (later) use of smp_processor_id(), so also introduce the PROC_TABLE macro for these which always use CPU 0's function pointers. Reviewed-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/proc-fns.h | 39 ++++++++++++++++++++++----------- arch/arm/kernel/setup.c | 4 +--- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index 19939e88efca..a1a71b068edc 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h @@ -23,7 +23,7 @@ struct mm_struct; /* * Don't change this structure - ASM code relies on it. */ -extern struct processor { +struct processor { /* MISC * get data abort address/flags */ @@ -79,9 +79,13 @@ extern struct processor { unsigned int suspend_size; void (*do_suspend)(void *); void (*do_resume)(void *); -} processor; +}; #ifndef MULTI_CPU +static inline void init_proc_vtable(const struct processor *p) +{ +} + extern void cpu_proc_init(void); extern void cpu_proc_fin(void); extern int cpu_do_idle(void); @@ -98,18 +102,27 @@ extern void cpu_reset(unsigned long addr) __attribute__((noreturn)); extern void cpu_do_suspend(void *); extern void cpu_do_resume(void *); #else -#define cpu_proc_init processor._proc_init -#define cpu_check_bugs processor.check_bugs -#define cpu_proc_fin processor._proc_fin -#define cpu_reset processor.reset -#define cpu_do_idle processor._do_idle -#define cpu_dcache_clean_area processor.dcache_clean_area -#define cpu_set_pte_ext processor.set_pte_ext -#define cpu_do_switch_mm processor.switch_mm -/* These three are private to arch/arm/kernel/suspend.c */ -#define cpu_do_suspend processor.do_suspend -#define cpu_do_resume processor.do_resume +extern struct processor processor; +#define PROC_VTABLE(f) processor.f +#define PROC_TABLE(f) processor.f +static inline void init_proc_vtable(const struct processor *p) +{ + processor = *p; +} + +#define cpu_proc_init PROC_VTABLE(_proc_init) +#define cpu_check_bugs PROC_VTABLE(check_bugs) +#define cpu_proc_fin PROC_VTABLE(_proc_fin) +#define cpu_reset PROC_VTABLE(reset) +#define cpu_do_idle PROC_VTABLE(_do_idle) +#define cpu_dcache_clean_area PROC_TABLE(dcache_clean_area) +#define cpu_set_pte_ext PROC_TABLE(set_pte_ext) +#define cpu_do_switch_mm PROC_VTABLE(switch_mm) + +/* These two are private to arch/arm/kernel/suspend.c */ +#define cpu_do_suspend PROC_VTABLE(do_suspend) +#define cpu_do_resume PROC_VTABLE(do_resume) #endif extern void cpu_resume(void); diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 5aa9c08de410..13bda9574e18 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -625,9 +625,7 @@ static void __init setup_processor(void) cpu_name = list->cpu_name; __cpu_architecture = __get_cpu_architecture(); -#ifdef MULTI_CPU - processor = *list->proc; -#endif + init_proc_vtable(list->proc); #ifdef MULTI_TLB cpu_tlb = *list->tlb; #endif From patchwork Thu Aug 1 08:16:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070347 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 CFD2813AC for ; Thu, 1 Aug 2019 08:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C15A02839C for ; Thu, 1 Aug 2019 08:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B50BF283C3; Thu, 1 Aug 2019 08:28:23 +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 989B2283A6 for ; Thu, 1 Aug 2019 08:28:22 +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=7JG5MOn2ar6h+5Ybp6DNE/2ucuS8lf/lV9MwczrJYGw=; b=S2z24tllOvqSnb dgNHtxD3N4td5U9JpW7QF0NEzkERHMwFh554aD0LSTjl645kVbVwl7wD3lCWIjnnXnQisjWcjsGiE geuLTVM3wIGuND15q4LD2fndubwEhw/JSdIsJuKoessiD0w/kMonuLdSO4mNBL2ZknaUX3NzjQGb3 WNlJMq4gGtJG8Qns3MXvYgIpiXyVNtjyyRhGukPvGUEwgAvokOvvaV0k37+KfGGjh0C7SIWnjLxwX qjReJlZfUbUMv/yt7cMfaoe+E9bsoOsUMY35Ku4V1nU0bWHM9C8NLmKvnbd7PHH2yTJvydKlky+g0 6vlosxnaF+p7JJBPoR5w==; 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 1ht6Rh-0005jM-EK; Thu, 01 Aug 2019 08:28:21 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6L1-0003kb-33 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:29 +0000 Received: by mail-pf1-x444.google.com with SMTP id m30so33618221pff.8 for ; Thu, 01 Aug 2019 01:21:27 -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=q2P7nbVondTzzEiUufavLpCtXHz6lnekor7t8KaG36c=; b=pTRCSsFiNu8OBieM4n9EH1oBWaf9DxqQrE8qfxItoRa9cD/Spg5spSoIPphBVmAIai rokTXzv97smMqkOdkzzyKoEUTdP3B+H++HwiH9+qNX60puKsd6dpA61w4Dn6n2GhvmH7 cVxFAgwWjdW1QLRyXVrIBUPaKR73xXXmvr5m7gAwvGcGLbJ39BMne+Xfj7MVv0Bh6mQj KcbBBnVOhhBhVRn/Ry9JiNyiQfHvZeqhXZzhDIblc8b020MRzcQ8Z+yxtBM52JqBNwYh HZWPgcTne1OqI6kvSgxDABJIJzN9Kahd5jeUObH6yW4QM1CbXdAxwjYLazDrslXSI564 gDnw== 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=q2P7nbVondTzzEiUufavLpCtXHz6lnekor7t8KaG36c=; b=VRfkmOzHYjHaDfsz+6Vqz/HMQj6TTD40K+zk+ulxSfIp9t467pbLfzVZbtfbV2WgmF hbmwwX+BPCnPGNPAMWznx4A6rYDiZCfqGtYDZJeE84WoRzoq1aSIKvTs2L3L0ZROroMD 3e73vYU2VKc7mMKhpJwDvIJDq9a3lWaXNF5SxWSsiQwgtYPcwNo2YoOvVPXgRwITUak+ r2u8eHeFS8JSYSVOGjffLqKh1Gu9mPm53JnUoxiCxfhTdmaXto0W+ZCFZafhyqXJuUcZ J+2EQdi3okhkORlaAi7NDvbEbGw3+7Dkqhonub2NUkBixR2S/yh1jYwJ7X3IsHUr38NY VC/Q== X-Gm-Message-State: APjAAAW/wgJh8rEkhr6wPEvEpM/jPjYOWAqXDRVYgyVC24cPVxNY7wth O/j5jC2ywm8fc5WoecuntBxtVQ== X-Google-Smtp-Source: APXvYqyinL72Ad1WC23YEaPJqW0xWZohjAv/ucPmvqt5ElYyOzPq0U5gBpJHjgVmPygyojXAbQoijA== X-Received: by 2002:a63:6206:: with SMTP id w6mr1819946pgb.428.1564647686306; Thu, 01 Aug 2019 01:21:26 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id u7sm64635107pfm.96.2019.08.01.01.21.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:25 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 43/47] arch: Introduce post-init read-only memory Date: Thu, 1 Aug 2019 13:46:27 +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-20190801_012127_155590_44440AF1 X-CRM114-Status: GOOD ( 16.97 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Kees Cook Commit c74ba8b3480da6ddaea17df2263ec09b869ac496 upstream. One of the easiest ways to protect the kernel from attack is to reduce the internal attack surface exposed when a "write" flaw is available. By making as much of the kernel read-only as possible, we reduce the attack surface. Many things are written to only during __init, and never changed again. These cannot be made "const" since the compiler will do the wrong thing (we do actually need to write to them). Instead, move these items into a memory region that will be made read-only during mark_rodata_ro() which happens after all kernel __init code has finished. This introduces __ro_after_init as a way to mark such memory, and adds some documentation about the existing __read_mostly marking. This improves the security of the Linux kernel by marking formerly read-write memory regions as read-only on a fully booted up system. Based on work by PaX Team and Brad Spengler. Signed-off-by: Kees Cook Cc: Andy Lutomirski Cc: Arnd Bergmann Cc: Borislav Petkov Cc: Brad Spengler Cc: Brian Gerst Cc: David Brown Cc: Denys Vlasenko Cc: Emese Revfy Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Mathias Krause Cc: Michael Ellerman Cc: PaX Team Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: kernel-hardening@lists.openwall.com Cc: linux-arch Link: http://lkml.kernel.org/r/1455748879-21872-5-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar Signed-off-by: Viresh Kumar --- arch/parisc/include/asm/cache.h | 3 +++ include/asm-generic/vmlinux.lds.h | 1 + include/linux/cache.h | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h index 3d0e17bcc8e9..df0f52bd18b4 100644 --- a/arch/parisc/include/asm/cache.h +++ b/arch/parisc/include/asm/cache.h @@ -22,6 +22,9 @@ #define __read_mostly __attribute__((__section__(".data..read_mostly"))) +/* Read-only memory is marked before mark_rodata_ro() is called. */ +#define __ro_after_init __read_mostly + void parisc_cache_init(void); /* initializes cache-flushing */ void disable_sr_hashing_asm(int); /* low level support for above */ void disable_sr_hashing(void); /* turns off space register hashing */ diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index a461b6604fd9..c63f92150eda 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -256,6 +256,7 @@ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ VMLINUX_SYMBOL(__start_rodata) = .; \ *(.rodata) *(.rodata.*) \ + *(.data..ro_after_init) /* Read only after init */ \ *(__vermagic) /* Kernel version magic */ \ . = ALIGN(8); \ VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \ diff --git a/include/linux/cache.h b/include/linux/cache.h index 17e7e82d2aa7..1be04f8c563a 100644 --- a/include/linux/cache.h +++ b/include/linux/cache.h @@ -12,10 +12,24 @@ #define SMP_CACHE_BYTES L1_CACHE_BYTES #endif +/* + * __read_mostly is used to keep rarely changing variables out of frequently + * updated cachelines. If an architecture doesn't support it, ignore the + * hint. + */ #ifndef __read_mostly #define __read_mostly #endif +/* + * __ro_after_init is used to mark things that are read-only after init (i.e. + * after mark_rodata_ro() has been called). These are effectively read-only, + * but may get written to during init, so can't live in .rodata (via "const"). + */ +#ifndef __ro_after_init +#define __ro_after_init __attribute__((__section__(".data..ro_after_init"))) +#endif + #ifndef ____cacheline_aligned #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES))) #endif From patchwork Thu Aug 1 08:16:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070349 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 DB8A213AC for ; Thu, 1 Aug 2019 08:28:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1A42839C for ; Thu, 1 Aug 2019 08:28:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0C06283C3; Thu, 1 Aug 2019 08:28:30 +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 52B0F2839C for ; Thu, 1 Aug 2019 08:28:30 +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=ZIt3z1TWjfcLtH7IhCQroDGm4JEEDe1Q6UQSouafT7Y=; b=SgTVhCSZbEhBsZ NZhe8JU0KYDPVV9KXIcI5K4rl6UBnYENC41LGITJC7iqtOqZSWgKIekFIdrb1JZs2xP77+laYYXRv /jmtqJu6QohA8do0IV1u68lxgUkXKgLtYD+SxmQVVeKHYznj8BSjPqC6FvqdMncCeSksDM3lI/n7y Vkh4sPb54DySsec80PJm4xRf/xCZDjwEWfnxg2kI8jRYGh4nOlYzBWwToSEv7NAx7mUQgDA71NFO9 DbQVCOx+yp4Ho9Xx3s3c+hup1LZISg4Bpe5JoequsIlxDmH/mwM6HQCcyVfeM71JsYTgYzoDpEx+9 TEriHM3HsitUq8w0CkpA==; 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 1ht6Ro-0005yd-Qj; Thu, 01 Aug 2019 08:28:28 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6L3-0003oF-NC for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:31 +0000 Received: by mail-pg1-x542.google.com with SMTP id l21so33731455pgm.3 for ; Thu, 01 Aug 2019 01:21:29 -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=OQQ7xLa0wSJEVHtnIJUBQOen48CMIup3yNRZI8hCHQM=; b=oUYvAhHhaGgQYxb7bVSRF/4PxV5nyflrpPmlxaW+Z0f9y4sbb5KYVLE2zZNCcCI8QC k6vhSEVq7El7m5wPYxjtWN+N50RBaxgAi75+esakTPx2EM8j8CsaHi6hbRpqZWS8QO6X J/25wYqXIe7p4IkEL1rWhx9nKPlX1oVIUTjPCtmlEV2i3zrah/Ba0a7jcMgt+O94BV1M NgDePvBcBEtfGbQpdElGyGpl/swofqLnHMPuTtPSERWiJys4+7sFcMZz9PCRPbozZ6/y jzqznP9NbpYao0nojWycpAH5xwx+8WyFQnqAJyO/3kxfDNdI4cMMVNIL96CVc6vhGyz3 +eYg== 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=OQQ7xLa0wSJEVHtnIJUBQOen48CMIup3yNRZI8hCHQM=; b=pcQvQ3wg4m1vsGnPITPK1qcs0S0TMIPCb2oVnswkYEsNixMPFBQwjfAhIEld5wDNkW CNte3dUWP7GZyYbsu3VEZ0Ao+8xoFSTuFNUYULXEfT4D5efn+6JDnB4LpPl0ujoZ+MD0 xZwXrgUsXEGVYxOa7JduCM7/a47SeB+ofIVf2/e3OWS/P3LoE6e8u2xDx/kpVW8/w4F/ vNtSGLA/E9scaw0dDvIVhUQk+pUDCCC5myYMsJ5ZEygIGxVysccLjTDxlTLDvfFXHLe9 6a7wMof7WqLkdWe+eydzRvahKsrMuuSL4uQng6MksfQZJ8MiH4T4eYTCknvdG82yg/z2 pRTw== X-Gm-Message-State: APjAAAWGbi96/mpYp7qeZeJtwt5FCeisF/qtU0jXuhTrbD9ryEz90hSX mTfnb9S/krNg9DtopUElMQ8nFw== X-Google-Smtp-Source: APXvYqya+t/VhD0GIZflUZQ26GkCty6MeltN7KGb6H/Xahi+frxD8hl8EQVaSEgY0SyvPt7cNJxFUw== X-Received: by 2002:a63:5b23:: with SMTP id p35mr5755254pgb.366.1564647688896; Thu, 01 Aug 2019 01:21:28 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id t9sm65393089pgj.89.2019.08.01.01.21.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:28 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 44/47] ARM: 8595/2: apply more __ro_after_init Date: Thu, 1 Aug 2019 13:46:28 +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-20190801_012129_784292_3EB931BD X-CRM114-Status: GOOD ( 12.96 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Kees Cook Commit 7619751f8c900fa5fdd76db06f4caf095c56de8e upstream. Guided by grsecurity's analogous __read_only markings in arch/arm, this applies several uses of __ro_after_init to structures that are only updated during __init. Signed-off-by: Kees Cook Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/kernel/cpuidle.c | 2 +- arch/arm/kernel/setup.c | 10 +++++----- arch/arm/kernel/smp.c | 2 +- arch/arm/lib/delay.c | 2 +- arch/arm/mm/mmu.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/arm/kernel/cpuidle.c b/arch/arm/kernel/cpuidle.c index 318da33465f4..68be7d89141d 100644 --- a/arch/arm/kernel/cpuidle.c +++ b/arch/arm/kernel/cpuidle.c @@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel __used __section(__cpuidle_method_of_table_end); -static struct cpuidle_ops cpuidle_ops[NR_CPUS]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS] __ro_after_init; /** * arm_cpuidle_simple_enter() - a wrapper to cpu_do_idle() diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 13bda9574e18..8081f88bf636 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -112,19 +112,19 @@ EXPORT_SYMBOL(elf_hwcap2); #ifdef MULTI_CPU -struct processor processor __read_mostly; +struct processor processor __ro_after_init; #endif #ifdef MULTI_TLB -struct cpu_tlb_fns cpu_tlb __read_mostly; +struct cpu_tlb_fns cpu_tlb __ro_after_init; #endif #ifdef MULTI_USER -struct cpu_user_fns cpu_user __read_mostly; +struct cpu_user_fns cpu_user __ro_after_init; #endif #ifdef MULTI_CACHE -struct cpu_cache_fns cpu_cache __read_mostly; +struct cpu_cache_fns cpu_cache __ro_after_init; #endif #ifdef CONFIG_OUTER_CACHE -struct outer_cache_fns outer_cache __read_mostly; +struct outer_cache_fns outer_cache __ro_after_init; EXPORT_SYMBOL(outer_cache); #endif diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index bafbd29c6e64..c92abf791aed 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -79,7 +79,7 @@ enum ipi_msg_type { static DECLARE_COMPLETION(cpu_running); -static struct smp_operations smp_ops; +static struct smp_operations smp_ops __ro_after_init; void __init smp_set_ops(const struct smp_operations *ops) { diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c index 8044591dca72..2cef11884857 100644 --- a/arch/arm/lib/delay.c +++ b/arch/arm/lib/delay.c @@ -29,7 +29,7 @@ /* * Default to the loop-based delay implementation. */ -struct arm_delay_ops arm_delay_ops = { +struct arm_delay_ops arm_delay_ops __ro_after_init = { .delay = __loop_delay, .const_udelay = __loop_const_udelay, .udelay = __loop_udelay, diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index aead23f15213..36f8c033714f 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -243,7 +243,7 @@ __setup("noalign", noalign_setup); #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE -static struct mem_type mem_types[] = { +static struct mem_type mem_types[] __ro_after_init = { [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */ .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED | L_PTE_SHARED, From patchwork Thu Aug 1 08:16:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070353 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 B90791395 for ; Thu, 1 Aug 2019 08:28:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8B762839C for ; Thu, 1 Aug 2019 08:28:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A713283C3; Thu, 1 Aug 2019 08:28:57 +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 02BBF2839C for ; Thu, 1 Aug 2019 08:28:57 +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=BPwtMu79XW2ENYLbIXjhrizJBA/ChsEQDq/GE/573RM=; b=b4Wsc2HiBFZGZC 0aeM/akwkbtaD2KAmhm9kaqIPqszH+zLFY8oM1awJGd3pRcxFQ6pltbnsVA/G3hcy3BZdVcTeno3q qm3EQJePAcJfQvZE3Bedx8TWFkvq6HpqvBoDMD2MFB2t+1HAGGUmnLMQ9QtUDiZqgHgtND4uM/MGW oMTINn5TY1aVesQRIWaIJ5SNurE1uLi+/dRgC8I6p3ZItpwN4Ch9tTZki/+xdpWAsp7y7gn4tY/tj DtMW9Q8Wn+nQNHm8O7fyJgnqa7+xMR71bd05gF/dsXd5WnLvSTBvzMIIw1xFYMq7QVYHsHWkis96Y 7LLrGrz5HND7oNMa8+CA==; 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 1ht6SG-0006dR-Ch; Thu, 01 Aug 2019 08:28:56 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6L6-0003sU-QV for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:35 +0000 Received: by mail-pg1-x542.google.com with SMTP id x15so23388038pgg.8 for ; Thu, 01 Aug 2019 01:21:32 -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=H4B5LlN5Nm5PcO8sp/nxTYTyQFk96hnkKyUFVVoH87s=; b=MaUgCHGQ6ZRUCIQBTSvrIEWWynAHGTPU5ZoAItdNZxUBR+fcHgjURqzz8mfkt5vOZV nwKXcoMT3zfoLnhKb9m/DLhWqhy6YxYBG1PsyLVL7M/7dOLRGGYQNnkguMBWr2Bd+Q9j zGUL5cqCpYnb6FoTarylw4LsyauiexM1aY3KYMJBNnbMcsEAphLMikrYHYJbS+BwcZ+/ EJV/8X8e3LxZVxVT3qH9DJlEid6CYeNzbjM/OpBjasc7t78Zz/3VyPrvY7b31GAzKYZm Za9yZBFICuAxsXpzLrZ8Jke/6ClA8b/rzCMDJlJckDEg0HTigxBSrf+rVLfNKk8n7VOF 1FAw== 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=H4B5LlN5Nm5PcO8sp/nxTYTyQFk96hnkKyUFVVoH87s=; b=N1T0THVlH+PTJQqAT7DgEO+ffQ4Hcfuk3WL7vVjsZVySte/3aFmNHq9BEnSuKTlQbm bdxGO+AOLmVrMQu6WOGkOy0ObssHlmlnyFnN7zzRiaKocCZx8n+DorQOGNetHbXee76G KLDLmR9ZAp4TsCcXnx7WcCwJrRTas6zYcSM9YWZzJMLBluvju20bHHm/abicZ880Gzt4 VNa7n0s7vFBYBP52XuIOBAWQ5c9jUFd3+1xXqulBN0+8XztapNaCcP6LlX0Tut+VmU/q jb/UYFuoDbGfyODTT4uzwCpdH10xoVD58SNFo3DpUhcSt1LXerBhD4WmPvZQr+3/oFQr Fh9w== X-Gm-Message-State: APjAAAWtk2ZBl6bqCQv8lasJwHIB9ky21Pttdoi6rSmDxYNtPQExOsPR eIKCbPdI4JwEE2lj0cvQRZsNfQ== X-Google-Smtp-Source: APXvYqxnZ7OMaHuD/nP76IDF8rMpJRdMu13D7bhbobWFZxQo/5txj+CzUh/s5NjThhr/6LqaW93mfg== X-Received: by 2002:a65:64cf:: with SMTP id t15mr114291628pgv.88.1564647691566; Thu, 01 Aug 2019 01:21:31 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id k22sm76945297pfk.157.2019.08.01.01.21.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:31 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 45/47] ARM: spectre-v2: per-CPU vtables to work around big.Little systems Date: Thu, 1 Aug 2019 13:46:29 +0530 Message-Id: <06b369712f1c6cdb7358f245da8f641243750ccb.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012133_349171_553F5114 X-CRM114-Status: GOOD ( 16.25 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 383fb3ee8024d596f488d2dbaf45e572897acbdb upstream. In big.Little systems, some CPUs require the Spectre workarounds in paths such as the context switch, but other CPUs do not. In order to handle these differences, we need per-CPU vtables. We are unable to use the kernel's per-CPU variables to support this as per-CPU is not initialised at times when we need access to the vtables, so we have to use an array indexed by logical CPU number. We use an array-of-pointers to avoid having function pointers in the kernel's read/write .data section. Note: Added include of linux/slab.h in arch/arm/smp.c. Reviewed-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/proc-fns.h | 23 +++++++++++++++++++++++ arch/arm/kernel/setup.c | 5 +++++ arch/arm/kernel/smp.c | 32 ++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7-bugs.c | 17 ++--------------- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index a1a71b068edc..1bfcc3bcfc6d 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h @@ -104,12 +104,35 @@ extern void cpu_do_resume(void *); #else extern struct processor processor; +#if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) +#include +/* + * This can't be a per-cpu variable because we need to access it before + * per-cpu has been initialised. We have a couple of functions that are + * called in a pre-emptible context, and so can't use smp_processor_id() + * there, hence PROC_TABLE(). We insist in init_proc_vtable() that the + * function pointers for these are identical across all CPUs. + */ +extern struct processor *cpu_vtable[]; +#define PROC_VTABLE(f) cpu_vtable[smp_processor_id()]->f +#define PROC_TABLE(f) cpu_vtable[0]->f +static inline void init_proc_vtable(const struct processor *p) +{ + unsigned int cpu = smp_processor_id(); + *cpu_vtable[cpu] = *p; + WARN_ON_ONCE(cpu_vtable[cpu]->dcache_clean_area != + cpu_vtable[0]->dcache_clean_area); + WARN_ON_ONCE(cpu_vtable[cpu]->set_pte_ext != + cpu_vtable[0]->set_pte_ext); +} +#else #define PROC_VTABLE(f) processor.f #define PROC_TABLE(f) processor.f static inline void init_proc_vtable(const struct processor *p) { processor = *p; } +#endif #define cpu_proc_init PROC_VTABLE(_proc_init) #define cpu_check_bugs PROC_VTABLE(check_bugs) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 8081f88bf636..f2833d7c5378 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -113,6 +113,11 @@ EXPORT_SYMBOL(elf_hwcap2); #ifdef MULTI_CPU struct processor processor __ro_after_init; +#if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) +struct processor *cpu_vtable[NR_CPUS] = { + [0] = &processor, +}; +#endif #endif #ifdef MULTI_TLB struct cpu_tlb_fns cpu_tlb __ro_after_init; diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index c92abf791aed..03c11e021962 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +98,30 @@ static unsigned long get_arch_pgd(pgd_t *pgd) #endif } +#if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) +static int secondary_biglittle_prepare(unsigned int cpu) +{ + if (!cpu_vtable[cpu]) + cpu_vtable[cpu] = kzalloc(sizeof(*cpu_vtable[cpu]), GFP_KERNEL); + + return cpu_vtable[cpu] ? 0 : -ENOMEM; +} + +static void secondary_biglittle_init(void) +{ + init_proc_vtable(lookup_processor(read_cpuid_id())->proc); +} +#else +static int secondary_biglittle_prepare(unsigned int cpu) +{ + return 0; +} + +static void secondary_biglittle_init(void) +{ +} +#endif + int __cpu_up(unsigned int cpu, struct task_struct *idle) { int ret; @@ -103,6 +129,10 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) if (!smp_ops.smp_boot_secondary) return -ENOSYS; + ret = secondary_biglittle_prepare(cpu); + if (ret) + return ret; + /* * We need to tell the secondary core where to find * its stack and the page tables. @@ -354,6 +384,8 @@ asmlinkage void secondary_start_kernel(void) struct mm_struct *mm = &init_mm; unsigned int cpu; + secondary_biglittle_init(); + /* * The identity mapping is uncached (strongly ordered), so * switch away from it before attempting any exclusive accesses. diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c index 5544b82a2e7a..9a07916af8dd 100644 --- a/arch/arm/mm/proc-v7-bugs.c +++ b/arch/arm/mm/proc-v7-bugs.c @@ -52,8 +52,6 @@ static void cpu_v7_spectre_init(void) case ARM_CPU_PART_CORTEX_A17: case ARM_CPU_PART_CORTEX_A73: case ARM_CPU_PART_CORTEX_A75: - if (processor.switch_mm != cpu_v7_bpiall_switch_mm) - goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = harden_branch_predictor_bpiall; spectre_v2_method = "BPIALL"; @@ -61,8 +59,6 @@ static void cpu_v7_spectre_init(void) case ARM_CPU_PART_CORTEX_A15: case ARM_CPU_PART_BRAHMA_B15: - if (processor.switch_mm != cpu_v7_iciallu_switch_mm) - goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = harden_branch_predictor_iciallu; spectre_v2_method = "ICIALLU"; @@ -88,11 +84,9 @@ static void cpu_v7_spectre_init(void) ARM_SMCCC_ARCH_WORKAROUND_1, &res); if ((int)res.a0 != 0) break; - if (processor.switch_mm != cpu_v7_hvc_switch_mm && cpu) - goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = call_hvc_arch_workaround_1; - processor.switch_mm = cpu_v7_hvc_switch_mm; + cpu_do_switch_mm = cpu_v7_hvc_switch_mm; spectre_v2_method = "hypervisor"; break; @@ -101,11 +95,9 @@ static void cpu_v7_spectre_init(void) ARM_SMCCC_ARCH_WORKAROUND_1, &res); if ((int)res.a0 != 0) break; - if (processor.switch_mm != cpu_v7_smc_switch_mm && cpu) - goto bl_error; per_cpu(harden_branch_predictor_fn, cpu) = call_smc_arch_workaround_1; - processor.switch_mm = cpu_v7_smc_switch_mm; + cpu_do_switch_mm = cpu_v7_smc_switch_mm; spectre_v2_method = "firmware"; break; @@ -119,11 +111,6 @@ static void cpu_v7_spectre_init(void) if (spectre_v2_method) pr_info("CPU%u: Spectre v2: using %s workaround\n", smp_processor_id(), spectre_v2_method); - return; - -bl_error: - pr_err("CPU%u: Spectre v2: incorrect context switching function, system vulnerable\n", - cpu); } #else static void cpu_v7_spectre_init(void) From patchwork Thu Aug 1 08:16:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070351 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 CCF7E1395 for ; Thu, 1 Aug 2019 08:28:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE1BC283A6 for ; Thu, 1 Aug 2019 08:28:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B216C283C5; Thu, 1 Aug 2019 08:28:45 +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 3CE7C283A6 for ; Thu, 1 Aug 2019 08:28:45 +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=SXMLkbmZVFiK/rGV7YmOOUJSl4bcJ9/O6xIHf9QTBIo=; b=kdIaOxA8esutVA 6pz/7OvZ6k5XkI6NoatvR7yRuSLA3Auy2LvY5ulG3Gz9KxsY/XiqvyN5t/fefXtEfLsQhbsS2660L 1wSWW75wfQhMqRjxQhGEyaxu2w9luKgXLrBbaWbNb2zwWLS3kFGL6DEXMlOKoygS1Ps8RDkbJey40 ftisEaMZNgN0yoZvfo7JK6/V4ly1uiepynf5k5uOaXIfrcHXz818Slmhb8NNrBtczOOpfh4UtFn0+ atLDq6M/hNLGN/tDd0HQ8qbxLgpjwfOIQXcUX0YyS+3q/6YkEsrlvDKfGwa+quOgl5HrffHfwqaX6 EkAId/pKVE5K6k7xHDoQ==; 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 1ht6S4-0006Lx-MC; Thu, 01 Aug 2019 08:28:44 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6L9-0003uz-2p for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:36 +0000 Received: by mail-pg1-x542.google.com with SMTP id n9so27510828pgc.1 for ; Thu, 01 Aug 2019 01:21: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=VcM2nk9n3X98Yf/dvDVr4bULZaEs8I54Pvp1eUOtnUY=; b=wgago/zpfmyqQLLQdap7Xa8Uept+x1Qd1u033aMgpN9UcZ2k7xYDBKbb5+pAmTYGgD xC0edVXG08xxx5WF8v25YYSNhl7HmBj9YBcqUxBZKs17aXRlpwxG6PgS2mETq4g6D47P b/+wh1/eVUzBRinby/9SHWDbNCMO7HEhhQvRfOihSoqAuNP2z00/tm9PPpJqXaBngIua gUXFe57xxGWupNlan4xHj5ulZWnqY6FKmEJ00v+KbEbiHhP+rvhpjyEX1zjTqlJE75EW Iiyc2AY4u/qxd3536giEWMQrGCiPYXOZ0VVJbuqFv1J1Ws1noO/dSsWJolYOORmclwWU rPuw== 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=VcM2nk9n3X98Yf/dvDVr4bULZaEs8I54Pvp1eUOtnUY=; b=hNvQqV9QVTeu+O43qeSiSMyfpGrXe4QBboYQmd3R+LrHHaleQsYCzUDzVtMZxcHNhN DQkmZCPRjoNR12Vlqx8NtkiyAYr8cSmK0nUXO9IMIAijzp9tG3AxOwEINlD0V1J13Hu/ yBobTYoxeyCdmUCJat7sYD7KcwfKjDlkrtMioTNTLxzo4nO6X0k+9td0va6WraQHF4Zt bRXk1CA4qQbM3scoc11mA55KwleJ+FGcVxPeDuMZeNVNnWUxQ6mExBuJxEN9/Ag6s3e2 2XL9XBNeSsMJ2GUluXH4W+A/E4FBRhaIU33HcDcI7gefOuMod65fKVJ8s5byko1zMRMq EDBw== X-Gm-Message-State: APjAAAXeEI4RIEGdJRiyIBP6Ewwwh2Vaeb59UYEzUaz4Ho8Tk10S+8SW eE+1hvFnyzZ2qmOIamgU3t1xQg== X-Google-Smtp-Source: APXvYqz0smOXC/yRZCeLsmsqR+rYdReSDcJ5waTey1emtkemTksgldVG2ZffWaFMsTKpL11UnFLb9g== X-Received: by 2002:a17:90a:8a91:: with SMTP id x17mr7257741pjn.95.1564647694091; Thu, 01 Aug 2019 01:21:34 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id p19sm80677529pfn.99.2019.08.01.01.21.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:33 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 46/47] ARM: ensure that processor vtables is not lost after boot Date: Thu, 1 Aug 2019 13:46:30 +0530 Message-Id: <1292f4e03c65f4cfa4665df9c0e6f7fb8bd526cc.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012135_168442_847B1CEC X-CRM114-Status: GOOD ( 12.27 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit 3a4d0c2172bcf15b7a3d9d498b2b355f9864286b upstream. Marek Szyprowski reported problems with CPU hotplug in current kernels. This was tracked down to the processor vtables being located in an init section, and therefore discarded after kernel boot, despite being required after boot to properly initialise the non-boot CPUs. Arrange for these tables to end up in .rodata when required. Reported-by: Marek Szyprowski Tested-by: Krzysztof Kozlowski Fixes: 383fb3ee8024 ("ARM: spectre-v2: per-CPU vtables to work around big.Little systems") Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/mm/proc-macros.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S index 212147c78f4b..d36a283b4099 100644 --- a/arch/arm/mm/proc-macros.S +++ b/arch/arm/mm/proc-macros.S @@ -259,6 +259,13 @@ .endm .macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0, bugs=0 +/* + * If we are building for big.Little with branch predictor hardening, + * we need the processor function tables to remain available after boot. + */ +#if 1 // defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) + .section ".rodata" +#endif .type \name\()_processor_functions, #object .align 2 ENTRY(\name\()_processor_functions) @@ -294,6 +301,9 @@ ENTRY(\name\()_processor_functions) .endif .size \name\()_processor_functions, . - \name\()_processor_functions +#if 1 // defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) + .previous +#endif .endm .macro define_cache_functions name:req From patchwork Thu Aug 1 08:16:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070355 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 E94F813AC for ; Thu, 1 Aug 2019 08:29:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94772839C for ; Thu, 1 Aug 2019 08:29:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD4ED283C3; Thu, 1 Aug 2019 08:29:08 +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 793382839C for ; Thu, 1 Aug 2019 08:29:08 +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=Xw9+fP/sylsxrRS7pHjATKR7Xjgrj0rwMqSoD/ph9EE=; b=Hiq+o5qm8tKGF3 3BwyG9qrZDlFNDagI3Sc4RzddbWKDGDIJH+Y42RRZ3CjueWUgXA1PvsN4E4ybXgxn3AxUA2LLZeMt 3dSjfhe9alIGG7WAipTWoXpnrdBhyUwgSr/iuFfqMjQN5JaiqVV2ajdF1YLkoox3DrFZd8i2qWaec f4eJREhilRbS74nsBrFbKH3XzM0sb1a09QUVq9TJaU4e3Drs79zQAtvYpQJOo1P2QB33a7gnFyRus RclmBr4nDAxBm8Dqp7rdLH6ktKgEEafjo/QSwoCKsPrBu4nvkJMLjrLo64U2zDAb10hjM86/p1XtK sLM8DQf+jQXWI4N2eRow==; 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 1ht6SR-0006rz-Hb; Thu, 01 Aug 2019 08:29:07 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6LB-0003xo-8q for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:39 +0000 Received: by mail-pl1-x643.google.com with SMTP id y8so31877134plr.12 for ; Thu, 01 Aug 2019 01:21:37 -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=vRfP6jZwD5k91GsO2EtwWgU9vmyZBDy37/lZXGzi3aU=; b=uCU3Z3Dd1P1FIooMb8g3/Yirwuf5gsToAiV9JYhukWAquCpOpLJOBCMoG93ZDCjBIJ btZaaTRhQMPYjtnilwUJTPxmpmuOa4OSnVouxkTRriItjzbs/k59piXQ+dz0rue37I54 jWgdNzREAD+kvsjZ7QRuA9AOa7zA0MSwjYD1mwFv3fmmirUdTHnq5OC9tDAS3419s9pd +ifs9FqauXsMYjmTt38hWLWb1QTU5UJ0UTt6fYxxN/QGNDipHnlelXreXhCWDUMaVJVU 1I9iNOsaPNQUDjeRv12Z4tcolTbd3/T/jvKxcOy1d/3XVOBwmdPAitFxF3bblCPruDBv yYNQ== 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=vRfP6jZwD5k91GsO2EtwWgU9vmyZBDy37/lZXGzi3aU=; b=pnkgj8A/BgAzKJ88CZeGF2Yjf/n3R/dTlQ+Lsu8ZF/nRnif3aCWXE/GNwSELYJKvVl wZMyk9dhj3xpgl4+7JQyi2bbo+7vlYxqUQniCPpF1wxmnnGsRjNMf4V5i4M9k/SXSrY2 TgwHWw8gee13jRVOBGRM2yu65lDpW7K1uiYfvKQJYiAHF5QFW0fOFNfYWk5FhTf4Loxh OxPJX6CCmfXyzXeXMlTAPScTZ6ughirQiJ0o+wMVFd4d1oqHj6h5S1UnOSxGzbTw1X4E U3fLVLPk5WVI2ahZqbH897UU5761KDG/8RthBXzLbi4XZBC4KTIVXOhXLPWBeiAr6xog jIDw== X-Gm-Message-State: APjAAAUjQyPXKiEmRfgEeqenMf9g5TxhBj8SeVXGAwK2frahxMmiXpbc 1xI3dG2SrbDB4VCtH5cLxqM3hg== X-Google-Smtp-Source: APXvYqy3bdFxraBtYPacUshSMabHdK1w+qknRAhTGD8v1pvTWLe1HAEYxa1g5Dfr6tEWO/e9NGOV3A== X-Received: by 2002:a17:902:4b:: with SMTP id 69mr123879677pla.89.1564647696697; Thu, 01 Aug 2019 01:21:36 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id y194sm47248614pfg.116.2019.08.01.01.21.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:21:36 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 47/47] ARM: fix the cockup in the previous patch Date: Thu, 1 Aug 2019 13:46:31 +0530 Message-Id: <455094dcf249c379282166ebbb866fee091d8c9f.1564646727.git.viresh.kumar@linaro.org> 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-20190801_012137_360867_CB9D05ED X-CRM114-Status: GOOD ( 12.78 ) 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 , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Russell King Commit d6951f582cc50ba0ad22ef46b599740966599b14 upstream. The intention in the previous patch was to only place the processor tables in the .rodata section if big.Little was being built and we wanted the branch target hardening, but instead (due to the way it was tested) it ended up always placing the tables into the .rodata section. Although harmless, let's correct this anyway. Fixes: 3a4d0c2172bc ("ARM: ensure that processor vtables is not lost after boot") Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/mm/proc-macros.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S index d36a283b4099..e6bfdcc381f8 100644 --- a/arch/arm/mm/proc-macros.S +++ b/arch/arm/mm/proc-macros.S @@ -263,7 +263,7 @@ * If we are building for big.Little with branch predictor hardening, * we need the processor function tables to remain available after boot. */ -#if 1 // defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) +#if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) .section ".rodata" #endif .type \name\()_processor_functions, #object @@ -301,7 +301,7 @@ ENTRY(\name\()_processor_functions) .endif .size \name\()_processor_functions, . - \name\()_processor_functions -#if 1 // defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) +#if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) .previous #endif .endm