@@ -1025,12 +1025,6 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
10251025#define RCU_POINTER_INITIALIZER (p , v ) \
10261026 .p = RCU_INITIALIZER(v)
10271027
1028- /*
1029- * Does the specified offset indicate that the corresponding rcu_head
1030- * structure can be handled by kvfree_rcu()?
1031- */
1032- #define __is_kvfree_rcu_offset (offset ) ((offset) < 4096)
1033-
10341028/**
10351029 * kfree_rcu() - kfree an object after a grace period.
10361030 * @ptr: pointer to kfree for double-argument invocations.
@@ -1041,11 +1035,11 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
10411035 * when they are used in a kernel module, that module must invoke the
10421036 * high-latency rcu_barrier() function at module-unload time.
10431037 *
1044- * The kfree_rcu() function handles this issue. Rather than encoding a
1045- * function address in the embedded rcu_head structure, kfree_rcu() instead
1046- * encodes the offset of the rcu_head structure within the base structure.
1047- * Because the functions are not allowed in the low-order 4096 bytes of
1048- * kernel virtual memory, offsets up to 4095 bytes can be accommodated.
1038+ * The kfree_rcu() function handles this issue. In order to have a universal
1039+ * callback function handling different offsets of rcu_head, the callback needs
1040+ * to determine the starting address of the freed object, which can be a large
1041+ * kmalloc or vmalloc allocation. To allow simply aligning the pointer down to
1042+ * page boundary for those, only offsets up to 4095 bytes can be accommodated.
10491043 * If the offset is larger than 4095 bytes, a compile-time error will
10501044 * be generated in kvfree_rcu_arg_2(). If this error is triggered, you can
10511045 * either fall back to use of call_rcu() or rearrange the structure to
@@ -1082,14 +1076,23 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
10821076#define kfree_rcu_mightsleep (ptr ) kvfree_rcu_arg_1(ptr)
10831077#define kvfree_rcu_mightsleep (ptr ) kvfree_rcu_arg_1(ptr)
10841078
1079+ /*
1080+ * In mm/slab_common.c, no suitable header to include here.
1081+ */
1082+ void kvfree_call_rcu (struct rcu_head * head , void * ptr );
1083+
1084+ /*
1085+ * The BUILD_BUG_ON() makes sure the rcu_head offset can be handled. See the
1086+ * comment of kfree_rcu() for details.
1087+ */
10851088#define kvfree_rcu_arg_2 (ptr , rhf ) \
10861089do { \
10871090 typeof (ptr) ___p = (ptr); \
10881091 \
1089- if (___p) { \
1090- BUILD_BUG_ON(!__is_kvfree_rcu_offset( offsetof(typeof(*(ptr)), rhf)) ); \
1091- kvfree_call_rcu(&((___p)->rhf), (void *) (___p)); \
1092- } \
1092+ if (___p) { \
1093+ BUILD_BUG_ON(offsetof(typeof(*(ptr)), rhf) >= 4096 ); \
1094+ kvfree_call_rcu(&((___p)->rhf), (void *) (___p)); \
1095+ } \
10931096} while (0)
10941097
10951098#define kvfree_rcu_arg_1 (ptr ) \
0 commit comments