All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	<linux-mm@kvack.org>, <linux-fsdevel@vger.kernel.org>,
	Al Viro <viro@ZenIV.linux.org.uk>,
	Hugh Dickins <hugh@veritas.com>, Tejun Heo <tj@kernel.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [RFC][PATCH 1/9] mm: Introduce remap_file_mappings.
Date: Sat, 11 Apr 2009 05:03:23 -0700	[thread overview]
Message-ID: <m1myan75ys.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <m1skkf761y.fsf@fess.ebiederm.org> (Eric W. Biederman's message of "Sat\, 11 Apr 2009 05\:01\:29 -0700")


>From 819088d701e3a821db8e08ed83d46c00c27cc772 Mon Sep 17 00:00:00 2001
From: Eric W. Biederman <ebiederm@xmission.com>
Date: Tue, 7 Apr 2009 19:35:07 -0700
Subject: 

When the backing store of a file becomes inaccessible we need a function
to remove that file from the page tables and arrange for page faults
to receive SIGBUS until the file is unmapped.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 include/linux/mm.h |    1 +
 mm/memory.c        |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index bff1f0d..96d8342 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -807,6 +807,7 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
 
 extern int vmtruncate(struct inode * inode, loff_t offset);
 extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end);
+extern void remap_file_mappings(struct file *file, struct vm_operations_struct *vm_ops);
 
 #ifdef CONFIG_MMU
 extern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
diff --git a/mm/memory.c b/mm/memory.c
index cf6873e..dcd0a3c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2325,6 +2325,93 @@ void unmap_mapping_range(struct address_space *mapping,
 }
 EXPORT_SYMBOL(unmap_mapping_range);
 
+static void remap_vma(struct vm_area_struct *vma,
+		      struct vm_operations_struct *vm_ops)
+{
+	struct file *file = vma->vm_file;
+	struct address_space *mapping = file->f_mapping;
+	unsigned long start_addr, end_addr, size;
+	struct mm_struct *mm;
+
+	start_addr = vma->vm_start;
+	end_addr = vma->vm_end;
+
+	/* Has this vma already been processed? */
+	if (vma->vm_ops == vm_ops)
+		return;
+
+	/* Switch out the locks so I can maninuplate this under the mm sem.
+	 * Needed so I can call vm_ops->close.
+	 */
+	mm = vma->vm_mm;
+	atomic_inc(&mm->mm_users);
+	spin_unlock(&mapping->i_mmap_lock);
+
+	/* Block page faults and other code modifying the mm. */
+	down_write(&mm->mmap_sem);
+
+	/* Lookup a vma for my file address */
+	vma = find_vma(mm, start_addr);
+	if (vma->vm_file != file)
+		goto out;
+	if (vma->vm_ops == vm_ops)
+		goto out;
+
+	start_addr = vma->vm_start;
+	end_addr   = vma->vm_end;
+	size	   = end_addr - start_addr;
+
+	/* Unmap the vma */
+	zap_page_range(vma, start_addr, size, NULL);
+
+	/* Close the vma */
+	if (vma->vm_ops && vma->vm_ops->close)
+		vma->vm_ops->close(vma);
+
+	/* Repurpose the vma  */
+	vma->vm_private_data = NULL;
+	vma->vm_ops = vm_ops;
+	if (vm_ops->open)
+		vm_ops->open(vma);
+out:
+	up_write(&mm->mmap_sem);
+	spin_lock(&mapping->i_mmap_lock);
+}
+
+void remap_file_mappings(struct file *file, struct vm_operations_struct *vm_ops)
+{
+	/* After file->f_ops has been changed update the vmas */
+	struct address_space *mapping = file->f_mapping;
+	struct vm_area_struct *vma;
+	struct prio_tree_iter iter;
+
+	spin_lock(&mapping->i_mmap_lock);
+
+restart_tree:
+	vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, 0, ULONG_MAX) {
+		/* Skip quickly over vmas that do not need to be touched */
+		if (vma->vm_file != file)
+			continue;
+		if (vma->vm_ops == vm_ops)
+			continue;
+		remap_vma(vma, vm_ops);
+		goto restart_tree;
+	}
+
+restart_list:
+	list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.vm_set.list) {
+		/* Skip quickly over vmas that do not need to be touched */
+		if (vma->vm_file != file)
+			continue;
+		if (vma->vm_ops == vm_ops)
+			continue;
+		remap_vma(vma, vm_ops);
+		goto restart_list;
+	}
+
+	spin_unlock(&mapping->i_mmap_lock);
+}
+
 /**
  * vmtruncate - unmap mappings "freed" by truncate() syscall
  * @inode: inode of the file used
-- 
1.6.1.2.350.g88cc


WARNING: multiple messages have this Message-ID (diff)
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	Al Viro <viro@ZenIV.linux.org.uk>,
	Hugh Dickins <hugh@veritas.com>, Tejun Heo <tj@kernel.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [RFC][PATCH 1/9] mm: Introduce remap_file_mappings.
Date: Sat, 11 Apr 2009 05:03:23 -0700	[thread overview]
Message-ID: <m1myan75ys.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <m1skkf761y.fsf@fess.ebiederm.org> (Eric W. Biederman's message of "Sat\, 11 Apr 2009 05\:01\:29 -0700")



  reply	other threads:[~2009-04-11 12:03 UTC|newest]

Thread overview: 207+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-11 12:01 [RFC][PATCH 0/9] File descriptor hot-unplug support Eric W. Biederman
2009-04-11 12:01 ` Eric W. Biederman
2009-04-11 12:03 ` Eric W. Biederman [this message]
2009-04-11 12:03   ` [RFC][PATCH 1/9] mm: Introduce remap_file_mappings Eric W. Biederman
2009-04-11 12:05 ` [RFC][PATCH 2/9] mm: Implement generic support for revoking a mapping Eric W. Biederman
2009-04-11 12:05   ` Eric W. Biederman
2009-04-11 12:05   ` Eric W. Biederman
2009-04-11 12:06 ` [RFC][PATCH 3/9] sysfs: Use remap_file_mappings Eric W. Biederman
2009-04-11 12:06   ` Eric W. Biederman
2009-04-11 12:06   ` Eric W. Biederman
2009-04-11 12:07 ` [RFC][PATCH 4/9] vfs: Generalize the file_list Eric W. Biederman
2009-04-11 12:07   ` Eric W. Biederman
2009-04-11 12:07   ` Eric W. Biederman
2009-04-11 12:08 ` [RFC][PATCH 5/9] vfs: Introduce basic infrastructure for revoking a file Eric W. Biederman
2009-04-11 12:08   ` Eric W. Biederman
2009-04-11 12:08   ` Eric W. Biederman
2009-04-14 22:12   ` Jonathan Corbet
2009-04-14 22:12     ` Jonathan Corbet
2009-04-15  2:55     ` Eric W. Biederman
2009-04-15  2:55       ` Eric W. Biederman
2009-04-15  2:55       ` Eric W. Biederman
2009-04-11 12:10 ` [RFC][PATCH 6/9] vfs: Utilize fops_read_lock where appropriate Eric W. Biederman
2009-04-11 12:10   ` Eric W. Biederman
2009-04-11 12:10   ` Eric W. Biederman
2009-04-11 12:11 ` [RFC][PATCH 7/9] vfs: Optimize fops_read_lock Eric W. Biederman
2009-04-11 12:11   ` Eric W. Biederman
2009-04-11 12:11   ` Eric W. Biederman
2009-04-11 12:13 ` [RFC][PATCH 8/9] vfs: Implement generic revoked file operations Eric W. Biederman
2009-04-11 12:13   ` Eric W. Biederman
2009-04-11 12:13   ` Eric W. Biederman
2009-04-12 18:56   ` Jamie Lokier
2009-04-12 18:56     ` Jamie Lokier
2009-04-12 20:04     ` Eric W. Biederman
2009-04-12 20:04       ` Eric W. Biederman
2009-04-12 20:31       ` Jamie Lokier
2009-04-12 20:31         ` Jamie Lokier
2009-04-12 21:53         ` Eric W. Biederman
2009-04-12 21:53           ` Eric W. Biederman
2009-04-12 20:54       ` Eric W. Biederman
2009-04-12 20:54         ` Eric W. Biederman
2009-04-12 21:02         ` Jamie Lokier
2009-04-12 21:02           ` Jamie Lokier
2009-04-12 23:06           ` Eric W. Biederman
2009-04-12 23:06             ` Eric W. Biederman
2009-04-11 12:14 ` [RFC][PATCH 9/9] proc: Use the generic vfs revoke facility that now exists Eric W. Biederman
2009-04-11 12:14   ` Eric W. Biederman
2009-04-11 15:58 ` [RFC][PATCH 0/9] File descriptor hot-unplug support Al Viro
2009-04-11 15:58   ` Al Viro
2009-04-11 16:49   ` Eric W. Biederman
2009-04-11 16:49     ` Eric W. Biederman
2009-04-11 16:56     ` Al Viro
2009-04-11 16:56       ` Al Viro
2009-04-11 23:57       ` Eric W. Biederman
2009-04-11 23:57         ` Eric W. Biederman
2009-04-12 20:21       ` Eric W. Biederman
2009-04-12 20:21         ` Eric W. Biederman
2009-04-14  3:16 ` Tejun Heo
2009-04-14  3:16   ` Tejun Heo
2009-04-14  7:39   ` Eric W. Biederman
2009-04-14  7:39     ` Eric W. Biederman
2009-04-14  7:45     ` Tejun Heo
2009-04-14  7:45       ` Tejun Heo
2009-04-14  8:27       ` Eric W. Biederman
2009-04-14  8:27         ` Eric W. Biederman
2009-04-14  8:49         ` Tejun Heo
2009-04-14  8:49           ` Tejun Heo
2009-04-14 15:07         ` Jamie Lokier
2009-04-14 15:07           ` Jamie Lokier
2009-04-14 19:09           ` Eric W. Biederman
2009-04-14 19:09             ` Eric W. Biederman
2009-06-01 21:45 ` [PATCH 0/23] File descriptor hot-unplug support v2 Eric W. Biederman
2009-06-01 21:45   ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 01/23] mm: Introduce revoke_file_mappings Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 22:25     ` Andrew Morton
2009-06-01 22:25       ` Andrew Morton
2009-06-02  0:12       ` Eric W. Biederman
2009-06-02  0:12         ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 02/23] vfs: Implement unpoll_file Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-06  8:08     ` Al Viro
2009-06-06  8:08       ` Al Viro
2009-06-01 21:50   ` [PATCH 03/23] vfs: Generalize the file_list Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-02  7:06     ` Nick Piggin
2009-06-02  7:06       ` Nick Piggin
2009-06-05 19:33       ` Eric W. Biederman
2009-06-05 19:33         ` Eric W. Biederman
2009-06-09 10:38         ` Nick Piggin
2009-06-09 10:38           ` Nick Piggin
2009-06-09 18:38           ` Eric W. Biederman
2009-06-09 18:38             ` Eric W. Biederman
2009-06-10  6:05             ` Nick Piggin
2009-06-10  6:05               ` Nick Piggin
2009-06-01 21:50   ` [PATCH 04/23] vfs: Introduce infrastructure for revoking a file Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-02  5:16     ` Pekka Enberg
2009-06-02  5:16       ` Pekka Enberg
2009-06-02  6:51       ` Eric W. Biederman
2009-06-02  6:51         ` Eric W. Biederman
2009-06-02  7:08         ` Pekka Enberg
2009-06-02  7:08           ` Pekka Enberg
2009-06-02  7:08           ` Pekka Enberg
2009-06-02  7:14     ` Nick Piggin
2009-06-02  7:14       ` Nick Piggin
2009-06-02 17:06       ` Linus Torvalds
2009-06-02 17:06         ` Linus Torvalds
2009-06-02 20:52         ` Eric W. Biederman
2009-06-02 20:52           ` Eric W. Biederman
2009-06-03  6:37           ` Nick Piggin
2009-06-03  6:37             ` Nick Piggin
2009-06-02 22:56       ` Eric W. Biederman
2009-06-02 22:56         ` Eric W. Biederman
2009-06-03  6:38         ` Nick Piggin
2009-06-03  6:38           ` Nick Piggin
2009-06-05  9:03     ` Miklos Szeredi
2009-06-05  9:03       ` Miklos Szeredi
2009-06-05 19:06       ` Eric W. Biederman
2009-06-05 19:06         ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 05/23] vfs: Teach lseek to use file_hotplug_lock Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 06/23] vfs: Teach read/write to use file_hotplug_read_lock Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 07/23] vfs: Teach sendfile,splice,tee,and vmsplice to use file_hotplug_lock Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-03 23:39     ` Badari Pulavarty
2009-06-03 23:39       ` Badari Pulavarty
2009-06-05 19:37       ` Eric W. Biederman
2009-06-05 19:37         ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 08/23] vfs: Teach readdir " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 09/23] vfs: Teach poll and select " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 10/23] vfs: Teach do_path_lookup " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 11/23] mm: Teach mmap " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 12/23] vfs: Teach fcntl " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 13/23] vfs: Teach ioctl " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 14/23] vfs: Teach flock " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 15/23] vfs: Teach fallocate, and filp_close " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 16/23] vfs: Teach fstatfs, fstatfs64, ftruncate, fchdir, fchmod, fchown " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 17/23] proc: Teach /proc/<pid>/fd " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 18/23] vfs: Teach epoll " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-02 16:51     ` Davide Libenzi
2009-06-02 16:51       ` Davide Libenzi
2009-06-02 21:23       ` Eric W. Biederman
2009-06-02 21:23         ` Eric W. Biederman
2009-06-02 21:52         ` Davide Libenzi
2009-06-02 21:52           ` Davide Libenzi
2009-06-02 22:51           ` Eric W. Biederman
2009-06-02 22:51             ` Eric W. Biederman
2009-06-03 14:57             ` Davide Libenzi
2009-06-03 14:57               ` Davide Libenzi
2009-06-03 20:53               ` Eric W. Biederman
2009-06-03 20:53                 ` Eric W. Biederman
2009-06-04  0:50                 ` Davide Libenzi
2009-06-04  0:50                   ` Davide Libenzi
2009-06-04  1:42                   ` Eric W. Biederman
2009-06-04  1:42                     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 19/23] eventpoll: Fix comment Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 20/23] vfs: Teach aio to use file_hotplug_lock Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 21/23] vfs: Teach fsync " Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 22/23] vfs: Teach fadvice to file_hotplug_lock Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-01 21:50   ` [PATCH 23/23] vfs: Teach readahead to use the file_hotplug_lock Eric W. Biederman
2009-06-01 21:50     ` Eric W. Biederman
2009-06-03 23:25     ` Badari Pulavarty
2009-06-03 23:25       ` Badari Pulavarty
2009-06-06  8:03   ` [PATCH 0/23] File descriptor hot-unplug support v2 Al Viro
2009-06-06  8:03     ` Al Viro
2009-06-08  9:41     ` Miklos Szeredi
2009-06-08  9:41       ` Miklos Szeredi
2009-06-08 10:24       ` Jamie Lokier
2009-06-08 10:24         ` Jamie Lokier
2009-06-08 16:29       ` Al Viro
2009-06-08 16:29         ` Al Viro
2009-06-08 16:44         ` Miklos Szeredi
2009-06-08 16:44           ` Miklos Szeredi
2009-06-08 17:50           ` Al Viro
2009-06-08 17:50             ` Al Viro
2009-06-08 18:01             ` Linus Torvalds
2009-06-08 18:01               ` Linus Torvalds
2009-06-08 18:50               ` Al Viro
2009-06-08 18:50                 ` Al Viro
2009-06-08 19:18                 ` Linus Torvalds
2009-06-08 19:18                   ` Linus Torvalds
2009-06-09  6:42                   ` Eric W. Biederman
2009-06-09  6:42                     ` Eric W. Biederman
2009-06-09 10:52                     ` Nick Piggin
2009-06-09 10:52                       ` Nick Piggin
2009-06-09  5:50             ` Miklos Szeredi
2009-06-09  5:50               ` Miklos Szeredi
2009-06-09  6:31               ` Eric W. Biederman
2009-06-09  6:31                 ` Eric W. Biederman
2009-06-09  6:22     ` Eric W. Biederman
2009-06-09  6:22       ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1myan75ys.fsf@fess.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@suse.de \
    --cc=hugh@veritas.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.