Received: by 10.223.185.116 with SMTP id b49csp2314080wrg; Thu, 15 Feb 2018 09:41:16 -0800 (PST) X-Google-Smtp-Source: AH8x224m4WT3w5L+4FS3vE3DDacPOP8qlppJxsqZhsEZ6XndOZEGDHg8ODP8q2A1e6ntDfKpSt7M X-Received: by 2002:a17:902:930a:: with SMTP id bc10-v6mr3272534plb.19.1518716476737; Thu, 15 Feb 2018 09:41:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518716476; cv=none; d=google.com; s=arc-20160816; b=Nk5ltj/3aESUyY4GLYjA6wPJ7WqrsrTAthDYgMf2l4bVQc8jC+xSiL0RuJcOi+jyE9 DZqeP8Ek/mRJ9uY4Hi1bXD3dkoeKRToAaBADJ+LzEzwAIQBa013fww6nXpyCuFubx2SR segqEw05bSIKEFoGyk3GEhg8NvMvnSv33HLuN2c4u3s+cGs3N+lveqMZ4GQnXFgs9bGA aIAnhNxv4l3kuJ2kecurth9u3me/g+db73qJ0bTZlfEDLC/ETVfJMEe1sdfkHQdz/bTG EF9kR/ZDMxuTS51e/U3RPzZgNtCq0DOuzG8PTTGojLAv+uJc8CWiCYX0gHEP5oQxlzZF F2Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JglXPR99GwD/CtNGRA8KQMnh5M5iLF5IrrjKTJAY6+s=; b=D7DR8mWXTtDXYjibA9+aUgl6K0QdNSgSN3lxxxf4Ivhdva7o7ozE828lZxevPYh6UE MUeDOghQ83tMwxFBvlYKh267GqGQB2PljNA1uJwrl0g9OdU2KHVg6OF7EXTAMAB64IXN iOK2QuKh+OAB+i9nnnsfEsyJwpSV5h00VpK7waraJOS5sxmPx1FSE8xjH04FZP6wSNQJ +W5LHwHXVSPeCpvVKk4i/olukh/SEp5RVTirNQvQnz1Cm6n/phKU3NwUmBiZ+P9XTU61 oaZ2Oa+PstmJLw8nsY/XrHR538mklJFhvFY9Fa6zN8UwWkPpdrJYFj6fNfhs/cd3B6u0 +PGg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i22-v6si2880473pll.212.2018.02.15.09.41.01; Thu, 15 Feb 2018 09:41:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1164687AbeBOPcp (ORCPT + 99 others); Thu, 15 Feb 2018 10:32:45 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:56518 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164637AbeBOPcm (ORCPT ); Thu, 15 Feb 2018 10:32:42 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 60535F97; Thu, 15 Feb 2018 15:32:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Marc Zyngier , Catalin Marinas , Ard Biesheuvel Subject: [PATCH 4.14 071/195] [Variant 2/Spectre-v2] arm64: Move BP hardening to check_and_switch_context Date: Thu, 15 Feb 2018 16:16:02 +0100 Message-Id: <20180215151709.252824917@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- arch/arm64/mm/context.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -227,6 +227,9 @@ void check_and_switch_context(struct mm_ raw_spin_unlock_irqrestore(&cpu_asid_lock, flags); switch_mm_fastpath: + + arm64_apply_bp_hardening(); + /* * Defer TTBR0_EL1 setting for user threads to uaccess_enable() when * emulating PAN. @@ -242,8 +245,6 @@ asmlinkage void post_ttbr_update_workaro "ic iallu; dsb nsh; isb", ARM64_WORKAROUND_CAVIUM_27456, CONFIG_CAVIUM_ERRATUM_27456)); - - arm64_apply_bp_hardening(); } static int asids_init(void)