From: Mark Rutland <mark.rutland@arm.com>
To: kernel test robot <lkp@intel.com>
Cc: kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: include/asm-generic/cmpxchg.h:37:39: sparse: sparse: cast truncates bits from constant value (deadbeef becomes ef)
Date: Fri, 26 Nov 2021 11:03:23 +0000 [thread overview]
Message-ID: <YaC++05+X4RYgdLh@FVFF77S0Q05N> (raw)
In-Reply-To: <202111240654.4qXNBmtC-lkp@intel.com>
Hi,
On Wed, Nov 24, 2021 at 06:19:48AM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 136057256686de39cc3a07c2e39ef6bc43003ff6
> commit: c7178cdecdbef8321f418fac55f3afaca3bb4c96 locking/atomic: h8300: use asm-generic exclusively
> date: 6 months ago
> config: h8300-randconfig-s031-20211117 (https://download.01.org/0day-ci/archive/20211124/202111240654.4qXNBmtC-lkp@intel.com/config.gz)
> compiler: h8300-linux-gcc (GCC) 11.2.0
> reproduce:
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # apt-get install sparse
> # sparse version: v0.6.4-dirty
> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c7178cdecdbef8321f418fac55f3afaca3bb4c96
> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout c7178cdecdbef8321f418fac55f3afaca3bb4c96
> # save the config file to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=h8300 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
>
> sparse warnings: (new ones prefixed by >>)
> lib/atomic64_test.c: note: in included file (through arch/h8300/include/generated/asm/cmpxchg.h, include/asm-generic/atomic.h, arch/h8300/include/generated/asm/atomic.h, ...):
> >> include/asm-generic/cmpxchg.h:37:39: sparse: sparse: cast truncates bits from constant value (deadbeef becomes ef)
> >> include/asm-generic/cmpxchg.h:48:40: sparse: sparse: cast truncates bits from constant value (deadbeef becomes beef)
> >> include/asm-generic/cmpxchg.h:37:39: sparse: sparse: cast truncates bits from constant value (deadbeef becomes ef)
> >> include/asm-generic/cmpxchg.h:48:40: sparse: sparse: cast truncates bits from constant value (deadbeef becomes beef)
> >> include/asm-generic/cmpxchg.h:37:39: sparse: sparse: cast truncates bits from constant value (deadbeef becomes ef)
> >> include/asm-generic/cmpxchg.h:48:40: sparse: sparse: cast truncates bits from constant value (deadbeef becomes beef)
> >> include/asm-generic/cmpxchg.h:37:39: sparse: sparse: cast truncates bits from constant value (deadbeef becomes ef)
> >> include/asm-generic/cmpxchg.h:48:40: sparse: sparse: cast truncates bits from constant value (deadbeef becomes beef)
This is the expected behaviour for the code below. The truncation on line 37 is
when we assign to a u8, and the truncation on line 48 is when we assign to a
u16.
I'm a little confused by the wording of the warning, because there's no cast on
the value being assigned. I'm not sure if that's just misleading wording from
sparse. Would a cast on the right hand side of the assignment be sufficient to
suppress this, e.g.
*(volatile u8 *)pte = (u8)x;
... because if so, maybe it's worth adding, unless we think this warning would
be useful for when this situation crops up outside of test code (in which case
we should just ignore it for now).
Thanks,
Mark.
> vim +37 include/asm-generic/cmpxchg.h
>
> b4816afa398670 David Howells 2012-03-28 24
> b4816afa398670 David Howells 2012-03-28 25 static inline
> b4816afa398670 David Howells 2012-03-28 26 unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
> b4816afa398670 David Howells 2012-03-28 27 {
> b4816afa398670 David Howells 2012-03-28 28 unsigned long ret, flags;
> b4816afa398670 David Howells 2012-03-28 29
> b4816afa398670 David Howells 2012-03-28 30 switch (size) {
> b4816afa398670 David Howells 2012-03-28 31 case 1:
> b4816afa398670 David Howells 2012-03-28 32 #ifdef __xchg_u8
> b4816afa398670 David Howells 2012-03-28 33 return __xchg_u8(x, ptr);
> b4816afa398670 David Howells 2012-03-28 34 #else
> b4816afa398670 David Howells 2012-03-28 35 local_irq_save(flags);
> b4816afa398670 David Howells 2012-03-28 36 ret = *(volatile u8 *)ptr;
> b4816afa398670 David Howells 2012-03-28 @37 *(volatile u8 *)ptr = x;
> b4816afa398670 David Howells 2012-03-28 38 local_irq_restore(flags);
> b4816afa398670 David Howells 2012-03-28 39 return ret;
> b4816afa398670 David Howells 2012-03-28 40 #endif /* __xchg_u8 */
> b4816afa398670 David Howells 2012-03-28 41
> b4816afa398670 David Howells 2012-03-28 42 case 2:
> b4816afa398670 David Howells 2012-03-28 43 #ifdef __xchg_u16
> b4816afa398670 David Howells 2012-03-28 44 return __xchg_u16(x, ptr);
> b4816afa398670 David Howells 2012-03-28 45 #else
> b4816afa398670 David Howells 2012-03-28 46 local_irq_save(flags);
> b4816afa398670 David Howells 2012-03-28 47 ret = *(volatile u16 *)ptr;
> b4816afa398670 David Howells 2012-03-28 @48 *(volatile u16 *)ptr = x;
> b4816afa398670 David Howells 2012-03-28 49 local_irq_restore(flags);
> b4816afa398670 David Howells 2012-03-28 50 return ret;
> b4816afa398670 David Howells 2012-03-28 51 #endif /* __xchg_u16 */
> b4816afa398670 David Howells 2012-03-28 52
> b4816afa398670 David Howells 2012-03-28 53 case 4:
> b4816afa398670 David Howells 2012-03-28 54 #ifdef __xchg_u32
> b4816afa398670 David Howells 2012-03-28 55 return __xchg_u32(x, ptr);
> b4816afa398670 David Howells 2012-03-28 56 #else
> b4816afa398670 David Howells 2012-03-28 57 local_irq_save(flags);
> b4816afa398670 David Howells 2012-03-28 58 ret = *(volatile u32 *)ptr;
> b4816afa398670 David Howells 2012-03-28 59 *(volatile u32 *)ptr = x;
> b4816afa398670 David Howells 2012-03-28 60 local_irq_restore(flags);
> b4816afa398670 David Howells 2012-03-28 61 return ret;
> b4816afa398670 David Howells 2012-03-28 62 #endif /* __xchg_u32 */
> b4816afa398670 David Howells 2012-03-28 63
>
> :::::: The code at line 37 was first introduced by commit
> :::::: b4816afa3986704d1404fc48e931da5135820472 Move the asm-generic/system.h xchg() implementation to asm-generic/cmpxchg.h
>
> :::::: TO: David Howells <dhowells@redhat.com>
> :::::: CC: David Howells <dhowells@redhat.com>
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
next prev parent reply other threads:[~2021-11-26 11:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 22:19 include/asm-generic/cmpxchg.h:37:39: sparse: sparse: cast truncates bits from constant value (deadbeef becomes ef) kernel test robot
2021-11-26 11:03 ` Mark Rutland [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-01-01 11:04 kernel test robot
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=YaC++05+X4RYgdLh@FVFF77S0Q05N \
--to=mark.rutland@arm.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox