Skip to content

Commit abb0dcf

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Fix firmware error on creation of 1k VQs
A firmware error is triggered when configuring a 9k MTU on the PF after switching to switchdev mode and then using a vdpa device with larger (1k) rings: mlx5_cmd_out_err: CREATE_GENERAL_OBJECT(0xa00) op_mod(0xd) failed, status bad resource(0x5), syndrome (0xf6db90), err(-22) This is due to the fact that the hw VQ size parameters are computed based on the umem_1/2/3_buffer_param_a/b capabilities and all device capabilities are read only when the driver is moved to switchdev mode. The problematic configuration flow looks like this: 1) Create VF 2) Unbind VF 3) Switch PF to switchdev mode. 4) Bind VF 5) Set PF MTU to 9k 6) create vDPA device 7) Start VM with vDPA device and 1K queue size Note that setting the MTU before step 3) doesn't trigger this issue. This patch reads the forementioned umem parameters at the latest point possible before the VQs of the device are created. v2: - Allocate output with kmalloc to reduce stack frame size. - Removed stable from cc. Fixes: 1a86b37 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices") Signed-off-by: Dragos Tatulea <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 07622bd commit abb0dcf

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,30 +625,70 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)
625625
mlx5_db_free(ndev->mvdev.mdev, &vcq->db);
626626
}
627627

628+
static int read_umem_params(struct mlx5_vdpa_net *ndev)
629+
{
630+
u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
631+
u16 opmod = (MLX5_CAP_VDPA_EMULATION << 1) | (HCA_CAP_OPMOD_GET_CUR & 0x01);
632+
struct mlx5_core_dev *mdev = ndev->mvdev.mdev;
633+
int out_size;
634+
void *caps;
635+
void *out;
636+
int err;
637+
638+
out_size = MLX5_ST_SZ_BYTES(query_hca_cap_out);
639+
out = kzalloc(out_size, GFP_KERNEL);
640+
if (!out)
641+
return -ENOMEM;
642+
643+
MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
644+
MLX5_SET(query_hca_cap_in, in, op_mod, opmod);
645+
err = mlx5_cmd_exec_inout(mdev, query_hca_cap, in, out);
646+
if (err) {
647+
mlx5_vdpa_warn(&ndev->mvdev,
648+
"Failed reading vdpa umem capabilities with err %d\n", err);
649+
goto out;
650+
}
651+
652+
caps = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
653+
654+
ndev->umem_1_buffer_param_a = MLX5_GET(virtio_emulation_cap, caps, umem_1_buffer_param_a);
655+
ndev->umem_1_buffer_param_b = MLX5_GET(virtio_emulation_cap, caps, umem_1_buffer_param_b);
656+
657+
ndev->umem_2_buffer_param_a = MLX5_GET(virtio_emulation_cap, caps, umem_2_buffer_param_a);
658+
ndev->umem_2_buffer_param_b = MLX5_GET(virtio_emulation_cap, caps, umem_2_buffer_param_b);
659+
660+
ndev->umem_3_buffer_param_a = MLX5_GET(virtio_emulation_cap, caps, umem_3_buffer_param_a);
661+
ndev->umem_3_buffer_param_b = MLX5_GET(virtio_emulation_cap, caps, umem_3_buffer_param_b);
662+
663+
out:
664+
kfree(out);
665+
return 0;
666+
}
667+
628668
static void set_umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq, int num,
629669
struct mlx5_vdpa_umem **umemp)
630670
{
631-
struct mlx5_core_dev *mdev = ndev->mvdev.mdev;
632-
int p_a;
633-
int p_b;
671+
u32 p_a;
672+
u32 p_b;
634673

635674
switch (num) {
636675
case 1:
637-
p_a = MLX5_CAP_DEV_VDPA_EMULATION(mdev, umem_1_buffer_param_a);
638-
p_b = MLX5_CAP_DEV_VDPA_EMULATION(mdev, umem_1_buffer_param_b);
676+
p_a = ndev->umem_1_buffer_param_a;
677+
p_b = ndev->umem_1_buffer_param_b;
639678
*umemp = &mvq->umem1;
640679
break;
641680
case 2:
642-
p_a = MLX5_CAP_DEV_VDPA_EMULATION(mdev, umem_2_buffer_param_a);
643-
p_b = MLX5_CAP_DEV_VDPA_EMULATION(mdev, umem_2_buffer_param_b);
681+
p_a = ndev->umem_2_buffer_param_a;
682+
p_b = ndev->umem_2_buffer_param_b;
644683
*umemp = &mvq->umem2;
645684
break;
646685
case 3:
647-
p_a = MLX5_CAP_DEV_VDPA_EMULATION(mdev, umem_3_buffer_param_a);
648-
p_b = MLX5_CAP_DEV_VDPA_EMULATION(mdev, umem_3_buffer_param_b);
686+
p_a = ndev->umem_3_buffer_param_a;
687+
p_b = ndev->umem_3_buffer_param_b;
649688
*umemp = &mvq->umem3;
650689
break;
651690
}
691+
652692
(*umemp)->size = p_a * mvq->num_ent + p_b;
653693
}
654694

@@ -2679,6 +2719,11 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)
26792719
goto out;
26802720
}
26812721
mlx5_vdpa_add_debugfs(ndev);
2722+
2723+
err = read_umem_params(ndev);
2724+
if (err)
2725+
goto err_setup;
2726+
26822727
err = setup_virtqueues(mvdev);
26832728
if (err) {
26842729
mlx5_vdpa_warn(mvdev, "setup_virtqueues\n");

drivers/vdpa/mlx5/net/mlx5_vnet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ struct mlx5_vdpa_net {
6565
struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
6666
struct mlx5_vdpa_irq_pool irqp;
6767
struct dentry *debugfs;
68+
69+
u32 umem_1_buffer_param_a;
70+
u32 umem_1_buffer_param_b;
71+
72+
u32 umem_2_buffer_param_a;
73+
u32 umem_2_buffer_param_b;
74+
75+
u32 umem_3_buffer_param_a;
76+
u32 umem_3_buffer_param_b;
6877
};
6978

7079
struct mlx5_vdpa_counter {

0 commit comments

Comments
 (0)