• Eran Ben Elisha's avatar
    net/mlx5: Avoid possible free of command entry while timeout comp handler · 50b2412b
    Eran Ben Elisha authored
    Upon command completion timeout, driver simulates a forced command
    completion. In a rare case where real interrupt for that command arrives
    simultaneously, it might release the command entry while the forced
    handler might still access it.
    
    Fix that by adding an entry refcount, to track current amount of allowed
    handlers. Command entry to be released only when this refcount is
    decremented to zero.
    
    Command refcount is always initialized to one. For callback commands,
    command completion handler is the symmetric flow to decrement it. For
    non-callback commands, it is wait_func().
    
    Before ringing the doorbell, increment the refcount for the real completion
    handler. Once the real completion handler is called, it will decrement it.
    
    For callback commands, once the delayed work is scheduled, increment the
    refcount. Upon callback command completion handler, we will try to cancel
    the timeout callback. In case of success, we need to decrement the callback
    refcount as it will never run.
    
    In addition, gather the entry index free and the entry free into a one
    flow for all command types release.
    
    Fixes: e126ba97 ("mlx5: Add driver for Mellanox Connect-IB adapters")
    Signed-off-by: default avatarEran Ben Elisha <eranbe@mellanox.com>
    Reviewed-by: default avatarMoshe Shemesh <moshe@mellanox.com>
    Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
    50b2412b
cmd.c 56.3 KB