From patchwork Mon Jun 24 21:03:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 11013031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93EC9186E for ; Mon, 24 Jun 2019 13:03:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8382E2842E for ; Mon, 24 Jun 2019 13:03:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 775E7287A1; Mon, 24 Jun 2019 13:03:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C4C328779 for ; Mon, 24 Jun 2019 13:03:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B708B6B0007; Mon, 24 Jun 2019 09:02:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AFA048E0003; Mon, 24 Jun 2019 09:02:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 972BC8E0002; Mon, 24 Jun 2019 09:02:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 642146B0007 for ; Mon, 24 Jun 2019 09:02:59 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id d3so9353561pgc.9 for ; Mon, 24 Jun 2019 06:02:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version; bh=WlB3EgfbNvNkzCBJJCkZdYVxKpEST/NPutqyeaBnRhg=; b=MHIaWdT6V0uOBxxEtH3tdRMiXbFEmCH8SqHVkw/2VMp4PnkrejTwP3kg7IRWAuSPtt zv1NO0EpX+7kIkq/6V4Rmu2NW9SRf+sIITZe7CpQItt5w/zDqO4FwllgkfaIXkV5s/Oa 7SNjwhZGHxlk+l7vPIPIqhkZ/EDZLOI6qwXRgTU4dTEJzTE2PsEyNeUgrAPhOdRrMvsS HYOBsybhznVCHnK+a5Iq17Z5dbe1KjpsZcZyW5Y+vvu3+ORblPHbf+xZYEi++uuZ46Jj MvN12ANBualEisiuIVI6xLMDtazaHoJ2DMfso4gHBl0ZyaNLnBLdDAVeOEovhTOcBmD3 H64A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of akaher@vmware.com designates 208.91.0.190 as permitted sender) smtp.mailfrom=akaher@vmware.com; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com X-Gm-Message-State: APjAAAUYEEGg29qndTU9I5fvgon04Ix2JUyUNNP+l/lkKlE5ivMgng6s i37h+lM4VXdJL5O+eSIkEnhmAYZTJNk2pXSFk7/90mZObo3t6JByXjSGSyEgTngeTdkdoXtF6Yc Xe4eg018TBXo6x6T9R6SOroveQaJeOqNlBHrfoNhl64c0wWwLxxq0LePhrSQtV/+TtA== X-Received: by 2002:a17:90a:d983:: with SMTP id d3mr24322989pjv.88.1561381379097; Mon, 24 Jun 2019 06:02:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCgtf6QxHXH6C1HDWDuzpnGBKaj/2bySKu85TqciWW5tkfLlKi4A8KvyZmVNB0oM2jgW5b X-Received: by 2002:a17:90a:d983:: with SMTP id d3mr24322906pjv.88.1561381378408; Mon, 24 Jun 2019 06:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561381378; cv=none; d=google.com; s=arc-20160816; b=U47sRwdmd5nUnpK8PNtGlcAvf8sX7jAAC+DzcvWUGJDjYrFatOZf3gF/ncYnh7EU/0 xaFV/nnAOFJK+OjXiPUp/vY5VaQ3sj7lAMAaVSGLCYUKNsDhUx3p3zL1IpQEBN1pwaBL U3pUhTx77l/AJryVuEKlNPQxeEZ7z00JDg5770yNqq6pt36DJaIfxrYMIrHvnJryJm2k DXl5y65GYVfF8EScFCQUlpUGm9LuKTkf1o5SRyn5mYMeHTkfV+Wog9uTjmZ0kGUz4GpO 51g09U0kAThQMjt9PV8FrXOcSsdbJl5gRipHx9tByGOTIyHoos7SgEidLx54iiDW46z0 oq3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=WlB3EgfbNvNkzCBJJCkZdYVxKpEST/NPutqyeaBnRhg=; b=wMFp98DTOTQLAUQl2WL3x6BjHyAyBGDjergq0dan3tCi/RRcuPUAF5f7v4vAOg57TK UwUmUmV/sTClHV+9Wlem+px42s7/A48zA6GVQWtSsXCD5xPFlOSIGg3hCYw0Dnuz4Kak ugmuuwiMdjFjRTaXtkaoaPHjsXv9eeGfUuy5BvDS610PVc1Vv1G4OBYPoE7PXB/lJOY/ eCaLeX684rczNBvKHASapwvuUFMkbe0RCveHqqNHQyqcqGEPKGuf6rcAigtY0G4Tys1s wa80anXGoVwQTavtZlYm2pAVSo3UIF5ZnJ4QRRpLEIpmpwKTzrOhB36xy65ptdRzqDPS G/ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of akaher@vmware.com designates 208.91.0.190 as permitted sender) smtp.mailfrom=akaher@vmware.com; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com. [208.91.0.190]) by mx.google.com with ESMTPS id v7si11880352pfb.132.2019.06.24.06.02.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Jun 2019 06:02:58 -0700 (PDT) Received-SPF: pass (google.com: domain of akaher@vmware.com designates 208.91.0.190 as permitted sender) client-ip=208.91.0.190; Authentication-Results: mx.google.com; spf=pass (google.com: domain of akaher@vmware.com designates 208.91.0.190 as permitted sender) smtp.mailfrom=akaher@vmware.com; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Mon, 24 Jun 2019 06:02:56 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 8452E412C5; Mon, 24 Jun 2019 06:02:51 -0700 (PDT) From: Ajay Kaher To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 2/3][v4.9.y] coredump: fix race condition between mmget_not_zero()/get_task_mm() and core dumping Date: Tue, 25 Jun 2019 02:33:04 +0530 Message-ID: <1561410186-3919-2-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561410186-3919-1-git-send-email-akaher@vmware.com> References: <1561410186-3919-1-git-send-email-akaher@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: akaher@vmware.com does not designate permitted sender hosts) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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);