Skip to contentSkip to conversation

PM/Hibernate: Thaw kernel threads in hibernation_snapshot() in error/test path

PATCH In review Srivatsa S. Bhat 3 participants 9 messages Feb 2, 2012

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

PATCH 1/1 PM/Hibernate: Thaw kernel threads in hibernation_snapshot() in error/test path

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +4 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
+ Thaw:
+	thaw_kernel_threads();
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +2 -6
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;
 
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

Thanks. :)

Signature · 1 line
tejun
#2 lore raw
In reply to Srivatsa S. Bhat
Quoted 33 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 5 lines
kernel/power/hibernate.c +2 -0
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

Quoted 15 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -3
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 10 lines
kernel/power/user.c +1 -3
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

Thanks,
Rafael

#3 lore raw
Quoted 37 lines · Rafael J. Wysocki
Quoted 36 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
Quoted 6 lines

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 2 lines
kernel/power/hibernate.c +2 -0
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

But then what about the case (in the existing code) when freeze_kernel_threads() fails? It would first thaw kernel threads (in fact it used to thaw even userspace tasks earlier!) before calling swsusp_free(). So, the existing code itself seems to be brittle, considering the point you raised. Right?

Quoted 19 lines
Quoted 19 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -4
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
Quoted 9 lines

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 6 lines
kernel/power/user.c +1 -2
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

This was intended as a cleanup only, not a bug fix. But now, (see my point above), I am beginning to feel that the existing code itself is not robust enough...

Regards,
Srivatsa S. Bhat

#4 lore raw
Quoted 47 lines · Srivatsa S. Bhat
Quoted 37 lines · Rafael J. Wysocki
Quoted 36 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
Quoted 6 lines

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 2 lines
kernel/power/hibernate.c +2 -0
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

Quoted 5 lines

But then what about the case (in the existing code) when freeze_kernel_threads() fails? It would first thaw kernel threads (in fact it used to thaw even userspace tasks earlier!) before calling swsusp_free(). So, the existing code itself seems to be brittle, considering the point you raised. Right?

Well, that's why freeze_kernel_threads() originally hadn't tried to thaw anything and started to do that after one of the Tejun's commits (and I forgot about this particular issue back then).

Quoted 30 lines
Quoted 19 lines
Quoted 19 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -4
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
Quoted 9 lines

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 6 lines
kernel/power/user.c +1 -2
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

Quoted 3 lines

This was intended as a cleanup only, not a bug fix. But now, (see my point above), I am beginning to feel that the existing code itself is not robust enough...

Well, let's pretend that we think it is safe to thaw kernel threads before freeing memory (actually, they are frozen after the preallocation, so it really should be OK).

So I think I'll apply your patch after all.

Thanks,
Rafael

#5 lore raw
Quoted 85 lines · Rafael J. Wysocki
Quoted 45 lines · Srivatsa S. Bhat
Quoted 37 lines · Rafael J. Wysocki
Quoted 36 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
Quoted 6 lines

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 2 lines
kernel/power/hibernate.c +2 -0
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

Quoted 5 lines

But then what about the case (in the existing code) when freeze_kernel_threads() fails? It would first thaw kernel threads (in fact it used to thaw even userspace tasks earlier!) before calling swsusp_free(). So, the existing code itself seems to be brittle, considering the point you raised. Right?

Well, that's why freeze_kernel_threads() originally hadn't tried to thaw anything and started to do that after one of the Tejun's commits (and I forgot about this particular issue back then).

Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -3
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 10 lines
kernel/power/user.c +1 -3
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

Quoted 8 lines
Quoted 3 lines

This was intended as a cleanup only, not a bug fix. But now, (see my point above), I am beginning to feel that the existing code itself is not robust enough...

Well, let's pretend that we think it is safe to thaw kernel threads before freeing memory (actually, they are frozen after the preallocation, so it really should be OK).

Yeah, even I had the same reasoning in mind when writing this patch.

Quoted 2 lines

So I think I'll apply your patch after all.

:-)

Regards,

Srivatsa S. Bhat

#6 lore raw
Quoted 97 lines · Srivatsa S. Bhat
Quoted 85 lines · Rafael J. Wysocki
Quoted 45 lines · Srivatsa S. Bhat
Quoted 37 lines · Rafael J. Wysocki
Quoted 36 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
Quoted 6 lines

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 2 lines
kernel/power/hibernate.c +2 -0
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

Quoted 5 lines

But then what about the case (in the existing code) when freeze_kernel_threads() fails? It would first thaw kernel threads (in fact it used to thaw even userspace tasks earlier!) before calling swsusp_free(). So, the existing code itself seems to be brittle, considering the point you raised. Right?

Well, that's why freeze_kernel_threads() originally hadn't tried to thaw anything and started to do that after one of the Tejun's commits (and I forgot about this particular issue back then).

Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -3
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 10 lines
kernel/power/user.c +1 -3
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

Quoted 8 lines
Quoted 3 lines

This was intended as a cleanup only, not a bug fix. But now, (see my point above), I am beginning to feel that the existing code itself is not robust enough...

Well, let's pretend that we think it is safe to thaw kernel threads before freeing memory (actually, they are frozen after the preallocation, so it really should be OK).

Quoted 8 lines

Yeah, even I had the same reasoning in mind when writing this patch.

Quoted 2 lines

So I think I'll apply your patch after all.

:-)

However, this one should probably be regarded as a regression fix:

http://marc.info/?l=linux-kernel&m=132813572708843&w=4

because thawing all processes before calling swsusp_free() is definitely not a good idea.

Thanks,
Rafael

#7 lore raw
Quoted 103 lines · Rafael J. Wysocki
Quoted 102 lines · Srivatsa S. Bhat
Quoted 85 lines · Rafael J. Wysocki
Quoted 45 lines · Srivatsa S. Bhat
Quoted 37 lines · Rafael J. Wysocki
Quoted 36 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
Quoted 6 lines

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 2 lines
kernel/power/hibernate.c +2 -0
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

Quoted 5 lines

But then what about the case (in the existing code) when freeze_kernel_threads() fails? It would first thaw kernel threads (in fact it used to thaw even userspace tasks earlier!) before calling swsusp_free(). So, the existing code itself seems to be brittle, considering the point you raised. Right?

Well, that's why freeze_kernel_threads() originally hadn't tried to thaw anything and started to do that after one of the Tejun's commits (and I forgot about this particular issue back then).

Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -3
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 10 lines
kernel/power/user.c +1 -3
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

Quoted 8 lines
Quoted 3 lines

This was intended as a cleanup only, not a bug fix. But now, (see my point above), I am beginning to feel that the existing code itself is not robust enough...

Well, let's pretend that we think it is safe to thaw kernel threads before freeing memory (actually, they are frozen after the preallocation, so it really should be OK).

Yeah, even I had the same reasoning in mind when writing this patch.

Quoted 2 lines

So I think I'll apply your patch after all.

Quoted 9 lines
Quoted 1 line

:-)

However, this one should probably be regarded as a regression fix:

http://marc.info/?l=linux-kernel&m=132813572708843&w=4

because thawing all processes before calling swsusp_free() is definitely not a good idea.

Right, I agree. So we need to get this into stable as well then.. Do you want me to re-spin the patch with the commit message explicitly stating that this is a regression fix and so on or is the current patch good enough?

Regards,
Srivatsa S. Bhat

#8 lore raw
Quoted 109 lines · Srivatsa S. Bhat
Quoted 107 lines · Rafael J. Wysocki
Quoted 97 lines · Srivatsa S. Bhat
Quoted 85 lines · Rafael J. Wysocki
Quoted 45 lines · Srivatsa S. Bhat
Quoted 37 lines · Rafael J. Wysocki
Quoted 36 lines · Srivatsa S. Bhat

In the hibernation call path, the kernel threads are frozen inside hibernation_snapshot(). If we happen to encounter an error further down the road or if we are exiting early due to a successful freezer test, then thaw kernel threads before returning to the caller.

---

 kernel/power/hibernate.c |    6 ++++--
 kernel/power/user.c      |    8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/power/hibernate.c +2 -2
index a5d4cf0..c6dee73 100644
@@ -343,13 +343,13 @@ int hibernation_snapshot(int platform_mode)
 		 * successful freezer test.
 		 */
 		freezer_test_done = true;
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	error = dpm_prepare(PMSG_FREEZE);
 	if (error) {
 		dpm_complete(PMSG_RECOVER);
-		goto Cleanup;
+		goto Thaw;
 	}
 
 	suspend_console();
@@ -385,6 +385,8 @@ int hibernation_snapshot(int platform_mode)
 	platform_end(platform_mode);
 	return error;
 
Quoted 6 lines

kernel/power/hibernate.c int hibernation_snapshot(int platform_mode) · line 389

Quoted 2 lines
kernel/power/hibernate.c +2 -0
+ Thaw:
+	thaw_kernel_threads();

Actaully, no. You have to do swsusp_free() before thawing, otherwise some allocations made by the just thawed kernel threads may fail.

Quoted 5 lines

But then what about the case (in the existing code) when freeze_kernel_threads() fails? It would first thaw kernel threads (in fact it used to thaw even userspace tasks earlier!) before calling swsusp_free(). So, the existing code itself seems to be brittle, considering the point you raised. Right?

Well, that's why freeze_kernel_threads() originally hadn't tried to thaw anything and started to do that after one of the Tejun's commits (and I forgot about this particular issue back then).

Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
kernel/power/hibernate.c +0 -0
  Cleanup:
 	swsusp_free();
 	goto Close;
kernel/power/user.c +1 -3
index 3e10007..7bee91f 100644
@@ -249,16 +249,12 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		}
 		pm_restore_gfp_mask();
 		error = hibernation_snapshot(data->platform_support);
-		if (error) {
-			thaw_kernel_threads();
-		} else {
+		if (!error) {

kernel/power/user.c static long snapshot_ioctl(struct file *filp, unsigned int cmd, · line 259

Quoted 10 lines
kernel/power/user.c +1 -3
 			error = put_user(in_suspend, (int __user *)arg);
 			if (!error && !freezer_test_done)
 				data->ready = 1;
-			if (freezer_test_done) {
+			if (freezer_test_done)
 				freezer_test_done = false;
-				thaw_kernel_threads();
-			}
 		}
 		break;

Overall, this seems to be a cleanup, or is it a bug fix?

Quoted 8 lines
Quoted 3 lines

This was intended as a cleanup only, not a bug fix. But now, (see my point above), I am beginning to feel that the existing code itself is not robust enough...

Well, let's pretend that we think it is safe to thaw kernel threads before freeing memory (actually, they are frozen after the preallocation, so it really should be OK).

Quoted 6 lines

Yeah, even I had the same reasoning in mind when writing this patch.

Quoted 2 lines

So I think I'll apply your patch after all.

:-)

However, this one should probably be regarded as a regression fix:

Quoted 8 lines
Quoted 5 lines

http://marc.info/?l=linux-kernel&m=132813572708843&w=4

because thawing all processes before calling swsusp_free() is definitely not a good idea.

Right, I agree. So we need to get this into stable as well then..

No, we don't, this is a 3.3 merge window fallout.

Quoted 2 lines

Do you want me to re-spin the patch with the commit message explicitly stating that this is a regression fix and so on or is the current patch good enough?

Yes, it would be nice to rework the changelog to reflect the real importance of the patch.

Thanks,
Rafael