Skip to contentSkip to conversation

fix refrigerator() vs thaw_process() race

PATCH In review Oleg Nesterov 3 participants 5 messages Feb 18, 2007 – Feb 20, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix refrigerator() vs thaw_process() race

refrigerator() can miss a wakeup, "wait event" loop needs a proper memory ordering.

kernel/power/process.c renamed from kernel/power/process.c~WAKE +4 -2
@@ -46,8 +46,10 @@ void refrigerator(void)
 	recalc_sigpending(); /* We sent fake signal, clean it up */
 	spin_unlock_irq(&current->sighand->siglock);
 
-	while (frozen(current)) {
-		current->state = TASK_UNINTERRUPTIBLE;
+	for (;;) {
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		if (!frozen(current))
+			break;
 		schedule();
 	}
 	pr_debug("%s left refrigerator\n", current->comm);
#1 lore raw
Quoted 4 lines · Oleg Nesterov

refrigerator() can miss a wakeup, "wait event" loop needs a proper memory ordering.

ACK

Quoted 18 lines
kernel/power/process.c renamed from kernel/power/process.c~WAKE +4 -2
@@ -46,8 +46,10 @@ void refrigerator(void)
 	recalc_sigpending(); /* We sent fake signal, clean it up */
 	spin_unlock_irq(&current->sighand->siglock);
 
-	while (frozen(current)) {
-		current->state = TASK_UNINTERRUPTIBLE;
+	for (;;) {
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		if (!frozen(current))
+			break;
 		schedule();
 	}
 	pr_debug("%s left refrigerator\n", current->comm);
Signature · 3 lines
If you don't have the time to read,
you don't have the time or the tools to write.
		- Stephen King
#2 lore raw
In reply to Oleg Nesterov

Hi!

kernel/power/process.c void refrigerator(void) · line 49

Quoted 13 lines

refrigerator() can miss a wakeup, "wait event" loop needs a proper memory ordering.

kernel/power/process.c renamed from kernel/power/process.c~WAKE +1 -1
@@ -46,8 +46,10 @@ void refrigerator(void)
 	recalc_sigpending(); /* We sent fake signal, clean it up */
 	spin_unlock_irq(&current->sighand->siglock);
 
-		current->state = TASK_UNINTERRUPTIBLE;
+		set_current_state(TASK_UNINTERRUPTIBLE);

Looks okay to me... but this one liner would be exactly as effective, right?

Pavel

Quoted 3 lines
kernel/power/process.c renamed from kernel/power/process.c~WAKE +0 -0
 		schedule();
 	}
 	pr_debug("%s left refrigerator\n", current->comm);
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw
Quoted 12 lines · Pavel Machek
Quoted 12 lines

refrigerator() can miss a wakeup, "wait event" loop needs a proper memory ordering.

kernel/power/process.c renamed from kernel/power/process.c~WAKE +0 -0
@@ -46,8 +46,10 @@ void refrigerator(void)
 	recalc_sigpending(); /* We sent fake signal, clean it up */
 	spin_unlock_irq(&current->sighand->siglock);
 
Quoted 6 lines

kernel/power/process.c void refrigerator(void) · line 50

Quoted 2 lines
kernel/power/process.c renamed from kernel/power/process.c~WAKE +1 -1
-		current->state = TASK_UNINTERRUPTIBLE;
+		set_current_state(TASK_UNINTERRUPTIBLE);

Looks okay to me... but this one liner would be exactly as effective, right?

I think no, with this one liner we have

	while (frozen(current)) {
		// ------ WINDOW ------------
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule();
	}

What if thaw_process() happens in the window above?

We need the barrier exactly because LOAD (check condition) should not come before STORE (set task->state).

Oleg.

#4 lore raw

Hi!

Quoted 26 lines
Quoted 11 lines
Quoted 11 lines

refrigerator() can miss a wakeup, "wait event" loop needs a proper memory ordering.

kernel/power/process.c renamed from kernel/power/process.c~WAKE +0 -0
@@ -46,8 +46,10 @@ void refrigerator(void)
 	recalc_sigpending(); /* We sent fake signal, clean it up */
 	spin_unlock_irq(&current->sighand->siglock);
 
Quoted 6 lines

kernel/power/process.c void refrigerator(void) · line 50

Quoted 2 lines
kernel/power/process.c renamed from kernel/power/process.c~WAKE +1 -1
-		current->state = TASK_UNINTERRUPTIBLE;
+		set_current_state(TASK_UNINTERRUPTIBLE);

Looks okay to me... but this one liner would be exactly as effective, right?

I think no, with this one liner we have

	while (frozen(current)) {
		// ------ WINDOW ------------
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule();
	}
Quoted 4 lines

What if thaw_process() happens in the window above?

We need the barrier exactly because LOAD (check condition) should not come before STORE (set task->state).

Aha, ok :-). You already have my ACK ;-).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html