Skip to content

Commit 7a763d1

Browse files
yishaihdledford
authored andcommitted
IB/core: Introduce rdma_user_mmap_entry_insert_range() API
Introduce rdma_user_mmap_entry_insert_range() API to be used once the required key for the given entry should be in a given range. Signed-off-by: Yishai Hadas <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Doug Ledford <[email protected]>
1 parent ed9085f commit 7a763d1

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

drivers/infiniband/core/ib_core_uverbs.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,28 +238,32 @@ void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry)
238238
EXPORT_SYMBOL(rdma_user_mmap_entry_remove);
239239

240240
/**
241-
* rdma_user_mmap_entry_insert() - Insert an entry to the mmap_xa
241+
* rdma_user_mmap_entry_insert_range() - Insert an entry to the mmap_xa
242+
* in a given range.
242243
*
243244
* @ucontext: associated user context.
244245
* @entry: the entry to insert into the mmap_xa
245246
* @length: length of the address that will be mmapped
247+
* @min_pgoff: minimum pgoff to be returned
248+
* @max_pgoff: maximum pgoff to be returned
246249
*
247250
* This function should be called by drivers that use the rdma_user_mmap
248251
* interface for implementing their mmap syscall A database of mmap offsets is
249252
* handled in the core and helper functions are provided to insert entries
250253
* into the database and extract entries when the user calls mmap with the
251-
* given offset. The function allocates a unique page offset that should be
252-
* provided to user, the user will use the offset to retrieve information such
253-
* as address to be mapped and how.
254+
* given offset. The function allocates a unique page offset in a given range
255+
* that should be provided to user, the user will use the offset to retrieve
256+
* information such as address to be mapped and how.
254257
*
255258
* Return: 0 on success and -ENOMEM on failure
256259
*/
257-
int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
258-
struct rdma_user_mmap_entry *entry,
259-
size_t length)
260+
int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
261+
struct rdma_user_mmap_entry *entry,
262+
size_t length, u32 min_pgoff,
263+
u32 max_pgoff)
260264
{
261265
struct ib_uverbs_file *ufile = ucontext->ufile;
262-
XA_STATE(xas, &ucontext->mmap_xa, 0);
266+
XA_STATE(xas, &ucontext->mmap_xa, min_pgoff);
263267
u32 xa_first, xa_last, npages;
264268
int err;
265269
u32 i;
@@ -285,7 +289,7 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
285289
entry->npages = npages;
286290
while (true) {
287291
/* First find an empty index */
288-
xas_find_marked(&xas, U32_MAX, XA_FREE_MARK);
292+
xas_find_marked(&xas, max_pgoff, XA_FREE_MARK);
289293
if (xas.xa_node == XAS_RESTART)
290294
goto err_unlock;
291295

@@ -332,4 +336,30 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
332336
mutex_unlock(&ufile->umap_lock);
333337
return -ENOMEM;
334338
}
339+
EXPORT_SYMBOL(rdma_user_mmap_entry_insert_range);
340+
341+
/**
342+
* rdma_user_mmap_entry_insert() - Insert an entry to the mmap_xa.
343+
*
344+
* @ucontext: associated user context.
345+
* @entry: the entry to insert into the mmap_xa
346+
* @length: length of the address that will be mmapped
347+
*
348+
* This function should be called by drivers that use the rdma_user_mmap
349+
* interface for handling user mmapped addresses. The database is handled in
350+
* the core and helper functions are provided to insert entries into the
351+
* database and extract entries when the user calls mmap with the given offset.
352+
* The function allocates a unique page offset that should be provided to user,
353+
* the user will use the offset to retrieve information such as address to
354+
* be mapped and how.
355+
*
356+
* Return: 0 on success and -ENOMEM on failure
357+
*/
358+
int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
359+
struct rdma_user_mmap_entry *entry,
360+
size_t length)
361+
{
362+
return rdma_user_mmap_entry_insert_range(ucontext, entry, length, 0,
363+
U32_MAX);
364+
}
335365
EXPORT_SYMBOL(rdma_user_mmap_entry_insert);

include/rdma/ib_verbs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,11 @@ int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
28322832
int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
28332833
struct rdma_user_mmap_entry *entry,
28342834
size_t length);
2835+
int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
2836+
struct rdma_user_mmap_entry *entry,
2837+
size_t length, u32 min_pgoff,
2838+
u32 max_pgoff);
2839+
28352840
struct rdma_user_mmap_entry *
28362841
rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
28372842
unsigned long pgoff);

0 commit comments

Comments
 (0)