Re: [PATCH] kernel/trace: Add TRACING_ALLOW_PRINTK config option

Nicolas Boichat
2020-06-25T01:13:50Z

On Wed, Jun 24, 2020 at 9:57 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Wed, Jun 24, 2020 at 04:45:24PM +0800, Nicolas Boichat wrote:
> > trace_printk is only meant as a debugging tool, and should never be
> > compiled into production code without source code changes, as
> > indicated by the warning that shows up on boot if any trace_printk
> > is called:
> > ** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **
> > ** **
> > ** trace_printk() being used. Allocating extra memory. **
> > ** **
> > ** This means that this is a DEBUG kernel and it is **
> > ** unsafe for production use. **
> >
> > If this option is set to n, the kernel will generate a build-time
> > error if trace_printk is used.
> >
> > Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
> > include/linux/kernel.h | 17 ++++++++++++++++-
> > kernel/trace/Kconfig | 9 +++++++++
> > 2 files changed, 25 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> > index 196607aaf653082..b6addc6ba669e85 100644
> > +++ b/include/linux/kernel.h
> > @@ -721,10 +721,15 @@ do { \
> > #define trace_printk(fmt, ...) \
> > do { \
> > char _______STR[] = __stringify((__VA_ARGS__)); \
> > + \
> > + __static_assert( \
> > + IS_ENABLED(CONFIG_TRACING_ALLOW_PRINTK),\
> > + "trace_printk called, please enable CONFIG_TRACING_ALLOW_PRINTK."); \
> > + \
>
> Why __static_assert not normal static_assert?

Oh, I misread the macro code (and didn't read the comment above in
include/linux/build_bug.h). static_assert would be just fine.

>
> Jason