gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
Subsystems (2)
PATCH 1/1 gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
Commit 36d4b36b6959 ("lib/nodemask: inline next_node_in() and node_random()") refactored some code by moving node_random() from lib/nodemask.c to include/linux/nodemask.h, thus requiring nodemask.h to include random.h, which conditionally defines add_latent_entropy() depending on whether the macro LATENT_ENTROPY_PLUGIN is defined.
This broke the build on powerpc, where nodemask.h is indirectly included in arch/powerpc/kernel/prom_init.c, part of the early boot machinery that is excluded from the latent entropy plugin using DISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag to disable the actual plugin, we don't undefine LATENT_ENTROPY_PLUGIN.
This leads to the following:
CC arch/powerpc/kernel/prom_init.o
In file included from ./include/linux/nodemask.h:97,
from ./include/linux/mmzone.h:17,
from ./include/linux/gfp.h:7,
from ./include/linux/xarray.h:15,
from ./include/linux/radix-tree.h:21,
from ./include/linux/idr.h:15,
from ./include/linux/kernfs.h:12,
from ./include/linux/sysfs.h:16,
from ./include/linux/kobject.h:20,
from ./include/linux/pci.h:35,
from arch/powerpc/kernel/prom_init.c:24:
./include/linux/random.h: In function 'add_latent_entropy':
./include/linux/random.h:25:46: error: 'latent_entropy' undeclared (first use in this function); did you mean 'add_latent_entropy'?
25 | add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
| ^~~~~~~~~~~~~~
| add_latent_entropy ./include/linux/random.h:25:46: note: each undeclared identifier is reported only once for each function it appears in make[2]: *** [scripts/Makefile.build:249: arch/powerpc/kernel/prom_init.o] Fehler 1
make[1]: *** [scripts/Makefile.build:465: arch/powerpc/kernel] Fehler 2
make: *** [Makefile:1855: arch/powerpc] Error 2
Change the DISABLE_LATENT_ENTROPY_PLUGIN flags to undefine LATENT_ENTROPY_PLUGIN for files where the plugin is disabled.
--- scripts/Makefile.gcc-plugins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.gcc-plugins +1 -1
@@ -4,7 +4,7 @@ gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) \ += -DLATENT_ENTROPY_PLUGIN ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY - DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable + DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable -ULATENT_ENTROPY_PLUGIN endif export DISABLE_LATENT_ENTROPY_PLUGIN
Signature · 1 line
2.30.2
Quoted 12 lines · Andrew Donnellan
Commit
36d4b36b6959("lib/nodemask: inlinenext_node_in()andnode_random()") refactored some code by movingnode_random()fromlib/nodemask.ctoinclude/linux/nodemask.h, thus requiringnodemask.hto includerandom.h, which conditionally definesadd_latent_entropy()depending on whether the macroLATENT_ENTROPY_PLUGINis defined.This broke the build on powerpc, where
nodemask.his indirectly included inarch/powerpc/kernel/prom_init.c, part of the early boot machinery that is excluded from the latent entropy plugin usingDISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag to disable the actual plugin, we don't undefineLATENT_ENTROPY_PLUGIN.
Quoted 7 lines
This leads to the following:
CC
arch/powerpc/kernel/prom_init.o
In file included from./include/linux/nodemask.h:97,from ./include/linux/mmzone.h:17, from ./include/linux/gfp.h:7, from ./include/linux/xarray.h:15,
As a side note, xarray can go with gfp_types.h instead of gfp.h
Quoted 17 lines
from ./include/linux/radix-tree.h:21, from ./include/linux/idr.h:15, from ./include/linux/kernfs.h:12, from ./include/linux/sysfs.h:16, from ./include/linux/kobject.h:20, from ./include/linux/pci.h:35, from arch/powerpc/kernel/prom_init.c:24: ./include/linux/random.h: In function 'add_latent_entropy': ./include/linux/random.h:25:46: error: 'latent_entropy' undeclared (first use in this function); did you mean 'add_latent_entropy'? 25 | add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy)); | ^~~~~~~~~~~~~~ | add_latent_entropy
./include/linux/random.h:25:46: note: each undeclared identifier is reported only once for each function it appears in make[2]: *** [scripts/Makefile.build:249:arch/powerpc/kernel/prom_init.o] Fehler 1
make[1]: *** [scripts/Makefile.build:465:arch/powerpc/kernel] Fehler 2
make: *** [Makefile:1855:arch/powerpc] Error 2
Quoted 6 lines
Change the
DISABLE_LATENT_ENTROPY_PLUGINflags to undefineLATENT_ENTROPY_PLUGINfor files where the plugin is disabled.Cc Yury Norov <[email protected]>Cc Emese Revfy <[email protected]>Fixes 36d4b36b6959 ("lib/nodemask: inline next_node_in() and node_random()")
I think it rather fixes 38addce8b600ca33 ("gcc-plugins: Add latent_entropy plugin").
For the rest,
Quoted 23 lines
Reported-by Erhard Furtner <[email protected]>Signed-off-by Andrew Donnellan <[email protected]>--- scripts/Makefile.gcc-plugins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.gcc-plugins +1
-1@@ -4,7 +4,7 @@ gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) \ += -DLATENT_ENTROPY_PLUGIN ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY - DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable + DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable -ULATENT_ENTROPY_PLUGIN endif export DISABLE_LATENT_ENTROPY_PLUGINSignature · 1 line
2.30.2
Quoted 20 lines · Yury Norov
Quoted 19 lines · Andrew Donnellan
Commit
36d4b36b6959("lib/nodemask: inlinenext_node_in()andnode_random()") refactored some code by movingnode_random()fromlib/nodemask.ctoinclude/linux/nodemask.h, thus requiringnodemask.hto
includerandom.h, which conditionally definesadd_latent_entropy()depending on whether the macroLATENT_ENTROPY_PLUGINis defined.This broke the build on powerpc, where
nodemask.his indirectly included
inarch/powerpc/kernel/prom_init.c, part of the early boot machinery that
is excluded from the latent entropy plugin usingDISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag
to disable the actual plugin, we don't undefineLATENT_ENTROPY_PLUGIN.This leads to the following:
Quoted 7 lines
Quoted 5 lines
CC
arch/powerpc/kernel/prom_init.oIn file included from./include/linux/nodemask.h:97, from./include/linux/mmzone.h:17, from./include/linux/gfp.h:7, from./include/linux/xarray.h:15,As a side note, xarray can go with
gfp_types.hinstead ofgfp.h
Indeed, I just saw your patch to fix this.
Quoted 6 lines
Quoted 3 lines
Fixes 36d4b36b6959 ("lib/nodemask: inline next_node_in() and
node_random()")I think it rather fixes
38addce8b600ca33("gcc-plugins: Addlatent_entropyplugin").
You're right, I was in a rush and should have tagged that appropriately.
Quoted 3 lines
For the rest,
Reviewed-by Yury Norov <[email protected]>
Thanks!
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Kees Cook
AppliedQuoted 6 lines · Andrew Donnellan
Commit
36d4b36b6959("lib/nodemask: inlinenext_node_in()andnode_random()") refactored some code by movingnode_random()fromlib/nodemask.ctoinclude/linux/nodemask.h, thus requiringnodemask.hto includerandom.h, which conditionally definesadd_latent_entropy()depending on whether the macroLATENT_ENTROPY_PLUGINis defined.
Quoted 7 lines
This broke the build on powerpc, where
nodemask.his indirectly included inarch/powerpc/kernel/prom_init.c, part of the early boot machinery that is excluded from the latent entropy plugin usingDISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag to disable the actual plugin, we don't undefineLATENT_ENTROPY_PLUGIN.[...]
Applied to for-next/hardening, thanks!
[1/1] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
https://git.kernel.org/kees/c/2d08c71d2c79
Signature · 1 line
Kees Cook
Quoted 6 lines · Kees Cook
Applied to for-next/hardening, thanks!
[1/1] gcc-plugins: Undefine
LATENT_ENTROPY_PLUGINwhen plugin disabled for a file
https://git.kernel.org/kees/c/2d08c71d2c79
Thanks Kees!
Can we make sure this lands in rc2?
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited