• Jiri Pirko's avatar
    net: devlink: make sure that devlink_try_get() works with valid pointer during xarray iteration · 30bab7cd
    Jiri Pirko authored
    Remove dependency on devlink_mutex during devlinks xarray iteration.
    
    The reason is that devlink_register/unregister() functions taking
    devlink_mutex would deadlock during devlink reload operation of devlink
    instance which registers/unregisters nested devlink instances.
    
    The devlinks xarray consistency is ensured internally by xarray.
    There is a reference taken when working with devlink using
    devlink_try_get(). But there is no guarantee that devlink pointer
    picked during xarray iteration is not freed before devlink_try_get()
    is called.
    
    Make sure that devlink_try_get() works with valid pointer.
    Achieve it by:
    1) Splitting devlink_put() so the completion is sent only
       after grace period. Completion unblocks the devlink_unregister()
       routine, which is followed-up by devlink_free()
    2) During devlinks xa_array iteration, get devlink pointer from xa_array
       holding RCU read lock and taking reference using devlink_try_get()
       before unlock.
    Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
    Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    30bab7cd
devlink.c 319 KB