linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] module: add -EEXIST module_init() reservation docs
@ 2025-12-18 20:59 Daniel Gomez
  2025-12-18 20:59 ` [PATCH 1/2] module: add -EEXIST documentation Daniel Gomez
  2025-12-18 20:59 ` [PATCH 2/2] docs: hacking: clarify reserved -EEXIST in module_init() Daniel Gomez
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Gomez @ 2025-12-18 20:59 UTC (permalink / raw)
  To: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen,
	Aaron Tomlin, Jonathan Corbet, Lucas De Marchi
  Cc: linux-modules, linux-kernel, linux-doc, Daniel Gomez

This series documents the -EEXIST error code reservation in the module
loader, building on Lucas's patches [1] that add the runtime safety net.

When module_init() returns -EEXIST, kmod interprets this as "module
already loaded" and reports success, hiding real init failures. Lucas's
patches warn and override this to -EBUSY. These patches document this
convention to prevent future cases.

This was originally reported in this thread [2].

Link: https://lore.kernel.org/all/20251013-module-warn-ret-v1-0-ab65b41af01f@intel.com/ [1]
Link: https://lore.kernel.org/all/aKEVQhJpRdiZSliu@orbyte.nwl.cc/#t [2]

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
Daniel Gomez (2):
      module: add -EEXIST documentation
      docs: hacking: clarify reserved -EEXIST in module_init()

 Documentation/kernel-hacking/hacking.rst | 7 +++++++
 kernel/module/main.c                     | 8 ++++++++
 2 files changed, 15 insertions(+)
---
base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a
change-id: 20251218-dev-module-init-eexists-modules-docs-1dc7cb7a96bb
prerequisite-change-id: 20251013-module-warn-ret-59f085298055:v1
prerequisite-patch-id: c3e4f5b5d01c2b48b4c94e51a60469cb74691853
prerequisite-patch-id: 2d5a726a75f3b9d9c256b8478fb6115a92f04354

Best regards,
--  
Daniel Gomez <da.gomez@samsung.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] module: add -EEXIST documentation
  2025-12-18 20:59 [PATCH 0/2] module: add -EEXIST module_init() reservation docs Daniel Gomez
@ 2025-12-18 20:59 ` Daniel Gomez
  2025-12-18 20:59 ` [PATCH 2/2] docs: hacking: clarify reserved -EEXIST in module_init() Daniel Gomez
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Gomez @ 2025-12-18 20:59 UTC (permalink / raw)
  To: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen,
	Aaron Tomlin, Jonathan Corbet, Lucas De Marchi
  Cc: linux-modules, linux-kernel, linux-doc, Daniel Gomez

From: Daniel Gomez <da.gomez@samsung.com>

The error code -EEXIST is reserved by the kernel module loader to
indicate that a module with the same name is already loaded. Add a
comment to clarify what this means for module authors and maintainers
to ensure the module_init() path return error do not conflict with the
reserved one.

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 kernel/module/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index a8394d81174f..655a780981d3 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -3038,6 +3038,14 @@ static noinline int do_init_module(struct module *mod)
 	if (mod->init != NULL)
 		ret = do_one_initcall(mod->init);
 	if (ret < 0) {
+		/*
+		 * -EEXIST is reserved by the module loader to mean "already loaded". kmod
+		 * interprets this as success, hiding real module failures. Override with
+		 * -EBUSY and warn.
+		 *
+		 * Module authors: use -EBUSY or -EALREADY instead of -EEXIST.
+		 * See Documentation/kernel-hacking/hacking.rst
+		 */
 		if (ret == -EEXIST) {
 			pr_warn("%s: init suspiciously returned -EEXIST: Overriding with -EBUSY\n",
 				mod->name);

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] docs: hacking: clarify reserved -EEXIST in module_init()
  2025-12-18 20:59 [PATCH 0/2] module: add -EEXIST module_init() reservation docs Daniel Gomez
  2025-12-18 20:59 ` [PATCH 1/2] module: add -EEXIST documentation Daniel Gomez
@ 2025-12-18 20:59 ` Daniel Gomez
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Gomez @ 2025-12-18 20:59 UTC (permalink / raw)
  To: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen,
	Aaron Tomlin, Jonathan Corbet, Lucas De Marchi
  Cc: linux-modules, linux-kernel, linux-doc, Daniel Gomez

From: Daniel Gomez <da.gomez@samsung.com>

The error code -EEXIST is reserved by the kernel module loader to
indicate that a module with the same name is already loaded. Add
a warning note to clarify what these means for module authors and
maintainers to ensure the module_init() path return error do not
conflict with the reserved one.

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 Documentation/kernel-hacking/hacking.rst | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/kernel-hacking/hacking.rst b/Documentation/kernel-hacking/hacking.rst
index 0042776a9e17..2c929ab93143 100644
--- a/Documentation/kernel-hacking/hacking.rst
+++ b/Documentation/kernel-hacking/hacking.rst
@@ -459,6 +459,13 @@ to fail (unfortunately, this has no effect if the module is compiled
 into the kernel). This function is called in user context with
 interrupts enabled, so it can sleep.
 
+.. warning::
+
+    The error code ``-EEXIST`` is reserved by the module loader to
+    indicate a module is already loaded. kmod interprets this as success,
+    so ``module_init()`` must never return ``-EEXIST``. Use ``-EBUSY`` or
+    ``-EALREADY`` instead.
+
 :c:func:`module_exit()`
 -----------------------
 

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-18 21:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-18 20:59 [PATCH 0/2] module: add -EEXIST module_init() reservation docs Daniel Gomez
2025-12-18 20:59 ` [PATCH 1/2] module: add -EEXIST documentation Daniel Gomez
2025-12-18 20:59 ` [PATCH 2/2] docs: hacking: clarify reserved -EEXIST in module_init() Daniel Gomez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).