Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4446229pxb; Mon, 21 Feb 2022 21:53:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJysGqO5wDhn9LcijRUvIN1Da5cBs7mGEkTexU/GmIOP0BhPbIjQRRy8Kp6IOEega1s2O6gl X-Received: by 2002:a17:902:8c84:b0:14e:e827:a6f0 with SMTP id t4-20020a1709028c8400b0014ee827a6f0mr21562299plo.82.1645509206225; Mon, 21 Feb 2022 21:53:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645509206; cv=none; d=google.com; s=arc-20160816; b=RnJ9aCpn23dKSVlajNZ+sJBVkB3gXWPGLKcIW//nKJSAFOx98c+CA6sswwgHDzHrtj Yse8anes+b9xepevgIctJJFqejvcqtG7qvpTlJBftnuFUiLMj0FclbnOp1iBIp/d00Lm 9lWI1q92dy1QA70s1QWweEvtJYdNzFCCUb+/EUxG3XBzmf3szGPd04qjOX9aR0GqG1AR vazmbIGgX728SFsOMHpwn0dk7m8ONDBu6oAXLsCrgRO6jAk5iWN+q8c9BR0lL3jXSzyu 6FfjBElxBQsp5UjlNVbEnKjZioThCAfrkcoYfaC6EYQ7Pq5KVmdaDohfd3dx7ne1eQyU iHbw== 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=Q8jlPWyu/Y9Harb7auTt3tEkuyCE9LKN33aCPH0Om3vaAB8mqS8EnbPHB+ykGHXwkl P49YePnUMEEZ0TRR+EmZCfjsbxGCx7/nGns0logC+BbJ3XNWuZ3L3dKdj8QTJxBsERBd jQB/clD0akPPh/tEAEnFPir+O9kTIIc/bM6pApXFbOx6swyHR+rUDRHcQ/P91eLm0ojB Z34pqGDaQ/y0dbBAsub6CShl1Qp6YVFzsK3rGxdOUgKzc7P2c+KyjIl1ZPr7zXiwRToW Ggg5P5ezA7z1QORL15Y5SmSpiTCmW9aCp1pWZPuxXwA/+SVUingmzHDGPLlgC0c+Xmt+ AJgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cto2hUqZ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l63si19262437pge.296.2022.02.21.21.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:53:26 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cto2hUqZ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EAB02E98F8; Mon, 21 Feb 2022 21:16:21 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236120AbiBUXSC (ORCPT + 99 others); Mon, 21 Feb 2022 18:18:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:32962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236064AbiBUXRy (ORCPT ); Mon, 21 Feb 2022 18:17:54 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C8F9245B2; Mon, 21 Feb 2022 15:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645485450; x=1677021450; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hxxx7U/IhkSHLnB5PbYul9lg1GjO2Izf/ptB46o3iFI=; b=Cto2hUqZmmwrZaR2suOPcFb0xcxSyoyJXQ7O2RQ5rytqnxmAxpHmhcw2 5GZSDCxNq8+WzGkn1YViF6+hlaHSySRmdpGC0K31EsU70cnk8hEjAy7Ch qMBWbbmOk9dRstc2CKpbG5nDDZ4XGBJEzHsYItVFHcmX0686x8fqsvJ2h gwPwXNjcrtZ7DGASfmkhhVcwDCXIUXwzZ47ZjW+A7U1eWerUcdmq5DNI1 bjmT7HV+U9LFLgosqKtnDEGyFk1tIHnfoi5croLk3JAeuXCKaXx54Pae8 OdTc91oE6+INiJmmmgy+8Hm/Q2lKijnNnw2OG0694CvF52Qe6xQyClw5u g==; X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="251530348" X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="251530348" 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:30 -0800 X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="638694383" 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:27 -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] [DO NOT MERGE] ref_tracker: add a count of untracked references Date: Tue, 22 Feb 2022 00:16:46 +0100 Message-Id: <20220221231705.1481059-5-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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 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