@@ -238,28 +238,32 @@ void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry)
238
238
EXPORT_SYMBOL (rdma_user_mmap_entry_remove );
239
239
240
240
/**
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.
242
243
*
243
244
* @ucontext: associated user context.
244
245
* @entry: the entry to insert into the mmap_xa
245
246
* @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
246
249
*
247
250
* This function should be called by drivers that use the rdma_user_mmap
248
251
* interface for implementing their mmap syscall A database of mmap offsets is
249
252
* handled in the core and helper functions are provided to insert entries
250
253
* 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.
254
257
*
255
258
* Return: 0 on success and -ENOMEM on failure
256
259
*/
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 )
260
264
{
261
265
struct ib_uverbs_file * ufile = ucontext -> ufile ;
262
- XA_STATE (xas , & ucontext -> mmap_xa , 0 );
266
+ XA_STATE (xas , & ucontext -> mmap_xa , min_pgoff );
263
267
u32 xa_first , xa_last , npages ;
264
268
int err ;
265
269
u32 i ;
@@ -285,7 +289,7 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
285
289
entry -> npages = npages ;
286
290
while (true) {
287
291
/* 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 );
289
293
if (xas .xa_node == XAS_RESTART )
290
294
goto err_unlock ;
291
295
@@ -332,4 +336,30 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
332
336
mutex_unlock (& ufile -> umap_lock );
333
337
return - ENOMEM ;
334
338
}
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
+ }
335
365
EXPORT_SYMBOL (rdma_user_mmap_entry_insert );
0 commit comments