Skip to content

Commit 5061e34

Browse files
committed
Merge branch 'mlxsw-fixes'
Petr Machata says: ==================== mlxsw: Fixes for PTP support This set fixes several issues in mlxsw PTP code. - Patch #1 fixes compilation warnings. - Patch #2 adjusts the order of operation during cleanup, thereby closing the window after PTP state was already cleaned in the ASIC for the given port, but before the port is removed, when the user could still in theory make changes to the configuration. - Patch #3 protects the PTP configuration with a custom mutex, instead of relying on RTNL, which is not held in all access paths. - Patch #4 forbids enablement of PTP only in RX or only in TX. The driver implicitly assumed this would be the case, but neglected to sanitize the configuration. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 0279957 + e01885c commit 5061e34

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1897,9 +1897,9 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
18971897

18981898
cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw);
18991899
cancel_delayed_work_sync(&mlxsw_sp_port->ptp.shaper_dw);
1900-
mlxsw_sp_port_ptp_clear(mlxsw_sp_port);
19011900
mlxsw_core_port_clear(mlxsw_sp->core, local_port, mlxsw_sp);
19021901
unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */
1902+
mlxsw_sp_port_ptp_clear(mlxsw_sp_port);
19031903
mlxsw_sp_port_vlan_classification_set(mlxsw_sp_port, true, true);
19041904
mlxsw_sp->ports[local_port] = NULL;
19051905
mlxsw_sp_port_vlan_flush(mlxsw_sp_port, true);

drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c

+23-7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct mlxsw_sp2_ptp_state {
4646
* enabled.
4747
*/
4848
struct hwtstamp_config config;
49+
struct mutex lock; /* Protects 'config' and HW configuration. */
4950
};
5051

5152
struct mlxsw_sp1_ptp_key {
@@ -1374,6 +1375,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
13741375
goto err_ptp_traps_set;
13751376

13761377
refcount_set(&ptp_state->ptp_port_enabled_ref, 0);
1378+
mutex_init(&ptp_state->lock);
13771379
return &ptp_state->common;
13781380

13791381
err_ptp_traps_set:
@@ -1388,6 +1390,7 @@ void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state_common)
13881390

13891391
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp);
13901392

1393+
mutex_destroy(&ptp_state->lock);
13911394
mlxsw_sp_ptp_traps_unset(mlxsw_sp);
13921395
kfree(ptp_state);
13931396
}
@@ -1461,7 +1464,10 @@ int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
14611464

14621465
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
14631466

1467+
mutex_lock(&ptp_state->lock);
14641468
*config = ptp_state->config;
1469+
mutex_unlock(&ptp_state->lock);
1470+
14651471
return 0;
14661472
}
14671473

@@ -1523,6 +1529,9 @@ mlxsw_sp2_ptp_get_message_types(const struct hwtstamp_config *config,
15231529
return -EINVAL;
15241530
}
15251531

1532+
if ((ing_types && !egr_types) || (!ing_types && egr_types))
1533+
return -EINVAL;
1534+
15261535
*p_ing_types = ing_types;
15271536
*p_egr_types = egr_types;
15281537
return 0;
@@ -1574,8 +1583,6 @@ static int mlxsw_sp2_ptp_configure_port(struct mlxsw_sp_port *mlxsw_sp_port,
15741583
struct mlxsw_sp2_ptp_state *ptp_state;
15751584
int err;
15761585

1577-
ASSERT_RTNL();
1578-
15791586
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
15801587

15811588
if (refcount_inc_not_zero(&ptp_state->ptp_port_enabled_ref))
@@ -1597,8 +1604,6 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port,
15971604
struct mlxsw_sp2_ptp_state *ptp_state;
15981605
int err;
15991606

1600-
ASSERT_RTNL();
1601-
16021607
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
16031608

16041609
if (!refcount_dec_and_test(&ptp_state->ptp_port_enabled_ref))
@@ -1618,16 +1623,20 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port,
16181623
int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
16191624
struct hwtstamp_config *config)
16201625
{
1626+
struct mlxsw_sp2_ptp_state *ptp_state;
16211627
enum hwtstamp_rx_filters rx_filter;
16221628
struct hwtstamp_config new_config;
16231629
u16 new_ing_types, new_egr_types;
16241630
bool ptp_enabled;
16251631
int err;
16261632

1633+
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
1634+
mutex_lock(&ptp_state->lock);
1635+
16271636
err = mlxsw_sp2_ptp_get_message_types(config, &new_ing_types,
16281637
&new_egr_types, &rx_filter);
16291638
if (err)
1630-
return err;
1639+
goto err_get_message_types;
16311640

16321641
new_config.flags = config->flags;
16331642
new_config.tx_type = config->tx_type;
@@ -1640,20 +1649,27 @@ int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
16401649
err = mlxsw_sp2_ptp_configure_port(mlxsw_sp_port, new_ing_types,
16411650
new_egr_types, new_config);
16421651
if (err)
1643-
return err;
1652+
goto err_configure_port;
16441653
} else if (!new_ing_types && !new_egr_types && ptp_enabled) {
16451654
err = mlxsw_sp2_ptp_deconfigure_port(mlxsw_sp_port, new_config);
16461655
if (err)
1647-
return err;
1656+
goto err_deconfigure_port;
16481657
}
16491658

16501659
mlxsw_sp_port->ptp.ing_types = new_ing_types;
16511660
mlxsw_sp_port->ptp.egr_types = new_egr_types;
16521661

16531662
/* Notify the ioctl caller what we are actually timestamping. */
16541663
config->rx_filter = rx_filter;
1664+
mutex_unlock(&ptp_state->lock);
16551665

16561666
return 0;
1667+
1668+
err_deconfigure_port:
1669+
err_configure_port:
1670+
err_get_message_types:
1671+
mutex_unlock(&ptp_state->lock);
1672+
return err;
16571673
}
16581674

16591675
int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,

drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
171171
{
172172
}
173173

174-
int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
175-
struct mlxsw_sp_port *mlxsw_sp_port,
176-
struct sk_buff *skb,
177-
const struct mlxsw_tx_info *tx_info)
174+
static inline int
175+
mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
176+
struct mlxsw_sp_port *mlxsw_sp_port,
177+
struct sk_buff *skb,
178+
const struct mlxsw_tx_info *tx_info)
178179
{
179180
return -EOPNOTSUPP;
180181
}
@@ -231,10 +232,11 @@ static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
231232
return mlxsw_sp_ptp_get_ts_info_noptp(info);
232233
}
233234

234-
int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
235-
struct mlxsw_sp_port *mlxsw_sp_port,
236-
struct sk_buff *skb,
237-
const struct mlxsw_tx_info *tx_info)
235+
static inline int
236+
mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
237+
struct mlxsw_sp_port *mlxsw_sp_port,
238+
struct sk_buff *skb,
239+
const struct mlxsw_tx_info *tx_info)
238240
{
239241
return -EOPNOTSUPP;
240242
}

0 commit comments

Comments
 (0)