Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2016549ybi; Mon, 1 Jul 2019 04:44:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzH3Bkf+StkBviwz82HjMUPFDpF771hXWNkvaWDx57Mdjd6tlgDLcjm1sUJY1PvRPRYsyeu X-Received: by 2002:a17:90a:2190:: with SMTP id q16mr29798627pjc.23.1561981444102; Mon, 01 Jul 2019 04:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561981444; cv=none; d=google.com; s=arc-20160816; b=W8Mjugv8zgcBHUCTN4SQuj1SotPS8eczdV1BPF44165fNFAIUF67uhPYSm76NcgtTN mpaiG9ElkpnlQdL+W+DC3fJjYZZbo2OZLaFcQ4cxMpSqQsZYblmJDNoXohYjcs9tGqhj lychOLj3/G4F0DrerYES95yxfEC/k8Mv9Uxl0E4U/Vk+QFLap8aUVHrRJqBp/5D1jkQ8 v5Uf0cfxD6TwOxb8bPkivV7LieScOROCtSq2O6LhWXRd+R83l5IQ075lBNeKOIj851Sd BxXXuX/ZmGLbV+CfdJr8GcpXFH0f7KpgvjrbsJ9sMSCEI7d2IepJpCYJjc/EUSNpmujD mdmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=hAAPf9o3GFQ98ap/3N6Z0MHRNPvvF/o7ljIAlON1qEM=; b=mZrUek7fdQuOcYB25QIOo2Iz8HuLM0ndtwAXGun3TTsHg/ZaA0+KwFw+VNG5ioVGgr TE9dQ9Yta3VO/u0VmjieI5di4aiC6U9S5a41+pGuPZW1waNx/BMABLEHq1c/JyFMw9Ub uvmwauaGHPG4E7MHJB0MCWjGIYifj1+d/5O+b/qSCS47PACuS+1x3/uQIYoQ5eXjTWc8 FxqDHVKNH9A2c/6Ph1wBO8J2iajxBAnDvZqKojh7Qb+FXDP7GBeVU2OQ7XM37h1cb470 l+XMsev6s1uU959dTzrVQ76F98bUOvQKQSb0qCjORdlvDMkeTxo7rluFMfo8DHMvw8qg EjWg== 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 a1si9931569pgh.196.2019.07.01.04.43.48; Mon, 01 Jul 2019 04:44:04 -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 S1728923AbfGAKc0 (ORCPT + 99 others); Mon, 1 Jul 2019 06:32:26 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:17544 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726076AbfGAKc0 (ORCPT ); Mon, 1 Jul 2019 06:32:26 -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, 1 Jul 2019 03:32:22 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 03F3E40FF9; Mon, 1 Jul 2019 03:32:17 -0700 (PDT) From: Ajay Kaher To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 2/3][v4.9.y] infiniband: fix race condition between infiniband mlx4, mlx5 driver and core dumping Date: Tue, 2 Jul 2019 00:02:06 +0530 Message-ID: <1562005928-1929-2-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1562005928-1929-1-git-send-email-akaher@vmware.com> References: <1562005928-1929-1-git-send-email-akaher@vmware.com> 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 Reviewed-by: Jason Gunthorpe --- 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 8d59a59..7ccf722 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -1172,6 +1172,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) @@ -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->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 b1daf5c..f94df0e 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -1307,6 +1307,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; list_for_each_entry_safe(vma_private, n, &context->vma_private_list, list) { vma = vma_private->vma; @@ -1321,6 +1323,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) list_del(&vma_private->list); kfree(vma_private); } +skip_mm: up_write(&owning_mm->mmap_sem); mmput(owning_mm); put_task_struct(owning_process); -- 2.7.4