@@ -238,28 +238,32 @@ void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry)
238238EXPORT_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+ }
335365EXPORT_SYMBOL (rdma_user_mmap_entry_insert );
0 commit comments