IB/mlx4: Take write semaphore when changing the vma struct
Subsystems (3)
PATCH 1/4 IB/mlx4: Take write semaphore when changing the vma struct
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
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.
--- drivers/infiniband/hw/mlx4/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx4/main.c +2 -2
@@ -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); }
Signature · 6 lines
2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20170329030303.4942-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
PATCH 2/4 IB/mlx4: Change vma from shared to private
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
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.
--- drivers/infiniband/hw/mlx4/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/infiniband/hw/mlx4/main.c +2 -0
@@ -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 ; }
Signature · 6 lines
2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/4 IB/mlx5: Take write semaphore when changing the vma struct
In reply to a message not in the archiveFrom: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
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.
--- drivers/infiniband/hw/mlx5/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/main.c +2 -2
@@ -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); }
Signature · 6 lines
2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/4 IB/mlx5: Change vma from shared to private
In reply to a message not in the archiveFrom: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
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.
--- drivers/infiniband/hw/mlx5/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/infiniband/hw/mlx5/main.c +1 -0
@@ -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);
Signature · 6 lines
2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Leon Romanovsky
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
When the driver disassociate user context, it changes the vma to anonymous by setting the
vm_opsto 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 Leon Romanovsky <[email protected]>
Thanks, series applied.
Signature · 9 lines
Doug Ledford <[email protected]> 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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html