• Amit Cohen's avatar
    mlxsw: spectrum_ptp: Protect PTP configuration with a mutex · d72fdef2
    Amit Cohen authored
    Currently the functions mlxsw_sp2_ptp_{configure, deconfigure}_port()
    assume that they are called when RTNL is locked and they warn otherwise.
    
    The deconfigure function can be called when port is removed, for example
    as part of device reload, then there is no locked RTNL and the function
    warns [1].
    
    To avoid such case, do not assume that RTNL protects this code, add a
    dedicated mutex instead. The mutex protects 'ptp_state->config' which
    stores the existing global configuration in hardware. Use this mutex also
    to protect the code which configures the hardware. Then, there will be
    only one configuration in any time, which will be updated in 'ptp_state'
    and a race will be avoided.
    
    [1]:
    RTNL: assertion failed at drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c (1600)
    WARNING: CPU: 1 PID: 1583493 at drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c:1600 mlxsw_sp2_ptp_hwtstamp_set+0x2d3/0x300 [mlxsw_spectrum]
    [...]
    CPU: 1 PID: 1583493 Comm: devlink Not tainted5.19.0-rc8-custom-127022-gb371dffda095 #789
    Hardware name: Mellanox Technologies Ltd.MSN3420/VMOD0005, BIOS 5.11 01/06/2019
    RIP: 0010:mlxsw_sp2_ptp_hwtstamp_set+0x2d3/0x300[mlxsw_spectrum]
    [...]
    Call Trace:
     <TASK>
     mlxsw_sp_port_remove+0x7e/0x190 [mlxsw_spectrum]
     mlxsw_sp_fini+0xd1/0x270 [mlxsw_spectrum]
     mlxsw_core_bus_device_unregister+0x55/0x280 [mlxsw_core]
     mlxsw_devlink_core_bus_device_reload_down+0x1c/0x30[mlxsw_core]
     devlink_reload+0x1ee/0x230
     devlink_nl_cmd_reload+0x4de/0x580
     genl_family_rcv_msg_doit+0xdc/0x140
     genl_rcv_msg+0xd7/0x1d0
     netlink_rcv_skb+0x49/0xf0
     genl_rcv+0x1f/0x30
     netlink_unicast+0x22f/0x350
     netlink_sendmsg+0x208/0x440
     __sys_sendto+0xf0/0x140
     __x64_sys_sendto+0x1b/0x20
     do_syscall_64+0x35/0x80
     entry_SYSCALL_64_after_hwframe+0x63/0xcd
    
    Fixes: 08ef8bc8 ("mlxsw: spectrum_ptp: Support SIOCGHWTSTAMP, SIOCSHWTSTAMP ioctls")
    Reported-by: default avatarIdo Schimmel <idosch@nvidia.com>
    Signed-off-by: default avatarAmit Cohen <amcohen@nvidia.com>
    Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
    Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    d72fdef2
spectrum_ptp.c 45.4 KB