All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/cma.c: find a named CMA area by name
@ 2020-01-16 10:13 buddy.zhang
  2020-01-16 12:12 ` Michal Hocko
  0 siblings, 1 reply; 11+ messages in thread
From: buddy.zhang @ 2020-01-16 10:13 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, BuddyZhang

From: BuddyZhang <buddy.zhang@aliyun.com>

This function could help developer who want to find a special
named CMA area.

The CMA supports multiple named CMA areas, and the device could
use or exclusive a special CAM arae via "cma_area" on "struct
device". When probing, the device can setup special CMA area which
find by "cma_find_by_name()".

If device can't find named CMA area, "cma_find_by_name()" will
return NULL, and device will used default CMA area.

Signed-off-by: BuddyZhang <buddy.zhang@aliyun.com>
---
 mm/cma.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index be55d1988c67..6581dabcaf34 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -40,6 +40,18 @@ struct cma cma_areas[MAX_CMA_AREAS];
 unsigned cma_area_count;
 static DEFINE_MUTEX(cma_mutex);
 
+struct cma *cma_find_by_name(const char *name)
+{
+	int idx;
+
+	for (idx = 0; idx < MAX_CMA_AREAS; idx++) {
+		if (cma_areas[idx].name && !strcmp(name, cma_areas[idx].name))
+			return &cma_areas[idx];
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(cma_find_by_name);
+
 phys_addr_t cma_get_base(const struct cma *cma)
 {
 	return PFN_PHYS(cma->base_pfn);

base-commit: 5b483a1a0ea1ab19a5734051c9692c2cfabe1327
-- 
2.17.1



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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-16 10:13 [PATCH] mm/cma.c: find a named CMA area by name buddy.zhang
@ 2020-01-16 12:12 ` Michal Hocko
  2020-01-17  2:16   ` buddy.zhang
  0 siblings, 1 reply; 11+ messages in thread
From: Michal Hocko @ 2020-01-16 12:12 UTC (permalink / raw)
  To: buddy.zhang; +Cc: akpm, linux-mm, linux-kernel

On Thu 16-01-20 18:13:22, buddy.zhang@aliyun.com wrote:
> From: BuddyZhang <buddy.zhang@aliyun.com>
> 
> This function could help developer who want to find a special
> named CMA area.
> 
> The CMA supports multiple named CMA areas, and the device could
> use or exclusive a special CAM arae via "cma_area" on "struct
> device". When probing, the device can setup special CMA area which
> find by "cma_find_by_name()".
> 
> If device can't find named CMA area, "cma_find_by_name()" will
> return NULL, and device will used default CMA area.

Please do not add new exported symbols without actual users.

> Signed-off-by: BuddyZhang <buddy.zhang@aliyun.com>
> ---
>  mm/cma.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/mm/cma.c b/mm/cma.c
> index be55d1988c67..6581dabcaf34 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -40,6 +40,18 @@ struct cma cma_areas[MAX_CMA_AREAS];
>  unsigned cma_area_count;
>  static DEFINE_MUTEX(cma_mutex);
>  
> +struct cma *cma_find_by_name(const char *name)
> +{
> +	int idx;
> +
> +	for (idx = 0; idx < MAX_CMA_AREAS; idx++) {
> +		if (cma_areas[idx].name && !strcmp(name, cma_areas[idx].name))
> +			return &cma_areas[idx];
> +	}
> +	return NULL;
> +}
> +EXPORT_SYMBOL(cma_find_by_name);
> +
>  phys_addr_t cma_get_base(const struct cma *cma)
>  {
>  	return PFN_PHYS(cma->base_pfn);
> 
> base-commit: 5b483a1a0ea1ab19a5734051c9692c2cfabe1327
> -- 
> 2.17.1
> 

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-16 12:12 ` Michal Hocko
@ 2020-01-17  2:16   ` buddy.zhang
  2020-01-17  6:28     ` Michal Hocko
  0 siblings, 1 reply; 11+ messages in thread
From: buddy.zhang @ 2020-01-17  2:16 UTC (permalink / raw)
  To: mhocko; +Cc: akpm, linux-mm, linux-kernel

[-- Attachment #1: Type: text/html, Size: 10642 bytes --]

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-17  2:16   ` buddy.zhang
@ 2020-01-17  6:28     ` Michal Hocko
  0 siblings, 0 replies; 11+ messages in thread
From: Michal Hocko @ 2020-01-17  6:28 UTC (permalink / raw)
  To: buddy.zhang; +Cc: akpm, linux-mm, linux-kernel

On Fri 17-01-20 10:16:46, buddy.zhang wrote:
[...]
>     So, if device want to use a special named CMA area on module,  
>     "cma_find_by_name()" need export symbols.

My question was whether there actually is any device that would like to
use this functionality. Your patch doesn't add any and there is no
reference to any either. We do not add exports for the functionality
which is not used in the tree.
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-14  7:51 buddy.zhang
@ 2020-01-17  4:17   ` kbuild test robot
  2020-01-16  4:21   ` kbuild test robot
  2020-01-17  4:17   ` kbuild test robot
  2 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2020-01-17  4:17 UTC (permalink / raw)
  To: buddy.zhang; +Cc: kbuild-all, akpm, linux-mm, linux-kernel, BuddyZhang

[-- Attachment #1: Type: text/plain, Size: 1962 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mmotm/master]
[also build test ERROR on next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/buddy-zhang-aliyun-com/mm-cma-c-find-a-named-CMA-area-by-name/20200114-155334
base:   git://git.cmpxchg.org/linux-mmotm.git master
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.5.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> mm/cma.c:55:1: error: expected ',' or ';' before 'phys_addr_t'
    phys_addr_t cma_get_base(const struct cma *cma)
    ^~~~~~~~~~~

vim +55 mm/cma.c

0095fc296f5cf9 BuddyZhang  2020-01-14  54  
ac173824959ade Sasha Levin 2015-04-14 @55  phys_addr_t cma_get_base(const struct cma *cma)
a254129e8686bf Joonsoo Kim 2014-08-06  56  {
a254129e8686bf Joonsoo Kim 2014-08-06  57  	return PFN_PHYS(cma->base_pfn);
a254129e8686bf Joonsoo Kim 2014-08-06  58  }
a254129e8686bf Joonsoo Kim 2014-08-06  59  

:::::: The code at line 55 was first introduced by commit
:::::: ac173824959adeb489f9fcf88858774c4535a241 mm: cma: constify and use correct signness in mm/cma.c

:::::: TO: Sasha Levin <sasha.levin@oracle.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 51220 bytes --]

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
@ 2020-01-17  4:17   ` kbuild test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2020-01-17  4:17 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2011 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mmotm/master]
[also build test ERROR on next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/buddy-zhang-aliyun-com/mm-cma-c-find-a-named-CMA-area-by-name/20200114-155334
base:   git://git.cmpxchg.org/linux-mmotm.git master
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.5.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> mm/cma.c:55:1: error: expected ',' or ';' before 'phys_addr_t'
    phys_addr_t cma_get_base(const struct cma *cma)
    ^~~~~~~~~~~

vim +55 mm/cma.c

0095fc296f5cf9 BuddyZhang  2020-01-14  54  
ac173824959ade Sasha Levin 2015-04-14 @55  phys_addr_t cma_get_base(const struct cma *cma)
a254129e8686bf Joonsoo Kim 2014-08-06  56  {
a254129e8686bf Joonsoo Kim 2014-08-06  57  	return PFN_PHYS(cma->base_pfn);
a254129e8686bf Joonsoo Kim 2014-08-06  58  }
a254129e8686bf Joonsoo Kim 2014-08-06  59  

:::::: The code at line 55 was first introduced by commit
:::::: ac173824959adeb489f9fcf88858774c4535a241 mm: cma: constify and use correct signness in mm/cma.c

:::::: TO: Sasha Levin <sasha.levin@oracle.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 51220 bytes --]

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-14  7:51 buddy.zhang
@ 2020-01-16  4:21   ` kbuild test robot
  2020-01-16  4:21   ` kbuild test robot
  2020-01-17  4:17   ` kbuild test robot
  2 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2020-01-16  4:21 UTC (permalink / raw)
  To: buddy.zhang; +Cc: kbuild-all, akpm, linux-mm, linux-kernel, BuddyZhang

[-- Attachment #1: Type: text/plain, Size: 10081 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mmotm/master]
[also build test ERROR on linus/master v5.5-rc6 next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/buddy-zhang-aliyun-com/mm-cma-c-find-a-named-CMA-area-by-name/20200114-155334
base:   git://git.cmpxchg.org/linux-mmotm.git master
config: i386-randconfig-a002-20200115 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-3) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   mm/cma.c:55:1: error: expected ';' before 'phys_addr_t'
    phys_addr_t cma_get_base(const struct cma *cma)
    ^~~~~~~~~~~
   mm/cma.c: In function 'cma_alloc':
   mm/cma.c:449:9: error: implicit declaration of function 'cma_bitmap_aligned_mask'; did you mean 'cma_bitmap_maxno'? [-Werror=implicit-function-declaration]
     mask = cma_bitmap_aligned_mask(cma, align);
            ^~~~~~~~~~~~~~~~~~~~~~~
            cma_bitmap_maxno
   mm/cma.c:450:11: error: implicit declaration of function 'cma_bitmap_aligned_offset'; did you mean 'cma_bitmap_maxno'? [-Werror=implicit-function-declaration]
     offset = cma_bitmap_aligned_offset(cma, align);
              ^~~~~~~~~~~~~~~~~~~~~~~~~
              cma_bitmap_maxno
   mm/cma.c:452:17: error: implicit declaration of function 'cma_bitmap_pages_to_bits'; did you mean 'cma_bitmap_maxno'? [-Werror=implicit-function-declaration]
     bitmap_count = cma_bitmap_pages_to_bits(cma, count);
                    ^~~~~~~~~~~~~~~~~~~~~~~~
                    cma_bitmap_maxno
>> mm/cma.c:484:3: error: implicit declaration of function 'cma_clear_bitmap'; did you mean 'cr4_clear_bits'? [-Werror=implicit-function-declaration]
      cma_clear_bitmap(cma, pfn, count);
      ^~~~~~~~~~~~~~~~
      cr4_clear_bits
   cc1: some warnings being treated as errors

vim +484 mm/cma.c

dbe43d4d2837da Jaewon Kim       2017-02-24  418  
a254129e8686bf Joonsoo Kim      2014-08-06  419  /**
a254129e8686bf Joonsoo Kim      2014-08-06  420   * cma_alloc() - allocate pages from contiguous area
a254129e8686bf Joonsoo Kim      2014-08-06  421   * @cma:   Contiguous memory region for which the allocation is performed.
a254129e8686bf Joonsoo Kim      2014-08-06  422   * @count: Requested number of pages.
a254129e8686bf Joonsoo Kim      2014-08-06  423   * @align: Requested alignment of pages (in PAGE_SIZE order).
6518202970c105 Marek Szyprowski 2018-08-17  424   * @no_warn: Avoid printing message about failed allocation
a254129e8686bf Joonsoo Kim      2014-08-06  425   *
a254129e8686bf Joonsoo Kim      2014-08-06  426   * This function allocates part of contiguous memory on specific
a254129e8686bf Joonsoo Kim      2014-08-06  427   * contiguous memory area.
a254129e8686bf Joonsoo Kim      2014-08-06  428   */
e2f466e32f56c8 Lucas Stach      2017-02-24  429  struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
6518202970c105 Marek Szyprowski 2018-08-17  430  		       bool no_warn)
a254129e8686bf Joonsoo Kim      2014-08-06  431  {
3acaea6804b3a1 Andrew Morton    2015-11-05  432  	unsigned long mask, offset;
3acaea6804b3a1 Andrew Morton    2015-11-05  433  	unsigned long pfn = -1;
3acaea6804b3a1 Andrew Morton    2015-11-05  434  	unsigned long start = 0;
a254129e8686bf Joonsoo Kim      2014-08-06  435  	unsigned long bitmap_maxno, bitmap_no, bitmap_count;
2813b9c0296259 Andrey Konovalov 2018-12-28  436  	size_t i;
a254129e8686bf Joonsoo Kim      2014-08-06  437  	struct page *page = NULL;
dbe43d4d2837da Jaewon Kim       2017-02-24  438  	int ret = -ENOMEM;
a254129e8686bf Joonsoo Kim      2014-08-06  439  
a254129e8686bf Joonsoo Kim      2014-08-06  440  	if (!cma || !cma->count)
a254129e8686bf Joonsoo Kim      2014-08-06  441  		return NULL;
a254129e8686bf Joonsoo Kim      2014-08-06  442  
67a2e213e7e937 Rohit Vaswani    2015-10-22  443  	pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma,
a254129e8686bf Joonsoo Kim      2014-08-06  444  		 count, align);
a254129e8686bf Joonsoo Kim      2014-08-06  445  
a254129e8686bf Joonsoo Kim      2014-08-06  446  	if (!count)
a254129e8686bf Joonsoo Kim      2014-08-06  447  		return NULL;
a254129e8686bf Joonsoo Kim      2014-08-06  448  
a254129e8686bf Joonsoo Kim      2014-08-06  449  	mask = cma_bitmap_aligned_mask(cma, align);
b5be83e308f70e Gregory Fong     2014-12-12 @450  	offset = cma_bitmap_aligned_offset(cma, align);
a254129e8686bf Joonsoo Kim      2014-08-06  451  	bitmap_maxno = cma_bitmap_maxno(cma);
a254129e8686bf Joonsoo Kim      2014-08-06  452  	bitmap_count = cma_bitmap_pages_to_bits(cma, count);
a254129e8686bf Joonsoo Kim      2014-08-06  453  
6b36ba599d602d Shiraz Hashim    2016-11-10  454  	if (bitmap_count > bitmap_maxno)
6b36ba599d602d Shiraz Hashim    2016-11-10  455  		return NULL;
6b36ba599d602d Shiraz Hashim    2016-11-10  456  
a254129e8686bf Joonsoo Kim      2014-08-06  457  	for (;;) {
a254129e8686bf Joonsoo Kim      2014-08-06  458  		mutex_lock(&cma->lock);
b5be83e308f70e Gregory Fong     2014-12-12  459  		bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap,
b5be83e308f70e Gregory Fong     2014-12-12  460  				bitmap_maxno, start, bitmap_count, mask,
b5be83e308f70e Gregory Fong     2014-12-12  461  				offset);
a254129e8686bf Joonsoo Kim      2014-08-06  462  		if (bitmap_no >= bitmap_maxno) {
a254129e8686bf Joonsoo Kim      2014-08-06  463  			mutex_unlock(&cma->lock);
a254129e8686bf Joonsoo Kim      2014-08-06  464  			break;
a254129e8686bf Joonsoo Kim      2014-08-06  465  		}
a254129e8686bf Joonsoo Kim      2014-08-06  466  		bitmap_set(cma->bitmap, bitmap_no, bitmap_count);
a254129e8686bf Joonsoo Kim      2014-08-06  467  		/*
a254129e8686bf Joonsoo Kim      2014-08-06  468  		 * It's safe to drop the lock here. We've marked this region for
a254129e8686bf Joonsoo Kim      2014-08-06  469  		 * our exclusive use. If the migration fails we will take the
a254129e8686bf Joonsoo Kim      2014-08-06  470  		 * lock again and unmark it.
a254129e8686bf Joonsoo Kim      2014-08-06  471  		 */
a254129e8686bf Joonsoo Kim      2014-08-06  472  		mutex_unlock(&cma->lock);
a254129e8686bf Joonsoo Kim      2014-08-06  473  
a254129e8686bf Joonsoo Kim      2014-08-06  474  		pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
a254129e8686bf Joonsoo Kim      2014-08-06  475  		mutex_lock(&cma_mutex);
ca96b625341027 Lucas Stach      2017-02-24  476  		ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
6518202970c105 Marek Szyprowski 2018-08-17  477  				     GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0));
a254129e8686bf Joonsoo Kim      2014-08-06  478  		mutex_unlock(&cma_mutex);
a254129e8686bf Joonsoo Kim      2014-08-06  479  		if (ret == 0) {
a254129e8686bf Joonsoo Kim      2014-08-06  480  			page = pfn_to_page(pfn);
a254129e8686bf Joonsoo Kim      2014-08-06  481  			break;
a254129e8686bf Joonsoo Kim      2014-08-06  482  		}
b7155e76a702d9 Joonsoo Kim      2014-08-06  483  
a254129e8686bf Joonsoo Kim      2014-08-06 @484  		cma_clear_bitmap(cma, pfn, count);
b7155e76a702d9 Joonsoo Kim      2014-08-06  485  		if (ret != -EBUSY)
b7155e76a702d9 Joonsoo Kim      2014-08-06  486  			break;
b7155e76a702d9 Joonsoo Kim      2014-08-06  487  
a254129e8686bf Joonsoo Kim      2014-08-06  488  		pr_debug("%s(): memory range at %p is busy, retrying\n",
a254129e8686bf Joonsoo Kim      2014-08-06  489  			 __func__, pfn_to_page(pfn));
a254129e8686bf Joonsoo Kim      2014-08-06  490  		/* try again with a bit different memory target */
a254129e8686bf Joonsoo Kim      2014-08-06  491  		start = bitmap_no + mask + 1;
a254129e8686bf Joonsoo Kim      2014-08-06  492  	}
a254129e8686bf Joonsoo Kim      2014-08-06  493  
3acaea6804b3a1 Andrew Morton    2015-11-05  494  	trace_cma_alloc(pfn, page, count, align);
99e8ea6cd2210c Stefan Strogin   2015-04-15  495  
2813b9c0296259 Andrey Konovalov 2018-12-28  496  	/*
2813b9c0296259 Andrey Konovalov 2018-12-28  497  	 * CMA can allocate multiple page blocks, which results in different
2813b9c0296259 Andrey Konovalov 2018-12-28  498  	 * blocks being marked with different tags. Reset the tags to ignore
2813b9c0296259 Andrey Konovalov 2018-12-28  499  	 * those page blocks.
2813b9c0296259 Andrey Konovalov 2018-12-28  500  	 */
2813b9c0296259 Andrey Konovalov 2018-12-28  501  	if (page) {
2813b9c0296259 Andrey Konovalov 2018-12-28  502  		for (i = 0; i < count; i++)
2813b9c0296259 Andrey Konovalov 2018-12-28  503  			page_kasan_tag_reset(page + i);
2813b9c0296259 Andrey Konovalov 2018-12-28  504  	}
2813b9c0296259 Andrey Konovalov 2018-12-28  505  
6518202970c105 Marek Szyprowski 2018-08-17  506  	if (ret && !no_warn) {
5984af1082f3b1 Pintu Agarwal    2017-11-15  507  		pr_err("%s: alloc failed, req-size: %zu pages, ret: %d\n",
dbe43d4d2837da Jaewon Kim       2017-02-24  508  			__func__, count, ret);
dbe43d4d2837da Jaewon Kim       2017-02-24  509  		cma_debug_show_areas(cma);
dbe43d4d2837da Jaewon Kim       2017-02-24  510  	}
dbe43d4d2837da Jaewon Kim       2017-02-24  511  
a254129e8686bf Joonsoo Kim      2014-08-06  512  	pr_debug("%s(): returned %p\n", __func__, page);
a254129e8686bf Joonsoo Kim      2014-08-06  513  	return page;
a254129e8686bf Joonsoo Kim      2014-08-06  514  }
a254129e8686bf Joonsoo Kim      2014-08-06  515  

:::::: The code at line 484 was first introduced by commit
:::::: a254129e8686bff7a340b58f35241b04927e81c0 CMA: generalize CMA reserved area management functionality

:::::: TO: Joonsoo Kim <iamjoonsoo.kim@lge.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 37413 bytes --]

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
@ 2020-01-16  4:21   ` kbuild test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2020-01-16  4:21 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 10235 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mmotm/master]
[also build test ERROR on linus/master v5.5-rc6 next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/buddy-zhang-aliyun-com/mm-cma-c-find-a-named-CMA-area-by-name/20200114-155334
base:   git://git.cmpxchg.org/linux-mmotm.git master
config: i386-randconfig-a002-20200115 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-3) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   mm/cma.c:55:1: error: expected ';' before 'phys_addr_t'
    phys_addr_t cma_get_base(const struct cma *cma)
    ^~~~~~~~~~~
   mm/cma.c: In function 'cma_alloc':
   mm/cma.c:449:9: error: implicit declaration of function 'cma_bitmap_aligned_mask'; did you mean 'cma_bitmap_maxno'? [-Werror=implicit-function-declaration]
     mask = cma_bitmap_aligned_mask(cma, align);
            ^~~~~~~~~~~~~~~~~~~~~~~
            cma_bitmap_maxno
   mm/cma.c:450:11: error: implicit declaration of function 'cma_bitmap_aligned_offset'; did you mean 'cma_bitmap_maxno'? [-Werror=implicit-function-declaration]
     offset = cma_bitmap_aligned_offset(cma, align);
              ^~~~~~~~~~~~~~~~~~~~~~~~~
              cma_bitmap_maxno
   mm/cma.c:452:17: error: implicit declaration of function 'cma_bitmap_pages_to_bits'; did you mean 'cma_bitmap_maxno'? [-Werror=implicit-function-declaration]
     bitmap_count = cma_bitmap_pages_to_bits(cma, count);
                    ^~~~~~~~~~~~~~~~~~~~~~~~
                    cma_bitmap_maxno
>> mm/cma.c:484:3: error: implicit declaration of function 'cma_clear_bitmap'; did you mean 'cr4_clear_bits'? [-Werror=implicit-function-declaration]
      cma_clear_bitmap(cma, pfn, count);
      ^~~~~~~~~~~~~~~~
      cr4_clear_bits
   cc1: some warnings being treated as errors

vim +484 mm/cma.c

dbe43d4d2837da Jaewon Kim       2017-02-24  418  
a254129e8686bf Joonsoo Kim      2014-08-06  419  /**
a254129e8686bf Joonsoo Kim      2014-08-06  420   * cma_alloc() - allocate pages from contiguous area
a254129e8686bf Joonsoo Kim      2014-08-06  421   * @cma:   Contiguous memory region for which the allocation is performed.
a254129e8686bf Joonsoo Kim      2014-08-06  422   * @count: Requested number of pages.
a254129e8686bf Joonsoo Kim      2014-08-06  423   * @align: Requested alignment of pages (in PAGE_SIZE order).
6518202970c105 Marek Szyprowski 2018-08-17  424   * @no_warn: Avoid printing message about failed allocation
a254129e8686bf Joonsoo Kim      2014-08-06  425   *
a254129e8686bf Joonsoo Kim      2014-08-06  426   * This function allocates part of contiguous memory on specific
a254129e8686bf Joonsoo Kim      2014-08-06  427   * contiguous memory area.
a254129e8686bf Joonsoo Kim      2014-08-06  428   */
e2f466e32f56c8 Lucas Stach      2017-02-24  429  struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
6518202970c105 Marek Szyprowski 2018-08-17  430  		       bool no_warn)
a254129e8686bf Joonsoo Kim      2014-08-06  431  {
3acaea6804b3a1 Andrew Morton    2015-11-05  432  	unsigned long mask, offset;
3acaea6804b3a1 Andrew Morton    2015-11-05  433  	unsigned long pfn = -1;
3acaea6804b3a1 Andrew Morton    2015-11-05  434  	unsigned long start = 0;
a254129e8686bf Joonsoo Kim      2014-08-06  435  	unsigned long bitmap_maxno, bitmap_no, bitmap_count;
2813b9c0296259 Andrey Konovalov 2018-12-28  436  	size_t i;
a254129e8686bf Joonsoo Kim      2014-08-06  437  	struct page *page = NULL;
dbe43d4d2837da Jaewon Kim       2017-02-24  438  	int ret = -ENOMEM;
a254129e8686bf Joonsoo Kim      2014-08-06  439  
a254129e8686bf Joonsoo Kim      2014-08-06  440  	if (!cma || !cma->count)
a254129e8686bf Joonsoo Kim      2014-08-06  441  		return NULL;
a254129e8686bf Joonsoo Kim      2014-08-06  442  
67a2e213e7e937 Rohit Vaswani    2015-10-22  443  	pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma,
a254129e8686bf Joonsoo Kim      2014-08-06  444  		 count, align);
a254129e8686bf Joonsoo Kim      2014-08-06  445  
a254129e8686bf Joonsoo Kim      2014-08-06  446  	if (!count)
a254129e8686bf Joonsoo Kim      2014-08-06  447  		return NULL;
a254129e8686bf Joonsoo Kim      2014-08-06  448  
a254129e8686bf Joonsoo Kim      2014-08-06  449  	mask = cma_bitmap_aligned_mask(cma, align);
b5be83e308f70e Gregory Fong     2014-12-12 @450  	offset = cma_bitmap_aligned_offset(cma, align);
a254129e8686bf Joonsoo Kim      2014-08-06  451  	bitmap_maxno = cma_bitmap_maxno(cma);
a254129e8686bf Joonsoo Kim      2014-08-06  452  	bitmap_count = cma_bitmap_pages_to_bits(cma, count);
a254129e8686bf Joonsoo Kim      2014-08-06  453  
6b36ba599d602d Shiraz Hashim    2016-11-10  454  	if (bitmap_count > bitmap_maxno)
6b36ba599d602d Shiraz Hashim    2016-11-10  455  		return NULL;
6b36ba599d602d Shiraz Hashim    2016-11-10  456  
a254129e8686bf Joonsoo Kim      2014-08-06  457  	for (;;) {
a254129e8686bf Joonsoo Kim      2014-08-06  458  		mutex_lock(&cma->lock);
b5be83e308f70e Gregory Fong     2014-12-12  459  		bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap,
b5be83e308f70e Gregory Fong     2014-12-12  460  				bitmap_maxno, start, bitmap_count, mask,
b5be83e308f70e Gregory Fong     2014-12-12  461  				offset);
a254129e8686bf Joonsoo Kim      2014-08-06  462  		if (bitmap_no >= bitmap_maxno) {
a254129e8686bf Joonsoo Kim      2014-08-06  463  			mutex_unlock(&cma->lock);
a254129e8686bf Joonsoo Kim      2014-08-06  464  			break;
a254129e8686bf Joonsoo Kim      2014-08-06  465  		}
a254129e8686bf Joonsoo Kim      2014-08-06  466  		bitmap_set(cma->bitmap, bitmap_no, bitmap_count);
a254129e8686bf Joonsoo Kim      2014-08-06  467  		/*
a254129e8686bf Joonsoo Kim      2014-08-06  468  		 * It's safe to drop the lock here. We've marked this region for
a254129e8686bf Joonsoo Kim      2014-08-06  469  		 * our exclusive use. If the migration fails we will take the
a254129e8686bf Joonsoo Kim      2014-08-06  470  		 * lock again and unmark it.
a254129e8686bf Joonsoo Kim      2014-08-06  471  		 */
a254129e8686bf Joonsoo Kim      2014-08-06  472  		mutex_unlock(&cma->lock);
a254129e8686bf Joonsoo Kim      2014-08-06  473  
a254129e8686bf Joonsoo Kim      2014-08-06  474  		pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
a254129e8686bf Joonsoo Kim      2014-08-06  475  		mutex_lock(&cma_mutex);
ca96b625341027 Lucas Stach      2017-02-24  476  		ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
6518202970c105 Marek Szyprowski 2018-08-17  477  				     GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0));
a254129e8686bf Joonsoo Kim      2014-08-06  478  		mutex_unlock(&cma_mutex);
a254129e8686bf Joonsoo Kim      2014-08-06  479  		if (ret == 0) {
a254129e8686bf Joonsoo Kim      2014-08-06  480  			page = pfn_to_page(pfn);
a254129e8686bf Joonsoo Kim      2014-08-06  481  			break;
a254129e8686bf Joonsoo Kim      2014-08-06  482  		}
b7155e76a702d9 Joonsoo Kim      2014-08-06  483  
a254129e8686bf Joonsoo Kim      2014-08-06 @484  		cma_clear_bitmap(cma, pfn, count);
b7155e76a702d9 Joonsoo Kim      2014-08-06  485  		if (ret != -EBUSY)
b7155e76a702d9 Joonsoo Kim      2014-08-06  486  			break;
b7155e76a702d9 Joonsoo Kim      2014-08-06  487  
a254129e8686bf Joonsoo Kim      2014-08-06  488  		pr_debug("%s(): memory range at %p is busy, retrying\n",
a254129e8686bf Joonsoo Kim      2014-08-06  489  			 __func__, pfn_to_page(pfn));
a254129e8686bf Joonsoo Kim      2014-08-06  490  		/* try again with a bit different memory target */
a254129e8686bf Joonsoo Kim      2014-08-06  491  		start = bitmap_no + mask + 1;
a254129e8686bf Joonsoo Kim      2014-08-06  492  	}
a254129e8686bf Joonsoo Kim      2014-08-06  493  
3acaea6804b3a1 Andrew Morton    2015-11-05  494  	trace_cma_alloc(pfn, page, count, align);
99e8ea6cd2210c Stefan Strogin   2015-04-15  495  
2813b9c0296259 Andrey Konovalov 2018-12-28  496  	/*
2813b9c0296259 Andrey Konovalov 2018-12-28  497  	 * CMA can allocate multiple page blocks, which results in different
2813b9c0296259 Andrey Konovalov 2018-12-28  498  	 * blocks being marked with different tags. Reset the tags to ignore
2813b9c0296259 Andrey Konovalov 2018-12-28  499  	 * those page blocks.
2813b9c0296259 Andrey Konovalov 2018-12-28  500  	 */
2813b9c0296259 Andrey Konovalov 2018-12-28  501  	if (page) {
2813b9c0296259 Andrey Konovalov 2018-12-28  502  		for (i = 0; i < count; i++)
2813b9c0296259 Andrey Konovalov 2018-12-28  503  			page_kasan_tag_reset(page + i);
2813b9c0296259 Andrey Konovalov 2018-12-28  504  	}
2813b9c0296259 Andrey Konovalov 2018-12-28  505  
6518202970c105 Marek Szyprowski 2018-08-17  506  	if (ret && !no_warn) {
5984af1082f3b1 Pintu Agarwal    2017-11-15  507  		pr_err("%s: alloc failed, req-size: %zu pages, ret: %d\n",
dbe43d4d2837da Jaewon Kim       2017-02-24  508  			__func__, count, ret);
dbe43d4d2837da Jaewon Kim       2017-02-24  509  		cma_debug_show_areas(cma);
dbe43d4d2837da Jaewon Kim       2017-02-24  510  	}
dbe43d4d2837da Jaewon Kim       2017-02-24  511  
a254129e8686bf Joonsoo Kim      2014-08-06  512  	pr_debug("%s(): returned %p\n", __func__, page);
a254129e8686bf Joonsoo Kim      2014-08-06  513  	return page;
a254129e8686bf Joonsoo Kim      2014-08-06  514  }
a254129e8686bf Joonsoo Kim      2014-08-06  515  

:::::: The code@line 484 was first introduced by commit
:::::: a254129e8686bff7a340b58f35241b04927e81c0 CMA: generalize CMA reserved area management functionality

:::::: TO: Joonsoo Kim <iamjoonsoo.kim@lge.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37413 bytes --]

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-14  9:02 ` David Hildenbrand
@ 2020-01-14 10:08   ` buddy.zhang
  0 siblings, 0 replies; 11+ messages in thread
From: buddy.zhang @ 2020-01-14 10:08 UTC (permalink / raw)
  To: david; +Cc: akpm, linux-mm, linux-kernel

[-- Attachment #1: Type: text/html, Size: 9980 bytes --]

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

* Re: [PATCH] mm/cma.c: find a named CMA area by name
  2020-01-14  7:51 buddy.zhang
@ 2020-01-14  9:02 ` David Hildenbrand
  2020-01-14 10:08   ` buddy.zhang
  2020-01-16  4:21   ` kbuild test robot
  2020-01-17  4:17   ` kbuild test robot
  2 siblings, 1 reply; 11+ messages in thread
From: David Hildenbrand @ 2020-01-14  9:02 UTC (permalink / raw)
  To: buddy.zhang, akpm; +Cc: linux-mm, linux-kernel

On 14.01.20 08:51, buddy.zhang@aliyun.com wrote:
> From: BuddyZhang <buddy.zhang@aliyun.com>
> 
> This function could help developer who want to find a special
> named CMA area.

*could help* - if there is no user, why do we need it? Or do you have a
user?

> 
> The CMA supports multiple named CMA areas, and the device could
> use or exclusive a special CAM arae via "cma_area" on "struct
> device". When probing, the device can setup special CMA area which
> find by "cma_find_by_name()".
> 
> If device can't find named CMA area, "cma_find_by_name()" will
> return NULL, and device will used default CMA area.
> 
> Signed-off-by: BuddyZhang <buddy.zhang@aliyun.com>
> ---
>  mm/cma.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/mm/cma.c b/mm/cma.c
> index be55d1988c67..b562557572c4 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -40,6 +40,18 @@ struct cma cma_areas[MAX_CMA_AREAS];
>  unsigned cma_area_count;
>  static DEFINE_MUTEX(cma_mutex);
>  
> +struct cma *cma_find_by_name(const char *name)
> +{
> +	int idx;
> +
> +	for (idx = 0; idx < MAX_CMA_AREAS; idx++) {
> +		if (cma_areas[idx].name && !strcmp(name, cma_areas[idx].name))
> +			return &cma_areas[idx];
> +	}
> +	return NULL;
> +}
> +EXPORT_SYMBOL(cma_find_by_name)
> +
>  phys_addr_t cma_get_base(const struct cma *cma)
>  {
>  	return PFN_PHYS(cma->base_pfn);
> 


-- 
Thanks,

David / dhildenb


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

* [PATCH] mm/cma.c: find a named CMA area by name
@ 2020-01-14  7:51 buddy.zhang
  2020-01-14  9:02 ` David Hildenbrand
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: buddy.zhang @ 2020-01-14  7:51 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, BuddyZhang

From: BuddyZhang <buddy.zhang@aliyun.com>

This function could help developer who want to find a special
named CMA area.

The CMA supports multiple named CMA areas, and the device could
use or exclusive a special CAM arae via "cma_area" on "struct
device". When probing, the device can setup special CMA area which
find by "cma_find_by_name()".

If device can't find named CMA area, "cma_find_by_name()" will
return NULL, and device will used default CMA area.

Signed-off-by: BuddyZhang <buddy.zhang@aliyun.com>
---
 mm/cma.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index be55d1988c67..b562557572c4 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -40,6 +40,18 @@ struct cma cma_areas[MAX_CMA_AREAS];
 unsigned cma_area_count;
 static DEFINE_MUTEX(cma_mutex);
 
+struct cma *cma_find_by_name(const char *name)
+{
+	int idx;
+
+	for (idx = 0; idx < MAX_CMA_AREAS; idx++) {
+		if (cma_areas[idx].name && !strcmp(name, cma_areas[idx].name))
+			return &cma_areas[idx];
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(cma_find_by_name)
+
 phys_addr_t cma_get_base(const struct cma *cma)
 {
 	return PFN_PHYS(cma->base_pfn);
-- 
2.17.1



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

end of thread, other threads:[~2020-01-17  6:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 10:13 [PATCH] mm/cma.c: find a named CMA area by name buddy.zhang
2020-01-16 12:12 ` Michal Hocko
2020-01-17  2:16   ` buddy.zhang
2020-01-17  6:28     ` Michal Hocko
  -- strict thread matches above, loose matches on Subject: below --
2020-01-14  7:51 buddy.zhang
2020-01-14  9:02 ` David Hildenbrand
2020-01-14 10:08   ` buddy.zhang
2020-01-16  4:21 ` kbuild test robot
2020-01-16  4:21   ` kbuild test robot
2020-01-17  4:17 ` kbuild test robot
2020-01-17  4:17   ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.