4747extern int rcutorture_runnable ; /* for sysctl */
4848#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
4949
50+ #if defined(CONFIG_TREE_RCU ) || defined(CONFIG_TREE_PREEMPT_RCU )
51+ extern void rcutorture_record_test_transition (void );
52+ extern void rcutorture_record_progress (unsigned long vernum );
53+ #else
54+ static inline void rcutorture_record_test_transition (void )
55+ {
56+ }
57+ static inline void rcutorture_record_progress (unsigned long vernum )
58+ {
59+ }
60+ #endif
61+
5062#define UINT_CMP_GE (a , b ) (UINT_MAX / 2 >= (a) - (b))
5163#define UINT_CMP_LT (a , b ) (UINT_MAX / 2 < (a) - (b))
5264#define ULONG_CMP_GE (a , b ) (ULONG_MAX / 2 >= (a) - (b))
@@ -68,7 +80,6 @@ extern void call_rcu_sched(struct rcu_head *head,
6880extern void synchronize_sched (void );
6981extern void rcu_barrier_bh (void );
7082extern void rcu_barrier_sched (void );
71- extern int sched_expedited_torture_stats (char * page );
7283
7384static inline void __rcu_read_lock_bh (void )
7485{
@@ -774,6 +785,7 @@ extern struct debug_obj_descr rcuhead_debug_descr;
774785
775786static inline void debug_rcu_head_queue (struct rcu_head * head )
776787{
788+ WARN_ON_ONCE ((unsigned long )head & 0x3 );
777789 debug_object_activate (head , & rcuhead_debug_descr );
778790 debug_object_active_state (head , & rcuhead_debug_descr ,
779791 STATE_RCU_HEAD_READY ,
@@ -797,4 +809,60 @@ static inline void debug_rcu_head_unqueue(struct rcu_head *head)
797809}
798810#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
799811
812+ static __always_inline bool __is_kfree_rcu_offset (unsigned long offset )
813+ {
814+ return offset < 4096 ;
815+ }
816+
817+ static __always_inline
818+ void __kfree_rcu (struct rcu_head * head , unsigned long offset )
819+ {
820+ typedef void (* rcu_callback )(struct rcu_head * );
821+
822+ BUILD_BUG_ON (!__builtin_constant_p (offset ));
823+
824+ /* See the kfree_rcu() header comment. */
825+ BUILD_BUG_ON (!__is_kfree_rcu_offset (offset ));
826+
827+ call_rcu (head , (rcu_callback )offset );
828+ }
829+
830+ extern void kfree (const void * );
831+
832+ static inline void __rcu_reclaim (struct rcu_head * head )
833+ {
834+ unsigned long offset = (unsigned long )head -> func ;
835+
836+ if (__is_kfree_rcu_offset (offset ))
837+ kfree ((void * )head - offset );
838+ else
839+ head -> func (head );
840+ }
841+
842+ /**
843+ * kfree_rcu() - kfree an object after a grace period.
844+ * @ptr: pointer to kfree
845+ * @rcu_head: the name of the struct rcu_head within the type of @ptr.
846+ *
847+ * Many rcu callbacks functions just call kfree() on the base structure.
848+ * These functions are trivial, but their size adds up, and furthermore
849+ * when they are used in a kernel module, that module must invoke the
850+ * high-latency rcu_barrier() function at module-unload time.
851+ *
852+ * The kfree_rcu() function handles this issue. Rather than encoding a
853+ * function address in the embedded rcu_head structure, kfree_rcu() instead
854+ * encodes the offset of the rcu_head structure within the base structure.
855+ * Because the functions are not allowed in the low-order 4096 bytes of
856+ * kernel virtual memory, offsets up to 4095 bytes can be accommodated.
857+ * If the offset is larger than 4095 bytes, a compile-time error will
858+ * be generated in __kfree_rcu(). If this error is triggered, you can
859+ * either fall back to use of call_rcu() or rearrange the structure to
860+ * position the rcu_head structure into the first 4096 bytes.
861+ *
862+ * Note that the allowable offset might decrease in the future, for example,
863+ * to allow something like kmem_cache_free_rcu().
864+ */
865+ #define kfree_rcu (ptr , rcu_head ) \
866+ __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
867+
800868#endif /* __LINUX_RCUPDATE_H */
0 commit comments