Skip to content

Commit 597ecc5

Browse files
jgunthorpedledford
authored andcommitted
RDMA/umem: Get rid of struct ib_umem.odp_data
This no longer has any use, we can use container_of to get to the umem_odp, and a simple flag to indicate if this is an odp MR. Remove the few remaining references to it. Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 41b4dee commit 597ecc5

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

drivers/infiniband/core/umem.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
112112
umem = kzalloc(sizeof(struct ib_umem_odp), GFP_KERNEL);
113113
if (!umem)
114114
return ERR_PTR(-ENOMEM);
115-
umem->odp_data = to_ib_umem_odp(umem);
115+
umem->is_odp = 1;
116116
} else {
117117
umem = kzalloc(sizeof(*umem), GFP_KERNEL);
118118
if (!umem)
@@ -243,7 +243,7 @@ EXPORT_SYMBOL(ib_umem_get);
243243
static void __ib_umem_release_tail(struct ib_umem *umem)
244244
{
245245
mmdrop(umem->owning_mm);
246-
if (umem->odp_data)
246+
if (umem->is_odp)
247247
kfree(to_ib_umem_odp(umem));
248248
else
249249
kfree(umem);
@@ -268,7 +268,7 @@ void ib_umem_release(struct ib_umem *umem)
268268
{
269269
struct ib_ucontext *context = umem->context;
270270

271-
if (umem->odp_data) {
271+
if (umem->is_odp) {
272272
ib_umem_odp_release(to_ib_umem_odp(umem));
273273
__ib_umem_release_tail(umem);
274274
return;
@@ -306,7 +306,7 @@ int ib_umem_page_count(struct ib_umem *umem)
306306
int n;
307307
struct scatterlist *sg;
308308

309-
if (umem->odp_data)
309+
if (umem->is_odp)
310310
return ib_umem_num_pages(umem);
311311

312312
n = 0;

drivers/infiniband/core/umem_odp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct ib_umem_odp *ib_alloc_odp_umem(struct ib_ucontext *context,
291291
umem->address = addr;
292292
umem->page_shift = PAGE_SHIFT;
293293
umem->writable = 1;
294+
umem->is_odp = 1;
294295

295296
mutex_init(&odp_data->umem_mutex);
296297
init_completion(&odp_data->notifier_completion);
@@ -319,8 +320,6 @@ struct ib_umem_odp *ib_alloc_odp_umem(struct ib_ucontext *context,
319320
&context->no_private_counters);
320321
up_write(&context->umem_rwsem);
321322

322-
umem->odp_data = odp_data;
323-
324323
return odp_data;
325324

326325
out_page_list:

drivers/infiniband/hw/mlx5/mem.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr,
5757
int entry;
5858
unsigned long page_shift = umem->page_shift;
5959

60-
if (umem->odp_data) {
60+
if (umem->is_odp) {
6161
*ncont = ib_umem_page_count(umem);
6262
*count = *ncont << (page_shift - PAGE_SHIFT);
6363
*shift = page_shift;
@@ -152,14 +152,13 @@ void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
152152
struct scatterlist *sg;
153153
int entry;
154154
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
155-
const bool odp = umem->odp_data != NULL;
156-
157-
if (odp) {
155+
if (umem->is_odp) {
158156
WARN_ON(shift != 0);
159157
WARN_ON(access_flags != (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE));
160158

161159
for (i = 0; i < num_pages; ++i) {
162-
dma_addr_t pa = umem->odp_data->dma_list[offset + i];
160+
dma_addr_t pa =
161+
to_ib_umem_odp(umem)->dma_list[offset + i];
163162

164163
pas[i] = cpu_to_be64(umem_dma_to_mtt(pa));
165164
}

drivers/infiniband/hw/mlx5/mr.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static bool use_umr_mtt_update(struct mlx5_ib_mr *mr, u64 start, u64 length)
9898
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
9999
static void update_odp_mr(struct mlx5_ib_mr *mr)
100100
{
101-
if (mr->umem->odp_data) {
101+
if (mr->umem->is_odp) {
102102
/*
103103
* This barrier prevents the compiler from moving the
104104
* setting of umem->odp_data->private to point to our
@@ -107,7 +107,7 @@ static void update_odp_mr(struct mlx5_ib_mr *mr)
107107
* handle invalidations.
108108
*/
109109
smp_wmb();
110-
mr->umem->odp_data->private = mr;
110+
to_ib_umem_odp(mr->umem)->private = mr;
111111
/*
112112
* Make sure we will see the new
113113
* umem->odp_data->private value in the invalidation
@@ -1624,15 +1624,16 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
16241624
struct ib_umem *umem = mr->umem;
16251625

16261626
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
1627-
if (umem && umem->odp_data) {
1627+
if (umem && umem->is_odp) {
1628+
struct ib_umem_odp *umem_odp = to_ib_umem_odp(umem);
1629+
16281630
/* Prevent new page faults from succeeding */
16291631
mr->live = 0;
16301632
/* Wait for all running page-fault handlers to finish. */
16311633
synchronize_srcu(&dev->mr_srcu);
16321634
/* Destroy all page mappings */
1633-
if (umem->odp_data->page_list)
1634-
mlx5_ib_invalidate_range(to_ib_umem_odp(umem),
1635-
ib_umem_start(umem),
1635+
if (umem_odp->page_list)
1636+
mlx5_ib_invalidate_range(umem_odp, ib_umem_start(umem),
16361637
ib_umem_end(umem));
16371638
else
16381639
mlx5_ib_free_implicit_mr(mr);

drivers/infiniband/hw/mlx5/odp.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,12 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr,
371371
struct ib_ucontext *ctx = mr->ibmr.pd->uobject->context;
372372
struct mlx5_ib_dev *dev = to_mdev(mr->ibmr.pd->device);
373373
struct ib_umem_odp *odp, *result = NULL;
374+
struct ib_umem_odp *odp_mr = to_ib_umem_odp(mr->umem);
374375
u64 addr = io_virt & MLX5_IMR_MTT_MASK;
375376
int nentries = 0, start_idx = 0, ret;
376377
struct mlx5_ib_mr *mtt;
377378

378-
mutex_lock(&mr->umem->odp_data->umem_mutex);
379+
mutex_lock(&odp_mr->umem_mutex);
379380
odp = odp_lookup(ctx, addr, 1, mr);
380381

381382
mlx5_ib_dbg(dev, "io_virt:%llx bcnt:%zx addr:%llx odp:%p\n",
@@ -388,14 +389,14 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr,
388389
} else {
389390
odp = ib_alloc_odp_umem(ctx, addr, MLX5_IMR_MTT_SIZE);
390391
if (IS_ERR(odp)) {
391-
mutex_unlock(&mr->umem->odp_data->umem_mutex);
392+
mutex_unlock(&odp_mr->umem_mutex);
392393
return ERR_CAST(odp);
393394
}
394395

395396
mtt = implicit_mr_alloc(mr->ibmr.pd, &odp->umem, 0,
396397
mr->access_flags);
397398
if (IS_ERR(mtt)) {
398-
mutex_unlock(&mr->umem->odp_data->umem_mutex);
399+
mutex_unlock(&odp_mr->umem_mutex);
399400
ib_umem_release(&odp->umem);
400401
return ERR_CAST(mtt);
401402
}
@@ -433,7 +434,7 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr,
433434
}
434435
}
435436

436-
mutex_unlock(&mr->umem->odp_data->umem_mutex);
437+
mutex_unlock(&odp_mr->umem_mutex);
437438
return result;
438439
}
439440

@@ -498,6 +499,7 @@ void mlx5_ib_free_implicit_mr(struct mlx5_ib_mr *imr)
498499
static int pagefault_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr,
499500
u64 io_virt, size_t bcnt, u32 *bytes_mapped)
500501
{
502+
struct ib_umem_odp *odp_mr = to_ib_umem_odp(mr->umem);
501503
u64 access_mask = ODP_READ_ALLOWED_BIT;
502504
int npages = 0, page_shift, np;
503505
u64 start_idx, page_mask;
@@ -506,15 +508,15 @@ static int pagefault_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr,
506508
size_t size;
507509
int ret;
508510

509-
if (!mr->umem->odp_data->page_list) {
511+
if (!odp_mr->page_list) {
510512
odp = implicit_mr_get_data(mr, io_virt, bcnt);
511513

512514
if (IS_ERR(odp))
513515
return PTR_ERR(odp);
514516
mr = odp->private;
515517

516518
} else {
517-
odp = mr->umem->odp_data;
519+
odp = odp_mr;
518520
}
519521

520522
next_mr:

include/rdma/ib_umem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ struct ib_umem {
4646
size_t length;
4747
unsigned long address;
4848
int page_shift;
49-
int writable;
50-
int hugetlb;
49+
u32 writable : 1;
50+
u32 hugetlb : 1;
51+
u32 is_odp : 1;
5152
struct work_struct work;
52-
struct ib_umem_odp *odp_data;
5353
struct sg_table sg_head;
5454
int nmap;
5555
int npages;

0 commit comments

Comments
 (0)