Commit 91c3a6ce authored by Ajay Kaher's avatar Ajay Kaher Committed by Greg Kroah-Hartman

infiniband: fix race condition between infiniband mlx4, mlx5 driver and core dumping

This patch is the extension of following upstream commit to fix
the race condition between get_task_mm() and core dumping
for IB->mlx4 and IB->mlx5 drivers:

commit 04f5866e ("coredump: fix race condition between
mmget_not_zero()/get_task_mm() and core dumping")'

Thanks to Jason for pointing this.
Signed-off-by: default avatarAjay Kaher <akaher@vmware.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 16903f1a
...@@ -1172,6 +1172,8 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) ...@@ -1172,6 +1172,8 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
* mlx4_ib_vma_close(). * mlx4_ib_vma_close().
*/ */
down_write(&owning_mm->mmap_sem); down_write(&owning_mm->mmap_sem);
if (!mmget_still_valid(owning_mm))
goto skip_mm;
for (i = 0; i < HW_BAR_COUNT; i++) { for (i = 0; i < HW_BAR_COUNT; i++) {
vma = context->hw_bar_info[i].vma; vma = context->hw_bar_info[i].vma;
if (!vma) if (!vma)
...@@ -1190,7 +1192,7 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) ...@@ -1190,7 +1192,7 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
/* context going to be destroyed, should not access ops any more */ /* context going to be destroyed, should not access ops any more */
context->hw_bar_info[i].vma->vm_ops = NULL; context->hw_bar_info[i].vma->vm_ops = NULL;
} }
skip_mm:
up_write(&owning_mm->mmap_sem); up_write(&owning_mm->mmap_sem);
mmput(owning_mm); mmput(owning_mm);
put_task_struct(owning_process); put_task_struct(owning_process);
......
...@@ -1307,6 +1307,8 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) ...@@ -1307,6 +1307,8 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
* mlx5_ib_vma_close. * mlx5_ib_vma_close.
*/ */
down_write(&owning_mm->mmap_sem); down_write(&owning_mm->mmap_sem);
if (!mmget_still_valid(owning_mm))
goto skip_mm;
list_for_each_entry_safe(vma_private, n, &context->vma_private_list, list_for_each_entry_safe(vma_private, n, &context->vma_private_list,
list) { list) {
vma = vma_private->vma; vma = vma_private->vma;
...@@ -1321,6 +1323,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) ...@@ -1321,6 +1323,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
list_del(&vma_private->list); list_del(&vma_private->list);
kfree(vma_private); kfree(vma_private);
} }
skip_mm:
up_write(&owning_mm->mmap_sem); up_write(&owning_mm->mmap_sem);
mmput(owning_mm); mmput(owning_mm);
put_task_struct(owning_process); put_task_struct(owning_process);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment