Skip to content

Commit 396f2fe

Browse files
Jack Morgensteinrolandd
authored andcommitted
mlx4_core: Implement mechanism for reserved Q_Keys
The SR-IOV special QP tunneling mechanism uses proxy special QPs (instead of the real special QPs) for MADs on guests. These proxy QPs send their packets to a "tunnel" QP owned by the master. The master then forwards the MAD (after any required paravirtualization) to the real special QP, which sends out the MAD. For security reasons (i.e., to prevent guests from sending MADs to tunnel QPs belonging to other guests), each proxy-tunnel QP pair is assigned a unique, reserved, Q_Key. These Q_Keys are available only for proxy and tunnel QPs -- if the guest tries to use these Q_Keys with other QPs, it will fail. This patch introduces a mechanism for reserving a block of 64K Q_Keys for proxy/tunneling use. The patch introduces also two new fields into mlx4_dev: base_sqpn and base_tunnel_sqpn. In SR-IOV mode, the QP numbers for the "real," proxy, and tunnel sqps are added to the reserved QPN area (so that they will not change). There are 8 special QPs per port in the HCA, and each of them is assigned both a proxy and a tunnel QP, for each VF and for the PF as well in SR-IOV mode. The QPNs for these QPs are arranged as follows: 1. The real SQP numbers (8) 2. The proxy SQPs (8 * (max number of VFs + max number of PFs) 3. The tunnel SQPs (8 * (max number of VFs + max number of PFs) To support these QPs, two new fields are added to struct mlx4_dev: base_sqp: this is the QP number of the first of the real SQPs base_tunnel_sqp: this is the qp number of the first qp in the tunnel sqp region. (On guests, this is the first tunnel sqp of the 8 which are assigned to that guest). In addition, in SR-IOV mode, sqp_start is the number of the first proxy SQP in the proxy SQP region. (In guests, this is the first proxy SQP of the 8 which are assigned to that guest) Note that in non-SR-IOV mode, there are no proxies and no tunnels. In this case, sqp_start is set to sqp_base -- which minimizes code changes. Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent 2aca117 commit 396f2fe

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx4/main.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ static int mlx4_how_many_lives_vf(struct mlx4_dev *dev)
391391
return ret;
392392
}
393393

394+
int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey)
395+
{
396+
u32 qk = MLX4_RESERVED_QKEY_BASE;
397+
if (qpn >= dev->caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX ||
398+
qpn < dev->caps.sqp_start)
399+
return -EINVAL;
400+
401+
if (qpn >= dev->caps.base_tunnel_sqpn)
402+
/* tunnel qp */
403+
qk += qpn - dev->caps.base_tunnel_sqpn;
404+
else
405+
qk += qpn - dev->caps.sqp_start;
406+
*qkey = qk;
407+
return 0;
408+
}
409+
EXPORT_SYMBOL(mlx4_get_parav_qkey);
410+
394411
int mlx4_is_slave_active(struct mlx4_dev *dev, int slave)
395412
{
396413
struct mlx4_priv *priv = mlx4_priv(dev);

‎include/linux/mlx4/device.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ enum {
5656
MLX4_MAX_PORTS = 2
5757
};
5858

59+
/* base qkey for use in sriov tunnel-qp/proxy-qp communication.
60+
* These qkeys must not be allowed for general use. This is a 64k range,
61+
* and to test for violation, we use the mask (protect against future chg).
62+
*/
63+
#define MLX4_RESERVED_QKEY_BASE (0xFFFF0000)
64+
#define MLX4_RESERVED_QKEY_MASK (0xFFFF0000)
65+
5966
enum {
6067
MLX4_BOARD_ID_LEN = 64
6168
};
@@ -293,6 +300,8 @@ struct mlx4_caps {
293300
int max_qp_init_rdma;
294301
int max_qp_dest_rdma;
295302
int sqp_start;
303+
u32 base_sqpn;
304+
u32 base_tunnel_sqpn;
296305
int num_srqs;
297306
int max_srq_wqes;
298307
int max_srq_sge;
@@ -772,4 +781,6 @@ int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port);
772781
int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
773782
void mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
774783

784+
int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey);
785+
775786
#endif /* MLX4_DEVICE_H */

0 commit comments

Comments
 (0)