Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp292059imu; Tue, 27 Nov 2018 12:29:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/WXFndYYMB62CBpAiR7ZJtNtVasQckk1iBQDkElEyIHB+EYOLKWce5e9HinnRgxBTHJZ+Qe X-Received: by 2002:a17:902:b701:: with SMTP id d1-v6mr32289049pls.29.1543350575904; Tue, 27 Nov 2018 12:29:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543350575; cv=none; d=google.com; s=arc-20160816; b=tZXdtzb/BZNK5CpnRy9FwaKIfTKuLW4blg/vqDLB+IdFhCwuWJTlfF+KtS0lRWZcC3 MqAQ8jmWdLcd/DFhcOtgWTc244yL8KLLwtd8tTI/BLSP7J/4rr3FaGncBJcYXH0rovCt YyPJk9lJ9C1XPtd0bbRkYrrtYs0pgLb1J9YdIGNgNQYE12hjPlVAeoG0b2GbNg2DGlcu UhjURPsiI4BKJVFvWFY6iVqhXqXhdw60fb4pq2q355rbWXU2cSdUyzPCCAqFbBhhgK+u eQvZcSk5H3kQ9WN88bHtCPmhO26Sol6k29ssnJDLpN/ZFqAihSJRpy8otgUEqsAbFi49 gOmQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject; bh=p5JtdRFMeSJotHjsPsjpArCrNHhqCG5X4BDA6e58JKo=; b=YjmJask3BbDZitrblhHS2GV3poM4MwZykphuCfEIn8oiEvDwnPmdm0Bt2i7GYXejyg aGVla/fJRBTjaHWecDdLFk0ZERm4kjoGgQCNEZJItoPUaQJp/DH1IqBq91XpGPdV0xqQ 5V0Tr/tazlVut9D545lAWrSHQGOGM9YL602TbYAZhDEGO0ukP8U3mog2Z+4xXaWOLcev qgRS16ERAaqwjxSsQuLup4SX3cg0ZPfNZefKlHnYARFCxouDbT3N5GUbKfqqu++LHNNn Lx538ppwN6Aj/OKWra0cgKGjQQM9/nw4fEbHg/vKrevf5Z9cMbv4Y+ZJI0cKI4EoySJA biRg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si4603325ply.74.2018.11.27.12.29.20; Tue, 27 Nov 2018 12:29:35 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbeK1H0U (ORCPT + 99 others); Wed, 28 Nov 2018 02:26:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33778 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725752AbeK1H0T (ORCPT ); Wed, 28 Nov 2018 02:26:19 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FDAE7F6B0; Tue, 27 Nov 2018 20:27:15 +0000 (UTC) Received: from jlaw-desktop.bos.csb (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0725260C45; Tue, 27 Nov 2018 20:27:14 +0000 (UTC) Subject: Re: [RFC PATCH 0/1] support ftrace and -ffunction-sections From: Joe Lawrence To: linux-kernel@vger.kernel.org Cc: Steven Rostedt , Masahiro Yamada References: <1542745158-25392-1-git-send-email-joe.lawrence@redhat.com> Organization: Red Hat Message-ID: Date: Tue, 27 Nov 2018 15:27:14 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <1542745158-25392-1-git-send-email-joe.lawrence@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 27 Nov 2018 20:27:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/20/2018 03:19 PM, Joe Lawrence wrote: > Hi Steve, > > I noticed that ftrace does not currently support functions built with > the -ffunction-sections option as they end up in .text. > ELF sections, never making into the __mcount_loc section. > > I modified the recordmcount scripts to handle such .text. section > prefixes and this appears to work on x86_64, ppc64le, and s390x -- at > least for simple modules, including the "Test trace_printk from module" > ftrace self-test. > > That said, I did notice 90ad4052e85c ("kbuild: avoid conflict between > -ffunction-sections and -pg on gcc-4.7") which indicates that the kernel > still supports versions of gcc which may not play well with ftrace and > -ffunction-sections. > > With that limitation in mind, can we support ftracing of functions in > such sections for compiler versions that do support it? (fwiw, gcc > v4.8.5 seems happy) And then if so, what additional testing or coding > would need to be done to be confident that it is safe? Is matching on > ".text.*" too inclusive? > Gentle ping... I took a dive through the rhkl-archives and found a few older discussions: [PATCH] scripts/recordmcount.pl: Support build with -ffunction-sections. https://lore.kernel.org/lkml/CAFbHwiRtBaHkpZqTm6VZ=fCJcyu+dsdpo_kxMHy1egce=rTuyA@mail.gmail.com/ and related LWN article: The source of the e1000e corruption bug https://lwn.net/Articles/304105/ Catching up with those, I assume that this has never been implemented in the past due to fear of ftrace modifying a potentially freed section (and bricking NICs in the process :( Looking through the kernel sources (like Will in 2008) I don't see any code jumping out at me that frees code other than .init. However a quick code inspection is no guarantee. Assuming the same use-after-free reservation holds true today: 1: Is there any reasonable way to mark code sections (pages?) as in-use to avoid memory freeing mechanisms from releasing them? The logic for .init is mostly arch-specific, so there could be many different ways random arches may try to pull this off. 2: Would/could it be safer to restrict __mcount_loc detection of ".text.*" sections to modules? The recordmcount.pl script already knows about is_module... that information could be provided to recordmcount.c as well for consideration. -- Joe