2014-07-30 23:57:42

by Behan Webster

[permalink] [raw]
Subject: [PATCH 0/4] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM

From: Behan Webster <[email protected]>

This patch set moves from using locally defined named registers to access the
stack pointer to using a globally defined named register. This allows the code
to work both with gcc and clang.

The LLVMLinux project aims to fully build the Linux kernel using both gcc and
clang (the C front end for the LLVM compiler infrastructure project).

Behan Webster (4):
arm64: LLVMLinux: Add current_stack_pointer() for arm64
arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
arm64: LLVMLinux: Calculate current_thread_info from
current_stack_pointer
arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c

arch/arm64/include/asm/thread_info.h | 9 +++++++--
arch/arm64/kernel/stacktrace.c | 3 +--
arch/arm64/kernel/traps.c | 3 +--
3 files changed, 9 insertions(+), 6 deletions(-)

--
1.9.1


2014-07-30 23:57:49

by Behan Webster

[permalink] [raw]
Subject: [PATCH 1/4] arm64: LLVMLinux: Add current_stack_pointer() for arm64

From: Behan Webster <[email protected]>

Define a global named register for current_stack_pointer. The use of this new
variable guarantees that both gcc and clang can access this register in C code.

Signed-off-by: Behan Webster <[email protected]>
Reviewed-by: Jan-Simon Möller <[email protected]>
Reviewed-by: Mark Charlebois <[email protected]>
---
arch/arm64/include/asm/thread_info.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
index e40b6d0..e6b6094 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -69,6 +69,11 @@ struct thread_info {
#define init_stack (init_thread_union.stack)

/*
+ * how to get the current stack pointer from C
+ */
+register unsigned long current_stack_pointer asm ("sp");
+
+/*
* how to get the thread information struct from C
*/
static inline struct thread_info *current_thread_info(void) __attribute_const__;
--
1.9.1

2014-07-30 23:57:53

by Behan Webster

[permalink] [raw]
Subject: [PATCH 3/4] arm64: LLVMLinux: Calculate current_thread_info from current_stack_pointer

From: Behan Webster <[email protected]>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and clang.

Signed-off-by: Behan Webster <[email protected]>
Signed-off-by: Mark Charlebois <[email protected]>
Reviewed-by: Jan-Simon M??ller <[email protected]>
---
arch/arm64/include/asm/thread_info.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
index e6b6094..c2432d2 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -80,8 +80,8 @@ static inline struct thread_info *current_thread_info(void) __attribute_const__;

static inline struct thread_info *current_thread_info(void)
{
- register unsigned long sp asm ("sp");
- return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
+ return (struct thread_info *) \
+ (current_stack_pointer & ~(THREAD_SIZE - 1));
}

#define thread_saved_pc(tsk) \
--
1.9.1

2014-07-30 23:58:10

by Behan Webster

[permalink] [raw]
Subject: [PATCH 4/4] arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c

From: Behan Webster <[email protected]>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and clang.

Signed-off-by: Behan Webster <[email protected]>
---
arch/arm64/kernel/traps.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index c43cfa9..0aeb316 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -132,7 +132,6 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
{
struct stackframe frame;
- const register unsigned long current_sp asm ("sp");

pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk);

@@ -145,7 +144,7 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
frame.pc = regs->pc;
} else if (tsk == current) {
frame.fp = (unsigned long)__builtin_frame_address(0);
- frame.sp = current_sp;
+ frame.sp = current_stack_pointer;
frame.pc = (unsigned long)dump_backtrace;
} else {
/*
--
1.9.1

2014-07-30 23:58:37

by Behan Webster

[permalink] [raw]
Subject: [PATCH 2/4] arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk

From: Behan Webster <[email protected]>

Use the global current_stack_pointer to get the value of the stack pointer.
This change supports being able to compile the kernel with both gcc and clang.

Signed-off-by: Behan Webster <[email protected]>
Signed-off-by: Mark Charlebois <[email protected]>
Reviewed-by: Jan-Simon M??ller <[email protected]>
---
arch/arm64/kernel/stacktrace.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 55437ba..407991b 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -111,10 +111,9 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
frame.sp = thread_saved_sp(tsk);
frame.pc = thread_saved_pc(tsk);
} else {
- register unsigned long current_sp asm("sp");
data.no_sched_functions = 0;
frame.fp = (unsigned long)__builtin_frame_address(0);
- frame.sp = current_sp;
+ frame.sp = current_stack_pointer;
frame.pc = (unsigned long)save_stack_trace_tsk;
}

--
1.9.1

2014-07-31 00:11:28

by Olof Johansson

[permalink] [raw]
Subject: Re: [PATCH 0/4] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM

On Wed, Jul 30, 2014 at 4:57 PM, <[email protected]> wrote:
> From: Behan Webster <[email protected]>
>
> This patch set moves from using locally defined named registers to access the
> stack pointer to using a globally defined named register. This allows the code
> to work both with gcc and clang.
>
> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
> clang (the C front end for the LLVM compiler infrastructure project).
>
> Behan Webster (4):
> arm64: LLVMLinux: Add current_stack_pointer() for arm64
> arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
> arm64: LLVMLinux: Calculate current_thread_info from
> current_stack_pointer
> arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c

Series:

Reviewed-by: Olof Johansson <[email protected]>

2014-07-31 05:31:38

by Andreas Färber

[permalink] [raw]
Subject: Re: [PATCH 3/4] arm64: LLVMLinux: Calculate current_thread_info from current_stack_pointer

Hi,

Am 31.07.2014 01:57, schrieb [email protected]:
> From: Behan Webster <[email protected]>
>
> Use the global current_stack_pointer to get the value of the stack pointer.
> This change supports being able to compile the kernel with both gcc and clang.
>
> Signed-off-by: Behan Webster <[email protected]>
> Signed-off-by: Mark Charlebois <[email protected]>
> Reviewed-by: Jan-Simon M??ller <[email protected]>

Something went wrong with ? encoding here and in 2/4.

> ---
> arch/arm64/include/asm/thread_info.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
> index e6b6094..c2432d2 100644
> --- a/arch/arm64/include/asm/thread_info.h
> +++ b/arch/arm64/include/asm/thread_info.h
> @@ -80,8 +80,8 @@ static inline struct thread_info *current_thread_info(void) __attribute_const__;
>
> static inline struct thread_info *current_thread_info(void)
> {
> - register unsigned long sp asm ("sp");
> - return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
> + return (struct thread_info *) \

This is not a macro, so \ seems superfluous.

Looks okay otherwise.

Regards,
Andreas

> + (current_stack_pointer & ~(THREAD_SIZE - 1));
> }
>
> #define thread_saved_pc(tsk) \

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imend?rffer; HRB 16746 AG N?rnberg

2014-07-31 10:34:39

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH 0/4] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM

On Thu, Jul 31, 2014 at 12:57:25AM +0100, [email protected] wrote:
> From: Behan Webster <[email protected]>
>
> This patch set moves from using locally defined named registers to access the
> stack pointer to using a globally defined named register. This allows the code
> to work both with gcc and clang.
>
> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
> clang (the C front end for the LLVM compiler infrastructure project).
>
> Behan Webster (4):
> arm64: LLVMLinux: Add current_stack_pointer() for arm64
> arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
> arm64: LLVMLinux: Calculate current_thread_info from
> current_stack_pointer
> arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c

Once Andreas's comments have been addressed:

Acked-by: Will Deacon <[email protected]>

Please can you send a new series after the merge window?

Cheers,

Will

2014-07-31 15:39:57

by Olof Johansson

[permalink] [raw]
Subject: Re: [PATCH 0/4] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM

On Thu, Jul 31, 2014 at 3:33 AM, Will Deacon <[email protected]> wrote:
> On Thu, Jul 31, 2014 at 12:57:25AM +0100, [email protected] wrote:
>> From: Behan Webster <[email protected]>
>>
>> This patch set moves from using locally defined named registers to access the
>> stack pointer to using a globally defined named register. This allows the code
>> to work both with gcc and clang.
>>
>> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
>> clang (the C front end for the LLVM compiler infrastructure project).
>>
>> Behan Webster (4):
>> arm64: LLVMLinux: Add current_stack_pointer() for arm64
>> arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
>> arm64: LLVMLinux: Calculate current_thread_info from
>> current_stack_pointer
>> arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c
>
> Once Andreas's comments have been addressed:
>
> Acked-by: Will Deacon <[email protected]>
>
> Please can you send a new series after the merge window?

Given that the ARM64 KVM guys are still actively breaking -next, and
this is considerably smaller and lower risk than that, I think you can
take it for 3.17?


-Olof

2014-07-31 15:49:20

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH 0/4] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM

On Thu, Jul 31, 2014 at 04:39:55PM +0100, Olof Johansson wrote:
> On Thu, Jul 31, 2014 at 3:33 AM, Will Deacon <[email protected]> wrote:
> > On Thu, Jul 31, 2014 at 12:57:25AM +0100, [email protected] wrote:
> >> From: Behan Webster <[email protected]>
> >>
> >> This patch set moves from using locally defined named registers to access the
> >> stack pointer to using a globally defined named register. This allows the code
> >> to work both with gcc and clang.
> >>
> >> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
> >> clang (the C front end for the LLVM compiler infrastructure project).
> >>
> >> Behan Webster (4):
> >> arm64: LLVMLinux: Add current_stack_pointer() for arm64
> >> arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
> >> arm64: LLVMLinux: Calculate current_thread_info from
> >> current_stack_pointer
> >> arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c
> >
> > Once Andreas's comments have been addressed:
> >
> > Acked-by: Will Deacon <[email protected]>
> >
> > Please can you send a new series after the merge window?
>
> Given that the ARM64 KVM guys are still actively breaking -next, and
> this is considerably smaller and lower risk than that, I think you can
> take it for 3.17?

Hey, those breakages are in the kvm tree not the arm64 tree! I'd really
rather wait on these as I don't see the rush to get them in for 3.17 and
it's not beyond the realms of possibility that they could cause problems
for a particular version of GCC (at the very least, I'd need to re-run
all the testing I've been doing).

Will

2014-07-31 15:52:26

by Olof Johansson

[permalink] [raw]
Subject: Re: [PATCH 0/4] LLVMLinux: Patches to enable the kernel to be compiled with clang/LLVM

On Thu, Jul 31, 2014 at 8:48 AM, Will Deacon <[email protected]> wrote:
> On Thu, Jul 31, 2014 at 04:39:55PM +0100, Olof Johansson wrote:
>> On Thu, Jul 31, 2014 at 3:33 AM, Will Deacon <[email protected]> wrote:
>> > On Thu, Jul 31, 2014 at 12:57:25AM +0100, [email protected] wrote:
>> >> From: Behan Webster <[email protected]>
>> >>
>> >> This patch set moves from using locally defined named registers to access the
>> >> stack pointer to using a globally defined named register. This allows the code
>> >> to work both with gcc and clang.
>> >>
>> >> The LLVMLinux project aims to fully build the Linux kernel using both gcc and
>> >> clang (the C front end for the LLVM compiler infrastructure project).
>> >>
>> >> Behan Webster (4):
>> >> arm64: LLVMLinux: Add current_stack_pointer() for arm64
>> >> arm64: LLVMLinux: Use current_stack_pointer in save_stack_trace_tsk
>> >> arm64: LLVMLinux: Calculate current_thread_info from
>> >> current_stack_pointer
>> >> arm64: LLVMLinux: Use current_stack_pointer in kernel/traps.c
>> >
>> > Once Andreas's comments have been addressed:
>> >
>> > Acked-by: Will Deacon <[email protected]>
>> >
>> > Please can you send a new series after the merge window?
>>
>> Given that the ARM64 KVM guys are still actively breaking -next, and
>> this is considerably smaller and lower risk than that, I think you can
>> take it for 3.17?
>
> Hey, those breakages are in the kvm tree not the arm64 tree! I'd really
> rather wait on these as I don't see the rush to get them in for 3.17 and
> it's not beyond the realms of possibility that they could cause problems
> for a particular version of GCC (at the very least, I'd need to re-run
> all the testing I've been doing).


Yeah, it was somewhat tongue in cheek that made not have made it
across the wire.

3.18 is fine with me too even though I find the concerns to be quite unlikely.


-Olof

2014-07-31 16:04:38

by Behan Webster

[permalink] [raw]
Subject: Re: [PATCH 3/4] arm64: LLVMLinux: Calculate current_thread_info from current_stack_pointer

On 07/30/14 22:31, Andreas F?rber wrote:
> Hi,
>
> Am 31.07.2014 01:57, schrieb [email protected]:
>> From: Behan Webster <[email protected]>
>>
>> Use the global current_stack_pointer to get the value of the stack pointer.
>> This change supports being able to compile the kernel with both gcc and clang.
>>
>> Signed-off-by: Behan Webster <[email protected]>
>> Signed-off-by: Mark Charlebois <[email protected]>
>> Reviewed-by: Jan-Simon M??ller <[email protected]>
> Something went wrong with ? encoding here and in 2/4.
Yeah. That keeps happening. :(

Thanks.

>> ---
>> arch/arm64/include/asm/thread_info.h | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
>> index e6b6094..c2432d2 100644
>> --- a/arch/arm64/include/asm/thread_info.h
>> +++ b/arch/arm64/include/asm/thread_info.h
>> @@ -80,8 +80,8 @@ static inline struct thread_info *current_thread_info(void) __attribute_const__;
>>
>> static inline struct thread_info *current_thread_info(void)
>> {
>> - register unsigned long sp asm ("sp");
>> - return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
>> + return (struct thread_info *) \
> This is not a macro, so \ seems superfluous.
Doh. Indeed. Will fix.

Behan

--
Behan Webster
[email protected]