Received: by 10.192.165.148 with SMTP id m20csp728199imm; Fri, 4 May 2018 05:36:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpcJS3wiAHCLF/oOGq7mK/wY8F2KX8l1RUsMHRx27x25ICX1SAj+i4A2r9i+iulB7IHTaVT X-Received: by 2002:a63:724b:: with SMTP id c11-v6mr2699675pgn.267.1525437370403; Fri, 04 May 2018 05:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525437370; cv=none; d=google.com; s=arc-20160816; b=whRiD6f9fEeJFsVvS1ZWVPOoWnn9iaRB8KZwCdTs5CTFCvpbI6DEDmCNWsevftdbnq omprSf4Egl/qOxTfSi/k5w+hmYIqPsyJS6o2VSv7QiD/CvVUJL1wzf/ZhsfLC4TKoHuL Q8IKF0esfThWNFVVRMLl4JqBbyMyCi1bkQTbqM7hLMCT00ss0qdlCpDTYlcTSJXmFU2/ TdvM61Zrx/YFx3tBg2IpZ7PuxklfN0Hvrd/yPYjs8LtIbBI9Ys6SZfabjJmoskkueJP1 /7rSBfh8rSuB8XDadU7JpBZT7xM2oDC/R0N0/Pb5yRWnt4Qt/LYqtBk+HEvqIu0jJooR LXEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:arc-authentication-results; bh=b4FwbxFMghkA2oKQ37wu7J94JN5QnS8uuKxxXc2BlF0=; b=IF9Bw3jyr21LEI9j1DeFUPWUAl46WJ6kZcEO7EFRmCvYYNGpz5meulDkN+v0QYA+Yl liShbo+D/bSZYEXKHVbhT+fdS28Hde7lAsfT2pTw0gftXedtLGYvGPf5T9+0n94klfLt gRic0GTDYWst1cdpb4FMR07tREWFuZBSYJxstTgvL8fpfVrNwjBZ0PHZPnzSR9PX3dhH a/062Kx9UHdtj6EBj2sJr8qxBwLhbn9s9+KeusSXlJtyDqBGhnhlLx41BCPZedrtLd6r VbREUdiWKiRs/gc9+28MIkgNWz4HXtPAXg3reTGQ/UyciUaV0UcAfhi5OsdzUGoOXqN8 Uz9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36-v6si2115149plb.140.2018.05.04.05.35.55; Fri, 04 May 2018 05:36:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751823AbeEDMe7 (ORCPT + 99 others); Fri, 4 May 2018 08:34:59 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:45327 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751756AbeEDMe0 (ORCPT ); Fri, 4 May 2018 08:34:26 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40crzx4mBmz9tvTF; Fri, 4 May 2018 14:34:21 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id zZYK-c86ECrp; Fri, 4 May 2018 14:34:21 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 40crzx4FZQz9ttC1; Fri, 4 May 2018 14:34:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6A2498B975; Fri, 4 May 2018 14:34:25 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id tc5t1T6i1iMc; Fri, 4 May 2018 14:34:25 +0200 (CEST) Received: from po14934vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3A7E68B972; Fri, 4 May 2018 14:34:25 +0200 (CEST) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id F41616CF2D; Fri, 4 May 2018 14:34:24 +0200 (CEST) Message-Id: <8955044d4d18afa0fc413d9401669156c990a243.1525435203.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH BAD 17/17] powerpc/mm: Use pte_fragment_alloc() on 8xx To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , aneesh.kumar@linux.vnet.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Fri, 4 May 2018 14:34:24 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org DO NOT APPLY THAT ONE, IT BUGS. But comments are welcome. In 16k pages mode, the 8xx still need only 4k for the page table. This patch makes use of the pte_fragment functions in order to avoid wasting memory space Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/mmu-8xx.h | 4 ++++ arch/powerpc/include/asm/nohash/32/pgalloc.h | 29 +++++++++++++++++++++++++++- arch/powerpc/include/asm/nohash/32/pgtable.h | 5 ++++- arch/powerpc/mm/mmu_context_nohash.c | 4 ++++ arch/powerpc/mm/pgtable.c | 10 +++++++++- arch/powerpc/mm/pgtable_32.c | 12 ++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 1 + 7 files changed, 62 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/mmu-8xx.h b/arch/powerpc/include/asm/mmu-8xx.h index 193f53116c7a..4f4cb754afd8 100644 --- a/arch/powerpc/include/asm/mmu-8xx.h +++ b/arch/powerpc/include/asm/mmu-8xx.h @@ -190,6 +190,10 @@ typedef struct { struct slice_mask mask_8m; # endif #endif +#ifdef CONFIG_NEED_PTE_FRAG + /* for 4K PTE fragment support */ + void *pte_frag; +#endif } mm_context_t; #define PHYS_IMMR_BASE (mfspr(SPRN_IMMR) & 0xfff80000) diff --git a/arch/powerpc/include/asm/nohash/32/pgalloc.h b/arch/powerpc/include/asm/nohash/32/pgalloc.h index 1c6461e7c6aa..1e3b8f580499 100644 --- a/arch/powerpc/include/asm/nohash/32/pgalloc.h +++ b/arch/powerpc/include/asm/nohash/32/pgalloc.h @@ -93,6 +93,32 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp, ((unlikely(pmd_none(*(pmd))) && __pte_alloc_kernel_g(pmd, address))? \ NULL: pte_offset_kernel(pmd, address)) +#ifdef CONFIG_NEED_PTE_FRAG +extern pte_t *pte_fragment_alloc(struct mm_struct *, unsigned long, int); +extern void pte_fragment_free(unsigned long *, int); + +static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, + unsigned long address) +{ + return (pte_t *)pte_fragment_alloc(mm, address, 1); +} + +static inline pgtable_t pte_alloc_one(struct mm_struct *mm, + unsigned long address) +{ + return (pgtable_t)pte_fragment_alloc(mm, address, 0); +} + +static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) +{ + pte_fragment_free((unsigned long *)pte, 1); +} + +static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage) +{ + pte_fragment_free((unsigned long *)ptepage, 0); +} +#else extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr); extern pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr); @@ -106,11 +132,12 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage) pgtable_page_dtor(ptepage); __free_page(ptepage); } +#endif static inline void pgtable_free(void *table, unsigned index_size) { if (!index_size) { - free_page((unsigned long)table); + pte_free_kernel(NULL, table); } else { BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE); kmem_cache_free(PGT_CACHE(index_size), table); diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h index 3efd616bbc80..e2a22c8dc7f6 100644 --- a/arch/powerpc/include/asm/nohash/32/pgtable.h +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h @@ -20,6 +20,9 @@ extern int icache_44x_need_flush; #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES) #define PTE_INDEX_SIZE (PTE_SHIFT - 2) +#define PTE_FRAG_NR 4 +#define PTE_FRAG_SIZE_SHIFT 12 +#define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT) #else #define PTE_INDEX_SIZE PTE_SHIFT #endif @@ -303,7 +306,7 @@ static inline void __ptep_set_access_flags(struct mm_struct *mm, */ #ifndef CONFIG_BOOKE #define pmd_page_vaddr(pmd) \ - ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK)) + ((unsigned long) __va(pmd_val(pmd) & ~(PTE_TABLE_SIZE - 1))) #define pmd_page(pmd) \ pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT) #else diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c index e09228a9ad00..8b0ab33673e5 100644 --- a/arch/powerpc/mm/mmu_context_nohash.c +++ b/arch/powerpc/mm/mmu_context_nohash.c @@ -390,6 +390,9 @@ int init_new_context(struct task_struct *t, struct mm_struct *mm) #endif mm->context.id = MMU_NO_CONTEXT; mm->context.active = 0; +#ifdef CONFIG_NEED_PTE_FRAG + mm->context.pte_frag = NULL; +#endif return 0; } @@ -418,6 +421,7 @@ void destroy_context(struct mm_struct *mm) nr_free_contexts++; } raw_spin_unlock_irqrestore(&context_lock, flags); + destroy_pagetable_page(mm); } #ifdef CONFIG_SMP diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 2d34755ed727..96cc5aa73331 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -320,10 +321,17 @@ static pte_t *__alloc_for_cache(struct mm_struct *mm, int kernel) return (pte_t *)ret; } -pte_t *pte_fragment_alloc(struct mm_struct *mm, unsigned long vmaddr, int kernel) +__ref pte_t *pte_fragment_alloc(struct mm_struct *mm, unsigned long vmaddr, int kernel) { pte_t *pte; + if (kernel && !slab_is_available()) { + pte = __va(memblock_alloc(PTE_FRAG_SIZE, PTE_FRAG_SIZE)); + if (pte) + memset(pte, 0, PTE_FRAG_SIZE); + + return pte; + } pte = get_from_cache(mm); if (pte) return pte; diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c index 3aa0c78db95d..5c8737cf2945 100644 --- a/arch/powerpc/mm/pgtable_32.c +++ b/arch/powerpc/mm/pgtable_32.c @@ -40,6 +40,17 @@ extern char etext[], _stext[], _sinittext[], _einittext[]; +#ifdef CONFIG_NEED_PTE_FRAG +void pte_fragment_free(unsigned long *table, int kernel) +{ + struct page *page = virt_to_page(table); + if (put_page_testzero(page)) { + if (!kernel) + pgtable_page_dtor(page); + free_unref_page(page); + } +} +#else __ref pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address) { pte_t *pte; @@ -69,6 +80,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address) } return ptepage; } +#endif #ifdef CONFIG_PPC_GUARDED_PAGE_IN_PMD int __pte_alloc_kernel_g(pmd_t *pmd, unsigned long address) diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 7172b04c91b5..eff6210ad3c0 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -340,6 +340,7 @@ config PPC_MM_SLICES config NEED_PTE_FRAG bool default y if PPC_BOOK3S_64 && PPC_64K_PAGES + default y if PPC_8xx && PPC_16K_PAGES default n config PPC_HAVE_PMU_SUPPORT -- 2.13.3