linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le
@ 2016-09-22  6:20 Akshay Adiga
  2016-09-22 10:21 ` Michael Ellerman
  0 siblings, 1 reply; 5+ messages in thread
From: Akshay Adiga @ 2016-09-22  6:20 UTC (permalink / raw)
  To: linux-kernel, linuxppc-dev; +Cc: anton, Akshay Adiga

Observed that boot arguments (passed as CONFIG_CMDLINE)  are not being
picked up by kernel while using gcc-ppc64-linux-gnu v5.4.0 and v6.1.1.
While it works as expected with v5.3.1 .

Found that in init/main.c in  setup_command_line() the pointers passed to
strcpy() is messed up.

source for setup_command_line from init/main.c:
void setup_command_line(char *command_line)
{
        saved_command_line =
                memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
        initcall_command_line =
                memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
        static_command_line = memblock_virt_alloc(strlen(command_line) + 1, 0);
        strcpy(saved_command_line, boot_command_line);
        strcpy(static_command_line, command_line);
}

Following is the asm dump for strcpy:

char *strcpy(char *dest, const char *src)
{
c000000000161408:       ff ff 84 38     addi    r4,r4,-1
c00000000016140c:       ff ff 43 39     addi    r10,r3,-1
                char *tmp = dest;

                while ((*dest++ = *src++) != '\0')
c000000000161410:       01 00 24 8d     lbzu    r9,1(r4)
c000000000161414:       00 00 a9 2f     cmpdi   cr7,r9,0
c000000000161418:       01 00 2a 9d     stbu    r9,1(r10)
c00000000016141c:       f4 ff 9e 40     bne     cr7,c000000000161410
<strcpy+0x8>
                                /* nothing */;
                return tmp;
}

Following are the asm dump for the working and non working binaries which
concluded that the argument for the second strcpy() is not loaded into r3 and
is getting clobbered with the return value of previous strcpy().

Not Working asm dump :

c0000000003308d8:       38 c4 6a f8     std     r3,-15304(r10)
                strcpy(saved_command_line, boot_command_line);
c0000000003308dc:       06 00 62 3c     addis   r3,r2,6
c0000000003308e0:       28 c4 63 e8     ld      r3,-15320(r3)
c0000000003308e4:       25 0b e3 4b     bl      c000000000161408
<strcpy>
c0000000003308e8:       00 00 00 60     nop
                strcpy(static_command_line, command_line);
c0000000003308ec:       78 f3 c4 7f     mr      r4,r30
c0000000003308f0:       19 0b e3 4b     bl      c000000000161408
<strcpy>
c0000000003308f4:       00 00 00 60     nop

Working asm dump :

c0000000003308d4:       38 c4 c3 fb     std     r30,-15304(r3)
        strcpy(saved_command_line, boot_command_line);
c0000000003308d8:       06 00 62 3c     addis   r3,r2,6
c0000000003308dc:       28 c4 63 e8     ld      r3,-15320(r3)
c0000000003308e0:       6d 08 e3 4b     bl      c00000000016114c
<strcpy>
c0000000003308e4:       00 00 00 60     nop
        strcpy(static_command_line, command_line);
c0000000003308e8:       78 eb a4 7f     mr      r4,r29
c0000000003308ec:       78 f3 c3 7f     mr      r3,r30
c0000000003308f0:       5d 08 e3 4b     bl      c00000000016114c
<strcpy>
c0000000003308f4:       00 00 00 60     nop

The problem goes away when compiler optimization is restricted to -O1.

Reported-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
---
 init/main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index a8a58e2..4259c42 100644
--- a/init/main.c
+++ b/init/main.c
@@ -358,7 +358,13 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }
  * parsing is performed in place, and we should allow a component to
  * store reference of name/value for future reference.
  */
-static void __init setup_command_line(char *command_line)
+static void __init
+#ifdef CONFIG_PPC64
+	#if  GCC_VERSION > 50301
+		__attribute__((optimize("-O1")))
+	#endif
+#endif
+		setup_command_line(char *command_line)
 {
 	saved_command_line =
 		memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le
  2016-09-22  6:20 [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le Akshay Adiga
@ 2016-09-22 10:21 ` Michael Ellerman
  2016-09-22 10:47   ` Anton Blanchard
  2016-09-23  4:15   ` Akshay Adiga
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Ellerman @ 2016-09-22 10:21 UTC (permalink / raw)
  To: Akshay Adiga, linux-kernel, linuxppc-dev; +Cc: anton, Akshay Adiga

Akshay Adiga <akshay.adiga@linux.vnet.ibm.com> writes:

> Observed that boot arguments (passed as CONFIG_CMDLINE)  are not being
> picked up by kernel while using gcc-ppc64-linux-gnu v5.4.0 and v6.1.1.
> While it works as expected with v5.3.1 .
>
> Found that in init/main.c in  setup_command_line() the pointers passed to
> strcpy() is messed up.

Hi Akshay,

Thanks for debugging this.

> The problem goes away when compiler optimization is restricted to -O1.

> diff --git a/init/main.c b/init/main.c
> index a8a58e2..4259c42 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -358,7 +358,13 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }
>   * parsing is performed in place, and we should allow a component to
>   * store reference of name/value for future reference.
>   */
> -static void __init setup_command_line(char *command_line)
> +static void __init
> +#ifdef CONFIG_PPC64
> +	#if  GCC_VERSION > 50301
> +		__attribute__((optimize("-O1")))
> +	#endif
> +#endif
> +		setup_command_line(char *command_line)
>  {
>  	saved_command_line =
>  		memblock_virt_alloc(strlen(boot_command_line) + 1, 0);

But I can't merge that patch.

Our options are one or both of:
 - get GCC fixed and backport the fix to the compilers we care about.
 - blacklist the broken compiler versions.

Is there a GCC bug filed for this?

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le
  2016-09-22 10:21 ` Michael Ellerman
@ 2016-09-22 10:47   ` Anton Blanchard
  2016-09-23  4:15   ` Akshay Adiga
  1 sibling, 0 replies; 5+ messages in thread
From: Anton Blanchard @ 2016-09-22 10:47 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: Akshay Adiga, linux-kernel, linuxppc-dev

Hi,

> But I can't merge that patch.
> 
> Our options are one or both of:
>  - get GCC fixed and backport the fix to the compilers we care about.
>  - blacklist the broken compiler versions.
> 
> Is there a GCC bug filed for this?

Likely: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71709

We need confirmation this patch fixes the 6.x issue too and that we need
a backport.

Anton

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le
  2016-09-22 10:21 ` Michael Ellerman
  2016-09-22 10:47   ` Anton Blanchard
@ 2016-09-23  4:15   ` Akshay Adiga
  2016-09-27 17:54     ` Akshay Adiga
  1 sibling, 1 reply; 5+ messages in thread
From: Akshay Adiga @ 2016-09-23  4:15 UTC (permalink / raw)
  To: Michael Ellerman, linux-kernel, linuxppc-dev; +Cc: anton

Hi Michael,

Anton found this bug and raised it against gcc v7.0 and a fix is available
  in upstream gcc.

	https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71709

Currently, gcc v5.4.0  and v6.1.1 shipped with Ubuntu 16.04 and 16.10  respectively,
  are hitting this problem.

I have also raised bug against Ubuntu for fixing gcc for 16.04.

https://bugzilla.linux.ibm.com/show_bug.cgi?id=146668


On 09/22/2016 03:51 PM, Michael Ellerman wrote:
> Akshay Adiga <akshay.adiga@linux.vnet.ibm.com> writes:
>
>> Observed that boot arguments (passed as CONFIG_CMDLINE)  are not being
>> picked up by kernel while using gcc-ppc64-linux-gnu v5.4.0 and v6.1.1.
>> While it works as expected with v5.3.1 .
>>
>> Found that in init/main.c in  setup_command_line() the pointers passed to
>> strcpy() is messed up.
> Hi Akshay,
>
> Thanks for debugging this.
>
>> The problem goes away when compiler optimization is restricted to -O1.
>> diff --git a/init/main.c b/init/main.c
>> index a8a58e2..4259c42 100644
>> --- a/init/main.c
>> +++ b/init/main.c
>> @@ -358,7 +358,13 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }
>>    * parsing is performed in place, and we should allow a component to
>>    * store reference of name/value for future reference.
>>    */
>> -static void __init setup_command_line(char *command_line)
>> +static void __init
>> +#ifdef CONFIG_PPC64
>> +	#if  GCC_VERSION > 50301
>> +		__attribute__((optimize("-O1")))
>> +	#endif
>> +#endif
>> +		setup_command_line(char *command_line)
>>   {
>>   	saved_command_line =
>>   		memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
> But I can't merge that patch.
>
> Our options are one or both of:
>   - get GCC fixed and backport the fix to the compilers we care about.
>   - blacklist the broken compiler versions.
>
> Is there a GCC bug filed for this?
>
> cheers
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le
  2016-09-23  4:15   ` Akshay Adiga
@ 2016-09-27 17:54     ` Akshay Adiga
  0 siblings, 0 replies; 5+ messages in thread
From: Akshay Adiga @ 2016-09-27 17:54 UTC (permalink / raw)
  To: Michael Ellerman, linux-kernel, linuxppc-dev; +Cc: anton

Hi Michael,

Here is the link to the bug raised on launchpad.
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1628207


On 09/23/2016 09:45 AM, Akshay Adiga wrote:
> Hi Michael,
>
> Anton found this bug and raised it against gcc v7.0 and a fix is 
> available
>  in upstream gcc.
>
>     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71709
>
> Currently, gcc v5.4.0  and v6.1.1 shipped with Ubuntu 16.04 and 16.10  
> respectively,
>  are hitting this problem.
>
> I have also raised bug against Ubuntu for fixing gcc for 16.04.
>
> https://bugzilla.linux.ibm.com/show_bug.cgi?id=146668
>
>
> On 09/22/2016 03:51 PM, Michael Ellerman wrote:
>> Akshay Adiga <akshay.adiga@linux.vnet.ibm.com> writes:
>>
>>> Observed that boot arguments (passed as CONFIG_CMDLINE)  are not being
>>> picked up by kernel while using gcc-ppc64-linux-gnu v5.4.0 and v6.1.1.
>>> While it works as expected with v5.3.1 .
>>>
>>> Found that in init/main.c in  setup_command_line() the pointers 
>>> passed to
>>> strcpy() is messed up.
>> Hi Akshay,
>>
>> Thanks for debugging this.
>>
>>> The problem goes away when compiler optimization is restricted to -O1.
>>> diff --git a/init/main.c b/init/main.c
>>> index a8a58e2..4259c42 100644
>>> --- a/init/main.c
>>> +++ b/init/main.c
>>> @@ -358,7 +358,13 @@ static inline void smp_prepare_cpus(unsigned 
>>> int maxcpus) { }
>>>    * parsing is performed in place, and we should allow a component to
>>>    * store reference of name/value for future reference.
>>>    */
>>> -static void __init setup_command_line(char *command_line)
>>> +static void __init
>>> +#ifdef CONFIG_PPC64
>>> +    #if  GCC_VERSION > 50301
>>> +        __attribute__((optimize("-O1")))
>>> +    #endif
>>> +#endif
>>> +        setup_command_line(char *command_line)
>>>   {
>>>       saved_command_line =
>>>           memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
>> But I can't merge that patch.
>>
>> Our options are one or both of:
>>   - get GCC fixed and backport the fix to the compilers we care about.
>>   - blacklist the broken compiler versions.
>>
>> Is there a GCC bug filed for this?
>>
>> cheers
>>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-27 17:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22  6:20 [PATCH] Work around for enabling CONFIG_CMDLINE on ppc64le Akshay Adiga
2016-09-22 10:21 ` Michael Ellerman
2016-09-22 10:47   ` Anton Blanchard
2016-09-23  4:15   ` Akshay Adiga
2016-09-27 17:54     ` Akshay Adiga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).