Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1469530ybg; Thu, 11 Jun 2020 10:36:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweXuZjhe0DbJhtoSa2TXd7n5If/XCiEHpf1+YAcmVkfdpy00HgthOtJgAw8SPSIOCFIprU X-Received: by 2002:a17:906:468e:: with SMTP id a14mr9348647ejr.124.1591896979782; Thu, 11 Jun 2020 10:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591896979; cv=none; d=google.com; s=arc-20160816; b=UrzZ1I3Yq9nlUhgEgGdhWU6MCHy+txU0HfCIET453u20hwCzy8DUbovrxYK4yQEdxG 2QSr1rPmJqjeCnXBdfEWtBpcNgGTLxnlZQXMzwHF+n0cjp0+ftnSPrx044xr4Y51jn0E H/E/vRsqF96Lj4Uyl1mOr7LeC0jLOBc5OlTTJDlBG8QcHdHWb/6B6zj8coXezq5L+YKV VddhPm2N4ZMG1Ko2J1kD7AdL8SMkDstpeqF3xYSuOW0cmr0MCAiaTxbPfPGAKoa+IZ/k SfAJ4pWE+EQo0XcU7a2J3BHDrxcvCix1JzD1crqyi5ngB0bERhzOOx3xCiLIDL+czTGT L/cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iS2yXa8gKHNwS2UChvutG5V1O7eVsWQuqeZ34MVLXc0=; b=H/V9eFYxJQ7nbbtBjN26tGtwCGCunBWBP6d0YgfvaglHig5FXwx9XaeaiKOqFi+FP3 Xjky/WQ9TlMnzn+1GOn8nQfc34BbMbx12SUGicY9/tWIWo3sXNs/ax8103QJrf0Mi4/x NWBdB8Pj7C+FTv6nm1nHXBv5cZUq7OE6SULnNLXvb60XgGbp/GyRU1sSbqh7JzsvBB+h l6IJ6OI3JtH9HV7Bm6SlrPgFsSZynsQf+Yu3XBzVNIrWn2BNSVJv2X1z6jfQnOIYl47f bXo5tqThqjmlB/ySfgBruuWFThjfKXbQLPKinn7diVdxCLNVNVMHQ5wNEUh01jsW5Miv ouMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=FseEPp8F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk10si2394678ejb.554.2020.06.11.10.35.56; Thu, 11 Jun 2020 10:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=FseEPp8F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728375AbgFKO34 (ORCPT + 99 others); Thu, 11 Jun 2020 10:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728229AbgFKO3z (ORCPT ); Thu, 11 Jun 2020 10:29:55 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7CA6C08C5C1 for ; Thu, 11 Jun 2020 07:29:55 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id p15so2703077qvr.9 for ; Thu, 11 Jun 2020 07:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=iS2yXa8gKHNwS2UChvutG5V1O7eVsWQuqeZ34MVLXc0=; b=FseEPp8Fso/6As15zVP3Ym7NPs9kvuOvCIptWPzePslhXjFzBDqQXKhNnYWATD+15R Al/WYp+hbHsKFK4X2ojiK+EHs7yhQmmL+EDMNyPnOR89aEMfOJc5yjRH0aJYrgc62Vs4 Doe6mzmOoH4EXTAuqTBF2FSP/hDXXwvjF9/30kmpRxNG9NB7+P9LM/fisKeD5/yoOQW2 PEChRlkS/fkvSbixN4O37472Uu4NlrAggCY6VhNzkkPK4SDvGr55LxYD+4T/EdoOhWVl 4gdKknLaMPLAltUrhRVsboI89uK5/pkjAghK31JbmOaIh7KRRHIu3+t+3Jd7dolDArof vWaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=iS2yXa8gKHNwS2UChvutG5V1O7eVsWQuqeZ34MVLXc0=; b=DhytL+JMJA7tUa7bFhIu+BQF1Jw3vSFHQ8RV7KiyKeaSTFyoFFtSpLO6DRljQbifGf sdyBzZJM3a8sLojmtYnOFNCpXHjrBQfrWaXrK3R/iusQOPWhWFOO0PUyhvezowzZpVyT 8e8LCVcy1q9PsOgCsTbn5HW7gb87eJrOfXXUYGdz9NibWTL8qrkiDpI0x4cR3YqhTudw THjlcamzQmVQ+2nGCW6SPQvhHURv0Oj6Qz7AH+DB5pIbiuO0ro5w3IZVtpmaHo/cHIWZ G3/F4fL1FachFkdD68WsUVyeOcRUOAaHKns5EvH7DI9JOJF7foLV8g/6rjKhHBzx1JsS sepg== X-Gm-Message-State: AOAM532VfyQpz98T3fR3C+IIXtRRok0yUhxiR8i7eYq2+lWp4FYlT6tX ypy4fd1T5EsNcrNmTtiKBMS4zQ== X-Received: by 2002:a05:6214:13e6:: with SMTP id ch6mr8093893qvb.29.1591885794923; Thu, 11 Jun 2020 07:29:54 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id 195sm2287728qkg.74.2020.06.11.07.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 07:29:54 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.93) (envelope-from ) id 1jjODJ-005xNV-Ml; Thu, 11 Jun 2020 11:29:53 -0300 Date: Thu, 11 Jun 2020 11:29:53 -0300 From: Jason Gunthorpe To: Daniel Vetter Cc: Intel Graphics Development , DRI Development , LKML , amd-gfx@lists.freedesktop.org, Thomas =?utf-8?Q?Hellstr=C3=B6m?= , Andrew Morton , linux-mm@kvack.org, linux-rdma@vger.kernel.org, Maarten Lankhorst , Christian =?utf-8?B?S8O2bmln?= , Daniel Vetter Subject: Re: [PATCH] mm: Track mmu notifiers in fs_reclaim_acquire/release Message-ID: <20200611142953.GA1419658@ziepe.ca> References: <20200604081224.863494-2-daniel.vetter@ffwll.ch> <20200610194101.1668038-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200610194101.1668038-1-daniel.vetter@ffwll.ch> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 10, 2020 at 09:41:01PM +0200, Daniel Vetter wrote: > fs_reclaim_acquire/release nicely catch recursion issues when > allocating GFP_KERNEL memory against shrinkers (which gpu drivers tend > to use to keep the excessive caches in check). For mmu notifier > recursions we do have lockdep annotations since 23b68395c7c7 > ("mm/mmu_notifiers: add a lockdep map for invalidate_range_start/end"). > > But these only fire if a path actually results in some pte > invalidation - for most small allocations that's very rarely the case. > The other trouble is that pte invalidation can happen any time when > __GFP_RECLAIM is set. Which means only really GFP_ATOMIC is a safe > choice, GFP_NOIO isn't good enough to avoid potential mmu notifier > recursion. > > I was pondering whether we should just do the general annotation, but > there's always the risk for false positives. Plus I'm assuming that > the core fs and io code is a lot better reviewed and tested than > random mmu notifier code in drivers. Hence why I decide to only > annotate for that specific case. > > Furthermore even if we'd create a lockdep map for direct reclaim, we'd > still need to explicit pull in the mmu notifier map - there's a lot > more places that do pte invalidation than just direct reclaim, these > two contexts arent the same. > > Note that the mmu notifiers needing their own independent lockdep map > is also the reason we can't hold them from fs_reclaim_acquire to > fs_reclaim_release - it would nest with the acquistion in the pte > invalidation code, causing a lockdep splat. And we can't remove the > annotations from pte invalidation and all the other places since > they're called from many other places than page reclaim. Hence we can > only do the equivalent of might_lock, but on the raw lockdep map. > > With this we can also remove the lockdep priming added in 66204f1d2d1b > ("mm/mmu_notifiers: prime lockdep") since the new annotations are > strictly more powerful. > > v2: Review from Thomas Hellstrom: > - unbotch the fs_reclaim context check, I accidentally inverted it, > but it didn't blow up because I inverted it immediately > - fix compiling for !CONFIG_MMU_NOTIFIER > > Cc: Thomas Hellström (Intel) > Cc: Andrew Morton > Cc: Jason Gunthorpe > Cc: linux-mm@kvack.org > Cc: linux-rdma@vger.kernel.org > Cc: Maarten Lankhorst > Cc: Christian König > Signed-off-by: Daniel Vetter > --- > This is part of a gpu lockdep annotation series simply because it > really helps to catch issues where gpu subsystem locks and primitives > can deadlock with themselves through allocations and mmu notifiers. > But aside from that motivation it should be completely free-standing, > and can land through -mm/-rdma/-hmm or any other tree really whenever. > -Daniel I'm still not totally clear on how all the GFP flags map to different behaviors, but this seems plausible to me At this point it should go through Andrew's tree, thanks Acked-by: Jason Gunthorpe # For mmu_notifiers Jason