Subject: Re: [RFT net-next 1/6] devlink: expose instance locking and add locked port registering

From: Leon Romanovsky <[email-masked]>
Date: Fri, 11 Mar 2022 20:19:42 +0200

On Fri, Mar 11, 2022 at 10:06:11AM -0800, Jakub Kicinski wrote:
> On Fri, 11 Mar 2022 19:49:36 +0200 Leon Romanovsky wrote:
> > > No, no, that function is mostly for rcu dereference checking.
> > > The calls should be eliminated as dead code on production systems.  
> > 
> > On systems without LOCKDEP, the devl_lock_is_held function will be
> > generated to be like this:
> > bool devl_lock_is_held(struct devlink *devlink)
> > {
> > 	return WARN_ON_ONCE(true);
> > }
> > EXPORT_SYMBOL_GPL(devl_lock_is_held);
> 
> I think you missed my first sentence. Anyway, this is what I'll do in
> v1:
> 
> #ifdef CONFIG_LOCKDEP
> /* For use in conjunction with LOCKDEP only e.g. rcu_dereference_protected() */
> bool devl_lock_is_held(struct devlink *devlink)
> {
> 	return lockdep_is_held(&devlink->lock);
> }
> EXPORT_SYMBOL_GPL(devl_lock_is_held);
> #endif

Because you put EXPORT_SYMBOL_GPL, this function will be used by drivers
too, which will need to write something like this:

if (IS_ENABLED(CONFIG_LOCKDEP))
     devl_lock_is_held(devlink)

Otherwise, they will get linkage error in systems without LOCKDEP.

Thanks