[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230112143825.822328168@infradead.org>
Date: Thu, 12 Jan 2023 15:31:46 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: x86@...nel.org, Joan Bruguera <joanbrugueram@...il.com>
Cc: linux-kernel@...r.kernel.org, peterz@...radead.org,
Juergen Gross <jgross@...e.com>,
"Rafael J. Wysocki" <rafael@...nel.org>,
xen-devel <xen-devel@...ts.xenproject.org>,
Jan Beulich <jbeulich@...e.com>,
Roger Pau Monne <roger.pau@...rix.com>,
Kees Cook <keescook@...omium.org>, mark.rutland@....com
Subject: [RFC][PATCH 5/6] PM / hibernate: Add minimal noinstr annotations
When resuming there must not be any code between swsusp_arch_suspend()
and restore_processor_state() since the CPU state is ill defined at
this point in time.
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
---
kernel/power/hibernate.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -280,6 +280,32 @@ __weak int arch_resume_nosmt(void)
return 0;
}
+static noinstr int suspend_and_restore(void)
+{
+ int error;
+
+ /*
+ * Strictly speaking swsusp_arch_suspend() should be noinstr too but it
+ * is typically written in asm, as such, assume it is good and shut up
+ * the validator.
+ */
+ instrumentation_begin();
+ error = swsusp_arch_suspend();
+ instrumentation_end();
+
+ /*
+ * Architecture resume code 'returns' from the swsusp_arch_suspend()
+ * call and resumes execution here with some very dodgy machine state.
+ *
+ * Compiler instrumentation between these two calls (or in
+ * restore_processor_state() for that matter) will make life *very*
+ * interesting indeed.
+ */
+ restore_processor_state();
+
+ return error;
+}
+
/**
* create_image - Create a hibernation image.
* @platform_mode: Whether or not to use the platform driver.
@@ -323,9 +349,7 @@ static int create_image(int platform_mod
in_suspend = 1;
save_processor_state();
trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true);
- error = swsusp_arch_suspend();
- /* Restore control flow magically appears here */
- restore_processor_state();
+ error = suspend_and_restore();
trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false);
if (error)
pr_err("Error %d creating image\n", error);
Powered by blists - more mailing lists