From patchwork Mon May 20 21:39:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10952373 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 05F7F1395 for ; Mon, 20 May 2019 21:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E936D27F93 for ; Mon, 20 May 2019 21:39:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCC7B28759; Mon, 20 May 2019 21:39:55 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 345D527F93 for ; Mon, 20 May 2019 21:39:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43A8D6B000C; Mon, 20 May 2019 17:39:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3ECAE6B000D; Mon, 20 May 2019 17:39:54 -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 2B4A66B000E; Mon, 20 May 2019 17:39:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id D502A6B000C for ; Mon, 20 May 2019 17:39:53 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id p14so27307664edc.4 for ; Mon, 20 May 2019 14:39:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=DucpRdkRgOoCBrOy6KiJUJJfWEr/7+ZCIIaJ4AvhfB0=; b=qQMSbpPIVHRZc12ws2w8r9iwPsH4DSRxyZYUJZMysomKr/U0pdl4e3mgkB5PwDBjDI IBhGnSTt8cHYtKO9LUiO+Lc5quy3RYfTSC/GH0FFBElrngDGPwF9OjqEo6XgbLdbmrs2 nI0ywifhDlfFxJMWzDWRqxb0nJVCtaF7eUzhS8Q/K2UJ+EQ4kahb71vvMsWRsGV/cQIa N3J/fpcjWaeUqWOLAkOb/WbwXQxLpS4p34F25pPGtckstTVzb5f6wFnvHhmCTuIhD0s6 4QalpwB7mhh8UQrFyXYUICOllrQrjmtaNu0dfPUUnJ1DpnyUYGYxrZaVrCnLN8dok5qa 7QeQ== X-Gm-Message-State: APjAAAWJKyh+qhbshE25olOSzdv3x6n7uYBeM9whpHqaOeMEeoFnTYX2 +N2aacKWGRGWbgc0KyYdWKTFu+/heKYJRowGa3S9oR9Wx7v1bFRNPMtiHaMghtGGfDjJGFVkzvf FDf+u6KHdn1A/9XYatnH7ooKGE5cln5VFpKuQVRwGG0ZRN1hbUaSISvWMClgJaSBwbA== X-Received: by 2002:a50:896a:: with SMTP id f39mr77625606edf.293.1558388393325; Mon, 20 May 2019 14:39:53 -0700 (PDT) X-Received: by 2002:a50:896a:: with SMTP id f39mr77625562edf.293.1558388392539; Mon, 20 May 2019 14:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558388392; cv=none; d=google.com; s=arc-20160816; b=yZnf3aLsrIf6VwaYcB0Dh8YvAgzK8fmguxfKvK82MK2IvWF9oxgNAKUmXX/SDJK0xO UxDcEfSYJhcm1XQFXRBGPS8gVWTKMSYyFdWJriqeLeqRySq8m3n7K5AqyAVIpOaJB/h4 3svfw6sbRmsM4rUHNw+y45Yjbmg7ugNAWEg0Y23OLs6tN+Z3lqgSMybfPglt/Tuyi8HP +rmaQT3gXYMmIT8B2CZvkaAGWgvA3FZLOEVysfJaOVulK8lO+FGAYttkjPzU3th4F4/a 0BycCD7q7uA2MBO1WJtHx1A43NAjKSgG2KINh8KvF0QsoIrBa53XYaDH5IUbz/qDNIrV uAAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=DucpRdkRgOoCBrOy6KiJUJJfWEr/7+ZCIIaJ4AvhfB0=; b=vIXLVJ26i3L6KoCsKSgeG0RV4ZL8pgzIxQn28rXct0DplXxI8yLcfm5ESZqyIYnBF3 Cs5RkpBOjLLYQkKn+UXIrsnsqNbIsfmi7skwj3/OCGzu3MM3Vwzo/WC+QzgemLQ8MZEM icrfsVxFSwnkxxm1ANFrmDMkjU1MzXysbhi9bEQZyo5BQUqWNtk8dAzK9wGA8wnjY6bH rcA0WvY8s8IetZ7k8ORGppqpb3Az2lnGBJcLHIyWuPxS+K0VrQiJZ4CUf9dOE1LhdjE3 XKpE3qYQgY1onb2fJIrDGFdayvpx06YRQS0UtRmlwM+IsbwvwHe5NhmvD/zxPKfzeMEa moEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=HKq8Duys; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b51sor2213149ede.8.2019.05.20.14.39.52 for (Google Transport Security); Mon, 20 May 2019 14:39:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=HKq8Duys; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DucpRdkRgOoCBrOy6KiJUJJfWEr/7+ZCIIaJ4AvhfB0=; b=HKq8DuysKW6hx7l8Yig0NV9UpMzIOK98ALTyHYlWExOE6Pc4XsceN9CwZTMEZ+y6cw Cotb3dp0LmPi/TnfsGu9Mc8wGpsj9yCkmJXIekv1AWGWZdRazvo+2R7pulay1RKnKq5x V5EN38iDPb1UvcB2ERZ4RtefPoEDwb5qTXLcw= X-Google-Smtp-Source: APXvYqzzZ2kpVp8haHdbToY3y03B93IZ2fARLhOO1vyR6C1AaG3mgxQcALaUAvLZsqLVYAWfP3KDjg== X-Received: by 2002:a50:b865:: with SMTP id k34mr79563563ede.16.1558388391895; Mon, 20 May 2019 14:39:51 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id v27sm3285772eja.68.2019.05.20.14.39.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 14:39:51 -0700 (PDT) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , LKML , Linux MM , Daniel Vetter , Andrew Morton , Michal Hocko , =?utf-8?q?Christian_K=C3=B6nig?= , David Rientjes , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Paolo Bonzini , Daniel Vetter Subject: [PATCH 1/4] mm: Check if mmu notifier callbacks are allowed to fail Date: Mon, 20 May 2019 23:39:42 +0200 Message-Id: <20190520213945.17046-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 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: 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. Inspired by some confusion we had discussing i915 mmu notifiers and whether we could use the newly-introduced return value to handle some corner cases. Until we realized that these are only for when a task has been killed by the oom reaper. An alternative approach would be to split the callback into two versions, one with the int return value, and the other with void return value like in older kernels. But that's a lot more churn for fairly little gain I think. Summary from the m-l discussion on why we want something at warning level: This allows automated tooling in CI to catch bugs without humans having to look at everything. If we just upgrade the existing pr_info to a pr_warn, then we'll have false positives. And as-is, no one will ever spot the problem since it's lost in the massive amounts of overall dmesg noise. v2: Drop the full WARN_ON backtrace in favour of just a pr_warn for the problematic case (Michal Hocko). v3: Rebase on top of Glisse's arg rework. v4: More rebase on top of Glisse reworking everything. 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 Reviewed-by: Christian König Signed-off-by: Daniel Vetter Reviewed-by: Jérôme Glisse --- mm/mmu_notifier.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index ee36068077b6..c05e406a7cd7 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -181,6 +181,9 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) pr_info("%pS callback failed with %d in %sblockable context.\n", mn->ops->invalidate_range_start, _ret, !mmu_notifier_range_blockable(range) ? "non-" : ""); + if (!mmu_notifier_range_blockable(range)) + pr_warn("%pS callback failure not allowed\n", + mn->ops->invalidate_range_start); ret = _ret; } } From patchwork Mon May 20 21:39:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10952377 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 1AE6D14C0 for ; Mon, 20 May 2019 21:39:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 096BF27F93 for ; Mon, 20 May 2019 21:39:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1A3D28767; Mon, 20 May 2019 21:39:58 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 0CE5C27F93 for ; Mon, 20 May 2019 21:39:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA80F6B000D; Mon, 20 May 2019 17:39:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A55596B000E; Mon, 20 May 2019 17:39:56 -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 91D206B0010; Mon, 20 May 2019 17:39:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 3F60A6B000D for ; Mon, 20 May 2019 17:39:56 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id c1so27216369edi.20 for ; Mon, 20 May 2019 14:39:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=EmM3y8RoE66pNVDPE35FtUxyGgXbfiMJbpXVG8+7zqI=; b=NSiEW/89Wq0u+IRQCWIwtlNzXO2zKN/bZSbbcSmK5PYy4fF3L5hyyncHuYh7kNLi2f +CI3SI/I24irGbxGZOWCFd+uD8zMms5ZiEu9ol5pfrFamRpU8InLbDQaE/So4mLV8q8t qJ1adYbRWu2Znb3IAiWsEHE+okPUhxgFz1JM4l0OcIFl+0JLQuxdQhl+mQ+GPZx+/3AE G8cm41vRiK+QdCWkXYvobILH4mLUQS8+NQPY9b4JAAeWZQpedaXFdUAHzo5Hg3OP7D9x PsNH2Bwnq+r5+oRnDEE+io9b+cDjtWxT6zE//YANr8oKirsRvso0JjcXmxNMFJ5H2uVJ lYzA== X-Gm-Message-State: APjAAAUAxyKRY1QV5hspOlWSSuAXFxsPt7BSiyAgG5lvhXBAhS/HkTwl wA9KsBpeXZKKEqZhCJR+jptTf+Wsl8DBlg7SGV2XcAUez/Ne060HCxR03vmMyT+K2NSGdWNMWjK fnJ4pGeWRuo1My1ZNzET65mi6fKIl+WLhKKXPArfEw9uUSOSSvb+TImW+YUKffy6q8g== X-Received: by 2002:a50:86a2:: with SMTP id r31mr77410544eda.259.1558388395707; Mon, 20 May 2019 14:39:55 -0700 (PDT) X-Received: by 2002:a50:86a2:: with SMTP id r31mr77410457eda.259.1558388394213; Mon, 20 May 2019 14:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558388394; cv=none; d=google.com; s=arc-20160816; b=VhcBmnnnRvQXqiXj8OO5pbPAj0QfFjlEBkc1XSZ08o1hOQfNpEWgt/FEdTPb9iG1Vk LxE5l41ZhZZrlx0KvUnzFqmDdPJ+95FNUlAnWF2k2y+nPGk9UlPMZlz3l+2+pKkQIi22 wtW7SeYgL1bCZqCsY2AHnt4GW4C81vcLJyPj51EDdclwzkqhgfPjJJYvULbGM/4m0aFe EQTasqVbnMGb7/aOXTDzV0of+YwBjW7JBH8V6Fv45qJiLd06f2YLNxPPSWx2LNMqvzwm fw5z15g9qOi8AYbM2yv49eXIl7mISZzOhU8dLAHUkYn9MIY/yQakVQLNumkf2yEOGNoY cexQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=EmM3y8RoE66pNVDPE35FtUxyGgXbfiMJbpXVG8+7zqI=; b=VA+djJSG5NxqlCTb7jK0+HzNXb0jg8p7qtzk+kf1Y1GTg2rlKLdZxOIlUVCymOhpFL x/BoXM/5x3ggkcHrAfQYpCBItsFV8DnjSQvtOPF5frlE8vf4r0LrLB6tXqp6y2XkeLPn Iut69wj/sU8Zxw1nsEBYngxuwtg3QHGjwO8uChm/TSVWtucS89vLWXgZ/ISCSktntPqM TW5S05a8tGTfqAGDIepH9TXExxKkLGzwCUnQMOD3k8+JwJyx2ezAEKp7ZDGZmKbx7Ca0 lMSYb2GBmCP7+g84hoeHko0bza/0sFPIYC0Ul5my2uRGbk3iH/DpAM6AJxbH6U9aWIx5 qI1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=VqCtD+FG; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id jo15sor2885272ejb.37.2019.05.20.14.39.54 for (Google Transport Security); Mon, 20 May 2019 14:39:54 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=VqCtD+FG; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch 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=EmM3y8RoE66pNVDPE35FtUxyGgXbfiMJbpXVG8+7zqI=; b=VqCtD+FGguTkslrrNgtc+3AsPTS7qL+QTDSCXi+eKgaqMA5bR+Vi1Zt3FimdTe93zi UUo6SSEc1uaTQZeWPxCi3yVl+T3Tk/MOF0wa5AgCnvXZvlQKsF/yAclCS1OGr15EZvta Zok9O7AuvN04KmdiIx3tL5Km97dnr+ZIZDhdM= X-Google-Smtp-Source: APXvYqyKS9SIiB/xC4IsRJBze6IGM3GgILAOQy6WS8nllsilzSuF5yZIrT+jePyKYUY+nowSZNCWnw== X-Received: by 2002:a17:906:35ca:: with SMTP id p10mr44566136ejb.244.1558388393833; Mon, 20 May 2019 14:39:53 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id v27sm3285772eja.68.2019.05.20.14.39.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 14:39:52 -0700 (PDT) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , LKML , Linux MM , Daniel Vetter , 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 2/4] kernel.h: Add non_block_start/end() Date: Mon, 20 May 2019 23:39:43 +0200 Message-Id: <20190520213945.17046-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190520213945.17046-1-daniel.vetter@ffwll.ch> References: <20190520213945.17046-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: X-Virus-Scanned: ClamAV using ClamSMTP 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) 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 Signed-off-by: Daniel Vetter --- include/linux/kernel.h | 10 +++++++++- include/linux/sched.h | 4 ++++ kernel/sched/core.c | 19 ++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74b1ee9027f5..b5f2c2ff0eab 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -214,7 +214,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 @@ -230,6 +232,10 @@ 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) +# define non_block_start() \ + do { current->non_block_count++; } while (0) +# 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) { } @@ -238,6 +244,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 11837410690f..7f5b293e72df 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -908,6 +908,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 102dfcf0a29a..dd08d423947d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3264,13 +3264,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_blocking_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); @@ -3377,7 +3386,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); @@ -6102,7 +6111,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; @@ -6118,8 +6127,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 May 20 21:39:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10952381 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 254D11395 for ; Mon, 20 May 2019 21:40:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12C9727F93 for ; Mon, 20 May 2019 21:40:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0656628767; Mon, 20 May 2019 21:40: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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 71C2F27F93 for ; Mon, 20 May 2019 21:40:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 944B66B000E; Mon, 20 May 2019 17:39:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8F7966B0010; Mon, 20 May 2019 17:39:57 -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 749866B0266; Mon, 20 May 2019 17:39:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 298F06B000E for ; Mon, 20 May 2019 17:39:57 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id 18so27208576eds.5 for ; Mon, 20 May 2019 14:39:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=eXUjiROiFGqrcZrxiXfMd6x0O70wFn+SjDBkygnZtOE=; b=Ek3r4NkVYxcS6ZmqN1HamBUzGA9A5z96eJ4fVR70XgRbGBS2HqKxxOYALwsliBF5CF ofzjDGm/Wzthi9iMUI4Sf4Dj28J6h9v6fdk2a7jn2UtSO7Zcn0toQrYyD4jfntHmqI2k bkNID9w1H8KF5mUVa34tD5Z5BuqFlSFd8vf15U6imq5GNYWxCdfOYL6sALfC3i/8zBmi jtFd8Zi6sUpLfObv77u7nMBkp9j2weNqfWl9OzwqV9oHE5UKK/jxozJ3O6olkN1+GRvy i3fg+sbthEcqoeBH1y3mrIIxNe5cp1G7t9Bi7c1bK9WYwAyIRXkECc4eIQK80uSUwj8Z BnUA== X-Gm-Message-State: APjAAAXLm2++Uvna+VCZ0hqid2gCQM8ljXHi7NSimT73IGSVsT0ItSIx TbbcRrgx/eO+VKEH4cnqsvGBDms4sIpMUImcCln1vQ54zRBYUbZHDgbHMa07KHjC9sZPf8KviMv jyP0UlwuKB6KPqOctQaZLJmOK8w/ow95HOBJ7L+2diZm14gNzjhrSkfgr+5PrfU4FHA== X-Received: by 2002:a50:9490:: with SMTP id s16mr78381797eda.260.1558388396688; Mon, 20 May 2019 14:39:56 -0700 (PDT) X-Received: by 2002:a50:9490:: with SMTP id s16mr78381747eda.260.1558388395753; Mon, 20 May 2019 14:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558388395; cv=none; d=google.com; s=arc-20160816; b=d82yYwSonLaPA9MuLP8OuhKGxamVm2nSrZeR7CcBAZxAz8IiaZkuLiXt4JGA/alP5w FIN5oT5ilvvMY7t4XzpoFfRHJkCUDr5B0PzxwKoNqZgA5zTq/SULqBzuWs20NpcviKl8 1HdVFUWe6KE1MXyAEHZqwloPkD/zwZAqq32pWgnqeUmVusIQCvmGtefOJarqyMsjO9hP kf6KISMtcg7BmT85zOi6exVYzizkeicRrQx11sAMbtEBwZFkRyzBcKYPDNnnIn0vhZc5 Febr1wbpAckqN5CdbUSTu+JJ+83gHgH2URZOgnRk3uBeIIi+mOqCsFOTO7gBdYhWR1x/ WHcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=eXUjiROiFGqrcZrxiXfMd6x0O70wFn+SjDBkygnZtOE=; b=Xj099LZovyYx36OEha87infgIQw/NEDQuL2I1ssMfSTlIhcP2zisxgMtyxdPn1Mabh 4p0v6hrcKK1UUB076IJySwNdhwRdqMVQoF56ueaNl6D5qwRhjA1AEvnG2Mb0/Pe6ifza GGtUBfOYolFi2Tu0B+GKNwcJcDHsywnb4hn34iAEln+TzoOn/UEjWyoQ0D7+Szs3/0xl iEAoLA1595O/crxnCOYVLGJEvx2kG71CqVneIIJGRQcCpg4bcaE+aOfMvdK5uyPlan3P /n+jAKpNPL9Vpui50XXjsnBdsIEKybmaM0SYTHtk7BqHpkNRRTHb3QTeP3Dn2wMHu3dT Tl9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=HE+2jI9y; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m19sor1756994ejx.25.2019.05.20.14.39.55 for (Google Transport Security); Mon, 20 May 2019 14:39:55 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=HE+2jI9y; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch 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=eXUjiROiFGqrcZrxiXfMd6x0O70wFn+SjDBkygnZtOE=; b=HE+2jI9yKoWCqEtPmGEmHm4ylYNZon4lbb4PF4NHS53IZxF8pOEgpY8SO8PWwjK/yd Kr/K3az9UYI2fpQ8PMsRr6OEK8DOagVNchYQwPKerYeVImZ6A8MUoeqdUStHHSrf9OL7 JAAzKQQ0avwTjuYS01lKURpWOQUYPaK/I6Hmg= X-Google-Smtp-Source: APXvYqz2Kva8jHAMyBKyLi3aGikci686nvq4u0U8stYOPI/ZCt3pyHtCQHVoinWV1c/CI2ko59Od2g== X-Received: by 2002:a17:906:4d4f:: with SMTP id b15mr1630714ejv.116.1558388395426; Mon, 20 May 2019 14:39:55 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id v27sm3285772eja.68.2019.05.20.14.39.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 14:39:54 -0700 (PDT) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , LKML , Linux MM , Daniel Vetter , 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 3/4] mm, notifier: Catch sleeping/blocking for !blockable Date: Mon, 20 May 2019 23:39:44 +0200 Message-Id: <20190520213945.17046-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190520213945.17046-1-daniel.vetter@ffwll.ch> References: <20190520213945.17046-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: 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. 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. 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 Signed-off-by: Daniel Vetter Reviewed-by: Jérôme Glisse --- 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 c05e406a7cd7..a09e737711d5 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -176,7 +176,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, From patchwork Mon May 20 21:39:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10952385 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 A04D71395 for ; Mon, 20 May 2019 21:40:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DAFA27F93 for ; Mon, 20 May 2019 21:40:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ECB928759; Mon, 20 May 2019 21:40:03 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 D84E327F93 for ; Mon, 20 May 2019 21:40:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D15DC6B0010; Mon, 20 May 2019 17:39:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CC6886B0266; Mon, 20 May 2019 17:39:58 -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 B8F3C6B0269; Mon, 20 May 2019 17:39:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 654F46B0010 for ; Mon, 20 May 2019 17:39:58 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id r48so27230290eda.11 for ; Mon, 20 May 2019 14:39:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pWxZTOU32QqeCUWxSxBPbL225yVTtI+hlaFCbsgM9zc=; b=Ont+e2JtMPphcxXSXDTm3akk6OB03WWVbhkkS6MD0B0IIrUTa++jppEv0DNuwbWUjD i3ej6mSwmW/mBUzdI/TorYUXIzU/fqOqoV0f3SXM99fMDBG7mC/vGQcFRLHY5/emzNfF lgodj86frV/hF293BBneNjjMeedJdyUwb0gYh58w3QCzeAWRiIOWilBBLVFTgNdBxuGU uVGTzRJFMozKcqAIYgqOGa6SB1wOB+c4No9+EGxI64AG1rwyAxVNhPQlRZmWY+/7NNM+ kCe9694skwLfL1tLrlKMMrOqNzJCKbx9WA538oQm8ZB612ZLazChcXrbMpjNJr7ICVhH mEhQ== X-Gm-Message-State: APjAAAWq35klSY6aFDbC4VEgkuRQ5nEPCYaRCSbBgcmSRKrSiXmWcjjn bRMnJUlLl6zNNauM7vVXsYBOUaVHG+YZk1ioEEH1qfzDbg0DoQi+rKrx1eK61Ro0rOpm5FMigeR tlHM7beyMfaW3Y8YOrsVpNMo+4MvXm45wXeocHF1csVazEYF2mDVy2IADO0tgmDTRMg== X-Received: by 2002:a17:907:20ed:: with SMTP id rh13mr42597593ejb.5.1558388397903; Mon, 20 May 2019 14:39:57 -0700 (PDT) X-Received: by 2002:a17:907:20ed:: with SMTP id rh13mr42597544ejb.5.1558388397027; Mon, 20 May 2019 14:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558388397; cv=none; d=google.com; s=arc-20160816; b=lSns80R/YLfFSzwuSC/mdjoVFsUruvf2tezMZeY4lmb5T4tEwMpv/wshKULp/a5EB5 h89rs49TGF+MYJuswjPf6SsIKJn4Vz5P0YUOWpwDP25AZ5eamp7cy2MrzaaIZMia33Mz H5JulKeMOnvOV18NUhdBwwT8P3Jst7QfraWwNEl1ZQ46lruYVY/HqOCZa+Qws2cUjUQ7 kMehT1ExoYyow75s79tjhXNxWe7S9XsSL7aoPT/iSSdQ6Apu0yxCNd41vzp+I955jaoA mo+gUsWpn5QK4jLfptuAogspjw5jO1QVHc8wKr/9GgaoLGNac8p8EgdStAnMg9Jc3sQd XBRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=pWxZTOU32QqeCUWxSxBPbL225yVTtI+hlaFCbsgM9zc=; b=wgu5/tFGO8aOMHEpmysnj1n8Xohm3Tp8E4G0tlAlSkx1M8IpL62ThL7/Msgvr6dwrm VydSG1F0x896yu6hMU3ybMNAJWfoz7/xnyZ5R6SmxsdwKjHJ+Qrmysw+vdPeWPUDrK8M h+ZgdeNYc6I8jLN+8qdIOS76sDsVgLSzlgMUy2ijPUdjU17uLi7zB3a3TOsPruHJws/i qB6U4M4N+umpqtikR2j6GfYA08jD+QkkzkCP4YfxrpeIh3O+Fze2TvcbrM7L4O7jmEio +82ASVdH+wHW4ejU+QO0xqIRjS6IyECjFGP2YC4RsUkZvgYtapZpZ5b3o5CIca6CAaie nYJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=lD66uZtM; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t11sor3084400ejq.55.2019.05.20.14.39.56 for (Google Transport Security); Mon, 20 May 2019 14:39:57 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=lD66uZtM; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of daniel.vetter@ffwll.ch) smtp.mailfrom=daniel.vetter@ffwll.ch 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=pWxZTOU32QqeCUWxSxBPbL225yVTtI+hlaFCbsgM9zc=; b=lD66uZtMoIMvvSsmt5W9Ap+FV3+sBqSE3BFc0cEJ684d/bm9E2HP1JXq7mSRH9YW4v nkbstF3kFQkxqWWqyv6BlV3/MFaD+qTRyQzGtP0efOBVs1Kb0ZlKW4eRerQFHNS9iDrt TmWczlsEj0ymWwKCv4nAMDK83tVqOnaVQm3Tg= X-Google-Smtp-Source: APXvYqx80jEeRT18HZXVIF2BoTYuZwcSTE9+LxH0PFGQif7m2Gu96O3Mba57kRuyzhiZzeoU6L992A== X-Received: by 2002:a17:906:5390:: with SMTP id g16mr53949638ejo.12.1558388396676; Mon, 20 May 2019 14:39:56 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id v27sm3285772eja.68.2019.05.20.14.39.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 14:39:56 -0700 (PDT) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , LKML , Linux MM , Daniel Vetter , Chris Wilson , Andrew Morton , David Rientjes , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Michal Hocko , =?utf-8?q?Christian_K=C3=B6nig?= , Greg Kroah-Hartman , Mike Rapoport , Daniel Vetter Subject: [PATCH 4/4] mm, notifier: Add a lockdep map for invalidate_range_start Date: Mon, 20 May 2019 23:39:45 +0200 Message-Id: <20190520213945.17046-4-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190520213945.17046-1-daniel.vetter@ffwll.ch> References: <20190520213945.17046-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: 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. 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. 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 Signed-off-by: Daniel Vetter Reviewed-by: Jérôme Glisse --- include/linux/mmu_notifier.h | 6 ++++++ mm/mmu_notifier.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index b6c004bd9f6a..9dd38c32fc53 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 @@ -310,10 +314,12 @@ 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 diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index a09e737711d5..33bdaddfb9b1 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