From patchwork Thu Mar 1 12:54:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130203 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2763250edc; Thu, 1 Mar 2018 04:59:00 -0800 (PST) X-Google-Smtp-Source: AG47ELvNDWP1bFNPknXk2NCedpmeKEazWS4uXzCH224RVe262ARfoXdgeLLphi5p4HsUod3I3anP X-Received: by 2002:a17:902:8289:: with SMTP id y9-v6mr1866365pln.242.1519909139946; Thu, 01 Mar 2018 04:58:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909139; cv=none; d=google.com; s=arc-20160816; b=uF8f4g1eE/950eCaceLNfjtOmAEcETf3DGAMOKloG+gvA4B1Ic4jU/xPnUru/bN2du 2Y77mdFK4a9glHlvyr6vlyutU6ZlGfUIURjEH67S+yJ36eaBUxpGSFQfGk3gkXNaFB/n sytc5IpVihmvNy13CGgVx3oQZuQdgEe5ZF3ldUkM/SCg1BbPCTYShYtFeSABvIWkn+Un SKRfUky9eMJ8z+0PKFRitguB/Pgb1CExOEvtFQiXc6dVYW1maZZmSUVOqfXQJl+AmC9u IQ3ERMv648tm5JsEfaSsGB8oyfd7J7dJweDWNTFwrVCU0Y5+8wXy2L1wWWJKr1OI46SU oIIQ== 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 m10si2472888pgs.236.2018.03.01.04.58.59; Thu, 01 Mar 2018 04:58:59 -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 S1030957AbeCAM64 (ORCPT + 28 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(-) -- 2.7.4 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)