Commit 2c75d2cc authored by Jack Morgenstein's avatar Jack Morgenstein Committed by Roland Dreier

IB/mlx4: Fix QP1 P_Key processing in the Primary Physical Function (PPF)

In the MAD paravirtualization code, one of the checks performed when
forwarding QP1 (GSI) packets from wire to slave was a P_Key check: the
P_Key received in the MAD must be present in the guest's paravirtualized
P_Key table, and at least one of the (packet P_Key, guest P_Key) must
be a full-membership P_Key.

However, if everyone involved has only limited membership in the
default P_Key, then packets sent by full-member remote hosts arrive at
the PPF but are not passed on to the VFs with the current P_Key1 check.

Fix this as follows:

1. Don't care if P_Key received over wire is full or not. If it
   successfully passed HW checks on the real QP1, then simply pass it
   to guest regardless of whether the guest has full or limited
   membership in its P_Key table.

2. If the guest (including paravirtualized master) has both full and
   limited P_Key forms in its table, preferentially pass the
   paravirtualized P_Key index of the full P_Key form in the tunnel
   header.

3. In the multicast join flow (mlx4/mcg.c), use the index for the
   default P_Key (wherever it is located) in replies generated from
   within the mcg module (previously, P_Key index 0 was used in all
   cases).
Signed-off-by: default avatarJack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
parent 8a095030
...@@ -409,38 +409,45 @@ int mlx4_ib_find_real_gid(struct ib_device *ibdev, u8 port, __be64 guid) ...@@ -409,38 +409,45 @@ int mlx4_ib_find_real_gid(struct ib_device *ibdev, u8 port, __be64 guid)
} }
static int get_pkey_phys_indices(struct mlx4_ib_dev *ibdev, u8 port, u8 ph_pkey_ix, static int find_slave_port_pkey_ix(struct mlx4_ib_dev *dev, int slave,
u8 *full_pk_ix, u8 *partial_pk_ix, u8 port, u16 pkey, u16 *ix)
int *is_full_member)
{ {
u16 search_pkey; int i, ret;
int fm; u8 unassigned_pkey_ix, pkey_ix, partial_ix = 0xFF;
int err = 0; u16 slot_pkey;
u16 pk;
err = ib_get_cached_pkey(&ibdev->ib_dev, port, ph_pkey_ix, &search_pkey); if (slave == mlx4_master_func_num(dev->dev))
if (err) return ib_find_cached_pkey(&dev->ib_dev, port, pkey, ix);
return err;
fm = (search_pkey & 0x8000) ? 1 : 0; unassigned_pkey_ix = dev->dev->phys_caps.pkey_phys_table_len[port] - 1;
if (fm) {
*full_pk_ix = ph_pkey_ix; for (i = 0; i < dev->dev->caps.pkey_table_len[port]; i++) {
search_pkey &= 0x7FFF; if (dev->pkeys.virt2phys_pkey[slave][port - 1][i] == unassigned_pkey_ix)
continue;
pkey_ix = dev->pkeys.virt2phys_pkey[slave][port - 1][i];
ret = ib_get_cached_pkey(&dev->ib_dev, port, pkey_ix, &slot_pkey);
if (ret)
continue;
if ((slot_pkey & 0x7FFF) == (pkey & 0x7FFF)) {
if (slot_pkey & 0x8000) {
*ix = (u16) pkey_ix;
return 0;
} else { } else {
*partial_pk_ix = ph_pkey_ix; /* take first partial pkey index found */
search_pkey |= 0x8000; if (partial_ix == 0xFF)
partial_ix = pkey_ix;
}
}
} }
if (ib_find_exact_cached_pkey(&ibdev->ib_dev, port, search_pkey, &pk)) if (partial_ix < 0xFF) {
pk = 0xFFFF; *ix = (u16) partial_ix;
return 0;
if (fm) }
*partial_pk_ix = (pk & 0xFF);
else
*full_pk_ix = (pk & 0xFF);
*is_full_member = fm; return -EINVAL;
return err;
} }
int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port, int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port,
...@@ -458,10 +465,8 @@ int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port, ...@@ -458,10 +465,8 @@ int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port,
unsigned tun_tx_ix = 0; unsigned tun_tx_ix = 0;
int dqpn; int dqpn;
int ret = 0; int ret = 0;
int i;
int is_full_member = 0;
u16 tun_pkey_ix; u16 tun_pkey_ix;
u8 ph_pkey_ix, full_pk_ix = 0, partial_pk_ix = 0; u16 cached_pkey;
if (dest_qpt > IB_QPT_GSI) if (dest_qpt > IB_QPT_GSI)
return -EINVAL; return -EINVAL;
...@@ -481,27 +486,17 @@ int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port, ...@@ -481,27 +486,17 @@ int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port,
else else
tun_qp = &tun_ctx->qp[1]; tun_qp = &tun_ctx->qp[1];
/* compute pkey index for slave */ /* compute P_Key index to put in tunnel header for slave */
/* get physical pkey -- virtualized Dom0 pkey to phys*/
if (dest_qpt) { if (dest_qpt) {
ph_pkey_ix = u16 pkey_ix;
dev->pkeys.virt2phys_pkey[mlx4_master_func_num(dev->dev)][port - 1][wc->pkey_index]; ret = ib_get_cached_pkey(&dev->ib_dev, port, wc->pkey_index, &cached_pkey);
/* now, translate this to the slave pkey index */
ret = get_pkey_phys_indices(dev, port, ph_pkey_ix, &full_pk_ix,
&partial_pk_ix, &is_full_member);
if (ret) if (ret)
return -EINVAL; return -EINVAL;
for (i = 0; i < dev->dev->caps.pkey_table_len[port]; i++) { ret = find_slave_port_pkey_ix(dev, slave, port, cached_pkey, &pkey_ix);
if ((dev->pkeys.virt2phys_pkey[slave][port - 1][i] == full_pk_ix) || if (ret)
(is_full_member &&
(dev->pkeys.virt2phys_pkey[slave][port - 1][i] == partial_pk_ix)))
break;
}
if (i == dev->dev->caps.pkey_table_len[port])
return -EINVAL; return -EINVAL;
tun_pkey_ix = i; tun_pkey_ix = pkey_ix;
} else } else
tun_pkey_ix = dev->pkeys.virt2phys_pkey[slave][port - 1][0]; tun_pkey_ix = dev->pkeys.virt2phys_pkey[slave][port - 1][0];
......
...@@ -233,7 +233,8 @@ static int send_mad_to_slave(int slave, struct mlx4_ib_demux_ctx *ctx, ...@@ -233,7 +233,8 @@ static int send_mad_to_slave(int slave, struct mlx4_ib_demux_ctx *ctx,
ib_query_ah(dev->sm_ah[ctx->port - 1], &ah_attr); ib_query_ah(dev->sm_ah[ctx->port - 1], &ah_attr);
wc.pkey_index = 0; if (ib_find_cached_pkey(&dev->ib_dev, ctx->port, IB_DEFAULT_PKEY_FULL, &wc.pkey_index))
return -EINVAL;
wc.sl = 0; wc.sl = 0;
wc.dlid_path_bits = 0; wc.dlid_path_bits = 0;
wc.port_num = ctx->port; wc.port_num = ctx->port;
......
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