On Tue, Aug 26, 2025 at 2:32 AM Vlastimil Babka <vba...@suse.cz> wrote: > > On 8/22/25 18:28, Suren Baghdasaryan wrote: > >> diff --git a/tools/testing/shared/linux/rcupdate.h > >> b/tools/testing/shared/linux/rcupdate.h > >> index > >> fed468fb0c78db6f33fb1900c7110ab5f3c19c65..c95e2f0bbd93798e544d7d34e0823ed68414f924 > >> 100644 > >> --- a/tools/testing/shared/linux/rcupdate.h > >> +++ b/tools/testing/shared/linux/rcupdate.h > >> @@ -9,4 +9,26 @@ > >> #define rcu_dereference_check(p, cond) rcu_dereference(p) > >> #define RCU_INIT_POINTER(p, v) do { (p) = (v); } while (0) > >> > >> +void kmem_cache_free_active(void *objp); > >> +static unsigned long kfree_cb_offset = 0; > >> + > >> +static inline void kfree_rcu_cb(struct rcu_head *head) > >> +{ > >> + void *objp = (void *) ((unsigned long)head - kfree_cb_offset); > >> + > >> + kmem_cache_free_active(objp); > >> +} > >> + > >> +#ifndef offsetof > >> +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) > >> +#endif > >> + > > > > We need a comment here that concurrent kfree_rcu() calls are not > > supported because they would override each other's kfree_cb_offset. > > I think it's a bit more complex and related to the commit log sentence "This > only works with one kmem_cache, and only the first one used.". The first > call to kfree_rcu sets kfree_cb_offset (but what if the rhv offset is > actually 0?) so the others won't update it. So concurrent calls will work as > far as from the same cache thus same offset. But I'd like Liam's > confirmation and the comment text, if possible :) > > > Kinda obvious but I think unusual limitations should be explicitly > > called out. > > > >> +#define kfree_rcu(ptr, rhv) \ > >> +do { \ > >> + if (!kfree_cb_offset) \ > >> + kfree_cb_offset = offsetof(typeof(*(ptr)), rhv); \ > >> + \ > >> + call_rcu(&ptr->rhv, kfree_rcu_cb); \ > >> +} while (0) > > > > Any specific reason kfree_rcu() is a macro and not a static inline function? > > Think it's needed for the typeof() to work. The kernel's kfree_rcu() is > similar in this aspect.
Ah, got it. Thanks! > > >> + > >> #endif > >> > >> -- > >> 2.50.1 > >> >