From patchwork Mon Aug 26 20:14:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11115493 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 07DA816B1 for ; Mon, 26 Aug 2019 20:14:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BAB58217F5 for ; Mon, 26 Aug 2019 20:14:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="He9JFSR4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BAB58217F5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4DCCC6B0275; Mon, 26 Aug 2019 16:14:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 48D9C6B0277; Mon, 26 Aug 2019 16:14:35 -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 357C36B0278; Mon, 26 Aug 2019 16:14:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 0D91A6B0275 for ; Mon, 26 Aug 2019 16:14:35 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id A1F50824CA3B for ; Mon, 26 Aug 2019 20:14:34 +0000 (UTC) X-FDA: 75865681668.26.bears74_44fa9fbceae25 X-Spam-Summary: 2,0,0,869d9da257318f65,d41d8cd98f00b204,daniel.vetter@ffwll.ch,:linux-kernel@vger.kernel.org::dri-devel@lists.freedesktop.org:daniel.vetter@ffwll.ch:jgg@ziepe.ca:chris@chris-wilson.co.uk:akpm@linux-foundation.org:rientjes@google.com:jglisse@redhat.com:mhocko@suse.com:christian.koenig@amd.com:gregkh@linuxfoundation.org:rppt@linux.vnet.ibm.com:jgg@mellanox.com:daniel.vetter@intel.com,RULES_HIT:41:152:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1500:1515:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3873:3874:4119:4250:4321:4385:4605:5007:6119:6261:6653:6742:8660:9010:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12679:12895:13148:13161:13229:13230:13846:13894:14096:14097:14181:14394:14659:14721:21063:21080:21222:21433:21444:21451:21627:21740:30029:30054:30056:30064:30070:30080,0,RBL:209.85.20 8.66:@ff X-HE-Tag: bears74_44fa9fbceae25 X-Filterd-Recvd-Size: 8267 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 20:14:33 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id f22so28143552edt.4 for ; Mon, 26 Aug 2019 13:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o7ZUgQ2t4EFE1mwtpJ1URNzAUsS76Vtu8jaG9dFn1TA=; b=He9JFSR4idYfY3cTrY5TrEj3IMz4MATcFkTbswKaFuTjJVLXrG8g5PlXrG5qVP0BAC vftisf9Y9ImOBlYxAlQuHQAvI72a+KbZ0fnsIWd3BIIgIdpM2sGiWSs2EGrPZfBpVrw1 hbx/vccXAWEoMwnC29A6T7olib4cw3Y+5UUpc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o7ZUgQ2t4EFE1mwtpJ1URNzAUsS76Vtu8jaG9dFn1TA=; b=ZWxIAg5eg4f7t6kS3/PczdEoS1s4TbGOuSHaZXGY6AodJ1WehEchJjA5N1B8XjYjmq 5k5M/DwfeloDY8d7ZYF1/eW7vcc9LUuQ+kAfd8p7wXeYCV6lcv66VpN5DKaAQa6YXouY ek5k+T9axQ4+Pbdqo/CIKDHxrWCvqdRQcPvl4E3iHnNxwl5/ynj+Z2b5hItSUin3dHA7 Ga36ZqDt6+grpf/dVvujLFPONvDjpQEgRPzd+KOssRUtrAjZLvCaSqr9qD8b8qwiNk1O 70k6B9MXKGeuLJyn9IhfzrIpTDI08bhdDtwEnUE71/4qaoZZNM8x14yYz8AvHr86EjPd tDnA== X-Gm-Message-State: APjAAAWW/1wWz2YOsPAyKBkEUt1bSJPt9qHV04yUcFYldM1TWX9xRL8N zH9f2qhUrl+cxaSJ3vOf3VBQCQ== X-Google-Smtp-Source: APXvYqwI2mGanGH2sozUgL+eYbKM81N0+mUwsmoxd/Kj0A+ZkgeS/zd44/6ltxt/cAqXnGD7EXIVMA== X-Received: by 2002:a50:ab5d:: with SMTP id t29mr20833370edc.32.1566850472927; Mon, 26 Aug 2019 13:14:32 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id j25sm3000780ejb.49.2019.08.26.13.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 13:14:32 -0700 (PDT) From: Daniel Vetter To: LKML Cc: Linux MM , DRI Development , Daniel Vetter , Jason Gunthorpe , Chris Wilson , Andrew Morton , David Rientjes , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Michal Hocko , =?utf-8?q?Christian_K=C3=B6nig?= , Greg Kroah-Hartman , Mike Rapoport , Jason Gunthorpe , Daniel Vetter Subject: [PATCH 1/5] mm, notifier: Add a lockdep map for invalidate_range_start/end Date: Mon, 26 Aug 2019 22:14:21 +0200 Message-Id: <20190826201425.17547-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190826201425.17547-1-daniel.vetter@ffwll.ch> References: <20190826201425.17547-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: This is a similar idea to the fs_reclaim fake lockdep lock. It's fairly easy to provoke a specific notifier to be run on a specific range: Just prep it, and then munmap() it. A bit harder, but still doable, is to provoke the mmu notifiers for all the various callchains that might lead to them. But both at the same time is really hard to reliable hit, especially when you want to exercise paths like direct reclaim or compaction, where it's not easy to control what exactly will be unmapped. By introducing a lockdep map to tie them all together we allow lockdep to see a lot more dependencies, without having to actually hit them in a single challchain while testing. On Jason's suggestion this is is rolled out for both invalidate_range_start and invalidate_range_end. They both have the same calling context, hence we can share the same lockdep map. Note that the annotation for invalidate_ranage_start is outside of the mm_has_notifiers(), to make sure lockdep is informed about all paths leading to this context irrespective of whether mmu notifiers are present for a given context. We don't do that on the invalidate_range_end side to avoid paying the overhead twice, there the lockdep annotation is pushed down behind the mm_has_notifiers() check. v2: Use lock_map_acquire/release() like fs_reclaim, to avoid confusion with this being a real mutex (Chris Wilson). v3: Rebase on top of Glisse's arg rework. v4: Also annotate invalidate_range_end (Jason Gunthorpe) Also annotate invalidate_range_start_nonblock, I somehow missed that one in the first version. Cc: Jason Gunthorpe Cc: Chris Wilson Cc: Andrew Morton Cc: David Rientjes Cc: "Jérôme Glisse" Cc: Michal Hocko Cc: "Christian König" Cc: Greg Kroah-Hartman Cc: Daniel Vetter Cc: Mike Rapoport Cc: linux-mm@kvack.org Reviewed-by: Jason Gunthorpe Signed-off-by: Daniel Vetter --- include/linux/mmu_notifier.h | 8 ++++++++ mm/mmu_notifier.c | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 31aa971315a1..3f9829a1f32e 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -42,6 +42,10 @@ enum mmu_notifier_event { #ifdef CONFIG_MMU_NOTIFIER +#ifdef CONFIG_LOCKDEP +extern struct lockdep_map __mmu_notifier_invalidate_range_start_map; +#endif + /* * The mmu notifier_mm structure is allocated and installed in * mm->mmu_notifier_mm inside the mm_take_all_locks() protected @@ -341,19 +345,23 @@ static inline void mmu_notifier_change_pte(struct mm_struct *mm, static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { + lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); if (mm_has_notifiers(range->mm)) { range->flags |= MMU_NOTIFIER_RANGE_BLOCKABLE; __mmu_notifier_invalidate_range_start(range); } + lock_map_release(&__mmu_notifier_invalidate_range_start_map); } static inline int mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) { + lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); if (mm_has_notifiers(range->mm)) { range->flags &= ~MMU_NOTIFIER_RANGE_BLOCKABLE; return __mmu_notifier_invalidate_range_start(range); } + lock_map_release(&__mmu_notifier_invalidate_range_start_map); return 0; } diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index d76ea27e2bbb..d48d3b2abd68 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -21,6 +21,13 @@ /* global SRCU for all MMs */ DEFINE_STATIC_SRCU(srcu); +#ifdef CONFIG_LOCKDEP +struct lockdep_map __mmu_notifier_invalidate_range_start_map = { + .name = "mmu_notifier_invalidate_range_start" +}; +EXPORT_SYMBOL_GPL(__mmu_notifier_invalidate_range_start_map); +#endif + /* * This function allows mmu_notifier::release callback to delay a call to * a function that will free appropriate resources. The function must be @@ -197,6 +204,7 @@ void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, struct mmu_notifier *mn; int id; + lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); id = srcu_read_lock(&srcu); hlist_for_each_entry_rcu(mn, &range->mm->mmu_notifier_mm->list, hlist) { /* @@ -220,6 +228,7 @@ void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, mn->ops->invalidate_range_end(mn, range); } srcu_read_unlock(&srcu, id); + lock_map_release(&__mmu_notifier_invalidate_range_start_map); } EXPORT_SYMBOL_GPL(__mmu_notifier_invalidate_range_end); From patchwork Mon Aug 26 20:14:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11115497 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 9B3AD1399 for ; Mon, 26 Aug 2019 20:14:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67C6C21883 for ; Mon, 26 Aug 2019 20:14:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="jWs+/c0l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67C6C21883 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A39BC6B0277; Mon, 26 Aug 2019 16:14:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 94A086B0279; Mon, 26 Aug 2019 16:14:36 -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 813176B027A; Mon, 26 Aug 2019 16:14:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 52B036B0277 for ; Mon, 26 Aug 2019 16:14:36 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id EEFCB824CA3B for ; Mon, 26 Aug 2019 20:14:35 +0000 (UTC) X-FDA: 75865681710.20.smoke09_45357b3d29514 X-Spam-Summary: 2,0,0,0f2878c2c7de5ba5,d41d8cd98f00b204,daniel.vetter@ffwll.ch,:linux-kernel@vger.kernel.org::dri-devel@lists.freedesktop.org:daniel.vetter@ffwll.ch:jgg@ziepe.ca:chris@chris-wilson.co.uk:akpm@linux-foundation.org:rientjes@google.com:jglisse@redhat.com:mhocko@suse.com:christian.koenig@amd.com:gregkh@linuxfoundation.org:rppt@linux.vnet.ibm.com:jgg@mellanox.com:daniel.vetter@intel.com,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1535:1541:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3870:3871:3874:4250:4321:5007:6261:6653:6742:7903:10004:10400:10450:10455:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13069:13311:13357:13846:13894:13972:14096:14097:14181:14394:14659:14721:19904:19999:21080:21444:21451:21627:30054:30064,0,RBL:209.85.208.68:@ffwll.ch:.lbl8.mailshell.net-62.8.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0. 5,0.5,Ne X-HE-Tag: smoke09_45357b3d29514 X-Filterd-Recvd-Size: 5043 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 20:14:35 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id s15so28186504edx.0 for ; Mon, 26 Aug 2019 13:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=43MMkU2nAs7jtnMnw+TAIk5AMkJWGIqIB3w6SHg2dOA=; b=jWs+/c0l0gQqLqnonUguMXmcEgRnSUc9uFPRnBjVNs1Nfg/BKnOJH3T6iKhSC9eb6q dpAfCEkDXZ40OJ02lIV0O9i7OYhqlEmJrKDApByW1yfFG3TBOGtD29nnDadAmOX0w/3a ohtG4NM02aYnLMkZ4fScN1kWA5UKzPn2mVZA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=43MMkU2nAs7jtnMnw+TAIk5AMkJWGIqIB3w6SHg2dOA=; b=i04T0ht5jY2Cj8+T3cYIt+pteC6ldAG8MyvXKR0pZtjDQ80MR3xvPLHM2kTrzxoekK +KHAlbg0h0iKExDU7sfGb/gPwfME/wl1q3GvTY1Q/OECYjIDQ2om/Bp4Bvy6Z4A7/TWM 6uNrplEltBuZ39W7pFte23VjZh/hlxxNMXjZqXI6BdgZkjMFtQMyuBhYpwUDQxUBQWym YivvCNnU8EiVvxfvov1HspCzSHMWClf3wCQmfwWBwGib9/VYbGm+/ch4KBT0KpLqp5ZI i29cz0mQdxfS5rRAtu8wwGKsT4ZHdjrtMZwKfbnNKDTl4Qc9exLKExHX7vjm6oElckpV dOLg== X-Gm-Message-State: APjAAAXTYidP/GBQvX6mcYdVap82JjJgYYRGgw4MwBg7Abw1XboHSRXG JWssDXmaolq675MEe2BekWzfpw== X-Google-Smtp-Source: APXvYqz1alL5dlGwBBuOouoL2tngfggzrmMx20gafiZ6V+aQeNinylzwLOpzJO1HhOF4TDXl6u3nsA== X-Received: by 2002:a50:d0cc:: with SMTP id g12mr19859322edf.201.1566850474445; Mon, 26 Aug 2019 13:14:34 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id j25sm3000780ejb.49.2019.08.26.13.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 13:14:33 -0700 (PDT) From: Daniel Vetter To: LKML Cc: Linux MM , DRI Development , Daniel Vetter , Jason Gunthorpe , Chris Wilson , Andrew Morton , David Rientjes , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Michal Hocko , =?utf-8?q?Christian_K=C3=B6nig?= , Greg Kroah-Hartman , Mike Rapoport , Jason Gunthorpe , Daniel Vetter Subject: [PATCH 2/5] mm, notifier: Prime lockdep Date: Mon, 26 Aug 2019 22:14:22 +0200 Message-Id: <20190826201425.17547-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190826201425.17547-1-daniel.vetter@ffwll.ch> References: <20190826201425.17547-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: We want to teach lockdep that mmu notifiers can be called from direct reclaim paths, since on many CI systems load might never reach that level (e.g. when just running fuzzer or small functional tests). Motivated by a discussion with Jason. I've put the annotation into mmu_notifier_register since only when we have mmu notifiers registered is there any point in teaching lockdep about them. Also, we already have a kmalloc(, GFP_KERNEL), so this is safe. Cc: Jason Gunthorpe Cc: Chris Wilson Cc: Andrew Morton Cc: David Rientjes Cc: "Jérôme Glisse" Cc: Michal Hocko Cc: "Christian König" Cc: Greg Kroah-Hartman Cc: Daniel Vetter Cc: Mike Rapoport Cc: linux-mm@kvack.org Reviewed-by: Jason Gunthorpe Signed-off-by: Daniel Vetter --- mm/mmu_notifier.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index d48d3b2abd68..0523555933c9 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -259,6 +259,13 @@ int __mmu_notifier_register(struct mmu_notifier *mn, struct mm_struct *mm) lockdep_assert_held_write(&mm->mmap_sem); BUG_ON(atomic_read(&mm->mm_users) <= 0); + if (IS_ENABLED(CONFIG_LOCKDEP)) { + fs_reclaim_acquire(GFP_KERNEL); + lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); + lock_map_release(&__mmu_notifier_invalidate_range_start_map); + fs_reclaim_release(GFP_KERNEL); + } + mn->mm = mm; mn->users = 1; From patchwork Mon Aug 26 20:14:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11115501 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 5C79D1399 for ; Mon, 26 Aug 2019 20:14:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DE9F23407 for ; Mon, 26 Aug 2019 20:14:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="VFNW6E8S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DE9F23407 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5793D6B0279; Mon, 26 Aug 2019 16:14:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5293F6B027B; Mon, 26 Aug 2019 16:14:38 -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 37C8E6B027C; Mon, 26 Aug 2019 16:14:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0107.hostedemail.com [216.40.44.107]) by kanga.kvack.org (Postfix) with ESMTP id 161116B0279 for ; Mon, 26 Aug 2019 16:14:38 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id A56B3381E for ; Mon, 26 Aug 2019 20:14:37 +0000 (UTC) X-FDA: 75865681794.29.stew01_456bc70865663 X-Spam-Summary: 2,0,0,66fd3abe3c97c62f,d41d8cd98f00b204,daniel.vetter@ffwll.ch,:linux-kernel@vger.kernel.org::dri-devel@lists.freedesktop.org:daniel.vetter@ffwll.ch:jgg@ziepe.ca:peterz@infradead.org:mingo@redhat.com:akpm@linux-foundation.org:mhocko@suse.com:rientjes@google.com:christian.koenig@amd.com:jglisse@redhat.com:yamada.masahiro@socionext.com:wvw@google.com:andriy.shevchenko@linux.intel.com:tglx@linutronix.de:jannh@google.com:feng.tang@intel.com:keescook@chromium.org:rdunlap@infradead.org:daniel.vetter@intel.com,RULES_HIT:1:2:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1593:1594:1605:1730:1747:1777:1792:2194:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4050:4321:5007:6261:6653:6742:7875:7903:7974:9108:9163:10004:11026:11232:11473:11658:11914:12043:12114:12291:12296:12297:12438:12517:12519:12555:12663:12895:12986:13846:13894:14394:14659:14877:21080:21324:21325:21433:21444 :21451:2 X-HE-Tag: stew01_456bc70865663 X-Filterd-Recvd-Size: 11040 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 20:14:36 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id g8so28158370edm.6 for ; Mon, 26 Aug 2019 13:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hvc+94UsrSo0dvtxcfDnaVeEmPfhp0JVZ15+D+5kcxs=; b=VFNW6E8Sf5IO/vio8FpctFWFmv5uJj0ggZOq4v0zfOgDSSsylE0MV0cDqxpUJ0O3+J jJbfISI7yr3sm+aoIHAjZ4ksh6Ts3a0rodKmpkYQuExF0IXSOGXHenwQjq/PFnh2xjem JCdCkwAuhHfBH1F/2PAMX7b12BePRCojTK8VM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hvc+94UsrSo0dvtxcfDnaVeEmPfhp0JVZ15+D+5kcxs=; b=qjPLFDnZHOCkyMQsjsJ/mWoRxs85tsG2FeUtv4mQK8Em5Uz3wlakgp6ko33LgGLvfk ++eRhMcxrKnfEhUsRFoZz2PTF+05EwISF5XSEqom8kdyHAhjgvM4UhP+LBL1IdcWa0CU 2Lc9uDFHLKgQ2hxYsICR2hs3bBqcoqeO6yxeIeCMV+V1cpnVbbdVQNChPjWOlCoM29G2 QpYa9XsaHcCM8PudQ0pDCwYlE3s8fktXxK9ipTBW0xydnCjQEu4hIi/9BQI9EiuGOMml lMNROLuKZlgdje/sgGeQycx0db2RgKS7UNXrz/hh343ir3kP08qokSQiesAqqSDr5PGT Mzqw== X-Gm-Message-State: APjAAAWl+JIN3OPfUgrxJtHBgecHBi23ffyGljZtprLApy7+dlMSiRkl tFOqpfN+8MGstoeox0KFLs3wvg== X-Google-Smtp-Source: APXvYqwb474jg9zO2UYtdgTPRZkQGqmNA6F5tuCOyD7Luea082jyI2817UPjUHI4jh54moplcdAmZw== X-Received: by 2002:a17:906:3b09:: with SMTP id g9mr18654098ejf.297.1566850475866; Mon, 26 Aug 2019 13:14:35 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id j25sm3000780ejb.49.2019.08.26.13.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 13:14:35 -0700 (PDT) From: Daniel Vetter To: LKML Cc: Linux MM , DRI Development , Daniel Vetter , Jason Gunthorpe , Peter Zijlstra , Ingo Molnar , Andrew Morton , Michal Hocko , David Rientjes , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?b?SsOp?= =?utf-8?b?csO0bWUgR2xpc3Nl?= , Masahiro Yamada , Wei Wang , Andy Shevchenko , Thomas Gleixner , Jann Horn , Feng Tang , Kees Cook , Randy Dunlap , Daniel Vetter Subject: [PATCH 3/5] kernel.h: Add non_block_start/end() Date: Mon, 26 Aug 2019 22:14:23 +0200 Message-Id: <20190826201425.17547-4-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190826201425.17547-1-daniel.vetter@ffwll.ch> References: <20190826201425.17547-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: In some special cases we must not block, but there's not a spinlock, preempt-off, irqs-off or similar critical section already that arms the might_sleep() debug checks. Add a non_block_start/end() pair to annotate these. This will be used in the oom paths of mmu-notifiers, where blocking is not allowed to make sure there's forward progress. Quoting Michal: "The notifier is called from quite a restricted context - oom_reaper - which shouldn't depend on any locks or sleepable conditionals. The code should be swift as well but we mostly do care about it to make a forward progress. Checking for sleepable context is the best thing we could come up with that would describe these demands at least partially." Peter also asked whether we want to catch spinlocks on top, but Michal said those are less of a problem because spinlocks can't have an indirect dependency upon the page allocator and hence close the loop with the oom reaper. Suggested by Michal Hocko. v2: - Improve commit message (Michal) - Also check in schedule, not just might_sleep (Peter) v3: It works better when I actually squash in the fixup I had lying around :-/ v4: Pick the suggestion from Andrew Morton to give non_block_start/end some good kerneldoc comments. I added that other blocking calls like wait_event pose similar issues, since that's the other example we discussed. Cc: Jason Gunthorpe Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Andrew Morton Cc: Michal Hocko Cc: David Rientjes Cc: "Christian König" Cc: Daniel Vetter Cc: "Jérôme Glisse" Cc: linux-mm@kvack.org Cc: Masahiro Yamada Cc: Wei Wang Cc: Andy Shevchenko Cc: Thomas Gleixner Cc: Jann Horn Cc: Feng Tang Cc: Kees Cook Cc: Randy Dunlap Cc: linux-kernel@vger.kernel.org Acked-by: Christian König (v1) Acked-by: Peter Zijlstra (Intel) Signed-off-by: Daniel Vetter Acked-by: Michal Hocko --- include/linux/kernel.h | 25 ++++++++++++++++++++++++- include/linux/sched.h | 4 ++++ kernel/sched/core.c | 19 ++++++++++++++----- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 4fa360a13c1e..82f84cfe372f 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -217,7 +217,9 @@ extern void __cant_sleep(const char *file, int line, int preempt_offset); * might_sleep - annotation for functions that can sleep * * this macro will print a stack trace if it is executed in an atomic - * context (spinlock, irq-handler, ...). + * context (spinlock, irq-handler, ...). Additional sections where blocking is + * not allowed can be annotated with non_block_start() and non_block_end() + * pairs. * * This is a useful debugging help to be able to catch problems early and not * be bitten later when the calling function happens to sleep when it is not @@ -233,6 +235,25 @@ extern void __cant_sleep(const char *file, int line, int preempt_offset); # define cant_sleep() \ do { __cant_sleep(__FILE__, __LINE__, 0); } while (0) # define sched_annotate_sleep() (current->task_state_change = 0) +/** + * non_block_start - annotate the start of section where sleeping is prohibited + * + * This is on behalf of the oom reaper, specifically when it is calling the mmu + * notifiers. The problem is that if the notifier were to block on, for example, + * mutex_lock() and if the process which holds that mutex were to perform a + * sleeping memory allocation, the oom reaper is now blocked on completion of + * that memory allocation. Other blocking calls like wait_event() pose similar + * issues. + */ +# define non_block_start() \ + do { current->non_block_count++; } while (0) +/** + * non_block_end - annotate the end of section where sleeping is prohibited + * + * Closes a section opened by non_block_start(). + */ +# define non_block_end() \ + do { WARN_ON(current->non_block_count-- == 0); } while (0) #else static inline void ___might_sleep(const char *file, int line, int preempt_offset) { } @@ -241,6 +262,8 @@ extern void __cant_sleep(const char *file, int line, int preempt_offset); # define might_sleep() do { might_resched(); } while (0) # define cant_sleep() do { } while (0) # define sched_annotate_sleep() do { } while (0) +# define non_block_start() do { } while (0) +# define non_block_end() do { } while (0) #endif #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) diff --git a/include/linux/sched.h b/include/linux/sched.h index b6ec130dff9b..e8bb965f5019 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -980,6 +980,10 @@ struct task_struct { struct mutex_waiter *blocked_on; #endif +#ifdef CONFIG_DEBUG_ATOMIC_SLEEP + int non_block_count; +#endif + #ifdef CONFIG_TRACE_IRQFLAGS unsigned int irq_events; unsigned long hardirq_enable_ip; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 45dceec209f4..0d01c7994a9a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3752,13 +3752,22 @@ static noinline void __schedule_bug(struct task_struct *prev) /* * Various schedule()-time debugging checks and statistics: */ -static inline void schedule_debug(struct task_struct *prev) +static inline void schedule_debug(struct task_struct *prev, bool preempt) { #ifdef CONFIG_SCHED_STACK_END_CHECK if (task_stack_end_corrupted(prev)) panic("corrupted stack end detected inside scheduler\n"); #endif +#ifdef CONFIG_DEBUG_ATOMIC_SLEEP + if (!preempt && prev->state && prev->non_block_count) { + printk(KERN_ERR "BUG: scheduling in a non-blocking section: %s/%d/%i\n", + prev->comm, prev->pid, prev->non_block_count); + dump_stack(); + add_taint(TAINT_WARN, LOCKDEP_STILL_OK); + } +#endif + if (unlikely(in_atomic_preempt_off())) { __schedule_bug(prev); preempt_count_set(PREEMPT_DISABLED); @@ -3870,7 +3879,7 @@ static void __sched notrace __schedule(bool preempt) rq = cpu_rq(cpu); prev = rq->curr; - schedule_debug(prev); + schedule_debug(prev, preempt); if (sched_feat(HRTICK)) hrtick_clear(rq); @@ -6641,7 +6650,7 @@ void ___might_sleep(const char *file, int line, int preempt_offset) rcu_sleep_check(); if ((preempt_count_equals(preempt_offset) && !irqs_disabled() && - !is_idle_task(current)) || + !is_idle_task(current) && !current->non_block_count) || system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING || oops_in_progress) return; @@ -6657,8 +6666,8 @@ void ___might_sleep(const char *file, int line, int preempt_offset) "BUG: sleeping function called from invalid context at %s:%d\n", file, line); printk(KERN_ERR - "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", - in_atomic(), irqs_disabled(), + "in_atomic(): %d, irqs_disabled(): %d, non_block: %d, pid: %d, name: %s\n", + in_atomic(), irqs_disabled(), current->non_block_count, current->pid, current->comm); if (task_stack_end_corrupted(current)) From patchwork Mon Aug 26 20:14:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11115503 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 D11B316B1 for ; Mon, 26 Aug 2019 20:14:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D91621872 for ; Mon, 26 Aug 2019 20:14:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="eqf/zxHz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D91621872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6649C6B027B; Mon, 26 Aug 2019 16:14:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5EE776B027D; Mon, 26 Aug 2019 16:14:39 -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 4DC7F6B027E; Mon, 26 Aug 2019 16:14:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 299106B027B for ; Mon, 26 Aug 2019 16:14:39 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id D20E2611C for ; Mon, 26 Aug 2019 20:14:38 +0000 (UTC) X-FDA: 75865681836.06.cat17_45996edb21e4a X-Spam-Summary: 2,0,0,f99397da50dcfb3f,d41d8cd98f00b204,daniel.vetter@ffwll.ch,:linux-kernel@vger.kernel.org::dri-devel@lists.freedesktop.org:daniel.vetter@ffwll.ch:jgg@ziepe.ca:akpm@linux-foundation.org:mhocko@suse.com:rientjes@google.com:christian.koenig@amd.com:jglisse@redhat.com:daniel.vetter@intel.com,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2911:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4321:4425:5007:6261:6653:7903:9010:9108:10004:10400:11026:11658:11914:12043:12297:12438:12517:12519:12555:12663:12895:12986:13846:13894:14181:14394:14659:14721:21080:21433:21444:21451:21627:21740:30012:30054:30064:30080,0,RBL:209.85.208.68:@ffwll.ch:.lbl8.mailshell.net-62.8.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:4,LUA_ SUMMARY: X-HE-Tag: cat17_45996edb21e4a X-Filterd-Recvd-Size: 5853 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 20:14:38 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id w5so28140283edl.8 for ; Mon, 26 Aug 2019 13:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bew81wZtU1Y0ks/RIjoWK2FqRSw2UObINLTLlREzuuI=; b=eqf/zxHzmkxFzdusChJdtOxtD1T//2StyL+3IeJkwUOueNAgekF2+ClgnH/jmo0xK7 qr4GW3Irit/IupsG1Na0ULH20pR7piGumm9IQOHaYtrHyUARGCU3fZukTvNoWL+1YqKl pT4WlAHyRMSIzeLbFjs0YtZDoFJZPwP/EgQ5o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bew81wZtU1Y0ks/RIjoWK2FqRSw2UObINLTLlREzuuI=; b=m1dYERv//asrzoczU0yKw5IIXhW4JsE4xyD8MZjlo6Xwa5bNh3pGTk804lUwUN12Lq cpuU2JAzaychshdPQxEkrx2AnFY6Qn+m5Nmuwig/hSGbbvWk0FoMnSirjZiswuHdvtrg 2Gk5jOYIIV5uvaXrlVF2b92aYa/7jsKfEOHK/AOjzA8oqD+MHWetFAltVWYCIy6BI4F+ cKRYwa7/D0l9vbhGVey9XY0rDdSQmmXD5aeN+uJB1DdX5ZH61g3zOvxRjAo1/KNdup3r xupuxamSi2/Dwbr/fk5EP+FiFoBI7BEOrVoEHZAXT4axZrv7sCJbc5o9OE9sUn+39SN2 vf/w== X-Gm-Message-State: APjAAAWd1WuDYmgTQM6hBcl2qwCsol1ITZWYeQyjFa7lPn1Gz+XosQc5 spxcy/SdPJCNcFlUHSGH+6vSww== X-Google-Smtp-Source: APXvYqw8z9afSvhgONVa7l2XkwoZjbx6t7Y2tVjSzj6EiE5l88NiQj8YRIrJNGWJ+8ua4BQqqD4zVA== X-Received: by 2002:a17:907:207a:: with SMTP id qp26mr18160870ejb.12.1566850477119; Mon, 26 Aug 2019 13:14:37 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id j25sm3000780ejb.49.2019.08.26.13.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 13:14:36 -0700 (PDT) From: Daniel Vetter To: LKML Cc: Linux MM , DRI Development , Daniel Vetter , Jason Gunthorpe , Andrew Morton , Michal Hocko , David Rientjes , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?b?SsOp?= =?utf-8?b?csO0bWUgR2xpc3Nl?= , Daniel Vetter Subject: [PATCH 4/5] mm, notifier: Catch sleeping/blocking for !blockable Date: Mon, 26 Aug 2019 22:14:24 +0200 Message-Id: <20190826201425.17547-5-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190826201425.17547-1-daniel.vetter@ffwll.ch> References: <20190826201425.17547-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: We need to make sure implementations don't cheat and don't have a possible schedule/blocking point deeply burried where review can't catch it. I'm not sure whether this is the best way to make sure all the might_sleep() callsites trigger, and it's a bit ugly in the code flow. But it gets the job done. Inspired by an i915 patch series which did exactly that, because the rules haven't been entirely clear to us. v2: Use the shiny new non_block_start/end annotations instead of abusing preempt_disable/enable. v3: Rebase on top of Glisse's arg rework. v4: Rebase on top of more Glisse rework. v5: Also annotate invalidate_range_end in the same style. I hope I got Jason's request for this right. Cc: Jason Gunthorpe Cc: Andrew Morton Cc: Michal Hocko Cc: David Rientjes Cc: "Christian König" Cc: Daniel Vetter Cc: "Jérôme Glisse" Cc: linux-mm@kvack.org Reviewed-by: Christian König (v1) Reviewed-by: Jérôme Glisse (v4) Signed-off-by: Daniel Vetter --- mm/mmu_notifier.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 0523555933c9..b17f3fd3779b 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -181,7 +181,13 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) id = srcu_read_lock(&srcu); hlist_for_each_entry_rcu(mn, &range->mm->mmu_notifier_mm->list, hlist) { if (mn->ops->invalidate_range_start) { - int _ret = mn->ops->invalidate_range_start(mn, range); + int _ret; + + if (!mmu_notifier_range_blockable(range)) + non_block_start(); + _ret = mn->ops->invalidate_range_start(mn, range); + if (!mmu_notifier_range_blockable(range)) + non_block_end(); if (_ret) { pr_info("%pS callback failed with %d in %sblockable context.\n", mn->ops->invalidate_range_start, _ret, @@ -224,8 +230,13 @@ void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, mn->ops->invalidate_range(mn, range->mm, range->start, range->end); - if (mn->ops->invalidate_range_end) + if (mn->ops->invalidate_range_end) { + if (!mmu_notifier_range_blockable(range)) + non_block_start(); mn->ops->invalidate_range_end(mn, range); + if (!mmu_notifier_range_blockable(range)) + non_block_end(); + } } srcu_read_unlock(&srcu, id); lock_map_release(&__mmu_notifier_invalidate_range_start_map); From patchwork Mon Aug 26 20:14:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11115507 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 3A4781399 for ; Mon, 26 Aug 2019 20:14:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06DF221872 for ; Mon, 26 Aug 2019 20:14:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="QViZPMOC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06DF221872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AAA146B027D; Mon, 26 Aug 2019 16:14:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9974B6B027F; Mon, 26 Aug 2019 16:14:40 -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 885AC6B0280; Mon, 26 Aug 2019 16:14:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 62F4D6B027D for ; Mon, 26 Aug 2019 16:14:40 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 06DB9824CA3B for ; Mon, 26 Aug 2019 20:14:40 +0000 (UTC) X-FDA: 75865681920.07.hen34_45c9d513cf939 X-Spam-Summary: 2,0,0,b598ffb36879ef4d,d41d8cd98f00b204,daniel.vetter@ffwll.ch,:linux-kernel@vger.kernel.org::dri-devel@lists.freedesktop.org:daniel.vetter@ffwll.ch:jgg@ziepe.ca:akpm@linux-foundation.org:mhocko@suse.com:rientjes@google.com:christian.koenig@amd.com:jglisse@redhat.com:daniel.vetter@intel.com,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3870:3874:4321:5007:6261:6653:7903:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13069:13161:13229:13311:13357:13846:13894:14096:14097:14181:14394:14659:14721:21080:21433:21444:21451:21627:30054:30064,0,RBL:209.85.208.67:@ffwll.ch:.lbl8.mailshell.net-62.8.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:32,LUA_SUMMARY:none X-HE-Tag: hen34_45c9d513cf939 X-Filterd-Recvd-Size: 4857 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 20:14:39 +0000 (UTC) Received: by mail-ed1-f67.google.com with SMTP id t50so28194644edd.2 for ; Mon, 26 Aug 2019 13:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bUhdeRpbg8gRloy4w33VnXTSeooO5sqpvDT0wx5DMzY=; b=QViZPMOCt4TCBDSlKAVCdrC+U37mohUaGpt7t54fKUAJnII/M30PJe3HVgsMvO32I/ JHmsQisAEo+uwv1GVmUHudMfC1x01ExLcWbO28gdRMZiZ/4jYiOIUrGZ6L9+5vRcVnku F9YxwgBgX7xnEA70Wp+hl/fz9/FJFtPM7Z4dQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bUhdeRpbg8gRloy4w33VnXTSeooO5sqpvDT0wx5DMzY=; b=FNOrI5rxnmPsSQQqYg0mBdy+O3wAwYTGLsr2QjnUwCAK5ZQcZruSbWTbBuf2yQX3gh hXwGGEGZ8GkucKC1uyhcznp2CwWIYO+wd7FGd/QEJVJBW3poyi8SQa1hprdrMJ8qgWor REpr+b/p0gVMtIe69ZduDZW9tyOqHUGJPb9KoVyr4uN0O/omOL/faAVp3/E8FvXK12b0 VuwesZvGQMRkCu+AFMZ/ouBMVZp8Sy7JFSeFIpUd+a92TITMOFN7SHK+YL3vJpbrPpZk 5N+o1R9zuvlDoyQx7CSdou9b/vlcMtmvJ5xF4wJTCE3gBDc+iUpzhTi5snolskwUth2H K+TQ== X-Gm-Message-State: APjAAAXILrIkGwGTq6n7YSIvzzUCcE1gLkSu0yZ5Ih0FJ3nt5aEizp2x qpY2j8Ec1+iXu+znEoY4D07EPA== X-Google-Smtp-Source: APXvYqwQX5rJn4xiT0PzmoOjk8RceDZHB/u+ViHnJA99I4EPasO1Ql6cGV43P/XDRPUyqHKPLLvlzQ== X-Received: by 2002:aa7:c552:: with SMTP id s18mr21104247edr.0.1566850478492; Mon, 26 Aug 2019 13:14:38 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id j25sm3000780ejb.49.2019.08.26.13.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 13:14:37 -0700 (PDT) From: Daniel Vetter To: LKML Cc: Linux MM , DRI Development , Daniel Vetter , Jason Gunthorpe , Andrew Morton , Michal Hocko , David Rientjes , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?b?SsOp?= =?utf-8?b?csO0bWUgR2xpc3Nl?= , Daniel Vetter Subject: [PATCH 5/5] mm, notifier: annotate with might_sleep() Date: Mon, 26 Aug 2019 22:14:25 +0200 Message-Id: <20190826201425.17547-6-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190826201425.17547-1-daniel.vetter@ffwll.ch> References: <20190826201425.17547-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: Since mmu notifiers don't exist for more processes, but could block in interesting places, add some annotations. This should help make sure core mm keeps up its end of the mmu notifier contract. The checks here are outside of all notifier checks because of that. They compile away without CONFIG_DEBUG_ATOMIC_SLEEP. Suggested by Jason. Cc: Jason Gunthorpe Cc: Andrew Morton Cc: Michal Hocko Cc: David Rientjes Cc: "Christian König" Cc: Daniel Vetter Cc: "Jérôme Glisse" Cc: linux-mm@kvack.org Signed-off-by: Daniel Vetter --- include/linux/mmu_notifier.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 3f9829a1f32e..8b71813417e7 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -345,6 +345,8 @@ static inline void mmu_notifier_change_pte(struct mm_struct *mm, static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { + might_sleep(); + lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); if (mm_has_notifiers(range->mm)) { range->flags |= MMU_NOTIFIER_RANGE_BLOCKABLE; @@ -368,6 +370,9 @@ mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) static inline void mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) { + if (mmu_notifier_range_blockable(range)) + might_sleep(); + if (mm_has_notifiers(range->mm)) __mmu_notifier_invalidate_range_end(range, false); }