From patchwork Fri May 3 18:27:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 16701 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A3B1A23905 for ; Fri, 3 May 2013 18:27:43 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id m1sf3418631ves.10 for ; Fri, 03 May 2013 11:27:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received: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=kaZ6r5YVhMiIK66wEzKU7j/ghHw7X05y61M783oQKMA=; b=RhNKQ7RUurwPkNnD3WLUHweEbTkuaqyKFLszvaQyyuAN9YUgwhY6Lew5u9/gfUJ0JB q1AlR9LRmnE4r2p1sTMkT6KEi4W6nwub728fYsM5iPsmaIeNJGEAbKJhB70l40skIR2B MoLF4PcoffW4TYiDxn21knwU8weNqKAIG5P0CGbrrPsktnRivwMUL6paCLBO/IzY6LYz hT74NpJeTW/MTK/7DadoqJGGuDrS5DTRtBnGRVBXguaYS8rorVmz5U6GL6UmVMMmRGSG S7w0O5kVTYEtNV+cQFkmwCp89Y0EmTNBNN7di5ElJtlTWe2PQowd6TjxWPL70sva1m4+ qYAg== X-Received: by 10.236.87.79 with SMTP id x55mr1782452yhe.54.1367605653375; Fri, 03 May 2013 11:27:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.128.104 with SMTP id nn8ls704314qeb.64.gmail; Fri, 03 May 2013 11:27:33 -0700 (PDT) X-Received: by 10.221.9.136 with SMTP id ow8mr3970047vcb.58.1367605652955; Fri, 03 May 2013 11:27:32 -0700 (PDT) Received: from mail-vb0-x22b.google.com (mail-vb0-x22b.google.com [2607:f8b0:400c:c02::22b]) by mx.google.com with ESMTPS id p20si5546832veh.12.2013.05.03.11.27.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 May 2013 11:27:32 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::22b 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::22b; Received: by mail-vb0-f43.google.com with SMTP id p14so1625894vbm.30 for ; Fri, 03 May 2013 11:27:32 -0700 (PDT) X-Received: by 10.58.230.130 with SMTP id sy2mr4008996vec.22.1367605652783; Fri, 03 May 2013 11:27:32 -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.58.127.98 with SMTP id nf2csp34386veb; Fri, 3 May 2013 11:27:32 -0700 (PDT) X-Received: by 10.66.255.99 with SMTP id ap3mr16187668pad.102.1367605651894; Fri, 03 May 2013 11:27:31 -0700 (PDT) Received: from mail-pb0-x233.google.com (mail-pb0-x233.google.com [2607:f8b0:400e:c01::233]) by mx.google.com with ESMTPS id pt5si4086742pac.156.2013.05.03.11.27.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 May 2013 11:27:31 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c01::233 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=2607:f8b0:400e:c01::233; Received: by mail-pb0-f51.google.com with SMTP id wy7so1029440pbc.10 for ; Fri, 03 May 2013 11:27:31 -0700 (PDT) X-Received: by 10.66.138.109 with SMTP id qp13mr15862666pab.127.1367605651440; Fri, 03 May 2013 11:27:31 -0700 (PDT) Received: from localhost.localdomain (c-24-21-54-107.hsd1.or.comcast.net. [24.21.54.107]) by mx.google.com with ESMTPSA id qh4sm13792406pac.8.2013.05.03.11.27.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 May 2013 11:27:30 -0700 (PDT) From: John Stultz To: Minchan Kim Cc: John Stultz Subject: [PATCH 07/12] vrange: Send SIGBUS when user try to access purged page Date: Fri, 3 May 2013 11:27:11 -0700 Message-Id: <1367605636-18284-8-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1367605636-18284-1-git-send-email-john.stultz@linaro.org> References: <1367605636-18284-1-git-send-email-john.stultz@linaro.org> X-Gm-Message-State: ALoCoQkF/gDxjfvkougDO+rm/w1vcfMz8bth4PsLPJP1kCd/akoJsuN6abuFFaMey734X0JO5ygy X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::22b 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: , From: Minchan Kim By vrange(2) semantic, user should see SIGBUG if he try to access purged page without vrange(...VRANGE_NOVOLATILE). This patch implements it. I reused PSE bit for quick prototype without enough considering so need time to see what's empty bit and I am surely missing many places to handle vrange pte bit. I should investigate all of pte handling places, especially pte_none case. TODO Signed-off-by: Minchan Kim Signed-off-by: John Stultz --- arch/x86/include/asm/pgtable_types.h | 2 ++ include/asm-generic/pgtable.h | 11 +++++++++++ include/linux/vrange.h | 2 ++ mm/memory.c | 23 +++++++++++++++++++++-- mm/vrange.c | 24 +++++++++++++++++++++++- 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 567b5d0..8c5163f 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -64,6 +64,8 @@ #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE) #define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE) +#define _PAGE_VRANGE _PAGE_BIT_PSE + /* * _PAGE_NUMA indicates that this page will trigger a numa hinting * minor page fault to gather numa placement statistics (see diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index bfd8768..1486d42 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -469,6 +469,17 @@ static inline unsigned long my_zero_pfn(unsigned long addr) #ifdef CONFIG_MMU +static inline pte_t pte_mkvrange(pte_t pte) +{ + pte = pte_set_flags(pte, _PAGE_VRANGE); + return pte_clear_flags(pte, _PAGE_PRESENT); +} + +static inline int pte_vrange(pte_t pte) +{ + return ((pte_flags(pte) | _PAGE_PRESENT) == _PAGE_VRANGE); +} + #ifndef CONFIG_TRANSPARENT_HUGEPAGE static inline int pmd_trans_huge(pmd_t pmd) { diff --git a/include/linux/vrange.h b/include/linux/vrange.h index 02c9017..25bcd92 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -41,6 +41,8 @@ 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); + #else static inline void vrange_init(void) {}; diff --git a/mm/memory.c b/mm/memory.c index ba94dec..010fc42 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -841,7 +842,7 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, /* pte contains position in swap or file, so copy. */ if (unlikely(!pte_present(pte))) { - if (!pte_file(pte)) { + if (!pte_file(pte) && !pte_vrange(pte)) { swp_entry_t entry = pte_to_swp_entry(pte); if (swap_duplicate(entry) < 0) @@ -1181,7 +1182,7 @@ again: if (pte_file(ptent)) { if (unlikely(!(vma->vm_flags & VM_NONLINEAR))) print_bad_pte(vma, addr, ptent, NULL); - } else { + } else if (!pte_vrange(ptent)) { swp_entry_t entry = pte_to_swp_entry(ptent); if (!non_swap_entry(entry)) @@ -3711,9 +3712,27 @@ int handle_pte_fault(struct mm_struct *mm, return do_linear_fault(mm, vma, address, pte, pmd, flags, entry); } +anon: return do_anonymous_page(mm, vma, address, pte, pmd, flags); } + + if (unlikely(pte_vrange(entry))) { + if (!is_purged_vrange(mm, address)) { + /* 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 anon; + } + + return VM_FAULT_SIGBUS; + } + 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 d3843a2..1fce20e 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -503,7 +503,9 @@ int try_to_discard_one(struct page *page, struct vm_area_struct *vma, present = pte_present(*pte); flush_cache_page(vma, address, page_to_pfn(page)); - pteval = ptep_clear_flush(vma, address, pte); + + ptep_clear_flush(vma, address, pte); + pteval = pte_mkvrange(*pte); update_hiwater_rss(mm); dec_mm_counter(mm, MM_ANONPAGES); @@ -517,6 +519,7 @@ int try_to_discard_one(struct page *page, struct vm_area_struct *vma, BUG_ON(1); } + set_pte_at(mm, address, pte, pteval); pte_unmap_unlock(pte, ptl); mmu_notifier_invalidate_page(mm, address); ret = 1; @@ -613,3 +616,22 @@ int discard_vpage(struct page *page) return 0; } + +bool is_purged_vrange(struct mm_struct *mm, unsigned long address) +{ + struct vrange_root *vroot = &mm->vroot; + struct interval_tree_node *node; + struct vrange *range; + bool ret = false; + + vrange_lock(vroot); + node = interval_tree_iter_first(&vroot->v_rb, address, + address + PAGE_SIZE - 1); + if (node) { + range = container_of(node, struct vrange, node); + if (range->purged) + ret = true; + } + vrange_unlock(vroot); + return ret; +}