Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

RDMA/rdmavt: Add driver mmap callback

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>

authored by

Dean Luick and committed by
Leon Romanovsky
6be4ca0a 0fed679e

+20 -5
+17 -5
drivers/infiniband/sw/rdmavt/mmap.c
··· 9 9 #include <rdma/uverbs_ioctl.h> 10 10 #include "mmap.h" 11 11 12 + /* number of reserved mmaps for the driver */ 13 + #define MMAP_RESERVED 256 14 + /* start point for dynamic offsets */ 15 + #define MMAP_OFFSET_START (MMAP_RESERVED * PAGE_SIZE) 16 + 12 17 /** 13 18 * rvt_mmap_init - init link list and lock for mem map 14 19 * @rdi: rvt dev struct ··· 22 17 { 23 18 INIT_LIST_HEAD(&rdi->pending_mmaps); 24 19 spin_lock_init(&rdi->pending_lock); 25 - rdi->mmap_offset = PAGE_SIZE; 20 + rdi->mmap_offset = MMAP_OFFSET_START; 26 21 spin_lock_init(&rdi->mmap_offset_lock); 27 22 } 28 23 ··· 77 72 unsigned long size = vma->vm_end - vma->vm_start; 78 73 struct rvt_mmap_info *ip, *pp; 79 74 int ret = -EINVAL; 75 + 76 + /* call driver if in reserved range */ 77 + if (offset < MMAP_OFFSET_START) { 78 + if (rdi->driver_f.mmap) 79 + return rdi->driver_f.mmap(context, vma); 80 + return -EINVAL; 81 + } 80 82 81 83 /* 82 84 * Search the device's list of objects waiting for a mmap call. ··· 141 129 142 130 spin_lock_irq(&rdi->mmap_offset_lock); 143 131 if (rdi->mmap_offset == 0) 144 - rdi->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA); 132 + rdi->mmap_offset = MMAP_OFFSET_START; 145 133 ip->offset = rdi->mmap_offset; 146 - rdi->mmap_offset += ALIGN(size, SHMLBA); 134 + rdi->mmap_offset += PAGE_SIZE; 147 135 spin_unlock_irq(&rdi->mmap_offset_lock); 148 136 149 137 INIT_LIST_HEAD(&ip->pending_mmaps); ··· 171 159 172 160 spin_lock_irq(&rdi->mmap_offset_lock); 173 161 if (rdi->mmap_offset == 0) 174 - rdi->mmap_offset = PAGE_SIZE; 162 + rdi->mmap_offset = MMAP_OFFSET_START; 175 163 ip->offset = rdi->mmap_offset; 176 - rdi->mmap_offset += size; 164 + rdi->mmap_offset += PAGE_SIZE; 177 165 spin_unlock_irq(&rdi->mmap_offset_lock); 178 166 179 167 ip->size = size;
+3
include/rdma/rdma_vt.h
··· 366 366 367 367 /* deallocate a ucontext */ 368 368 void (*dealloc_ucontext)(struct ib_ucontext *context); 369 + 370 + /* driver mmap */ 371 + int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma); 369 372 }; 370 373 371 374 struct rvt_dev_info {