From patchwork Thu Nov 22 16:51:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10694505 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 346BE5A4 for ; Thu, 22 Nov 2018 16:51:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20A652C90A for ; Thu, 22 Nov 2018 16:51:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EC192C99C; Thu, 22 Nov 2018 16:51:22 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE3532CD67 for ; Thu, 22 Nov 2018 16:51:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A5DE6E4E9; Thu, 22 Nov 2018 16:51:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 975606E537 for ; Thu, 22 Nov 2018 16:51:15 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id z28so8208743edi.8 for ; Thu, 22 Nov 2018 08:51:15 -0800 (PST) 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=35SA+A3zSGOUwg2DuEDiDQyYR9o/qAXgi6nZL2aj8/Q=; b=Qc4Qtxm15EuzaVeaXk4+d6Vpy3X1AYY0fqgmmRphFD+xF4yws83EVqPKQ+8Jpz2VQQ X8FLhadK2lUQd73XQV+UWZuCixcw9OGpKHO31bYtcwGCQpvo7rszwLIpFP/tqrwiEzW2 64uPKzz2IBrL46rtkWKUgGXD8roG4dYHujL33knhbqX5X+fxiTyiIXVzmzWhZnm6wN8t IWmztej86HHpcsiQDOmG2enGQ83Az4uKEysmqvvt5nej6mewC7dLi+3U3VM0F4SBTkng fBPxuNOMr3yTlbSdOJpDR1XnW6/dhEHReGyKBT4XhwqIUQVa63vNuBfB2DLKUIg93lx9 DUDw== X-Gm-Message-State: AA+aEWb4dUg37JeK8KtPOFsgtuJiXbepYANMLK9R2UjvrZO1yup+7HHY zzS6wBmwxi+QrkjqLIBYYSvDdHvhSP0= X-Google-Smtp-Source: AFSGD/UaEjvJQp9C/3K0fUJG/8rVELf5/0i7gzNYdUB5+WGaWrnZRqdyJkJ9AKcGEmio8EYKSuwHCg== X-Received: by 2002:a50:bdc8:: with SMTP id z8mr3626337edh.46.1542905474153; Thu, 22 Nov 2018 08:51:14 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id s12sm12914780edb.43.2018.11.22.08.51.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 08:51:13 -0800 (PST) From: Daniel Vetter To: LKML Subject: [PATCH 1/3] mm: Check if mmu notifier callbacks are allowed to fail Date: Thu, 22 Nov 2018 17:51:04 +0100 Message-Id: <20181122165106.18238-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122165106.18238-1-daniel.vetter@ffwll.ch> References: <20181122165106.18238-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Daniel Vetter , Daniel Vetter , Intel Graphics Development , DRI Development , Linux MM , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , David Rientjes , Paolo Bonzini , Andrew Morton , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Just a bit of paranoia, since if we start pushing this deep into callchains it's hard to spot all places where an mmu notifier implementation might fail when it's not allowed to. Cc: Andrew Morton Cc: Michal Hocko Cc: "Christian König" Cc: David Rientjes Cc: Daniel Vetter Cc: "Jérôme Glisse" Cc: linux-mm@kvack.org Cc: Paolo Bonzini Signed-off-by: Daniel Vetter Acked-by: Christian König --- mm/mmu_notifier.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 5119ff846769..59e102589a25 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -190,6 +190,8 @@ int __mmu_notifier_invalidate_range_start(struct mm_struct *mm, pr_info("%pS callback failed with %d in %sblockable context.\n", mn->ops->invalidate_range_start, _ret, !blockable ? "non-" : ""); + WARN(blockable,"%pS callback failure not allowed\n", + mn->ops->invalidate_range_start); ret = _ret; } } From patchwork Thu Nov 22 16:51:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10694515 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 5C0BB15A7 for ; Thu, 22 Nov 2018 16:51:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A20F2C713 for ; Thu, 22 Nov 2018 16:51:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4841D2CC44; Thu, 22 Nov 2018 16:51:30 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E45F52CBF5 for ; Thu, 22 Nov 2018 16:51:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D94076E002; Thu, 22 Nov 2018 16:51:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0078C6E4ED for ; Thu, 22 Nov 2018 16:51:16 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id h50so8229697ede.5 for ; Thu, 22 Nov 2018 08:51:16 -0800 (PST) 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=IgwJtKz/bAk5V2diWi6f2OFLQxM1W0dMUc8sKowBqdg=; b=Fv8dTiP9WPohD1F9WY9D0FHaUg9eDlWUzAXvbxn830Uu4KGb4ohPW89eelcScOHI9h b5zfKvCjKhIILDhZsbeePbxqpzT4i+JeT4ZotgV4p+rHgPbjsCv3+PCkyR2Z4DaDd+lp t5AnVpWwBM7BnKQVbY7xqwRc0MB1b/42jC+xCdhPksfUODSgQu0j8bnewq8AVanHcrJm 5ohgTZhxviM+L3yZmOojUXfSJRAHIUeb7UonRq5tHeTQ/ePLUhqpIEKrcLnqwlo5o8+q kvIpjlXpD+mjUgIBImsVQhkG/kLYHVq7Kcx8burTv3E8ARr3RbZv9CScj6PymN/wfKb3 cmKw== X-Gm-Message-State: AA+aEWZhPOsDEexhsi3xs2FRuabx6uXw4SZzbKz5zi4CVDet/d8XjwBb F0n+GpNu8u9ivO/IJsqnzlfx5g== X-Google-Smtp-Source: AJdET5f7D95UNLjpN3z6CjQVNTRkjvktjeA+ZinA1S4SxGyQ/8odF3x2QRcRsfY9v4Pi6Pu0SMQitA== X-Received: by 2002:a17:906:3b11:: with SMTP id g17-v6mr8689028ejf.210.1542905475467; Thu, 22 Nov 2018 08:51:15 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id s12sm12914780edb.43.2018.11.22.08.51.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 08:51:14 -0800 (PST) From: Daniel Vetter To: LKML Subject: [PATCH 2/3] mm, notifier: Catch sleeping/blocking for !blockable Date: Thu, 22 Nov 2018 17:51:05 +0100 Message-Id: <20181122165106.18238-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122165106.18238-1-daniel.vetter@ffwll.ch> References: <20181122165106.18238-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Daniel Vetter , Intel Graphics Development , DRI Development , Linux MM , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , David Rientjes , Daniel Vetter , Andrew Morton , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 --- mm/mmu_notifier.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 59e102589a25..4d282cfb296e 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -185,7 +185,13 @@ int __mmu_notifier_invalidate_range_start(struct mm_struct *mm, id = srcu_read_lock(&srcu); hlist_for_each_entry_rcu(mn, &mm->mmu_notifier_mm->list, hlist) { if (mn->ops->invalidate_range_start) { - int _ret = mn->ops->invalidate_range_start(mn, mm, start, end, blockable); + int _ret; + + if (IS_ENABLED(CONFIG_DEBUG_ATOMIC_SLEEP) && !blockable) + preempt_disable(); + _ret = mn->ops->invalidate_range_start(mn, mm, start, end, blockable); + if (IS_ENABLED(CONFIG_DEBUG_ATOMIC_SLEEP) && !blockable) + preempt_enable(); if (_ret) { pr_info("%pS callback failed with %d in %sblockable context.\n", mn->ops->invalidate_range_start, _ret, From patchwork Thu Nov 22 16:51:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10694509 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 145C215A7 for ; Thu, 22 Nov 2018 16:51:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02CEF2CD38 for ; Thu, 22 Nov 2018 16:51:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8ED52CCED; Thu, 22 Nov 2018 16:51:24 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 530152CD3E for ; Thu, 22 Nov 2018 16:51:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3763B89428; Thu, 22 Nov 2018 16:51:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 53B566E4ED for ; Thu, 22 Nov 2018 16:51:18 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id y56so8196990edd.11 for ; Thu, 22 Nov 2018 08:51:18 -0800 (PST) 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=IqCNVNv0Y8aoRKucGwKEjdCDvF336AuZYaELjzjP6Ls=; b=aVgFZ3wGGA19h+QfwT72oDhoIyEO1ytDet8ejproUm6q11hvprp1dOuGnaJa11lnO/ OFcmKN9l4gyIv2NMgN8voRYNqV7ErjQNyI32PI2Ts99NtHGI06f018Ev8QFev6PjkHnJ hg0qnPNDzKvsiuyq7m5NJDmJw/7iCmifpLN4FpTIC6A/+aAT4jaCJgKv5Ptx9oAC8Fft HGsdk/QNPel2AFV7Cy0vX5UwVAjizAh0jJAPN5gBNAYBln9kfaXnQTkMpGKQeOmng9WR pBezkX2fQkc31mB92uJTp7J1Om+W7Pnrye5icMkj//oOY76591mKU3P9eXIrpmaCfcYO HwoA== X-Gm-Message-State: AA+aEWbGjQrRVhtVlLPCJ3HKEhDPqsyC5NoxFkSjrnBMSIzkj/LbR0TV sfw6ZNmS/M7BcrsTk17adCqx+w== X-Google-Smtp-Source: AFSGD/X3yt1n8EIDxKFM/dx7WPreYbLdq5CVYlgu9XO9dTU/ze5Lq/MSqa8fCcbBo2dSkl61aed9Sg== X-Received: by 2002:a50:fd0e:: with SMTP id i14mr9994539eds.98.1542905476815; Thu, 22 Nov 2018 08:51:16 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id s12sm12914780edb.43.2018.11.22.08.51.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 08:51:16 -0800 (PST) From: Daniel Vetter To: LKML Subject: [PATCH 3/3] mm, notifier: Add a lockdep map for invalidate_range_start Date: Thu, 22 Nov 2018 17:51:06 +0100 Message-Id: <20181122165106.18238-4-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122165106.18238-1-daniel.vetter@ffwll.ch> References: <20181122165106.18238-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Greg Kroah-Hartman , Daniel Vetter , Intel Graphics Development , DRI Development , Linux MM , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Mike Rapoport , David Rientjes , Daniel Vetter , Andrew Morton , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Aside: Since I typed this to test i915 mmu notifiers I've only rolled this out for the invaliate_range_start callback. If there's interest, we should probably roll this out to all of them. But my undestanding of core mm is seriously lacking, and I'm not clear on whether we need a lockdep map for each callback, or whether some can be shared. 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 Signed-off-by: Daniel Vetter --- include/linux/mmu_notifier.h | 7 +++++++ mm/mmu_notifier.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 9893a6432adf..a39ba218dbbe 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -12,6 +12,10 @@ struct mmu_notifier_ops; #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 @@ -267,8 +271,11 @@ static inline void mmu_notifier_change_pte(struct mm_struct *mm, static inline void mmu_notifier_invalidate_range_start(struct mm_struct *mm, unsigned long start, unsigned long end) { + mutex_acquire(&__mmu_notifier_invalidate_range_start_map, 0, 0, + _RET_IP_); if (mm_has_notifiers(mm)) __mmu_notifier_invalidate_range_start(mm, start, end, true); + mutex_release(&__mmu_notifier_invalidate_range_start_map, 1, _RET_IP_); } static inline int mmu_notifier_invalidate_range_start_nonblock(struct mm_struct *mm, diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 4d282cfb296e..c6e797927376 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -23,6 +23,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