* [PATCH rdma-next 1/4] IB/mlx4: Take write semaphore when changing the vma struct
@ 2017-03-29 3:03 Leon Romanovsky
[not found] ` <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Leon Romanovsky @ 2017-03-29 3:03 UTC (permalink / raw)
To: Doug Ledford; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Maor Gottlieb
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
When the driver disassociate user context, it changes the vma to
anonymous by setting the vm_ops to null and zap the vma ptes.
In order to avoid race in the kernel, we need to take write lock
before we change the vma entries.
Fixes: ae184ddeca5db ('IB/mlx4_ib: Disassociate support')
Signed-off-by: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
drivers/infiniband/hw/mlx4/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index fba94df28cf1..a2c9629f63d0 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -1173,7 +1173,7 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
/* need to protect from a race on closing the vma as part of
* mlx4_ib_vma_close().
*/
- down_read(&owning_mm->mmap_sem);
+ down_write(&owning_mm->mmap_sem);
for (i = 0; i < HW_BAR_COUNT; i++) {
vma = context->hw_bar_info[i].vma;
if (!vma)
@@ -1191,7 +1191,7 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
context->hw_bar_info[i].vma->vm_ops = NULL;
}
- up_read(&owning_mm->mmap_sem);
+ up_write(&owning_mm->mmap_sem);
mmput(owning_mm);
put_task_struct(owning_process);
}
--
2.12.0
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>]
* [PATCH rdma-next 2/4] IB/mlx4: Change vma from shared to private [not found] ` <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> @ 2017-03-29 3:03 ` Leon Romanovsky 2017-03-29 3:03 ` [PATCH rdma-next 3/4] IB/mlx5: Take write semaphore when changing the vma struct Leon Romanovsky ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: Leon Romanovsky @ 2017-03-29 3:03 UTC (permalink / raw) To: Doug Ledford; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Maor Gottlieb From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> Anonymous VMA (->vm_ops == NULL) cannot be shared, otherwise it would lead to SIGBUS. Remove the shared flags from the vma after we change it to be anonymous. This is easily reproduced by doing modprobe -r while running a user-space application such as raw_ethernet_bw. Fixes: ae184ddeca5db ('IB/mlx4_ib: Disassociate support') Signed-off-by: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- drivers/infiniband/hw/mlx4/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index a2c9629f63d0..e6efc7c34c9a 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -1187,6 +1187,8 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) BUG_ON(1); } + context->hw_bar_info[i].vma->vm_flags &= + ~(VM_SHARED | VM_MAYSHARE); /* context going to be destroyed, should not access ops any more */ context->hw_bar_info[i].vma->vm_ops = NULL; } -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH rdma-next 3/4] IB/mlx5: Take write semaphore when changing the vma struct [not found] ` <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 2017-03-29 3:03 ` [PATCH rdma-next 2/4] IB/mlx4: Change vma from shared to private Leon Romanovsky @ 2017-03-29 3:03 ` Leon Romanovsky 2017-03-29 3:03 ` [PATCH rdma-next 4/4] IB/mlx5: Change vma from shared to private Leon Romanovsky 2017-04-24 16:12 ` [PATCH rdma-next 1/4] IB/mlx4: Take write semaphore when changing the vma struct Doug Ledford 3 siblings, 0 replies; 5+ messages in thread From: Leon Romanovsky @ 2017-03-29 3:03 UTC (permalink / raw) To: Doug Ledford; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Maor Gottlieb From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> When the driver disassociate user context, it changes the vma to anonymous by setting the vm_ops to null and zap the vma ptes. In order to avoid race in the kernel, we need to take write lock before we change the vma entries. Fixes: 7c2344c3bbf97 ('IB/mlx5: Implements disassociate_ucontext API') Signed-off-by: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- drivers/infiniband/hw/mlx5/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 4dc0a8785fe0..88070a7cde48 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -1478,7 +1478,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) /* need to protect from a race on closing the vma as part of * mlx5_ib_vma_close. */ - down_read(&owning_mm->mmap_sem); + down_write(&owning_mm->mmap_sem); list_for_each_entry_safe(vma_private, n, &context->vma_private_list, list) { vma = vma_private->vma; @@ -1492,7 +1492,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) list_del(&vma_private->list); kfree(vma_private); } - up_read(&owning_mm->mmap_sem); + up_write(&owning_mm->mmap_sem); mmput(owning_mm); put_task_struct(owning_process); } -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH rdma-next 4/4] IB/mlx5: Change vma from shared to private [not found] ` <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 2017-03-29 3:03 ` [PATCH rdma-next 2/4] IB/mlx4: Change vma from shared to private Leon Romanovsky 2017-03-29 3:03 ` [PATCH rdma-next 3/4] IB/mlx5: Take write semaphore when changing the vma struct Leon Romanovsky @ 2017-03-29 3:03 ` Leon Romanovsky 2017-04-24 16:12 ` [PATCH rdma-next 1/4] IB/mlx4: Take write semaphore when changing the vma struct Doug Ledford 3 siblings, 0 replies; 5+ messages in thread From: Leon Romanovsky @ 2017-03-29 3:03 UTC (permalink / raw) To: Doug Ledford; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Maor Gottlieb From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> Anonymous VMA (->vm_ops == NULL) cannot be shared, otherwise it would lead to SIGBUS. Remove the shared flags from the vma after we change it to be anonymous. This is easily reproduced by doing modprobe -r while running a user-space application such as raw_ethernet_bw. Fixes: 7c2344c3bbf97 ('IB/mlx5: Implements disassociate_ucontext API') Signed-off-by: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- drivers/infiniband/hw/mlx5/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 88070a7cde48..3ecb3c3f6ed2 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -1488,6 +1488,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) /* context going to be destroyed, should * not access ops any more. */ + vma->vm_flags &= ~(VM_SHARED | VM_MAYSHARE); vma->vm_ops = NULL; list_del(&vma_private->list); kfree(vma_private); -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH rdma-next 1/4] IB/mlx4: Take write semaphore when changing the vma struct [not found] ` <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> ` (2 preceding siblings ...) 2017-03-29 3:03 ` [PATCH rdma-next 4/4] IB/mlx5: Change vma from shared to private Leon Romanovsky @ 2017-04-24 16:12 ` Doug Ledford 3 siblings, 0 replies; 5+ messages in thread From: Doug Ledford @ 2017-04-24 16:12 UTC (permalink / raw) To: Leon Romanovsky; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Maor Gottlieb On Wed, 2017-03-29 at 06:03 +0300, Leon Romanovsky wrote: > From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> > > When the driver disassociate user context, it changes the vma to > anonymous by setting the vm_ops to null and zap the vma ptes. > > In order to avoid race in the kernel, we need to take write lock > before we change the vma entries. > > Fixes: ae184ddeca5db ('IB/mlx4_ib: Disassociate support') > Signed-off-by: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> > Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Thanks, series applied. -- Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-04-24 16:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-29 3:03 [PATCH rdma-next 1/4] IB/mlx4: Take write semaphore when changing the vma struct Leon Romanovsky
[not found] ` <20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-03-29 3:03 ` [PATCH rdma-next 2/4] IB/mlx4: Change vma from shared to private Leon Romanovsky
2017-03-29 3:03 ` [PATCH rdma-next 3/4] IB/mlx5: Take write semaphore when changing the vma struct Leon Romanovsky
2017-03-29 3:03 ` [PATCH rdma-next 4/4] IB/mlx5: Change vma from shared to private Leon Romanovsky
2017-04-24 16:12 ` [PATCH rdma-next 1/4] IB/mlx4: Take write semaphore when changing the vma struct Doug Ledford
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox