From patchwork Mon Jun 10 04:38:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10984083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FE7676 for ; Mon, 10 Jun 2019 04:41:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31E2F28758 for ; Mon, 10 Jun 2019 04:41:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22762287A6; Mon, 10 Jun 2019 04:41:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB6A228758 for ; Mon, 10 Jun 2019 04:41:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC8FB6B0006; Mon, 10 Jun 2019 00:41:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A7AEC6B0007; Mon, 10 Jun 2019 00:41:04 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 941336B0008; Mon, 10 Jun 2019 00:41:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 53C626B0006 for ; Mon, 10 Jun 2019 00:41:04 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id z1so6385017pfb.7 for ; Sun, 09 Jun 2019 21:41:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=WprUKeEfMWXhdh9Vnjm94ZzvQwSvelV63YsiIiNMw9M=; b=i3eeCj7CXIsuhtN1+1qQpPI3nuyZwrX+eQI+LNSdSbUJLRTMQRjBH22u401fgO1vQ8 1abAYb2fFmk5CNdLMv6WVUF/TwFQvQ8jNlHnXg4+tlun/zJeAYJ8sFIYeCT9sDLyOQZ9 ley6D/2dvGi4N3lgU8jLdM0UhXzlJkCjvZxOVWqQ2fWC8LCsPPuQLzYQ1z8ODF0eg7Q/ Q5lkojrW6hk43EmOcdd+aZGNsd9H9N7EFiz2H5yyH270EnbiTvqyJ/BTtrat+YACPUbI fSAJktRmjoQasdMIBUVJz/Otzet9F2QhVOOZ5SSbNWOWPPsBfLI4di5pAGoWmEUJRM8d lxDg== X-Gm-Message-State: APjAAAW0pe+Sb/zIhZcQHXUC4Sg3q7XDJLq7zrWnW3E+qGIbU0Pkywmt KfJPTTAOSlhrM5ZUmDgjeJzld+KhM9+UxYZVqioQWcExd2TriZpafN+oMVYUeyEaBEM5vy1xzXq TvtMS2tzKcSesLfpp71xjm9PQxm8aVgRZ0tg/LuQC3znzQ6Wl6UlV26ICjKteIT6iHA== X-Received: by 2002:a17:902:a81:: with SMTP id 1mr67977063plp.287.1560141663796; Sun, 09 Jun 2019 21:41:03 -0700 (PDT) X-Received: by 2002:a17:902:a81:: with SMTP id 1mr67977002plp.287.1560141662287; Sun, 09 Jun 2019 21:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560141662; cv=none; d=google.com; s=arc-20160816; b=H36OcqeqlJ2AaBxnSTuy3E3KJCh1heuskjUkDsdNK9A0PncDoFHgzecmIgh+d443pL o4R1MBwadhtn+gqVeBrHhoQIqPZVehng9VesQK+mvEYymhHWNgWI3iDFn5p/+7LFvERe YmJaiQa8ZXzuNltwzPTmsla8xgH+MhYAca1kmrp4d3msxCjQDemkpfY0mksIRwgEEtI7 2YYIUznlY1aGbVrHR3mQkTz3NarjmC1iLE76cX/Sfns4KCtOXbauVp3a3F6+Y96fzeJt 1eh/rmxVtfiTE2yu7u44EtQE7DcJN/avUhaCxUoWaY08xJmbs6XuFYEnh7vcrQKx2cf8 MWPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=WprUKeEfMWXhdh9Vnjm94ZzvQwSvelV63YsiIiNMw9M=; b=fa19RW/qgrP4dJMg0gcRr62QjQ5qiRLy3zsPkQU6rqk4hexy0cuOt4TNMudip3/0IN 3rxag2sxA5toOqiR6GmZcuZQuZsoPWTonVJQmK05ZmXlyljTU4sbdnLuJKqqBy4GuTRW 2d6i/mixwDLlcjLxJLQ+tmJ6C7SySLZ5pf2p7Dt7bQSL5WQ8dgEBhaMnCvotO/lPqhvq tvM7gL6Nlayo6cL+RAXfFIpcICJHShfpRQ1cLxnHR9v48msI/xSrrHgOQ+wj33LC2UWH 6/ZYeNoujzFy2L8glCCR7plbHq3LVfdoaCFzFchioXrKZs5R3gzVrY0tSlrv2WuaFFVT 3eWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mSwnpaGl; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g9sor8872924pfi.35.2019.06.09.21.41.02 for (Google Transport Security); Sun, 09 Jun 2019 21:41:02 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mSwnpaGl; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WprUKeEfMWXhdh9Vnjm94ZzvQwSvelV63YsiIiNMw9M=; b=mSwnpaGlhM+pfDIfL6iZW5NFtqF9Aho3gdmDbAZJrBfc1x9FC/2tnaQTSCQi1VMLzx V919GC4MQkTlMifVkbR59kCLapV/GlRMlnyFQPeHui4Z8gdqWp8nzijcSifuDqevHR3z LZ8pzUf9Ve4gA8WmY8/p1TR7X61DRrBcz0JyY3xhO980DcQDX14BvvlrQGm7hrDV8IW8 czjcMg1C8Oo89JyDx/h12QFWAMPvdxbha5ufy/z0n4Hp95z6z5MAEaKGtuKt4Mhol9YK dOiuyHqbdcQRQ+6ooUlKw1HwZmyQOum+1nBN9+2E1ETu5LC9mjip5KpRvQN5YUM2zrmd mzfQ== X-Google-Smtp-Source: APXvYqxdWalE9oVbqiB4oHvpPSgdxqYkGs5siUIznVBKme8yjGRXTmtT5sfjxzJ2ZNCKnE0Ks4r4RQ== X-Received: by 2002:a62:ed09:: with SMTP id u9mr72196459pfh.23.1560141661550; Sun, 09 Jun 2019 21:41:01 -0700 (PDT) Received: from bobo.local0.net (60-241-56-246.tpgi.com.au. [60.241.56.246]) by smtp.gmail.com with ESMTPSA id l1sm9166802pgj.67.2019.06.09.21.40.58 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 09 Jun 2019 21:41:01 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/4] mm: Move ioremap page table mapping function to mm/ Date: Mon, 10 Jun 2019 14:38:35 +1000 Message-Id: <20190610043838.27916-1-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP ioremap_page_range is a generic function to create a kernel virtual mapping, move it to mm/vmalloc.c and rename it vmap_range. For clarity with this move, also: - Rename vunmap_page_range (vmap_range's inverse) to vunmap_range. - Rename vmap_page_range (which takes a page array) to vmap_pages. Signed-off-by: Nicholas Piggin --- Fixed up the arm64 compile errors, fixed a few bugs, and tidied things up a bit more. Have tested powerpc and x86 but not arm64, would appreciate a review and test of the arm64 patch if possible. include/linux/vmalloc.h | 3 + lib/ioremap.c | 173 +++--------------------------- mm/vmalloc.c | 228 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 229 insertions(+), 175 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 51e131245379..812bea5866d6 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -147,6 +147,9 @@ extern struct vm_struct *find_vm_area(const void *addr); extern int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page **pages); #ifdef CONFIG_MMU +extern int vmap_range(unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift); extern int map_kernel_range_noflush(unsigned long start, unsigned long size, pgprot_t prot, struct page **pages); extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size); diff --git a/lib/ioremap.c b/lib/ioremap.c index 063213685563..e13946da8ec3 100644 --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -58,165 +58,24 @@ static inline int ioremap_pud_enabled(void) { return 0; } static inline int ioremap_pmd_enabled(void) { return 0; } #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ -static int ioremap_pte_range(pmd_t *pmd, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, pgprot_t prot) -{ - pte_t *pte; - u64 pfn; - - pfn = phys_addr >> PAGE_SHIFT; - pte = pte_alloc_kernel(pmd, addr); - if (!pte) - return -ENOMEM; - do { - BUG_ON(!pte_none(*pte)); - set_pte_at(&init_mm, addr, pte, pfn_pte(pfn, prot)); - pfn++; - } while (pte++, addr += PAGE_SIZE, addr != end); - return 0; -} - -static int ioremap_try_huge_pmd(pmd_t *pmd, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, - pgprot_t prot) -{ - if (!ioremap_pmd_enabled()) - return 0; - - if ((end - addr) != PMD_SIZE) - return 0; - - if (!IS_ALIGNED(phys_addr, PMD_SIZE)) - return 0; - - if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)) - return 0; - - return pmd_set_huge(pmd, phys_addr, prot); -} - -static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, pgprot_t prot) -{ - pmd_t *pmd; - unsigned long next; - - pmd = pmd_alloc(&init_mm, pud, addr); - if (!pmd) - return -ENOMEM; - do { - next = pmd_addr_end(addr, end); - - if (ioremap_try_huge_pmd(pmd, addr, next, phys_addr, prot)) - continue; - - if (ioremap_pte_range(pmd, addr, next, phys_addr, prot)) - return -ENOMEM; - } while (pmd++, phys_addr += (next - addr), addr = next, addr != end); - return 0; -} - -static int ioremap_try_huge_pud(pud_t *pud, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, - pgprot_t prot) -{ - if (!ioremap_pud_enabled()) - return 0; - - if ((end - addr) != PUD_SIZE) - return 0; - - if (!IS_ALIGNED(phys_addr, PUD_SIZE)) - return 0; - - if (pud_present(*pud) && !pud_free_pmd_page(pud, addr)) - return 0; - - return pud_set_huge(pud, phys_addr, prot); -} - -static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, pgprot_t prot) -{ - pud_t *pud; - unsigned long next; - - pud = pud_alloc(&init_mm, p4d, addr); - if (!pud) - return -ENOMEM; - do { - next = pud_addr_end(addr, end); - - if (ioremap_try_huge_pud(pud, addr, next, phys_addr, prot)) - continue; - - if (ioremap_pmd_range(pud, addr, next, phys_addr, prot)) - return -ENOMEM; - } while (pud++, phys_addr += (next - addr), addr = next, addr != end); - return 0; -} - -static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, - pgprot_t prot) -{ - if (!ioremap_p4d_enabled()) - return 0; - - if ((end - addr) != P4D_SIZE) - return 0; - - if (!IS_ALIGNED(phys_addr, P4D_SIZE)) - return 0; - - if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)) - return 0; - - return p4d_set_huge(p4d, phys_addr, prot); -} - -static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr, - unsigned long end, phys_addr_t phys_addr, pgprot_t prot) -{ - p4d_t *p4d; - unsigned long next; - - p4d = p4d_alloc(&init_mm, pgd, addr); - if (!p4d) - return -ENOMEM; - do { - next = p4d_addr_end(addr, end); - - if (ioremap_try_huge_p4d(p4d, addr, next, phys_addr, prot)) - continue; - - if (ioremap_pud_range(p4d, addr, next, phys_addr, prot)) - return -ENOMEM; - } while (p4d++, phys_addr += (next - addr), addr = next, addr != end); - return 0; -} - int ioremap_page_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { - pgd_t *pgd; - unsigned long start; - unsigned long next; - int err; - - might_sleep(); - BUG_ON(addr >= end); - - start = addr; - pgd = pgd_offset_k(addr); - do { - next = pgd_addr_end(addr, end); - err = ioremap_p4d_range(pgd, addr, next, phys_addr, prot); - if (err) - break; - } while (pgd++, phys_addr += (next - addr), addr = next, addr != end); - - flush_cache_vmap(start, end); + unsigned int max_page_shift = PAGE_SHIFT; + + /* + * Due to the max_page_shift parameter to vmap_range, platforms must + * enable all smaller sizes to take advantage of a given size, + * otherwise fall back to small pages. + */ + if (ioremap_pmd_enabled()) { + max_page_shift = PMD_SHIFT; + if (ioremap_pud_enabled()) { + max_page_shift = PUD_SHIFT; + if (ioremap_p4d_enabled()) + max_page_shift = P4D_SHIFT; + } + } - return err; + return vmap_range(addr, end, phys_addr, prot, max_page_shift); } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 233af6936c93..dd27cfb29b10 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -119,7 +119,7 @@ static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end) } while (p4d++, addr = next, addr != end); } -static void vunmap_page_range(unsigned long addr, unsigned long end) +static void vunmap_range(unsigned long addr, unsigned long end) { pgd_t *pgd; unsigned long next; @@ -135,6 +135,198 @@ static void vunmap_page_range(unsigned long addr, unsigned long end) } static int vmap_pte_range(pmd_t *pmd, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot) +{ + pte_t *pte; + u64 pfn; + + pfn = phys_addr >> PAGE_SHIFT; + pte = pte_alloc_kernel(pmd, addr); + if (!pte) + return -ENOMEM; + do { + BUG_ON(!pte_none(*pte)); + set_pte_at(&init_mm, addr, pte, pfn_pte(pfn, prot)); + pfn++; + } while (pte++, addr += PAGE_SIZE, addr != end); + return 0; +} + +static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP)) + return 0; + + if (max_page_shift < PMD_SHIFT) + return 0; + + if ((end - addr) != PMD_SIZE) + return 0; + + if (!IS_ALIGNED(phys_addr, PMD_SIZE)) + return 0; + + if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr)) + return 0; + + return pmd_set_huge(pmd, phys_addr, prot); +} + +static inline int vmap_pmd_range(pud_t *pud, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + pmd_t *pmd; + unsigned long next; + + pmd = pmd_alloc(&init_mm, pud, addr); + if (!pmd) + return -ENOMEM; + do { + next = pmd_addr_end(addr, end); + + if (vmap_try_huge_pmd(pmd, addr, next, phys_addr, prot, + max_page_shift)) + continue; + + if (vmap_pte_range(pmd, addr, next, phys_addr, prot)) + return -ENOMEM; + } while (pmd++, phys_addr += (next - addr), addr = next, addr != end); + return 0; +} + +static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP)) + return 0; + + if (max_page_shift < PUD_SHIFT) + return 0; + + if ((end - addr) != PUD_SIZE) + return 0; + + if (!IS_ALIGNED(phys_addr, PUD_SIZE)) + return 0; + + if (pud_present(*pud) && !pud_free_pmd_page(pud, addr)) + return 0; + + return pud_set_huge(pud, phys_addr, prot); +} + +static inline int vmap_pud_range(p4d_t *p4d, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + pud_t *pud; + unsigned long next; + + pud = pud_alloc(&init_mm, p4d, addr); + if (!pud) + return -ENOMEM; + do { + next = pud_addr_end(addr, end); + + if (vmap_try_huge_pud(pud, addr, next, phys_addr, prot, + max_page_shift)) + continue; + + if (vmap_pmd_range(pud, addr, next, phys_addr, prot, + max_page_shift)) + return -ENOMEM; + } while (pud++, phys_addr += (next - addr), addr = next, addr != end); + return 0; +} + +static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP)) + return 0; + + if (max_page_shift < P4D_SHIFT) + return 0; + + if ((end - addr) != P4D_SIZE) + return 0; + + if (!IS_ALIGNED(phys_addr, P4D_SIZE)) + return 0; + + if (p4d_present(*p4d) && !p4d_free_pud_page(p4d, addr)) + return 0; + + return p4d_set_huge(p4d, phys_addr, prot); +} + +static inline int vmap_p4d_range(pgd_t *pgd, unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + p4d_t *p4d; + unsigned long next; + + p4d = p4d_alloc(&init_mm, pgd, addr); + if (!p4d) + return -ENOMEM; + do { + next = p4d_addr_end(addr, end); + + if (vmap_try_huge_p4d(p4d, addr, next, phys_addr, prot, + max_page_shift)) + continue; + + if (vmap_pud_range(p4d, addr, next, phys_addr, prot, + max_page_shift)) + return -ENOMEM; + } while (p4d++, phys_addr += (next - addr), addr = next, addr != end); + return 0; +} + +static int vmap_range_noflush(unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + pgd_t *pgd; + unsigned long start; + unsigned long next; + int err; + + might_sleep(); + BUG_ON(addr >= end); + + start = addr; + pgd = pgd_offset_k(addr); + do { + next = pgd_addr_end(addr, end); + err = vmap_p4d_range(pgd, addr, next, phys_addr, prot, + max_page_shift); + if (err) + break; + } while (pgd++, phys_addr += (next - addr), addr = next, addr != end); + + return err; +} + +int vmap_range(unsigned long addr, + unsigned long end, phys_addr_t phys_addr, pgprot_t prot, + unsigned int max_page_shift) +{ + int ret; + + ret = vmap_range_noflush(addr, end, phys_addr, prot, max_page_shift); + flush_cache_vmap(addr, end); + + return ret; +} + +static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pgprot_t prot, struct page **pages, int *nr) { pte_t *pte; @@ -160,7 +352,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, return 0; } -static int vmap_pmd_range(pud_t *pud, unsigned long addr, +static int vmap_pages_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, pgprot_t prot, struct page **pages, int *nr) { pmd_t *pmd; @@ -171,13 +363,13 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr, return -ENOMEM; do { next = pmd_addr_end(addr, end); - if (vmap_pte_range(pmd, addr, next, prot, pages, nr)) + if (vmap_pages_pte_range(pmd, addr, next, prot, pages, nr)) return -ENOMEM; } while (pmd++, addr = next, addr != end); return 0; } -static int vmap_pud_range(p4d_t *p4d, unsigned long addr, +static int vmap_pages_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, pgprot_t prot, struct page **pages, int *nr) { pud_t *pud; @@ -188,13 +380,13 @@ static int vmap_pud_range(p4d_t *p4d, unsigned long addr, return -ENOMEM; do { next = pud_addr_end(addr, end); - if (vmap_pmd_range(pud, addr, next, prot, pages, nr)) + if (vmap_pages_pmd_range(pud, addr, next, prot, pages, nr)) return -ENOMEM; } while (pud++, addr = next, addr != end); return 0; } -static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, +static int vmap_pages_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end, pgprot_t prot, struct page **pages, int *nr) { p4d_t *p4d; @@ -205,7 +397,7 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, return -ENOMEM; do { next = p4d_addr_end(addr, end); - if (vmap_pud_range(p4d, addr, next, prot, pages, nr)) + if (vmap_pages_pud_range(p4d, addr, next, prot, pages, nr)) return -ENOMEM; } while (p4d++, addr = next, addr != end); return 0; @@ -217,7 +409,7 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, * * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N] */ -static int vmap_page_range_noflush(unsigned long start, unsigned long end, +static int vmap_pages_range_noflush(unsigned long start, unsigned long end, pgprot_t prot, struct page **pages) { pgd_t *pgd; @@ -230,7 +422,7 @@ static int vmap_page_range_noflush(unsigned long start, unsigned long end, pgd = pgd_offset_k(addr); do { next = pgd_addr_end(addr, end); - err = vmap_p4d_range(pgd, addr, next, prot, pages, &nr); + err = vmap_pages_p4d_range(pgd, addr, next, prot, pages, &nr); if (err) return err; } while (pgd++, addr = next, addr != end); @@ -238,12 +430,12 @@ static int vmap_page_range_noflush(unsigned long start, unsigned long end, return nr; } -static int vmap_page_range(unsigned long start, unsigned long end, +static int vmap_pages_range(unsigned long start, unsigned long end, pgprot_t prot, struct page **pages) { int ret; - ret = vmap_page_range_noflush(start, end, prot, pages); + ret = vmap_pages_range_noflush(start, end, prot, pages); flush_cache_vmap(start, end); return ret; } @@ -1148,7 +1340,7 @@ static void free_vmap_area(struct vmap_area *va) */ static void unmap_vmap_area(struct vmap_area *va) { - vunmap_page_range(va->va_start, va->va_end); + vunmap_range(va->va_start, va->va_end); } /* @@ -1586,7 +1778,7 @@ static void vb_free(const void *addr, unsigned long size) rcu_read_unlock(); BUG_ON(!vb); - vunmap_page_range((unsigned long)addr, (unsigned long)addr + size); + vunmap_range((unsigned long)addr, (unsigned long)addr + size); if (debug_pagealloc_enabled()) flush_tlb_kernel_range((unsigned long)addr, @@ -1736,7 +1928,7 @@ void *vm_map_ram(struct page **pages, unsigned int count, int node, pgprot_t pro addr = va->va_start; mem = (void *)addr; } - if (vmap_page_range(addr, addr + size, prot, pages) < 0) { + if (vmap_pages_range(addr, addr + size, prot, pages) < 0) { vm_unmap_ram(mem, count); return NULL; } @@ -1903,7 +2095,7 @@ void __init vmalloc_init(void) int map_kernel_range_noflush(unsigned long addr, unsigned long size, pgprot_t prot, struct page **pages) { - return vmap_page_range_noflush(addr, addr + size, prot, pages); + return vmap_pages_range_noflush(addr, addr + size, prot, pages); } /** @@ -1922,7 +2114,7 @@ int map_kernel_range_noflush(unsigned long addr, unsigned long size, */ void unmap_kernel_range_noflush(unsigned long addr, unsigned long size) { - vunmap_page_range(addr, addr + size); + vunmap_range(addr, addr + size); } EXPORT_SYMBOL_GPL(unmap_kernel_range_noflush); @@ -1939,7 +2131,7 @@ void unmap_kernel_range(unsigned long addr, unsigned long size) unsigned long end = addr + size; flush_cache_vunmap(addr, end); - vunmap_page_range(addr, end); + vunmap_range(addr, end); flush_tlb_kernel_range(addr, end); } EXPORT_SYMBOL_GPL(unmap_kernel_range); @@ -1950,7 +2142,7 @@ int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page **pages) unsigned long end = addr + get_vm_area_size(area); int err; - err = vmap_page_range(addr, end, prot, pages); + err = vmap_pages_range(addr, end, prot, pages); return err > 0 ? 0 : err; } From patchwork Mon Jun 10 04:38:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10984085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0117876 for ; Mon, 10 Jun 2019 04:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E509628758 for ; Mon, 10 Jun 2019 04:41:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8EC2287A6; Mon, 10 Jun 2019 04:41:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F27C28758 for ; Mon, 10 Jun 2019 04:41:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7246A6B0007; Mon, 10 Jun 2019 00:41:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 65C1A6B000A; Mon, 10 Jun 2019 00:41:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D6CA6B000C; Mon, 10 Jun 2019 00:41:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 083D06B0007 for ; Mon, 10 Jun 2019 00:41:06 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id l184so6100651pgd.18 for ; Sun, 09 Jun 2019 21:41:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=hJ710Nece9JdDCt+W2M5u9CutQXF450XDxzyXKmRa0k=; b=lpaGLZ1NtnZHq+DRjGNUaaPjOTl6PRd3fVdNuIgCAMfloc2eRCioeDunVmb8t/L/Hb OlYyzPRzPbjkSlrHS8KJaAUQRBc/OBwJNmR++oXQ0uaEqOd0ibfVAUhcZKVB5828c2mi FKTL9nV8xf0LGUqVcTgagv8F4xE83TE8q3M6i8P0JQmRtu4EucGe8y+OfWTIMPJKCj/U oeu5U+1yRJffx0s1IrFaPO9Egfi+9XeJ9qhxZZhB1Qy60BZUM71ltM2rVoQcyT+Igzdx cEbyaqudSN+tkMBCR8Hp8Jz3dg6oKJ+y6USu6v1GK0ZeI87HkiP4hPTn/vEC7ckMEkHH N86w== X-Gm-Message-State: APjAAAUGs8BStW2J+8nkDZ33GWuHw/1cBOka7l24cJUj511ie2tw9CU8 Jm9hGDcfz4IehPePM74kOCGdRrUh3mYWfB8SP2Zkjo3TY5ri/ep23/INl1GgcKG5U+4DDEKZBaG TnoaMIKKzbLl0fZGB1rVN7pNR4vKg9k5VeLmmu2T/jjdSkpvE4M2lDhOENPDPIUEuig== X-Received: by 2002:a17:90a:a397:: with SMTP id x23mr19782762pjp.118.1560141665607; Sun, 09 Jun 2019 21:41:05 -0700 (PDT) X-Received: by 2002:a17:90a:a397:: with SMTP id x23mr19782727pjp.118.1560141664960; Sun, 09 Jun 2019 21:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560141664; cv=none; d=google.com; s=arc-20160816; b=n6DcQ9QDvtm+QXZFHWzq21NPHhAJZQhLwf7dZnj9BTyj98Kw6qAnRdesoWK4Q5wFYi wpbybquJjU/ToDtKQazEsbjDs1otNi3ZRaUwOvEHb1OiJ+Ln98HKOMNj252ycLtQHLfU sv2BCIay/oBoh1A4OwuQ8tfC9uIvvcuHBGJjynHCfoI56nX4ewlWFK0p4XI+eXE+cfBh sISk3ILhGihuKY5qyN2bSKWW5Lejag+IVWA4iBat4v0sOertiJl78nw/wefldEkuH3m9 m4Em1WOO01Z8+xDbo9hgN8XiTFUR8+8oiQH1f1Zvn3yyuLRvUtIvQdT24mA1KRN/WS9u iWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=hJ710Nece9JdDCt+W2M5u9CutQXF450XDxzyXKmRa0k=; b=xAluApz6epsWDr/JMnt7rt5eURZMw4Nk5gxJJzxSvbuPhaKYrOM8jo2pC/gBP68IMQ H+HnqOKOzVCUbxUjmcwQpbmqvEw6Dwi59Fmr9Y6EoNxrRUC4FmvuL97OqnwUI2IgUR0g jXt9C0AE7hJgUUqDcGpeHnbiqT1o+WXqvKc5tH1f/Q8zotlSvZl7rFAkxRQhtO9gsoca lSWAqyEeEt+ujC2iLn5cMeiq2YGeeoUkvfIG9sWQF//U0r5jN2lF8igCF6VEnEkk9ktZ L+mHuVlacQ2t7EcbS6HycijYyf5oISqGg3ae7hqzwD1k0dnw1ZrNdRNPFNB0hcePYzG1 myYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fz34Jtvm; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n9sor8061444pgl.15.2019.06.09.21.41.04 for (Google Transport Security); Sun, 09 Jun 2019 21:41:04 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fz34Jtvm; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hJ710Nece9JdDCt+W2M5u9CutQXF450XDxzyXKmRa0k=; b=fz34JtvmsEEbz+uG7YHcmaePdpnvHSrr9OzG0Fob2Vn/ojNW3ILIH/7028H5WbNhf/ ozwk2iOir1e6dQLEkGP6el5dRxrVSReFLnAqVr050NDHhkui/0LVdt5/hWGRB0Quv5ry MwcfC53bLQB5nw6tMMWHl5S2ClvoJ/dI4A6eJN0A4OvoGJ2OS3XhKIou0oDGf9rzwRs5 jtggh0AqFgaHwYeCfg9cR6kagIuVfcpp+sfjWTqBHuVGTir0il8bOgANLRz3fwgf5tKL fn6NFsZYGYRUj/uudTy5p/8SjGhYPJ1jpLuoGku/u7LnyvT35k2ZkTlrj6CU6TrUNbP0 qpNA== X-Google-Smtp-Source: APXvYqz9ZBs8sn3RctkWOS+ZWyR8ZuOTeqNvx84zu+AkZf7kx8BtX4P+3MbV3oNpSvArhcN856sjFA== X-Received: by 2002:a65:4544:: with SMTP id x4mr14322154pgr.323.1560141664470; Sun, 09 Jun 2019 21:41:04 -0700 (PDT) Received: from bobo.local0.net (60-241-56-246.tpgi.com.au. [60.241.56.246]) by smtp.gmail.com with ESMTPSA id l1sm9166802pgj.67.2019.06.09.21.41.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 09 Jun 2019 21:41:04 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/4] arm64: support huge vmap vmalloc Date: Mon, 10 Jun 2019 14:38:36 +1000 Message-Id: <20190610043838.27916-2-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190610043838.27916-1-npiggin@gmail.com> References: <20190610043838.27916-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Applying huge vmap to vmalloc requires vmalloc_to_page to walk huge pages. Define pud_large and pmd_large to support this. Signed-off-by: Nicholas Piggin --- arch/arm64/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 2c41b04708fe..30fe7b344bf7 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -428,6 +428,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, PMD_TYPE_TABLE) #define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \ PMD_TYPE_SECT) +#define pmd_large(pmd) pmd_sect(pmd) #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 #define pud_sect(pud) (0) @@ -438,6 +439,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, #define pud_table(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \ PUD_TYPE_TABLE) #endif +#define pud_large(pud) pud_sect(pud) extern pgd_t init_pg_dir[PTRS_PER_PGD]; extern pgd_t init_pg_end[]; From patchwork Mon Jun 10 04:38:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10984087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E7881398 for ; Mon, 10 Jun 2019 04:41:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0007528758 for ; Mon, 10 Jun 2019 04:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E83A1287A6; Mon, 10 Jun 2019 04:41:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7668928758 for ; Mon, 10 Jun 2019 04:41:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C28BD6B000A; Mon, 10 Jun 2019 00:41:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BB1CA6B000C; Mon, 10 Jun 2019 00:41:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A09E56B000D; Mon, 10 Jun 2019 00:41:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 5B9CC6B000A for ; Mon, 10 Jun 2019 00:41:09 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id 14so6104994pgo.14 for ; Sun, 09 Jun 2019 21:41:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=j0iK9oPhBRVSERhwHAEayZPRDfAp+ATJEAPI7I5uyj4=; b=Jx8h/wbYJjC9DlgH+8hT3ossUlsKfZkHAsc4QYAIl+uDa//ozks2Pc5joqGAPNs8qI wEH25s7JlL92cHWyq2YNalloAdfxHJ0WgiORDPoT0I3DnVLd6jDO7TTSXf7mgGVlenXF HQ3FoxSv8qNa4gGBrrMsC0pQGAG/3zcmWgBYPe8HVOASzgTnDxsPADb0I2axut0ZKZlI HZevEYw9KZ3gJwdZfaDRK+Zc6HKx0FI2pFd5/3qKAbYDDrRAEdWdaqAXy3tgeYC+uQTm GNBmC2khwMud6CG4HGVuOm7j9afThNpQu5WZwwlTlwHo37uhFFgjrok9QCRnc650e42o tnEg== X-Gm-Message-State: APjAAAVIu9M7wHpPwDeOEOm6nK+g2lN7usrtMGOKorPwUKYTcBLiHwCC yBnr5EkXxLJLpv0qZVjmQLQVK+mSDOibg/zmYfURlYF5UHDten92q60ic2twsIBmp3VxNW/pItn ztIT7HAhruNAStnaOlTf6apD6wXOIl8dn2FYwDDIfxj7W+l5tziHuOUlldMzkjgZudA== X-Received: by 2002:aa7:8193:: with SMTP id g19mr66092890pfi.162.1560141669044; Sun, 09 Jun 2019 21:41:09 -0700 (PDT) X-Received: by 2002:aa7:8193:: with SMTP id g19mr66092839pfi.162.1560141667997; Sun, 09 Jun 2019 21:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560141667; cv=none; d=google.com; s=arc-20160816; b=yf/TsxTkIk5NKIBXXz2hjX+2Or/n+1UcGRkwbPeyBz6TRUBci1R0RR2CcHhd6+1cYI SuACo1PSL0J3P7p8GQntw+yUW9MXqrmzSkeMnK5R1Vano1/z6F6m0CpsrWoOgyCZ5xm2 sIbbTaiavBqlOfjlm/flIueYoLAPHu2v3XfIUF2KpVqSwgKwpC72OkjdB9Gb5IGEV/yG BaOk+a220jVekSnZhzshvEIEifKm8lfN6D6A6kVWOYXsyMClVjCux7C96w5zHXeoGcPQ oIq6yYakdrJoB9XoNmHzaGFxSkpNWKz3GYV9hMkS+yl9gLzQe64JlwUqJVQjUowZAC0C OXfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=j0iK9oPhBRVSERhwHAEayZPRDfAp+ATJEAPI7I5uyj4=; b=oJjXEm53q3Unk+8cjOZnJl8sf2nwW6CZZeZNgyBYSioZfug8DW3Mfyqts8XW9CED/J piMN4cyABg3bRzYwzV1ySisZ/hMoHxlffRasymjRbjoZyvq2h7uoiV/oltQr5+PbxFpJ tEpElmQ7lhw3cNf9FZ8DOb980ys0qbtfxDETImgix/3opRuq8vpJelaDPOw3RsFlctj3 ntzU8e06/eB4u3DWuJgMfMCA8LxYCZBM4AUpV35CfrE4y9KqxsQz0e4k/XzsQd+PPkMY VM6ZuiIYZ5IxQ5wEnqvszpRMegY8wRM/lltxcmmLKmyyR7kTgFrkmGmkLLIi83WT0TAJ OW2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QcKUZrLg; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b5sor10523250pjq.8.2019.06.09.21.41.07 for (Google Transport Security); Sun, 09 Jun 2019 21:41:07 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QcKUZrLg; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j0iK9oPhBRVSERhwHAEayZPRDfAp+ATJEAPI7I5uyj4=; b=QcKUZrLgQKctcgR3ilhCBa5vjFh1fCNel4R0mH2jk1Tp1iY8hD5fmbOXmGKoUrtwrX aooSLGAYY4vJTaJiilgcSwtsbtlReimSqPJehqwexfgMa1TSDy87tibLD1OVDBuraUgF 1eug6DwfebsLN8WATm5Uo/buzMbsbe7cmFeeGAou4YR8gUntPh269QbxM4FU0ceR+tkZ yYV/k5ae9a57jsDNkdnoZv/7BNEnWzMf2bpp4UgMJtp4lhaMos2gOosWi+v2Q2ucsNo8 u4SyyZAk+CXBmcTfhN9KeuKxn8I04ooCPtfQSfJVzUy10NVs7IEypZ1DcHHiWqHw2nfp FjMA== X-Google-Smtp-Source: APXvYqw+VLnzFiNoQ//mElPmrK/yDIA214P00B8jjBcBGJdQSiCpHxlwG6iJk4iNAZq+HcvbqmTphQ== X-Received: by 2002:a17:90a:9f8e:: with SMTP id o14mr18793157pjp.82.1560141667565; Sun, 09 Jun 2019 21:41:07 -0700 (PDT) Received: from bobo.local0.net (60-241-56-246.tpgi.com.au. [60.241.56.246]) by smtp.gmail.com with ESMTPSA id l1sm9166802pgj.67.2019.06.09.21.41.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 09 Jun 2019 21:41:07 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/4] powerpc/64s/radix: support huge vmap vmalloc Date: Mon, 10 Jun 2019 14:38:37 +1000 Message-Id: <20190610043838.27916-3-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190610043838.27916-1-npiggin@gmail.com> References: <20190610043838.27916-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Applying huge vmap to vmalloc requires vmalloc_to_page to walk huge pages. Define pud_large and pmd_large to support this. Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/book3s/64/pgtable.h | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index 5faceeefd9f9..8e02077b11fb 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -923,6 +923,11 @@ static inline int pud_present(pud_t pud) return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT)); } +static inline int pud_large(pud_t pud) +{ + return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE)); +} + extern struct page *pud_page(pud_t pud); extern struct page *pmd_page(pmd_t pmd); static inline pte_t pud_pte(pud_t pud) @@ -966,6 +971,11 @@ static inline int pgd_present(pgd_t pgd) return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT)); } +static inline int pgd_large(pgd_t pgd) +{ + return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PTE)); +} + static inline pte_t pgd_pte(pgd_t pgd) { return __pte_raw(pgd_raw(pgd)); @@ -1091,6 +1101,11 @@ static inline pte_t *pmdp_ptep(pmd_t *pmd) #define pmd_mk_savedwrite(pmd) pte_pmd(pte_mk_savedwrite(pmd_pte(pmd))) #define pmd_clear_savedwrite(pmd) pte_pmd(pte_clear_savedwrite(pmd_pte(pmd))) +static inline int pmd_large(pmd_t pmd) +{ + return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); +} + #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY #define pmd_soft_dirty(pmd) pte_soft_dirty(pmd_pte(pmd)) #define pmd_mksoft_dirty(pmd) pte_pmd(pte_mksoft_dirty(pmd_pte(pmd))) @@ -1159,15 +1174,6 @@ pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, return hash__pmd_hugepage_update(mm, addr, pmdp, clr, set); } -/* - * returns true for pmd migration entries, THP, devmap, hugetlb - * But compile time dependent on THP config - */ -static inline int pmd_large(pmd_t pmd) -{ - return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); -} - static inline pmd_t pmd_mknotpresent(pmd_t pmd) { return __pmd(pmd_val(pmd) & ~_PAGE_PRESENT); From patchwork Mon Jun 10 04:38:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10984091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15BE076 for ; Mon, 10 Jun 2019 04:41:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0569B28758 for ; Mon, 10 Jun 2019 04:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED882287A6; Mon, 10 Jun 2019 04:41:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C2D528758 for ; Mon, 10 Jun 2019 04:41:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 637096B000E; Mon, 10 Jun 2019 00:41:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5E52B6B0010; Mon, 10 Jun 2019 00:41:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4600C6B0266; Mon, 10 Jun 2019 00:41:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 06DBE6B000E for ; Mon, 10 Jun 2019 00:41:13 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id g11so5009783plt.23 for ; Sun, 09 Jun 2019 21:41:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sL83o5GmSL2dCmHfrkqeaNUT3nyNNx/ViCtqeruTtoM=; b=tJfSeLfKhpgg2ND1H4Icy77VkcZt9CPZkGFxUsKB3+9LijJiT5/upAJ//eRzz1CSqZ hI6hLSRBJ5afgs/yRldAuI5jD+TFvfy8UkrTzyok3nNBV3Spxkh36Kn5/RtEnPhPzunT eUi0PRhseZzrhWMWx0D+Wz9OSJWl4b5ktlyEIUZPFJohxGswj7qpysVlA2STCYQmgiWs Aj0lvNQo/yGr5DIPrCWukgzImZ0O5m0Z1GNWLu5xIDw+zCEwJes8/Wm0+FkikSvrJfrB 8RisHh5Haw0l17GDq7IqW1VtObqN9Ts207r1VeZfGvqeUEx3x1TrEVNTv0X8aqk1LB14 s5vw== X-Gm-Message-State: APjAAAVHuNDEaLPONWh4t3i0byJWHKCAGQzZRDPaV+zhFq7iJdcGO1kR pSx9JBTWyXekIvL8Rwz1+g+MGS74FeL4/82jezUQLL9fZenbKXj19bam/1EI9mBvWivR6jjvKYO WCxVz+zrFIkQBZI9VcOJfkXWHxmGgTHnLsXAFBpzuUHGZoWj/xbSJXmFfpro9FxzGmA== X-Received: by 2002:aa7:8294:: with SMTP id s20mr63538268pfm.75.1560141672584; Sun, 09 Jun 2019 21:41:12 -0700 (PDT) X-Received: by 2002:aa7:8294:: with SMTP id s20mr63538204pfm.75.1560141671087; Sun, 09 Jun 2019 21:41:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560141671; cv=none; d=google.com; s=arc-20160816; b=tlXD4K3lKp+yfMr5rSgVU0jNMgipgscatvXe+i26+NsqIgyqTyBX8JTFH2XGfFJmnx b7ZbLKPn+ggGOHbjoFoad4a3R+ar05LyFOv7Udjr11hD5y/CsbHOYvzcP8EEaU+B9fmr 2spt7tYlBE9BkEY9g5/i2pDiBuiqcWaseBwphiQ06WMDCW3zTmVQcwmoemjIkAjpVcft fZFVvXqUj/saEgX3+U0EaSlrILKcBnkWpjVTml4YzBg4zljPv7cXtRdhiYd10jhb6Pkc BrCXRJ/ASMei3WgnWjy9jyjAE6t4ev9lUFSiTuMfqfHL/p3Px1uWmeOswYkrVZAPL8Fo DCzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=sL83o5GmSL2dCmHfrkqeaNUT3nyNNx/ViCtqeruTtoM=; b=cHA/1MmxU+l2lxkBB7PI1JmfaJYKEVqfA+kuGLemWHzZjyrf5OjWUb0pyUUilQy5r3 cIzuF57ZexcbO/d0ntTdG9YNnVIviqDoPoHP4K3OUpRJxf2aK0D5D86sMt2jU9lmuXsi AV4lLcc/lfKZifvPpc38Er10rKt/p66sCLaN1sO7EBA2eLiw/7dx5dW6eHCLhtXuo3cs Ok78hF6IdUKqA1U/mPYceRHj+CiX5oBUpOALVJvbTVwKKelvIMs+l5g+PbXvAwLOlKj2 FViWoKJ0rE3PObBgQvKvT/P4it+Ej2/8tuDzgiBEbDC4Rk2M5z2PlRNRZSUGwWmI2COK WoMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RO1OVz8a; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d6sor10558547pjs.23.2019.06.09.21.41.10 for (Google Transport Security); Sun, 09 Jun 2019 21:41:11 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RO1OVz8a; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sL83o5GmSL2dCmHfrkqeaNUT3nyNNx/ViCtqeruTtoM=; b=RO1OVz8aaLV5Rr9K7e6Kj+LnA1vIHWrb9LtDUDXGEyE9Sjtvt4YQF+5ZcrF/4bVwk5 0gHf3z1I/9rFUqJic3T2F4qbrXx9GixwaS3gwpL4u8KkjK7vESCtsydKVWvcVKYLy7bb uHkphxOUuDVniKUm+UYECNHKvuFQKiZOOUnBdVPZ9tzdcErdJmHSqBBV+u+0Ee5SCouk wUsZM5oIOc1lnIIfkEmgYF/aS0lpxEBe1s8j0dEQTKwkoCmwVNrc1a/JtAsby4fGD4OD h20RZZt8XYksTyyjUgW9zIezh8TaSurYm2QmMadQdKeXK2aEi3P8K85i22wEhBaIP4WW GesA== X-Google-Smtp-Source: APXvYqx5xLsoxUHDjuTqVHUN6KWL4KccSuLF+xYRdn3IRei9u/+KqQ8FZiwEbYaMYD/V+xoD54miIA== X-Received: by 2002:a17:90a:b298:: with SMTP id c24mr19149840pjr.18.1560141670415; Sun, 09 Jun 2019 21:41:10 -0700 (PDT) Received: from bobo.local0.net (60-241-56-246.tpgi.com.au. [60.241.56.246]) by smtp.gmail.com with ESMTPSA id l1sm9166802pgj.67.2019.06.09.21.41.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 09 Jun 2019 21:41:09 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/4] mm/vmalloc: Hugepage vmalloc mappings Date: Mon, 10 Jun 2019 14:38:38 +1000 Message-Id: <20190610043838.27916-4-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190610043838.27916-1-npiggin@gmail.com> References: <20190610043838.27916-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP For platforms that define HAVE_ARCH_HUGE_VMAP, have vmap allow vmalloc to allocate huge pages and map them This brings dTLB misses for linux kernel tree `git diff` from 45,000 to 8,000 on a Kaby Lake KVM guest with 8MB dentry hash and mitigations=off (performance is in the noise, under 1% difference, page tables are likely to be well cached for this workload). Similar numbers are seen on POWER9. Signed-off-by: Nicholas Piggin --- include/asm-generic/4level-fixup.h | 1 + include/asm-generic/5level-fixup.h | 1 + include/linux/vmalloc.h | 1 + mm/vmalloc.c | 132 +++++++++++++++++++++++------ 4 files changed, 107 insertions(+), 28 deletions(-) diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h index e3667c9a33a5..3cc65a4dd093 100644 --- a/include/asm-generic/4level-fixup.h +++ b/include/asm-generic/4level-fixup.h @@ -20,6 +20,7 @@ #define pud_none(pud) 0 #define pud_bad(pud) 0 #define pud_present(pud) 1 +#define pud_large(pud) 0 #define pud_ERROR(pud) do { } while (0) #define pud_clear(pud) pgd_clear(pud) #define pud_val(pud) pgd_val(pud) diff --git a/include/asm-generic/5level-fixup.h b/include/asm-generic/5level-fixup.h index bb6cb347018c..c4377db09a4f 100644 --- a/include/asm-generic/5level-fixup.h +++ b/include/asm-generic/5level-fixup.h @@ -22,6 +22,7 @@ #define p4d_none(p4d) 0 #define p4d_bad(p4d) 0 #define p4d_present(p4d) 1 +#define p4d_large(p4d) 0 #define p4d_ERROR(p4d) do { } while (0) #define p4d_clear(p4d) pgd_clear(p4d) #define p4d_val(p4d) pgd_val(p4d) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 812bea5866d6..4c92dc608928 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -42,6 +42,7 @@ struct vm_struct { unsigned long size; unsigned long flags; struct page **pages; + unsigned int page_shift; unsigned int nr_pages; phys_addr_t phys_addr; const void *caller; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index dd27cfb29b10..0cf8e861caeb 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -440,6 +441,41 @@ static int vmap_pages_range(unsigned long start, unsigned long end, return ret; } +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +static int vmap_hpages_range(unsigned long start, unsigned long end, + pgprot_t prot, struct page **pages, + unsigned int page_shift) +{ + unsigned long addr = start; + unsigned int i, nr = (end - start) >> (PAGE_SHIFT + page_shift); + + for (i = 0; i < nr; i++) { + int err; + + err = vmap_range_noflush(addr, + addr + (PAGE_SIZE << page_shift), + __pa(page_address(pages[i])), prot, + PAGE_SHIFT + page_shift); + if (err) + return err; + + addr += PAGE_SIZE << page_shift; + } + flush_cache_vmap(start, end); + + return nr; +} +#else +static int vmap_hpages_range(unsigned long start, unsigned long end, + pgprot_t prot, struct page **pages, + unsigned int page_shift) +{ + BUG_ON(page_shift != PAGE_SIZE); + return vmap_pages_range(start, end, prot, pages); +} +#endif + + int is_vmalloc_or_module_addr(const void *x) { /* @@ -462,7 +498,7 @@ struct page *vmalloc_to_page(const void *vmalloc_addr) { unsigned long addr = (unsigned long) vmalloc_addr; struct page *page = NULL; - pgd_t *pgd = pgd_offset_k(addr); + pgd_t *pgd; p4d_t *p4d; pud_t *pud; pmd_t *pmd; @@ -474,27 +510,38 @@ struct page *vmalloc_to_page(const void *vmalloc_addr) */ VIRTUAL_BUG_ON(!is_vmalloc_or_module_addr(vmalloc_addr)); + pgd = pgd_offset_k(addr); if (pgd_none(*pgd)) return NULL; + p4d = p4d_offset(pgd, addr); if (p4d_none(*p4d)) return NULL; - pud = pud_offset(p4d, addr); +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (p4d_large(*p4d)) + return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT); +#endif + if (WARN_ON_ONCE(p4d_bad(*p4d))) + return NULL; - /* - * Don't dereference bad PUD or PMD (below) entries. This will also - * identify huge mappings, which we may encounter on architectures - * that define CONFIG_HAVE_ARCH_HUGE_VMAP=y. Such regions will be - * identified as vmalloc addresses by is_vmalloc_addr(), but are - * not [unambiguously] associated with a struct page, so there is - * no correct value to return for them. - */ - WARN_ON_ONCE(pud_bad(*pud)); - if (pud_none(*pud) || pud_bad(*pud)) + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) + return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (pud_large(*pud)) + return pud_page(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); +#endif + if (WARN_ON_ONCE(pud_bad(*pud))) return NULL; + pmd = pmd_offset(pud, addr); - WARN_ON_ONCE(pmd_bad(*pmd)); - if (pmd_none(*pmd) || pmd_bad(*pmd)) + if (pmd_none(*pmd)) + return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (pmd_large(*pmd)) + return pmd_page(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); +#endif + if (WARN_ON_ONCE(pmd_bad(*pmd))) return NULL; ptep = pte_offset_map(pmd, addr); @@ -502,6 +549,7 @@ struct page *vmalloc_to_page(const void *vmalloc_addr) if (pte_present(pte)) page = pte_page(pte); pte_unmap(ptep); + return page; } EXPORT_SYMBOL(vmalloc_to_page); @@ -2185,8 +2233,9 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, return NULL; if (flags & VM_IOREMAP) - align = 1ul << clamp_t(int, get_count_order_long(size), - PAGE_SHIFT, IOREMAP_MAX_ORDER); + align = max(align, + 1ul << clamp_t(int, get_count_order_long(size), + PAGE_SHIFT, IOREMAP_MAX_ORDER)); area = kzalloc_node(sizeof(*area), gfp_mask & GFP_RECLAIM_MASK, node); if (unlikely(!area)) @@ -2398,7 +2447,7 @@ static void __vunmap(const void *addr, int deallocate_pages) struct page *page = area->pages[i]; BUG_ON(!page); - __free_pages(page, 0); + __free_pages(page, area->page_shift); } kvfree(area->pages); @@ -2541,14 +2590,17 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot, int node) { struct page **pages; + unsigned long addr = (unsigned long)area->addr; + unsigned long size = get_vm_area_size(area); + unsigned int page_shift = area->page_shift; + unsigned int shift = page_shift + PAGE_SHIFT; unsigned int nr_pages, array_size, i; const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO; const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN; const gfp_t highmem_mask = (gfp_mask & (GFP_DMA | GFP_DMA32)) ? - 0 : - __GFP_HIGHMEM; + 0 : __GFP_HIGHMEM; - nr_pages = get_vm_area_size(area) >> PAGE_SHIFT; + nr_pages = size >> shift; array_size = (nr_pages * sizeof(struct page *)); area->nr_pages = nr_pages; @@ -2569,10 +2621,8 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, for (i = 0; i < area->nr_pages; i++) { struct page *page; - if (node == NUMA_NO_NODE) - page = alloc_page(alloc_mask|highmem_mask); - else - page = alloc_pages_node(node, alloc_mask|highmem_mask, 0); + page = alloc_pages_node(node, + alloc_mask|highmem_mask, page_shift); if (unlikely(!page)) { /* Successfully allocated i pages, free them in __vunmap() */ @@ -2584,8 +2634,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, cond_resched(); } - if (map_vm_area(area, prot, pages)) + if (vmap_hpages_range(addr, addr + size, prot, pages, page_shift) < 0) goto fail; + return area->addr; fail: @@ -2619,22 +2670,39 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, pgprot_t prot, unsigned long vm_flags, int node, const void *caller) { - struct vm_struct *area; + struct vm_struct *area = NULL; void *addr; unsigned long real_size = size; + unsigned long real_align = align; + unsigned int shift = PAGE_SHIFT; size = PAGE_ALIGN(size); if (!size || (size >> PAGE_SHIFT) > totalram_pages()) goto fail; + if (IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP)) { + unsigned long size_per_node; + + size_per_node = size; + if (node == NUMA_NO_NODE) + size_per_node /= num_online_nodes(); + if (size_per_node >= PMD_SIZE) + shift = PMD_SHIFT; + } +again: + align = max(real_align, 1UL << shift); + size = ALIGN(real_size, align); + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | vm_flags, start, end, node, gfp_mask, caller); if (!area) goto fail; + area->page_shift = shift - PAGE_SHIFT; + addr = __vmalloc_area_node(area, gfp_mask, prot, node); if (!addr) - return NULL; + goto fail; /* * In this function, newly allocated vm_struct has VM_UNINITIALIZED @@ -2648,8 +2716,16 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, return addr; fail: - warn_alloc(gfp_mask, NULL, + if (shift == PMD_SHIFT) { + shift = PAGE_SHIFT; + goto again; + } + + if (!area) { + /* Warn for area allocation, page allocations already warn */ + warn_alloc(gfp_mask, NULL, "vmalloc: allocation failure: %lu bytes", real_size); + } return NULL; }