HomeFreeBSD

Add ifa_try_ref() to simplify ifa handling inside epoch.

Description

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)

Details

Provenance
melifaroAuthored on Feb 16 2021, 8:12 PM
Reviewer
rstone
Differential Revision
D28639: Add ifa_try_ref() to simplify ifa handling inside epoch.
Parents
rGf67641675958: Make in_localip_more() fib-aware.
Branches
Unknown
Tags
Unknown