Received: by 10.223.185.116 with SMTP id b49csp3489108wrg; Mon, 26 Feb 2018 00:25:28 -0800 (PST) X-Google-Smtp-Source: AH8x224yoTo2MhazFJrtYKmAhMZVCqTYKMNGk13OCkl9cTbtgOG3Cjiq7FdC2Ces6Tw+lkJGrGF/ X-Received: by 10.98.149.90 with SMTP id p87mr9760530pfd.28.1519633528459; Mon, 26 Feb 2018 00:25:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633528; cv=none; d=google.com; s=arc-20160816; b=CtCOV3STd2mV0VSHsxgPoMRGrfGwryvi57L6h9Yiqc4nUNi6DW+UgBrIGXMazd7B69 Q/ctdpIcCh5b8YMtQcawwPpMYQqW9S0E9N2MC0RjH9ZyWXFcRiNzQ8FN7tB5ZJRjb4UK w8jNEC48T3dSL5wKF8e/BUsntQRyoAPiO77ve5fbw4jInNBf4JnvV0oynJXbmKt8sxxu YD+0iDzhSHirSZnfYC2N+ZshQTX6se4/mXg/MHNqYHktiEFvbEOZW3Tuz+MJ2f4qnCHj TzfHfjCJ87YEmLc11z9C2522Z/8eDhD9/3mdqXZYgvo5aeWlKyeyVW4tKGI/q6vLPyac UyPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=i1j7Y/8yxFvtha7QKxycJLsEJDbrUtAASAguHbCEvfE=; b=om8gLYkY3+HI3kH62izikZwHQ3Fjk+oZm1t2j+GRB77Nv5GYXmyCZrx4iJvSrRrrij EJSDG4+oTCsxkkCKzf5aoyiQtVXxglDV1eM9IkFZOTmJuExI0FoYt99E4n7XfbMxH3zC texWZlGbm6OkVAjMHWzpNEe2ZuUoAseUanVdQ5zLRnVkFIn8Gff00D+ad9e0fquMC6qw fIvnMuu5MftwwRGZQrIxnmjF3q2srNWOUdwfXyjZBFVIQY98+0KaVh7glFres54++oLD UDmZCB38qsRBc5c6uUCzTxYKHbtqr1cqPupe25bAEXfr1p4kfwRb91iZlCOnl2kEmbfd QFWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CEJiCbWl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f31-v6si6455327plb.636.2018.02.26.00.25.14; Mon, 26 Feb 2018 00:25:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CEJiCbWl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752576AbeBZIYE (ORCPT + 99 others); Mon, 26 Feb 2018 03:24:04 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:40637 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752558AbeBZIYA (ORCPT ); Mon, 26 Feb 2018 03:24:00 -0500 Received: by mail-pl0-f66.google.com with SMTP id i6so8867570plt.7 for ; Mon, 26 Feb 2018 00:24:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=i1j7Y/8yxFvtha7QKxycJLsEJDbrUtAASAguHbCEvfE=; b=CEJiCbWleySP5jLeh92MpVfuwucYcYtIqYEyq+tq/WZTWIrLSmxxBwsx74HHR2IRQI As4BwTeF+xm+NE7vklxC9XWkSvjwRZqmL/IafolLCeHMEZ2ivDMDiagMG/mMaD2piZ2f N571MwRlH3Qj5k9k2SxMmuDIxo1FYSlbR8830= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=i1j7Y/8yxFvtha7QKxycJLsEJDbrUtAASAguHbCEvfE=; b=ETgxPqvAiWlig5h6VZgMRN3ounmUoNFzkdgcRM+5lL7+4y1Rc3ghtVTvKrh354w2eo KDhZAv0f4ogKD3SK4ywK0DBF5piyv7lbOMFvo1jTybSrJg1fFsNzfNHRk6rPuNkmcLNo NBVbIO6jM+/TdCnfgDWPy9zu8k4wVl4WLF2pSk9zcrfupXT7/lC1BKl8ZDZiLDZQi+Mn dr/7BYtnhpKBDlS8vKatBVPD/jl8FSlHG1l1E5F+M0IDHv+XTcbTzrBgD6Nbay6akXQ/ FYXTaCuXbnbEfhJStkdYLWXZARvvqlDfzjlcdHU7TDUDxxu93sZw1gmMI+E8sbfEq04t VB9g== X-Gm-Message-State: APf1xPDx39NyUO/DwIdjOAYV1u6em/FPEKXvgarJrOmMmdnFETW9iwAk 3uRACesLbCprcFWzl1h6MzWuKw== X-Received: by 2002:a17:902:3341:: with SMTP id a59-v6mr4855144plc.20.1519633439665; Mon, 26 Feb 2018 00:23:59 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.23.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:23:59 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 24/52] arm64: Move BP hardening to check_and_switch_context Date: Mon, 26 Feb 2018 16:19:58 +0800 Message-Id: <1519633227-29832-25-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit a8e4c0a919ae upstream. We call arm64_apply_bp_hardening() from post_ttbr_update_workaround, which has the unexpected consequence of being triggered on every exception return to userspace when ARM64_SW_TTBR0_PAN is selected, even if no context switch actually occured. This is a bit suboptimal, and it would be more logical to only invalidate the branch predictor when we actually switch to a different mm. In order to solve this, move the call to arm64_apply_bp_hardening() into check_and_switch_context(), where we're guaranteed to pick a different mm context. Acked-by: Will Deacon Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: no sw pan in arch/arm64/mm/context.c --- arch/arm64/mm/context.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index afc9266..36416e4 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -221,6 +221,7 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu) raw_spin_unlock_irqrestore(&cpu_asid_lock, flags); switch_mm_fastpath: + arm64_apply_bp_hardening(); cpu_switch_mm(mm->pgd, mm); } @@ -231,8 +232,6 @@ asmlinkage void post_ttbr_update_workaround(void) "ic iallu; dsb nsh; isb", ARM64_WORKAROUND_CAVIUM_27456, CONFIG_CAVIUM_ERRATUM_27456)); - - arm64_apply_bp_hardening(); } static int asids_init(void) -- 2.7.4