Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [axboe-block:for-6.10/io_uring 42/42] io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op')
@ 2024-03-29  6:23 kernel test robot
  2024-03-29 22:04 ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2024-03-29  6:23 UTC (permalink / raw
  Cc: oe-kbuild-all, llvm

TO: Gabriel Krisman Bertazi <krisman@suse.de>
CC: Jens Axboe <axboe@kernel.dk>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-6.10/io_uring
head:   2c1b098239d277b21a006cc0c8009ad7bf1b6189
commit: 2c1b098239d277b21a006cc0c8009ad7bf1b6189 [42/42] io_uring: Avoid anonymous enums in io_uring uapi
config: s390-allnoconfig (https://download.01.org/0day-ci/archive/20240329/202403291458.6AjzdI64-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 79ba323bdd0843275019e16b6e9b35133677c514)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240329/202403291458.6AjzdI64-lkp@intel.com/reproduce)

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/202403291458.6AjzdI64-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from io_uring/register.c:9:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:5:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
   In file included from include/linux/cpu.h:17:
   In file included from include/linux/node.h:18:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:173:
   In file included from arch/s390/include/asm/mmu_context.h:11:
   In file included from arch/s390/include/asm/pgalloc.h:18:
   In file included from include/linux/mm.h:2208:
   include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     522 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from io_uring/register.c:29:
   In file included from io_uring/napi.h:8:
   In file included from include/net/busy_poll.h:15:
   In file included from include/linux/netdevice.h:38:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:28:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     547 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     560 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
         |                                                           ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
     102 | #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
         |                                                      ^
   In file included from io_uring/register.c:29:
   In file included from io_uring/napi.h:8:
   In file included from include/net/busy_poll.h:15:
   In file included from include/linux/netdevice.h:38:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:28:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     573 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                                                           ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
     115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
         |                                                      ^
   In file included from io_uring/register.c:29:
   In file included from io_uring/napi.h:8:
   In file included from include/net/busy_poll.h:15:
   In file included from include/linux/netdevice.h:38:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:28:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     584 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     594 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     604 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     692 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     700 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     708 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     717 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     726 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     735 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
>> io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op') [-Wenum-enum-conversion]
     175 |         if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
         |                               ^~~~~~~~~~~~~~~~~~~~~~~
   io_uring/register.c:31:58: note: expanded from macro 'IORING_MAX_RESTRICTIONS'
      31 | #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
         |                                  ~~~~~~~~~~~~~~~~~~~~~~~ ^
      32 |                                  IORING_REGISTER_LAST + IORING_OP_LAST)
         |                                  ~~~~~~~~~~~~~~~~~~~~
   14 warnings generated.


vim +175 io_uring/register.c

c43203154d8ac5 Jens Axboe 2023-12-19  159  
c43203154d8ac5 Jens Axboe 2023-12-19  160  static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
c43203154d8ac5 Jens Axboe 2023-12-19  161  					   void __user *arg, unsigned int nr_args)
c43203154d8ac5 Jens Axboe 2023-12-19  162  {
c43203154d8ac5 Jens Axboe 2023-12-19  163  	struct io_uring_restriction *res;
c43203154d8ac5 Jens Axboe 2023-12-19  164  	size_t size;
c43203154d8ac5 Jens Axboe 2023-12-19  165  	int i, ret;
c43203154d8ac5 Jens Axboe 2023-12-19  166  
c43203154d8ac5 Jens Axboe 2023-12-19  167  	/* Restrictions allowed only if rings started disabled */
c43203154d8ac5 Jens Axboe 2023-12-19  168  	if (!(ctx->flags & IORING_SETUP_R_DISABLED))
c43203154d8ac5 Jens Axboe 2023-12-19  169  		return -EBADFD;
c43203154d8ac5 Jens Axboe 2023-12-19  170  
c43203154d8ac5 Jens Axboe 2023-12-19  171  	/* We allow only a single restrictions registration */
c43203154d8ac5 Jens Axboe 2023-12-19  172  	if (ctx->restrictions.registered)
c43203154d8ac5 Jens Axboe 2023-12-19  173  		return -EBUSY;
c43203154d8ac5 Jens Axboe 2023-12-19  174  
c43203154d8ac5 Jens Axboe 2023-12-19 @175  	if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
c43203154d8ac5 Jens Axboe 2023-12-19  176  		return -EINVAL;
c43203154d8ac5 Jens Axboe 2023-12-19  177  
c43203154d8ac5 Jens Axboe 2023-12-19  178  	size = array_size(nr_args, sizeof(*res));
c43203154d8ac5 Jens Axboe 2023-12-19  179  	if (size == SIZE_MAX)
c43203154d8ac5 Jens Axboe 2023-12-19  180  		return -EOVERFLOW;
c43203154d8ac5 Jens Axboe 2023-12-19  181  
c43203154d8ac5 Jens Axboe 2023-12-19  182  	res = memdup_user(arg, size);
c43203154d8ac5 Jens Axboe 2023-12-19  183  	if (IS_ERR(res))
c43203154d8ac5 Jens Axboe 2023-12-19  184  		return PTR_ERR(res);
c43203154d8ac5 Jens Axboe 2023-12-19  185  
c43203154d8ac5 Jens Axboe 2023-12-19  186  	ret = 0;
c43203154d8ac5 Jens Axboe 2023-12-19  187  
c43203154d8ac5 Jens Axboe 2023-12-19  188  	for (i = 0; i < nr_args; i++) {
c43203154d8ac5 Jens Axboe 2023-12-19  189  		switch (res[i].opcode) {
c43203154d8ac5 Jens Axboe 2023-12-19  190  		case IORING_RESTRICTION_REGISTER_OP:
c43203154d8ac5 Jens Axboe 2023-12-19  191  			if (res[i].register_op >= IORING_REGISTER_LAST) {
c43203154d8ac5 Jens Axboe 2023-12-19  192  				ret = -EINVAL;
c43203154d8ac5 Jens Axboe 2023-12-19  193  				goto out;
c43203154d8ac5 Jens Axboe 2023-12-19  194  			}
c43203154d8ac5 Jens Axboe 2023-12-19  195  
c43203154d8ac5 Jens Axboe 2023-12-19  196  			__set_bit(res[i].register_op,
c43203154d8ac5 Jens Axboe 2023-12-19  197  				  ctx->restrictions.register_op);
c43203154d8ac5 Jens Axboe 2023-12-19  198  			break;
c43203154d8ac5 Jens Axboe 2023-12-19  199  		case IORING_RESTRICTION_SQE_OP:
c43203154d8ac5 Jens Axboe 2023-12-19  200  			if (res[i].sqe_op >= IORING_OP_LAST) {
c43203154d8ac5 Jens Axboe 2023-12-19  201  				ret = -EINVAL;
c43203154d8ac5 Jens Axboe 2023-12-19  202  				goto out;
c43203154d8ac5 Jens Axboe 2023-12-19  203  			}
c43203154d8ac5 Jens Axboe 2023-12-19  204  
c43203154d8ac5 Jens Axboe 2023-12-19  205  			__set_bit(res[i].sqe_op, ctx->restrictions.sqe_op);
c43203154d8ac5 Jens Axboe 2023-12-19  206  			break;
c43203154d8ac5 Jens Axboe 2023-12-19  207  		case IORING_RESTRICTION_SQE_FLAGS_ALLOWED:
c43203154d8ac5 Jens Axboe 2023-12-19  208  			ctx->restrictions.sqe_flags_allowed = res[i].sqe_flags;
c43203154d8ac5 Jens Axboe 2023-12-19  209  			break;
c43203154d8ac5 Jens Axboe 2023-12-19  210  		case IORING_RESTRICTION_SQE_FLAGS_REQUIRED:
c43203154d8ac5 Jens Axboe 2023-12-19  211  			ctx->restrictions.sqe_flags_required = res[i].sqe_flags;
c43203154d8ac5 Jens Axboe 2023-12-19  212  			break;
c43203154d8ac5 Jens Axboe 2023-12-19  213  		default:
c43203154d8ac5 Jens Axboe 2023-12-19  214  			ret = -EINVAL;
c43203154d8ac5 Jens Axboe 2023-12-19  215  			goto out;
c43203154d8ac5 Jens Axboe 2023-12-19  216  		}
c43203154d8ac5 Jens Axboe 2023-12-19  217  	}
c43203154d8ac5 Jens Axboe 2023-12-19  218  
c43203154d8ac5 Jens Axboe 2023-12-19  219  out:
c43203154d8ac5 Jens Axboe 2023-12-19  220  	/* Reset all restrictions if an error happened */
c43203154d8ac5 Jens Axboe 2023-12-19  221  	if (ret != 0)
c43203154d8ac5 Jens Axboe 2023-12-19  222  		memset(&ctx->restrictions, 0, sizeof(ctx->restrictions));
c43203154d8ac5 Jens Axboe 2023-12-19  223  	else
c43203154d8ac5 Jens Axboe 2023-12-19  224  		ctx->restrictions.registered = true;
c43203154d8ac5 Jens Axboe 2023-12-19  225  
c43203154d8ac5 Jens Axboe 2023-12-19  226  	kfree(res);
c43203154d8ac5 Jens Axboe 2023-12-19  227  	return ret;
c43203154d8ac5 Jens Axboe 2023-12-19  228  }
c43203154d8ac5 Jens Axboe 2023-12-19  229  

:::::: The code at line 175 was first introduced by commit
:::::: c43203154d8ac579537aa0c7802b77d463b1f53a io_uring/register: move io_uring_register(2) related code to register.c

:::::: TO: Jens Axboe <axboe@kernel.dk>
:::::: CC: Jens Axboe <axboe@kernel.dk>

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

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

* Re: [axboe-block:for-6.10/io_uring 42/42] io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op')
  2024-03-29  6:23 [axboe-block:for-6.10/io_uring 42/42] io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op') kernel test robot
@ 2024-03-29 22:04 ` Gabriel Krisman Bertazi
  2024-03-29 23:15   ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-03-29 22:04 UTC (permalink / raw
  To: kernel test robot; +Cc: oe-kbuild-all, llvm, io-uring

kernel test robot <lkp@intel.com> writes:

[+ io_uring list ]

>>> io_uring/register.c:175:24: warning: arithmetic between different
> enumeration types ('enum io_uring_register_restriction_op' and 'enum
> io_uring_register_op') [-Wenum-enum-conversion]
>      175 |         if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
>          |                               ^~~~~~~~~~~~~~~~~~~~~~~
>    io_uring/register.c:31:58: note: expanded from macro 'IORING_MAX_RESTRICTIONS'
>       31 | #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
>          |                                  ~~~~~~~~~~~~~~~~~~~~~~~ ^
>       32 |                                  IORING_REGISTER_LAST + IORING_OP_LAST)
>          |                                  ~~~~~~~~~~~~~~~~~~~~
>    14 warnings generated.

hm.

Do we want to fix?  The arithmetic is safe here.  I actually tried
triggering the warning with gcc, but even with -Wenum-conversion in
gcc-12 (which is in -Wextra and we don't use in the kernel build), I
couldn't do it.  only llvm catches this.

can we explicit cast to int to silent it?

-- 
Gabriel Krisman Bertazi

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

* Re: [axboe-block:for-6.10/io_uring 42/42] io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op')
  2024-03-29 22:04 ` Gabriel Krisman Bertazi
@ 2024-03-29 23:15   ` Jens Axboe
  2024-04-01 19:35     ` Nathan Chancellor
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2024-03-29 23:15 UTC (permalink / raw
  To: Gabriel Krisman Bertazi, kernel test robot; +Cc: oe-kbuild-all, llvm, io-uring

On 3/29/24 4:04 PM, Gabriel Krisman Bertazi wrote:
> kernel test robot <lkp@intel.com> writes:
> 
> [+ io_uring list ]
> 
>>>> io_uring/register.c:175:24: warning: arithmetic between different
>> enumeration types ('enum io_uring_register_restriction_op' and 'enum
>> io_uring_register_op') [-Wenum-enum-conversion]
>>      175 |         if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
>>          |                               ^~~~~~~~~~~~~~~~~~~~~~~
>>    io_uring/register.c:31:58: note: expanded from macro 'IORING_MAX_RESTRICTIONS'
>>       31 | #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
>>          |                                  ~~~~~~~~~~~~~~~~~~~~~~~ ^
>>       32 |                                  IORING_REGISTER_LAST + IORING_OP_LAST)
>>          |                                  ~~~~~~~~~~~~~~~~~~~~
>>    14 warnings generated.
> 
> hm.
> 
> Do we want to fix?  The arithmetic is safe here.  I actually tried
> triggering the warning with gcc, but even with -Wenum-conversion in
> gcc-12 (which is in -Wextra and we don't use in the kernel build), I
> couldn't do it.  only llvm catches this.
> 
> can we explicit cast to int to silent it?

I don't think we care, there are others like it in the kernel already.
Plus you need some magic warning incantation to hit it, clang by default
is not going to be enough.

-- 
Jens Axboe


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

* Re: [axboe-block:for-6.10/io_uring 42/42] io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op')
  2024-03-29 23:15   ` Jens Axboe
@ 2024-04-01 19:35     ` Nathan Chancellor
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2024-04-01 19:35 UTC (permalink / raw
  To: Jens Axboe
  Cc: Gabriel Krisman Bertazi, kernel test robot, oe-kbuild-all, llvm,
	io-uring

On Fri, Mar 29, 2024 at 05:15:44PM -0600, Jens Axboe wrote:
> On 3/29/24 4:04 PM, Gabriel Krisman Bertazi wrote:
> > kernel test robot <lkp@intel.com> writes:
> > 
> > [+ io_uring list ]
> > 
> >>>> io_uring/register.c:175:24: warning: arithmetic between different
> >> enumeration types ('enum io_uring_register_restriction_op' and 'enum
> >> io_uring_register_op') [-Wenum-enum-conversion]
> >>      175 |         if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
> >>          |                               ^~~~~~~~~~~~~~~~~~~~~~~
> >>    io_uring/register.c:31:58: note: expanded from macro 'IORING_MAX_RESTRICTIONS'
> >>       31 | #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
> >>          |                                  ~~~~~~~~~~~~~~~~~~~~~~~ ^
> >>       32 |                                  IORING_REGISTER_LAST + IORING_OP_LAST)
> >>          |                                  ~~~~~~~~~~~~~~~~~~~~
> >>    14 warnings generated.
> > 
> > hm.
> > 
> > Do we want to fix?  The arithmetic is safe here.  I actually tried
> > triggering the warning with gcc, but even with -Wenum-conversion in
> > gcc-12 (which is in -Wextra and we don't use in the kernel build), I
> > couldn't do it.  only llvm catches this.
> > 
> > can we explicit cast to int to silent it?
> 
> I don't think we care, there are others like it in the kernel already.
> Plus you need some magic warning incantation to hit it, clang by default
> is not going to be enough.

The magic incantion would be W=1 after commit 75b5ab134bb5 ("kbuild:
Move -Wenum-{compare-conditional,enum-conversion} into W=1") but yes,
there are plenty of other instances of this warning in the kernel and if
the arithmetic is safe, ignoring the warning is perfectly fine in my
opinion. The primary reason it is in W=1 rather than off by default is
to see how many current instances may be bugs and see what new instances
may pop up, as they may be unsafe conversions. We will have to come up
with some way to annotate safe conversions if we want to turn this on by
default (which is still being determined at this point). You do also
have to have a tip of tree Clang to see this at the moment as well.

Cheers,
Nathan

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

end of thread, other threads:[~2024-04-01 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-29  6:23 [axboe-block:for-6.10/io_uring 42/42] io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op') kernel test robot
2024-03-29 22:04 ` Gabriel Krisman Bertazi
2024-03-29 23:15   ` Jens Axboe
2024-04-01 19:35     ` Nathan Chancellor

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 read-only IMAP folder(s) and NNTP newsgroup(s).