From patchwork Tue Sep 15 18:01:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woods X-Patchwork-Id: 7189061 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C94B4BEEC1 for ; Tue, 15 Sep 2015 18:05:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7484A20839 for ; Tue, 15 Sep 2015 18:05:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CA3D20835 for ; Tue, 15 Sep 2015 18:05:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZbuZT-0001PP-Hq; Tue, 15 Sep 2015 18:03:11 +0000 Received: from mail-db3on0086.outbound.protection.outlook.com ([157.55.234.86] helo=emea01-db3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZbuZP-0001K1-V6 for linux-arm-kernel@lists.infradead.org; Tue, 15 Sep 2015 18:03:09 +0000 Received: from HE1PR02CA0032.eurprd02.prod.outlook.com (10.162.33.42) by AM2PR02MB0772.eurprd02.prod.outlook.com (10.163.146.16) with Microsoft SMTP Server (TLS) id 15.1.268.17; Tue, 15 Sep 2015 18:02:43 +0000 Received: from DB3FFO11FD050.protection.gbl (2a01:111:f400:7e04::148) by HE1PR02CA0032.outlook.office365.com (2a01:111:e400:5149::42) with Microsoft SMTP Server (TLS) id 15.1.268.17 via Frontend Transport; Tue, 15 Sep 2015 18:02:43 +0000 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; kvack.org; dkim=none (message not signed) header.d=none; kvack.org; dmarc=none action=none header.from=ezchip.com; Received-SPF: Fail (protection.outlook.com: domain of ezchip.com does not designate 12.216.194.146 as permitted sender) receiver=protection.outlook.com; client-ip=12.216.194.146; helo=ld-2.internal.tilera.com; Received: from ld-2.internal.tilera.com (12.216.194.146) by DB3FFO11FD050.mail.protection.outlook.com (10.47.217.81) with Microsoft SMTP Server (TLS) id 15.1.262.18 via Frontend Transport; Tue, 15 Sep 2015 18:02:41 +0000 Received: (from dwoods@localhost) by ld-2.internal.tilera.com (8.14.4/8.14.4/Submit) id t8FI2cxe004019; Tue, 15 Sep 2015 14:02:38 -0400 From: David Woods To: Chris Metcalf Subject: [PATCH] arm64: Add support for PTE contiguous bit. Date: Tue, 15 Sep 2015 14:01:57 -0400 Message-ID: <1442340117-3964-1-git-send-email-dwoods@ezchip.com> X-Mailer: git-send-email 2.1.2 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD050; 1:9HrloFEGBNoFlPnTX9gg0KgDOsTNmhcvM7JHjVdgLHBzY1gN/SIlQsPUzvBuQSC2oqs2dzCoM2KU+nVEiao6HxYJUlGJVqEMZ9hty6mauhK7nXQk3NTHEcl884PKF3wJ/ytvMawg8yshXBwp1AJIsTGkcwjI2/h1qPTuYqWyZ/xuehYyrMph5YrqRt0nvNJUjsObCWRDxb1FL+mmCOUHfZ6FRGchG+oj1+z4tH2GKzvY0b1YflKa4IP7GBljN4PTUtn7Y2MrlylFbihzkc7hvr0ag0HYQaLsr50IVWb3C/QzrUqY7ls7Gkg8zJzvgJqPvldVE9efnfUSxt/9jz+lKNfAMTZQG0h0jDdnVN4wjzXyhUCO8EWv8JecFS4z1BrGQPwSYBk5SzJ+EDaYv2B0hQ== X-Forefront-Antispam-Report: CIP:12.216.194.146; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(77156002)(6806004)(42186005)(19580395003)(47776003)(92566002)(68736005)(5007970100001)(64706001)(11100500001)(110136002)(33646002)(19580405001)(5001960100002)(50986999)(4001450100002)(50226001)(189998001)(46102003)(106476002)(86362001)(106356001)(48376002)(97736004)(85426001)(104016003)(62966003)(50466002)(229853001)(105606002)(81156007)(106466001)(5003940100001)(4001540100001)(87936001)(36756003)(5001860100001)(5001830100001)(9376005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR02MB0772; H:ld-2.internal.tilera.com; FPR:; SPF:Fail; PTR:InfoNoRecords; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; AM2PR02MB0772; 2:QDP6w52cqgbZ4Q1vXYq2llBIzWCCV96f8mtbJQgB9td4rQc3X7PEAoIXQhreGDSPkhcEHYWz4PuiH6TNysy1bcXaP0cjCxC9tRgfBlUD0Rt4pJMzpx10/UNaaClPe8+KgCIf3bNCTfnu+p67lsqBQX+qhmoPAOqvri4a4J3Dkk8=; 3:H5tG8guKO1TE4bJRNnIauY5OQDISuxLNXlvd/1Gthh2rIxCri5+f4X9UtyhxUQQGqlo6mAi9qxRqCiZusvlmjtZmG+egqFEawWGhwxyxRZq2PyCRy6/Yo5Z6W2rcuPvdwG5p4dRbiotiZwBPlA3/vgTowvvA44ZFWAKIvxOkX8+kDTW7RkF7sonlGhCZwOrmiYzVpAQPT4m2z09MhhckxVkaydkkwvXCCTwgKmjuHNTuEQC4rUPI1OG3xoCLkLlT; 25:Ag7iwLTLlbSbmnq5FgfVD3QAloOVH1rsX3VjXnFfsT7A1SX/yj/XHNea5oQ8lCJb4JQHeHikXxiv0gq9NGzRhk0J+UKjTkTBZCgusax4HN9qJKGtXyqTOwWq9xykrA9zSSEtv6L8soZYCRvEo6W/O0b6bwkAV8LOdyBmmM/nwSW40xr1C6kG50RDj1HJh6E+XteBejPviubF5ktvAYwodgJ28nffsxqD+IR89irryVp8EbkT1yVVDoc65qlMY0kRxPG6FXREzaj9rFmALZR53w==; 20:9pG0oTjLAKmi+9Qm3YJdL6usF1i5I+7RQc0/siGGUcJYC/P+LxT37xHgWygraeqRQQQDtf/UVsSwVHVSthYtlUukMySPrPjkSBJdrSgXB6GUn4jFKzfWYYTaSimNstYOHRlkE+W9IVEG8ecQDj6V0i2/EMc7AxvlWvkV19vWQIQ= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM2PR02MB0772; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(8121501046)(520075)(5005006)(520078)(3002001); SRVR:AM2PR02MB0772; BCL:0; PCL:0; RULEID:; SRVR:AM2PR02MB0772; X-Microsoft-Exchange-Diagnostics: 1; AM2PR02MB0772; 4:rM/IBuynJjY3PrLw71gZcCe5gutel22fFe79WpxBWfz5W3VmRo1n9zy+o/fylt7rww9cS8Ot2vq7KXtewFx5YRV6Tl70arpm4HuszV78KK0+gE3biZlybE2wVM8dxDs0G7nuBb9omqACMH8qW3+rExYQKX54YkP6D2CpYKyDXeABw5e3ni+VXlCZhwAbjp6OkAfxyXX6rF2eW5DjLGjgOatu4O3cs+q++iVZx2vzjm3ARJDaXrT5KGaUyrpUIBdHkjpSY9DI2x+xYDHQROXYXgHOG9WTZ/4249ie/h/YpYDd+jdgT3HOkH1hQHXGzHj7qu+V9l6U+kFWxOawtOWVlhh2HaLzzry5BmhMwAQgH1s= X-Forefront-PRVS: 070092A9D3 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM2PR02MB0772; 23:1KWYwLDT1/DBo1taakYGAn4XNxV/nbNhJ68EZsm/k?= =?us-ascii?Q?6sh+y1RH9by4mDIJ3bWVo3NpV3bveqzgvFVRORUNOAtx83BxCPmxQLJcqo/y?= =?us-ascii?Q?zuvgTkpqo1cqcMFuO6I/JZ6PfP3l+Id5Cw9/DF6n2N5ZH7ZQwpDNgIINKsqQ?= =?us-ascii?Q?uPh/1elk/TMle65dwMPzV70zkIO4DpvJYAlni8xkDU0c+AUlTY58qcyJSX8z?= =?us-ascii?Q?WrmhaLkj4Msu9ur+emXtmY7aNsnwNl0rjKfUShSlH5Z9EkVDJl6fwebr1ttD?= =?us-ascii?Q?0Y0g6lZqIGeePaTpSaaohgOX/YdOnXylcRtVY3QdJa3I2dzXV9h0s8PSUl9R?= =?us-ascii?Q?e2qv8+h5mlMrXj7taXxEzpABBDauM7kskoS2YHs2G+GmWu9vc10XKq/cq3zB?= =?us-ascii?Q?IgQRhiNf+kt+z6O8N5G9eF7FWAgyj6R0tDz4wGDM9LhBhxbiR4oT669nznDI?= =?us-ascii?Q?B8uEN2V3yKmVe8UV87+npFVfRejpB1weXOdoeTP/bqQk8R4S8IQ6MmGvzMhC?= =?us-ascii?Q?Hrb0AgTXN6GzU2mL2TTR8N4bxd0WZI1oyX6OuNtpQJSXs+sIFxYemzmHEY8e?= =?us-ascii?Q?yRvkV5/xOG4SDiDaBCVqwcnSysDRMhFMzyWMCe3V/wtCSQfhD1n8ZARtCxhW?= =?us-ascii?Q?hqbEeVywyZ5bYbeIr43xJmt1OpfWeeXsEs2d5u73pGhU2P7YalUuxND8rVxi?= =?us-ascii?Q?kNmvhC9szMYUgI7Qkd1ViKPSEbkVwZd8PBcNXC17JvoGpgLgprnpiEwPcs6E?= =?us-ascii?Q?+s0Lo+hdCTM2pT7HTR1JVBDbtDHyfqUL+HubwaM9BizElgthgS6p/u0Op924?= =?us-ascii?Q?nBZdqbbf52JiMejxCralIi7vKF8WW5xQGTTar8MfQsB0RLGXUkm4DfHGewCV?= =?us-ascii?Q?q5qVNSXOxWNKuyI5RHZuLlXdZzpjn0pQfuiu3AG1RYLIPFPOnPoYzi5t875r?= =?us-ascii?Q?cU9azp0sV3bm0vhZ5e3kBrv+tI5ab4Ru9k4SRDifEsJs04ziQSe6/L0sUaVS?= =?us-ascii?Q?qqk7t4j+fa1eQBXWub01lKtr2YePHwSG/h7GuW6oHVaqMjCmYYpmymg1SHeS?= =?us-ascii?Q?O6e5wyJ2DVPKe1ZtEabcB5FpMS7u7YIXBNM6bDKu+hyyIENfVND+qzQznkfG?= =?us-ascii?Q?IBiyNFThhrVqe+un0BepxO6pruL1/BfljIAVJQ8ftm+YgNHoFQvA+6cn2Vjp?= =?us-ascii?Q?b3VZQFE/tt+YPthiwGSiCqk2wxaBMaqZ1CKrYP0Qpyljip1d2Jhp6mxFcAt3?= =?us-ascii?Q?SGwBfsXQFtu5QmrtNA=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM2PR02MB0772; 5:ibGlVElNgxELLii9Xw6YySEZBl33Fb2jSWPzSEdzABkLs9BNruJGCZ2FoAv3EiI30fZZ+UQlyxhQXGkZIbfkZh8EqHE1W81GP2iD96VpS4hSjNSI48xXy2G1NXSDjy6OwelqeEpFY4rlJYSBM1LjAw==; 24:0Pc9ucz+cMhJLbsIeCpDJVgU29Yzdz4MTc0ySiTsZG4/z5v9hQf7fJu6HwvAswzykdRgA1oXcsYzF2adCALOXbkHE+igWy6d0Yaj6hnqrJQ=; 20:XT7d8hkvAZd0JcnRy8xcQuFHx8BPjbAO8ZruXHEiFeyJcvx0ijt7PxVvsQLf68pOWPxm0R1nmIYxCmsm7yfOQw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2015 18:02:41.6534 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3; Ip=[12.216.194.146]; Helo=[ld-2.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR02MB0772 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150915_110308_487033_2830791A X-CRM114-Status: GOOD ( 19.33 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Steve Capper , Marc Zyngier , David Woods , Hugh Dickins , linux-kernel@vger.kernel.org, Will Deacon , linux-mm@kvack.org, Catalin Marinas , Naoya Horiguchi , Andrew Morton , linux-arm-kernel@lists.infradead.org, Mike Kravetz Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The arm64 MMU supports a Contiguous bit which is a hint that the TTE is one of a set of contiguous entries which can be cached in a single TLB entry. Supporting this bit adds new intermediate huge page sizes. The set of huge page sizes available depends on the base page size. Without using contiguous pages the huge page sizes are as follows. 4KB: 2MB 1GB 64KB: 512MB 4TB With 4KB pages, the contiguous bit groups together sets of 16 pages and with 64KB pages it groups sets of 32 pages. This enables two new huge page sizes in each case, so that the full set of available sizes is as follows. 4KB: 64KB 2MB 32MB 1GB 64KB: 2MB 512MB 16GB 4TB If the base page size is set to 64KB then 2MB pages are enabled by default. It is possible in the future to make 2MB the default huge page size for both 4KB and 64KB pages. Signed-off-by: David Woods Reviewed-by: Chris Metcalf --- arch/arm64/Kconfig | 3 - arch/arm64/include/asm/hugetlb.h | 4 + arch/arm64/include/asm/pgtable-hwdef.h | 15 +++ arch/arm64/include/asm/pgtable.h | 30 +++++- arch/arm64/mm/hugetlbpage.c | 165 ++++++++++++++++++++++++++++++++- 5 files changed, 210 insertions(+), 7 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7d95663..8310e38 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -447,9 +447,6 @@ config HW_PERF_EVENTS config SYS_SUPPORTS_HUGETLBFS def_bool y -config ARCH_WANT_GENERAL_HUGETLB - def_bool y - config ARCH_WANT_HUGE_PMD_SHARE def_bool y if !ARM64_64K_PAGES diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index bb4052e..e5af553 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -97,4 +97,8 @@ static inline void arch_clear_hugepage_flags(struct page *page) clear_bit(PG_dcache_clean, &page->flags); } +extern pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma, + struct page *page, int writable); +#define arch_make_huge_pte arch_make_huge_pte + #endif /* __ASM_HUGETLB_H */ diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 24154b0..da73243 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -55,6 +55,19 @@ #define SECTION_MASK (~(SECTION_SIZE-1)) /* + * Contiguous large page definitions. + */ +#ifdef CONFIG_ARM64_64K_PAGES +#define CONTIG_SHIFT 5 +#define CONTIG_PAGES 32 +#else +#define CONTIG_SHIFT 4 +#define CONTIG_PAGES 16 +#endif +#define CONTIG_PTE_SIZE (CONTIG_PAGES * PAGE_SIZE) +#define CONTIG_PTE_MASK (~(CONTIG_PTE_SIZE - 1)) + +/* * Hardware page table definitions. * * Level 1 descriptor (PUD). @@ -83,6 +96,7 @@ #define PMD_SECT_S (_AT(pmdval_t, 3) << 8) #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10) #define PMD_SECT_NG (_AT(pmdval_t, 1) << 11) +#define PMD_SECT_CONTIG (_AT(pmdval_t, 1) << 52) #define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53) #define PMD_SECT_UXN (_AT(pmdval_t, 1) << 54) @@ -105,6 +119,7 @@ #define PTE_AF (_AT(pteval_t, 1) << 10) /* Access Flag */ #define PTE_NG (_AT(pteval_t, 1) << 11) /* nG */ #define PTE_DBM (_AT(pteval_t, 1) << 51) /* Dirty Bit Management */ +#define PTE_CONTIG (_AT(pteval_t, 1) << 52) /* Contiguous */ #define PTE_PXN (_AT(pteval_t, 1) << 53) /* Privileged XN */ #define PTE_UXN (_AT(pteval_t, 1) << 54) /* User XN */ diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 6900b2d9..df5ec64 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -144,6 +144,7 @@ extern struct page *empty_zero_page; #define pte_special(pte) (!!(pte_val(pte) & PTE_SPECIAL)) #define pte_write(pte) (!!(pte_val(pte) & PTE_WRITE)) #define pte_exec(pte) (!(pte_val(pte) & PTE_UXN)) +#define pte_contig(pte) (!!(pte_val(pte) & PTE_CONTIG)) #ifdef CONFIG_ARM64_HW_AFDBM #define pte_hw_dirty(pte) (!(pte_val(pte) & PTE_RDONLY)) @@ -206,6 +207,9 @@ static inline pte_t pte_mkspecial(pte_t pte) return set_pte_bit(pte, __pgprot(PTE_SPECIAL)); } +extern pte_t pte_mkcontig(pte_t pte); +extern pmd_t pmd_mkcontig(pmd_t pmd); + static inline void set_pte(pte_t *ptep, pte_t pte) { *ptep = pte; @@ -275,7 +279,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, /* * Hugetlb definitions. */ -#define HUGE_MAX_HSTATE 2 +#define HUGE_MAX_HSTATE ((2 * CONFIG_PGTABLE_LEVELS) - 1) #define HPAGE_SHIFT PMD_SHIFT #define HPAGE_SIZE (_AC(1, UL) << HPAGE_SHIFT) #define HPAGE_MASK (~(HPAGE_SIZE - 1)) @@ -372,7 +376,8 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, #define pmd_none(pmd) (!pmd_val(pmd)) #define pmd_present(pmd) (pmd_val(pmd)) -#define pmd_bad(pmd) (!(pmd_val(pmd) & 2)) +#define pmd_bad(pmd) (!(pmd_val(pmd) & \ + (PMD_TABLE_BIT | PMD_SECT_CONTIG))) #define pmd_table(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \ PMD_TYPE_TABLE) @@ -500,7 +505,8 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long addr) static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) { const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY | - PTE_PROT_NONE | PTE_WRITE | PTE_TYPE_MASK; + PTE_PROT_NONE | PTE_WRITE | PTE_TYPE_MASK | + PTE_CONTIG; /* preserve the hardware dirty information */ if (pte_hw_dirty(pte)) newprot |= PTE_DIRTY; @@ -513,6 +519,24 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) return pte_pmd(pte_modify(pmd_pte(pmd), newprot)); } +static inline pte_t pte_modify_pfn(pte_t pte, unsigned long newpfn) +{ + const pteval_t mask = PHYS_MASK & PAGE_MASK; + + pte_val(pte) = pfn_pte(newpfn, (pte_val(pte) & ~mask)); + return pte; +} + +#if CONFIG_PGTABLE_LEVELS > 2 +static inline pmd_t pmd_modify_pfn(pmd_t pmd, unsigned long newpfn) +{ + const pmdval_t mask = PHYS_MASK & PAGE_MASK; + + pmd = pfn_pmd(newpfn, (pmd_val(pmd) & ~mask)); + return pmd; +} +#endif + #ifdef CONFIG_ARM64_HW_AFDBM /* * Atomic pte/pmd modifications. diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 383b03f..f5bbbbc 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -41,6 +41,155 @@ int pud_huge(pud_t pud) #endif } +pte_t *huge_pte_alloc(struct mm_struct *mm, + unsigned long addr, unsigned long sz) +{ + pgd_t *pgd; + pud_t *pud; + pte_t *pte = NULL; + int i; + + pgd = pgd_offset(mm, addr); + pud = pud_alloc(mm, pgd, addr); + if (pud) { + if (sz == PUD_SIZE) { + pte = (pte_t *)pud; + } else if (sz == PMD_SIZE) { +#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE + if (pud_none(*pud)) + pte = huge_pmd_share(mm, addr, pud); + else +#endif + pte = (pte_t *)pmd_alloc(mm, pud, addr); + } else if (sz == (PAGE_SIZE * CONTIG_PAGES)) { + pmd_t *pmd = pmd_alloc(mm, pud, addr); + + WARN_ON(addr & (sz - 1)); + pte = pte_alloc_map(mm, NULL, pmd, addr); + if (pte_present(*pte)) { + unsigned long pfn; + *pte = pte_mkcontig(*pte); + pfn = pte_pfn(*pte); + for (i = 0; i < CONTIG_PAGES; i++) { + set_pte(&pte[i], + pte_modify_pfn(*pte, pfn + i)); + } + } +#if CONFIG_PGTABLE_LEVELS > 2 + } else if (sz == (PMD_SIZE * CONTIG_PAGES)) { + pmd_t *pmd; + + pmd = pmd_alloc(mm, pud, addr); + WARN_ON(addr & (sz - 1)); + if (pmd && pmd_present(*pmd)) { + unsigned long pfn; + pmd_t pmdval; + + pmdval = *pmd = pmd_mkcontig(*pmd); + pfn = pmd_pfn(*pmd); + for (i = 0; i < CONTIG_PAGES; i++) { + unsigned long newpfn = pfn + + (i << (PMD_SHIFT - PAGE_SHIFT)); + if (!pmd_present(pmd[i])) + atomic_long_inc(&mm->nr_ptes); + set_pmd(&pmd[i], + pmd_modify_pfn(pmdval, newpfn)); + } + } + return pmd; +#endif + } + } + + return pte; +} + +pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd = NULL; + pte_t *pte = NULL; + + pgd = pgd_offset(mm, addr); + if (pgd_present(*pgd)) { + pud = pud_offset(pgd, addr); + if (pud_present(*pud)) { + if (pud_huge(*pud)) + return (pte_t *)pud; + pmd = pmd_offset(pud, addr); + if (pmd_present(*pmd)) { + if (pmd_huge(*pmd)) + return (pte_t *)pmd; + pte = pte_offset_kernel(pmd, addr); + if (pte_present(*pte) && pte_contig(*pte)) { + pte = pte_offset_kernel( + pmd, (addr & CONTIG_PTE_MASK)); + return pte; + } + } + } + } + return (pte_t *) NULL; +} + +pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma, + struct page *page, int writable) +{ + size_t pagesize = huge_page_size(hstate_vma(vma)); + pte_t nent = {0}; + + if (pagesize == PUD_SIZE || pagesize == PMD_SIZE) + nent = entry; + else if (pagesize == (PAGE_SIZE * CONTIG_PAGES)) + nent = pte_mkcontig(entry); +#if CONFIG_PGTABLE_LEVELS > 2 + else if (pagesize == (PMD_SIZE * CONTIG_PAGES) || + pagesize == (PUD_SIZE * CONTIG_PAGES)) + nent = pmd_mkcontig(entry); +#endif + else { + pr_warn("%s: unrecognized huge page size 0x%lx\n", + __func__, pagesize); + } + return nent; +} + +pte_t pte_mkcontig(pte_t pte) +{ + pte = set_pte_bit(pte, __pgprot(PTE_CONTIG)); + pte = set_pte_bit(pte, __pgprot(PTE_TYPE_PAGE)); + return pte; +} + +pmd_t pmd_mkcontig(pmd_t pmd) +{ + pmd = __pmd(pmd_val(pmd) | PMD_SECT_CONTIG); + return pmd; +} + +struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address, + pmd_t *pmd, int write) +{ + struct page *page; + + page = pte_page(*(pte_t *)pmd); + if (page) + page += ((address & ~PMD_MASK) >> PAGE_SHIFT); + return page; +} + +struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address, + pud_t *pud, int write) +{ + struct page *page; + + page = pte_page(*(pte_t *)pud); + if (page) + page += ((address & ~PUD_MASK) >> PAGE_SHIFT); + return page; +} + static __init int setup_hugepagesz(char *opt) { unsigned long ps = memparse(opt, &opt); @@ -48,10 +197,24 @@ static __init int setup_hugepagesz(char *opt) hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT); } else if (ps == PUD_SIZE) { hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT); + } else if (ps == (PAGE_SIZE * CONTIG_PAGES)) { + hugetlb_add_hstate(CONTIG_SHIFT); + } else if (ps == (PMD_SIZE * CONTIG_PAGES)) { + hugetlb_add_hstate((PMD_SHIFT + CONTIG_SHIFT) - PAGE_SHIFT); } else { - pr_err("hugepagesz: Unsupported page size %lu M\n", ps >> 20); + pr_err("hugepagesz: Unsupported page size %lu K\n", ps >> 10); return 0; } return 1; } __setup("hugepagesz=", setup_hugepagesz); + +#ifdef CONFIG_ARM64_64K_PAGES +static __init int add_default_hugepagesz(void) +{ + if (size_to_hstate(CONTIG_PAGES * PAGE_SIZE) == NULL) + hugetlb_add_hstate(CONTIG_SHIFT); + return 0; +} +arch_initcall(add_default_hugepagesz); +#endif