From nobody Sat Oct 11 04:18:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62141274FDE for ; Wed, 11 Jun 2025 10:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749638082; cv=none; b=TPfTikSHYuv7dgb10Khh9t82Gq/WrgQ28P+9ZTKtPh0WT7AMVIvFLzsi3eVTBnqcvdPDrMXVgcwQFod6v/TtWjdb6f7a74ZxiOjdvjzDKlLSlS7NS5dT5f4V8NargYjTk3x+h93k1pkAWeMtVf17mXv1JJecJDBzRP+pUBwY8n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749638082; c=relaxed/simple; bh=cXATu5WHYSddNew6hPBjs/f3aIkMJ3j64KCP2miazbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZRw5TN8kX+ntNUKEX7Dy5TjKD6FjZMrCnXJQ4BN2iL/zUYsY5K9bXDqigdnMibWRYMBuFVbxWwZFup3QmezkrDmDxtPfBS4Iep4KH9+QZiVxnuzaHwsDibDfmWJti7/iLwuUzeXY7K4I9YKbp0lHBBnplvDYh44K4/jk8H65wc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M50ui/yX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M50ui/yX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4587C4CEF1; Wed, 11 Jun 2025 10:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749638081; bh=cXATu5WHYSddNew6hPBjs/f3aIkMJ3j64KCP2miazbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M50ui/yXjAWeqdhPtiRb5YNgR5csZZbU0dMbAf1SpZQLgRRYnrdJmgmchbRqy90EB DcrthmNCiS488fnCof9yiZ340e4+lvhHeWsiSxlNO5AWo7G9pSYAfILd00pXuh7URX ddsaYwzBvuZblZF7l8ms5jrTnUwt3t8fElD6PayX6NJKS1MquCu4cQj5CFfpNNP8vN vdEudbPaO3I9zBVmd1Y1k5dkzB6pWgEiZcRYp9DmNA2l0l5/VrcO4YMk/NupqABOH9 dDBQ1zSu0NLy6ESqdUcWznTMGW5h9C/qi1n/Yfi2zEHhsHTyS0OdxhjGn6l6BhO/fS aS1wEUUOmU+FQ== From: Alexey Gladkov To: Masahiro Yamada Cc: Petr Pavlu , Alexey Gladkov , Ard Biesheuvel , Nathan Chancellor , Nicolas Schier , linux-kernel@vger.kernel.org, Khalid Aziz , "Martin K. Petersen" , James Bottomley Subject: [PATCH 1/3] scsi: Always define blogic_pci_tbl structure Date: Wed, 11 Jun 2025 12:34:29 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: <20250606041029.614348-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The blogic_pci_tbl structure is used by the MODULE_DEVICE_TABLE macro. There is no longer a need to protect it with the MODULE condition, since this no longer causes the compiler to warn about an unused variable. Cc: Khalid Aziz Cc: "Martin K. Petersen" Suggested-by: James Bottomley Signed-off-by: Alexey Gladkov --- drivers/scsi/BusLogic.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c index 1f100270cd38..08e12a3d6703 100644 --- a/drivers/scsi/BusLogic.c +++ b/drivers/scsi/BusLogic.c @@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void) =20 __setup("BusLogic=3D", blogic_setup); =20 -#ifdef MODULE /*static const struct pci_device_id blogic_pci_tbl[] =3D { { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, @@ -3731,7 +3730,6 @@ static const struct pci_device_id blogic_pci_tbl[] = =3D { {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)}, {0, }, }; -#endif MODULE_DEVICE_TABLE(pci, blogic_pci_tbl); =20 module_init(blogic_init); --=20 2.49.0 From nobody Sat Oct 11 04:18:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 562E82798FD for ; Wed, 11 Jun 2025 10:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749638084; cv=none; b=FvqAjn9K5FQ6MAA+LBhh12x9qTMhIFYJn2gQArOO7GiuDX0oi4roouHk6aitq2Dwh5/w+XomB7727n4knjzSSSXHKXPK9NGMdIdp7EoSkLuVaEVVuvPc3pG95E5eg4kQF8E39VSn9lAmADNOy58yKzby1P4fKFDLIxH1R09s43U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749638084; c=relaxed/simple; bh=q/SZLjSqTibh2hypBF9kUWxN4M5BbdYEvmWzASdB61U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lQ0JGOIsQlhJRJbfdZwUvTGJ89a70gDg96nSBaQwmgrOE5XOMzUWMcI5HL9VBFyvDamdkcTB9+yilIq9wnHQaX/CsD26+1E+ZAJKDNMTzDcN38pOSAcjGGH/wXdQYR3d8TTBT8Dogkj03py7bJeBdpIlzuJGycCQ+iAr2Dakpwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cl+i6huM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cl+i6huM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A849C4CEEE; Wed, 11 Jun 2025 10:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749638084; bh=q/SZLjSqTibh2hypBF9kUWxN4M5BbdYEvmWzASdB61U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cl+i6huMsdpAPHDNSeGnNThyPYDnkxolHoTM+0keMZFolomjiwUCvL3Zi25Gw1rGL fRCMV8drQ3++PAq6TGc8oxR6pKvYrLCfx31j3BuiyggzZFlQJLQnSGayoGpa1FHUEU kY7tnOqnRDQa9gfoUZubj14y/55XdKF7tO6JDLJ9imYfFLyVv3RbMyZAqNG+FHkNlk BuFTB5txGm/VePh0me5kBn4bbL9oCVsJvWmj8BBavpxpOI70rpJHS+Gt6H2ZOrUHiW bmi2BiuOhTyBSnwB5bwyIhib+kosFLS5TcMAjZqRXcVRvcNg9s6HTZnSP0SwE/tgOm AMU9uycGW+/cg== From: Alexey Gladkov To: Masahiro Yamada Cc: Petr Pavlu , Alexey Gladkov , Ard Biesheuvel , Nathan Chancellor , Nicolas Schier , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] modpost: Add modname to mod_device_table alias Date: Wed, 11 Jun 2025 12:34:30 +0200 Message-ID: <6e2f70b07a710e761eb68d089d96cee7b27bb2d5.1749637146.git.legion@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: <20250606041029.614348-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At this point, if a symbol is compiled as part of the kernel, information about which module the symbol belongs to is lost. To save this it is possible to add the module name to the alias name. It's not very pretty, but it's possible for now. Signed-off-by: Alexey Gladkov --- include/linux/module.h | 14 +++++++++++--- rust/kernel/device_id.rs | 8 ++++---- scripts/mod/file2alias.c | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 24fe6b865e9c..e0f826fab2ac 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -243,11 +243,19 @@ struct module_kobject *lookup_or_create_module_kobjec= t(const char *name); /* What your module does. */ #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _descrip= tion) =20 +/* Format: __mod_device_table__kmod_____ */ +#define __mod_device_table(type, name) \ + __PASTE(__mod_device_table__, \ + __PASTE(__KBUILD_MODNAME, \ + __PASTE(__, \ + __PASTE(type, \ + __PASTE(__, name))))) + #ifdef MODULE /* Creates an alias so file2alias.c can find device table. */ -#define MODULE_DEVICE_TABLE(type, name) \ -extern typeof(name) __mod_device_table__##type##__##name \ - __attribute__ ((unused, alias(__stringify(name)))) +#define MODULE_DEVICE_TABLE(type, name) \ +static typeof(name) __mod_device_table(type, name) \ + __attribute__ ((used, alias(__stringify(name)))) #else /* !MODULE */ #define MODULE_DEVICE_TABLE(type, name) #endif diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs index 0a4eb56d98f2..365d8f544844 100644 --- a/rust/kernel/device_id.rs +++ b/rust/kernel/device_id.rs @@ -154,10 +154,10 @@ macro_rules! module_device_table { ($table_type: literal, $module_table_name:ident, $table_name:ident) = =3D> { #[rustfmt::skip] #[export_name =3D - concat!("__mod_device_table__", $table_type, - "__", module_path!(), - "_", line!(), - "_", stringify!($table_name)) + concat!("__mod_device_table__", line!(), + "__kmod_", module_path!(), + "__", $table_type, + "__", stringify!($table_name)) ] static $module_table_name: [::core::mem::MaybeUninit; $table_n= ame.raw_ids().size()] =3D unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) }; diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 00586119a25b..13021266a18f 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1476,8 +1476,8 @@ void handle_moddevtable(struct module *mod, struct el= f_info *info, { void *symval; char *zeros =3D NULL; - const char *type, *name; - size_t typelen; + const char *type, *name, *modname; + size_t typelen, modnamelen; static const char *prefix =3D "__mod_device_table__"; =20 /* We're looking for a section relative symbol */ @@ -1488,10 +1488,20 @@ void handle_moddevtable(struct module *mod, struct = elf_info *info, if (ELF_ST_TYPE(sym->st_info) !=3D STT_OBJECT) return; =20 - /* All our symbols are of form __mod_device_table____. */ + /* All our symbols are of form __mod_device_table__kmod___= __. */ if (!strstarts(symname, prefix)) return; - type =3D symname + strlen(prefix); + + modname =3D strstr(symname, "__kmod_"); + if (!modname) + return; + modname +=3D strlen("__kmod_"); + + type =3D strstr(modname, "__"); + if (!type) + return; + modnamelen =3D type - modname; + type +=3D strlen("__"); =20 name =3D strstr(type, "__"); if (!name) --=20 2.49.0 From nobody Sat Oct 11 04:18:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8941327466F for ; Wed, 11 Jun 2025 10:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749638086; cv=none; b=h3UE9N4po078fiUyyTzxr5AjR5IPJdaMgojo8PdYLq9AreWhkU/vH+1fIXHPyn92Rmz0hzZ4UqfGdh/CnbBR8rMr/agRAJh3MrOPjzqTOfSt5IQR/jX2wTw3N+wvR4yBewKX0f4FiAnlXMVZRKJhrVqoD8FauVz7rW+G34MmCl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749638086; c=relaxed/simple; bh=nEVwenXZZz5nM7DkAj/oakR9uk7yJuktxc9Q++SALQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DSREf0FSZWnHptXBoJopb0YATAebcMgxg9ak3fjfXAPTqcHYfdjE+Erysjk4HNI41GtwqEi7Z+d/O3/Ct8yM83AbZWePqgo170kcKeFX/a4kC5XzUou194to9qcuurl92PPlrL1u6MguapZb6VLQyWUefGB80b2X57cl3id+MVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B2VPZxmn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B2VPZxmn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C1E2C4CEF2; Wed, 11 Jun 2025 10:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749638086; bh=nEVwenXZZz5nM7DkAj/oakR9uk7yJuktxc9Q++SALQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B2VPZxmnIj7RIjnIOyiDHfUNfdEod0jaCPx3WX3qLKIPISSkDHkeOgUz+gAByMQrn tp/PFs4R/ciMTbsz6an5eNIvWCcEMLhdiX9V9EVYdjRo/fSf970ls1xwCii5+A+qi2 yI6qcsywwsiKrOATtFiZWzr7IzBZCUBoZVK2FR7MQB3UIv56GgXatBGV58G/Z3fafb MnOhOy6SAiFQdduxLcJTtqmNmDVTVj+C6zO9rrEbxsMCUNQ2fOG49EER76iWdmECvf 8ZtMVQXuCTE33/HurXMwV0U3VXs/nvIhDZFWe8GvxLP8/hVDLRNFnWp+GXpC/ku8cy h9hCeps6TqmMA== From: Alexey Gladkov To: Masahiro Yamada Cc: Petr Pavlu , Alexey Gladkov , Ard Biesheuvel , Nathan Chancellor , Nicolas Schier , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] modpost: Create modalias for builtin modules Date: Wed, 11 Jun 2025 12:34:31 +0200 Message-ID: <321947106ec997b5a2a9c93ec2229cb2f9eb377c.1749637146.git.legion@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: <20250606041029.614348-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For some modules, modalias is generated using the modpost utility and the section is added to the module file. When a module is added inside vmlinux, modpost does not generate modalias for such modules and the information is lost. As a result kmod (which uses modules.builtin.modinfo in userspace) cannot determine that modalias is handled by a builtin kernel module. $ cat /sys/devices/pci0000:00/0000:00:14.0/modalias pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 $ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller Driver Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately. To fix this it is necessary to generate the same modalias for vmlinux as for the individual modules. Fortunately '.vmlinux.export.o' is already generated from which '.modinfo' can be extracted in the same way as for vmlinux.o. Signed-off-by: Masahiro Yamada Signed-off-by: Alexey Gladkov --- include/linux/module.h | 4 ---- scripts/Makefile.vmlinux | 5 ++++- scripts/mksysmap | 3 +++ scripts/mod/file2alias.c | 16 ++++++++++++++++ scripts/mod/modpost.c | 17 ++++++++++++++++- scripts/mod/modpost.h | 2 ++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index e0f826fab2ac..3aeee5d0a77c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -251,14 +251,10 @@ struct module_kobject *lookup_or_create_module_kobjec= t(const char *name); __PASTE(type, \ __PASTE(__, name))))) =20 -#ifdef MODULE /* Creates an alias so file2alias.c can find device table. */ #define MODULE_DEVICE_TABLE(type, name) \ static typeof(name) __mod_device_table(type, name) \ __attribute__ ((used, alias(__stringify(name)))) -#else /* !MODULE */ -#define MODULE_DEVICE_TABLE(type, name) -#endif =20 /* Version of form [:][-]. * Or for CVS/RCS ID version, everything but the number is stripped. diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index fdab5aa90215..fcc188d26ead 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -89,8 +89,11 @@ endif remove-section-y :=3D .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) +=3D '.rel*' =20 +remove-symbols :=3D -w --strip-symbol=3D'__mod_device_table__*' + quiet_cmd_strip_relocs =3D OBJCOPY $@ - cmd_strip_relocs =3D $(OBJCOPY) $(addprefix --remove-section=3D,$(re= move-section-y)) $< $@ + cmd_strip_relocs =3D $(OBJCOPY) $(addprefix --remove-section=3D,$(re= move-section-y)) \ + $(remove-symbols) $< $@ =20 targets +=3D vmlinux vmlinux: vmlinux.unstripped FORCE diff --git a/scripts/mksysmap b/scripts/mksysmap index a607a0059d11..c4531eacde20 100755 --- a/scripts/mksysmap +++ b/scripts/mksysmap @@ -59,6 +59,9 @@ # EXPORT_SYMBOL (namespace) / __kstrtabns_/d =20 +# MODULE_DEVICE_TABLE (symbol name) +/ __mod_device_table__/d + # ------------------------------------------------------------------------= --- # Ignored suffixes # (do not forget '$' after each pattern) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 13021266a18f..7da9735e7ab3 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1527,5 +1527,21 @@ void handle_moddevtable(struct module *mod, struct e= lf_info *info, } } =20 + if (mod->is_vmlinux) { + struct module_alias *alias; + + /* + * If this is vmlinux, record the name of the builtin module. + * Traverse the linked list in the reverse order, and set the + * builtin_modname unless it has already been set in the + * previous call. + */ + list_for_each_entry_reverse(alias, &mod->aliases, node) { + if (alias->builtin_modname) + break; + alias->builtin_modname =3D xstrndup(modname, modnamelen); + } + } + free(zeros); } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index be89921d60b6..67668b159444 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2021,11 +2021,26 @@ static void write_if_changed(struct buffer *b, cons= t char *fname) static void write_vmlinux_export_c_file(struct module *mod) { struct buffer buf =3D { }; + struct module_alias *alias, *next; =20 buf_printf(&buf, - "#include \n"); + "#include \n" + "#include \n"); =20 add_exported_symbols(&buf, mod); + + buf_printf(&buf, + "#undef __MODULE_INFO_PREFIX\n" + "#define __MODULE_INFO_PREFIX\n"); + + list_for_each_entry_safe(alias, next, &mod->aliases, node) { + buf_printf(&buf, "MODULE_INFO(%s.alias, \"%s\");\n", + alias->builtin_modname, alias->str); + list_del(&alias->node); + free(alias->builtin_modname); + free(alias); + } + write_if_changed(&buf, ".vmlinux.export.c"); free(buf.p); } diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 9133e4c3803f..2aecb8f25c87 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len); * struct module_alias - auto-generated MODULE_ALIAS() * * @node: linked to module::aliases + * @modname: name of the builtin module (only for vmlinux) * @str: a string for MODULE_ALIAS() */ struct module_alias { struct list_head node; + char *builtin_modname; char str[]; }; =20 --=20 2.49.0