]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Add ifa_try_ref() to simplify ifa handling inside epoch.
authorAlexander V. Chernikov <melifaro@FreeBSD.org>
Tue, 16 Feb 2021 20:12:58 +0000 (20:12 +0000)
committerAlexander V. Chernikov <melifaro@FreeBSD.org>
Tue, 16 Feb 2021 20:14:50 +0000 (20:14 +0000)
commit600eade2fb4faacfcd408a01140ef15f85f0c817
treed408a46c62b12fff4c4612a42007643accf91d79
parent9fdbf7eef5c006002769add15b1ebb8fa8d9e220
Add ifa_try_ref() to simplify ifa handling inside epoch.

More and more code migrates from lock-based protection to the NET_EPOCH
 umbrella. It requires some logic changes, including, notably, refcount
 handling.

When we have an `ifa` pointer and we're running inside epoch we're
 guaranteed that this pointer will not be freed.
However, the following case can still happen:
 * in thread 1 we drop to 0 refcount for ifa and schedule its deletion.
 * in thread 2 we use this ifa and reference it
 * destroy callout kicks in
 * unhappy user reports bug

To address it, new `ifa_try_ref()` function is added, allowing to return
 failure when we try to reference `ifa` with 0 refcount.
Additionally, existing `ifa_ref()` is enforced with `KASSERT` to provide
 cleaner error in such scenarious.

Reviewed By: rstone, donner
Differential Revision: https://reviews.freebsd.org/D28639
MFC after: 1 week
sys/net/if.c
sys/net/if_var.h