Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3189556ybi; Mon, 10 Jun 2019 06:07:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRyl7C5jw28hBODA2SzlGBiKJ5Rbu5Ut7RBMiyetjOAIIvLjhnE7Ue9jSJw336ewREmiH/ X-Received: by 2002:a63:cc4b:: with SMTP id q11mr15723711pgi.43.1560172079262; Mon, 10 Jun 2019 06:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560172079; cv=none; d=google.com; s=arc-20160816; b=vg71/Petfaung5hgfdarDFPBGV7yjxDCh7u/YVxGygE+M/194VqMMgE5/OJEX9yiAt a5HfTq/vnt55jDko3CiL6dhbnyyCb6Hhh2B/QQq9kevh7mXSqXHPnd1jU5z+j3ebiAI8 dTfQpvDowcRoVwYOTD0G8c3JIEzLzXKfpO4wWA9Wz+xEGZKeQuqIuhviZtGyAEOYDxim Q1+b01qCUcuUJyf3fAx4nv19U3dgSG4rRdgkHqCyLaqwncX06AHPWXJNVwEA8sisCicI mpe11Zd3I4ckp871JykUtyYHst5yuPXbzeQSu9lg3DwRr4YiCXjuSZDXRIQ9BwVJ8MMg NGhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=lkzqtDkumh9+k/xNOLRTOHIAVD4FJ19ptGQVduaMtyw=; b=rw5+GEs//jnuPb4DrXVF+pBjeL/VnJ+swyfqP+ZxjlOcwi83LCGwwvtVBP6geuSjY0 zEvw1Z5tf75RJ9IK+lg6cacJUfGuLjrJ0BRTnhqmco4ZHU515X6PKNRo6qkmFV/Tp5S/ 3bl83gDZjkk6tIrBgG0iw/+4qB43Dj1jlNtejzYN3WqKyKtzgImkd3zbweJIBYvLQw2f 2VaihUvDxT5rggcewhyoeXib3rPOFYJOz8hBZc5ZYwxbe3TzWCYEpOq+NcJkhtkCzgnp IWznTspngvHLZL0mHVovTlpEZjuoJbHNLVj1r1CrsKNLjfu724n46pDx9PA+2XX5Lbax eq2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q85si10857500pfc.85.2019.06.10.06.07.42; Mon, 10 Jun 2019 06:07:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390051AbfFJMwH (ORCPT + 99 others); Mon, 10 Jun 2019 08:52:07 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:26243 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388373AbfFJMwH (ORCPT ); Mon, 10 Jun 2019 08:52:07 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Mon, 10 Jun 2019 05:51:59 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 6C6AE40E0B; Mon, 10 Jun 2019 05:52:01 -0700 (PDT) From: Ajay Kaher To: , , , , , , CC: , , , , , , , , , , , Subject: [PATCH] [v4.14.y] infiniband: fix race condition between infiniband mlx4, mlx5 driver and core dumping Date: Tue, 11 Jun 2019 02:22:17 +0530 Message-ID: <1560199937-23476-1-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: akaher@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 04f5866e41fb ("coredump: fix race condition between mmget_not_zero()/get_task_mm() and core dumping")' Thanks to Jason for pointing this. Signed-off-by: Ajay Kaher --- drivers/infiniband/hw/mlx4/main.c | 4 +++- drivers/infiniband/hw/mlx5/main.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index e2beb18..0299c06 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -1197,6 +1197,8 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) * mlx4_ib_vma_close(). */ down_write(&owning_mm->mmap_sem); + if (!mmget_still_valid(owning_mm)) + goto skip_mm; for (i = 0; i < HW_BAR_COUNT; i++) { vma = context->hw_bar_info[i].vma; if (!vma) @@ -1215,7 +1217,7 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) /* context going to be destroyed, should not access ops any more */ context->hw_bar_info[i].vma->vm_ops = NULL; } - +skip_mm: up_write(&owning_mm->mmap_sem); mmput(owning_mm); put_task_struct(owning_process); diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 13a9206..3fbe396 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -1646,6 +1646,8 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) * mlx5_ib_vma_close. */ down_write(&owning_mm->mmap_sem); + if (!mmget_still_valid(owning_mm)) + goto skip_mm; mutex_lock(&context->vma_private_list_mutex); list_for_each_entry_safe(vma_private, n, &context->vma_private_list, list) { @@ -1662,6 +1664,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) kfree(vma_private); } mutex_unlock(&context->vma_private_list_mutex); +skip_mm: up_write(&owning_mm->mmap_sem); mmput(owning_mm); put_task_struct(owning_process); -- 2.7.4