From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA59ECAAD2 for ; Mon, 29 Aug 2022 08:16:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 479D3940008; Mon, 29 Aug 2022 04:16:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 429CD940007; Mon, 29 Aug 2022 04:16:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F123940008; Mon, 29 Aug 2022 04:16:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1B9FD940007 for ; Mon, 29 Aug 2022 04:16:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DEDC9A0585 for ; Mon, 29 Aug 2022 08:16:03 +0000 (UTC) X-FDA: 79851922206.24.8B4BF29 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 0304B180017 for ; Mon, 29 Aug 2022 08:16:01 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0BC6060DC0; Mon, 29 Aug 2022 08:16:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E87ADC433C1; Mon, 29 Aug 2022 08:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661760960; bh=UWwY3Af7IKEUO4nLKlGbtQuRQ96FU24HUXJEzDT7wqs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ul4+n76QreCtEx5zZF4zYm/1yCAfE5t952aAwI/VjV4og2KeZsHEf9f/UO2Z6BYdE ZIXLw40dLL6ybKnLhjgauM1XZl5HfqhAdcPWFbeuF0rWNjvlYKFwx8bPSeXsaSGtHg we40gi9cvKxImoX+1Qq/zcgguSOSEGXanEwSljHyWP/pnA8T0nBBXbsUXp2w4FstHR JEqJdBuTLQbR77dyqEk7KP/41iozoKNNrEPEMTDktvTiaEdVoMxB5KregHVhDD8eG/ GueEX/9nh9m/xGe6aaRWC9+x5s6nsUf/w3fdrxkMINifbYCwx2FEpewf7giUxUAat7 Qpp43u4faobxQ== Date: Mon, 29 Aug 2022 11:15:56 +0300 From: Leon Romanovsky To: Jason Gunthorpe , Andrew Morton , linux-mm@kvack.org Cc: Yishai Hadas , linux-rdma@vger.kernel.org, Maor Gottlieb , linux-kernel@vger.kernel.org, Thomas Gleixner Subject: Re: [PATCH RESEND rdma-rc] IB/core: Fix a nested dead lock as part of ODP flow Message-ID: References: <74d93541ea533ef7daec6f126deb1072500aeb16.1661251841.git.leonro@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <74d93541ea533ef7daec6f126deb1072500aeb16.1661251841.git.leonro@nvidia.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661760962; a=rsa-sha256; cv=none; b=xM3eyzJCPQp3MEd4jlWJo3QBjYvRPpHJpe3WyiniCZZ+fWJfQW+TMMv4WbpEQzj3hci95v iC4P4rBQctsGSb1DJ+Y5dlZDE0qmJTG6kb8muI88ZEadwRPGZGaiJRvR+hCbknggcJulNA qtwOOWd0uxljrALdmUBQsLyEyyW82B8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ul4+n76Q; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=leon@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661760962; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SGU2iAYMIuZ1UXuZtQZ+e5Z3N0Ipt+zEdpmYTlcHPO4=; b=1E9En+KqHl2Kl0hPKJJ/zs9xmakmjaSAE4uRla1EH5Xdy7ZnI+1KIyRvMNR4UGjYkOxpmm 91reF8+oX6Vq2FahDnWz0fDHeYgUcAAQUjlq1Kl3gUd0efXxx7HQbvAGabFKWoQPWNZ5Gq 04UChagYg6Dk347RZuX/MuVYgylvbnY= X-Stat-Signature: 5o4nuqm3tdq9h991png36nktfkchkzc9 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ul4+n76Q; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=leon@kernel.org X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0304B180017 X-Rspam-User: X-HE-Tag: 1661760961-712926 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: On Wed, Aug 24, 2022 at 09:10:36AM +0300, Leon Romanovsky wrote: > From: Yishai Hadas > > Fix a nested dead lock as part of ODP flow by using mmput_async(). > > From the below call trace [1] can see that calling mmput() once we have > the umem_odp->umem_mutex locked as required by > ib_umem_odp_map_dma_and_lock() might trigger in the same task the > exit_mmap()->__mmu_notifier_release()->mlx5_ib_invalidate_range() which > may dead lock when trying to lock the same mutex. > > Moving to use mmput_async() will solve the problem as the above > exit_mmap() flow will be called in other task and will be executed once > the lock will be available. > > [1] > [64843.077665] task:kworker/u133:2 state:D stack: 0 pid:80906 ppid: > 2 flags:0x00004000 > [64843.077672] Workqueue: mlx5_ib_page_fault mlx5_ib_eqe_pf_action [mlx5_ib] > [64843.077719] Call Trace: > [64843.077722] > [64843.077724] __schedule+0x23d/0x590 > [64843.077729] schedule+0x4e/0xb0 > [64843.077735] schedule_preempt_disabled+0xe/0x10 > [64843.077740] __mutex_lock.constprop.0+0x263/0x490 > [64843.077747] __mutex_lock_slowpath+0x13/0x20 > [64843.077752] mutex_lock+0x34/0x40 > [64843.077758] mlx5_ib_invalidate_range+0x48/0x270 [mlx5_ib] > [64843.077808] __mmu_notifier_release+0x1a4/0x200 > [64843.077816] exit_mmap+0x1bc/0x200 > [64843.077822] ? walk_page_range+0x9c/0x120 > [64843.077828] ? __cond_resched+0x1a/0x50 > [64843.077833] ? mutex_lock+0x13/0x40 > [64843.077839] ? uprobe_clear_state+0xac/0x120 > [64843.077860] mmput+0x5f/0x140 > [64843.077867] ib_umem_odp_map_dma_and_lock+0x21b/0x580 [ib_core] > [64843.077931] pagefault_real_mr+0x9a/0x140 [mlx5_ib] > [64843.077962] pagefault_mr+0xb4/0x550 [mlx5_ib] > [64843.077992] pagefault_single_data_segment.constprop.0+0x2ac/0x560 > [mlx5_ib] > [64843.078022] mlx5_ib_eqe_pf_action+0x528/0x780 [mlx5_ib] > [64843.078051] process_one_work+0x22b/0x3d0 > [64843.078059] worker_thread+0x53/0x410 > [64843.078065] ? process_one_work+0x3d0/0x3d0 > [64843.078073] kthread+0x12a/0x150 > [64843.078079] ? set_kthread_struct+0x50/0x50 > [64843.078085] ret_from_fork+0x22/0x30 > [64843.078093] > > Fixes: 36f30e486dce ("IB/core: Improve ODP to use hmm_range_fault()") > Reviewed-by: Maor Gottlieb > Signed-off-by: Yishai Hadas > Signed-off-by: Leon Romanovsky > --- > Resend to larger forum. > https://lore.kernel.org/all/74d93541ea533ef7daec6f126deb1072500aeb16.1661251841.git.leonro@nvidia.com > --- > drivers/infiniband/core/umem_odp.c | 2 +- > kernel/fork.c | 1 + > 2 files changed, 2 insertions(+), 1 deletion(-) Any objections? Thanks > > diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c > index 186ed8859920..d39e16c211e8 100644 > --- a/drivers/infiniband/core/umem_odp.c > +++ b/drivers/infiniband/core/umem_odp.c > @@ -462,7 +462,7 @@ int ib_umem_odp_map_dma_and_lock(struct ib_umem_odp *umem_odp, u64 user_virt, > mutex_unlock(&umem_odp->umem_mutex); > > out_put_mm: > - mmput(owning_mm); > + mmput_async(owning_mm); > out_put_task: > if (owning_process) > put_task_struct(owning_process); > diff --git a/kernel/fork.c b/kernel/fork.c > index 90c85b17bf69..8a9e92068b15 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1225,6 +1225,7 @@ void mmput_async(struct mm_struct *mm) > schedule_work(&mm->async_put_work); > } > } > +EXPORT_SYMBOL_GPL(mmput_async); > #endif > > /** > -- > 2.37.2 >