Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp45989pxu; Tue, 24 Nov 2020 18:08:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLUaVbZ/Nw41giUwq03U0e5f2PAzRSnT+dwyHof8PqK4zyPX5flEi0xG6zAYMQVAmQaZ7Q X-Received: by 2002:a17:906:2345:: with SMTP id m5mr1143723eja.329.1606270100056; Tue, 24 Nov 2020 18:08:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606270100; cv=none; d=google.com; s=arc-20160816; b=0yWj59Ab0WO09W5Ti3n/8wTt0y28PwdFJ8O2uVIiVYVvlFMcqfnJjUIUj96c7pboyr MtrEUKPxnWZDTudEN17FLrW1MpmPr2o+6Yoq9BH1tcFHN87kwxWJoo5Z6Ulp0KQiGC9G SPZsAKGA6HU31dI+jKGOD8ALaQGCV/6+AJwWIZZtKez4ZRSDXhMn7eQdr7+lzJxzdBj5 y0nx004J7Cpu0HbC4B+sTHU+29huXSvK8KxTa3NFkEKXT4elny1uCepavA09Q3QCUANH FMzy6ND+dYGjUV0CBrjlkXzMC6rE+cYfS7FhZe8PhHrI6HZGRNsYwgpIb13ubxF9hskt xoLA== 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-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=YQpCas1RNfDZEcGYI04yEm6odPOACipDcEuTBaoIULk=; b=iI+r5Mk5QKJDuEY9LkahumUUNJ9xuN4N7MpoXu/c/0Wct2OvXHZgMF3/nU9Rry3Cvu 2E6/iM2mnUNdlXdcRpekbImkj9dHoUl0uKPEqrvP6uxHasHeTv2rab3SZjLuiogOiv6/ vwiRWOgwXa6oGFR1k3sMgvVT34PJWpMI0DuK6E/uA7p4geCXC+qk3j9UWhBClCcbsQUx fbtLMB9EnyRO+FgEstHGXK+zozrA7Qd0inRpAyFJ/RmLJeS5bDb7dFd1t3jc3xLqvmS2 h09SMcbnfiCHt00YNQtl18/SmqeRI5CA0+vreWUDEMqol+Y0HbGQ59TmNKA8W8Mge4Hq 2uoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=UhV7hB9L; 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 w12si421910ejb.135.2020.11.24.18.07.56; Tue, 24 Nov 2020 18:08:20 -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=@ffwll.ch header.s=google header.b=UhV7hB9L; 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 S2389048AbgKXOeS (ORCPT + 99 others); Tue, 24 Nov 2020 09:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388847AbgKXOeQ (ORCPT ); Tue, 24 Nov 2020 09:34:16 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8944C0617A6 for ; Tue, 24 Nov 2020 06:34:15 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id p8so22550800wrx.5 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=sohnyt4KBY9Xc/EgB0z20h9eUlAu1Im6jSZ+LqWfRAPoZtrdrI2cE1h4OVv+Y9J47r hCr/Km5w6g1Z107WR4QhRIk3Qc07IbXHvSnKfs9O6giyW5nIxg+jNhvklh8rBkQ4BjO0 fqfD9FKSeME91jMn7ETxoKXgrZTxgmLKxBK9kvALE2oY/jLn0uz+vNgcJjtrvcZpEBKE tdVpcLxQ6BN0t8uje8w1nIVB+nmUjxp9gTiJXiU7fmlIxjAUhJ9FOiK6Bgzshd/URdjg 8XDjOgbaA8hzVvTzDnQQIXHCZJjMUS5K0B9ZqSGgnesrLLbbFPt2xz4im7khmCZ9BGz0 J+Zw== X-Gm-Message-State: AOAM531SqCTuKy2JA6Z+i/dmNwf4xS/pD2H7AXMqiExWHWHQ1HWbPEJa 2jav4P1GyZS4/G6mRguuY/Emag== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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