aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gunthorpe <jgunthorpe@obsidianresearch.com>2017-03-10 13:34:20 -0500
committerDoug Ledford <dledford@redhat.com>2017-03-24 16:50:51 -0400
commitcb8864559631754ac93d5734b165ccd0cad4728c (patch)
treeebc218fa46b4ca0feb11029cb7acaab9d0086d1a
parent86f46aba8d1ac3ed0904542158a9b9cb9c7a143c (diff)
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 <josh.beavers@gmail.com> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/sw/rdmavt/mmap.c4
-rw-r--r--drivers/infiniband/sw/rxe/rxe_mmap.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/drivers/infiniband/sw/rdmavt/mmap.c b/drivers/infiniband/sw/rdmavt/mmap.c
index e202b8142759..6b712eecbd37 100644
--- a/drivers/infiniband/sw/rdmavt/mmap.c
+++ b/drivers/infiniband/sw/rdmavt/mmap.c
@@ -170,9 +170,9 @@ struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi,
170 170
171 spin_lock_irq(&rdi->mmap_offset_lock); 171 spin_lock_irq(&rdi->mmap_offset_lock);
172 if (rdi->mmap_offset == 0) 172 if (rdi->mmap_offset == 0)
173 rdi->mmap_offset = PAGE_SIZE; 173 rdi->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA);
174 ip->offset = rdi->mmap_offset; 174 ip->offset = rdi->mmap_offset;
175 rdi->mmap_offset += size; 175 rdi->mmap_offset += ALIGN(size, SHMLBA);
176 spin_unlock_irq(&rdi->mmap_offset_lock); 176 spin_unlock_irq(&rdi->mmap_offset_lock);
177 177
178 INIT_LIST_HEAD(&ip->pending_mmaps); 178 INIT_LIST_HEAD(&ip->pending_mmaps);
diff --git a/drivers/infiniband/sw/rxe/rxe_mmap.c b/drivers/infiniband/sw/rxe/rxe_mmap.c
index c572a4c09359..bd812e00988e 100644
--- a/drivers/infiniband/sw/rxe/rxe_mmap.c
+++ b/drivers/infiniband/sw/rxe/rxe_mmap.c
@@ -156,10 +156,10 @@ struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *rxe,
156 spin_lock_bh(&rxe->mmap_offset_lock); 156 spin_lock_bh(&rxe->mmap_offset_lock);
157 157
158 if (rxe->mmap_offset == 0) 158 if (rxe->mmap_offset == 0)
159 rxe->mmap_offset = PAGE_SIZE; 159 rxe->mmap_offset = ALIGN(PAGE_SIZE, SHMLBA);
160 160
161 ip->info.offset = rxe->mmap_offset; 161 ip->info.offset = rxe->mmap_offset;
162 rxe->mmap_offset += size; 162 rxe->mmap_offset += ALIGN(size, SHMLBA);
163 163
164 spin_unlock_bh(&rxe->mmap_offset_lock); 164 spin_unlock_bh(&rxe->mmap_offset_lock);
165 165