From: julian-lagattuta <julian.lagattuta@gmail.com>
To: Luis Chamberlain <mcgrof@kernel.org>, Petr Pavlu <petr.pavlu@suse.com>
Cc: Sami Tolvanen <samitolvanen@google.com>,
Daniel Gomez <da.gomez@samsung.com>,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
julian-lagattuta <julian.lagattuta@gmail.com>
Subject: [PATCH 5/6] module: store and complete idempotent upon force unloading
Date: Thu, 18 Sep 2025 16:11:14 -0400 [thread overview]
Message-ID: <20250918201109.24620-12-julian.lagattuta@gmail.com> (raw)
In-Reply-To: <20250918201109.24620-2-julian.lagattuta@gmail.com>
Move idempotent definition up and add idempotent_complete declaration.
Add idempotent to struct load_info which gets passed into load_module
and then stored in the struct module.
run idempotent_complete after module is unloaded and give EBUSY
to any process waiting for the module to finish initializing
via finit_module.
Signed-off-by: julian-lagattuta <julian.lagattuta@gmail.com>
---
kernel/module/internal.h | 3 +++
kernel/module/main.c | 29 +++++++++++++++++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/kernel/module/internal.h b/kernel/module/internal.h
index 8d74b0a21c82..43f537475859 100644
--- a/kernel/module/internal.h
+++ b/kernel/module/internal.h
@@ -89,6 +89,9 @@ struct load_info {
unsigned int vers_ext_crc;
unsigned int vers_ext_name;
} index;
+#ifdef CONFIG_MODULE_FORCE_UNLOAD
+ struct idempotent* idempotent;
+#endif
};
enum mod_license {
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 217185dbc3c1..256e30259bcf 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -80,6 +80,17 @@ static void do_free_init(struct work_struct *w);
static DECLARE_WORK(init_free_wq, do_free_init);
static LLIST_HEAD(init_free_list);
+
+struct idempotent {
+ const void *cookie;
+ struct hlist_node entry;
+ struct completion complete;
+ int ret;
+};
+
+static int idempotent_complete(struct idempotent *u, int ret);
+
+
struct mod_tree_root mod_tree __cacheline_aligned = {
.addr_min = -1UL,
};
@@ -784,7 +795,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
!IS_ENABLED(CONFIG_MODULE_FORCE_UNLOAD))
) {
if (mod->state == MODULE_STATE_GOING)
- pr_debug("%s already dying\n", mod->name);
+ pr_debug("%s already dying\n", mod->name);
ret = -EBUSY;
goto out;
}
@@ -833,6 +844,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
strscpy(last_unloaded_module.name, mod->name);
strscpy(last_unloaded_module.taints, module_flags(mod, buf, false));
+#ifdef CONFIG_MODULE_FORCE_UNLOAD
+ if (did_init_crash && mod->idempotent)
+ idempotent_complete(mod->idempotent, -EBUSY);
+#endif
+
free_module(mod);
/* someone could wait for the module in add_unformed_module() */
wake_up_all(&module_wq);
@@ -3591,12 +3607,6 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
return load_module(&info, uargs, 0);
}
-struct idempotent {
- const void *cookie;
- struct hlist_node entry;
- struct completion complete;
- int ret;
-};
#define IDEM_HASH_BITS 8
static struct hlist_head idem_hash[1 << IDEM_HASH_BITS];
@@ -3683,7 +3693,7 @@ static int idempotent_wait_for_completion(struct idempotent *u)
return ret;
}
-static int init_module_from_file(struct file *f, const char __user * uargs, int flags)
+static int init_module_from_file(struct file *f, const char __user * uargs, int flags, struct idempotent *idempotent __maybe_unused)
{
struct load_info info = { };
void *buf = NULL;
@@ -3707,6 +3717,9 @@ static int init_module_from_file(struct file *f, const char __user * uargs, int
info.hdr = buf;
info.len = len;
}
+#ifdef CONFIG_MODULE_FORCE_UNLOAD
+ info.idempotent = idempotent;
+#endif
return load_module(&info, uargs, flags);
}
--
2.45.2
next prev parent reply other threads:[~2025-09-18 20:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 20:11 [PATCH 0/6] module: enable force unloading of modules that have crashed during init julian-lagattuta
2025-09-18 20:11 ` [PATCH 1/6] module: store init_pid and idempotent in module julian-lagattuta
2025-09-18 20:11 ` [PATCH 2/6] module: detect if init crashed and unload julian-lagattuta
2025-09-18 20:11 ` [PATCH 3/6] module: move freeinit allocation to avoid memory leak julian-lagattuta
2025-09-18 20:11 ` [PATCH 4/6] module: move idempotent allocation to heap julian-lagattuta
2025-09-18 20:11 ` julian-lagattuta [this message]
2025-09-18 20:11 ` [PATCH 6/6] module: comment describing new codepath julian-lagattuta
2025-09-23 7:21 ` [PATCH 0/6] module: enable force unloading of modules that have crashed during init Petr Pavlu
2025-09-24 22:16 ` Julian LaGattuta
2025-09-30 13:16 ` Petr Pavlu
2025-09-30 15:51 ` Julian LaGattuta
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=20250918201109.24620-12-julian.lagattuta@gmail.com \
--to=julian.lagattuta@gmail.com \
--cc=da.gomez@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
/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
all inboxes | Powered by JetHome®