Received: by 10.223.185.116 with SMTP id b49csp7394661wrg; Thu, 1 Mar 2018 05:00:44 -0800 (PST) X-Google-Smtp-Source: AG47ELthZ0qN1miVMFIUoV7zv99nBTK+5ZBHsFMV4ZB8MGvaO0Q5niJcYLk6E8zRm0UWc3jwA8A0 X-Received: by 2002:a17:902:968e:: with SMTP id n14-v6mr1888923plp.21.1519909243929; Thu, 01 Mar 2018 05:00:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909243; cv=none; d=google.com; s=arc-20160816; b=atJEvckiYaFhOLvgnjM+eFX6LIkXuo6TaCra/yjjR3TUQF4Sn7DolvPl5TlWZCvwSw tK7X0/HFTAHwc4vcVff9UAaKRI87upMt1usg1I4x5hJutJUANozbkDr/D3Z9pd7TtHh0 JkTq/afL4To4SL9aCdozO0fAIx1i626GtHCGtRidU2t4YmhF5wclDN/FGf1k/jsJitVu MsyWievl7RhNUWYLPbrOTQfVpwpStYM1gCz0hsa2rX3hrG5ttaXdzn/pO0rfp0J2dCmy jXZ02FJM+4YtNEAm+vtSB1PTADRltbSFtNtpOkQPt7+sCDGoZ8qKOasfcXHfOHuTuNId 0oTQ== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=YTi+3EgVxwTxApY3ucUH/g1LD9enZczbL8ouc6EbVOA=; b=TCovxmcR8up70SCjA7IjlV3iYTOBZKqFU7PuuOjoiqFXIo0tR3Hu4M5Y7OvqTEyslF Cv3MvI9KAG2me8KoVzSgbwoTNoW/vyufUwV36fVDpQAQwQ3eKNvaTQQYZ7dzlFa3DdwS T4TtYpZQrDdDFuBvLtmXTQQBFTErLWht6dnUQKhWRSqEdxVjDg/gcduU6W78keMTdLPU lkTvgzvALPFie/8n05zbza1fMNiLL3im6QhQ9ACcaBKf7sN3MEBA0gJxxeVHvSkJjack squxh1PSFlpBhJpdz5pxcpK7dsiX9EJP/lFtv7P7kriqLSyLa8m11hQ4Jk8AvTNP6aGT XuQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YOD8Yuf8; 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 k128si2450899pgc.609.2018.03.01.05.00.28; Thu, 01 Mar 2018 05:00:43 -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=YOD8Yuf8; 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 S1030954AbeCAM64 (ORCPT + 99 others); Thu, 1 Mar 2018 07:58:56 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:36317 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030753AbeCAM6r (ORCPT ); Thu, 1 Mar 2018 07:58:47 -0500 Received: by mail-pl0-f65.google.com with SMTP id 61-v6so3597205plf.3 for ; Thu, 01 Mar 2018 04:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YTi+3EgVxwTxApY3ucUH/g1LD9enZczbL8ouc6EbVOA=; b=YOD8Yuf8Eht7WwsO2JikzfyCrD/zUq3mDMabSjHjiBmlZ7LEMeNgKyqNYRMTppc499 AKj8idWMxjeL7qN6Oo9fxNE8q7JAJdy0toCtrOanbS47W/vuAcgTaf9VCKVL27przxMd QeVDBxPnK9PsrR3SzNx+ME1pZBJfYGjrS1q+Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YTi+3EgVxwTxApY3ucUH/g1LD9enZczbL8ouc6EbVOA=; b=NQluhonxdhagYkkqTmOgJgruCgWL3CGl/M/Bdpb4RVydDdknidrrj2dg32wlp7CVqm +QmeRPBnjJmAg96GQO6UPPVUwn2iBXj34krJ5xLCNPQve8rHEU0+OzfVZAyApE2WqVGz QhAhdvptP8O9IK+sNXm9k/gAgW8oXqxEWMEoiAKy35SGAuMN5cbyWTOpqHXjdBm0lMVF xdH3aEiNxYeXeJir1QsLyAQk31/Nry70ohc7TGzq636jrJZwhU2uIAwFszS/cshXBoH2 F5o+EaoVIV3G/w3R+oljXEfQSHU1HXjZmTi3eCZtC5ZtylgLMfpEcuhuA19xD3UvhrYd LoHA== X-Gm-Message-State: APf1xPC8seGTCJLHwWfSadyVnXKxAglrtfKftz11viCs3ahy5n48rS2Q cQAVjjQp4S4+A+2/OPIJzh+wfg== X-Received: by 2002:a17:902:f44:: with SMTP id 62-v6mr1819010ply.27.1519909126862; Thu, 01 Mar 2018 04:58:46 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:58:46 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 24/45] arm64: Move BP hardening to check_and_switch_context Date: Thu, 1 Mar 2018 20:54:01 +0800 Message-Id: <1519908862-11425-25-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> 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 --- 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