From patchwork Tue Jun 11 02:11:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 17763 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7ADB72397B for ; Tue, 11 Jun 2013 02:11:43 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id kw10sf1152895vcb.3 for ; Mon, 10 Jun 2013 19:11:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=3Ut71jAsYmrSxIJq73YeAcFNuS5sglbUX/LUXfYCCGQ=; b=Aovtmsy9WYgtzioE21BQ12OtEg1H9LkG/OmQbK8chUaDWBFRwvzr792gHvkLegzdJG h8jpsQhsSBDQmn7KNBO7Qc/SLDY1SydXCgOKWwnZUdHS/VXf6VjLk+He21hV8G34Q2UJ 7aSVt9Jye2HLFHvi6MKniAIbLkB4R/OMz4VPaw9yqtAtNOIurWiOEb32jygFH7uweazJ +eoVgCEcLMkqmiJUD7jx7JI/OopuMdjJ5GPiI1+LCFqJ35ae9+qyjuaNCa09dj9afTQm VKQMPIKqUbWSrGGX/CzhY2wvi3RPR1s1bgen04tJkJ0rJQVtZbzVr5usoXmfIH9Iy6Sc CJCg== X-Received: by 10.224.205.138 with SMTP id fq10mr9859780qab.1.1370916703189; Mon, 10 Jun 2013 19:11:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.52.40 with SMTP id q8ls3095743qeo.1.gmail; Mon, 10 Jun 2013 19:11:42 -0700 (PDT) X-Received: by 10.52.68.205 with SMTP id y13mr6012113vdt.33.1370916702935; Mon, 10 Jun 2013 19:11:42 -0700 (PDT) Received: from mail-vb0-x233.google.com (mail-vb0-x233.google.com [2607:f8b0:400c:c02::233]) by mx.google.com with ESMTPS id ha3si6194385vdb.134.2013.06.10.19.11.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 19:11:42 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::233 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::233; Received: by mail-vb0-f51.google.com with SMTP id x17so4798747vbf.38 for ; Mon, 10 Jun 2013 19:11:42 -0700 (PDT) X-Received: by 10.220.246.8 with SMTP id lw8mr7196900vcb.8.1370916702802; Mon, 10 Jun 2013 19:11:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.10.206 with SMTP id pb14csp90903vcb; Mon, 10 Jun 2013 19:11:42 -0700 (PDT) X-Received: by 10.66.145.2 with SMTP id sq2mr16294515pab.2.1370916701702; Mon, 10 Jun 2013 19:11:41 -0700 (PDT) Received: from mail-pd0-f175.google.com (mail-pd0-f175.google.com [209.85.192.175]) by mx.google.com with ESMTPS id av8si5937723pbd.9.2013.06.10.19.11.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 19:11:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.175 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.175; Received: by mail-pd0-f175.google.com with SMTP id 4so8060742pdd.20 for ; Mon, 10 Jun 2013 19:11:41 -0700 (PDT) X-Received: by 10.68.52.10 with SMTP id p10mr12509999pbo.92.1370916701203; Mon, 10 Jun 2013 19:11:41 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id nt2sm12427175pbc.17.2013.06.10.19.11.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 19:11:40 -0700 (PDT) From: John Stultz To: minchan.kim@lge.com Cc: John Stultz Subject: [PATCH 04/13] vrange: Clear volatility on new mmaps Date: Mon, 10 Jun 2013 19:11:23 -0700 Message-Id: <1370916692-9576-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1370916692-9576-1-git-send-email-john.stultz@linaro.org> References: <1370916692-9576-1-git-send-email-john.stultz@linaro.org> X-Gm-Message-State: ALoCoQmwMMBdawAq0ExToJau+fLAVcZbnHxhICMM0ZbnGBMqpfkiZ2aIv5+U7CtFkjKXvHmmjuQA X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::233 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- include/linux/vrange.h | 2 ++ mm/mmap.c | 5 +++++ mm/vrange.c | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/include/linux/vrange.h b/include/linux/vrange.h index 13f4887..a97ac25 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -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); diff --git a/mm/mmap.c b/mm/mmap.c index f681e18..80d3676 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -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; diff --git a/mm/vrange.c b/mm/vrange.c index bbaa184..5ca8853 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -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;