@@ -32,6 +32,8 @@ static inline int vrange_type(struct vrange *vrange)
}
void vrange_init(void);
+extern int vrange_clear(struct vrange_root *vroot,
+ unsigned long start, unsigned long end);
extern void vrange_root_cleanup(struct vrange_root *vroot);
extern int vrange_fork(struct mm_struct *new,
struct mm_struct *old);
@@ -36,6 +36,7 @@
#include <linux/sched/sysctl.h>
#include <linux/notifier.h>
#include <linux/memory.h>
+#include <linux/vrange.h>
#include <asm/uaccess.h>
#include <asm/cacheflush.h>
@@ -1500,6 +1501,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
/* Clear old maps */
error = -ENOMEM;
munmap_back:
+
+ /* zap any volatile ranges */
+ vrange_clear(&mm->vroot, addr, addr + len);
+
if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
if (do_munmap(mm, addr, len))
return -ENOMEM;
@@ -164,6 +164,14 @@ static int vrange_remove(struct vrange_root *vroot,
return 0;
}
+int vrange_clear(struct vrange_root *vroot,
+ unsigned long start, unsigned long end)
+{
+ int purged;
+
+ return vrange_remove(vroot, start, end-1, &purged);
+}
+
void vrange_root_cleanup(struct vrange_root *vroot)
{
struct vrange *range;
At lsf-mm, the issue was brought up that there is a precedence with interfaces like mlock, such that new mappings in a pre-existing range do no inherit the mlock state. This is mostly because mlock only modifies the existing vmas, and so any new mmaps create new vmas, which won't be mlocked. Since volatility is not stored in the vma (for good cause, specfically as we'd have to have manage file volatility differently from anonymous), this patch clears volatilty on new mappings, to ensure that we don't inherit volatility if memory in an existing volatile range is unmapped and then re-mapped with something else. Thus, this patch forces any volatility to be cleared on mmap. XXX - Minchan would like to see this issue addressed differently. Signed-off-by: John Stultz <john.stultz@linaro.org> --- include/linux/vrange.h | 2 ++ mm/mmap.c | 5 +++++ mm/vrange.c | 8 ++++++++ 3 files changed, 15 insertions(+)