All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomas Winkler <tomasw@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	mm-commits@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-scsi@vger.kernel.org, jpoimboe@redhat.com,
	Martin Jambor <mjambor@suse.cz>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Denys Vlasenko <dvlasenk@redhat.com>, Thomas Graf <tgraf@suug.ch>,
	Peter Zijlstra <peterz@infradead.org>,
	David Rientjes <rientjes@google.com>,
	Ingo Molnar <mingo@kernel.org>,
	Himanshu Madhani <himanshu.madhani@qlogic.com>,
	Dept-Eng QLA2xxx Upstream <qla2xxx-upstream@qlogic.com>,
	Jan Hubicka <hubicka@ucw.cz>,
	"Amir (Jer)" <amir.jer.levy@intel.com>
Subject: Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug
Date: Wed, 22 Jun 2016 11:24:50 +0300	[thread overview]
Message-ID: <CA+i0qc74R9Qfy8r+an4cwXQvtrk8W-=zXe3+2VgWft=J3EpV9Q@mail.gmail.com> (raw)
In-Reply-To: <CA+i0qc6iCDx44hbX-VWvhinXtPBFS_wcQ3h7abNMjJpWfvbsug@mail.gmail.com>

On Tue, Jun 21, 2016 at 12:02 PM, Tomas Winkler <tomasw@gmail.com> wrote:
> On Tue, May 3, 2016 at 9:36 AM, Arnd Bergmann <arnd@arndb.de> wrote:
>> On Monday 02 May 2016 16:32:25 Andrew Morton wrote:
>>> On Tue, 03 May 2016 01:10:16 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
>>>
>>> > On Monday 02 May 2016 16:02:18 Andrew Morton wrote:
>>> > > On Mon, 02 May 2016 23:48:19 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
>>> > >
>>> > > > This is another attempt to avoid a regression in wwn_to_u64() after
>>> > > > that started using get_unaligned_be64(), which in turn ran into a
>>> > > > bug on gcc-4.9 through 6.1.
>>> > >
>>> > > I'm still getting a couple screenfuls of things like
>>> > >
>>> > > net/tipc/name_distr.c: In function 'tipc_named_process_backlog':
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'unsigned int'
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 4 has type 'unsigned int'
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 5 has type 'unsigned int'
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 7 has type 'unsigned int'
>>> >
>>> > I've built a few thousand kernels (arm32 with gcc-6.1) with the patch applied,
>>> > but didn't see this one. What target architecture and compiler version produced
>>> > this? Does it go away if you add a (__u32) cast? I don't even know what the
>>> > warning is trying to tell me.
>>>
>>> heh, I didn't actually read it.
>>>
>>> Hopefully we can write this off as a gcc-4.4.4 glitch. 4.8.4 is OK.
>>
>> Ah, old compiler. I've tried gcc-4.3 now on ARM, and I don't get this warning
>> (just a lot "may be used uninitialized"), but unlike gcc-4.4, my version doesn't
>> actually get into the code path I have changed because __builtin_bswap32 was only
>> introduced with 4.4.
>>
>> I don't have gcc-4.4 and 4.5 here, but the warning does show up with 4.6, 4.7
>> and 4.8:
>>
>> drivers/soc/sunxi/sunxi_sram.c: In function ‘sunxi_sram_show’:
>> drivers/soc/sunxi/sunxi_sram.c:103:7: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
>>
>> 4.8 is probably still common enough that we should try to address this.
>> This change addresses the problem for me with ARM gcc-4.8, but adding
>> two more type casts. This also makes the 16/32/64 bit swaps all
>> look the same. I would expect this to also have the same effect on 4.4.
>>
>> Please fold into the previous patch.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>>
>> diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
>> index d737804af181..8f3a8f606fd9 100644
>> --- a/include/uapi/linux/swab.h
>> +++ b/include/uapi/linux/swab.h
>> @@ -97,7 +97,7 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val)
>>   * @x: value to byteswap
>>   */
>>  #ifdef __HAVE_BUILTIN_BSWAP16__
>> -#define __swab16(x) __builtin_bswap16((__u16)(x))
>> +#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
>>  #else
>>  #define __swab16(x)                            \
>>         (__builtin_constant_p((__u16)(x)) ?     \
>> @@ -110,7 +110,7 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val)
>>   * @x: value to byteswap
>>   */
>>  #ifdef __HAVE_BUILTIN_BSWAP32__
>> -#define __swab32(x) __builtin_bswap32((__u32)(x))
>> +#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
>>  #else
>>  #define __swab32(x)                            \
>>         (__builtin_constant_p((__u32)(x)) ?     \
>
>>
>
> I wonder if this doesn't break switch statement that requires a
> constant expression, there few cases like this over the kernel.
>
> switch(val) {
> case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_FCPRSP):
>
> http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c#L458
>

I'm asking because sparse and checkpatch doesn't agree on that ping
sparse issues
'error: bad constant expression'
When changing to __constant_cpu_to_le32 sparse is happy but
checkpatch.ps is complaining
__constant_cpu_to_le32 should be cpu_to_le32



 Thanks
 Tomas

WARNING: multiple messages have this Message-ID (diff)
From: Tomas Winkler <tomasw@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	mm-commits@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-scsi@vger.kernel.org, jpoimboe@redhat.com,
	Martin Jambor <mjambor@suse.cz>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Denys Vlasenko <dvlasenk@redhat.com>, Thomas Graf <tgraf@suug.ch>,
	Peter Zijlstra <peterz@infradead.org>,
	David Rientjes <rientjes@google.com>,
	Ingo Molnar <mingo@kernel.org>,
	Himanshu Madhani <himanshu.madhani@qlogic.com>,
	Dept-Eng QLA2xxx Upstream <qla2xxx-upstream@qlogic.com>,
	Jan Hubicka <hubicka@ucw.cz>,
	"Amir (Jer)" <amir.jer.levy@intel.com>
Subject: Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug
Date: Wed, 22 Jun 2016 11:24:50 +0300	[thread overview]
Message-ID: <CA+i0qc74R9Qfy8r+an4cwXQvtrk8W-=zXe3+2VgWft=J3EpV9Q@mail.gmail.com> (raw)
In-Reply-To: <CA+i0qc6iCDx44hbX-VWvhinXtPBFS_wcQ3h7abNMjJpWfvbsug@mail.gmail.com>

On Tue, Jun 21, 2016 at 12:02 PM, Tomas Winkler <tomasw@gmail.com> wrote:
> On Tue, May 3, 2016 at 9:36 AM, Arnd Bergmann <arnd@arndb.de> wrote:
>> On Monday 02 May 2016 16:32:25 Andrew Morton wrote:
>>> On Tue, 03 May 2016 01:10:16 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
>>>
>>> > On Monday 02 May 2016 16:02:18 Andrew Morton wrote:
>>> > > On Mon, 02 May 2016 23:48:19 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
>>> > >
>>> > > > This is another attempt to avoid a regression in wwn_to_u64() after
>>> > > > that started using get_unaligned_be64(), which in turn ran into a
>>> > > > bug on gcc-4.9 through 6.1.
>>> > >
>>> > > I'm still getting a couple screenfuls of things like
>>> > >
>>> > > net/tipc/name_distr.c: In function 'tipc_named_process_backlog':
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'unsigned int'
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 4 has type 'unsigned int'
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 5 has type 'unsigned int'
>>> > > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', but argument 7 has type 'unsigned int'
>>> >
>>> > I've built a few thousand kernels (arm32 with gcc-6.1) with the patch applied,
>>> > but didn't see this one. What target architecture and compiler version produced
>>> > this? Does it go away if you add a (__u32) cast? I don't even know what the
>>> > warning is trying to tell me.
>>>
>>> heh, I didn't actually read it.
>>>
>>> Hopefully we can write this off as a gcc-4.4.4 glitch. 4.8.4 is OK.
>>
>> Ah, old compiler. I've tried gcc-4.3 now on ARM, and I don't get this warning
>> (just a lot "may be used uninitialized"), but unlike gcc-4.4, my version doesn't
>> actually get into the code path I have changed because __builtin_bswap32 was only
>> introduced with 4.4.
>>
>> I don't have gcc-4.4 and 4.5 here, but the warning does show up with 4.6, 4.7
>> and 4.8:
>>
>> drivers/soc/sunxi/sunxi_sram.c: In function ‘sunxi_sram_show’:
>> drivers/soc/sunxi/sunxi_sram.c:103:7: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
>>
>> 4.8 is probably still common enough that we should try to address this.
>> This change addresses the problem for me with ARM gcc-4.8, but adding
>> two more type casts. This also makes the 16/32/64 bit swaps all
>> look the same. I would expect this to also have the same effect on 4.4.
>>
>> Please fold into the previous patch.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>>
>> diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
>> index d737804af181..8f3a8f606fd9 100644
>> --- a/include/uapi/linux/swab.h
>> +++ b/include/uapi/linux/swab.h
>> @@ -97,7 +97,7 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val)
>>   * @x: value to byteswap
>>   */
>>  #ifdef __HAVE_BUILTIN_BSWAP16__
>> -#define __swab16(x) __builtin_bswap16((__u16)(x))
>> +#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
>>  #else
>>  #define __swab16(x)                            \
>>         (__builtin_constant_p((__u16)(x)) ?     \
>> @@ -110,7 +110,7 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val)
>>   * @x: value to byteswap
>>   */
>>  #ifdef __HAVE_BUILTIN_BSWAP32__
>> -#define __swab32(x) __builtin_bswap32((__u32)(x))
>> +#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
>>  #else
>>  #define __swab32(x)                            \
>>         (__builtin_constant_p((__u32)(x)) ?     \
>
>>
>
> I wonder if this doesn't break switch statement that requires a
> constant expression, there few cases like this over the kernel.
>
> switch(val) {
> case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_FCPRSP):
>
> http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c#L458
>

I'm asking because sparse and checkpatch doesn't agree on that ping
sparse issues
'error: bad constant expression'
When changing to __constant_cpu_to_le32 sparse is happy but
checkpatch.ps is complaining
__constant_cpu_to_le32 should be cpu_to_le32



 Thanks
 Tomas
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-06-22  8:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-02 21:48 [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Arnd Bergmann
2016-05-02 23:02 ` Andrew Morton
2016-05-02 23:10   ` Arnd Bergmann
2016-05-02 23:32     ` Andrew Morton
2016-05-02 23:32     ` Andrew Morton
2016-05-03  6:36       ` Arnd Bergmann
2016-06-21  9:02         ` Tomas Winkler
2016-06-21  9:02           ` Tomas Winkler
2016-06-22  8:24           ` Tomas Winkler [this message]
2016-06-22  8:24             ` Tomas Winkler
2016-06-22  9:59             ` Arnd Bergmann
2016-06-22 10:25               ` Levy, Amir (Jer)
2016-06-22 11:44                 ` Tomas Winkler
2016-06-22 12:25                   ` Arnd Bergmann
2016-06-23  6:27                     ` Tomas Winkler
2016-06-23  9:29                       ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+i0qc74R9Qfy8r+an4cwXQvtrk8W-=zXe3+2VgWft=J3EpV9Q@mail.gmail.com' \
    --to=tomasw@gmail.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=amir.jer.levy@intel.com \
    --cc=arnd@arndb.de \
    --cc=dvlasenk@redhat.com \
    --cc=himanshu.madhani@qlogic.com \
    --cc=hubicka@ucw.cz \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mingo@kernel.org \
    --cc=mjambor@suse.cz \
    --cc=mm-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=qla2xxx-upstream@qlogic.com \
    --cc=rientjes@google.com \
    --cc=tgraf@suug.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.