Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4492615ybx; Mon, 4 Nov 2019 14:19:17 -0800 (PST) X-Google-Smtp-Source: APXvYqwuX2UrO1UjbLddAeF9vEAMWn53H5ecYDeXMaHI0SjdK6CJBdJ1eHHiugZK/MW/8ZLEjBK2 X-Received: by 2002:a50:f783:: with SMTP id h3mr32160351edn.294.1572905957182; Mon, 04 Nov 2019 14:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905957; cv=none; d=google.com; s=arc-20160816; b=FbB1QRY/HJCjy2Atto6/mWFL4zQyVyJWJFs50ZFq46R6Z1P8yeIuLMLUKTlRAuiC+n fFp8ju4O4oQVeeG9/smDBE6wGWbKj3yACSxn147YnfIh7gkTppoHtg5uKqazkKBRzJkm dkZhu+36MEfXrh28YkWR4D7r4StZpvq85fovFpKZ+M5zv/c9F49/H9oSYKUXLINFKY8w eSqsRoQ18xxhz+x9CZcf/3NNgQAhTAfWYo4dRAVDumivU4g+vvrDWBVHCKn7byXj00+h jYIXZRLeFe9iHsaLSyhbRhPM/6Vqq0TQivCTUNFIKv16gY7WyVbReq+Qv+AKFUc/SPof 72KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ywbMQeaYvf12+qc0axHlXMxXhSFDBpMdZvCgGK1fKV4=; b=WEs9xgwUA0a2LuJfwcdSVuV6sYCc1Y864lvu22IivAlj42a15mH7Cyvnl9OBl79k0c LvsDWlFU6ATwENdlphsRIg//16rVTqyf1nWy27bn/HYGBTSBb4C7JfEhD+kWE0gb3ymC RVVpK3p+/stZSWnLHacKFZRy9XP+M4b06kiT1zAXUKRuWqeOV5hOyUxV3NXeG7S5a3LR EFusarkBk4UypqgcSSeTzPTKGic/EckMkav9l1BbghgD/5InTaTBTgi04s4dGsyn9qEM ZR7RgqnYSCvdS9JYPGMf+k/YEkF3iTTCxFehicvq9VL3lsMkhGB/V1pGdVzEZAoP0i9x JNxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZaqydWIB; 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 a60si8849815edf.169.2019.11.04.14.18.40; Mon, 04 Nov 2019 14:19:17 -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=@kernel.org header.s=default header.b=ZaqydWIB; 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 S2389807AbfKDWFL (ORCPT + 99 others); Mon, 4 Nov 2019 17:05:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:36332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389801AbfKDWFJ (ORCPT ); Mon, 4 Nov 2019 17:05:09 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B121421E6F; Mon, 4 Nov 2019 22:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905108; bh=KDouM1x/ZhUC/AxhtbM10VlvxvdYU4eTIV21usld9RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZaqydWIBqUX3JD1O8kMnKc96N+185Hc/sk8ZFYmhCi4PaigzrNh2G1y0iS5KXBArT p9tUV4cQGmllF18nHLx9OiBodJvudfH3wOZZBRnmGN6cFhp1OmPUUy19huFjjWYSUT qlsUyEGiIW5EvOEgg2d2cfpcONem2fobs/cfHNC0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Morse , Will Deacon , Sasha Levin Subject: [PATCH 5.3 031/163] arm64: ftrace: Ensure synchronisation in PLT setup for Neoverse-N1 #1542419 Date: Mon, 4 Nov 2019 22:43:41 +0100 Message-Id: <20191104212142.544193256@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Morse [ Upstream commit dd8a1f13488438c6c220b7cafa500baaf21a6e53 ] CPUs affected by Neoverse-N1 #1542419 may execute a stale instruction if it was recently modified. The affected sequence requires freshly written instructions to be executable before a branch to them is updated. There are very few places in the kernel that modify executable text, all but one come with sufficient synchronisation: * The module loader's flush_module_icache() calls flush_icache_range(), which does a kick_all_cpus_sync() * bpf_int_jit_compile() calls flush_icache_range(). * Kprobes calls aarch64_insn_patch_text(), which does its work in stop_machine(). * static keys and ftrace both patch between nops and branches to existing kernel code (not generated code). The affected sequence is the interaction between ftrace and modules. The module PLT is cleaned using __flush_icache_range() as the trampoline shouldn't be executable until we update the branch to it. Drop the double-underscore so that this path runs kick_all_cpus_sync() too. Signed-off-by: James Morse Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/ftrace.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index 1717732579742..06e56b4703153 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -121,10 +121,16 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) /* * Ensure updated trampoline is visible to instruction - * fetch before we patch in the branch. + * fetch before we patch in the branch. Although the + * architecture doesn't require an IPI in this case, + * Neoverse-N1 erratum #1542419 does require one + * if the TLB maintenance in module_enable_ro() is + * skipped due to rodata_enabled. It doesn't seem worth + * it to make it conditional given that this is + * certainly not a fast-path. */ - __flush_icache_range((unsigned long)&dst[0], - (unsigned long)&dst[1]); + flush_icache_range((unsigned long)&dst[0], + (unsigned long)&dst[1]); } addr = (unsigned long)dst; #else /* CONFIG_ARM64_MODULE_PLTS */ -- 2.20.1