Skip to content

Commit b6a7828

Browse files
committed
Merge tag 'modules-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux
Pull module updates from Luis Chamberlain: "The summary of the changes for this pull requests is: - Song Liu's new struct module_memory replacement - Nick Alcock's MODULE_LICENSE() removal for non-modules - My cleanups and enhancements to reduce the areas where we vmalloc module memory for duplicates, and the respective debug code which proves the remaining vmalloc pressure comes from userspace. Most of the changes have been in linux-next for quite some time except the minor fixes I made to check if a module was already loaded prior to allocating the final module memory with vmalloc and the respective debug code it introduces to help clarify the issue. Although the functional change is small it is rather safe as it can only *help* reduce vmalloc space for duplicates and is confirmed to fix a bootup issue with over 400 CPUs with KASAN enabled. I don't expect stable kernels to pick up that fix as the cleanups would have also had to have been picked up. Folks on larger CPU systems with modules will want to just upgrade if vmalloc space has been an issue on bootup. Given the size of this request, here's some more elaborate details: The functional change change in this pull request is the very first patch from Song Liu which replaces the 'struct module_layout' with a new 'struct module_memory'. The old data structure tried to put together all types of supported module memory types in one data structure, the new one abstracts the differences in memory types in a module to allow each one to provide their own set of details. This paves the way in the future so we can deal with them in a cleaner way. If you look at changes they also provide a nice cleanup of how we handle these different memory areas in a module. This change has been in linux-next since before the merge window opened for v6.3 so to provide more than a full kernel cycle of testing. It's a good thing as quite a bit of fixes have been found for it. Jason Baron then made dynamic debug a first class citizen module user by using module notifier callbacks to allocate / remove module specific dynamic debug information. Nick Alcock has done quite a bit of work cross-tree to remove module license tags from things which cannot possibly be module at my request so to: a) help him with his longer term tooling goals which require a deterministic evaluation if a piece a symbol code could ever be part of a module or not. But quite recently it is has been made clear that tooling is not the only one that would benefit. Disambiguating symbols also helps efforts such as live patching, kprobes and BPF, but for other reasons and R&D on this area is active with no clear solution in sight. b) help us inch closer to the now generally accepted long term goal of automating all the MODULE_LICENSE() tags from SPDX license tags In so far as a) is concerned, although module license tags are a no-op for non-modules, tools which would want create a mapping of possible modules can only rely on the module license tag after the commit 8b41fc4 ("kbuild: create modules.builtin without Makefile.modbuiltin or tristate.conf"). Nick has been working on this *for years* and AFAICT I was the only one to suggest two alternatives to this approach for tooling. The complexity in one of my suggested approaches lies in that we'd need a possible-obj-m and a could-be-module which would check if the object being built is part of any kconfig build which could ever lead to it being part of a module, and if so define a new define -DPOSSIBLE_MODULE [0]. A more obvious yet theoretical approach I've suggested would be to have a tristate in kconfig imply the same new -DPOSSIBLE_MODULE as well but that means getting kconfig symbol names mapping to modules always, and I don't think that's the case today. I am not aware of Nick or anyone exploring either of these options. Quite recently Josh Poimboeuf has pointed out that live patching, kprobes and BPF would benefit from resolving some part of the disambiguation as well but for other reasons. The function granularity KASLR (fgkaslr) patches were mentioned but Joe Lawrence has clarified this effort has been dropped with no clear solution in sight [1]. In the meantime removing module license tags from code which could never be modules is welcomed for both objectives mentioned above. Some developers have also welcomed these changes as it has helped clarify when a module was never possible and they forgot to clean this up, and so you'll see quite a bit of Nick's patches in other pull requests for this merge window. I just picked up the stragglers after rc3. LWN has good coverage on the motivation behind this work [2] and the typical cross-tree issues he ran into along the way. The only concrete blocker issue he ran into was that we should not remove the MODULE_LICENSE() tags from files which have no SPDX tags yet, even if they can never be modules. Nick ended up giving up on his efforts due to having to do this vetting and backlash he ran into from folks who really did *not understand* the core of the issue nor were providing any alternative / guidance. I've gone through his changes and dropped the patches which dropped the module license tags where an SPDX license tag was missing, it only consisted of 11 drivers. To see if a pull request deals with a file which lacks SPDX tags you can just use: ./scripts/spdxcheck.py -f \ $(git diff --name-only commid-id | xargs echo) You'll see a core module file in this pull request for the above, but that's not related to his changes. WE just need to add the SPDX license tag for the kernel/module/kmod.c file in the future but it demonstrates the effectiveness of the script. Most of Nick's changes were spread out through different trees, and I just picked up the slack after rc3 for the last kernel was out. Those changes have been in linux-next for over two weeks. The cleanups, debug code I added and final fix I added for modules were motivated by David Hildenbrand's report of boot failing on a systems with over 400 CPUs when KASAN was enabled due to running out of virtual memory space. Although the functional change only consists of 3 lines in the patch "module: avoid allocation if module is already present and ready", proving that this was the best we can do on the modules side took quite a bit of effort and new debug code. The initial cleanups I did on the modules side of things has been in linux-next since around rc3 of the last kernel, the actual final fix for and debug code however have only been in linux-next for about a week or so but I think it is worth getting that code in for this merge window as it does help fix / prove / evaluate the issues reported with larger number of CPUs. Userspace is not yet fixed as it is taking a bit of time for folks to understand the crux of the issue and find a proper resolution. Worst come to worst, I have a kludge-of-concept [3] of how to make kernel_read*() calls for modules unique / converge them, but I'm currently inclined to just see if userspace can fix this instead" Link: https://lore.kernel.org/all/Y/kXDqW+7d71C4wz@bombadil.infradead.org/ [0] Link: https://lkml.kernel.org/r/025f2151-ce7c-5630-9b90-98742c97ac65@redhat.com [1] Link: https://lwn.net/Articles/927569/ [2] Link: https://lkml.kernel.org/r/20230414052840.1994456-3-mcgrof@kernel.org [3] * tag 'modules-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux: (121 commits) module: add debugging auto-load duplicate module support module: stats: fix invalid_mod_bytes typo module: remove use of uninitialized variable len module: fix building stats for 32-bit targets module: stats: include uapi/linux/module.h module: avoid allocation if module is already present and ready module: add debug stats to help identify memory pressure module: extract patient module check into helper modules/kmod: replace implementation with a semaphore Change DEFINE_SEMAPHORE() to take a number argument module: fix kmemleak annotations for non init ELF sections module: Ignore L0 and rename is_arm_mapping_symbol() module: Move is_arm_mapping_symbol() to module_symbol.h module: Sync code of is_arm_mapping_symbol() scripts/gdb: use mem instead of core_layout to get the module address interconnect: remove module-related code interconnect: remove MODULE_LICENSE in non-modules zswap: remove MODULE_LICENSE in non-modules zpool: remove MODULE_LICENSE in non-modules x86/mm/dump_pagetables: remove MODULE_LICENSE in non-modules ...
2 parents d06f5a3 + 8660484 commit b6a7828

158 files changed

Lines changed: 1982 additions & 1034 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3363,6 +3363,12 @@
33633363
specified, <module>.async_probe takes precedence for
33643364
the specific module.
33653365

3366+
module.enable_dups_trace
3367+
[KNL] When CONFIG_MODULE_DEBUG_AUTOLOAD_DUPS is set,
3368+
this means that duplicate request_module() calls will
3369+
trigger a WARN_ON() instead of a pr_warn(). Note that
3370+
if MODULE_DEBUG_AUTOLOAD_DUPS_TRACE is set, WARN_ON()s
3371+
will always be issued and this option does nothing.
33663372
module.sig_enforce
33673373
[KNL] When CONFIG_MODULE_SIG is set, this means that
33683374
modules without (valid) signatures will fail to load.

Documentation/core-api/kernel-api.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,30 @@ relay interface
220220
Module Support
221221
==============
222222

223-
Module Loading
224-
--------------
223+
Kernel module auto-loading
224+
--------------------------
225225

226-
.. kernel-doc:: kernel/kmod.c
226+
.. kernel-doc:: kernel/module/kmod.c
227227
:export:
228228

229+
Module debugging
230+
----------------
231+
232+
.. kernel-doc:: kernel/module/stats.c
233+
:doc: module debugging statistics overview
234+
235+
dup_failed_modules - tracks duplicate failed modules
236+
****************************************************
237+
238+
.. kernel-doc:: kernel/module/stats.c
239+
:doc: dup_failed_modules - tracks duplicate failed modules
240+
241+
module statistics debugfs counters
242+
**********************************
243+
244+
.. kernel-doc:: kernel/module/stats.c
245+
:doc: module statistics debugfs counters
246+
229247
Inter Module support
230248
--------------------
231249

Documentation/translations/zh_CN/core-api/kernel-api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ kernel/relay.c
226226

227227
该API在以下内核代码中:
228228

229-
kernel/kmod.c
229+
kernel/module/kmod.c
230230

231231
模块接口支持
232232
------------

MAINTAINERS

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11601,16 +11601,6 @@ F: include/linux/kmemleak.h
1160111601
F: mm/kmemleak.c
1160211602
F: samples/kmemleak/kmemleak-test.c
1160311603

11604-
KMOD KERNEL MODULE LOADER - USERMODE HELPER
11605-
M: Luis Chamberlain <mcgrof@kernel.org>
11606-
L: linux-kernel@vger.kernel.org
11607-
L: linux-modules@vger.kernel.org
11608-
S: Maintained
11609-
F: include/linux/kmod.h
11610-
F: kernel/kmod.c
11611-
F: lib/test_kmod.c
11612-
F: tools/testing/selftests/kmod/
11613-
1161411604
KMSAN
1161511605
M: Alexander Potapenko <glider@google.com>
1161611606
R: Marco Elver <elver@google.com>
@@ -14186,8 +14176,11 @@ L: linux-kernel@vger.kernel.org
1418614176
S: Maintained
1418714177
T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
1418814178
F: include/linux/module.h
14179+
F: include/linux/kmod.h
1418914180
F: kernel/module/
1419014181
F: scripts/module*
14182+
F: lib/test_kmod.c
14183+
F: tools/testing/selftests/kmod/
1419114184

1419214185
MONOLITHIC POWER SYSTEM PMIC DRIVER
1419314186
M: Saravanan Sekar <sravanhome@gmail.com>

arch/arc/kernel/unwind.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ void *unwind_add_table(struct module *module, const void *table_start,
369369
unsigned long table_size)
370370
{
371371
struct unwind_table *table;
372+
struct module_memory *core_text;
373+
struct module_memory *init_text;
372374

373375
if (table_size <= 0)
374376
return NULL;
@@ -377,11 +379,11 @@ void *unwind_add_table(struct module *module, const void *table_start,
377379
if (!table)
378380
return NULL;
379381

380-
init_unwind_table(table, module->name,
381-
module->core_layout.base, module->core_layout.size,
382-
module->init_layout.base, module->init_layout.size,
383-
table_start, table_size,
384-
NULL, 0);
382+
core_text = &module->mem[MOD_TEXT];
383+
init_text = &module->mem[MOD_INIT_TEXT];
384+
385+
init_unwind_table(table, module->name, core_text->base, core_text->size,
386+
init_text->base, init_text->size, table_start, table_size, NULL, 0);
385387

386388
init_unwind_hdr(table, unw_hdr_alloc);
387389

arch/arm/boot/compressed/decompress.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/* Not needed, but used in some headers pulled in by decompressors */
3232
extern char * strstr(const char * s1, const char *s2);
3333
extern size_t strlen(const char *s);
34+
extern int strcmp(const char *cs, const char *ct);
3435
extern int memcmp(const void *cs, const void *ct, size_t count);
3536
extern char * strchrnul(const char *, int);
3637

arch/arm/kernel/module-plts.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ static const u32 fixed_plts[] = {
2828
#endif
2929
};
3030

31-
static bool in_init(const struct module *mod, unsigned long loc)
32-
{
33-
return loc - (u32)mod->init_layout.base < mod->init_layout.size;
34-
}
35-
3631
static void prealloc_fixed(struct mod_plt_sec *pltsec, struct plt_entries *plt)
3732
{
3833
int i;
@@ -50,8 +45,8 @@ static void prealloc_fixed(struct mod_plt_sec *pltsec, struct plt_entries *plt)
5045

5146
u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val)
5247
{
53-
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
54-
&mod->arch.init;
48+
struct mod_plt_sec *pltsec = !within_module_init(loc, mod) ?
49+
&mod->arch.core : &mod->arch.init;
5550
struct plt_entries *plt;
5651
int idx;
5752

arch/arm64/kernel/module-plts.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,12 @@ static bool plt_entries_equal(const struct plt_entry *a,
6565
(q + aarch64_insn_adrp_get_offset(le32_to_cpu(b->adrp)));
6666
}
6767

68-
static bool in_init(const struct module *mod, void *loc)
69-
{
70-
return (u64)loc - (u64)mod->init_layout.base < mod->init_layout.size;
71-
}
72-
7368
u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
7469
void *loc, const Elf64_Rela *rela,
7570
Elf64_Sym *sym)
7671
{
77-
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
78-
&mod->arch.init;
72+
struct mod_plt_sec *pltsec = !within_module_init((unsigned long)loc, mod) ?
73+
&mod->arch.core : &mod->arch.init;
7974
struct plt_entry *plt = (struct plt_entry *)sechdrs[pltsec->plt_shndx].sh_addr;
8075
int i = pltsec->plt_num_entries;
8176
int j = i - 1;
@@ -105,8 +100,8 @@ u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
105100
u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
106101
void *loc, u64 val)
107102
{
108-
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
109-
&mod->arch.init;
103+
struct mod_plt_sec *pltsec = !within_module_init((unsigned long)loc, mod) ?
104+
&mod->arch.core : &mod->arch.init;
110105
struct plt_entry *plt = (struct plt_entry *)sechdrs[pltsec->plt_shndx].sh_addr;
111106
int i = pltsec->plt_num_entries++;
112107
u32 br;

arch/ia64/kernel/module.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,19 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
485485
return 0;
486486
}
487487

488-
static inline int
488+
static inline bool
489489
in_init (const struct module *mod, uint64_t addr)
490490
{
491-
return addr - (uint64_t) mod->init_layout.base < mod->init_layout.size;
491+
return within_module_init(addr, mod);
492492
}
493493

494-
static inline int
494+
static inline bool
495495
in_core (const struct module *mod, uint64_t addr)
496496
{
497-
return addr - (uint64_t) mod->core_layout.base < mod->core_layout.size;
497+
return within_module_core(addr, mod);
498498
}
499499

500-
static inline int
500+
static inline bool
501501
is_internal (const struct module *mod, uint64_t value)
502502
{
503503
return in_init(mod, value) || in_core(mod, value);
@@ -677,7 +677,8 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
677677
break;
678678

679679
case RV_BDREL:
680-
val -= (uint64_t) (in_init(mod, val) ? mod->init_layout.base : mod->core_layout.base);
680+
val -= (uint64_t) (in_init(mod, val) ? mod->mem[MOD_INIT_TEXT].base :
681+
mod->mem[MOD_TEXT].base);
681682
break;
682683

683684
case RV_LTV:
@@ -812,15 +813,18 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
812813
* addresses have been selected...
813814
*/
814815
uint64_t gp;
815-
if (mod->core_layout.size > MAX_LTOFF)
816+
struct module_memory *mod_mem;
817+
818+
mod_mem = &mod->mem[MOD_DATA];
819+
if (mod_mem->size > MAX_LTOFF)
816820
/*
817821
* This takes advantage of fact that SHF_ARCH_SMALL gets allocated
818822
* at the end of the module.
819823
*/
820-
gp = mod->core_layout.size - MAX_LTOFF / 2;
824+
gp = mod_mem->size - MAX_LTOFF / 2;
821825
else
822-
gp = mod->core_layout.size / 2;
823-
gp = (uint64_t) mod->core_layout.base + ((gp + 7) & -8);
826+
gp = mod_mem->size / 2;
827+
gp = (uint64_t) mod_mem->base + ((gp + 7) & -8);
824828
mod->arch.gp = gp;
825829
DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
826830
}

arch/mips/cavium-octeon/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extern void pci_console_init(const char *arg);
7272
static unsigned long long max_memory = ULLONG_MAX;
7373
static unsigned long long reserve_low_mem;
7474

75-
DEFINE_SEMAPHORE(octeon_bootbus_sem);
75+
DEFINE_SEMAPHORE(octeon_bootbus_sem, 1);
7676
EXPORT_SYMBOL(octeon_bootbus_sem);
7777

7878
static struct octeon_boot_descriptor *octeon_boot_desc_ptr;

0 commit comments

Comments
 (0)