2023-02-01 17:34:07

by kernel test robot

[permalink] [raw]
Subject: drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: c0b67534c95c537f7a506a06b98e5e85d72e2b7d
commit: 7e9c7ef83d785236f5a8c3761dd053fae9b92fb8 PCI/P2PDMA: Allow userspace VMA allocations through sysfs
date: 3 months ago
config: arm64-randconfig-s042-20230201 (https://download.01.org/0day-ci/archive/20230202/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.1.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-39-gce1a6720-dirty
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7e9c7ef83d785236f5a8c3761dd053fae9b92fb8
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 7e9c7ef83d785236f5a8c3761dd053fae9b92fb8
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/pci/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

sparse warnings: (new ones prefixed by >>)
>> drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression

vim +199 drivers/pci/p2pdma.c

193
194 static void p2pdma_page_free(struct page *page)
195 {
196 struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page->pgmap);
197 struct percpu_ref *ref;
198
> 199 gen_pool_free_owner(pgmap->provider->p2pdma->pool,
200 (uintptr_t)page_to_virt(page), PAGE_SIZE,
201 (void **)&ref);
202 percpu_ref_put(ref);
203 }
204

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


2023-02-06 15:26:35

by Chaitanya Kulkarni

[permalink] [raw]
Subject: Re: drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression

Logan,

> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
>
> sparse warnings: (new ones prefixed by >>)
>>> drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression
>
> vim +199 drivers/pci/p2pdma.c
>
> 193
> 194 static void p2pdma_page_free(struct page *page)
> 195 {
> 196 struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page->pgmap);
> 197 struct percpu_ref *ref;
> 198
> > 199 gen_pool_free_owner(pgmap->provider->p2pdma->pool,
> 200 (uintptr_t)page_to_virt(page), PAGE_SIZE,
> 201 (void **)&ref);
> 202 percpu_ref_put(ref);
> 203 }
> 204
>

Did you get a chance to look into this ?

-ck

2023-02-06 18:21:32

by Logan Gunthorpe

[permalink] [raw]
Subject: Re: drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression



On 2023-02-06 8:26 a.m., Chaitanya Kulkarni wrote:
> Logan,
>
>> If you fix the issue, kindly add following tag where applicable
>> | Reported-by: kernel test robot <[email protected]>
>>
>> sparse warnings: (new ones prefixed by >>)
>>>> drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression
>>
>> vim +199 drivers/pci/p2pdma.c
>>
>> 193
>> 194 static void p2pdma_page_free(struct page *page)
>> 195 {
>> 196 struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page->pgmap);
>> 197 struct percpu_ref *ref;
>> 198
>> > 199 gen_pool_free_owner(pgmap->provider->p2pdma->pool,
>> 200 (uintptr_t)page_to_virt(page), PAGE_SIZE,
>> 201 (void **)&ref);
>> 202 percpu_ref_put(ref);
>> 203 }
>> 204
>>
>
> Did you get a chance to look into this ?

Oh, I didn't notice that email. Wonder why it took this long for sparse
to see that.

Looks like we need to add a rcu_derference_protected() around the p2pdma
dereference there. I can send a patch later this week.

Thanks,

Logan