ref_tracker: add a count of untracked references

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2096377

Conflicts:
- context conflict due to missing 2dba5eb1c73b ("lib/stackdepot: allow
  optional init and stack_table allocation by kvmalloc()")

commit 8fd5522f44dcd7f05454ddc4f16d0f821b676cd9
Author: Eric Dumazet <edumazet@google.com>
Date:   Fri Feb 4 14:42:36 2022 -0800

    ref_tracker: add a count of untracked references

    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 <edumazet@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
This commit is contained in:
Ivan Vecera 2022-06-13 18:39:20 +02:00
parent 5de2574985
commit 332ff16036
2 changed files with 13 additions and 1 deletions

View File

@ -12,6 +12,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 */
@ -28,6 +29,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);
}
void ref_tracker_dir_exit(struct ref_tracker_dir *dir);

View File

@ -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;