Skip to content

Commit 446044e

Browse files
joelagnelpaulmckrcu
authored andcommitted
rcu/tree: Make debug_objects logic independent of rcu_head
kfree_rcu()'s debug_objects logic uses the address of the object's embedded rcu_head to queue/unqueue. Instead of this, make use of the object's address itself as preparation for future headless kfree_rcu() support. Reviewed-by: Uladzislau Rezki <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Signed-off-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 594aa59 commit 446044e

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

kernel/rcu/tree.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,13 +2970,11 @@ EXPORT_SYMBOL_GPL(call_rcu);
29702970
* @nr_records: Number of active pointers in the array
29712971
* @records: Array of the kfree_rcu() pointers
29722972
* @next: Next bulk object in the block chain
2973-
* @head_free_debug: For debug, when CONFIG_DEBUG_OBJECTS_RCU_HEAD is set
29742973
*/
29752974
struct kfree_rcu_bulk_data {
29762975
unsigned long nr_records;
29772976
void *records[KFREE_BULK_MAX_ENTR];
29782977
struct kfree_rcu_bulk_data *next;
2979-
struct rcu_head *head_free_debug;
29802978
};
29812979

29822980
/**
@@ -3026,11 +3024,13 @@ struct kfree_rcu_cpu {
30263024
static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc);
30273025

30283026
static __always_inline void
3029-
debug_rcu_head_unqueue_bulk(struct rcu_head *head)
3027+
debug_rcu_bhead_unqueue(struct kfree_rcu_bulk_data *bhead)
30303028
{
30313029
#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
3032-
for (; head; head = head->next)
3033-
debug_rcu_head_unqueue(head);
3030+
int i;
3031+
3032+
for (i = 0; i < bhead->nr_records; i++)
3033+
debug_rcu_head_unqueue((struct rcu_head *)(bhead->records[i]));
30343034
#endif
30353035
}
30363036

@@ -3060,7 +3060,7 @@ static void kfree_rcu_work(struct work_struct *work)
30603060
for (; bhead; bhead = bnext) {
30613061
bnext = bhead->next;
30623062

3063-
debug_rcu_head_unqueue_bulk(bhead->head_free_debug);
3063+
debug_rcu_bhead_unqueue(bhead);
30643064

30653065
rcu_lock_acquire(&rcu_callback_map);
30663066
trace_rcu_invoke_kfree_bulk_callback(rcu_state.name,
@@ -3082,14 +3082,15 @@ static void kfree_rcu_work(struct work_struct *work)
30823082
*/
30833083
for (; head; head = next) {
30843084
unsigned long offset = (unsigned long)head->func;
3085+
void *ptr = (void *)head - offset;
30853086

30863087
next = head->next;
3087-
debug_rcu_head_unqueue(head);
3088+
debug_rcu_head_unqueue((struct rcu_head *)ptr);
30883089
rcu_lock_acquire(&rcu_callback_map);
30893090
trace_rcu_invoke_kfree_callback(rcu_state.name, head, offset);
30903091

30913092
if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset)))
3092-
kfree((void *)head - offset);
3093+
kfree(ptr);
30933094

30943095
rcu_lock_release(&rcu_callback_map);
30953096
cond_resched_tasks_rcu_qs();
@@ -3228,18 +3229,11 @@ kfree_call_rcu_add_ptr_to_bulk(struct kfree_rcu_cpu *krcp,
32283229
/* Initialize the new block. */
32293230
bnode->nr_records = 0;
32303231
bnode->next = krcp->bhead;
3231-
bnode->head_free_debug = NULL;
32323232

32333233
/* Attach it to the head. */
32343234
krcp->bhead = bnode;
32353235
}
32363236

3237-
#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
3238-
head->func = func;
3239-
head->next = krcp->bhead->head_free_debug;
3240-
krcp->bhead->head_free_debug = head;
3241-
#endif
3242-
32433237
/* Finally insert. */
32443238
krcp->bhead->records[krcp->bhead->nr_records++] =
32453239
(void *) head - (unsigned long) func;
@@ -3263,14 +3257,17 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
32633257
{
32643258
unsigned long flags;
32653259
struct kfree_rcu_cpu *krcp;
3260+
void *ptr;
32663261

32673262
local_irq_save(flags); // For safely calling this_cpu_ptr().
32683263
krcp = this_cpu_ptr(&krc);
32693264
if (krcp->initialized)
32703265
raw_spin_lock(&krcp->lock);
32713266

3267+
ptr = (void *)head - (unsigned long)func;
3268+
32723269
// Queue the object but don't yet schedule the batch.
3273-
if (debug_rcu_head_queue(head)) {
3270+
if (debug_rcu_head_queue(ptr)) {
32743271
// Probable double kfree_rcu(), just leak.
32753272
WARN_ONCE(1, "%s(): Double-freed call. rcu_head %p\n",
32763273
__func__, head);

0 commit comments

Comments
 (0)