]> 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>
Wed, 10 Mar 2021 21:47:54 +0000 (21:47 +0000)
commitd9bcd8e7a2dd77969f8ac940fe8ec5e90588e3ea
tree0c2dc04a4dcae3d34dcb1d08aa30c5fcc25e93e2
parentf67641675958cb566b0ae50dc6942017d42393fe
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

(cherry picked from commit 600eade2fb4faacfcd408a01140ef15f85f0c817)
sys/net/if.c
sys/net/if_var.h