Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp823924pxb; Thu, 17 Feb 2022 15:51:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKK2nhu/nHg7XVUjesNmdrtuocbjOxHCPAHGHRC/4VqpcX1QhXiWZ5zqfGy9m64zxVwoX/ X-Received: by 2002:a63:161c:0:b0:372:e459:70e6 with SMTP id w28-20020a63161c000000b00372e45970e6mr4243156pgl.596.1645141910818; Thu, 17 Feb 2022 15:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645141910; cv=none; d=google.com; s=arc-20160816; b=aAbhokFUMiw70M2gEGTyEnUV6+LVU7TYUHix5rsT/5aNN7gN6BEQRRtkXZRVTiu/gn Fsyt8NaBFvJYXsu89Qz0q9iPmBy2jT4PYVXeYIzkUfLiEeFF4uV1nAZIF135jqcHGfyM SXdjhpgNbB5x+7Y/Xn0GiU977w8ONG74SZ4OU9XmI1En2U3p0GhJKlZJKDI9y5AbakxH 77sLPwuhxmNeLjsY/PQPtduc1PyNnEfh8/bOxcBZy6+2be9b2U+fjKHZ8VWyntQqJrY6 mCHgVDS2g8/18HqkQBzG0W1WaPoMcmWDbnOqTZULTgVnw++7zcr43DOnfj6bsVwreBXL nEog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ue09UYaxTaEqS175+LfKF6ZQhoNdq+QTxAZ6/A1fP2M=; b=SDGYC8WjBUb3jWvK2FCQu4rS7rYwyx2jY2v0os5J/ae1+Y3SJ0XLBvN5/I4465u9ra nnNB7HemkgSc8ULasCidiAHtePEGwi0/0nbHBjjsE22ODCTl7YRylZDuDP7d8oqYLhyt AZC4XXUjuR5Q5DE/WOVNxcC4iA0zweXOuJgMv0DwRu8WOfN/Xa3DVp4c3P9wg7E2+ln5 h7BU8RF/BNbMt4tmuqQ6xyEgJEnCNFj9Uq5xht+OUl1C347OCOb2vuOOz4O55HDaR3Mj y/ilfb8jrnHHTFLJbhYiH2dD+eCoaQznyWghlrGRPbVfMyKcbYmP/UBZnBFHwLQ6BBqi GEOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DbdZsHSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w5si1953982pjr.136.2022.02.17.15.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 15:51:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DbdZsHSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE95050B3B; Thu, 17 Feb 2022 15:24:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241782AbiBQPNo (ORCPT + 99 others); Thu, 17 Feb 2022 10:13:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242341AbiBQPNl (ORCPT ); Thu, 17 Feb 2022 10:13:41 -0500 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FED2A0D41 for ; Thu, 17 Feb 2022 07:13:27 -0800 (PST) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-2d07c4a0d06so35084597b3.13 for ; Thu, 17 Feb 2022 07:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ue09UYaxTaEqS175+LfKF6ZQhoNdq+QTxAZ6/A1fP2M=; b=DbdZsHSudW3XTJiY+K1xA58iiJbLUQuB5eSPGNbbgrAQPf8IlmE03xiqg1+9wuD6fz prwczh4o+KUv8m47n1jAFn1qlfpy8WgmxUtJU/UkjM4IEiFhE+lKg/ImrzVwLl9cfwfr 2GNgce03dRItFvEmtPhz8UhPt0AuJ3S9+3H5wTMYIgsXFNpN0hjy4pN2DVvhRasuX/eq 0p33LNW5rO3BP2q6hlTUU+N6+1LwrNkcul1fnfrspmH5cI+FTRtcmC5a1ODWbB+hX/vG PykTm84tq45e7zRH6B+axrW4X3oQ+cbMYPhhkaugixg9Db8CDpkGUKfZhEErAOW4Grp6 C+XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ue09UYaxTaEqS175+LfKF6ZQhoNdq+QTxAZ6/A1fP2M=; b=HKx5wDAgF8B/w0mn0Njh72gptgWNYNGKv/kaRn6i/c9q5PSL2g8o5F974hf31DMm41 xw67mhwzsfc5ac5FUINUiWYoqUaD3/2IHSJZz/2loUy44UyiAPgZM8H+93esMJbuM0VX H86vNuYHpxXS+qTBiT6yuhCw2vmYvx76JvSuehKe5mhtI2U17D5DMONbRbMn8N0s8ThG JrMg3vpsquLwVc7QYmEedE6mXjflZnGSFaz3La+F4URLt5Odn/h7X5qoWVg09rI9ZdF/ blrhzC2KYmav4hS7w+qddWs99IfLC7GQg0gYFvu9h6NpXovlrnpfFNsFW2B0sX2ier7M Lh7w== X-Gm-Message-State: AOAM531bkw1w9LxQZLpgFLnNJ0Yf4hMfz19Dun5WHT6XfwfbvGDqzFGD XrL2l/3m4YcrMED/Kjo7L74re3sRl/pT6rwVUHlB0A== X-Received: by 2002:a81:1516:0:b0:2d0:e7ca:2a5 with SMTP id 22-20020a811516000000b002d0e7ca02a5mr2946109ywv.55.1645110804769; Thu, 17 Feb 2022 07:13:24 -0800 (PST) MIME-Version: 1.0 References: <20220217140441.1218045-1-andrzej.hajda@intel.com> <20220217140441.1218045-6-andrzej.hajda@intel.com> In-Reply-To: <20220217140441.1218045-6-andrzej.hajda@intel.com> From: Eric Dumazet Date: Thu, 17 Feb 2022 07:13:13 -0800 Message-ID: Subject: Re: [PATCH 5/9] lib/ref_tracker: improve allocation flags To: Andrzej Hajda Cc: LKML , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev , Jani Nikula , Daniel Vetter , Lucas De Marchi , Chris Wilson , Dmitry Vyukov , Jakub Kicinski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 17, 2022 at 6:05 AM Andrzej Hajda wrote: > > Library can be called in non-sleeping context, so it should not use > __GFP_NOFAIL. Instead it should calmly handle allocation fails, for > this __GFP_NOWARN has been added as well. Your commit changelog is misleading . The GFP_NOFAIL issue has been fixed already in commit c12837d1bb31032bead9060dec99ef310d5b9fb7 ("ref_tracker: use __GFP_NOFAIL more carefully") > > Signed-off-by: Andrzej Hajda > --- > lib/ref_tracker.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c > index 7b00bca300043..c8441ffbb058a 100644 > --- a/lib/ref_tracker.c > +++ b/lib/ref_tracker.c > @@ -59,7 +59,7 @@ __ref_tracker_dir_pr_ostream(struct ref_tracker_dir *dir, > if (list_empty(&dir->list)) > return; > > - sbuf = kmalloc(STACK_BUF_SIZE, GFP_NOWAIT); > + sbuf = kmalloc(STACK_BUF_SIZE, GFP_NOWAIT | __GFP_NOWARN); This belongs to patch 3 in your series. > > list_for_each_entry(tracker, &dir->list, head) > ++total; > @@ -154,11 +154,11 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir, > unsigned long entries[REF_TRACKER_STACK_ENTRIES]; > struct ref_tracker *tracker; > unsigned int nr_entries; > - gfp_t gfp_mask = gfp; Simply change this line to : gfp_t gfp_mask = gfp | __GFP_NOFAIL; > + gfp_t gfp_mask; > unsigned long flags; > Then leave all this code as is ? I find current code more readable. > - if (gfp & __GFP_DIRECT_RECLAIM) > - gfp_mask |= __GFP_NOFAIL; > + gfp |= __GFP_NOWARN; > + gfp_mask = (gfp & __GFP_DIRECT_RECLAIM) ? (gfp | __GFP_NOFAIL) : gfp; > *trackerp = tracker = kzalloc(sizeof(*tracker), gfp_mask); > if (unlikely(!tracker)) { > pr_err_once("memory allocation failure, unreliable refcount tracker.\n"); > @@ -191,7 +191,8 @@ int ref_tracker_free(struct ref_tracker_dir *dir, > } > nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1); > nr_entries = filter_irq_stacks(entries, nr_entries); lib/ref_tracker.c got patches in net-next, your patch series is going to add conflicts. git log --oneline 5740d0689096..4d449bdc5b26 --no-merges -- lib/ref_tracker.c c2d1e3df4af59261777b39c2e47476acd4d1cbeb ref_tracker: remove filter_irq_stacks() call 8fd5522f44dcd7f05454ddc4f16d0f821b676cd9 ref_tracker: add a count of untracked references e3ececfe668facd87d920b608349a32607060e66 ref_tracker: implement use-after-free detection > - stack_handle = stack_depot_save(entries, nr_entries, GFP_ATOMIC); > + stack_handle = stack_depot_save(entries, nr_entries, > + GFP_NOWAIT | __GFP_NOWARN); This is fine. > > spin_lock_irqsave(&dir->lock, flags); > if (tracker->dead) { > -- > 2.25.1 >