Skip to content

Commit

Permalink
Merge tag 'modules-6.4-rc1' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/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/[email protected]/ [0]
Link: https://lkml.kernel.org/r/[email protected] [1]
Link: https://lwn.net/Articles/927569/ [2]
Link: https://lkml.kernel.org/r/[email protected] [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
  ...
  • Loading branch information
torvalds committed Apr 27, 2023
2 parents d06f5a3 + 8660484 commit b6a7828
Show file tree
Hide file tree
Showing 158 changed files with 1,982 additions and 1,034 deletions.
6 changes: 6 additions & 0 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,12 @@
specified, <module>.async_probe takes precedence for
the specific module.

module.enable_dups_trace
[KNL] When CONFIG_MODULE_DEBUG_AUTOLOAD_DUPS is set,
this means that duplicate request_module() calls will
trigger a WARN_ON() instead of a pr_warn(). Note that
if MODULE_DEBUG_AUTOLOAD_DUPS_TRACE is set, WARN_ON()s
will always be issued and this option does nothing.
module.sig_enforce
[KNL] When CONFIG_MODULE_SIG is set, this means that
modules without (valid) signatures will fail to load.
Expand Down
24 changes: 21 additions & 3 deletions Documentation/core-api/kernel-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,30 @@ relay interface
Module Support
==============

Module Loading
--------------
Kernel module auto-loading
--------------------------

.. kernel-doc:: kernel/kmod.c
.. kernel-doc:: kernel/module/kmod.c
:export:

Module debugging
----------------

.. kernel-doc:: kernel/module/stats.c
:doc: module debugging statistics overview

dup_failed_modules - tracks duplicate failed modules
****************************************************

.. kernel-doc:: kernel/module/stats.c
:doc: dup_failed_modules - tracks duplicate failed modules

module statistics debugfs counters
**********************************

.. kernel-doc:: kernel/module/stats.c
:doc: module statistics debugfs counters

Inter Module support
--------------------

Expand Down
2 changes: 1 addition & 1 deletion Documentation/translations/zh_CN/core-api/kernel-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ kernel/relay.c

该API在以下内核代码中:

kernel/kmod.c
kernel/module/kmod.c

模块接口支持
------------
Expand Down
13 changes: 3 additions & 10 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -11601,16 +11601,6 @@ F: include/linux/kmemleak.h
F: mm/kmemleak.c
F: samples/kmemleak/kmemleak-test.c

KMOD KERNEL MODULE LOADER - USERMODE HELPER
M: Luis Chamberlain <[email protected]>
L: [email protected]
L: [email protected]
S: Maintained
F: include/linux/kmod.h
F: kernel/kmod.c
F: lib/test_kmod.c
F: tools/testing/selftests/kmod/

KMSAN
M: Alexander Potapenko <[email protected]>
R: Marco Elver <[email protected]>
Expand Down Expand Up @@ -14186,8 +14176,11 @@ L: [email protected]
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
F: include/linux/module.h
F: include/linux/kmod.h
F: kernel/module/
F: scripts/module*
F: lib/test_kmod.c
F: tools/testing/selftests/kmod/

MONOLITHIC POWER SYSTEM PMIC DRIVER
M: Saravanan Sekar <[email protected]>
Expand Down
12 changes: 7 additions & 5 deletions arch/arc/kernel/unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ void *unwind_add_table(struct module *module, const void *table_start,
unsigned long table_size)
{
struct unwind_table *table;
struct module_memory *core_text;
struct module_memory *init_text;

if (table_size <= 0)
return NULL;
Expand All @@ -377,11 +379,11 @@ void *unwind_add_table(struct module *module, const void *table_start,
if (!table)
return NULL;

init_unwind_table(table, module->name,
module->core_layout.base, module->core_layout.size,
module->init_layout.base, module->init_layout.size,
table_start, table_size,
NULL, 0);
core_text = &module->mem[MOD_TEXT];
init_text = &module->mem[MOD_INIT_TEXT];

init_unwind_table(table, module->name, core_text->base, core_text->size,
init_text->base, init_text->size, table_start, table_size, NULL, 0);

init_unwind_hdr(table, unw_hdr_alloc);

Expand Down
1 change: 1 addition & 0 deletions arch/arm/boot/compressed/decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/* Not needed, but used in some headers pulled in by decompressors */
extern char * strstr(const char * s1, const char *s2);
extern size_t strlen(const char *s);
extern int strcmp(const char *cs, const char *ct);
extern int memcmp(const void *cs, const void *ct, size_t count);
extern char * strchrnul(const char *, int);

Expand Down
9 changes: 2 additions & 7 deletions arch/arm/kernel/module-plts.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ static const u32 fixed_plts[] = {
#endif
};

static bool in_init(const struct module *mod, unsigned long loc)
{
return loc - (u32)mod->init_layout.base < mod->init_layout.size;
}

static void prealloc_fixed(struct mod_plt_sec *pltsec, struct plt_entries *plt)
{
int i;
Expand All @@ -50,8 +45,8 @@ static void prealloc_fixed(struct mod_plt_sec *pltsec, struct plt_entries *plt)

u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val)
{
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
&mod->arch.init;
struct mod_plt_sec *pltsec = !within_module_init(loc, mod) ?
&mod->arch.core : &mod->arch.init;
struct plt_entries *plt;
int idx;

Expand Down
13 changes: 4 additions & 9 deletions arch/arm64/kernel/module-plts.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,12 @@ static bool plt_entries_equal(const struct plt_entry *a,
(q + aarch64_insn_adrp_get_offset(le32_to_cpu(b->adrp)));
}

static bool in_init(const struct module *mod, void *loc)
{
return (u64)loc - (u64)mod->init_layout.base < mod->init_layout.size;
}

u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
void *loc, const Elf64_Rela *rela,
Elf64_Sym *sym)
{
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
&mod->arch.init;
struct mod_plt_sec *pltsec = !within_module_init((unsigned long)loc, mod) ?
&mod->arch.core : &mod->arch.init;
struct plt_entry *plt = (struct plt_entry *)sechdrs[pltsec->plt_shndx].sh_addr;
int i = pltsec->plt_num_entries;
int j = i - 1;
Expand Down Expand Up @@ -105,8 +100,8 @@ u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
void *loc, u64 val)
{
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
&mod->arch.init;
struct mod_plt_sec *pltsec = !within_module_init((unsigned long)loc, mod) ?
&mod->arch.core : &mod->arch.init;
struct plt_entry *plt = (struct plt_entry *)sechdrs[pltsec->plt_shndx].sh_addr;
int i = pltsec->plt_num_entries++;
u32 br;
Expand Down
24 changes: 14 additions & 10 deletions arch/ia64/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,19 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
return 0;
}

static inline int
static inline bool
in_init (const struct module *mod, uint64_t addr)
{
return addr - (uint64_t) mod->init_layout.base < mod->init_layout.size;
return within_module_init(addr, mod);
}

static inline int
static inline bool
in_core (const struct module *mod, uint64_t addr)
{
return addr - (uint64_t) mod->core_layout.base < mod->core_layout.size;
return within_module_core(addr, mod);
}

static inline int
static inline bool
is_internal (const struct module *mod, uint64_t value)
{
return in_init(mod, value) || in_core(mod, value);
Expand Down Expand Up @@ -677,7 +677,8 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
break;

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

case RV_LTV:
Expand Down Expand Up @@ -812,15 +813,18 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
* addresses have been selected...
*/
uint64_t gp;
if (mod->core_layout.size > MAX_LTOFF)
struct module_memory *mod_mem;

mod_mem = &mod->mem[MOD_DATA];
if (mod_mem->size > MAX_LTOFF)
/*
* This takes advantage of fact that SHF_ARCH_SMALL gets allocated
* at the end of the module.
*/
gp = mod->core_layout.size - MAX_LTOFF / 2;
gp = mod_mem->size - MAX_LTOFF / 2;
else
gp = mod->core_layout.size / 2;
gp = (uint64_t) mod->core_layout.base + ((gp + 7) & -8);
gp = mod_mem->size / 2;
gp = (uint64_t) mod_mem->base + ((gp + 7) & -8);
mod->arch.gp = gp;
DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/cavium-octeon/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern void pci_console_init(const char *arg);
static unsigned long long max_memory = ULLONG_MAX;
static unsigned long long reserve_low_mem;

DEFINE_SEMAPHORE(octeon_bootbus_sem);
DEFINE_SEMAPHORE(octeon_bootbus_sem, 1);
EXPORT_SYMBOL(octeon_bootbus_sem);

static struct octeon_boot_descriptor *octeon_boot_desc_ptr;
Expand Down
11 changes: 5 additions & 6 deletions arch/mips/kernel/vpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,17 @@ static void layout_sections(struct module *mod, const Elf_Ehdr *hdr,
for (m = 0; m < ARRAY_SIZE(masks); ++m) {
for (i = 0; i < hdr->e_shnum; ++i) {
Elf_Shdr *s = &sechdrs[i];
struct module_memory *mod_mem;

mod_mem = &mod->mem[MOD_TEXT];

if ((s->sh_flags & masks[m][0]) != masks[m][0]
|| (s->sh_flags & masks[m][1])
|| s->sh_entsize != ~0UL)
continue;
s->sh_entsize =
get_offset((unsigned long *)&mod->core_layout.size, s);
get_offset((unsigned long *)&mod_mem->size, s);
}

if (m == 0)
mod->core_layout.text_size = mod->core_layout.size;

}
}

Expand Down Expand Up @@ -641,7 +640,7 @@ static int vpe_elfload(struct vpe *v)
layout_sections(&mod, hdr, sechdrs, secstrings);
}

v->load_addr = alloc_progmem(mod.core_layout.size);
v->load_addr = alloc_progmem(mod.mem[MOD_TEXT].size);
if (!v->load_addr)
return -ENOMEM;

Expand Down
Loading

0 comments on commit b6a7828

Please sign in to comment.