From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48FC7C63798 for ; Tue, 24 Nov 2020 14:34:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AF8A320757 for ; Tue, 24 Nov 2020 14:34:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="UhV7hB9L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF8A320757 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 1E2B66B00A8; Tue, 24 Nov 2020 09:34:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 191F48D0003; Tue, 24 Nov 2020 09:34:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 032B88D0002; Tue, 24 Nov 2020 09:34:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id E4A076B00A8 for ; Tue, 24 Nov 2020 09:34:16 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id ABB631EF1 for ; Tue, 24 Nov 2020 14:34:16 +0000 (UTC) X-FDA: 77519556912.28.toe09_38142862736e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 890AF6C3A for ; Tue, 24 Nov 2020 14:34:16 +0000 (UTC) X-HE-Tag: toe09_38142862736e X-Filterd-Recvd-Size: 8011 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Nov 2020 14:34:15 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id 64so9125581wra.11 for ; Tue, 24 Nov 2020 06:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=YQpCas1RNfDZEcGYI04yEm6odPOACipDcEuTBaoIULk=; b=UhV7hB9LJySyibtoHRqaxMir8P7FnhXAU96E4aHd3ofIMEZCRtLh+zeMX/RZH2wp/d ASfb7zsWToxZhdhECdglvYGnSj/gHkK+a128+ByWw8EqQuvRvEHVa/6FGH0Q/PMdeY8p cOVbuuXQq/r/33GWKbTOqEjjjzE0whLpLoOC4= 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 :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=YQpCas1RNfDZEcGYI04yEm6odPOACipDcEuTBaoIULk=; b=WARTTSyfB8Xv8lxLMLufsYr/+rVyq2t7GrbOI2dXD443mOrDaw32du/VIK7BZ6kRq3 bvZTbujTDAAjKGUgGjcwe4Gz3HfCag5w+a2swi/GutuglKykeagx+SJ7LN/YIdC0pe1h BZEHWHyFS0RqBapjo7zslxNiS7bRiOYhLgjuFypGHcUHXFeckZYJxk1/QDs65cjX6p9E +K22LeyXSXvn4mzKqjgfFj7GmD25dvm+BFvEO30/XOfEI9eZEuE7JUtk6VXwjXPbEtmA sTsEMjGmNPA3XPMYEBRcou32y1vlgvML9IkjBB8IUpZcWovOuS5S0KdcDnh3ipuO2Ejh foSg== X-Gm-Message-State: AOAM532yrbrABwdCyLAsSmhtEQ6GJvAqwqGRMUbBvS9fn9gjgHrW1JUP Cn8ajHHBly7uMGOpPtPuMrD7mw== X-Google-Smtp-Source: ABdhPJz6iTrOgvt95IAsr45xzCdl3M2C2ca0X4EFZPlX+gugzV3LnRN6/oGeySsazf01z6hbldI7qw== X-Received: by 2002:a5d:50d1:: with SMTP id f17mr5715898wrt.264.1606228454425; Tue, 24 Nov 2020 06:34:14 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id m18sm27135410wru.37.2020.11.24.06.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 06:34:13 -0800 (PST) Date: Tue, 24 Nov 2020 15:34:11 +0100 From: Daniel Vetter To: Jason Gunthorpe Cc: Daniel Vetter , DRI Development , Intel Graphics Development , linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, LKML , Vlastimil Babka , "Paul E . McKenney" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Peter Zijlstra , Ingo Molnar , Mathieu Desnoyers , Sebastian Andrzej Siewior , Michel Lespinasse , Waiman Long , Thomas Gleixner , Randy Dunlap , Dave Chinner , Qian Cai , "Matthew Wilcox (Oracle)" , Daniel Vetter Subject: Re: [PATCH 2/3] mm: Extract might_alloc() debug check Message-ID: <20201124143411.GN401619@phenom.ffwll.local> Mail-Followup-To: Jason Gunthorpe , DRI Development , Intel Graphics Development , linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, LKML , Vlastimil Babka , "Paul E . McKenney" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Peter Zijlstra , Ingo Molnar , Mathieu Desnoyers , Sebastian Andrzej Siewior , Michel Lespinasse , Waiman Long , Thomas Gleixner , Randy Dunlap , Dave Chinner , Qian Cai , "Matthew Wilcox (Oracle)" , Daniel Vetter References: <20201120095445.1195585-1-daniel.vetter@ffwll.ch> <20201120095445.1195585-3-daniel.vetter@ffwll.ch> <20201120180719.GO244516@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201120180719.GO244516@ziepe.ca> X-Operating-System: Linux phenom 5.7.0-1-amd64 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: On Fri, Nov 20, 2020 at 02:07:19PM -0400, Jason Gunthorpe wrote: > On Fri, Nov 20, 2020 at 10:54:43AM +0100, Daniel Vetter wrote: > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > > index d5ece7a9a403..f94405d43fd1 100644 > > --- a/include/linux/sched/mm.h > > +++ b/include/linux/sched/mm.h > > @@ -180,6 +180,22 @@ static inline void fs_reclaim_acquire(gfp_t gfp_mask) { } > > static inline void fs_reclaim_release(gfp_t gfp_mask) { } > > #endif > > > > +/** > > + * might_alloc - Marks possible allocation sites > > + * @gfp_mask: gfp_t flags that would be use to allocate > > + * > > + * Similar to might_sleep() and other annotations this can be used in functions > > + * that might allocate, but often dont. Compiles to nothing without > > + * CONFIG_LOCKDEP. Includes a conditional might_sleep() if @gfp allows blocking. > > + */ > > +static inline void might_alloc(gfp_t gfp_mask) > > +{ > > + fs_reclaim_acquire(gfp_mask); > > + fs_reclaim_release(gfp_mask); > > + > > + might_sleep_if(gfpflags_allow_blocking(gfp_mask)); > > +} > > Reviewed-by: Jason Gunthorpe > > Oh, I just had a another thread with Matt about xarray, this would be > perfect to add before xas_nomem(): Yeah I think there's plenty of places where this will be useful. Want to slap a sob onto this diff so I can include it for the next round, or will you or Matt send this out when my might_alloc has landed? -Daniel > > diff --git a/lib/idr.c b/lib/idr.c > index f4ab4f4aa3c7f5..722d9ddff53221 100644 > --- a/lib/idr.c > +++ b/lib/idr.c > @@ -391,6 +391,8 @@ int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, > if ((int)max < 0) > max = INT_MAX; > > + might_alloc(gfp); > + > retry: > xas_lock_irqsave(&xas, flags); > next: > diff --git a/lib/xarray.c b/lib/xarray.c > index 5fa51614802ada..dd260ee7dcae9a 100644 > --- a/lib/xarray.c > +++ b/lib/xarray.c > @@ -1534,6 +1534,8 @@ void *__xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) > XA_STATE(xas, xa, index); > void *curr; > > + might_alloc(gfp); > + > if (WARN_ON_ONCE(xa_is_advanced(entry))) > return XA_ERROR(-EINVAL); > if (xa_track_free(xa) && !entry) > @@ -1600,6 +1602,8 @@ void *__xa_cmpxchg(struct xarray *xa, unsigned long index, > XA_STATE(xas, xa, index); > void *curr; > > + might_alloc(gfp); > + > if (WARN_ON_ONCE(xa_is_advanced(entry))) > return XA_ERROR(-EINVAL); > > @@ -1637,6 +1641,8 @@ int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) > XA_STATE(xas, xa, index); > void *curr; > > + might_alloc(gfp); > + > if (WARN_ON_ONCE(xa_is_advanced(entry))) > return -EINVAL; > if (!entry) > @@ -1806,6 +1812,8 @@ int __xa_alloc(struct xarray *xa, u32 *id, void *entry, > { > XA_STATE(xas, xa, 0); > > + might_alloc(gfp); > + > if (WARN_ON_ONCE(xa_is_advanced(entry))) > return -EINVAL; > if (WARN_ON_ONCE(!xa_track_free(xa))) -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch