Skip to contentSkip to conversation

rcu_do_batch: rcu_data->qlen is not irq safe

PATCH In review Oleg Nesterov 2 participants 5 messages Sep 10, 2006

lore
Share & tools
lore
#0 lore raw

rcu_do_batch() decrements rdp->qlen with irqs enabled. This is not good, it can also be modified by call_rcu() from interrupt.

So, is it worth fixing? The problem is mostly theoretical.

If yes, is it ok to use local_t ? Iirc, the were some problems with local_t on some arches. Sometimes it is just atomic_t ...

Otherwise, we can update ->qlen after the main loop,

	local_irq_disable();
	rdp->qlen -= count;
	local_irq_enable();

What dou you think?

Oleg.

#1 lore raw
Quoted 5 lines · Oleg Nesterov

rcu_do_batch() decrements rdp->qlen with irqs enabled. This is not good, it can also be modified by call_rcu() from interrupt.

So, is it worth fixing? The problem is mostly theoretical.

I think we should fix it even though the problem is theoritical.

Quoted 3 lines

If yes, is it ok to use local_t ? Iirc, the were some problems with local_t on some arches. Sometimes it is just atomic_t ...

AFAIK, x86 local_t is atomic. Not good.

Quoted 8 lines

Otherwise, we can update ->qlen after the main loop,

	local_irq_disable();
	rdp->qlen -= count;
	local_irq_enable();

What dou you think?

We should do this.

Thanks
Dipankar

#3 lore raw

PATCH 1/1 rcu_do_batch: make ->qlen decrement irq safe

In reply to Dipankar Sarma

rcu_do_batch() decrements rdp->qlen with irqs enabled. This is not good, it can also be modified by call_rcu() from interrupt.

Decrement ->qlen once with irqs disabled, after a main loop.

kernel/rcupdate.c renamed from kernel/rcupdate.c~ +5 -1
@@ -241,12 +241,16 @@ static void rcu_do_batch(struct rcu_data
 		next = rdp->donelist = list->next;
 		list->func(list);
 		list = next;
-		rdp->qlen--;
 		if (++count >= rdp->blimit)
 			break;
 	}
+
+	local_irq_disable();
+	rdp->qlen -= count;
+	local_irq_enable();
 	if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark)
 		rdp->blimit = blimit;
+
 	if (!rdp->donelist)
 		rdp->donetail = &rdp->donelist;
 	else
#4 lore raw

Re: [PATCH] rcu_do_batch: make ->qlen decrement irq safe

Quoted 17 lines · Oleg Nesterov

rcu_do_batch() decrements rdp->qlen with irqs enabled. This is not good, it can also be modified by call_rcu() from interrupt.

Decrement ->qlen once with irqs disabled, after a main loop.

kernel/rcupdate.c renamed from kernel/rcupdate.c~ +0 -1
@@ -241,12 +241,16 @@ static void rcu_do_batch(struct rcu_data
 		next = rdp->donelist = list->next;
 		list->func(list);
 		list = next;
-		rdp->qlen--;
 		if (++count >= rdp->blimit)
 			break;
 	}

kernel/rcupdate.c static void rcu_do_batch(struct rcu_data · line 256

Quoted 10 lines
kernel/rcupdate.c renamed from kernel/rcupdate.c~ +5 -0
+
+	local_irq_disable();
+	rdp->qlen -= count;
+	local_irq_enable();
 	if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark)
 		rdp->blimit = blimit;
+
 	if (!rdp->donelist)
 		rdp->donetail = &rdp->donelist;
 	else

Looks good to me.

Thanks
Dipankar