Skip to content
  • Mike Kravetz's avatar
    mm/hugetlbfs: fix bugs in fallocate hole punch of areas with holes · 1817889e
    Mike Kravetz authored
    Hugh Dickins pointed out problems with the new hugetlbfs fallocate hole
    punch code.  These problems are in the routine remove_inode_hugepages and
    mostly occur in the case where there are holes in the range of pages to be
    removed.  These holes could be the result of a previous hole punch or
    simply sparse allocation.  The current code could access pages outside the
    specified range.
    
    remove_inode_hugepages handles both hole punch and truncate operations.
    Page index handling was fixed/cleaned up so that the loop index always
    matches the page being processed.  The code now only makes a single pass
    through the range of pages as it was determined page faults could not race
    with truncate.  A cond_resched() was added after removing up to
    PAGEVEC_SIZE pages.
    
    Some totally unnecessary code in hugetlbfs_fallocate() that remained from
    early development was also removed.
    
    Tested with fallocate tests submitted here:
    http://librelist.com/browser//libhugetlbfs/2015/6/25/patch-tests-add-tests-for-fallocate-system-call/
    And, some ftruncate tests under development
    
    Fixes: b5cec28d
    
     ("hugetlbfs: truncate_hugepages() takes a range of pages")
    Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
    Acked-by: default avatarHugh Dickins <hughd@google.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: "Hillf Danton" <hillf.zj@alibaba-inc.com>
    Cc: <stable@vger.kernel.org>	[4.3]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    1817889e