Return-Path: Received: from omzsmtpe02.verizonbusiness.com ([199.249.25.209]:42381 "EHLO omzsmtpe02.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753159AbdLMB6W (ORCPT ); Tue, 12 Dec 2017 20:58:22 -0500 From: alexander.levin@verizon.com Cc: Jason Gunthorpe , Doug Ledford , alexander.levin@verizon.com To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH AUTOSEL for 4.9 045/100] infiniband: Fix alignment of mmap cookies to support VIPT caching Date: Wed, 13 Dec 2017 01:57:33 +0000 Message-ID: <20171213015722.6722-20-alexander.levin@verizon.com> References: <20171213015722.6722-1-alexander.levin@verizon.com> In-Reply-To: <20171213015722.6722-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jason Gunthorpe [ Upstream commit cb8864559631754ac93d5734b165ccd0cad4728c ] 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 Signed-off-by: Jason Gunthorpe Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rdmavt/mmap.c | 4 ++-- drivers/infiniband/sw/rxe/rxe_mmap.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/sw/rdmavt/mmap.c b/drivers/infiniband/sw/rd= mavt/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_d= ev_info *rdi, =20 spin_lock_irq(&rdi->mmap_offset_lock); if (rdi->mmap_offset =3D=3D 0) - rdi->mmap_offset =3D PAGE_SIZE; + rdi->mmap_offset =3D ALIGN(PAGE_SIZE, SHMLBA); ip->offset =3D rdi->mmap_offset; - rdi->mmap_offset +=3D size; + rdi->mmap_offset +=3D ALIGN(size, SHMLBA); spin_unlock_irq(&rdi->mmap_offset_lock); =20 INIT_LIST_HEAD(&ip->pending_mmaps); diff --git a/drivers/infiniband/sw/rxe/rxe_mmap.c b/drivers/infiniband/sw/r= xe/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, spin_lock_bh(&rxe->mmap_offset_lock); =20 if (rxe->mmap_offset =3D=3D 0) - rxe->mmap_offset =3D PAGE_SIZE; + rxe->mmap_offset =3D ALIGN(PAGE_SIZE, SHMLBA); =20 ip->info.offset =3D rxe->mmap_offset; - rxe->mmap_offset +=3D size; + rxe->mmap_offset +=3D ALIGN(size, SHMLBA); =20 spin_unlock_bh(&rxe->mmap_offset_lock); =20 --=20 2.11.0