[Devel] [PATCH RHEL7 COMMIT] ms/mm: cleanup size checks in filemap_fault() and filemap_map_pages()

Konstantin Khorenko khorenko at virtuozzo.com
Thu Feb 27 19:07:33 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1062.12.1.vz7.131.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.12.1.vz7.131.4
------>
commit 34bb34e59250ff00af55d1306f52d8ff521fb5d3
Author: Kirill A. Shutemov <kirill.shutemov at linux.intel.com>
Date:   Thu Feb 27 19:07:33 2020 +0300

    ms/mm: cleanup size checks in filemap_fault() and filemap_map_pages()
    
    Minor cleanups:
     - 'size' variable is now in bytes, not pages;
     - use round_up(): it should be easier to read.
    
    Signed-off-by: Kirill A. Shutemov <kirill.shutemov at linux.intel.com>
    Cc: Linus Torvalds <torvalds at linux-foundation.org>
    Cc: Mel Gorman <mgorman at suse.de>
    Cc: Rik van Riel <riel at redhat.com>
    Cc: Andi Kleen <ak at linux.intel.com>
    Cc: Matthew Wilcox <matthew.r.wilcox at intel.com>
    Cc: Dave Hansen <dave.hansen at linux.intel.com>
    Cc: Alexander Viro <viro at zeniv.linux.org.uk>
    Cc: Dave Chinner <david at fromorbit.com>
    Cc: Ning Qu <quning at gmail.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    
    https://jira.sw.ru/browse/PSBM-101300
    (cherry picked from commit 99e3e53f4e0fd807607bf381e14f6de8feedd383)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/filemap.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 2ba7ef844af67..bbddfeb2675d6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2285,11 +2285,11 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	struct inode *inode = mapping->host;
 	pgoff_t offset = vmf->pgoff;
 	struct page *page;
-	pgoff_t size;
+	loff_t size;
 	int ret = 0;
 
-	size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
-	if (offset >= size)
+	size = round_up(i_size_read(inode), PAGE_CACHE_SIZE);
+	if (offset >= size >> PAGE_CACHE_SHIFT)
 		return VM_FAULT_SIGBUS;
 
 	/*
@@ -2350,8 +2350,8 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	 * Found the page and have a reference on it.
 	 * We must recheck i_size under page lock.
 	 */
-	size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
-	if (unlikely(offset >= size)) {
+	size = round_up(i_size_read(inode), PAGE_CACHE_SIZE);
+	if (unlikely(offset >= size >> PAGE_CACHE_SHIFT)) {
 		unlock_page(page);
 		page_cache_release(page);
 		return VM_FAULT_SIGBUS;
@@ -2455,8 +2455,8 @@ void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
 		if (page->mapping != mapping || !PageUptodate(page))
 			goto unlock;
 
-		size = i_size_read(mapping->host) + PAGE_CACHE_SIZE - 1;
-		if (page->index >= size	>> PAGE_CACHE_SHIFT)
+		size = round_up(i_size_read(mapping->host), PAGE_CACHE_SIZE);
+		if (page->index >= size >> PAGE_CACHE_SHIFT)
 			goto unlock;
 
 		pte = vmf->pte + page->index - vmf->pgoff;


More information about the Devel mailing list