Re: [PATCH v1 07/25] lockdep: Add preemption disabled assertion API

Peter Zijlstra
2020-05-22T17:57:46Z

On Tue, May 19, 2020 at 11:45:29PM +0200, Ahmed S. Darwish wrote:
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index 206774ac6946..54c929ea5b98 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -702,6 +702,14 @@ do { \
> "Not in hardirq as expected\n"); \
> } while (0)
>
> +/*
> + * Don't define this assertion here to avoid a call-site's header file
> + * dependency on sched.h task_struct current. This is needed by call
> + * sites that are inline defined at header files already included by
> + * sched.h.
> + */
> +void lockdep_assert_preemption_disabled(void);

So how about:

#if defined(CONFIG_PREEMPT_COUNT) && defined(CONFIG_TRACE_IRQFLAGS)
#define lockdep_assert_preemption_disabled() do { \
WARN_ON(debug_locks && !preempt_count() && \
current->hardirqs_enabled); \
} while (0)
#else
#define lockdep_assert_preemption_disabled() do { } while (0)
#endif

That is both more consistent with the things you claim it's modelled
after and also completely avoids that header dependency.