Re: [PATCH] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-03-01 Thread Miaohe Lin
On 2021/2/10 23:32, kernel test robot wrote:
> Hi Miaohe,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on next-20210125]
> [also build test ERROR on v5.11-rc7]
> [cannot apply to linux/master linus/master hnaz-linux-mm/master v5.11-rc7 
> v5.11-rc6 v5.11-rc5]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:
> https://github.com/0day-ci/linux/commits/Miaohe-Lin/hugetlb_cgroup-fix-imbalanced-css_get-and-css_put-pair-for-shared-mappings/20210210-171736
> base:59fa6a163ffabc1bf25c5e0e33899e268a96d3cc
> config: arm64-randconfig-r025-20210209 (attached as .config)
> compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 
> c9439ca36342fb6013187d0a69aef92736951476)
> reproduce (this is a W=1 build):
> wget 
> https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
> ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # install arm64 cross compiling tool for clang build
> # apt-get install binutils-aarch64-linux-gnu
> # 
> https://github.com/0day-ci/linux/commit/68f4ed1b80aa7c51a921c3ad913ee7e6e00618d0
> git remote add linux-review https://github.com/0day-ci/linux
> git fetch --no-tags linux-review 
> Miaohe-Lin/hugetlb_cgroup-fix-imbalanced-css_get-and-css_put-pair-for-shared-mappings/20210210-171736
> git checkout 68f4ed1b80aa7c51a921c3ad913ee7e6e00618d0
> # save the attached .config to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot 
> 
> All errors (new ones prefixed by >>):
> 
>>> mm/hugetlb.c:5222:17: error: incomplete definition of type 'struct 
>>> hugetlb_cgroup'
>css_put(_cg->css);
> ^
>include/linux/hugetlb_cgroup.h:20:8: note: forward declaration of 'struct 
> hugetlb_cgroup'
>struct hugetlb_cgroup;
>   ^
>1 error generated.
> 

Sorry for late respond. Will fix this. Thanks!

> 
> vim +5222 mm/hugetlb.c
> 
>   5091
>   5092/* Return true if reservation was successful, false otherwise.  
> */
>   5093bool hugetlb_reserve_pages(struct inode *inode,
>   5094long from, long to,
>   5095struct vm_area_struct 
> *vma,
>   5096vm_flags_t vm_flags)
>   5097{
>   5098long chg, add = -1;
>   5099struct hstate *h = hstate_inode(inode);
>   5100struct hugepage_subpool *spool = subpool_inode(inode);
>   5101struct resv_map *resv_map;
>   5102struct hugetlb_cgroup *h_cg = NULL;
>   5103long gbl_reserve, regions_needed = 0;
>   5104
>   5105/* This should never happen */
>   5106if (from > to) {
>   5107VM_WARN(1, "%s called with a negative range\n", 
> __func__);
>   5108return false;
>   5109}
>   5110
>   5111/*
>   5112 * Only apply hugepage reservation if asked. At fault 
> time, an
>   5113 * attempt will be made for VM_NORESERVE to allocate a 
> page
>   5114 * without using reserves
>   5115 */
>   5116if (vm_flags & VM_NORESERVE)
>   5117return true;
>   5118
>   5119/*
>   5120 * Shared mappings base their reservation on the number 
> of pages that
>   5121 * are already allocated on behalf of the file. Private 
> mappings need
>   5122 * to reserve the full area even if read-only as 
> mprotect() may be
>   5123 * called to make the mapping read-write. Assume !vma 
> is a shm mapping
>   5124 */
>   5125if (!vma || vma->vm_flags & VM_MAYSHARE) {
>   5126/*
>   5127 * resv_map can not be NULL as 
> hugetlb_reserve_pages is only
>   5128 * called for inodes for which resv_maps were 
> created (see
>   5129 * hugetlbfs_get_inode).
>   5130 */
>   5131resv_map = inode_resv_map(inode);
>   5132
>   5133chg = region_chg(resv_map, from, to, 
> _needed);
>   5134
>   5135} else {
>   5136/* Private mapping. */
>   5137resv_map = resv_map_alloc();
>   5138if (!resv_map)
>   5139 

Re: [PATCH] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-02-10 Thread kernel test robot
Hi Miaohe,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20210125]
[also build test ERROR on v5.11-rc7]
[cannot apply to linux/master linus/master hnaz-linux-mm/master v5.11-rc7 
v5.11-rc6 v5.11-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Miaohe-Lin/hugetlb_cgroup-fix-imbalanced-css_get-and-css_put-pair-for-shared-mappings/20210210-171736
base:59fa6a163ffabc1bf25c5e0e33899e268a96d3cc
config: x86_64-randconfig-c002-20210209 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
# 
https://github.com/0day-ci/linux/commit/68f4ed1b80aa7c51a921c3ad913ee7e6e00618d0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Miaohe-Lin/hugetlb_cgroup-fix-imbalanced-css_get-and-css_put-pair-for-shared-mappings/20210210-171736
git checkout 68f4ed1b80aa7c51a921c3ad913ee7e6e00618d0
# save the attached .config to linux build tree
make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   mm/hugetlb.c: In function 'hugetlb_reserve_pages':
>> mm/hugetlb.c:5222:17: error: dereferencing pointer to incomplete type 
>> 'struct hugetlb_cgroup'
5222 |css_put(_cg->css);
 | ^~


vim +5222 mm/hugetlb.c

  5091  
  5092  /* Return true if reservation was successful, false otherwise.  */
  5093  bool hugetlb_reserve_pages(struct inode *inode,
  5094  long from, long to,
  5095  struct vm_area_struct *vma,
  5096  vm_flags_t vm_flags)
  5097  {
  5098  long chg, add = -1;
  5099  struct hstate *h = hstate_inode(inode);
  5100  struct hugepage_subpool *spool = subpool_inode(inode);
  5101  struct resv_map *resv_map;
  5102  struct hugetlb_cgroup *h_cg = NULL;
  5103  long gbl_reserve, regions_needed = 0;
  5104  
  5105  /* This should never happen */
  5106  if (from > to) {
  5107  VM_WARN(1, "%s called with a negative range\n", 
__func__);
  5108  return false;
  5109  }
  5110  
  5111  /*
  5112   * Only apply hugepage reservation if asked. At fault time, an
  5113   * attempt will be made for VM_NORESERVE to allocate a page
  5114   * without using reserves
  5115   */
  5116  if (vm_flags & VM_NORESERVE)
  5117  return true;
  5118  
  5119  /*
  5120   * Shared mappings base their reservation on the number of 
pages that
  5121   * are already allocated on behalf of the file. Private 
mappings need
  5122   * to reserve the full area even if read-only as mprotect() may 
be
  5123   * called to make the mapping read-write. Assume !vma is a shm 
mapping
  5124   */
  5125  if (!vma || vma->vm_flags & VM_MAYSHARE) {
  5126  /*
  5127   * resv_map can not be NULL as hugetlb_reserve_pages is 
only
  5128   * called for inodes for which resv_maps were created 
(see
  5129   * hugetlbfs_get_inode).
  5130   */
  5131  resv_map = inode_resv_map(inode);
  5132  
  5133  chg = region_chg(resv_map, from, to, _needed);
  5134  
  5135  } else {
  5136  /* Private mapping. */
  5137  resv_map = resv_map_alloc();
  5138  if (!resv_map)
  5139  return false;
  5140  
  5141  chg = to - from;
  5142  
  5143  set_vma_resv_map(vma, resv_map);
  5144  set_vma_resv_flags(vma, HPAGE_RESV_OWNER);
  5145  }
  5146  
  5147  if (chg < 0)
  5148  goto out_err;
  5149  
  5150  if (hugetlb_cgroup_charge_cgroup_rsvd(hstate_index(h),
  5151  chg * pages_per_huge_page(h), _cg) < 
0)
  5152  goto out_err;
  5153  
  5154  if (vma && !(vma->vm_flags & VM_MAYSHARE) && h_cg) {
  5155  /* For private mappings, the hugetlb_cgroup uncharge 
info hangs
  5156   * of the resv_map.
  5157   */
  5158  resv_map_set_hugetlb_cgroup_uncharge_info(resv_map, 
h_cg, h);
  5159  }
  5160  
  5161  /*
  5162   * There must be enough pages in the subpool for the mapping. If
  5163   * the subpool has a minimum size, there may be some global
  5164   * reservations already in place (gbl_reserve).
  5165   */
 

Re: [PATCH] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-02-10 Thread kernel test robot
Hi Miaohe,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20210125]
[also build test ERROR on v5.11-rc7]
[cannot apply to linux/master linus/master hnaz-linux-mm/master v5.11-rc7 
v5.11-rc6 v5.11-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Miaohe-Lin/hugetlb_cgroup-fix-imbalanced-css_get-and-css_put-pair-for-shared-mappings/20210210-171736
base:59fa6a163ffabc1bf25c5e0e33899e268a96d3cc
config: arm64-randconfig-r025-20210209 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 
c9439ca36342fb6013187d0a69aef92736951476)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# 
https://github.com/0day-ci/linux/commit/68f4ed1b80aa7c51a921c3ad913ee7e6e00618d0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Miaohe-Lin/hugetlb_cgroup-fix-imbalanced-css_get-and-css_put-pair-for-shared-mappings/20210210-171736
git checkout 68f4ed1b80aa7c51a921c3ad913ee7e6e00618d0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

>> mm/hugetlb.c:5222:17: error: incomplete definition of type 'struct 
>> hugetlb_cgroup'
   css_put(_cg->css);
^
   include/linux/hugetlb_cgroup.h:20:8: note: forward declaration of 'struct 
hugetlb_cgroup'
   struct hugetlb_cgroup;
  ^
   1 error generated.


vim +5222 mm/hugetlb.c

  5091  
  5092  /* Return true if reservation was successful, false otherwise.  */
  5093  bool hugetlb_reserve_pages(struct inode *inode,
  5094  long from, long to,
  5095  struct vm_area_struct *vma,
  5096  vm_flags_t vm_flags)
  5097  {
  5098  long chg, add = -1;
  5099  struct hstate *h = hstate_inode(inode);
  5100  struct hugepage_subpool *spool = subpool_inode(inode);
  5101  struct resv_map *resv_map;
  5102  struct hugetlb_cgroup *h_cg = NULL;
  5103  long gbl_reserve, regions_needed = 0;
  5104  
  5105  /* This should never happen */
  5106  if (from > to) {
  5107  VM_WARN(1, "%s called with a negative range\n", 
__func__);
  5108  return false;
  5109  }
  5110  
  5111  /*
  5112   * Only apply hugepage reservation if asked. At fault time, an
  5113   * attempt will be made for VM_NORESERVE to allocate a page
  5114   * without using reserves
  5115   */
  5116  if (vm_flags & VM_NORESERVE)
  5117  return true;
  5118  
  5119  /*
  5120   * Shared mappings base their reservation on the number of 
pages that
  5121   * are already allocated on behalf of the file. Private 
mappings need
  5122   * to reserve the full area even if read-only as mprotect() may 
be
  5123   * called to make the mapping read-write. Assume !vma is a shm 
mapping
  5124   */
  5125  if (!vma || vma->vm_flags & VM_MAYSHARE) {
  5126  /*
  5127   * resv_map can not be NULL as hugetlb_reserve_pages is 
only
  5128   * called for inodes for which resv_maps were created 
(see
  5129   * hugetlbfs_get_inode).
  5130   */
  5131  resv_map = inode_resv_map(inode);
  5132  
  5133  chg = region_chg(resv_map, from, to, _needed);
  5134  
  5135  } else {
  5136  /* Private mapping. */
  5137  resv_map = resv_map_alloc();
  5138  if (!resv_map)
  5139  return false;
  5140  
  5141  chg = to - from;
  5142  
  5143  set_vma_resv_map(vma, resv_map);
  5144  set_vma_resv_flags(vma, HPAGE_RESV_OWNER);
  5145  }
  5146  
  5147  if (chg < 0)
  5148  goto out_err;
  5149  
  5150  if (hugetlb_cgroup_charge_cgroup_rsvd(hstate_index(h),
  5151  chg * pages_per_huge_page(h), _cg) < 
0)
  5152  goto out_err;
  5153  
  5154  if (vma && !(vma->vm_flags & VM_MAYSHARE) && h_cg) {
  5155  /* For private