Re: [PATCH -tip 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure

From: Uros Bizjak
Date: Sun Dec 03 2023 - 17:50:08 EST


On Sun, Dec 3, 2023 at 11:19 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Mon, 4 Dec 2023 at 07:12, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> >
> > +/*
> > + * The generic per-cpu infrastrucutre is not suitable for
> > + * reading const-qualified variables.
> > + */
> > +#define this_cpu_read_const(pcp) ({ BUG(); (typeof(pcp))0; })
>
> NAK. Absolutely not.
>
> No way in hell is it acceptable to make this a run-time BUG. If it
> doesn't work, it needs to be a compile failure. End of story.

Thanks - BUILD_BUG() also works here and is indeed more appropriate:

/**
* BUILD_BUG - break compile if used.
*
* If you have some code that you expect the compiler to eliminate at
* build time, you should use BUILD_BUG to detect if it is
* unexpectedly used.
*/

v2 is in testing.

Thanks,
Uros.