From patchwork Mon Oct 19 20:09:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woods X-Patchwork-Id: 7439581 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 75325BEEA4 for ; Mon, 19 Oct 2015 20:12:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 13107206DD for ; Mon, 19 Oct 2015 20:12:08 +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 5E46A20528 for ; Mon, 19 Oct 2015 20:12:06 +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 1ZoGko-0007IV-7S; Mon, 19 Oct 2015 20:09:58 +0000 Received: from mail-db3on0088.outbound.protection.outlook.com ([157.55.234.88] helo=emea01-db3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZoGkj-00079S-Vo for linux-arm-kernel@lists.infradead.org; Mon, 19 Oct 2015 20:09:55 +0000 Received: from DB3PR02MB0441.eurprd02.prod.outlook.com (10.160.50.145) by DB3PR02MB026.eurprd02.prod.outlook.com (10.242.128.22) with Microsoft SMTP Server (TLS) id 15.1.300.14; Mon, 19 Oct 2015 20:09:31 +0000 Received: from DB3PR02CA0004.eurprd02.prod.outlook.com (10.242.134.14) by DB3PR02MB0441.eurprd02.prod.outlook.com (10.160.50.145) with Microsoft SMTP Server (TLS) id 15.1.300.14; Mon, 19 Oct 2015 20:09:29 +0000 Received: from DB3FFO11FD006.protection.gbl (2a01:111:f400:7e04::117) by DB3PR02CA0004.outlook.office365.com (2a01:111:e400:9814::14) with Microsoft SMTP Server (TLS) id 15.1.300.14 via Frontend Transport; Mon, 19 Oct 2015 20:09:29 +0000 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none; ezchip.com; 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 DB3FFO11FD006.mail.protection.outlook.com (10.47.216.95) with Microsoft SMTP Server (TLS) id 15.1.300.4 via Frontend Transport; Mon, 19 Oct 2015 20:09:28 +0000 Received: (from dwoods@localhost) by ld-2.internal.tilera.com (8.14.4/8.14.4/Submit) id t9JK9RZo013288; Mon, 19 Oct 2015 16:09:27 -0400 From: David Woods To: Subject: [PATCH v2] arm64: Add support for PTE contiguous bit. Date: Mon, 19 Oct 2015 16:09:09 -0400 Message-ID: <1445285349-13242-1-git-send-email-dwoods@ezchip.com> X-Mailer: git-send-email 2.1.2 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD006; 1:Bd9MztA+yuxJn/cYgyXnMzMgLobU/w8pLdAIMy9vpXXFROkHA7nNYrZW9uVBORrtHl0lsK5/S/nrSSS2I9RKA5KPhhjFpILFUCfuw6bqs4NNCD3EdLtr4uzNFquQneyrXKAQLRXP4HubMmkn7z9mQ2Im+oPnqo2o2A8fpju9YI+E5gGAL5D4Fytg/87Payph8sXVaBC1VmML4g1xKfix6hxSHCqc8Rm5iEdsYNi8wY22anu0iJfNNHnB29r29gOa/e7T9ZmBGFPbRy5fhs8VDZpmSyrC/NZLji8A1Qmt/okDySK4x7KlNY7MEDqodL8AlOM4S/l9xqIntwPebYua1vcod21dY45eR8V8x5V4by4= X-Forefront-Antispam-Report: CIP:12.216.194.146; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(33646002)(46102003)(64706001)(5007970100001)(11100500001)(19580405001)(42186005)(6200100001)(5001960100002)(110136002)(107886002)(19580395003)(189998001)(50226001)(50986999)(47776003)(85426001)(36756003)(86362001)(50466002)(4001450100002)(48376002)(2351001)(5008740100001)(229853001)(6806005)(106476002)(106356001)(106466001)(104016004)(81156007)(7049001)(5003940100001)(92566002)(87936001)(97736004)(105606002)(9376005)(4001430100001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR02MB0441; H:ld-2.internal.tilera.com; FPR:; SPF:Fail; PTR:InfoNoRecords; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DB3PR02MB0441; 2:1StRUDRzICcDGYWlqDfGqNeW7rZBWxzX7tEv+CJ4PE6v3YQ0P13g3zLvhNdcD+AAsDB+XYk9iUDh6lR2rBp5TKtu1Q0fUC7Of2Dh2ikFEyOPxJyJ1ZYXuOXVLYUxBnPYGrT5I4nfJuJ7rCYbj8Nqv0Q1brbWFNLHPeHDsJJ5CSA=; 3:gjKPbXT9LslmVzeNSyifl6gC3N+FsdkgpGJnRuo9709IJfD4pv3B9nXENRTNVU6pXQUfpwGDD6DSkgvoIFiGGwET+GlvPU7kutanguOmAZOpdIOh1izTpbiIjD3XjGlwqUBgal24UjGiuGV+1ETetpnnj+8KCZpFb1zf3z8mr8dh4AYsLP5ajTE6jMuyjXrPio51WErQyFnVMISMP2esJQ6Cs46PPxQBbjmrn23ZHMVz6PfP/Qi4uM4CQngpJrYs; 25:mf4CHMy/zhEzPkQH5fiTgVOJVh5PNoayPn/cyx+o32fp+5u+dG6k2MHmkU+/JsxCe8QAjgd9QTI0lmQrTRJFsuXu0lU8bq5LTuWlib+yrY8ueYCklG2xrnrLDAuWQh6M6EYHst1vB31+3ygYUQ48DdXH8v+pOx133fs9FO3MC4lo8d469CpRrPFClwNuKPgBC/genK8BOau8gZbdwEkOszHg9NVxkursbXpQyBmeuawnDOQMUmE9hdg3iBYKwYOK; 20:wQKSF51KcKQBm4CgmBXKGIwJpN28oenaOiITlRYyheW0svvkUZzTbXqdr10SdE6mtTp6zrRA8y3Iw6snNZ+UhQlxB2+I1OpZutNkSN139J/lq8Ty7hC4ycAWgNgU+IvKgvahDgfcWAg6ZjEIXujU5rmkKy2sBPNm0QWVntIgre4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB3PR02MB0441; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(121898900299872); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001); SRVR:DB3PR02MB0441; BCL:0; PCL:0; RULEID:; SRVR:DB3PR02MB0441; X-Microsoft-Exchange-Diagnostics: 1; DB3PR02MB0441; 4:52O0cO7kuNcI5HRU19D6a/imG8d+p+otQNuspH62irBExbh2caruXUzs67Wje/oa3CSExRxcG38zKbHH3pkv9ED6ALFQjFrQPZ7nF/6W7YxQRctuboSmROMcoth8MWp7lTKs4xmJ/jdwJ4HdAWP0/bJgV1HTlhbi0M05AYKaSpoKNWa6h55Ek1OUd8+RJwqS9ve0VJ7ZbNOtTnQ1x7kmKVWKuiju7xVqAmrUjLNMMJjbm+V8Bg2bfTVkIxek3N/TonduOHoUzHuhBiFWvpXSVx6c7CXxVAVy72Iai02d8+3+eQMUXxqY57X7x0hZYoGruiLoq3oFMSta0OS2X57lc26GQkypdS3AFe/fjr/D77I= X-Forefront-PRVS: 07349BFAD2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB3PR02MB0441; 23:yE1jI1EuUxyKA3ApG3lSNwYera5TSNiyht0SI3bXM?= =?us-ascii?Q?tTM2Y46aC1CWj6sEShOg2xn4B1ldjeabfloYk7FXrgTaO6I9tB/Oq4MmmYGY?= =?us-ascii?Q?GyRCqt4rwj5DNSNeOAg93enD+zGLH4u6FBPQLI8TDq20+pSQCXaANgkaAu1l?= =?us-ascii?Q?OVY79i8DtF49t1L6rMsR5s9kBNyHf8Y9k5/AUdry9hCQchqfhYr6CNwZkCcI?= =?us-ascii?Q?qhxbDKu0/zjS5xk0AQ8hRNTmb8+OUb5GSeJGyS6oZdvfzF8XsmQ8dtc+F7yL?= =?us-ascii?Q?k8l+QYt6uMUJd2+xdnWIOlKhAGFnSa6qkeSjWcWnsLWE8LXdlSvPAVJglazW?= =?us-ascii?Q?PMGKRDrmv65f0WYTaSBv1g7b1IjYkDHfMa9Qeg3Id9OTXJ2KKYbu4zN7wtqr?= =?us-ascii?Q?D2yO5YYZlYXEYC5xg4aebsOVHxqrBqZQwA7q1Mfdv10dz7uJTpSZQAxtmJsK?= =?us-ascii?Q?7sU8TrMWzWeuL+W7kulOVKgTPDrrCfrucI71Em8v6sB6z1AsNHudBSiaQA28?= =?us-ascii?Q?UzbwecKukWVgqgliqatwqLVch00plhVklfYK49fgLJCKSrGHTGl8UixYOwW6?= =?us-ascii?Q?MX11uQaN9li/WHhnUSg1wp8soQhk+AJiI0NcxU25sS/qWkpTAr4Z0UX1VYQ1?= =?us-ascii?Q?6QbrxJF45V9NZAIG8YIYyETxofXm8Cfr2AmSowKCRRZmHVaUMrzaRetCj/ic?= =?us-ascii?Q?a6oSB/TECFucnIGiaW4HgvLJ1nXGLJYWb4tPPFOi3ZAJD0rid6K5iyCk3sh6?= =?us-ascii?Q?Nhbi4zv9hjErz2jpP9UckXpNMvJWdWKVygoSAVrM3gElJIRfx7qJpizraWAf?= =?us-ascii?Q?VAIyCaXvJoBsfu/qqrZKxyhb9tziAYe6jyB0Kya+3Zczp+QkUbt3NMOBsxSu?= =?us-ascii?Q?PEFbxc9mTEk+5DTSrCTsEh2yOC+bvcgxStSctvrgpTYTflgOjQ4FajbI60uv?= =?us-ascii?Q?Frfcb2iLD9ADm4twN/aKQwH0aMrkMSo9Zwxdz8PMeKBPB6JVth/v87EJDteO?= =?us-ascii?Q?nUUrUeeH/89F0n4oiy3tK3SYvZAmMaegvDeUDgsY8xmEJnwdqjPsFjJ4wdBS?= =?us-ascii?Q?1BP98RtoG5LKjUKmzZbXhJeHrENw9aYCEvQ1xKAwoBcHgt3o14dLkr0Xq0BB?= =?us-ascii?Q?lwBgA8/dxli7KexHGRltG9Iw3kAm5QJ9xPRAUuoYgHtkhTva2G+0Ka7SH158?= =?us-ascii?Q?E3+3LgVcFCWdC6/yJVvhNR1DuFB0RErKigG4Tj5Opf0gNKv/9ke5NZm8A=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB3PR02MB0441; 5:HiQbq1Kul+HpGnEcmMDq0TCfJ1loJjcI1jfyLK94k0PESpj2rRCN5E016U8U1cMjU+gjFCZpcgoUwLR2LBfxybU7ing/19YSb2d2m/V3sCTcjKpW5vR16o5VMOIwkcy0E9Pjhs7cSMNRTnxmcUB2zg==; 24:NdBGcFuNc73SKP9L3SDoQOBb4x4AS4fA3Corm98jxVQZgl9MM9DIH9nT5c+Sr7Verw3scqLBQUvhgqnpnKvkRX66LTs21KNTyjqqFNsEvIA=; 20:HvLfN723iiwOpyGp0fn1kZIYnEK1lfCwSlnYI1LiH3jCMV2n+bF1chcTPqM3XiKm4e7Be2uEyHT+QRzFYWfAgw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2015 20:09:28.7922 (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: DB3PR02MB0441 X-Microsoft-Exchange-Diagnostics: 1; DB3PR02MB026; 2:8HSHADTr4NS1W69VH9/bfHUoIC/4VM7TVbiAO7J7HPZMVhrTpQqO7YqolryhA37/Rs+iJPQo/MY/BWQ6ZuEYZbuqr6O2hknFTKZmQexStPCyl0muVWFeB85Bj7whCKxtJUEm5Z/xIBVM3oFipeGsUutY4XBy7zBTaV3c6suwZxE=; 23:FsVDLT3JxCMTHXSxFiXCTNLauAY6xrD1bbRCJfmThddptfsxf3a1Bh87J2Q026fQekpa0L2MqnvdwIVxfmqCJOmmRCcx9IJ41RU/LDtySF76/ydi/TJyWwknj6ZjnX15JJ4H5+sGiM3NOFSMDekbAi+diQhlV3Ed4LWphWHM6JI4HKRpiRHfxZ1eUOegvq/L X-OriginatorOrg: ezchip.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151019_130954_658502_DEED325C X-CRM114-Status: GOOD ( 16.57 ) 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@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, jeremy.linton@arm.com, linux-mm@kvack.org, cmetcalf@ezchip.com, linux-arm-kernel@lists.infradead.org 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, 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 With a 4KB granule, the contiguous bit groups together sets of 16 pages and with a 64KB granule 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 If a 16KB granule is used then the contiguous bit groups 128 pages at the PTE level and 32 pages at the PMD level. 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 granules. Signed-off-by: David Woods Reviewed-by: Chris Metcalf --- arch/arm64/Kconfig | 3 - arch/arm64/include/asm/hugetlb.h | 30 ++--- arch/arm64/include/asm/pgtable-hwdef.h | 20 ++++ arch/arm64/include/asm/pgtable.h | 33 +++++- arch/arm64/mm/hugetlbpage.c | 211 ++++++++++++++++++++++++++++++++- 5 files changed, 272 insertions(+), 25 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 07d1811..3aa151d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -464,9 +464,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..2b153a9 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -26,12 +26,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep) return *ptep; } -static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) -{ - set_pte_at(mm, addr, ptep, pte); -} - static inline void huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { @@ -44,19 +38,6 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, ptep_set_wrprotect(mm, addr, ptep); } -static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, - unsigned long addr, pte_t *ptep) -{ - return ptep_get_and_clear(mm, addr, ptep); -} - -static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep, - pte_t pte, int dirty) -{ - return ptep_set_access_flags(vma, addr, ptep, pte, dirty); -} - static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, unsigned long floor, @@ -97,4 +78,15 @@ 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 +extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte); +extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t pte, int dirty); +extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep); + #endif /* __ASM_HUGETLB_H */ diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 24154b0..1b921a5 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -55,6 +55,24 @@ #define SECTION_MASK (~(SECTION_SIZE-1)) /* + * Contiguous page definitions. + */ +#ifdef CONFIG_ARM64_64K_PAGES +#define CONT_PTE_SHIFT 5 +#define CONT_PMD_SHIFT 5 +#else +#define CONT_PTE_SHIFT 4 +#define CONT_PMD_SHIFT 4 +#endif + +#define CONT_PTES (1 << CONT_PTE_SHIFT) +#define CONT_PTE_SIZE (CONT_PTES * PAGE_SIZE) +#define CONT_PTE_MASK (~(CONT_PTE_SIZE - 1)) +#define CONT_PMDS (1 << CONT_PMD_SHIFT) +#define CONT_PMD_SIZE (CONT_PMDS * PMD_SIZE) +#define CONT_PMD_MASK (~(CONT_PMD_SIZE - 1)) + +/* * Hardware page table definitions. * * Level 1 descriptor (PUD). @@ -83,6 +101,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_CONT (_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 +124,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_CONT (_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 26b0666..cf079a1 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -140,6 +140,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_cont(pte) (!!(pte_val(pte) & PTE_CONT)) #ifdef CONFIG_ARM64_HW_AFDBM #define pte_hw_dirty(pte) (pte_write(pte) && !(pte_val(pte) & PTE_RDONLY)) @@ -202,6 +203,18 @@ static inline pte_t pte_mkspecial(pte_t pte) return set_pte_bit(pte, __pgprot(PTE_SPECIAL)); } +static inline pte_t pte_mkcont(pte_t pte) +{ + pte = set_pte_bit(pte, __pgprot(PTE_CONT)); + return set_pte_bit(pte, __pgprot(PTE_TYPE_PAGE)); + return pte; +} + +static inline pmd_t pmd_mkcont(pmd_t pmd) +{ + return __pmd(pmd_val(pmd) | PMD_SECT_CONT); +} + static inline void set_pte(pte_t *ptep, pte_t pte) { *ptep = pte; @@ -271,7 +284,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)) @@ -496,7 +509,7 @@ 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_VALID | PTE_WRITE; + PTE_PROT_NONE | PTE_VALID | PTE_WRITE | PTE_CONT; /* preserve the hardware dirty information */ if (pte_hw_dirty(pte)) pte = pte_mkdirty(pte); @@ -509,6 +522,22 @@ 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; +} + +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; +} + #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..20fd34c 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -41,6 +41,201 @@ int pud_huge(pud_t pud) #endif } +static int find_num_contig(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, size_t *pgsize) +{ + pgd_t *pgd = pgd_offset(mm, addr); + pud_t *pud; + pmd_t *pmd; + + if (!pte_cont(pte)) + return 1; + + pud = pud_offset(pgd, addr); + pmd = pmd_offset(pud, addr); + if ((pte_t *)pmd == ptep) { + *pgsize = PMD_SIZE; + return CONT_PMDS; + } + *pgsize = PAGE_SIZE; + return CONT_PTES; +} + +extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte) +{ + size_t pgsize; + int ncontig = find_num_contig(mm, addr, ptep, pte, &pgsize); + + if (ncontig == 1) { + set_pte_at(mm, addr, ptep, pte); + } else { + int i; + unsigned long pfn = pte_pfn(pte); + pgprot_t hugeprot = + __pgprot(pte_val(pfn_pte(pfn, 0) ^ pte_val(pte))); + for (i = 0; i < ncontig; i++) { + pr_debug("%s: set pte %p to 0x%llx\n", __func__, ptep, + pfn_pte(pfn, hugeprot)); + set_pte_at(mm, addr, ptep, pfn_pte(pfn, hugeprot)); + ptep++; + pfn += pgsize / PAGE_SIZE; + addr += pgsize; + } + } +} + +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; + + pr_debug("%s: addr:0x%lx sz:0x%lx\n", __func__, addr, sz); + pgd = pgd_offset(mm, addr); + pud = pud_alloc(mm, pgd, addr); + if (pud) { + if (sz == PUD_SIZE) { + pte = (pte_t *)pud; + } else if (sz == (PAGE_SIZE * CONT_PTES)) { + pmd_t *pmd = pmd_alloc(mm, pud, addr); + + WARN_ON(addr & (sz - 1)); + pte = pte_alloc_map(mm, NULL, pmd, addr); + } 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 == (PMD_SIZE * CONT_PMDS)) { + pmd_t *pmd; + + pmd = pmd_alloc(mm, pud, addr); + WARN_ON(addr & (sz - 1)); + return (pte_t *)pmd; + } + } + + pr_debug("%s: addr:0x%lx sz:0x%lx ret pte=%p/0x%llx\n", __func__, addr, + sz, pte, pte_val(*pte)); + 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); + pr_debug("%s: addr:0x%lx pgd:%p\n", __func__, addr, pgd); + 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 (pte_cont(pmd_pte(*pmd))) { + pmd = pmd_offset( + pud, (addr & CONT_PMD_MASK)); + return (pte_t *)pmd; + } + if (pmd_huge(*pmd)) + return (pte_t *)pmd; + pte = pte_offset_kernel(pmd, addr); + if (pte_present(*pte) && pte_cont(*pte)) { + pte = pte_offset_kernel( + pmd, (addr & CONT_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)); + + if (pagesize == CONT_PTE_SIZE) { + entry = pte_mkcont(entry); + } else if (pagesize == CONT_PMD_SIZE) { + entry = pmd_pte(pmd_mkcont(pte_pmd(entry))); + } else if (pagesize != PUD_SIZE && pagesize != PMD_SIZE) { + pr_warn("%s: unrecognized huge page size 0x%lx\n", + __func__, pagesize); + } + return entry; +} + +extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) +{ + pte_t pte = {0}; + + if (pte_cont(*ptep)) { + int ncontig, i; + size_t pgsize; + pte_t *cpte; + bool is_dirty = false; + + cpte = huge_pte_offset(mm, addr); + ncontig = find_num_contig(mm, addr, cpte, + pte_val(*cpte), &pgsize); + /* save the 1st pte to return */ + pte = ptep_get_and_clear(mm, addr, cpte); + for (i = 1; i < ncontig; ++i) { + if (pte_dirty(ptep_get_and_clear(mm, addr, ++cpte))) + is_dirty = true; + } + if (is_dirty) + return pte_mkdirty(pte); + else + return pte; + } else { + return ptep_get_and_clear(mm, addr, ptep); + } +} + +int huge_ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t pte, int dirty) +{ + pte_t *cpte; + + if (pte_cont(pte)) { + int ncontig, i, changed = 0; + size_t pgsize = 0; + unsigned long pfn = pte_pfn(pte); + /* Select all bits except the pfn */ + pgprot_t hugeprot = + __pgprot(pte_val(pfn_pte(pfn, 0) ^ pte_val(pte))); + + cpte = huge_pte_offset(vma->vm_mm, addr); + pfn = pte_pfn(*cpte); + ncontig = find_num_contig(vma->vm_mm, addr, cpte, + pte_val(*cpte), &pgsize); + for (i = 0; i < ncontig; ++i, ++cpte) { + changed = ptep_set_access_flags(vma, addr, cpte, + pfn_pte(pfn, + hugeprot), + dirty); + pfn += pgsize / PAGE_SIZE; + } + return changed; + } else { + return ptep_set_access_flags(vma, addr, ptep, pte, dirty); + } +} + + static __init int setup_hugepagesz(char *opt) { unsigned long ps = memparse(opt, &opt); @@ -48,10 +243,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 * CONT_PTES)) { + hugetlb_add_hstate(CONT_PTE_SHIFT); + } else if (ps == (PMD_SIZE * CONT_PMDS)) { + hugetlb_add_hstate((PMD_SHIFT + CONT_PMD_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(CONT_PTES * PAGE_SIZE) == NULL) + hugetlb_add_hstate(CONT_PMD_SHIFT); + return 0; +} +arch_initcall(add_default_hugepagesz); +#endif