net/mlx4_core: Prevent VF from changing port configuration
authorSaeed Mahameed <saeedm@mellanox.com>
Sun, 2 Nov 2014 14:26:13 +0000 (16:26 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Nov 2014 17:28:13 +0000 (12:28 -0500)
Added wrapper to the ACCESS_REG command for handling guest HW
registers access, preventing write operations, but do allow reads.

This will prevent SRIOV guests to change port PTYS configuration,
such as speed/advertised link modes.

Fixes: adbc7ac5c15e ('net/mlx4_core: Introduce ACCESS_REG CMD [...]')
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: Amir Vadai <amirv@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx4/cmd.c
drivers/net/ethernet/mellanox/mlx4/fw.c
drivers/net/ethernet/mellanox/mlx4/mlx4.h

index 916459effcfa9060de816423832fccfca1d3101b..1312ccf8b83a4f7b277bc70cfeb8851af0f68478 100644 (file)
@@ -1345,7 +1345,7 @@ static struct mlx4_cmd_info cmd_info[] = {
                .out_is_imm = false,
                .encode_slave_id = false,
                .verify = NULL,
-               .wrapper = NULL,
+               .wrapper = mlx4_ACCESS_REG_wrapper,
        },
        /* Native multicast commands are not available for guests */
        {
index 72289ef5ebbecc6e10ccb8ad2b5765723a59306d..e7639e31fc8a60e5be50170efa40c4e25dda522d 100644 (file)
@@ -2220,7 +2220,7 @@ static int mlx4_ACCESS_REG(struct mlx4_dev *dev, u16 reg_id,
        memcpy(inbuf->reg_data, reg_data, reg_len);
        err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, 0, 0,
                           MLX4_CMD_ACCESS_REG, MLX4_CMD_TIME_CLASS_C,
-                          MLX4_CMD_NATIVE);
+                          MLX4_CMD_WRAPPED);
        if (err)
                goto out;
 
@@ -2263,3 +2263,31 @@ int mlx4_ACCESS_PTYS_REG(struct mlx4_dev *dev,
                               method, sizeof(*ptys_reg), ptys_reg);
 }
 EXPORT_SYMBOL_GPL(mlx4_ACCESS_PTYS_REG);
+
+int mlx4_ACCESS_REG_wrapper(struct mlx4_dev *dev, int slave,
+                           struct mlx4_vhcr *vhcr,
+                           struct mlx4_cmd_mailbox *inbox,
+                           struct mlx4_cmd_mailbox *outbox,
+                           struct mlx4_cmd_info *cmd)
+{
+       struct mlx4_access_reg *inbuf = inbox->buf;
+       u8 method = inbuf->method & MLX4_ACCESS_REG_METHOD_MASK;
+       u16 reg_id = be16_to_cpu(inbuf->reg_id);
+
+       if (slave != mlx4_master_func_num(dev) &&
+           method == MLX4_ACCESS_REG_WRITE)
+               return -EPERM;
+
+       if (reg_id == MLX4_REG_ID_PTYS) {
+               struct mlx4_ptys_reg *ptys_reg =
+                       (struct mlx4_ptys_reg *)inbuf->reg_data;
+
+               ptys_reg->local_port =
+                       mlx4_slave_convert_port(dev, slave,
+                                               ptys_reg->local_port);
+       }
+
+       return mlx4_cmd_box(dev, inbox->dma, outbox->dma, vhcr->in_modifier,
+                           0, MLX4_CMD_ACCESS_REG, MLX4_CMD_TIME_CLASS_C,
+                           MLX4_CMD_NATIVE);
+}
index de10dbb2e6ed519e958f6f4d77b75bdd91d3076f..254ec7b1ca2ff16773883830ff575f0607d553b6 100644 (file)
@@ -1273,6 +1273,11 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
                                         struct mlx4_cmd_mailbox *inbox,
                                         struct mlx4_cmd_mailbox *outbox,
                                         struct mlx4_cmd_info *cmd);
+int mlx4_ACCESS_REG_wrapper(struct mlx4_dev *dev, int slave,
+                           struct mlx4_vhcr *vhcr,
+                           struct mlx4_cmd_mailbox *inbox,
+                           struct mlx4_cmd_mailbox *outbox,
+                           struct mlx4_cmd_info *cmd);
 
 int mlx4_get_mgm_entry_size(struct mlx4_dev *dev);
 int mlx4_get_qp_per_mgm(struct mlx4_dev *dev);