[Devel] [PATCH rh7] Port diff-mm-mmap-call-mmap-prep-only-for-regular-files

Vladimir Davydov vdavydov at parallels.com
Thu Aug 20 02:33:50 PDT 2015


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 31cd9d73417c..e0ac8ae736ff 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);
-- 
2.1.4




More information about the Devel mailing list