[Devel] [PATCH RHEL7 COMMIT] mmap: call mmap prep only for regular files

Konstantin Khorenko khorenko at virtuozzo.com
Tue Sep 1 05:16:59 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-229.7.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.6.5
------>
commit 1e596ab0358ff8dde342efb6274e08459d08a711
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Tue Sep 1 16:16:59 2015 +0400

    mmap: call mmap prep only for regular files
    
    Port 2.6.32-x diff-mm-mmap-call-mmap-prep-only-for-regular-files
    
    We forgot to port this patch. This results in KP on an attempt to mmap a
    char device on ext4.
    
    =============================================================================
    Author: Vladimir Davydov
    Email: vdavydov at parallels.com
    Subject: mmap: call mmap prep only for regular files
    Date: Mon, 17 Feb 2014 12:59:36 +0400
    
    To give FS a chance to clear pfcache csum on shared mmap, we issue
    ->mmap(vma=NULL) for those FS's that want it (FS_HAS_MMAP_PREP) before
    taking mmap_sem (we can't do it under mmap_sem due to lockdep, see
    PSBM-23133). There we haven't checked arguments properly yet. In
    particular, the file can refer to a device, in which case we will
    crash, because devices' ->mmap (e.g. /dev/zero) is not supposed to be
    called with vma=NULL. Fix this by checking if the file refers to a
    regular file before calling mmap prep for it.
    
    https://bugzilla.openvz.org/show_bug.cgi?id=2886
    https://jira.sw.ru/browse/PSBM-25031
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    Acked-by: Dmitry Monakhov <dmonakhov at openvz.org>
    =============================================================================
    
    Reported-by: Andrew Perepechko <panda at cloudlinux.com>
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    
    Cc: Andrew Perepechko <panda at cloudlinux.com>
    Cc: Alex Lyashkov <umka at cloudlinux.com>
    Cc: Igor Seletskiy <i at cloudlinux.com>
---
 mm/util.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/util.c b/mm/util.c
index 31cd9d7..e0ac8ae 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -367,6 +367,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	if (!ret) {
 		/* Ugly fix for PSBM-23133 vdavydov@ */
 		if (file && file->f_op && (flag & MAP_TYPE) == MAP_SHARED &&
+		    S_ISREG(file_inode(file)->i_mode) &&
 		    (file_inode(file)->i_sb->s_type->fs_flags & FS_HAS_MMAP_PREP))
 			file->f_op->mmap(file, NULL);
 		down_write(&mm->mmap_sem);



More information about the Devel mailing list