Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rcuref: Provide rcuref_is_dead()

rcuref_read() returns the number of references that are currently held.
If 0 is returned then it is not safe to assume that the object ca be
scheduled for deconstruction because it is marked DEAD. This happens if
the return value of rcuref_put() is ignored and assumptions are made.

If 0 is returned then the counter transitioned from 0 to RCUREF_NOREF.
If rcuref_put() did not return to the caller then the counter did not
yet transition from RCUREF_NOREF to RCUREF_DEAD. This means that there
is still a chance that the counter will transition from RCUREF_NOREF to
0 meaning it is still valid and must not be deconstructed. In this brief
window rcuref_read() will return 0.

Provide rcuref_is_dead() to determine if the counter is marked as
RCUREF_DEAD.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250416162921.513656-2-bigeasy@linutronix.de

authored by

Sebastian Andrzej Siewior and committed by
Peter Zijlstra
3efa66ce b4432656

+21 -1
+21 -1
include/linux/rcuref.h
··· 30 30 * rcuref_read - Read the number of held reference counts of a rcuref 31 31 * @ref: Pointer to the reference count 32 32 * 33 - * Return: The number of held references (0 ... N) 33 + * Return: The number of held references (0 ... N). The value 0 does not 34 + * indicate that it is safe to schedule the object, protected by this reference 35 + * counter, for deconstruction. 36 + * If you want to know if the reference counter has been marked DEAD (as 37 + * signaled by rcuref_put()) please use rcuread_is_dead(). 34 38 */ 35 39 static inline unsigned int rcuref_read(rcuref_t *ref) 36 40 { ··· 42 38 43 39 /* Return 0 if within the DEAD zone. */ 44 40 return c >= RCUREF_RELEASED ? 0 : c + 1; 41 + } 42 + 43 + /** 44 + * rcuref_is_dead - Check if the rcuref has been already marked dead 45 + * @ref: Pointer to the reference count 46 + * 47 + * Return: True if the object has been marked DEAD. This signals that a previous 48 + * invocation of rcuref_put() returned true on this reference counter meaning 49 + * the protected object can safely be scheduled for deconstruction. 50 + * Otherwise, returns false. 51 + */ 52 + static inline bool rcuref_is_dead(rcuref_t *ref) 53 + { 54 + unsigned int c = atomic_read(&ref->refcnt); 55 + 56 + return (c >= RCUREF_RELEASED) && (c < RCUREF_NOREF); 45 57 } 46 58 47 59 extern __must_check bool rcuref_get_slowpath(rcuref_t *ref);