RE: [PATCH 1/3] dma-direct: provide the ability to reserve per-numa CMA

From: Song Bao Hua (Barry Song)
Date: Fri Jun 05 2020 - 02:04:55 EST




> -----Original Message-----
> From: Dan Carpenter [mailto:dan.carpenter@xxxxxxxxxx]
> Sent: Thursday, June 4, 2020 11:37 PM
> To: kbuild@xxxxxxxxxxxx; Song Bao Hua (Barry Song)
> <song.bao.hua@xxxxxxxxxxxxx>; hch@xxxxxx; m.szyprowski@xxxxxxxxxxx;
> robin.murphy@xxxxxxx; catalin.marinas@xxxxxxx
> Cc: lkp@xxxxxxxxx; Dan Carpenter <error27@xxxxxxxxx>;
> kbuild-all@xxxxxxxxxxxx; iommu@xxxxxxxxxxxxxxxxxxxxxxxxxx;
> linux-arm-kernel@xxxxxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Linuxarm
> <linuxarm@xxxxxxxxxx>; Jonathan Cameron
> <jonathan.cameron@xxxxxxxxxx>; John Garry <john.garry@xxxxxxxxxx>
> Subject: Re: [PATCH 1/3] dma-direct: provide the ability to reserve per-numa
> CMA
>
> Hi Barry,
>
> url:
> https://github.com/0day-ci/linux/commits/Barry-Song/support-per-numa-CM
> A-for-ARM-server/20200603-104821
> base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
> for-next/core
> config: x86_64-randconfig-m001-20200603 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

Dan, thanks! Good catch!
as this patch has not been in mainline yet, is it correct to add these "reported-by" in patch v2?

Barry

>
> smatch warnings:
> kernel/dma/contiguous.c:274 dma_alloc_contiguous() warn: variable
> dereferenced before check 'dev' (see line 272)
>
> #
> https://github.com/0day-ci/linux/commit/adb919e972c1cac3d8b11905d525
> 8d23d3aac6a4
> git remote add linux-review https://github.com/0day-ci/linux git remote
> update linux-review git checkout
> adb919e972c1cac3d8b11905d5258d23d3aac6a4
> vim +/dev +274 kernel/dma/contiguous.c
>
> b1d2dc009dece4 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 267 struct page *dma_alloc_contiguous(struct device *dev,
> size_t size, gfp_t gfp)
> b1d2dc009dece4 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 268 {
> 90ae409f9eb3bc kernel/dma/contiguous.c Christoph Hellwig
> 2019-08-20 269 size_t count = size >> PAGE_SHIFT;
> b1d2dc009dece4 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 270 struct page *page = NULL;
> bd2e75633c8012 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 271 struct cma *cma = NULL;
> adb919e972c1ca kernel/dma/contiguous.c Barry Song
> 2020-06-03 @272 int nid = dev_to_node(dev);
>
> ^^^ Dereferenced inside function.
>
> bd2e75633c8012 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 273
> bd2e75633c8012 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 @274 if (dev && dev->cma_area)
>
> ^^^ Too late.
>
> bd2e75633c8012 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 275 cma = dev->cma_area;
> adb919e972c1ca kernel/dma/contiguous.c Barry Song
> 2020-06-03 276 else if ((nid != NUMA_NO_NODE) &&
> dma_contiguous_pernuma_area[nid]
> adb919e972c1ca kernel/dma/contiguous.c Barry Song
> 2020-06-03 277 && !(gfp & (GFP_DMA | GFP_DMA32)))
> adb919e972c1ca kernel/dma/contiguous.c Barry Song
> 2020-06-03 278 cma = dma_contiguous_pernuma_area[nid];
> bd2e75633c8012 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 279 else if (count > 1)
> bd2e75633c8012 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 280 cma = dma_contiguous_default_area;
> b1d2dc009dece4 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 281
> b1d2dc009dece4 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 282 /* CMA can be used only in the context which permits
> sleeping */
> b1d2dc009dece4 kernel/dma/contiguous.c Nicolin Chen
> 2019-05-23 283 if (cma && gfpflags_allow_blocking(gfp)) {
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx