From 54a015104136974262afa4b8ddd943ea70dec8a2 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 10 Apr 2008 15:37:38 -0700 Subject: asmlinkage_protect replaces prevent_tail_call The prevent_tail_call() macro works around the problem of the compiler clobbering argument words on the stack, which for asmlinkage functions is the caller's (user's) struct pt_regs. The tail/sibling-call optimization is not the only way that the compiler can decide to use stack argument words as scratch space, which we have to prevent. Other optimizations can do it too. Until we have new compiler support to make "asmlinkage" binding on the compiler's own use of the stack argument frame, we have work around all the manifestations of this issue that crop up. More cases seem to be prevented by also keeping the incoming argument variables live at the end of the function. This makes their original stack slots attractive places to leave those variables, so the compiler tends not clobber them for something else. It's still no guarantee, but it handles some observed cases that prevent_tail_call() did not. Signed-off-by: Roland McGrath Signed-off-by: Linus Torvalds --- include/linux/linkage.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/linux/linkage.h') diff --git a/include/linux/linkage.h b/include/linux/linkage.h index 0592936344c..fe2a39c489b 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h @@ -17,8 +17,8 @@ # define asmregparm #endif -#ifndef prevent_tail_call -# define prevent_tail_call(ret) do { } while (0) +#ifndef asmlinkage_protect +# define asmlinkage_protect(n, ret, args...) do { } while (0) #endif #ifndef __ALIGN -- cgit v1.2.3 From d10d89ec78114f925f63c5126a2b2490f501a462 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 10 Apr 2008 17:35:23 -0700 Subject: Add commentary about the new "asmlinkage_protect()" macro It's really a pretty ugly thing to need, and some day it will hopefully be obviated by teaching gcc about the magic calling conventions for the low-level system call code, but in the meantime we can at least add big honking comments about why we need these insane and strange macros. I took my comments from my version of the macro, but I ended up deciding to just pick Roland's version of the actual code instead (with his prettier syntax that uses vararg macros). Thus the previous two commits that actually implement it. Signed-off-by: Linus Torvalds --- include/linux/linkage.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/linux/linkage.h') diff --git a/include/linux/linkage.h b/include/linux/linkage.h index fe2a39c489b..b163c5c40db 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h @@ -17,6 +17,19 @@ # define asmregparm #endif +/* + * This is used by architectures to keep arguments on the stack + * untouched by the compiler by keeping them live until the end. + * The argument stack may be owned by the assembly-language + * caller, not the callee, and gcc doesn't always understand + * that. + * + * We have the return value, and a maximum of six arguments. + * + * This should always be followed by a "return ret" for the + * protection to work (ie no more work that the compiler might + * end up needing stack temporaries for). + */ #ifndef asmlinkage_protect # define asmlinkage_protect(n, ret, args...) do { } while (0) #endif -- cgit v1.2.3 From b0fac02370cffad956ff3de5e8ed4df7e7b875d7 Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Fri, 11 Apr 2008 13:46:54 +0200 Subject: Fix "$(AS) -traditional" compile breakage caused by asmlinkage_protect git commit 54a015104136974262afa4b8ddd943ea70dec8a2 ("asmlinkage_protect replaces prevent_tail_call") causes this build failure on s390: AS arch/s390/kernel/entry64.o In file included from arch/s390/kernel/entry64.S:14: include/linux/linkage.h:34: error: syntax error in macro parameter list make[1]: *** [arch/s390/kernel/entry64.o] Error 1 make: *** [arch/s390/kernel] Error 2 and some other architectures. The reason is that some architectures add the "-traditional" flag to the invocation of $(AS), which disables variadic macro argument support. So just surround the new define with an #ifndef __ASSEMBLY__ to prevent any side effects on asm code. Cc: Roland McGrath Cc: Martin Schwidefsky Signed-off-by: Heiko Carstens Signed-off-by: Linus Torvalds --- include/linux/linkage.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/linux/linkage.h') diff --git a/include/linux/linkage.h b/include/linux/linkage.h index b163c5c40db..2119610b24f 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h @@ -30,9 +30,12 @@ * protection to work (ie no more work that the compiler might * end up needing stack temporaries for). */ +/* Assembly files may be compiled with -traditional .. */ +#ifndef __ASSEMBLY__ #ifndef asmlinkage_protect # define asmlinkage_protect(n, ret, args...) do { } while (0) #endif +#endif #ifndef __ALIGN #define __ALIGN .align 4,0x90 -- cgit v1.2.3