From patchwork Thu Jun 21 01:29:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 10478925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AAFCB60365 for ; Thu, 21 Jun 2018 01:29:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92A5928D9C for ; Thu, 21 Jun 2018 01:29:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7665628DA4; Thu, 21 Jun 2018 01:29:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE64B28D9C for ; Thu, 21 Jun 2018 01:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MhTjYvpRKIqq6GtfEpztsoEa3dE67fvbbuFffPyjeCs=; b=eP8OmPG5guSGRE cTnpbnyHxldy4SUUIsy8/juu+JZNtKVK5vyxVBL2FLNvuuXWiIRJlKG7MlwFma79rNE80Z+W1I9lg YTZAWI6kHLCBwxVHBNWjQXhaqcLFMWtwOFhHhvndgF68BqUNrh7gPVAnCZ9OQKODlqg56ZAdONghe BMyezWPkyL45x/4FEOA8aWrFtlNuUCn75tW2G53aJqrrRcGG1b6FlVYCryN+5RpRijWNQFQQUzikn 08Bk3SfP9v6aip9kWmnTG3GrMl1v6oH+Ky4NgKcC7OnN3Pkqpe6k9Wf+z7uGSri3awpcu+mvlCJia YjzIjION+FcGfdC4Me0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVoPa-0003xl-Jl; Thu, 21 Jun 2018 01:29:22 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVoPX-0003x8-9Y for linux-arm-kernel@lists.infradead.org; Thu, 21 Jun 2018 01:29:20 +0000 Received: from vmware.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (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 B115420693; Thu, 21 Jun 2018 01:29:07 +0000 (UTC) Date: Wed, 20 Jun 2018 21:29:06 -0400 From: Steven Rostedt To: Russell King - ARM Linux Subject: Re: Dynamic ftrace self test broken on ARM Message-ID: <20180620212906.24b7b66e@vmware.local.home> In-Reply-To: <20180620230734.GO17671@n2100.armlinux.org.uk> References: <65fb14b356bc0a414f1fe5cf5c6eb395@agner.ch> <20180618175437.3e6c85a1@gandalf.local.home> <20180619091735.7aec75d0@gandalf.local.home> <5e26cebbb2ebeb87fdc808509881736b@agner.ch> <20180620101311.0bcd73d3@gandalf.local.home> <7904ed3fe9f59a54526d64f366915b43@agner.ch> <20180620230734.GO17671@n2100.armlinux.org.uk> X-Mailer: Claws Mail 3.15.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180620_182919_371316_3190711E X-CRM114-Status: GOOD ( 13.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rabin@rab.in, Abhishek Sagar , Stefan Agner , abelvesa@linux.com, mingo@redhat.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 21 Jun 2018 00:07:34 +0100 Russell King - ARM Linux wrote: > > Any input from ARM folks? > > The same issues must exist on other architectures as ARM is not the only > architecture to implement read-only kernel text and dynamic ftrace, so > surely this problem isn't unique to ARM. Probably because of the way set_kernel_text_ro() is implemented in other archs. For example, in x86, we have: void set_kernel_text_ro(void) { unsigned long start = PFN_ALIGN(_text); unsigned long end = PFN_ALIGN(__stop___ex_table); if (!kernel_set_to_readonly) return; /* * Set the kernel identity mapping for text RO. */ set_memory_ro(start, (end - start) >> PAGE_SHIFT); } and arm has: void set_kernel_text_ro(void) { set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true, current->active_mm); } Where x86's set_kernel_text_ro() is a nop until the kernel_set_to_readonly is set. Perhaps this may fix things? [ Not even compiled tested ] -- Steve Reviewed-by: Stefan Agner Tested-by: Stefan Agner 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 @@ -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); }