]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net/mlx5e: Use READ_ONCE/WRITE_ONCE for DCBX trust state
authorMaxim Mikityanskiy <maximmi@nvidia.com>
Tue, 25 Jan 2022 10:52:56 +0000 (12:52 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 15 Feb 2022 06:30:51 +0000 (22:30 -0800)
trust_state can be written while mlx5e_select_queue() is reading it. To
avoid inconsistencies, use READ_ONCE and WRITE_ONCE for access and
updates, and touch the variable only once per operation.

Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en/selq.c
drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c

index aab2046da45b02626da3e28acac9c19d44e9a54e..b8f1a955944dfc325176af9f413c06bc60b2e399 100644 (file)
@@ -113,7 +113,7 @@ static int mlx5e_get_dscp_up(struct mlx5e_priv *priv, struct sk_buff *skb)
 static int mlx5e_get_up(struct mlx5e_priv *priv, struct sk_buff *skb)
 {
 #ifdef CONFIG_MLX5_CORE_EN_DCB
-       if (priv->dcbx_dp.trust_state == MLX5_QPTS_TRUST_DSCP)
+       if (READ_ONCE(priv->dcbx_dp.trust_state) == MLX5_QPTS_TRUST_DSCP)
                return mlx5e_get_dscp_up(priv, skb);
 #endif
        if (skb_vlan_tag_present(skb))
index a4c8d8d00d5a444578c37ee0e005c0ea5982ef43..d659fe07d46452b563fc0fdc2ac59821fb04e495 100644 (file)
@@ -1142,7 +1142,7 @@ static int mlx5e_update_trust_state_hw(struct mlx5e_priv *priv, void *context)
        err = mlx5_set_trust_state(priv->mdev, *trust_state);
        if (err)
                return err;
-       priv->dcbx_dp.trust_state = *trust_state;
+       WRITE_ONCE(priv->dcbx_dp.trust_state, *trust_state);
 
        return 0;
 }
@@ -1187,16 +1187,18 @@ static int mlx5e_set_dscp2prio(struct mlx5e_priv *priv, u8 dscp, u8 prio)
 static int mlx5e_trust_initialize(struct mlx5e_priv *priv)
 {
        struct mlx5_core_dev *mdev = priv->mdev;
+       u8 trust_state;
        int err;
 
-       priv->dcbx_dp.trust_state = MLX5_QPTS_TRUST_PCP;
-
-       if (!MLX5_DSCP_SUPPORTED(mdev))
+       if (!MLX5_DSCP_SUPPORTED(mdev)) {
+               WRITE_ONCE(priv->dcbx_dp.trust_state, MLX5_QPTS_TRUST_PCP);
                return 0;
+       }
 
-       err = mlx5_query_trust_state(priv->mdev, &priv->dcbx_dp.trust_state);
+       err = mlx5_query_trust_state(priv->mdev, &trust_state);
        if (err)
                return err;
+       WRITE_ONCE(priv->dcbx_dp.trust_state, trust_state);
 
        mlx5e_params_calc_trust_tx_min_inline_mode(priv->mdev, &priv->channels.params,
                                                   priv->dcbx_dp.trust_state);