]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
IB/mlx5: Limit mkey page size to 2GB
authorMajd Dibbiny <majd@mellanox.com>
Thu, 27 Oct 2016 13:36:47 +0000 (16:36 +0300)
committerDoug Ledford <dledford@redhat.com>
Thu, 17 Nov 2016 01:04:48 +0000 (20:04 -0500)
The maximum page size in the mkey context is 2GB.

Until today, we didn't enforce this requirement in the code,
and therefore, if we got a page size larger than 2GB, we
have passed zeros in the log_page_shift instead of the actual value
and the registration failed.

This patch limits the driver to use compound pages of 2GB for mkeys.

Fixes: e126ba97dba9 ('mlx5: Add driver for Mellanox Connect-IB adapters')
Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Majd Dibbiny <majd@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/mlx5/cq.c
drivers/infiniband/hw/mlx5/mem.c
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/mr.c
drivers/infiniband/hw/mlx5/qp.c
drivers/infiniband/hw/mlx5/srq.c

index 79d017baf6f49dac160090d1e75ec75fd8b3cf2c..9e0598b5615f877ba04de247a4a49691e1a3997a 100644 (file)
@@ -770,7 +770,7 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
        if (err)
                goto err_umem;
 
-       mlx5_ib_cont_pages(cq->buf.umem, ucmd.buf_addr, &npages, &page_shift,
+       mlx5_ib_cont_pages(cq->buf.umem, ucmd.buf_addr, 0, &npages, &page_shift,
                           &ncont, NULL);
        mlx5_ib_dbg(dev, "addr 0x%llx, size %u, npages %d, page_shift %d, ncont %d\n",
                    ucmd.buf_addr, entries * ucmd.cqe_size, npages, page_shift, ncont);
@@ -1125,7 +1125,7 @@ static int resize_user(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
                return err;
        }
 
-       mlx5_ib_cont_pages(umem, ucmd.buf_addr, &npages, page_shift,
+       mlx5_ib_cont_pages(umem, ucmd.buf_addr, 0, &npages, page_shift,
                           npas, NULL);
 
        cq->resize_umem = umem;
index 996b54e366b03d031a7791e8f80c55aba232e2f1..6851357c16f4ea30f5a51ae5265549f088bd1b48 100644 (file)
 
 /* @umem: umem object to scan
  * @addr: ib virtual address requested by the user
+ * @max_page_shift: high limit for page_shift - 0 means no limit
  * @count: number of PAGE_SIZE pages covered by umem
  * @shift: page shift for the compound pages found in the region
  * @ncont: number of compund pages
  * @order: log2 of the number of compound pages
  */
-void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
+void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr,
+                       unsigned long max_page_shift,
+                       int *count, int *shift,
                        int *ncont, int *order)
 {
        unsigned long tmp;
@@ -72,6 +75,8 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
        addr = addr >> page_shift;
        tmp = (unsigned long)addr;
        m = find_first_bit(&tmp, BITS_PER_LONG);
+       if (max_page_shift)
+               m = min_t(unsigned long, max_page_shift - page_shift, m);
        skip = 1 << m;
        mask = skip - 1;
        i = 0;
index d5d007740159eec49b878e45fbedff6ea3e5fc12..95937e7d2584ea482311cbcf55a084a7790065e7 100644 (file)
@@ -63,6 +63,8 @@ pr_warn("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__,   \
 #define MLX5_IB_DEFAULT_UIDX 0xffffff
 #define MLX5_USER_ASSIGNED_UIDX_MASK __mlx5_mask(qpc, user_index)
 
+#define MLX5_MKEY_PAGE_SHIFT_MASK __mlx5_mask(mkc, log_page_size)
+
 enum {
        MLX5_IB_MMAP_CMD_SHIFT  = 8,
        MLX5_IB_MMAP_CMD_MASK   = 0xff,
@@ -823,7 +825,9 @@ int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
                       struct ib_port_attr *props);
 int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
 void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
-void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
+void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr,
+                       unsigned long max_page_shift,
+                       int *count, int *shift,
                        int *ncont, int *order);
 void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
                            int page_shift, size_t offset, size_t num_pages,
index 881166a9d8689c111f6cd0a6e779d40d78a2ed10..6cbda901f259ac2cdc9ee9e695557bf540fbb682 100644 (file)
@@ -855,7 +855,8 @@ static struct ib_umem *mr_umem_get(struct ib_pd *pd, u64 start, u64 length,
                return (void *)umem;
        }
 
-       mlx5_ib_cont_pages(umem, start, npages, page_shift, ncont, order);
+       mlx5_ib_cont_pages(umem, start, MLX5_MKEY_PAGE_SHIFT_MASK, npages,
+                          page_shift, ncont, order);
        if (!*npages) {
                mlx5_ib_warn(dev, "avoid zero region\n");
                ib_umem_release(umem);
index c84b07f9f111f3bcc8d55bbd474371f441b833ad..aa27688f5ae92f8ef882beca47c45c789daa415c 100644 (file)
@@ -675,7 +675,7 @@ static int mlx5_ib_umem_get(struct mlx5_ib_dev *dev,
                return PTR_ERR(*umem);
        }
 
-       mlx5_ib_cont_pages(*umem, addr, npages, page_shift, ncont, NULL);
+       mlx5_ib_cont_pages(*umem, addr, 0, npages, page_shift, ncont, NULL);
 
        err = mlx5_ib_get_buf_offset(addr, *page_shift, offset);
        if (err) {
@@ -728,7 +728,7 @@ static int create_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd,
                return err;
        }
 
-       mlx5_ib_cont_pages(rwq->umem, ucmd->buf_addr, &npages, &page_shift,
+       mlx5_ib_cont_pages(rwq->umem, ucmd->buf_addr, 0, &npages, &page_shift,
                           &ncont, NULL);
        err = mlx5_ib_get_buf_offset(ucmd->buf_addr, page_shift,
                                     &rwq->rq_page_offset);
index 3857dbd9c95604d8169e3078a82c22d0f2ca4c95..f384db5367fbf844bcba65cc13f3e8c7d985459a 100644 (file)
@@ -118,7 +118,7 @@ static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq,
                return err;
        }
 
-       mlx5_ib_cont_pages(srq->umem, ucmd.buf_addr, &npages,
+       mlx5_ib_cont_pages(srq->umem, ucmd.buf_addr, 0, &npages,
                           &page_shift, &ncont, NULL);
        err = mlx5_ib_get_buf_offset(ucmd.buf_addr, page_shift,
                                     &offset);