diff mbox

[v5,07/10] x86/asm/acpi: Fix asmvalidate warnings for wakeup_64.S

Message ID 2817f5690aa760a601a614b738545fd60b087bbb.1433937132.git.jpoimboe@redhat.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Josh Poimboeuf June 10, 2015, 12:06 p.m. UTC
Fix the following asmvalidate warnings:

   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x15: unsupported jump to outside of function
   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x55: unsupported jump to outside of function
   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64(): unsupported fallthrough at end of function
   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x9a: unsupported jump to outside of function
   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x116: unsupported jump to outside of function
   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): unsupported fallthrough at end of function
   asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): missing FP_SAVE/RESTORE macros

1. wakeup_long64() isn't a function that can be called.  It's actually
   redirected to via a return instruction in the entry code.  It
   shouldn't be annotated as a callable function.  Change ENDPROC ->
   PROC accordingly.

2. do_suspend_lowlevel() is a non-leaf callable function, so
   save/restore the frame pointer with FP_SAVE/RESTORE.

3. Remove the unnecessary jump to .Lresume_point, as it just results in
   jumping to the next instruction (which is a nop because of the
   align).  Otherwise asmvalidate gets confused by the jump.

4. Change the "jmp restore_processor_state" to a call instruction,
   because jumping outside the function's boundaries isn't allowed.  Now
   restore_processor_state() will return back to do_suspend_lowlevel()
   instead of do_suspend_lowlevel()'s caller.

5. Remove superfluous rsp changes.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <len.brown@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: linux-pm@vger.kernel.org
---
 arch/x86/kernel/acpi/wakeup_64.S | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Pavel Machek June 10, 2015, 1:19 p.m. UTC | #1
Hi!

> Fix the following asmvalidate warnings:
> 
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x15: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x55: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64(): unsupported fallthrough at end of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x9a: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x116: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): unsupported fallthrough at end of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): missing FP_SAVE/RESTORE macros
> 
> 1. wakeup_long64() isn't a function that can be called.  It's actually
>    redirected to via a return instruction in the entry code.  It
>    shouldn't be annotated as a callable function.  Change ENDPROC ->
>    PROC accordingly.

But I see -> END.

> 2. do_suspend_lowlevel() is a non-leaf callable function, so
>    save/restore the frame pointer with FP_SAVE/RESTORE.

It does not work with the frame pointer itself. Is FP_SAVE/RESTORE
still neccessary? Will you need FP_RESTORE to wakeup_long64, then?

> 3. Remove the unnecessary jump to .Lresume_point, as it just results in
>    jumping to the next instruction (which is a nop because of the
>    align).  Otherwise asmvalidate gets confused by the jump.

It also results in flushing the pipeline. Ok, I guess this one is unneccessary.

> 4. Change the "jmp restore_processor_state" to a call instruction,
>    because jumping outside the function's boundaries isn't allowed.  Now
>    restore_processor_state() will return back to do_suspend_lowlevel()
>    instead of do_suspend_lowlevel()'s caller.
> 
> 5. Remove superfluous rsp changes.

Did you test the changes?

Do you plan to make similar changes to wakeup_32.S?

> diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
> index 8c35df4..7e442be 100644
> --- a/arch/x86/kernel/acpi/wakeup_64.S
> +++ b/arch/x86/kernel/acpi/wakeup_64.S
> @@ -5,6 +5,7 @@
>  #include <asm/page_types.h>
>  #include <asm/msr.h>
>  #include <asm/asm-offsets.h>
> +#include <asm/func.h>
>  
>  # Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
>  
> @@ -33,13 +34,13 @@ ENTRY(wakeup_long64)
>  
>  	movq	saved_rip, %rax
>  	jmp	*%rax
> -ENDPROC(wakeup_long64)
> +END(wakeup_long64)
>

This should result in no binary code changes, so that's ok with me...

>  ENTRY(do_suspend_lowlevel)
> -	subq	$8, %rsp
> +	FP_SAVE
>  	xorl	%eax, %eax
>  	call	save_processor_state
>

Are you sure? Stuff like
        movq    $saved_context, %rax
        movq    %rsp, pt_regs_sp(%rax)

follows. And you did not modify wakeup_long64, which now receives
different value in saved_rsp.

> @@ -108,8 +108,9 @@ ENTRY(do_suspend_lowlevel)
>  	movq	pt_regs_r15(%rax), %r15
>  
>  	xorl	%eax, %eax
> -	addq	$8, %rsp
> -	jmp	restore_processor_state
> +	call	restore_processor_state
> +	FP_RESTORE
> +	ret
>  ENDPROC(do_suspend_lowlevel)

Umm. I rather liked the direct jump.

									Pavel
Pavel Machek June 10, 2015, 1:21 p.m. UTC | #2
On Wed 2015-06-10 07:06:15, Josh Poimboeuf wrote:
> Fix the following asmvalidate warnings:
> 
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x15: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x55: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64(): unsupported fallthrough at end of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x9a: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x116: unsupported jump to outside of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): unsupported fallthrough at end of function
>    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): missing FP_SAVE/RESTORE macros
>

Actually first things first. Purpose of warnings is to pinpoint
errors. Do you believe there are some errors in wakeup_64.S?
								Pavel
Josh Poimboeuf June 10, 2015, 2:08 p.m. UTC | #3
On Wed, Jun 10, 2015 at 03:19:14PM +0200, Pavel Machek wrote:
> Hi!
> 
> > Fix the following asmvalidate warnings:
> > 
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x15: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x55: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64(): unsupported fallthrough at end of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x9a: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x116: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): unsupported fallthrough at end of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): missing FP_SAVE/RESTORE macros
> > 
> > 1. wakeup_long64() isn't a function that can be called.  It's actually
> >    redirected to via a return instruction in the entry code.  It
> >    shouldn't be annotated as a callable function.  Change ENDPROC ->
> >    PROC accordingly.
> 
> But I see -> END.

Oops!  It should say -> END.

> > 2. do_suspend_lowlevel() is a non-leaf callable function, so
> >    save/restore the frame pointer with FP_SAVE/RESTORE.
> 
> It does not work with the frame pointer itself. Is FP_SAVE/RESTORE
> still neccessary? Will you need FP_RESTORE to wakeup_long64, then?

wakeup_long64 jumps to .Lresume_point, which does the FP_RESTORE.

> > 3. Remove the unnecessary jump to .Lresume_point, as it just results in
> >    jumping to the next instruction (which is a nop because of the
> >    align).  Otherwise asmvalidate gets confused by the jump.
> 
> It also results in flushing the pipeline. Ok, I guess this one is unneccessary.
> 
> > 4. Change the "jmp restore_processor_state" to a call instruction,
> >    because jumping outside the function's boundaries isn't allowed.  Now
> >    restore_processor_state() will return back to do_suspend_lowlevel()
> >    instead of do_suspend_lowlevel()'s caller.
> > 
> > 5. Remove superfluous rsp changes.
> 
> Did you test the changes?

Yes, I verified that it didn't break suspend/resume on my system.

> Do you plan to make similar changes to wakeup_32.S?

Currently, asmvalidate is x86_64 only, so I'm only fixing the 64-bit
stuff right now.

> > diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
> > index 8c35df4..7e442be 100644
> > --- a/arch/x86/kernel/acpi/wakeup_64.S
> > +++ b/arch/x86/kernel/acpi/wakeup_64.S
> > @@ -5,6 +5,7 @@
> >  #include <asm/page_types.h>
> >  #include <asm/msr.h>
> >  #include <asm/asm-offsets.h>
> > +#include <asm/func.h>
> >  
> >  # Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
> >  
> > @@ -33,13 +34,13 @@ ENTRY(wakeup_long64)
> >  
> >  	movq	saved_rip, %rax
> >  	jmp	*%rax
> > -ENDPROC(wakeup_long64)
> > +END(wakeup_long64)
> >
> 
> This should result in no binary code changes, so that's ok with me...
> 
> >  ENTRY(do_suspend_lowlevel)
> > -	subq	$8, %rsp
> > +	FP_SAVE
> >  	xorl	%eax, %eax
> >  	call	save_processor_state
> >
> 
> Are you sure? Stuff like
>         movq    $saved_context, %rax
>         movq    %rsp, pt_regs_sp(%rax)
> 
> follows. And you did not modify wakeup_long64, which now receives
> different value in saved_rsp.

Hm, I'm looking hard, but I still don't see a problem with that code.
It's saving rsp to the saved_context struct.  As I mentioned above, it's
ok for the wakeup_long64 path to restore the same rsp value, since it
jumps to .Lresume_point which has FP_RESTORE.

> > @@ -108,8 +108,9 @@ ENTRY(do_suspend_lowlevel)
> >  	movq	pt_regs_r15(%rax), %r15
> >  
> >  	xorl	%eax, %eax
> > -	addq	$8, %rsp
> > -	jmp	restore_processor_state
> > +	call	restore_processor_state
> > +	FP_RESTORE
> > +	ret
> >  ENDPROC(do_suspend_lowlevel)
> 
> Umm. I rather liked the direct jump.

Why?
Josh Poimboeuf June 10, 2015, 2:13 p.m. UTC | #4
On Wed, Jun 10, 2015 at 03:21:35PM +0200, Pavel Machek wrote:
> On Wed 2015-06-10 07:06:15, Josh Poimboeuf wrote:
> > Fix the following asmvalidate warnings:
> > 
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x15: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x55: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64(): unsupported fallthrough at end of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x9a: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x116: unsupported jump to outside of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): unsupported fallthrough at end of function
> >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): missing FP_SAVE/RESTORE macros
> >
> 
> Actually first things first. Purpose of warnings is to pinpoint
> errors. Do you believe there are some errors in wakeup_64.S?

The "errors" are that it doesn't conform with the guidelines outlined in
the cover letter.  Specifically, wakeup_long64() is improperly
annotated, and do_suspend_lowlevel() doesn't honor CONFIG_FRAME_POINTER.
Ingo Molnar June 11, 2015, 6:13 a.m. UTC | #5
* Josh Poimboeuf <jpoimboe@redhat.com> wrote:

> On Wed, Jun 10, 2015 at 03:21:35PM +0200, Pavel Machek wrote:
> > On Wed 2015-06-10 07:06:15, Josh Poimboeuf wrote:
> > > Fix the following asmvalidate warnings:
> > > 
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x15: unsupported jump to outside of function
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64()+0x55: unsupported jump to outside of function
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: wakeup_long64(): unsupported fallthrough at end of function
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x9a: unsupported jump to outside of function
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel()+0x116: unsupported jump to outside of function
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): unsupported fallthrough at end of function
> > >    asmvalidate: arch/x86/kernel/acpi/wakeup_64.o: do_suspend_lowlevel(): missing FP_SAVE/RESTORE macros
> > >
> > 
> > Actually first things first. Purpose of warnings is to pinpoint
> > errors. Do you believe there are some errors in wakeup_64.S?
> 
> The "errors" are that it doesn't conform with the guidelines outlined in
> the cover letter.  Specifically, wakeup_long64() is improperly
> annotated, and do_suspend_lowlevel() doesn't honor CONFIG_FRAME_POINTER.

Please create a file for this in Documentation/x86/, outlining the common cases of 
such .S debug info problems and the effects this has on the stack backtrace 
output.

Thanks,

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pavel Machek June 11, 2015, 12:36 p.m. UTC | #6
Hi!

> > > 5. Remove superfluous rsp changes.
> > 
> > Did you test the changes?
> 
> Yes, I verified that it didn't break suspend/resume on my system.

Ok, so I can not see anything wrong, either. I'd like to understand
why the original code manipulated %rsp, but...

If you did testing with frame pointer on, you can get my

Acked-by: Pavel Machek <pavel@ucw.cz>

> > Do you plan to make similar changes to wakeup_32.S?
> 
> Currently, asmvalidate is x86_64 only, so I'm only fixing the 64-bit
> stuff right now.

Well, you are "improving debuggability", afaict. It worked well before.

> > > @@ -108,8 +108,9 @@ ENTRY(do_suspend_lowlevel)
> > >  	movq	pt_regs_r15(%rax), %r15
> > >  
> > >  	xorl	%eax, %eax
> > > -	addq	$8, %rsp
> > > -	jmp	restore_processor_state
> > > +	call	restore_processor_state
> > > +	FP_RESTORE
> > > +	ret
> > >  ENDPROC(do_suspend_lowlevel)
> > 
> > Umm. I rather liked the direct jump.
> 
> Why?

It is both smaller and faster than the new code. But...

									Pavel
diff mbox

Patch

diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index 8c35df4..7e442be 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -5,6 +5,7 @@ 
 #include <asm/page_types.h>
 #include <asm/msr.h>
 #include <asm/asm-offsets.h>
+#include <asm/func.h>
 
 # Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
 
@@ -33,13 +34,13 @@  ENTRY(wakeup_long64)
 
 	movq	saved_rip, %rax
 	jmp	*%rax
-ENDPROC(wakeup_long64)
+END(wakeup_long64)
 
 bogus_64_magic:
 	jmp	bogus_64_magic
 
 ENTRY(do_suspend_lowlevel)
-	subq	$8, %rsp
+	FP_SAVE
 	xorl	%eax, %eax
 	call	save_processor_state
 
@@ -70,12 +71,11 @@  ENTRY(do_suspend_lowlevel)
 	movq	%rdi, saved_rdi
 	movq	%rsi, saved_rsi
 
-	addq	$8, %rsp
 	movl	$3, %edi
 	xorl	%eax, %eax
 	call	x86_acpi_enter_sleep_state
+
 	/* in case something went wrong, restore the machine status and go on */
-	jmp	.Lresume_point
 
 	.align 4
 .Lresume_point:
@@ -108,8 +108,9 @@  ENTRY(do_suspend_lowlevel)
 	movq	pt_regs_r15(%rax), %r15
 
 	xorl	%eax, %eax
-	addq	$8, %rsp
-	jmp	restore_processor_state
+	call	restore_processor_state
+	FP_RESTORE
+	ret
 ENDPROC(do_suspend_lowlevel)
 
 .data