Commit d3d010b3 authored by Talat Batheesh's avatar Talat Batheesh Committed by Ben Hutchings

net/mlx4: Fix the check in attaching steering rules

commit 6dc06c08 upstream.

Our previous patch (cited below) introduced a regression
for RAW Eth QPs.

Fix it by checking if the QP number provided by user-space
exists, hence allowing steering rules to be added for valid
QPs only.

Fixes: 89c55768 ("net/mlx4_en: Avoid adding steering rules with invalid ring")
Reported-by: default avatarOr Gerlitz <gerlitz.or@gmail.com>
Signed-off-by: default avatarTalat Batheesh <talatb@mellanox.com>
Signed-off-by: default avatarTariq Toukan <tariqt@mellanox.com>
Acked-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 14216e1b
...@@ -930,11 +930,6 @@ static int mlx4_en_flow_replace(struct net_device *dev, ...@@ -930,11 +930,6 @@ static int mlx4_en_flow_replace(struct net_device *dev,
qpn = priv->drop_qp.qpn; qpn = priv->drop_qp.qpn;
else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) { else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) {
qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1); qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1);
if (qpn < priv->rss_map.base_qpn ||
qpn >= priv->rss_map.base_qpn + priv->rx_ring_num) {
en_warn(priv, "rxnfc: QP (0x%x) doesn't exist\n", qpn);
return -EINVAL;
}
} else { } else {
if (cmd->fs.ring_cookie >= priv->rx_ring_num) { if (cmd->fs.ring_cookie >= priv->rx_ring_num) {
en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist\n", en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist\n",
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/mlx4/cmd.h> #include <linux/mlx4/cmd.h>
#include <linux/mlx4/qp.h>
#include <linux/export.h> #include <linux/export.h>
#include "mlx4.h" #include "mlx4.h"
...@@ -889,16 +890,21 @@ int mlx4_flow_attach(struct mlx4_dev *dev, ...@@ -889,16 +890,21 @@ int mlx4_flow_attach(struct mlx4_dev *dev,
if (IS_ERR(mailbox)) if (IS_ERR(mailbox))
return PTR_ERR(mailbox); return PTR_ERR(mailbox);
if (!mlx4_qp_lookup(dev, rule->qpn)) {
mlx4_err_rule(dev, "QP doesn't exist\n", rule);
ret = -EINVAL;
goto out;
}
trans_rule_ctrl_to_hw(rule, mailbox->buf); trans_rule_ctrl_to_hw(rule, mailbox->buf);
size += sizeof(struct mlx4_net_trans_rule_hw_ctrl); size += sizeof(struct mlx4_net_trans_rule_hw_ctrl);
list_for_each_entry(cur, &rule->list, list) { list_for_each_entry(cur, &rule->list, list) {
ret = parse_trans_rule(dev, cur, mailbox->buf + size); ret = parse_trans_rule(dev, cur, mailbox->buf + size);
if (ret < 0) { if (ret < 0)
mlx4_free_cmd_mailbox(dev, mailbox); goto out;
return ret;
}
size += ret; size += ret;
} }
...@@ -910,6 +916,7 @@ int mlx4_flow_attach(struct mlx4_dev *dev, ...@@ -910,6 +916,7 @@ int mlx4_flow_attach(struct mlx4_dev *dev,
else if (ret) else if (ret)
mlx4_err_rule(dev, "Fail to register network rule\n", rule); mlx4_err_rule(dev, "Fail to register network rule\n", rule);
out:
mlx4_free_cmd_mailbox(dev, mailbox); mlx4_free_cmd_mailbox(dev, mailbox);
return ret; return ret;
......
...@@ -355,6 +355,19 @@ static void mlx4_qp_free_icm(struct mlx4_dev *dev, int qpn) ...@@ -355,6 +355,19 @@ static void mlx4_qp_free_icm(struct mlx4_dev *dev, int qpn)
__mlx4_qp_free_icm(dev, qpn); __mlx4_qp_free_icm(dev, qpn);
} }
struct mlx4_qp *mlx4_qp_lookup(struct mlx4_dev *dev, u32 qpn)
{
struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table;
struct mlx4_qp *qp;
spin_lock(&qp_table->lock);
qp = __mlx4_qp_lookup(dev, qpn);
spin_unlock(&qp_table->lock);
return qp;
}
int mlx4_qp_alloc(struct mlx4_dev *dev, int qpn, struct mlx4_qp *qp, gfp_t gfp) int mlx4_qp_alloc(struct mlx4_dev *dev, int qpn, struct mlx4_qp *qp, gfp_t gfp)
{ {
struct mlx4_priv *priv = mlx4_priv(dev); struct mlx4_priv *priv = mlx4_priv(dev);
......
...@@ -429,6 +429,7 @@ struct mlx4_update_qp_params { ...@@ -429,6 +429,7 @@ struct mlx4_update_qp_params {
u8 smac_index; u8 smac_index;
}; };
struct mlx4_qp *mlx4_qp_lookup(struct mlx4_dev *dev, u32 qpn);
int mlx4_update_qp(struct mlx4_dev *dev, struct mlx4_qp *qp, int mlx4_update_qp(struct mlx4_dev *dev, struct mlx4_qp *qp,
enum mlx4_update_qp_attr attr, enum mlx4_update_qp_attr attr,
struct mlx4_update_qp_params *params); struct mlx4_update_qp_params *params);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment