From: Ingo Molnar <mingo@kernel.org>
To: Mathias Krause <minipli@googlemail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Joe Perches <joe@perches.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCHv3 0/9] Mark literal strings in __init / __exit code
Date: Thu, 21 Aug 2014 14:57:17 +0200 [thread overview]
Message-ID: <20140821125717.GA28987@gmail.com> (raw)
In-Reply-To: <1408623792-7973-1-git-send-email-minipli@googlemail.com>
* Mathias Krause <minipli@googlemail.com> wrote:
> This is v3 of the patch series initially posted here:
>
> https://lkml.org/lkml/2014/6/22/149
>
> This series tries to address the problem of dangling strings of __init
> functions after initialization, as well as __exit strings for code not
> even included in the final kernel image. The code might get freed, but
> the format strings are not, as they're in the wrong section.
>
> One solution to the problem might be to declare variables in the code
> and mark those variables as __initconst. That, though, makes the code
> ugly, as can be seen, e.g., in drivers/hwmon/w83627ehf.c -- a pile of
> 'static const char[] __initconst' lines just for the pr_info() call.
>
> To be able to mark strings easily patch 1 adds macros to init.h to do so
> without the need to explicitly define variables in the code. (Internally
> it'll declare ones nonetheless, as this seem to be the only way to
> attach an __attribute__() to a verbatim string.) That's already enough to
> solve the problem -- mark the corresponding stings by using these
> macros. But patch 2 adds some syntactical sugar for the most popular use
> case, by providing pr_<level> alike macros, namely pi_<level> for __init
> code and pe_<level> for __exit code. This hides the use of the marker
> macros behind the commonly known printing functions -- with just a
> single character changed. For code that cannot be changed to use the
> pi_<level>() / pe_<level>() helpers printk_init() and printk_exit()
> macros are provided, too.
>
> The (hidden) variables used in the macros of patch 1 will pollute the
> kernel's symbol table with unneeded entries. It'll be a problem in the
> KALLSYMS_ALL case only, however, patch 3 takes care of filtering the
> pseudo symbols. They have no value for us beside being the only way to
> attach an __attribute__ to a string literal.
>
> If users of the new macros get it wrong, e.g. use printk_init() /
> pi_<level>() in non-init code or vice versa printk_exit() / pe_<level>()
> in non-exit code, modpost will detect the error as a section mismatch
> and report it accordingly. Still, the message printed by modpost with
> CONFIG_DEBUG_SECTION_MISMATCH=y is rather confusing as the __initconst /
> __exitdata annotation is hidden behind the macros. That's what patch 4
> takes care of -- detecting such cases and providing better modpost
> messages, guiding the user on how to fix the error.
>
> The remaining patches (5 to 9) exemplarily change strings and format
> strings in a selection of files under arch/x86/ to use the new macros.
> They also address a few styling issues, e.g., patches 4 and 5 are
> cleanup patches I stumbled across while changing the corresponding code
> to make use of the new pi_*() helpers. The changes to arch/x86/ already
> lead to moving ~3kb of memory from .rodata to .init.rodata. This should
> free up a page after init on almost any x86 system.
>
> To show that there's actual more value to it: A hacked up script, dully
> changing pr_<level> to pi_<level> for __init functions under arch/x86/
> is able to move ~8kB of r/o data into the .init section (partly already
> covered by the patches of this series). The script, though, is dump. It
> does not handle any of the printk() calls, nor does it handle panic()
> calls or other strings used only in initialization code. So there's more
> to squeeze out.
It feels like a burdensome hack that kernel developers are
forced to use different printing facilities, depending on the
life cycle of a method. We want to simplify init annotations,
we don't want to complicate them!
Why isn't this problem solved transparently at build time, via
tooling, instead of burdening developers? If a particular
string is only used by an init (or exit) function, it can be
moved to an init section without forcing the developer to
declare it as such.
And if tooling isn't ready for this, then wouldn't the right
solution be to improve tooling - instead of complicating the
kernel?
Thanks,
Ingo
next prev parent reply other threads:[~2014-08-21 12:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-21 12:23 [PATCHv3 0/9] Mark literal strings in __init / __exit code Mathias Krause
2014-08-21 12:23 ` [PATCHv3 1/9] init.h: Add __init_str / __exit_str macros Mathias Krause
2014-08-21 12:23 ` [PATCHv3 2/9] printk: Provide pi_<level> / pe_<level> macros for __init / __exit code Mathias Krause
2014-08-21 12:23 ` [PATCHv3 3/9] kallsyms: exclude pseudo symbols for __init / __exit strings Mathias Krause
2014-08-21 12:23 ` [PATCHv3 4/9] modpost: provide better diagnostics " Mathias Krause
2014-08-21 12:23 ` [PATCHv3 5/9] x86, acpi: Mark __init strings as such Mathias Krause
2014-08-21 12:23 ` [PATCHv3 6/9] x86, mm: Make x86_init.memory_setup() return a const char * Mathias Krause
2014-08-21 12:23 ` [PATCHv3 7/9] x86, mm: early_panic() - pass on the message as string Mathias Krause
2014-08-21 12:23 ` [PATCHv3 8/9] x86, mm: e820 - mark __init strings as such Mathias Krause
2014-08-21 12:23 ` [PATCHv3 9/9] x86: setup " Mathias Krause
2014-08-21 12:57 ` Ingo Molnar [this message]
2014-08-21 14:29 ` [PATCHv3 0/9] Mark literal strings in __init / __exit code Mathias Krause
2014-08-22 8:24 ` Ingo Molnar
2014-08-30 15:28 ` Mathias Krause
2014-09-16 8:57 ` Ingo Molnar
2014-08-21 16:25 ` Sam Ravnborg
2014-08-24 16:04 ` Mathias Krause
2014-08-24 16:28 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140821125717.GA28987@gmail.com \
--to=mingo@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mingo@redhat.com \
--cc=minipli@googlemail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox