This prevents a user fd from being opened when osnoise_options_write() has already stopped threads but not yet set OSN_WORKLOAD, and matches what all callers of start_kthread() do.
The original intent was probably for interface_lock to cover things like this, but it never covered the full race window, and currently can't due to lock order issues stemming from using interface_lock in osnoise_sleep(). There does not appear to be any remaining reason to take interface_lock in timerlat_fd_open(), so remove it. Signed-off-by: Crystal Wood <[email protected]> --- Do we really need that interface_lock in osnoise_sleep()? Technically we should probably be grabbing it every time we access osnoise_data, but we don't seem to do so anywhere else. Perhaps this was due to concerns about the atomicity of "period - runtime", but that's just synchronization theater given that userspace has no way of writing to both atomically. In any case, we shouldn't use the same lock for protecting osnoise_data members that we use for major reconfiguration procedures. --- kernel/trace/trace_osnoise.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 0f27af6ade3e..3d12ce8a591e 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -2466,16 +2466,14 @@ static int timerlat_fd_open(struct inode *inode, struct file *file) long cpu = (long) inode->i_cdev; int ret = 0; - mutex_lock(&interface_lock); + guard(mutex)(&trace_types_lock); /* * This file is accessible only if timerlat is enabled, and * NO_OSNOISE_WORKLOAD is set. */ - if (!timerlat_enabled() || test_bit(OSN_WORKLOAD, &osnoise_options)) { - mutex_unlock(&interface_lock); + if (!timerlat_enabled() || test_bit(OSN_WORKLOAD, &osnoise_options)) return -EINVAL; - } migrate_disable(); @@ -2524,7 +2522,6 @@ static int timerlat_fd_open(struct inode *inode, struct file *file) * Setup is done. */ mutex_unlock(&osn_var->lock); - mutex_unlock(&interface_lock); tlat = this_cpu_tmr_var(); tlat->count = 0; @@ -2536,7 +2533,6 @@ static int timerlat_fd_open(struct inode *inode, struct file *file) err: mutex_unlock(&osn_var->lock); - mutex_unlock(&interface_lock); migrate_enable(); return ret; }; -- 2.54.0
