From patchwork Tue Feb 25 21:28:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 25317 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0DB3F20543 for ; Tue, 25 Feb 2014 21:29:03 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id n16sf3744873oag.9 for ; Tue, 25 Feb 2014 13:29:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=wT5afqUYf8sl56KhnD0YPX0UMnKCYUJGKNABb5fOPz4=; b=I1mvxgXvp1xEjL4oOLj8g75BkgcxafV/F1Vf0pi6aGSP2uXXVxjsBOEfQboMKt83q5 gaQ0bE2CF08w2I6N9BoPT5+o2qs+oF81tzmdIn6oy8nZ0HO9RtVqIEvefjsZHkzYaNkP 0lPWtjQr2Bl4XrOomRYRb9woRtxgJs+70ifWv3KXMO/PW6PxuOYC8zqbGT5aFkC2h1Dy u3WFHd90vxvznAUeSs9lUu/H0C3nF+y5Mv61+6Cx1wrgiojfFniDAJDXbakJtlPOaHgB BTvUoRUKFkquH8+W8WmjXko63+KDH9TX8bfWbNHbB35F0jynqhH7bGIYICEHD4cgbsDL DE+w== X-Gm-Message-State: ALoCoQlhhVFw/AAZz65QJTCuKntl0Q29sVTH2DhvZCUo66Ex/TDgRAnc/qfLVA2EW42DxscLVoTu X-Received: by 10.42.70.142 with SMTP id f14mr830064icj.6.1393363743477; Tue, 25 Feb 2014 13:29:03 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.161 with SMTP id d30ls1960766qge.4.gmail; Tue, 25 Feb 2014 13:29:03 -0800 (PST) X-Received: by 10.52.232.168 with SMTP id tp8mr1438876vdc.38.1393363743322; Tue, 25 Feb 2014 13:29:03 -0800 (PST) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id sm10si7163381vec.81.2014.02.25.13.29.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 13:29:03 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id id10so7978522vcb.13 for ; Tue, 25 Feb 2014 13:29:03 -0800 (PST) X-Received: by 10.220.164.80 with SMTP id d16mr2744860vcy.15.1393363743244; Tue, 25 Feb 2014 13:29:03 -0800 (PST) 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.220.174.196 with SMTP id u4csp168918vcz; Tue, 25 Feb 2014 13:29:02 -0800 (PST) X-Received: by 10.66.150.69 with SMTP id ug5mr3989670pab.55.1393363742427; Tue, 25 Feb 2014 13:29:02 -0800 (PST) Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by mx.google.com with ESMTPS id yc8si4836988pbc.247.2014.02.25.13.29.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 13:29:02 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.48 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.48; Received: by mail-pa0-f48.google.com with SMTP id kx10so8676883pab.35 for ; Tue, 25 Feb 2014 13:29:01 -0800 (PST) X-Received: by 10.68.93.132 with SMTP id cu4mr1979512pbb.129.1393363741916; Tue, 25 Feb 2014 13:29:01 -0800 (PST) Received: from buildbox.hsd1.or.comcast.net (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id pp5sm13870254pbb.33.2014.02.25.13.29.00 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 13:29:01 -0800 (PST) From: John Stultz To: Minchan Kim Cc: John Stultz Subject: [PATCH 2/2] vrange: Try to add sigbus semantics. Date: Tue, 25 Feb 2014 13:28:49 -0800 Message-Id: <1393363729-8459-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393363729-8459-1-git-send-email-john.stultz@linaro.org> References: <1393363729-8459-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 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: , This patch tries to add sigbus semantics when applications access volatile pages that have been purged. XXX: this breaks the pages_purged reporting. This patch is based on earlier work of Minchan's, so credit to him for his original work. Cc: Minchan Kim Signed-off-by: John Stultz --- include/linux/swap.h | 6 +++++- include/linux/vrange.h | 14 +++++++++++++- mm/memory.c | 24 ++++++++++++++++++++++++ mm/vrange.c | 2 +- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 46ba0c6..d90d245 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -49,6 +49,9 @@ static inline int current_is_kswapd(void) * actions on faults. */ +#define SWP_VRANGE_NUM 1 +#define SWP_VRANGE (MAX_SWAPFILES + SWP_HWPOISON_NUM + SWP_MIGRATION_NUM) + /* * NUMA node memory migration support */ @@ -71,7 +74,8 @@ static inline int current_is_kswapd(void) #endif #define MAX_SWAPFILES \ - ((1 << MAX_SWAPFILES_SHIFT) - SWP_MIGRATION_NUM - SWP_HWPOISON_NUM) + ((1 << MAX_SWAPFILES_SHIFT) - SWP_MIGRATION_NUM - SWP_HWPOISON_NUM \ + -SWP_VRANGE_NUM) /* * Magic header for a swap area. The first part of the union is diff --git a/include/linux/vrange.h b/include/linux/vrange.h index 696e001..d51d822 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -2,11 +2,23 @@ #define _LINUX_VRANGE_H #include - +#include +#include #define VRANGE_NONVOLATILE 0 #define VRANGE_VOLATILE 1 extern int discard_vpage(struct page *page); +static inline swp_entry_t make_vrange_entry(void) +{ + return swp_entry(SWP_VRANGE, 0); +} + +static inline int is_vrange_entry(swp_entry_t entry) +{ + return swp_type(entry) == SWP_VRANGE; +} + + #endif /* _LINUX_VRANGE_H */ diff --git a/mm/memory.c b/mm/memory.c index be6a0c0..2e8dc62 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -807,6 +808,8 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, if (unlikely(!pte_present(pte))) { if (!pte_file(pte)) { swp_entry_t entry = pte_to_swp_entry(pte); + if (is_vrange_entry(entry)) + goto out_set_pte; if (swap_duplicate(entry) < 0) return entry.val; @@ -1152,6 +1155,8 @@ again: print_bad_pte(vma, addr, ptent, NULL); } else { swp_entry_t entry = pte_to_swp_entry(ptent); + if (is_vrange_entry(entry)) + goto out; if (!non_swap_entry(entry)) rss[MM_SWAPENTS]--; @@ -1168,6 +1173,7 @@ again: if (unlikely(!free_swap_and_cache(entry))) print_bad_pte(vma, addr, ptent, NULL); } +out: pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); } while (pte++, addr += PAGE_SIZE, addr != end); @@ -3642,6 +3648,8 @@ static int handle_pte_fault(struct mm_struct *mm, entry = *pte; if (!pte_present(entry)) { + swp_entry_t vrange_entry; +retry: if (pte_none(entry)) { if (vma->vm_ops) { if (likely(vma->vm_ops->fault)) @@ -3651,6 +3659,22 @@ static int handle_pte_fault(struct mm_struct *mm, return do_anonymous_page(mm, vma, address, pte, pmd, flags); } + + vrange_entry = pte_to_swp_entry(entry); + if (unlikely(is_vrange_entry(vrange_entry))) { + if (vma->vm_flags & VM_VOLATILE) + return VM_FAULT_SIGBUS; + /* zap pte */ + ptl = pte_lockptr(mm, pmd); + spin_lock(ptl); + if (unlikely(!pte_same(*pte, entry))) + goto unlock; + flush_cache_page(vma, address, pte_pfn(*pte)); + ptep_clear_flush(vma, address, pte); + pte_unmap_unlock(pte, ptl); + goto retry; + } + if (pte_file(entry)) return do_nonlinear_fault(mm, vma, address, pte, pmd, flags, entry); diff --git a/mm/vrange.c b/mm/vrange.c index b80f611..69b58d0 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -209,7 +209,7 @@ static void try_to_discard_one(struct page *page, struct vm_area_struct *vma) page_remove_rmap(page); page_cache_release(page); -// set_pte_at(mm, addr, pte, swp_entry_to_pte(make_vrange_entry())); + set_pte_at(mm, addr, pte, swp_entry_to_pte(make_vrange_entry())); pte_unmap_unlock(pte, ptl); mmu_notifier_invalidate_page(mm, addr);