Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4362045pxb; Mon, 21 Feb 2022 19:07:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzF0HCIasS5wuDLpMtRl9H8Ia0HfLSNf5SzMsRGLtNUIF2/aUuKQO8wTKkH1Z868TVtEF+5 X-Received: by 2002:a17:903:22ce:b0:14f:5be1:e01c with SMTP id y14-20020a17090322ce00b0014f5be1e01cmr20789659plg.127.1645499260689; Mon, 21 Feb 2022 19:07:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645499260; cv=none; d=google.com; s=arc-20160816; b=fBdqiCK5CjWL0R1hqh+TJossEbdr6pcatUrY8yqCw4x9/QxEgntChwIRqFaf/tr2Ob sc35UOhM05c0O8NSnwoTPwihtiu6N8szfcuV7YcsAn3CrLAfIioFVMqy3F3laXCW5akv ZMUCuOxX5hSHHGNEoiI3Z8gg9t3srcf/F0HPCqPDySecPK1P5mMPwLPDYMNgIMg9vGyv bpa2QyKPeH4AxETOQ85D46aaI02gxkbzij/BqLYU/shWLSX+gHXeAgGgNvpBtxJCUHlj +G3FqasaKwz08+ydoEEXRILMBJDOht2HtJyugiAd/gbjlgfWUp8RVoApZgYkTkZBUOV4 u9iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Oqp/sS+VePx++0m73dNBiUCcut71ZyRCKu37YgHkcsQ=; b=Ni/q/opi8nbjyZu0LleiMXEP5UVVdTI0DF1EXSQmBBMji/6O8Aw8JwfQqGPdv58Qx/ UT3B2Lc+t7zIQ9WaV/2uGcz2DdSaPuBe9YQm7AMwE80oTkO/pwvKeX8aoxXjx/8brdxm VpbqGw6TyLbbRSy7S8mQZTiVCPqxxw7KJwxdS0nUbnJPYUW3rErFmVKMYfwqVX6CQNvV yoN5LcEmFhzEHmWYmcqQzHgsT+3hihij47uKtfg6JIxoSAL0bsNKnHwGZqRjRaHHCPpc EKmZCnv2PPmZ1uS45zrMTu+zu5Xr51ZSECNQSfGqq5UWAJCkYS18dPqoSszTonHIXoZZ f/BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gmmZK8ab; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 123si18856820pgb.239.2022.02.21.19.07.24; Mon, 21 Feb 2022 19:07:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gmmZK8ab; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236226AbiBUXSJ (ORCPT + 99 others); Mon, 21 Feb 2022 18:18:09 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236051AbiBUXSB (ORCPT ); Mon, 21 Feb 2022 18:18:01 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865C8245AD; Mon, 21 Feb 2022 15:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645485457; x=1677021457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hxxx7U/IhkSHLnB5PbYul9lg1GjO2Izf/ptB46o3iFI=; b=gmmZK8abjwwCvc5LvvB8sjTAnReXC0LHRqiXqjpUyFZgiX9oNWSQAeR8 hj13Up6cC2NugLzumx0ljHXsbnPKH12V0VcBWhNuW6hEVPj6BSTZICK4M UQO2vg+cgXmD5jAgQP3t0JpLzi6e4USVn3KxasPmVuv3b+4wCHT8dryXZ 7bKF34IhHoMop/ys114yeAH7vyXEiCUf9sy0p8iQFHLzDO3JE1M2XBZmc zwW4Txutssw83vePN/3eD/RxWH9iF+UgjFmg3bBYugf3TG30BJe9NBVDO ExXel8rbItnnXVqYyzIqqsJ4EVH7SpfdFUKMZpWHRGIrfP85rP2wFvulK A==; X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="251530383" X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="251530383" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 15:17:37 -0800 X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="638694418" Received: from lab-ah.igk.intel.com ([10.91.215.196]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 15:17:34 -0800 From: Andrzej Hajda To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev Cc: Eric Dumazet , Jani Nikula , Daniel Vetter , Lucas De Marchi , Andrzej Hajda , Chris Wilson , Dmitry Vyukov , Jakub Kicinski , "David S . Miller" Subject: [PATCH v2 02/11] ref_tracker: add a count of untracked references Date: Tue, 22 Feb 2022 00:16:48 +0100 Message-Id: <20220221231705.1481059-7-andrzej.hajda@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221231705.1481059-1-andrzej.hajda@intel.com> References: <20220221231705.1481059-1-andrzej.hajda@intel.com> MIME-Version: 1.0 Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Eric Dumazet We are still chasing a netdev refcount imbalance, and we suspect we have one rogue dev_put() that is consuming a reference taken from a dev_hold_track() To detect this case, allow ref_tracker_alloc() and ref_tracker_free() to be called with a NULL @trackerp parameter, and use a dedicated refcount_t just for them. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Andrzej Hajda --- include/linux/ref_tracker.h | 2 ++ lib/ref_tracker.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h index a443abda937d8..9ca353ab712b5 100644 --- a/include/linux/ref_tracker.h +++ b/include/linux/ref_tracker.h @@ -13,6 +13,7 @@ struct ref_tracker_dir { spinlock_t lock; unsigned int quarantine_avail; refcount_t untracked; + refcount_t no_tracker; bool dead; struct list_head list; /* List of active trackers */ struct list_head quarantine; /* List of dead trackers */ @@ -29,6 +30,7 @@ static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir, dir->quarantine_avail = quarantine_count; dir->dead = false; refcount_set(&dir->untracked, 1); + refcount_set(&dir->no_tracker, 1); stack_depot_init(); } diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c index 32ff6bd497f8e..9c0c2e09df666 100644 --- a/lib/ref_tracker.c +++ b/lib/ref_tracker.c @@ -38,6 +38,7 @@ void ref_tracker_dir_exit(struct ref_tracker_dir *dir) spin_unlock_irqrestore(&dir->lock, flags); WARN_ON_ONCE(leak); WARN_ON_ONCE(refcount_read(&dir->untracked) != 1); + WARN_ON_ONCE(refcount_read(&dir->no_tracker) != 1); } EXPORT_SYMBOL(ref_tracker_dir_exit); @@ -75,6 +76,10 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir, WARN_ON_ONCE(dir->dead); + if (!trackerp) { + refcount_inc(&dir->no_tracker); + return 0; + } if (gfp & __GFP_DIRECT_RECLAIM) gfp_mask |= __GFP_NOFAIL; *trackerp = tracker = kzalloc(sizeof(*tracker), gfp_mask); @@ -98,13 +103,18 @@ int ref_tracker_free(struct ref_tracker_dir *dir, struct ref_tracker **trackerp) { unsigned long entries[REF_TRACKER_STACK_ENTRIES]; - struct ref_tracker *tracker = *trackerp; depot_stack_handle_t stack_handle; + struct ref_tracker *tracker; unsigned int nr_entries; unsigned long flags; WARN_ON_ONCE(dir->dead); + if (!trackerp) { + refcount_dec(&dir->no_tracker); + return 0; + } + tracker = *trackerp; if (!tracker) { refcount_dec(&dir->untracked); return -EEXIST; -- 2.25.1