Skip to content

Commit cb88645

Browse files
jgunthorpedledford
authored andcommitted
infiniband: Fix alignment of mmap cookies to support VIPT caching
When vmalloc_user is used to create memory that is supposed to be mmap'd to user space, it is necessary for the mmap cookie (eg the offset) to be aligned to SHMLBA. This creates a situation where all virtual mappings of the same physical page share the same virtual cache index and guarantees VIPT coherence. Otherwise the cache is non-coherent and the kernel will not see writes by userspace when reading the shared page (or vice-versa). Reported-by: Josh Beavers <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 86f46ab commit cb88645

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/infiniband/sw/rdmavt/mmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi,
170170

171171
spin_lock_irq(&rdi->mmap_offset_lock);
172172
if (rdi->mmap_offset == 0)
173-
rdi->mmap_offset = PAGE_SIZE;
173+
rdi->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA);
174174
ip->offset = rdi->mmap_offset;
175-
rdi->mmap_offset += size;
175+
rdi->mmap_offset += ALIGN(size, SHMLBA);
176176
spin_unlock_irq(&rdi->mmap_offset_lock);
177177

178178
INIT_LIST_HEAD(&ip->pending_mmaps);

drivers/infiniband/sw/rxe/rxe_mmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *rxe,
156156
spin_lock_bh(&rxe->mmap_offset_lock);
157157

158158
if (rxe->mmap_offset == 0)
159-
rxe->mmap_offset = PAGE_SIZE;
159+
rxe->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA);
160160

161161
ip->info.offset = rxe->mmap_offset;
162-
rxe->mmap_offset += size;
162+
rxe->mmap_offset += ALIGN(size, SHMLBA);
163163

164164
spin_unlock_bh(&rxe->mmap_offset_lock);
165165

0 commit comments

Comments
 (0)