Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4439640pxb; Mon, 21 Feb 2022 21:40:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqwIc6H/Z77gWWLkvT/CjSbxu7r6LK6nKM/rUiS7qCdFEqTCd8CdxIUyJlN3YVdLhUkdYf X-Received: by 2002:a17:90a:ec10:b0:1b8:9da7:3d13 with SMTP id l16-20020a17090aec1000b001b89da73d13mr2482575pjy.194.1645508409399; Mon, 21 Feb 2022 21:40:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645508409; cv=none; d=google.com; s=arc-20160816; b=QZ5ij4E13d4q4BIXJ9n1FGUhHdwzI8qpl5UP7pgxuocMpZlxi1aoxI/cPPspkW9CvO cnXnXhso/xcJpkaOZQDufXstU5xXph19TJOIvhs4QtnO7BQWa992IDPZIeoMLgRC6w96 SQJYVL+pz/bA9H3EXgUg2099i7yYCBmoiCfgWUOmZb0xfAIcpyP3Z+wawasanuQNCDKd vQXthZmCw3sqAjnw+m66a8jLvqlkVqaQOHiWwlo68KRmL1AT1szQzy0PSZmOFJVNQUpL Wq5n0BzI4z+NsQlKJiq7V1djP7G43u+EQtoK38pKDJPjj1etMy3bbbGxUG0a5/l9vm6p ZY2w== 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=FXJmw26lZpWos5r4NMSLBkAQOJ0C4lpeqJ8Gs8h8MRVlw87cqs/QyzlG3rMmufetli 7A8jGSfUaPxl5OHqRMZ+9ErABdKxMQHftAf2PdrD3CTiM4jaulI3dKtJ48rP2zzZDFOU k3dXseHqX4G1kVS7zzrwilxAfN2yBLQ5HD0b7xkid9WGnO/knbIgV5OgBLMr7ERs+vkP v053X5ygEqeYqvFtgjmI2vQAJgK+75gIYwZS6PvUyalfTP+OLymBhsL1AGVnRiu/sCiY LDYxPrLs3lOH2jtO2II81d5BQyPh6itcvDOQ4FOpUWd2rDK7Tjac63xP9A24y/Jf5rSB BqRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WweAJFQx; 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 n8-20020a17090a2bc800b001bc44833226si1154461pje.56.2022.02.21.21.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:40:09 -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=WweAJFQx; 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 B66B88F62C; Mon, 21 Feb 2022 21:06:45 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236692AbiBUX03 (ORCPT + 99 others); Mon, 21 Feb 2022 18:26:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236567AbiBUX0Z (ORCPT ); Mon, 21 Feb 2022 18:26:25 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BFFD24F0E; Mon, 21 Feb 2022 15:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645485961; x=1677021961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hxxx7U/IhkSHLnB5PbYul9lg1GjO2Izf/ptB46o3iFI=; b=WweAJFQx53Oe0D9N7rrT5CTS5g0sX9TRrR9Zvhpbhj9jdVAw6tlG6zkB zyg9vrpy8oTfJGZEqdaSFdwlB1YZ1Wc/Ue6aoycmMhnPnsH9D+pr1RhQ/ cqFb38noTAt75hXqG4nwNYT7KU1VXXCATqioj9DhE4BMvQi7WGoNl2dEm 3opFA4IydZ5QDHCe3yyME1JDWCzYSNqDM6Z4BPNQIl0Ughn0PCl9cf9TW B6x82K8DpcCldNX7oh776ZvQTsHFP3PsxmxPgqC6BEsGtJYzLV+FN1Oaa WVqAJ2pvE6YRXakJtCbhoMiytZ78/PnQYp4P1Hg4cCeXjgh2ubKVBXLFL w==; X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="338011872" X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="338011872" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 15:26:01 -0800 X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="706396982" Received: from lab-ah.igk.intel.com ([10.91.215.196]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 15:25:58 -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 v3 02/11] [DO NOT MERGE] ref_tracker: add a count of untracked references Date: Tue, 22 Feb 2022 00:25:33 +0100 Message-Id: <20220221232542.1481315-3-andrzej.hajda@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221232542.1481315-1-andrzej.hajda@intel.com> References: <20220221232542.1481315-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