Skip to content

Commit 352e3b0

Browse files
Knut OmangMukesh Kacker
authored andcommitted
ib_umem: Add a new, more generic ib_umem_get_attrs
This call allows a full range of DMA attributes and also DMA direction to be supplied and is just a refactor of the old ib_umem_get. Reimplement ib_umem_get using the new generic call, now a trivial implementation. Orabug: 20930262 Signed-off-by: Knut Omang <[email protected]> Signed-off-by: Mukesh Kacker <[email protected]>
1 parent 24b440a commit 352e3b0

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

drivers/infiniband/core/umem.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
5353
if (umem->nmap > 0)
5454
ib_dma_unmap_sg(dev, umem->sg_head.sgl,
5555
umem->nmap,
56-
DMA_BIDIRECTIONAL);
56+
umem->dir);
5757

5858
for_each_sg(umem->sg_head.sgl, sg, umem->npages, i) {
5959

@@ -82,6 +82,17 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
8282
*/
8383
struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
8484
size_t size, int access, int dmasync)
85+
{
86+
DEFINE_DMA_ATTRS(attrs);
87+
if (dmasync)
88+
dma_set_attr(DMA_ATTR_WRITE_BARRIER, &attrs);
89+
return ib_umem_get_attrs(context, addr, size, access, DMA_BIDIRECTIONAL, &attrs);
90+
}
91+
EXPORT_SYMBOL(ib_umem_get);
92+
93+
struct ib_umem *ib_umem_get_attrs(struct ib_ucontext *context, unsigned long addr,
94+
size_t size, int access, enum dma_data_direction dir,
95+
struct dma_attrs *attrs)
8596
{
8697
struct ib_umem *umem;
8798
struct page **page_list;
@@ -92,13 +103,9 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
92103
unsigned long npages;
93104
int ret;
94105
int i;
95-
DEFINE_DMA_ATTRS(attrs);
96106
struct scatterlist *sg, *sg_list_start;
97107
int need_release = 0;
98108

99-
if (dmasync)
100-
dma_set_attr(DMA_ATTR_WRITE_BARRIER, &attrs);
101-
102109
if (!size)
103110
return ERR_PTR(-EINVAL);
104111

@@ -122,6 +129,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
122129
umem->address = addr;
123130
umem->page_size = PAGE_SIZE;
124131
umem->pid = get_task_pid(current, PIDTYPE_PID);
132+
umem->dir = dir;
125133
/*
126134
* We ask for writable memory if any of the following
127135
* access flags are set. "Local write" and "remote write"
@@ -214,8 +222,8 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
214222
umem->nmap = ib_dma_map_sg_attrs(context->device,
215223
umem->sg_head.sgl,
216224
umem->npages,
217-
DMA_BIDIRECTIONAL,
218-
&attrs);
225+
dir,
226+
attrs);
219227

220228
if (umem->nmap <= 0) {
221229
ret = -ENOMEM;
@@ -240,7 +248,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
240248

241249
return ret < 0 ? ERR_PTR(ret) : umem;
242250
}
243-
EXPORT_SYMBOL(ib_umem_get);
251+
EXPORT_SYMBOL(ib_umem_get_attrs);
244252

245253
static void ib_umem_account(struct work_struct *work)
246254
{

include/rdma/ib_umem.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
#include <linux/list.h>
3737
#include <linux/scatterlist.h>
3838
#include <linux/workqueue.h>
39+
#include <linux/dma-direction.h>
3940

4041
struct ib_ucontext;
4142
struct ib_umem_odp;
43+
struct dma_attrs;
4244

4345
struct ib_umem {
4446
struct ib_ucontext *context;
@@ -47,6 +49,7 @@ struct ib_umem {
4749
int page_size;
4850
int writable;
4951
int hugetlb;
52+
enum dma_data_direction dir;
5053
struct work_struct work;
5154
struct pid *pid;
5255
struct mm_struct *mm;
@@ -81,9 +84,12 @@ static inline size_t ib_umem_num_pages(struct ib_umem *umem)
8184
}
8285

8386
#ifdef CONFIG_INFINIBAND_USER_MEM
84-
8587
struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
8688
size_t size, int access, int dmasync);
89+
struct ib_umem *ib_umem_get_attrs(struct ib_ucontext *context, unsigned long addr,
90+
size_t size, int access,
91+
enum dma_data_direction dir,
92+
struct dma_attrs *attrs);
8793
void ib_umem_release(struct ib_umem *umem);
8894
int ib_umem_page_count(struct ib_umem *umem);
8995
int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
@@ -98,6 +104,14 @@ static inline struct ib_umem *ib_umem_get(struct ib_ucontext *context,
98104
int access, int dmasync) {
99105
return ERR_PTR(-EINVAL);
100106
}
107+
static inline struct ib_umem *ib_umem_get_attrs(struct ib_ucontext *context,
108+
unsigned long addr,
109+
size_t size, int access,
110+
enum dma_data_direction dir,
111+
struct dma_attrs *attrs)
112+
{
113+
return ERR_PTR(-EINVAL);
114+
}
101115
static inline void ib_umem_release(struct ib_umem *umem) { }
102116
static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
103117
static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,

0 commit comments

Comments
 (0)