Re: [PATCH 5/8] module: Add module_for_each_mod() function

From: Steven Rostedt
Date: Fri Feb 14 2025 - 17:30:12 EST


On Thu, 6 Feb 2025 10:27:20 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> > BTW, do we really need to disable preempt or is it enough to call
> > rcu_read_lock()?
>
> Bah, as I expected this function to be changed, I didn't spend too much
> time on looking at its implementation. I just cut and pasted how the other
> loops worked. But yes, it should not be disabling preemption. In fact, I
> think the module code itself should not be disabling preemption!
>
> I'll have to go and look into that.

It really looks like it requires preempt_disable(), as the code in
kernel/module/main.c has in several places:

preempt_disable();

list_for_each_entry_rcu(mod, &modules, list) {
[..]
}

preempt_enable();

Or

module_assert_mutex_or_preempt();

[..]

list_for_each_entry_rcu(mod, &modules, list,
lockdep_is_held(&module_mutex)) {


So it looks like it either requires preempt_disable or holding the
module_mutex.

As I need to call this with trace_types_lock held, and there's a place
where trace_types_lock is within a module callback, I don't think it's safe
to take that lock in that loop, otherwise we have the ABBA deadlock.

Luis,

Is this patch OK, and also is there any plan to move the module code to
using just rcu_read_lock instead of preempt_disable?

-- Steve