]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/rdmavt: Add driver mmap callback
authorDean Luick <dean.luick@cornelisnetworks.com>
Mon, 9 Mar 2026 20:44:59 +0000 (16:44 -0400)
committerLeon Romanovsky <leon@kernel.org>
Wed, 11 Mar 2026 19:17:28 +0000 (15:17 -0400)
Add a reserved range and a driver callback to allow the driver to
have custom mmaps.

Generated mmap offsets are cookies and are not related to the size of
the mmap.  Advance the mmap offset by the minimum, PAGE_SIZE, rather
than the size of the mmap.

Signed-off-by: Dean Luick <dean.luick@cornelisnetworks.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Link: https://patch.msgid.link/177308909972.1279894.15543003811821875042.stgit@awdrv-04.cornelisnetworks.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/sw/rdmavt/mmap.c
include/rdma/rdma_vt.h

index 46e3b3e0643ab0eed55a49fb25d48722d8360454..473f464f33fa26ace931eab7b2b67de5162b1025 100644 (file)
@@ -9,6 +9,11 @@
 #include <rdma/uverbs_ioctl.h>
 #include "mmap.h"
 
+/* number of reserved mmaps for the driver */
+#define MMAP_RESERVED 256
+/* start point for dynamic offsets */
+#define MMAP_OFFSET_START (MMAP_RESERVED * PAGE_SIZE)
+
 /**
  * rvt_mmap_init - init link list and lock for mem map
  * @rdi: rvt dev struct
@@ -17,7 +22,7 @@ void rvt_mmap_init(struct rvt_dev_info *rdi)
 {
        INIT_LIST_HEAD(&rdi->pending_mmaps);
        spin_lock_init(&rdi->pending_lock);
-       rdi->mmap_offset = PAGE_SIZE;
+       rdi->mmap_offset = MMAP_OFFSET_START;
        spin_lock_init(&rdi->mmap_offset_lock);
 }
 
@@ -73,6 +78,13 @@ int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
        struct rvt_mmap_info *ip, *pp;
        int ret = -EINVAL;
 
+       /* call driver if in reserved range */
+       if (offset < MMAP_OFFSET_START) {
+               if (rdi->driver_f.mmap)
+                       return rdi->driver_f.mmap(context, vma);
+               return -EINVAL;
+       }
+
        /*
         * Search the device's list of objects waiting for a mmap call.
         * Normally, this list is very short since a call to create a
@@ -129,9 +141,9 @@ struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi, u32 size,
 
        spin_lock_irq(&rdi->mmap_offset_lock);
        if (rdi->mmap_offset == 0)
-               rdi->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA);
+               rdi->mmap_offset = MMAP_OFFSET_START;
        ip->offset = rdi->mmap_offset;
-       rdi->mmap_offset += ALIGN(size, SHMLBA);
+       rdi->mmap_offset += PAGE_SIZE;
        spin_unlock_irq(&rdi->mmap_offset_lock);
 
        INIT_LIST_HEAD(&ip->pending_mmaps);
@@ -159,9 +171,9 @@ void rvt_update_mmap_info(struct rvt_dev_info *rdi, struct rvt_mmap_info *ip,
 
        spin_lock_irq(&rdi->mmap_offset_lock);
        if (rdi->mmap_offset == 0)
-               rdi->mmap_offset = PAGE_SIZE;
+               rdi->mmap_offset = MMAP_OFFSET_START;
        ip->offset = rdi->mmap_offset;
-       rdi->mmap_offset += size;
+       rdi->mmap_offset += PAGE_SIZE;
        spin_unlock_irq(&rdi->mmap_offset_lock);
 
        ip->size = size;
index 8671c6da16bb29bd3469a992c0d3bb4f02d8c751..7d8de561f71b5b6db4fbfdec01f0cc1e017d79a2 100644 (file)
@@ -366,6 +366,9 @@ struct rvt_driver_provided {
 
        /* deallocate a ucontext */
        void (*dealloc_ucontext)(struct ib_ucontext *context);
+
+       /* driver mmap */
+       int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma);
 };
 
 struct rvt_dev_info {