Path: csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod From: "Kirill A. Shutemov" Newsgroups: linux.kernel Subject: [PATCHv4 07/33] mm: introduce __p4d_alloc() Date: Mon, 06 Mar 2017 15:10:04 +0100 Message-ID: References: X-Extloop1: 1 X-Ironport-Av: E=Sophos;i="5.35,253,1484035200"; d="scan'208";a="1105321898" X-Mailer: git-send-email 2.11.0 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 43 Organization: linux.* mail to news gateway X-Original-Cc: Andi Kleen , Dave Hansen , Andy Lutomirski , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" X-Original-Date: Mon, 6 Mar 2017 16:53:31 +0300 X-Original-Message-ID: <20170306135357.3124-8-kirill.shutemov@linux.intel.com> X-Original-References: <20170306135357.3124-1-kirill.shutemov@linux.intel.com> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1593386 For full 5-level paging we need a helper to allocate p4d page table. Signed-off-by: Kirill A. Shutemov --- mm/memory.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 7f1c2163b3ce..235ba51b2fbf 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3906,6 +3906,29 @@ int handle_mm_fault(struct vm_area_struct *vma, unsigned long address, } EXPORT_SYMBOL_GPL(handle_mm_fault); +#ifndef __PAGETABLE_P4D_FOLDED +/* + * Allocate p4d page table. + * We've already handled the fast-path in-line. + */ +int __p4d_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address) +{ + p4d_t *new = p4d_alloc_one(mm, address); + if (!new) + return -ENOMEM; + + smp_wmb(); /* See comment in __pte_alloc */ + + spin_lock(&mm->page_table_lock); + if (pgd_present(*pgd)) /* Another has populated it */ + p4d_free(mm, new); + else + pgd_populate(mm, pgd, new); + spin_unlock(&mm->page_table_lock); + return 0; +} +#endif /* __PAGETABLE_P4D_FOLDED */ + #ifndef __PAGETABLE_PUD_FOLDED /* * Allocate page upper directory. -- 2.11.0