From patchwork Thu Jul 16 15:30:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 11667797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C1EE913 for ; Thu, 16 Jul 2020 15:31:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 38179206F5 for ; Thu, 16 Jul 2020 15:31:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38179206F5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4664A8D0021; Thu, 16 Jul 2020 11:31:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 417878D0016; Thu, 16 Jul 2020 11:31:11 -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 3549F8D0021; Thu, 16 Jul 2020 11:31:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 2175C8D0016 for ; Thu, 16 Jul 2020 11:31:11 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8CE0C2DFD for ; Thu, 16 Jul 2020 15:31:10 +0000 (UTC) X-FDA: 77044327500.28.bead75_0b0f5c426f03 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 9BF736D93 for ; Thu, 16 Jul 2020 15:31:02 +0000 (UTC) X-Spam-Summary: 1,0,0,466dc70f9c687526,d41d8cd98f00b204,penguin-kernel@i-love.sakura.ne.jp,,RULES_HIT:41:355:379:541:960:967:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2393:2525:2559:2563:2682:2685:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6261:9025:10004:11026:11473:11658:11914:12043:12050:12296:12297:12438:12517:12519:12523:12532:12555:12895:13069:13075:13311:13357:14181:14384:14394:14721:21080:21324:21365:21433:21451:21627:21939:30054:30070,0,RBL:202.181.97.72:@i-love.sakura.ne.jp:.lbl8.mailshell.net-64.201.201.201 62.8.10.100;04yrwixeqjfbbdz41imtgt4ex6zj3yp1kpzdame4fepyaiqj1gpabes5q5h46ts.6ryunx1e97jhoj65831zfdhcy8q36f41r7u6eucrs9ntq5kwgw93o9gnuxcpjcg.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_S UMMARY:n X-HE-Tag: bead75_0b0f5c426f03 X-Filterd-Recvd-Size: 2746 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Jul 2020 15:31:01 +0000 (UTC) Received: from fsav102.sakura.ne.jp (fsav102.sakura.ne.jp [27.133.134.229]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 06GFUgOo080175; Fri, 17 Jul 2020 00:30:42 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav102.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav102.sakura.ne.jp); Fri, 17 Jul 2020 00:30:42 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav102.sakura.ne.jp) Received: from localhost.localdomain (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 06GFUbtS079989 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 17 Jul 2020 00:30:42 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Andrew Morton Cc: linux-mm , Tetsuo Handa Subject: [PATCH] mm: Warn mmput() from memory reclaim context. Date: Fri, 17 Jul 2020 00:30:34 +0900 Message-Id: <20200716153034.4935-1-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 2.18.4 X-Rspamd-Queue-Id: 9BF736D93 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: syzbot is reporting that mmput() from shrinker function has a risk of deadlock [1], for delayed_uprobe_add() from update_ref_ctr() calls kzalloc(GFP_KERNEL) with delayed_uprobe_lock held, and uprobe_clear_state() from __mmput() also holds delayed_uprobe_lock. However, it took 18 months to hit this race for the third time, for mmput() invokes __mmput() only when ->mm_users dropped to 0. If we always warn like might_sleep(), we can detect the possibility of deadlock more easier. For now, I inlined the check under CONFIG_PROVE_LOCKING. If we find more locations, we could introduce a macro like might_sleep(). [1] https://syzkaller.appspot.com/bug?id=bc9e7303f537c41b2b0cc2dfcea3fc42964c2d45 Signed-off-by: Tetsuo Handa --- kernel/fork.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index efc5493203ae..8717ce50ff0d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1109,6 +1109,10 @@ static inline void __mmput(struct mm_struct *mm) void mmput(struct mm_struct *mm) { might_sleep(); +#ifdef CONFIG_PROVE_LOCKING + /* Calling mmput() from shrinker context can deadlock. */ + WARN_ON(current->flags & PF_MEMALLOC); +#endif if (atomic_dec_and_test(&mm->mm_users)) __mmput(mm);