From patchwork Tue Jun 11 01:12:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 17759 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CB09725DF9 for ; Tue, 11 Jun 2013 01:13:04 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id k13sf6938698wgh.11 for ; Mon, 10 Jun 2013 18:13:04 -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=oHibg4IpgIqKbzAyAnM/ghjCiI5vxcyAjmaw9c+VfGo=; b=eV/YAwyxLs0CEdd+QCXFqqfFXygGVZGmBivhT+o5s3fQmu21yy2BJd/uzYhVLT5FZE heORXcFffvnCFhCE4i9W142QQOPyKHxp6TKUVQ0ZrnyLaT5dEFbN8ayjs/ZhlxuAAApc +Y0DRD8m2/NoJY9+9FCmeVfyzhaDW41aR2dhWJ6Ff9ewbOEPi7dtPDvmACBihlhPP9Dt jUKxJGTq/x4QxnADVWsNtI/KnC4ulWCkkCT4zjbtDeCcLWgPBpe80I7JKIkMkNxTn8D8 4oQ1PKH7iiYLsNPeKi2JloNY04TW+zovvuW0Qj6cNqRMN/hfS+B6QNGWpSp4NK3dda+h s8gg== X-Received: by 10.180.36.211 with SMTP id s19mr16137wij.1.1370913184044; Mon, 10 Jun 2013 18:13:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.76.71 with SMTP id i7ls931395wiw.34.gmail; Mon, 10 Jun 2013 18:13:03 -0700 (PDT) X-Received: by 10.194.20.97 with SMTP id m1mr6930683wje.31.1370913183915; Mon, 10 Jun 2013 18:13:03 -0700 (PDT) Received: from mail-ve0-x22d.google.com (mail-ve0-x22d.google.com [2607:f8b0:400c:c01::22d]) by mx.google.com with ESMTPS id bp3si4463588wjb.95.2013.06.10.18.13.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 18:13:03 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22d 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:c01::22d; Received: by mail-ve0-f173.google.com with SMTP id jw11so5400075veb.32 for ; Mon, 10 Jun 2013 18:13:02 -0700 (PDT) X-Received: by 10.220.91.9 with SMTP id k9mr7253523vcm.41.1370913182750; Mon, 10 Jun 2013 18:13:02 -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 pb14csp89611vcb; Mon, 10 Jun 2013 18:13:02 -0700 (PDT) X-Received: by 10.68.204.196 with SMTP id la4mr12092600pbc.190.1370913181691; Mon, 10 Jun 2013 18:13:01 -0700 (PDT) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by mx.google.com with ESMTPS id wf5si2504052pab.138.2013.06.10.18.13.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 18:13:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.170 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.170; Received: by mail-pd0-f170.google.com with SMTP id x11so2266472pdj.15 for ; Mon, 10 Jun 2013 18:13:01 -0700 (PDT) X-Received: by 10.66.164.3 with SMTP id ym3mr16331652pab.106.1370913181156; Mon, 10 Jun 2013 18:13:01 -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 qe10sm9802489pbb.2.2013.06.10.18.13.00 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 18:13:00 -0700 (PDT) From: John Stultz To: minchan@kernel.org Cc: dgiani@mozilla.com, John Stultz Subject: [PATCH 13/13] vrange: Add checks in fault handler so we return SIGBUS on purged file pages Date: Mon, 10 Jun 2013 18:12:19 -0700 Message-Id: <1370913139-9320-14-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1370913139-9320-1-git-send-email-john.stultz@linaro.org> References: <1370913139-9320-1-git-send-email-john.stultz@linaro.org> X-Gm-Message-State: ALoCoQnYmeMAT+siLxrVbwWFzLIZY/lKeYw9UHfsmrJCGgbWAhiVfEJ+bhYffXxWwnUC+f95xdhQ X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22d 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: , The earlier fvrange() work didn't handle setting the SIGBUS faulting when purged file pages were accessed. This patch remedies that. XXX: Likely need to consolidate anonymous and file page methods here. Using truncate_inode_page_ranges is easier for now then going over all the ptes and marking them w/ mkvrange(). Signed-off-by: John Stultz --- include/linux/vrange.h | 5 ++++- mm/filemap.c | 1 + mm/memory.c | 13 ++++++++++++- mm/vrange.c | 31 ++++++++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/include/linux/vrange.h b/include/linux/vrange.h index bd36d67..ac60f76 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -58,7 +58,10 @@ int discard_vpage(struct page *page); bool vrange_address(struct mm_struct *mm, unsigned long start, unsigned long end); -extern bool is_purged_vrange(struct mm_struct *mm, unsigned long address); +extern bool is_purged_anon_vrange(struct mm_struct *mm, unsigned long address); +extern bool is_purged_file_vrange(struct address_space *mapping, + unsigned long offset); + unsigned int discard_vrange_pages(struct zone *zone, int nr_to_discard); void lru_move_vrange_to_head(struct mm_struct *mm, unsigned long address); diff --git a/mm/filemap.c b/mm/filemap.c index 7905fe7..06c7997 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -33,6 +33,7 @@ #include /* for BUG_ON(!in_atomic()) only */ #include #include +#include #include "internal.h" #define CREATE_TRACE_POINTS diff --git a/mm/memory.c b/mm/memory.c index 341c794..1783327 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3486,9 +3486,20 @@ static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, pte_t *page_table, pmd_t *pmd, unsigned int flags, pte_t orig_pte) { + struct address_space *mapping = 0; + pgoff_t pgoff = (((address & PAGE_MASK) - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; + + if (vma->vm_file) + mapping = vma->vm_file->f_mapping; + + if (mapping) + if (is_purged_file_vrange(mapping, (pgoff<vroot; struct interval_tree_node *node; @@ -680,6 +680,31 @@ bool is_purged_vrange(struct mm_struct *mm, unsigned long address) return ret; } + +bool is_purged_file_vrange(struct address_space *mapping, unsigned long offset) +{ + struct vrange_root *vroot = &mapping->vroot; + struct interval_tree_node *node; + struct vrange *range; + bool ret = false; + + + if (!vroot) + return false; + + vrange_lock(vroot); + node = interval_tree_iter_first(&vroot->v_rb, offset, + offset + PAGE_SIZE - 1); + if (node) { + range = container_of(node, struct vrange, node); + if (range->purged) + ret = true; + } + vrange_unlock(vroot); + return ret; +} + + static void vrange_pte_entry(pte_t pteval, unsigned long address, unsigned ptent_size, struct mm_walk *walk) {