Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1382154imm; Tue, 10 Jul 2018 00:25:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeYH7cb3Cmi7ai7idQ365Abtz+7XGf3Mt1W8s8lRrK4T6xnAhRdrjQGSRGls5zqWt4H/C8I X-Received: by 2002:a62:e0d5:: with SMTP id d82-v6mr24386316pfm.59.1531207529835; Tue, 10 Jul 2018 00:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531207529; cv=none; d=google.com; s=arc-20160816; b=IxUocMJojRbrw0DGal/67SsZUnJArjWNDbVmIoUbQuSTkffNtl2O9oytJbSuoycrak E03sM9l1SXRPtIUtI92DTCu4pgea8yvqCq7/Q1ufu6NLvBh2swy2pJcMu8WAoS17aeiE qHd/KXYL3GurJqXb88G9XFmOJSKBJpQc0RMKT7WPOB5ckIA3w4fyU6ai1I3+IiQNHsC1 Rmupa7Of8GIJv4V2nDpemprk2z84x86fJZqP/VrUEB0mK/I2aU+aL//oYXytPes7lPmQ AR1eLmANf55bcK90kiWKmMdaOGOKm+fcKLrCAmxX2xhX5t2aUNa6jkF3cy0AnWZSxZiI nZDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:arc-authentication-results; bh=d8CU79KHEK5N028rdN55yi9l3syBS8qhN8JVv4bV7qc=; b=Bx0x85ZhxG4m5gxfD2F3UEq0FKcW1CBm/Jt7guaOqroBzn27XCb+/7Bx0chnfZOhX8 LgG2UuKgVbYG8gkf+OUwGm6g/lXG3ubMcbC/Fdcv2FYlqbU5PI10RV7Yd2hQNScjkaMB 3zggB1Kpl1f3ggR8onlaih1XnBspoLeAl+QqL3R0A0mmxpQNuKV1ovGM5IVgewlFkYjp LZlf8Q4QeuMDFWzpeO2sHgvPUHRGnv7DQnf+8H6XLPu3PmO0WFvWptaNzr66EEGXMp3t 0A6fXtfwA13dzV7PQNKTKwl473ln3zN3zU7bCXHkaRi6Dv4nEWLPdCbXt5vhh6TUKlCT wKmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=Mz5ZarAb; 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 q65-v6si15715058pga.283.2018.07.10.00.25.14; Tue, 10 Jul 2018 00:25:29 -0700 (PDT) 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=@agner.ch header.s=dkim header.b=Mz5ZarAb; 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 S1751201AbeGJHYf (ORCPT + 99 others); Tue, 10 Jul 2018 03:24:35 -0400 Received: from mail.kmu-office.ch ([178.209.48.109]:57230 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751053AbeGJHYe (ORCPT ); Tue, 10 Jul 2018 03:24:34 -0400 Received: from webmail.kmu-office.ch (unknown [IPv6:2a02:418:6a02::a3]) by mail.kmu-office.ch (Postfix) with ESMTPSA id E33F45C01B2; Tue, 10 Jul 2018 09:24:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1531207472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d8CU79KHEK5N028rdN55yi9l3syBS8qhN8JVv4bV7qc=; b=Mz5ZarAbT3TLyZDt/QssetfQiU4EJwi2YNALPKW3FGCvTFijtBIaMMAnj1AlZwjcHzVSSt nN45RdSLWFOoJhxaumdI8wcA50Km8ekeiaV+dXxOxZ8AHy60UgoXF/SCtKH9FGMCxUtOU0 /unI/dA1H9OOWhEkax40bhA7gb3QHco= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Tue, 10 Jul 2018 09:24:32 +0200 From: Stefan Agner To: Steven Rostedt Cc: LKML , linux-arm-kernel@lists.infradead.org, Russell King - ARM Linux , abelvesa@linux.com, Abhishek Sagar , Ingo Molnar Subject: Re: [PATCH] ARM: ftrace: Only set kernel memory back to read-only after boot In-Reply-To: <7aa5a479aa484775f492dc5251bcf5c9@agner.ch> References: <20180621124710.453ee0ae@gandalf.local.home> <7aa5a479aa484775f492dc5251bcf5c9@agner.ch> Message-ID: X-Sender: stefan@agner.ch User-Agent: Roundcube Webmail/1.3.4 X-Spamd-Result: default: False [-2.96 / 15.00]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; ASN(0.00)[asn:29691, ipnet:2a02:418::/29, country:CH]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-2.86)[99.42%]; ARC_NA(0.00)[] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04.07.2018 13:30, Stefan Agner wrote: > On 21.06.2018 18:47, Steven Rostedt wrote: >> From: Steven Rostedt (VMware) >> >> Dynamic ftrace requires modifying the code segments that are usually >> set to read-only. To do this, a per arch function is called both before >> and after the ftrace modifications are performed. The "before" function >> will set kernel code text to read-write to allow for ftrace to make the >> modifications, and the "after" function will set the kernel code text >> back to "read-only" to keep the kernel code text protected. >> >> The issue happens when dynamic ftrace is tested at boot up. The test is >> done before the kernel code text has been set to read-only. But the >> "before" and "after" calls are still performed. The "after" call will >> change the kernel code text to read-only prematurely, and other boot >> code that expects this code to be read-write will fail. >> >> The solution is to add a variable that is set when the kernel code text >> is expected to be converted to read-only, and make the ftrace "before" >> and "after" calls do nothing if that variable is not yet set. This is >> similar to the x86 solution from commit 162396309745 ("ftrace, x86: >> make kernel text writable only for conversions"). >> >> Reported-by: Stefan Agner >> Tested-by: Stefan Agner >> Link: http://lkml.kernel.org/r/20180620212906.24b7b66e@vmware.local.home >> Signed-off-by: Steven Rostedt (VMware) >> --- >> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c >> index c186474422f3..0cc8e04295a4 100644 >> --- a/arch/arm/mm/init.c >> +++ b/arch/arm/mm/init.c > > I guess this can be seen as reviewed? > > Patches touching core ARM port usually go through Russels patch tracker. > > You have to submit the patch here: > http://www.armlinux.org.uk/developer/patches/ > FWIW, I added this patch to the patch tracker, its patch ID is 8780/1. -- Stefan > > >> @@ -736,20 +736,29 @@ static int __mark_rodata_ro(void *unused) >> return 0; >> } >> >> +static int kernel_set_to_readonly __read_mostly; >> + >> void mark_rodata_ro(void) >> { >> + kernel_set_to_readonly = 1; >> stop_machine(__mark_rodata_ro, NULL, NULL); >> debug_checkwx(); >> } >> >> void set_kernel_text_rw(void) >> { >> + if (!kernel_set_to_readonly) >> + return; >> + >> set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), false, >> current->active_mm); >> } >> >> void set_kernel_text_ro(void) >> { >> + if (!kernel_set_to_readonly) >> + return; >> + >> set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true, >> current->active_mm); >> }