Skip to content

Commit 0a2fd01

Browse files
yishaihjgunthorpe
authored andcommitted
IB/mlx5: Move to fully dynamic UAR mode once user space supports it
Move to fully dynamic UAR mode once user space supports it. In this case we prevent any legacy mode of UARs on the allocated context and prevent redundant allocation of the static ones. Link: https://lore.kernel.org/r/20200324060143.1569116-6-leon@kernel.org Signed-off-by: Yishai Hadas <yishaih@mellanox.com> Reviewed-by: Michael Guralnik <michaelgur@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 2152862 commit 0a2fd01

5 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎drivers/infiniband/hw/mlx5/cq.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,14 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
741741
MLX5_SET(cqc, cqc, log_page_size,
742742
page_shift - MLX5_ADAPTER_PAGE_SHIFT);
743743

744-
if (ucmd.flags & MLX5_IB_CREATE_CQ_FLAGS_UAR_PAGE_INDEX)
744+
if (ucmd.flags & MLX5_IB_CREATE_CQ_FLAGS_UAR_PAGE_INDEX) {
745745
*index = ucmd.uar_page_index;
746-
else
746+
} else if (context->bfregi.lib_uar_dyn) {
747+
err = -EINVAL;
748+
goto err_cqb;
749+
} else {
747750
*index = context->bfregi.sys_pages[0];
751+
}
748752

749753
if (ucmd.cqe_comp_en == 1) {
750754
int mini_cqe_format;

‎drivers/infiniband/hw/mlx5/main.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,7 @@ static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx,
17861786
max_cqe_version);
17871787
u32 dump_fill_mkey;
17881788
bool lib_uar_4k;
1789+
bool lib_uar_dyn;
17891790

17901791
if (!dev->ib_active)
17911792
return -EAGAIN;
@@ -1844,8 +1845,14 @@ static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx,
18441845
}
18451846

18461847
lib_uar_4k = req.lib_caps & MLX5_LIB_CAP_4K_UAR;
1848+
lib_uar_dyn = req.lib_caps & MLX5_LIB_CAP_DYN_UAR;
18471849
bfregi = &context->bfregi;
18481850

1851+
if (lib_uar_dyn) {
1852+
bfregi->lib_uar_dyn = lib_uar_dyn;
1853+
goto uar_done;
1854+
}
1855+
18491856
/* updates req->total_num_bfregs */
18501857
err = calc_total_bfregs(dev, lib_uar_4k, &req, bfregi);
18511858
if (err)
@@ -1872,6 +1879,7 @@ static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx,
18721879
if (err)
18731880
goto out_sys_pages;
18741881

1882+
uar_done:
18751883
if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) {
18761884
err = mlx5_ib_devx_create(dev, true);
18771885
if (err < 0)
@@ -1893,7 +1901,7 @@ static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx,
18931901
INIT_LIST_HEAD(&context->db_page_list);
18941902
mutex_init(&context->db_page_mutex);
18951903

1896-
resp.tot_bfregs = req.total_num_bfregs;
1904+
resp.tot_bfregs = lib_uar_dyn ? 0 : req.total_num_bfregs;
18971905
resp.num_ports = dev->num_ports;
18981906

18991907
if (offsetofend(typeof(resp), cqe_version) <= udata->outlen)
@@ -2141,6 +2149,9 @@ static int uar_mmap(struct mlx5_ib_dev *dev, enum mlx5_ib_mmap_cmd cmd,
21412149
int max_valid_idx = dyn_uar ? bfregi->num_sys_pages :
21422150
bfregi->num_static_sys_pages;
21432151

2152+
if (bfregi->lib_uar_dyn)
2153+
return -EINVAL;
2154+
21442155
if (vma->vm_end - vma->vm_start != PAGE_SIZE)
21452156
return -EINVAL;
21462157

‎drivers/infiniband/hw/mlx5/mlx5_ib.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct mlx5_bfreg_info {
139139
struct mutex lock;
140140
u32 ver;
141141
u8 lib_uar_4k : 1;
142+
u8 lib_uar_dyn : 1;
142143
u32 num_sys_pages;
143144
u32 num_static_sys_pages;
144145
u32 total_num_bfregs;

‎drivers/infiniband/hw/mlx5/qp.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ static int alloc_bfreg(struct mlx5_ib_dev *dev,
697697
{
698698
int bfregn = -ENOMEM;
699699

700+
if (bfregi->lib_uar_dyn)
701+
return -EINVAL;
702+
700703
mutex_lock(&bfregi->lock);
701704
if (bfregi->ver >= 2) {
702705
bfregn = alloc_high_class_bfreg(dev, bfregi);
@@ -768,6 +771,9 @@ int bfregn_to_uar_index(struct mlx5_ib_dev *dev,
768771
u32 index_of_sys_page;
769772
u32 offset;
770773

774+
if (bfregi->lib_uar_dyn)
775+
return -EINVAL;
776+
771777
bfregs_per_sys_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k) *
772778
MLX5_NON_FP_BFREGS_PER_UAR;
773779
index_of_sys_page = bfregn / bfregs_per_sys_page;

‎include/uapi/rdma/mlx5-abi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct mlx5_ib_alloc_ucontext_req {
7979

8080
enum mlx5_lib_caps {
8181
MLX5_LIB_CAP_4K_UAR = (__u64)1 << 0,
82+
MLX5_LIB_CAP_DYN_UAR = (__u64)1 << 1,
8283
};
8384

8485
enum mlx5_ib_alloc_uctx_v2_flags {

0 commit comments

Comments
 (0)