Re: [PATCH v17 2/6] ring-buffer: Introducing ring-buffer mapping functions

Steven Rostedt
2024-02-13T20:51:40Z

On Tue, 13 Feb 2024 11:49:41 +0000
Vincent Donnefort <vdonnefort@google.com> wrote:

Did you test with lockdep?

> +static int __rb_inc_dec_mapped(struct trace_buffer *buffer,
> + struct ring_buffer_per_cpu *cpu_buffer,
> + bool inc)
> +{
> + unsigned long flags;
> +
> + lockdep_assert_held(cpu_buffer->mapping_lock);

/work/git/linux-trace.git/kernel/trace/ring_buffer.c: In function ‘__rb_inc_dec_mapped’:
/work/git/linux-trace.git/include/linux/lockdep.h:234:61: error: invalid type argument of ‘->’ (have ‘struct mutex’)
234 | #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
| ^~
/work/git/linux-trace.git/include/asm-generic/bug.h:123:32: note: in definition of macro ‘WARN_ON’
123 | int __ret_warn_on = !!(condition); \
| ^~~~~~~~~
/work/git/linux-trace.git/include/linux/lockdep.h:267:9: note: in expansion of macro ‘lockdep_assert’
267 | lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
| ^~~~~~~~~~~~~~
/work/git/linux-trace.git/include/linux/lockdep.h:267:24: note: in expansion of macro ‘lockdep_is_held’
267 | lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
| ^~~~~~~~~~~~~~~
/work/git/linux-trace.git/kernel/trace/ring_buffer.c:6167:9: note: in expansion of macro ‘lockdep_assert_held’
6167 | lockdep_assert_held(cpu_buffer->mapping_lock);
| ^~~~~~~~~~~~~~~~~~~

I believe that is supposed to be:

lockdep_assert_held(&cpu_buffer->mapping_lock);

-- Steve

> +
> + if (inc && cpu_buffer->mapped == UINT_MAX)
> + return -EBUSY;
> +
> + if (WARN_ON(!inc && cpu_buffer->mapped == 0))
> + return -EINVAL;
> +
> + mutex_lock(&buffer->mutex);
> + raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> +
> + if (inc)
> + cpu_buffer->mapped++;
> + else
> + cpu_buffer->mapped--;
> +
> + raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
> + mutex_unlock(&buffer->mutex);
> +
> + return 0;
> +}