linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: peterz@infradead.org
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, paulmck@kernel.org, joel@joelfernandes.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	rcu@vger.kernel.org, josh@joshtriplett.org,
	christian.brauner@ubuntu.com, mingo@redhat.com, will@kernel.org
Subject: Re: [PATCH net-next 6/7] lockdep: provide dummy forward declaration of *_is_held() helpers
Date: Thu, 17 Sep 2020 17:14:29 +0200	[thread overview]
Message-ID: <20200917151429.GJ1362448@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200916184528.498184-7-kuba@kernel.org>

On Wed, Sep 16, 2020 at 11:45:27AM -0700, Jakub Kicinski wrote:
> When CONFIG_LOCKDEP is not set, lock_is_held() and lockdep_is_held()
> are not declared or defined. This forces all callers to use ifdefs
> around these checks.
> 
> Recent RCU changes added a lot of lockdep_is_held() calls inside
> rcu_dereference_protected(). rcu_dereference_protected() hides
> its argument on !LOCKDEP builds, but this may lead to unused variable
> warnings.
> 
> Provide forward declarations of lock_is_held() and lockdep_is_held()
> but never define them. This way callers can keep them visible to
> the compiler on !LOCKDEP builds and instead depend on dead code
> elimination to remove the references before the linker barfs.
> 
> We need lock_is_held() for RCU.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> --
> CC: peterz@infradead.org
> CC: mingo@redhat.com
> CC: will@kernel.org
> ---
>  include/linux/lockdep.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index 6a584b3e5c74..6b5bbc536bf6 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -371,6 +371,12 @@ static inline void lockdep_unregister_key(struct lock_class_key *key)
>  
>  #define lockdep_depth(tsk)	(0)
>  
> +/*
> + * Dummy forward declarations, allow users to write less ifdef-y code
> + * and depend on dead code elimination.
> + */
> +int lock_is_held(const void *);

extern int lock_is_held(const struct lockdep_map *);

> +int lockdep_is_held(const void *);

extern

I suppose we can't pull the lockdep_is_held() definition out from under
CONFIG_LOCKDEP because it does the ->dep_map dereference and many types
will simply not have that member.

>  #define lockdep_is_held_type(l, r)		(1)
>  
>  #define lockdep_assert_held(l)			do { (void)(l); } while (0)

  reply	other threads:[~2020-09-17 15:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 18:45 [PATCH net-next 0/7] rcu: prevent RCU_LOCKDEP_WARN() from swallowing the condition Jakub Kicinski
2020-09-16 18:45 ` [PATCH net-next 1/7] sched: un-hide lockdep_tasklist_lock_is_held() for !LOCKDEP Jakub Kicinski
2020-09-16 18:45 ` [PATCH net-next 2/7] rcu: un-hide lockdep maps " Jakub Kicinski
2020-09-16 18:45 ` [PATCH net-next 3/7] net: un-hide lockdep_sock_is_held() " Jakub Kicinski
2020-09-16 18:45 ` [PATCH net-next 4/7] net: sched: remove broken definitions and un-hide " Jakub Kicinski
2020-09-16 18:45 ` [PATCH net-next 5/7] srcu: use a more appropriate lockdep helper Jakub Kicinski
2020-09-16 18:45 ` [PATCH net-next 6/7] lockdep: provide dummy forward declaration of *_is_held() helpers Jakub Kicinski
2020-09-17 15:14   ` peterz [this message]
2020-09-16 18:45 ` [PATCH net-next 7/7] rcu: prevent RCU_LOCKDEP_WARN() from swallowing the condition Jakub Kicinski
2020-09-16 23:15 ` [PATCH net-next 0/7] " Paul E. McKenney
2020-09-17  0:48   ` Jakub Kicinski

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=20200917151429.GJ1362448@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=davem@davemloft.net \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).