2021-05-03 18:08:15

by Dan Carpenter

[permalink] [raw]
Subject: [kbuild] fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a 64 bit type?

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 9ccce092fc64d19504fa54de4fd659e279cc92e7
commit: c2d0ad00d948de73c78f05d2b3e5bdfa605035cc virtiofs: implement dax read/write operations
config: i386-randconfig-m031-20210503 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a 64 bit type?

Old smatch warnings:
fs/fuse/dax.c:197 dmap_removemapping_list() error: uninitialized symbol 'ret'.

vim +113 fs/fuse/dax.c

c2d0ad00d948de Vivek Goyal 2020-08-19 105 static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx,
c2d0ad00d948de Vivek Goyal 2020-08-19 106 struct fuse_dax_mapping *dmap, bool writable,
c2d0ad00d948de Vivek Goyal 2020-08-19 107 bool upgrade)
c2d0ad00d948de Vivek Goyal 2020-08-19 108 {
c2d0ad00d948de Vivek Goyal 2020-08-19 109 struct fuse_conn *fc = get_fuse_conn(inode);
c2d0ad00d948de Vivek Goyal 2020-08-19 110 struct fuse_conn_dax *fcd = fc->dax;
c2d0ad00d948de Vivek Goyal 2020-08-19 111 struct fuse_inode *fi = get_fuse_inode(inode);
c2d0ad00d948de Vivek Goyal 2020-08-19 112 struct fuse_setupmapping_in inarg;
c2d0ad00d948de Vivek Goyal 2020-08-19 @113 loff_t offset = start_idx << FUSE_DAX_SHIFT;

This is only an issue on 32 bit systems but "offset" is a 64bit and
"start_idx" is ulong.

c2d0ad00d948de Vivek Goyal 2020-08-19 114 FUSE_ARGS(args);
c2d0ad00d948de Vivek Goyal 2020-08-19 115 ssize_t err;
c2d0ad00d948de Vivek Goyal 2020-08-19 116
c2d0ad00d948de Vivek Goyal 2020-08-19 117 WARN_ON(fcd->nr_free_ranges < 0);
c2d0ad00d948de Vivek Goyal 2020-08-19 118
c2d0ad00d948de Vivek Goyal 2020-08-19 119 /* Ask fuse daemon to setup mapping */
c2d0ad00d948de Vivek Goyal 2020-08-19 120 memset(&inarg, 0, sizeof(inarg));
c2d0ad00d948de Vivek Goyal 2020-08-19 121 inarg.foffset = offset;
c2d0ad00d948de Vivek Goyal 2020-08-19 122 inarg.fh = -1;
c2d0ad00d948de Vivek Goyal 2020-08-19 123 inarg.moffset = dmap->window_offset;
c2d0ad00d948de Vivek Goyal 2020-08-19 124 inarg.len = FUSE_DAX_SZ;
c2d0ad00d948de Vivek Goyal 2020-08-19 125 inarg.flags |= FUSE_SETUPMAPPING_FLAG_READ;
c2d0ad00d948de Vivek Goyal 2020-08-19 126 if (writable)
c2d0ad00d948de Vivek Goyal 2020-08-19 127 inarg.flags |= FUSE_SETUPMAPPING_FLAG_WRITE;
c2d0ad00d948de Vivek Goyal 2020-08-19 128 args.opcode = FUSE_SETUPMAPPING;
c2d0ad00d948de Vivek Goyal 2020-08-19 129 args.nodeid = fi->nodeid;
c2d0ad00d948de Vivek Goyal 2020-08-19 130 args.in_numargs = 1;
c2d0ad00d948de Vivek Goyal 2020-08-19 131 args.in_args[0].size = sizeof(inarg);
c2d0ad00d948de Vivek Goyal 2020-08-19 132 args.in_args[0].value = &inarg;
c2d0ad00d948de Vivek Goyal 2020-08-19 133 err = fuse_simple_request(fc, &args);
c2d0ad00d948de Vivek Goyal 2020-08-19 134 if (err < 0)
c2d0ad00d948de Vivek Goyal 2020-08-19 135 return err;
c2d0ad00d948de Vivek Goyal 2020-08-19 136 dmap->writable = writable;
c2d0ad00d948de Vivek Goyal 2020-08-19 137 if (!upgrade) {
c2d0ad00d948de Vivek Goyal 2020-08-19 138 dmap->itn.start = dmap->itn.last = start_idx;
c2d0ad00d948de Vivek Goyal 2020-08-19 139 /* Protected by fi->dax->sem */
c2d0ad00d948de Vivek Goyal 2020-08-19 140 interval_tree_insert(&dmap->itn, &fi->dax->tree);
c2d0ad00d948de Vivek Goyal 2020-08-19 141 fi->dax->nr++;
c2d0ad00d948de Vivek Goyal 2020-08-19 142 }
c2d0ad00d948de Vivek Goyal 2020-08-19 143 return 0;
c2d0ad00d948de Vivek Goyal 2020-08-19 144 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]


2021-05-11 14:24:23

by Miklos Szeredi

[permalink] [raw]
Subject: Re: [kbuild] fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a 64 bit type?

On Mon, May 3, 2021 at 3:27 PM Dan Carpenter <[email protected]> wrote:
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 9ccce092fc64d19504fa54de4fd659e279cc92e7
> commit: c2d0ad00d948de73c78f05d2b3e5bdfa605035cc virtiofs: implement dax read/write operations
> config: i386-randconfig-m031-20210503 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
>
> New smatch warnings:
> fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a 64 bit type?

Yes.

But does it make any sense to enable virtiofs and/or dax on 32bit
guest? We sure aren't testing it, as seen from this bug report.

Vivek, what do you think?

Thanks,
Miklos

2021-05-11 14:55:29

by Vivek Goyal

[permalink] [raw]
Subject: Re: [kbuild] fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a 64 bit type?

On Tue, May 11, 2021 at 04:21:32PM +0200, Miklos Szeredi wrote:
> On Mon, May 3, 2021 at 3:27 PM Dan Carpenter <[email protected]> wrote:
> >
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 9ccce092fc64d19504fa54de4fd659e279cc92e7
> > commit: c2d0ad00d948de73c78f05d2b3e5bdfa605035cc virtiofs: implement dax read/write operations
> > config: i386-randconfig-m031-20210503 (attached as .config)
> > compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> >
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <[email protected]>
> > Reported-by: Dan Carpenter <[email protected]>
> >
> > New smatch warnings:
> > fs/fuse/dax.c:113 fuse_setup_one_mapping() warn: should 'start_idx << 21' be a 64 bit type?
>
> Yes.
>
> But does it make any sense to enable virtiofs and/or dax on 32bit
> guest? We sure aren't testing it, as seen from this bug report.
>
> Vivek, what do you think?

Hi Miklos,

We sure are not testing it but looks like it is possible to compile it
on 32 bit systems.

I can't think of a good reason that why virtiofs DAX should be disabled on
32 bit systems. So I sent a patch series to fix this warning here.

https://lore.kernel.org/linux-fsdevel/[email protected]/

Thanks
Vivek