Skip to content

Commit c7ff693

Browse files
petrpavlumcgrof
authored andcommitted
module: Split modules_install compression and in-kernel decompression
The kernel configuration allows specifying a module compression mode. If one is selected then each module gets compressed during 'make modules_install' and additionally one can also enable support for a respective direct in-kernel decompression support. This means that the decompression support cannot be enabled without the automatic compression. Some distributions, such as the (open)SUSE family, use a signer service for modules. A build runs on a worker machine but signing is done by a separate locked-down server that is in possession of the signing key. The build invokes 'make modules_install' to create a modules tree, collects information about the modules, asks the signer service for their signature, appends each signature to the respective module and compresses all modules. When using this arrangment, the 'make modules_install' step produces unsigned+uncompressed modules and the distribution's own build recipe takes care of signing and compression later. The signing support can be currently enabled without automatically signing modules during 'make modules_install'. However, the in-kernel decompression support can be selected only after first enabling automatic compression during this step. To allow only enabling the in-kernel decompression support without the automatic compression during 'make modules_install', separate the compression options similarly to the signing options, as follows: > Enable loadable module support [*] Module compression Module compression type (GZIP) ---> [*] Automatically compress all modules [ ] Support in-kernel module decompression * "Module compression" (MODULE_COMPRESS) is a new main switch for the compression/decompression support. It replaces MODULE_COMPRESS_NONE. * "Module compression type" (MODULE_COMPRESS_<type>) chooses the compression type, one of GZ, XZ, ZSTD. * "Automatically compress all modules" (MODULE_COMPRESS_ALL) is a new option to enable module compression during 'make modules_install'. It defaults to Y. * "Support in-kernel module decompression" (MODULE_DECOMPRESS) enables in-kernel decompression. Signed-off-by: Petr Pavlu <[email protected]> Acked-by: Masahiro Yamada <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 47ac09b commit c7ff693

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

kernel/module/Kconfig

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -278,64 +278,65 @@ config MODULE_SIG_HASH
278278
default "sha3-384" if MODULE_SIG_SHA3_384
279279
default "sha3-512" if MODULE_SIG_SHA3_512
280280

281-
choice
282-
prompt "Module compression mode"
281+
config MODULE_COMPRESS
282+
bool "Module compression"
283283
help
284-
This option allows you to choose the algorithm which will be used to
285-
compress modules when 'make modules_install' is run. (or, you can
286-
choose to not compress modules at all.)
287-
288-
External modules will also be compressed in the same way during the
289-
installation.
290-
291-
For modules inside an initrd or initramfs, it's more efficient to
292-
compress the whole initrd or initramfs instead.
293-
284+
Enable module compression to reduce on-disk size of module binaries.
294285
This is fully compatible with signed modules.
295286

296-
Please note that the tool used to load modules needs to support the
297-
corresponding algorithm. module-init-tools MAY support gzip, and kmod
298-
MAY support gzip, xz and zstd.
287+
The tool used to work with modules needs to support the selected
288+
compression type. kmod MAY support gzip, xz and zstd. Other tools
289+
might have a limited selection of the supported types.
299290

300-
Your build system needs to provide the appropriate compression tool
301-
to compress the modules.
291+
Note that for modules inside an initrd or initramfs, it's more
292+
efficient to compress the whole ramdisk instead.
302293

303-
If in doubt, select 'None'.
294+
If unsure, say N.
304295

305-
config MODULE_COMPRESS_NONE
306-
bool "None"
296+
choice
297+
prompt "Module compression type"
298+
depends on MODULE_COMPRESS
307299
help
308-
Do not compress modules. The installed modules are suffixed
309-
with .ko.
300+
Choose the supported algorithm for module compression.
310301

311302
config MODULE_COMPRESS_GZIP
312303
bool "GZIP"
313304
help
314-
Compress modules with GZIP. The installed modules are suffixed
315-
with .ko.gz.
305+
Support modules compressed with GZIP. The installed modules are
306+
suffixed with .ko.gz.
316307

317308
config MODULE_COMPRESS_XZ
318309
bool "XZ"
319310
help
320-
Compress modules with XZ. The installed modules are suffixed
321-
with .ko.xz.
311+
Support modules compressed with XZ. The installed modules are
312+
suffixed with .ko.xz.
322313

323314
config MODULE_COMPRESS_ZSTD
324315
bool "ZSTD"
325316
help
326-
Compress modules with ZSTD. The installed modules are suffixed
327-
with .ko.zst.
317+
Support modules compressed with ZSTD. The installed modules are
318+
suffixed with .ko.zst.
328319

329320
endchoice
330321

322+
config MODULE_COMPRESS_ALL
323+
bool "Automatically compress all modules"
324+
default y
325+
depends on MODULE_COMPRESS
326+
help
327+
Compress all modules during 'make modules_install'.
328+
329+
Your build system needs to provide the appropriate compression tool
330+
for the selected compression type. External modules will also be
331+
compressed in the same way during the installation.
332+
331333
config MODULE_DECOMPRESS
332334
bool "Support in-kernel module decompression"
333-
depends on MODULE_COMPRESS_GZIP || MODULE_COMPRESS_XZ || MODULE_COMPRESS_ZSTD
335+
depends on MODULE_COMPRESS
334336
select ZLIB_INFLATE if MODULE_COMPRESS_GZIP
335337
select XZ_DEC if MODULE_COMPRESS_XZ
336338
select ZSTD_DECOMPRESS if MODULE_COMPRESS_ZSTD
337339
help
338-
339340
Support for decompressing kernel modules by the kernel itself
340341
instead of relying on userspace to perform this task. Useful when
341342
load pinning security policy is enabled.

scripts/Makefile.modinst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ $(foreach x, % :, $(if $(findstring $x, $(dst)), \
5151
$(error module installation path cannot contain '$x')))
5252

5353
suffix-y :=
54+
ifdef CONFIG_MODULE_COMPRESS_ALL
5455
suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
5556
suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
5657
suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
58+
endif
5759

5860
modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
5961
install-$(CONFIG_MODULES) += $(modules)

0 commit comments

Comments
 (0)