All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	John Ogness <john.ogness@linutronix.de>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kees Cook <keescook@chromium.org>,
	kernel-team@fb.com
Subject: Re: [PATCH v5] printk: Userspace format enumeration support
Date: Tue, 16 Mar 2021 14:28:12 +0000	[thread overview]
Message-ID: <YFDAfPCnS204jiD5@chrisdown.name> (raw)
In-Reply-To: <02c3b2f3-ff8e-ceb9-b30b-e533959c0491@rasmusvillemoes.dk>

Rasmus Villemoes writes:
>I think it's pointless renaming the symbol to _printk, with all the
>churn and reduced readability that involves (especially when reading
>assembly "why are we calling _printk and not printk here?"). There's
>nothing wrong with providing a macro wrapper by the same name
>
>#define printk(bla bla) ({ do_stuff; printk(bla bla); })
>
>Only two places would need to be updated to surround the word printk in
>parentheses to suppress macro expansion: The declaration and the
>definition of printk. I.e.
>
>int (printk)(const char *s, ...)

Hmm, I'm indifferent to either. Personally I don't like the ambiguity of having 
both a macro and function share the same name and having to think "what's the 
preprocessor context here?".

>> +extern struct pi_object __start_printk_index[];
>> +extern struct pi_object __stop_printk_index[];
>
>Do you need these declarations to be visible to the whole kernel? Can't
>they live in printk/index.c?

Yeah, this is a leftover: already noted for rescoping in v6. :-)

>> +
>> +#define pi_sec_elf_embed(_p_func, _fmt, ...)				       \
>> +	({								       \
>> +		int _p_ret;						       \
>> +									       \
>> +		if (__builtin_constant_p(_fmt)) {			       \
>> +			/*
>> +			 * The compiler may not be able to eliminate this, so
>> +			 * we need to make sure that it doesn't see any
>> +			 * hypothetical assignment for non-constants even
>> +			 * though this is already inside the
>> +			 * __builtin_constant_p guard.
>> +			 */						       \
>> +			static struct pi_object _pi			       \
>
>static const struct pi_object?
>
>> +			__section(".printk_index") = {			       \
>> +				.fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
>> +				.func = __func__,			       \
>> +				.file = __FILE__,			       \
>> +				.line = __LINE__,			       \
>> +			};						       \
>> +			_p_ret = _p_func(_pi.fmt, ##__VA_ARGS__);	       \
>
>Is the use of _pi.fmt here a trick to prevent gcc from eliding the _pi
>object, so it is seen as "used"? That seems a bit fragile, especially if
>the compiler ends up generating the same code in .text - that means gcc
>does not load the format string from the _pi object (which it
>shouldn't), but then I don't see why it (or the next version of gcc)
>couldn't realize that _pi is indeed unused.
>
>There's the __used attribute precisely for this kind of thing. Then you
>could also eliminate
>
>> +		} else							       \
>> +			_p_ret = _p_func(_fmt, ##__VA_ARGS__);		       \
>> +									       \
>
>this and the _p_ret variable
>
>> +		_p_ret;							       \
>
>and just end the ({}) with _p_func(_fmt, ##__VA_ARGS__);

Oh, this is a leftover from the early days of the patch when we used to 
explicitly store the formats in ._printk_fmts in order to avoid duplication. 
Now that we just store a pointer instead of storing the format itself, it 
probably should be fine to move to using _fmt directly and __used. Thanks, I'll 
investigate this for v6.

  reply	other threads:[~2021-03-16 14:29 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10  2:30 [PATCH v5] printk: Userspace format enumeration support Chris Down
2021-03-10  6:20 ` kernel test robot
2021-03-10  6:20   ` kernel test robot
2021-03-10  6:50 ` Greg Kroah-Hartman
2021-03-10 12:12   ` Chris Down
2021-03-10 12:16     ` Greg Kroah-Hartman
2021-03-11  9:34       ` Petr Mladek
2021-03-11  9:43         ` Greg Kroah-Hartman
2021-03-10 12:17 ` Chris Down
2021-03-11  9:20   ` Petr Mladek
2021-03-10 12:31 ` kernel test robot
2021-03-10 12:31   ` kernel test robot
2021-03-12 11:14 ` Petr Mladek
2021-03-12 13:53   ` Chris Down
2021-03-15 10:02     ` Petr Mladek
2021-03-15 12:20       ` Chris Down
2021-03-16 11:39         ` Petr Mladek
2021-03-16 13:27           ` Chris Down
2021-03-16 14:12 ` Rasmus Villemoes
2021-03-16 14:28   ` Chris Down [this message]
2021-03-17  8:40     ` Petr Mladek
2021-03-17 10:03       ` Rasmus Villemoes
2021-03-18 10:46         ` Petr Mladek
2021-03-18 11:31           ` Rasmus Villemoes
2021-03-19 11:43             ` Petr Mladek
2021-04-16 13:56           ` Chris Down
2021-04-16 14:09             ` Joe Perches
2021-04-16 14:29               ` Chris Down
2021-04-19  7:27             ` Rasmus Villemoes
2021-04-19  9:16               ` Petr Mladek
2021-04-19  9:53                 ` Greg Kroah-Hartman
2021-04-19 11:02                   ` Joe Perches
2021-04-21 13:14               ` Chris Down
2021-04-22 12:36                 ` Joe Perches
2021-04-22 14:59                   ` Chris Down

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=YFDAfPCnS204jiD5@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=john.ogness@linutronix.de \
    --cc=keescook@chromium.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.