Generic Linux architectural discussions
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Petr Pavlu <petr.pavlu@suse.com>
Cc: "Linus Torvalds" <torvalds@linux-foundation.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Alexey Gladkov" <legion@kernel.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Kees Cook" <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, linux-riscv@lists.infradead.org,
	linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-efi@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-doc@vger.kernel.org, "Jens Axboe" <axboe@kernel.dk>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v4 14/22] modpost: emit module descriptors as assembly
Date: Fri, 16 Oct 2026 18:06:21 +0100	[thread overview]
Message-ID: <atJVYDgv8ejLoIrA@gremlin> (raw)
In-Reply-To: <b17e9924-ca92-4cdf-b5e6-54164039e09a@suse.com>

On Fri, Oct 16, 2026 at 02:14:16PM +0200, Petr Pavlu wrote:
> This version looks mostly ok to me, from a modules perspective. Below
> are a few nits plus one more useful comment about handling
> MODULE_ARCH_INIT.

Ack thanks :)

>
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 0fd43c8a89ea..9d96459e492c 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
...
> > +/* The equivalent of KSYMTAB_FUNC()/KSYMTAB_DATA(). */
> > +static void add_asm_ksymtab(struct buffer *buf, const struct symbol *sym)
> > +{
> > +	const char *name = sym->name;
> > +
> > +	add_asm_kstrtab(buf, sym);
> > +
> > +	buf_printf(buf, "\t.section \"___ksymtab+%s\", \"a\"\n", name);
> > +	buf_printf(buf, "\t.balign %d\n", KSYM_ALIGN);
> > +	buf_printf(buf, "__ksymtab_%s:\n", name);
> > +	add_asm_ksym_ref(buf, sym->is_func ? MOD_FUNC_PREFIX : "", name);
> > +	add_asm_ksym_ref(buf, "__kstrtab_", name);
> > +	add_asm_ksym_ref(buf, "__kstrtabns_", name);
> > +	buf_printf(buf, "\t.previous\n");
> > +
> > +	add_asm_kflagstab(buf, sym);
> > +}
>
> add_asm_kstrtab() and add_asm_kflagstab() are only called from
> add_asm_ksymtab() and their logic is fairly short. I suggest merging
> these functions.

Ack, done for v5.

>
> > +
> > +/* The equivalent of SYMBOL_CRC(). */
> > +static void add_asm_crc(struct buffer *buf, const struct symbol *sym)
> > +{
> > +	buf_printf(buf, "\t.section \"___kcrctab+%s\",\"a\"\n", sym->name);
> > +	buf_printf(buf, "\t.balign 4\n");
> > +	buf_printf(buf, "__crc_%s:\n", sym->name);
> > +	buf_printf(buf, "\t.long 0x%08x\n", sym->crc);
> > +	buf_printf(buf, "\t.previous\n");
> > +}
> > +
> > +static bool export_is_kept(const struct symbol *sym)
> > +{
> > +	return !trim_unused_exports || sym->used;
> > +}
>
> export_is_kept() is only called once from add_asm_exported_symbols().
> The condition can be inlined directly there.

Ack done.

> > +/*
> > + * The equivalent of:
> > + *
> > + *	__visible struct module __this_module __section(".gnu.linkonce.this_module")
> > + *		= { .name = KBUILD_MODNAME, .init = init_module, .exit = cleanup_module,
> > + *		    .arch = MODULE_ARCH_INIT };
> > + *
> > + * Everything not listed is zero, MODULE_ARCH_INIT included, except on m68k.
> > + */
> > +static void add_asm_this_module(struct buffer *buf, const struct module *mod,
> > +				const char *modname)
> > +{
> > +	struct this_module_field fields[THIS_MODULE_MAX_FIELDS];
> > +	const unsigned int nr_fields = get_this_module_fields(mod, modname, fields);
>
> The const qualifier can be removed from the nr_fields definition to
> match the usual kernel style.

Ack done.

> > +/*
> > + * The equivalent of:
> > + *	static const u32 ____version_ext_crcs[] __section("__version_ext_crcs") = { crc, ... };
> > + *	static const char ____version_ext_names[] __section("__version_ext_names") = "name\0" ...;
> > + *
> > + * for unresolved symbols.
> > + */
> > +static void add_asm_extended_versions(struct buffer *buf, struct module *mod)
> > +{
> > +	struct symbol *sym;
> > +
> > +	if (!extended_modversions)
> > +		return;
> > +
> > +	buf_printf(buf, "\n\t.section __version_ext_crcs,\"a\",%%progbits\n");
> > +	buf_printf(buf, "\t.balign 4\n");
> > +	list_for_each_entry(sym, &mod->unresolved_symbols, list) {
> > +		if (skip_unversioned(mod, sym))
> > +			continue;
> > +
> > +		buf_printf(buf, "\t.long 0x%08x\n", sym->crc);
> > +	}
> > +
> > +	/*
> > +	 * A symbol without a CRC was warned about above, and is skipped here
> > +	 * too so that the names line up with the CRCs.
> > +	 */
> > +	buf_printf(buf, "\t.section __version_ext_names,\"a\",%%progbits\n");
> > +	list_for_each_entry(sym, &mod->unresolved_symbols, list) {
> > +		if (!sym->module || !sym->crc_valid)
> > +			continue;
>
> This condition must match the logic in skip_unversioned(). It would be
> clearer to keep it only in one place by calling skip_unversioned() here
> and adding a "silent" parameter to the function.

Ack done.

>
> > diff --git a/scripts/mod/module-offsets.c b/scripts/mod/module-offsets.c
> > new file mode 100644
> > index 000000000000..a336dd47aa33
> > --- /dev/null
> > +++ b/scripts/mod/module-offsets.c

> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Layout of the structures modpost emits into *.mod.S, extracted from the
> > + * target headers as devicetable-offsets.c does for the device tables.
> > + */
>
> The second part of the comment, after the comma, is superfluous. It is
> expected that the various parts of modpost use consistent mechanisms
> where appropriate.

Ack done.

> > +int main(void)
> > +{
> > +	DEFINE(MOD_SIZEOF_LONG, sizeof(long));
> > +	DEFINE(MOD_PREL32_RELOCATIONS, IS_ENABLED(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS));
> > +	DEFINE(MOD_FUNC_PLABEL, IS_ENABLED(CONFIG_PARISC) && IS_ENABLED(CONFIG_64BIT));
> > +
> > +	DEFINE(MOD_SIZEOF_struct_module, sizeof(struct module));
> > +	DEFINE(MOD_ALIGNOF_struct_module, __alignof__(struct module));
> > +	OFFSET(MOD_OFF_module_name, module, name);
> > +	OFFSET(MOD_OFF_module_init, module, init);
> > +#ifdef CONFIG_MODULE_UNLOAD
> > +	OFFSET(MOD_OFF_module_exit, module, exit);
> > +#endif
> > +#if defined(CONFIG_M68K) && defined(CONFIG_MMU)
> > +	/* MODULE_ARCH_INIT: the only architecture where it is not all zeroes. */
> > +	OFFSET(MOD_OFF_module_arch_fixup_start, module, arch.fixup_start);
> > +	OFFSET(MOD_OFF_module_arch_fixup_end, module, arch.fixup_end);
> > +#endif
>
> I feel it is a bit of a layering violation for modpost to know how
> individual architectures need to initialize module::arch.

Yeah that is kinda gross :)

>
> For now, this is probably ok. I would just remove MODULE_ARCH_INIT from
> include/linux/module.h and arch/m68k/include/asm/module.h, along with
> the comment referring to it in scripts/mod/modpost.c.

ack done.

>
> In the future, this could be avoided by having the m68k module support
> look up the .m68k_fixup section at runtime, as other architectures
> typically do for similar sections.

Yes, arch stuff should live with the arch-specific stuff.

--
Cheers, Lorenzo

  reply	other threads:[~2026-10-16 17:06 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 17:17 [PATCH v4 00/22] kbuild: significantly speed up kernel builds Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 01/22] kbuild: do not allocate .modinfo in vmlinux Lorenzo Stoakes (ARM)
2026-09-24 13:44   ` Nicolas Schier
2026-09-23 17:17 ` [PATCH v4 02/22] kallsyms: index symbols by token to speed up table compression Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 03/22] kallsyms: output binary data to speed output and kallsyms assembly Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 04/22] sorttable: parse nm output correctly Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 05/22] kbuild: do not sort nm output where the order is irrelevant Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 06/22] kbuild: only emit vmlinux relocations when required Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 07/22] elf-parse: add section flags, symbol binding and mapping helpers Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 08/22] kallsyms: reimplement mksysmap in C Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 09/22] kbuild: calculate list, composite object state per object Lorenzo Stoakes (ARM)
2026-09-23 17:17 ` [PATCH v4 10/22] kbuild: implement and use depcheck to check dependency timestamps Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 11/22] kbuild: move the toolchain checks into scripts/Kconfig.toolchain Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 12/22] kbuild: avoid re-running compiler and linker probes Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 13/22] modpost: cache section relocation mismatch state Lorenzo Stoakes (ARM)
2026-10-15 15:42   ` Petr Pavlu
2026-10-16 16:44     ` Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 14/22] modpost: emit module descriptors as assembly Lorenzo Stoakes (ARM)
2026-10-16 12:14   ` Petr Pavlu
2026-10-16 17:06     ` Lorenzo Stoakes (ARM) [this message]
2026-09-23 17:18 ` [PATCH v4 15/22] kbuild: batch module finalisation Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 16/22] objtool: do not hash DWARF relocations Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 17/22] objtool: cache relocations, do less work, eliminate relocation hash Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 18/22] objtool: size the instruction hash to the text Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 19/22] objtool: decode instructions and resolve branch targets in parallel Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 20/22] rust: make exports.o depend on the headers generated for it Lorenzo Stoakes (ARM)
2026-09-24 13:44   ` Nicolas Schier
2026-09-23 17:18 ` [PATCH v4 21/22] kbuild: build rust crates in parallel with the rest of the build Lorenzo Stoakes (ARM)
2026-09-23 17:18 ` [PATCH v4 22/22] kbuild: compress the kernel with pigz if available Lorenzo Stoakes (ARM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=atJVYDgv8ejLoIrA@gremlin \
    --to=ljs@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=alex@ghiti.fr \
    --cc=aliceryhl@google.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=gary@garyguo.net \
    --cc=gustavoars@kernel.org \
    --cc=hpa@zytor.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jpoimboe@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=legion@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=llvm@lists.linux.dev \
    --cc=lossin@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=masahiroy@kernel.org \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=peterz@infradead.org \
    --cc=petr.pavlu@suse.com \
    --cc=pjw@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.org \
    --cc=work@onurozkan.dev \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox