]> www.infradead.org Git - linux.git/commit
net/sched: cls_u32: replace int refcounts with proper refcounts
authorPedro Tammela <pctammela@mojatatu.com>
Tue, 14 Nov 2023 14:18:55 +0000 (11:18 -0300)
committerJakub Kicinski <kuba@kernel.org>
Sun, 19 Nov 2023 03:38:23 +0000 (19:38 -0800)
commit6b78debe1c07e6aa3c91ca0b1384bf3cb8217c50
treec35ee85ebbd366fa6de7906dd9fee462393ca826
parent289354f21b2c3fac93e956efd45f256a88a4d997
net/sched: cls_u32: replace int refcounts with proper refcounts

Proper refcounts will always warn splat when something goes wrong,
be it underflow, saturation or object resurrection. As these are always
a source of bugs, use it in cls_u32 as a safeguard to prevent/catch issues.
Another benefit is that the refcount API self documents the code, making
clear when transitions to dead are expected.

For such an update we had to make minor adaptations on u32 to fit the refcount
API. First we set explicitly to '1' when objects are created, then the
objects are alive until a 1 -> 0 happens, which is then released appropriately.

The above made clear some redundant operations in the u32 code
around the root_ht handling that were removed. The root_ht is created
with a refcnt set to 1. Then when it's associated with tcf_proto it increments the refcnt to 2.
Throughout the entire code the root_ht is an exceptional case and can never be referenced,
therefore the refcnt never incremented/decremented.
Its lifetime is always bound to tcf_proto, meaning if you delete tcf_proto
the root_ht is deleted as well. The code made up for the fact that root_ht refcnt is 2 and did
a double decrement to free it, which is not a fit for the refcount API.

Even though refcount_t is implemented using atomics, we should observe
a negligible control plane impact.

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20231114141856.974326-2-pctammela@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sched/cls_u32.c