Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1478712pxb; Fri, 20 Nov 2020 10:25:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkq7hCcppZvRiumqh7OYJsAEZzI0hDuj01wQ+pch92DIH+LCuHpYUvDbAEYVGYPv9gXk4D X-Received: by 2002:aa7:d356:: with SMTP id m22mr36609376edr.270.1605896713672; Fri, 20 Nov 2020 10:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605896713; cv=none; d=google.com; s=arc-20160816; b=kx+c51B1ZZ+RB5kQFolSkAsRHZZnW13ecx5abpKdZnrxVX1Uis2Hgy9vV9EBpRZIrZ lrEbkgoAnl8rat5/MfFepNPySBDBjhY1I3oGo/mX5+r2uWvrB2YrKicHKosK7O3hdniI vgRu+cwGD0+own0+6QqDvGGsr4z9lvh1G8I4WQ7zE2rNWSmfyO8Yl8rD69EVQH+WXWX7 ETDPJH1A47zE5isg/WNqINPW9ByK+shLKztpKQoC0vGwMsAoRPZwl+TRaRGbz77H7KwL M+1r54V8aBLO6hVIC/AuBByR7L7KEJwErK/gcaHzSuFP+cIh/foqBs7QW/e7RX7uLC8p Ihcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UCRF1tW/AZBL2cTgUwVNxqtk7LoMkUYo1UAbEj+RJjA=; b=sJ/uMR2bxBAAdVfm75igVJUT6+LG1OuQMKuiHPAb4jWBBK83/CqemvoQdPmoQgN8k6 j2cWlsbaaHI9dqg7vqSoZ3nz11sSlfNyGgzghNree596/UaImbUiHDOEbCXI2d2SFi1q 9jdjdPFpCIte0rwn3bdg5TDnw8hp+xgKOrYwyEnl6+HDPRxenG4Itsc8ge1w3h1C+X3K rBcDzj+2WjOSYgQWrlxLutDkdWYRSP/uyPiwnJapp7dVktMwhDtO3KsEpWqQT8KNU0SX wOlOfNyguMyGQ7VtjBtK+2kdvQ7siLyh1tQlgETy56hptFzeA/QNFxebXXLbOM/dkwQ1 5haA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=B4hybK4y; 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 do13si2201336ejc.286.2020.11.20.10.24.49; Fri, 20 Nov 2020 10:25:13 -0800 (PST) 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=B4hybK4y; 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 S1728696AbgKTSXV (ORCPT + 99 others); Fri, 20 Nov 2020 13:23:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728383AbgKTSXU (ORCPT ); Fri, 20 Nov 2020 13:23:20 -0500 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 CD6E3C061A04 for ; Fri, 20 Nov 2020 10:23:18 -0800 (PST) Received: by mail-qv1-xf42.google.com with SMTP id a15so5122635qvk.5 for ; Fri, 20 Nov 2020 10:23:18 -0800 (PST) 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=UCRF1tW/AZBL2cTgUwVNxqtk7LoMkUYo1UAbEj+RJjA=; b=B4hybK4yzaLM2Npm1+7g6r63APKMgeTYmtc+xA4iVzmdUpm8/fc6u8PaaYBUCEqsTa DQGtD0B85sfZ6AQDUGUUQC5pVjZlDUujNTP78g/UuI8FK4lpcR30mtecsvkVf7DRgiuW MlO955aCtgx98+WPuV3NTYdOklNjuBLotWjSZU4ObiQWcAx2srZjTgQUtz+nDfdm6w6W DZqPXoE1QXdh/pboRXeD4ejJgfX5GK2Q1BTBAtJtZmFj9fTPLr6v/mkTDWfR54U03nWV iXOwhBmbqACTOvfxkYtC+csJIypzFC+zmDe+YDbqWg3tSfxHioKaKSUTa24FTqD2nFIt rECQ== 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=UCRF1tW/AZBL2cTgUwVNxqtk7LoMkUYo1UAbEj+RJjA=; b=PRNDDITI+xCG68ts1GgGdgVr7tCUvkpUZydiVkJxGCV+edPpqvfWU1EHoRMip8Hjmc KQXJQZwKIRQZnmiFbVzRb2T0lUkz1mJKkzNChk4b7vPSbA2PYEk+gj3810uwaMRmCB4r fkBrWwkSCUm1L6nRIalcGi2lMYg4u5Ds8a7kpbxtqoKpUDtnRGkF/eOUJX3ahAIr1wWw iq/y7GJsF0rOAuhUzg3FAXVUh2ei4P48lMEsW/y8IE2MzH6SI3xiyj5rfsuGB5KNgpC7 57JTpEt8vBzbdnGRrsmMAcgMjyINRsMlZg0LLme2X+wwdwWLD/3IxISgAisXL4LSNY8V wSKw== X-Gm-Message-State: AOAM533IqSKuOnx/qqIDfGt1dIITFnky0B26pGCf+91z/pVgf6oFYpWZ Ws8aky8BKflB/dw/oPc9uJCvaw== X-Received: by 2002:a0c:b18a:: with SMTP id v10mr16583162qvd.46.1605896597938; Fri, 20 Nov 2020 10:23:17 -0800 (PST) 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 v9sm2453624qkv.34.2020.11.20.10.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 10:23:17 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kgB40-008ub6-IN; Fri, 20 Nov 2020 14:23:16 -0400 Date: Fri, 20 Nov 2020 14:23:16 -0400 From: Jason Gunthorpe To: Daniel Vetter Cc: DRI Development , Intel Graphics Development , linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, LKML , Dave Chinner , Qian Cai , Thomas =?utf-8?Q?Hellstr=C3=B6m?= , Andrew Morton , linux-rdma@vger.kernel.org, Maarten Lankhorst , Christian =?utf-8?B?S8O2bmln?= , "Matthew Wilcox (Oracle)" , Daniel Vetter Subject: Re: [PATCH 1/3] mm: Track mmu notifiers in fs_reclaim_acquire/release Message-ID: <20201120182316.GP244516@ziepe.ca> References: <20201120095445.1195585-1-daniel.vetter@ffwll.ch> <20201120095445.1195585-2-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: <20201120095445.1195585-2-daniel.vetter@ffwll.ch> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 20, 2020 at 10:54:42AM +0100, 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 > > v3: Unbreak the PF_MEMALLOC_ context flags. Thanks to Qian for the > report and Dave for explaining what I failed to see. > > Cc: linux-fsdevel@vger.kernel.org > Cc: Dave Chinner > Cc: Qian Cai > Cc: linux-xfs@vger.kernel.org > 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 > Cc: "Matthew Wilcox (Oracle)" > Signed-off-by: Daniel Vetter > --- > mm/mmu_notifier.c | 7 ------- > mm/page_alloc.c | 31 ++++++++++++++++++++----------- > 2 files changed, 20 insertions(+), 18 deletions(-) Reviewed-by: Jason Gunthorpe Jason