Linux RAID subsystem development
 help / color / mirror / Atom feed
* [song-md:md-next 25/29] drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
@ 2023-06-14 12:32 kernel test robot
  2023-06-15  1:47 ` Yu Kuai
  0 siblings, 1 reply; 3+ messages in thread
From: kernel test robot @ 2023-06-14 12:32 UTC (permalink / raw)
  To: Yu Kuai; +Cc: llvm, oe-kbuild-all, linux-raid, Song Liu

tree:   git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
head:   460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4
commit: 8295efbe68c080047e98d9c0eb5cb933b238a8cb [25/29] md/raid1-10: factor out a helper to submit normal write
config: arm-randconfig-r026-20230612 (https://download.01.org/0day-ci/archive/20230614/202306142042.fmjfmTF8-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?id=8295efbe68c080047e98d9c0eb5cb933b238a8cb
        git remote add song-md git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git
        git fetch --no-tags song-md md-next
        git checkout 8295efbe68c080047e98d9c0eb5cb933b238a8cb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306142042.fmjfmTF8-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/md/raid10.c:80:
>> drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
     117 |         struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
         |                                ^
   1 error generated.


vim +117 drivers/md/raid1-10.c

   113	
   114	
   115	static inline void raid1_submit_write(struct bio *bio)
   116	{
 > 117		struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
   118	
   119		bio->bi_next = NULL;
   120		bio_set_dev(bio, rdev->bdev);
   121		if (test_bit(Faulty, &rdev->flags))
   122			bio_io_error(bio);
   123		else if (unlikely(bio_op(bio) ==  REQ_OP_DISCARD &&
   124				  !bdev_max_discard_sectors(bio->bi_bdev)))
   125			/* Just ignore it */
   126			bio_endio(bio);
   127		else
   128			submit_bio_noacct(bio);
   129	}
   130	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [song-md:md-next 25/29] drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
  2023-06-14 12:32 [song-md:md-next 25/29] drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *' kernel test robot
@ 2023-06-15  1:47 ` Yu Kuai
  2023-06-15 15:41   ` Nathan Chancellor
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Kuai @ 2023-06-15  1:47 UTC (permalink / raw)
  To: kernel test robot; +Cc: llvm, oe-kbuild-all, linux-raid, Song Liu, yukuai (C)

Hi,

在 2023/06/14 20:32, kernel test robot 写道:
> tree:   git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
> head:   460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4
> commit: 8295efbe68c080047e98d9c0eb5cb933b238a8cb [25/29] md/raid1-10: factor out a helper to submit normal write
> config: arm-randconfig-r026-20230612 (https://download.01.org/0day-ci/archive/20230614/202306142042.fmjfmTF8-lkp@intel.com/config)
> compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
> reproduce (this is a W=1 build):
>          mkdir -p ~/bin
>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>          chmod +x ~/bin/make.cross
>          # install arm cross compiling tool for clang build
>          # apt-get install binutils-arm-linux-gnueabi
>          # https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?id=8295efbe68c080047e98d9c0eb5cb933b238a8cb
>          git remote add song-md git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git
>          git fetch --no-tags song-md md-next
>          git checkout 8295efbe68c080047e98d9c0eb5cb933b238a8cb
>          # save the config file
>          mkdir build_dir && cp config build_dir/.config
>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig
>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202306142042.fmjfmTF8-lkp@intel.com/
> 
> All errors (new ones prefixed by >>):
> 
>     In file included from drivers/md/raid10.c:80:
>>> drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
>       117 |         struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;

I didn't hit this warning with W=1 in my local machine, so I guess this
might related to compiler. I'm using gcc (GCC) 12.2.1 and here is clang
version 17.0.0.

I'm planning to get rid of all these weird usage, which is used a lot in
raid, to borrow a field to store something else temporarily, but this
might take sometime.

Can someone help to confirm following change can prevent this warning?

struct md_rdev *rdev = (void *)bio->bi_bdev

Thanks,
Kuai

>           |                                ^
>     1 error generated.
> 
> 
> vim +117 drivers/md/raid1-10.c
> 
>     113	
>     114	
>     115	static inline void raid1_submit_write(struct bio *bio)
>     116	{
>   > 117		struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
>     118	
>     119		bio->bi_next = NULL;
>     120		bio_set_dev(bio, rdev->bdev);
>     121		if (test_bit(Faulty, &rdev->flags))
>     122			bio_io_error(bio);
>     123		else if (unlikely(bio_op(bio) ==  REQ_OP_DISCARD &&
>     124				  !bdev_max_discard_sectors(bio->bi_bdev)))
>     125			/* Just ignore it */
>     126			bio_endio(bio);
>     127		else
>     128			submit_bio_noacct(bio);
>     129	}
>     130	
> 


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

* Re: [song-md:md-next 25/29] drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
  2023-06-15  1:47 ` Yu Kuai
@ 2023-06-15 15:41   ` Nathan Chancellor
  0 siblings, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2023-06-15 15:41 UTC (permalink / raw)
  To: Yu Kuai
  Cc: kernel test robot, llvm, oe-kbuild-all, linux-raid, Song Liu,
	yukuai (C), Kees Cook

On Thu, Jun 15, 2023 at 09:47:24AM +0800, Yu Kuai wrote:
> Hi,
> 
> 在 2023/06/14 20:32, kernel test robot 写道:
> > tree:   git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
> > head:   460af1f9d9e62acce4a21f9bd00b5bcd5963bcd4
> > commit: 8295efbe68c080047e98d9c0eb5cb933b238a8cb [25/29] md/raid1-10: factor out a helper to submit normal write
> > config: arm-randconfig-r026-20230612 (https://download.01.org/0day-ci/archive/20230614/202306142042.fmjfmTF8-lkp@intel.com/config)
> > compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
> > reproduce (this is a W=1 build):
> >          mkdir -p ~/bin
> >          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >          chmod +x ~/bin/make.cross
> >          # install arm cross compiling tool for clang build
> >          # apt-get install binutils-arm-linux-gnueabi
> >          # https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?id=8295efbe68c080047e98d9c0eb5cb933b238a8cb
> >          git remote add song-md git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git
> >          git fetch --no-tags song-md md-next
> >          git checkout 8295efbe68c080047e98d9c0eb5cb933b238a8cb
> >          # save the config file
> >          mkdir build_dir && cp config build_dir/.config
> >          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig
> >          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/
> > 
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202306142042.fmjfmTF8-lkp@intel.com/
> > 
> > All errors (new ones prefixed by >>):
> > 
> >     In file included from drivers/md/raid10.c:80:
> > > > drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *'
> >       117 |         struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
> 
> I didn't hit this warning with W=1 in my local machine, so I guess this
> might related to compiler. I'm using gcc (GCC) 12.2.1 and here is clang
> version 17.0.0.

Interesting, I would have expected the GCC plugin to have the same
behavior as clang (which has randstruct in the compiler proper) and
error when casting randomized structures but I just tested with
aarch64-linux-gnu-gcc (GCC) 13.1.0 and drivers/md/raid10.c builds just
fine, so confirmed.

For the record, this is a hard error, not a warning, so the build is
broken in -next because of this:

https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/5278732212/jobs/9552208141

> I'm planning to get rid of all these weird usage, which is used a lot in
> raid, to borrow a field to store something else temporarily, but this
> might take sometime.
> 
> Can someone help to confirm following change can prevent this warning?
> 
> struct md_rdev *rdev = (void *)bio->bi_bdev

Yes, this fixes the build.

In the future, if you need to reproduce issues with clang, I have
prebuilt versions of stable clang/LLVM available on kernel.org:

https://mirrors.edge.kernel.org/pub/tools/llvm/

Cheers,
Nathan

> >           |                                ^
> >     1 error generated.
> > 
> > 
> > vim +117 drivers/md/raid1-10.c
> > 
> >     113	
> >     114	
> >     115	static inline void raid1_submit_write(struct bio *bio)
> >     116	{
> >   > 117		struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
> >     118	
> >     119		bio->bi_next = NULL;
> >     120		bio_set_dev(bio, rdev->bdev);
> >     121		if (test_bit(Faulty, &rdev->flags))
> >     122			bio_io_error(bio);
> >     123		else if (unlikely(bio_op(bio) ==  REQ_OP_DISCARD &&
> >     124				  !bdev_max_discard_sectors(bio->bi_bdev)))
> >     125			/* Just ignore it */
> >     126			bio_endio(bio);
> >     127		else
> >     128			submit_bio_noacct(bio);
> >     129	}
> >     130	
> > 
> 
> 

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

end of thread, other threads:[~2023-06-15 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 12:32 [song-md:md-next 25/29] drivers/md/raid1-10.c:117:25: error: casting from randomized structure pointer type 'struct block_device *' to 'struct md_rdev *' kernel test robot
2023-06-15  1:47 ` Yu Kuai
2023-06-15 15:41   ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox