Commit 63fbae0a authored by Tariq Toukan's avatar Tariq Toukan Committed by Saeed Mahameed

net/mlx5: Prevent high-rate FW commands from populating all slots

Certain connection-based device-offload protocols (like TLS) use
per-connection HW objects to track the state, maintain the context, and
perform the offload properly. Some of these objects are created,
modified, and destroyed via FW commands. Under high connection rate,
this type of FW commands might continuously populate all slots of the FW
command interface and throttle it, while starving other critical control
FW commands.

Limit these throttle commands to using only up to a portion (half) of
the FW command interface slots. FW commands maximal rate is not hit, and
the same high rate is still reached when applying this limitation.
Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.com>
Reviewed-by: default avatarMoshe Shemesh <moshe@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 7cb5eb93
...@@ -94,6 +94,21 @@ static u16 in_to_opcode(void *in) ...@@ -94,6 +94,21 @@ static u16 in_to_opcode(void *in)
return MLX5_GET(mbox_in, in, opcode); return MLX5_GET(mbox_in, in, opcode);
} }
/* Returns true for opcodes that might be triggered very frequently and throttle
* the command interface. Limit their command slots usage.
*/
static bool mlx5_cmd_is_throttle_opcode(u16 op)
{
switch (op) {
case MLX5_CMD_OP_CREATE_GENERAL_OBJECT:
case MLX5_CMD_OP_DESTROY_GENERAL_OBJECT:
case MLX5_CMD_OP_MODIFY_GENERAL_OBJECT:
case MLX5_CMD_OP_QUERY_GENERAL_OBJECT:
return true;
}
return false;
}
static struct mlx5_cmd_work_ent * static struct mlx5_cmd_work_ent *
cmd_alloc_ent(struct mlx5_cmd *cmd, struct mlx5_cmd_msg *in, cmd_alloc_ent(struct mlx5_cmd *cmd, struct mlx5_cmd_msg *in,
struct mlx5_cmd_msg *out, void *uout, int uout_size, struct mlx5_cmd_msg *out, void *uout, int uout_size,
...@@ -1825,6 +1840,7 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, ...@@ -1825,6 +1840,7 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
{ {
struct mlx5_cmd_msg *inb, *outb; struct mlx5_cmd_msg *inb, *outb;
u16 opcode = in_to_opcode(in); u16 opcode = in_to_opcode(in);
bool throttle_op;
int pages_queue; int pages_queue;
gfp_t gfp; gfp_t gfp;
u8 token; u8 token;
...@@ -1833,13 +1849,21 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, ...@@ -1833,13 +1849,21 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
if (mlx5_cmd_is_down(dev) || !opcode_allowed(&dev->cmd, opcode)) if (mlx5_cmd_is_down(dev) || !opcode_allowed(&dev->cmd, opcode))
return -ENXIO; return -ENXIO;
throttle_op = mlx5_cmd_is_throttle_opcode(opcode);
if (throttle_op) {
/* atomic context may not sleep */
if (callback)
return -EINVAL;
down(&dev->cmd.throttle_sem);
}
pages_queue = is_manage_pages(in); pages_queue = is_manage_pages(in);
gfp = callback ? GFP_ATOMIC : GFP_KERNEL; gfp = callback ? GFP_ATOMIC : GFP_KERNEL;
inb = alloc_msg(dev, in_size, gfp); inb = alloc_msg(dev, in_size, gfp);
if (IS_ERR(inb)) { if (IS_ERR(inb)) {
err = PTR_ERR(inb); err = PTR_ERR(inb);
return err; goto out_up;
} }
token = alloc_token(&dev->cmd); token = alloc_token(&dev->cmd);
...@@ -1873,6 +1897,9 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, ...@@ -1873,6 +1897,9 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
mlx5_free_cmd_msg(dev, outb); mlx5_free_cmd_msg(dev, outb);
out_in: out_in:
free_msg(dev, inb); free_msg(dev, inb);
out_up:
if (throttle_op)
up(&dev->cmd.throttle_sem);
return err; return err;
} }
...@@ -2222,6 +2249,7 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev) ...@@ -2222,6 +2249,7 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
sema_init(&cmd->sem, cmd->max_reg_cmds); sema_init(&cmd->sem, cmd->max_reg_cmds);
sema_init(&cmd->pages_sem, 1); sema_init(&cmd->pages_sem, 1);
sema_init(&cmd->throttle_sem, DIV_ROUND_UP(cmd->max_reg_cmds, 2));
cmd_h = (u32)((u64)(cmd->dma) >> 32); cmd_h = (u32)((u64)(cmd->dma) >> 32);
cmd_l = (u32)(cmd->dma); cmd_l = (u32)(cmd->dma);
......
...@@ -310,6 +310,7 @@ struct mlx5_cmd { ...@@ -310,6 +310,7 @@ struct mlx5_cmd {
struct workqueue_struct *wq; struct workqueue_struct *wq;
struct semaphore sem; struct semaphore sem;
struct semaphore pages_sem; struct semaphore pages_sem;
struct semaphore throttle_sem;
int mode; int mode;
u16 allowed_opcode; u16 allowed_opcode;
struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS]; struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS];
......
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