2016-04-29 20:26:29 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2015-2016, Aneesh Kumar K.V, IBM Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
2017-02-04 06:16:44 +07:00
|
|
|
#include <linux/mm_types.h>
|
2018-04-16 18:27:14 +07:00
|
|
|
#include <linux/memblock.h>
|
2017-07-27 13:24:54 +07:00
|
|
|
#include <misc/cxl-base.h>
|
2017-02-04 06:16:44 +07:00
|
|
|
|
2016-04-29 20:26:29 +07:00
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/tlb.h>
|
2018-04-16 18:27:14 +07:00
|
|
|
#include <asm/trace.h>
|
|
|
|
#include <asm/powernv.h>
|
2016-04-29 20:26:29 +07:00
|
|
|
|
|
|
|
#include "mmu_decl.h"
|
|
|
|
#include <trace/events/thp.h>
|
|
|
|
|
2018-04-16 18:27:22 +07:00
|
|
|
unsigned long __pmd_frag_nr;
|
|
|
|
EXPORT_SYMBOL(__pmd_frag_nr);
|
|
|
|
unsigned long __pmd_frag_size_shift;
|
|
|
|
EXPORT_SYMBOL(__pmd_frag_size_shift);
|
|
|
|
|
2016-08-04 12:32:06 +07:00
|
|
|
int (*register_process_table)(unsigned long base, unsigned long page_size,
|
|
|
|
unsigned long tbl_size);
|
|
|
|
|
2016-04-29 20:26:29 +07:00
|
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
|
|
|
/*
|
|
|
|
* This is called when relaxing access to a hugepage. It's also called in the page
|
|
|
|
* fault path when we don't hit any of the major fault cases, ie, a minor
|
|
|
|
* update of _PAGE_ACCESSED, _PAGE_DIRTY, etc... The generic code will have
|
|
|
|
* handled those two for us, we additionally deal with missing execute
|
|
|
|
* permission here on some processors
|
|
|
|
*/
|
|
|
|
int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
|
|
|
|
pmd_t *pmdp, pmd_t entry, int dirty)
|
|
|
|
{
|
|
|
|
int changed;
|
|
|
|
#ifdef CONFIG_DEBUG_VM
|
2017-06-28 08:32:34 +07:00
|
|
|
WARN_ON(!pmd_trans_huge(*pmdp) && !pmd_devmap(*pmdp));
|
2018-04-16 18:27:16 +07:00
|
|
|
assert_spin_locked(pmd_lockptr(vma->vm_mm, pmdp));
|
2016-04-29 20:26:29 +07:00
|
|
|
#endif
|
|
|
|
changed = !pmd_same(*(pmdp), entry);
|
|
|
|
if (changed) {
|
2018-05-29 21:28:40 +07:00
|
|
|
/*
|
|
|
|
* We can use MMU_PAGE_2M here, because only radix
|
|
|
|
* path look at the psize.
|
|
|
|
*/
|
|
|
|
__ptep_set_access_flags(vma, pmdp_ptep(pmdp),
|
|
|
|
pmd_pte(entry), address, MMU_PAGE_2M);
|
2016-04-29 20:26:29 +07:00
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pmdp_test_and_clear_young(struct vm_area_struct *vma,
|
|
|
|
unsigned long address, pmd_t *pmdp)
|
|
|
|
{
|
|
|
|
return __pmdp_test_and_clear_young(vma->vm_mm, address, pmdp);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* set a new huge pmd. We should not be called for updating
|
|
|
|
* an existing pmd entry. That should go via pmd_hugepage_update.
|
|
|
|
*/
|
|
|
|
void set_pmd_at(struct mm_struct *mm, unsigned long addr,
|
|
|
|
pmd_t *pmdp, pmd_t pmd)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_DEBUG_VM
|
2018-09-21 01:09:42 +07:00
|
|
|
/*
|
|
|
|
* Make sure hardware valid bit is not set. We don't do
|
|
|
|
* tlb flush for this update.
|
|
|
|
*/
|
powerpc/mm: Fix WARN_ON with THP NUMA migration
WARNING: CPU: 12 PID: 4322 at /arch/powerpc/mm/pgtable-book3s64.c:76 set_pmd_at+0x4c/0x2b0
Modules linked in:
CPU: 12 PID: 4322 Comm: qemu-system-ppc Tainted: G W 4.19.0-rc3-00758-g8f0c636b0542 #36
NIP: c0000000000872fc LR: c000000000484eec CTR: 0000000000000000
REGS: c000003fba876fe0 TRAP: 0700 Tainted: G W (4.19.0-rc3-00758-g8f0c636b0542)
MSR: 900000010282b033 <SF,HV,VEC,VSX,EE,FP,ME,IR,DR,RI,LE,TM[E]> CR: 24282884 XER: 00000000
CFAR: c000000000484ee8 IRQMASK: 0
GPR00: c000000000484eec c000003fba877268 c000000001f0ec00 c000003fbd229f80
GPR04: 00007c8fe8e00000 c000003f864c5a38 860300853e0000c0 0000000000000080
GPR08: 0000000080000000 0000000000000001 0401000000000080 0000000000000001
GPR12: 0000000000002000 c000003fffff5400 c000003fce292000 00007c9024570000
GPR16: 0000000000000000 0000000000ffffff 0000000000000001 c000000001885950
GPR20: 0000000000000000 001ffffc0004807c 0000000000000008 c000000001f49d05
GPR24: 00007c8fe8e00000 c0000000020f2468 ffffffffffffffff c000003fcd33b090
GPR28: 00007c8fe8e00000 c000003fbd229f80 c000003f864c5a38 860300853e0000c0
NIP [c0000000000872fc] set_pmd_at+0x4c/0x2b0
LR [c000000000484eec] do_huge_pmd_numa_page+0xb1c/0xc20
Call Trace:
[c000003fba877268] [c00000000045931c] mpol_misplaced+0x1bc/0x230 (unreliable)
[c000003fba8772c8] [c000000000484eec] do_huge_pmd_numa_page+0xb1c/0xc20
[c000003fba877398] [c00000000040d344] __handle_mm_fault+0x5e4/0x2300
[c000003fba8774d8] [c00000000040f400] handle_mm_fault+0x3a0/0x420
[c000003fba877528] [c0000000003ff6f4] __get_user_pages+0x2e4/0x560
[c000003fba877628] [c000000000400314] get_user_pages_unlocked+0x104/0x2a0
[c000003fba8776c8] [c000000000118f44] __gfn_to_pfn_memslot+0x284/0x6a0
[c000003fba877748] [c0000000001463a0] kvmppc_book3s_radix_page_fault+0x360/0x12d0
[c000003fba877838] [c000000000142228] kvmppc_book3s_hv_page_fault+0x48/0x1300
[c000003fba877988] [c00000000013dc08] kvmppc_vcpu_run_hv+0x1808/0x1b50
[c000003fba877af8] [c000000000126b44] kvmppc_vcpu_run+0x34/0x50
[c000003fba877b18] [c000000000123268] kvm_arch_vcpu_ioctl_run+0x288/0x2d0
[c000003fba877b98] [c00000000011253c] kvm_vcpu_ioctl+0x1fc/0x8c0
[c000003fba877d08] [c0000000004e9b24] do_vfs_ioctl+0xa44/0xae0
[c000003fba877db8] [c0000000004e9c44] ksys_ioctl+0x84/0xf0
[c000003fba877e08] [c0000000004e9cd8] sys_ioctl+0x28/0x80
We removed the pte_protnone check earlier with the understanding that we
mark the pte invalid before the set_pte/set_pmd usage. But the huge pmd
autonuma still use the set_pmd_at directly. This is ok because a protnone pte
won't have translation cache in TLB.
Fixes: da7ad366b497 ("powerpc/mm/book3s: Update pmd_present to look at _PAGE_PRESENT bit")
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-10-13 23:48:15 +07:00
|
|
|
|
|
|
|
WARN_ON(pte_hw_valid(pmd_pte(*pmdp)) && !pte_protnone(pmd_pte(*pmdp)));
|
2018-04-16 18:27:16 +07:00
|
|
|
assert_spin_locked(pmd_lockptr(mm, pmdp));
|
2018-09-21 01:09:44 +07:00
|
|
|
WARN_ON(!(pmd_large(pmd) || pmd_devmap(pmd)));
|
2016-04-29 20:26:29 +07:00
|
|
|
#endif
|
|
|
|
trace_hugepage_set_pmd(addr, pmd_val(pmd));
|
|
|
|
return set_pte_at(mm, addr, pmdp_ptep(pmdp), pmd_pte(pmd));
|
|
|
|
}
|
2017-07-27 13:24:54 +07:00
|
|
|
|
|
|
|
static void do_nothing(void *unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Serialize against find_current_mm_pte which does lock-less
|
|
|
|
* lookup in page tables with local interrupts disabled. For huge pages
|
|
|
|
* it casts pmd_t to pte_t. Since format of pte_t is different from
|
|
|
|
* pmd_t we want to prevent transit from pmd pointing to page table
|
|
|
|
* to pmd pointing to huge page (and back) while interrupts are disabled.
|
|
|
|
* We clear pmd to possibly replace it with page table pointer in
|
|
|
|
* different code paths. So make sure we wait for the parallel
|
|
|
|
* find_current_mm_pte to finish.
|
|
|
|
*/
|
|
|
|
void serialize_against_pte_lookup(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
smp_mb();
|
2017-07-27 13:24:55 +07:00
|
|
|
smp_call_function_many(mm_cpumask(mm), do_nothing, NULL, 1);
|
2017-07-27 13:24:54 +07:00
|
|
|
}
|
|
|
|
|
2016-04-29 20:26:29 +07:00
|
|
|
/*
|
|
|
|
* We use this to invalidate a pmdp entry before switching from a
|
|
|
|
* hugepte to regular pmd entry.
|
|
|
|
*/
|
2018-02-01 07:18:02 +07:00
|
|
|
pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
|
2016-04-29 20:26:29 +07:00
|
|
|
pmd_t *pmdp)
|
|
|
|
{
|
2018-02-01 07:18:02 +07:00
|
|
|
unsigned long old_pmd;
|
|
|
|
|
2018-09-21 01:09:42 +07:00
|
|
|
old_pmd = pmd_hugepage_update(vma->vm_mm, address, pmdp, _PAGE_PRESENT, _PAGE_INVALID);
|
2016-07-13 16:36:40 +07:00
|
|
|
flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
|
2016-04-29 20:26:29 +07:00
|
|
|
/*
|
|
|
|
* This ensures that generic code that rely on IRQ disabling
|
|
|
|
* to prevent a parallel THP split work as expected.
|
|
|
|
*/
|
2017-07-27 13:24:54 +07:00
|
|
|
serialize_against_pte_lookup(vma->vm_mm);
|
2018-02-01 07:18:02 +07:00
|
|
|
return __pmd(old_pmd);
|
2016-04-29 20:26:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static pmd_t pmd_set_protbits(pmd_t pmd, pgprot_t pgprot)
|
|
|
|
{
|
|
|
|
return __pmd(pmd_val(pmd) | pgprot_val(pgprot));
|
|
|
|
}
|
|
|
|
|
|
|
|
pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgprot)
|
|
|
|
{
|
|
|
|
unsigned long pmdv;
|
|
|
|
|
|
|
|
pmdv = (pfn << PAGE_SHIFT) & PTE_RPN_MASK;
|
|
|
|
return pmd_set_protbits(__pmd(pmdv), pgprot);
|
|
|
|
}
|
|
|
|
|
|
|
|
pmd_t mk_pmd(struct page *page, pgprot_t pgprot)
|
|
|
|
{
|
|
|
|
return pfn_pmd(page_to_pfn(page), pgprot);
|
|
|
|
}
|
|
|
|
|
|
|
|
pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
|
|
|
|
{
|
|
|
|
unsigned long pmdv;
|
|
|
|
|
|
|
|
pmdv = pmd_val(pmd);
|
|
|
|
pmdv &= _HPAGE_CHG_MASK;
|
|
|
|
return pmd_set_protbits(__pmd(pmdv), newprot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called at the end of handling a user page fault, when the
|
|
|
|
* fault has been handled by updating a HUGE PMD entry in the linux page tables.
|
|
|
|
* We use it to preload an HPTE into the hash table corresponding to
|
|
|
|
* the updated linux HUGE PMD entry.
|
|
|
|
*/
|
|
|
|
void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
|
|
|
|
pmd_t *pmd)
|
|
|
|
{
|
2018-06-01 17:01:18 +07:00
|
|
|
if (radix_enabled())
|
|
|
|
prefetch((void *)addr);
|
2016-04-29 20:26:29 +07:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
|
2016-08-19 15:52:37 +07:00
|
|
|
|
|
|
|
/* For use by kexec */
|
|
|
|
void mmu_cleanup_all(void)
|
|
|
|
{
|
|
|
|
if (radix_enabled())
|
|
|
|
radix__mmu_cleanup_all();
|
|
|
|
else if (mmu_hash_ops.hpte_clear_all)
|
|
|
|
mmu_hash_ops.hpte_clear_all();
|
|
|
|
}
|
2017-01-04 03:39:51 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_MEMORY_HOTPLUG
|
2018-03-30 20:11:24 +07:00
|
|
|
int __meminit create_section_mapping(unsigned long start, unsigned long end, int nid)
|
2017-01-04 03:39:51 +07:00
|
|
|
{
|
|
|
|
if (radix_enabled())
|
2018-02-13 22:08:22 +07:00
|
|
|
return radix__create_section_mapping(start, end, nid);
|
2017-01-04 03:39:51 +07:00
|
|
|
|
2018-02-13 22:08:22 +07:00
|
|
|
return hash__create_section_mapping(start, end, nid);
|
2017-01-04 03:39:51 +07:00
|
|
|
}
|
|
|
|
|
2018-03-10 03:45:58 +07:00
|
|
|
int __meminit remove_section_mapping(unsigned long start, unsigned long end)
|
2017-01-04 03:39:51 +07:00
|
|
|
{
|
|
|
|
if (radix_enabled())
|
2017-01-17 02:07:45 +07:00
|
|
|
return radix__remove_section_mapping(start, end);
|
2017-01-04 03:39:51 +07:00
|
|
|
|
|
|
|
return hash__remove_section_mapping(start, end);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MEMORY_HOTPLUG */
|
2018-04-16 18:27:14 +07:00
|
|
|
|
|
|
|
void __init mmu_partition_table_init(void)
|
|
|
|
{
|
|
|
|
unsigned long patb_size = 1UL << PATB_SIZE_SHIFT;
|
|
|
|
unsigned long ptcr;
|
|
|
|
|
|
|
|
BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 36), "Partition table size too large.");
|
|
|
|
/* Initialize the Partition Table with no entries */
|
2019-03-08 07:30:48 +07:00
|
|
|
partition_tb = memblock_alloc(patb_size, patb_size);
|
2019-03-12 13:30:31 +07:00
|
|
|
if (!partition_tb)
|
|
|
|
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
|
|
|
|
__func__, patb_size, patb_size);
|
2018-04-16 18:27:14 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* update partition table control register,
|
|
|
|
* 64 K size.
|
|
|
|
*/
|
|
|
|
ptcr = __pa(partition_tb) | (PATB_SIZE_SHIFT - 12);
|
|
|
|
mtspr(SPRN_PTCR, ptcr);
|
|
|
|
powernv_set_nmmu_ptcr(ptcr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
|
|
|
|
unsigned long dw1)
|
|
|
|
{
|
|
|
|
unsigned long old = be64_to_cpu(partition_tb[lpid].patb0);
|
|
|
|
|
|
|
|
partition_tb[lpid].patb0 = cpu_to_be64(dw0);
|
|
|
|
partition_tb[lpid].patb1 = cpu_to_be64(dw1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global flush of TLBs and partition table caches for this lpid.
|
|
|
|
* The type of flush (hash or radix) depends on what the previous
|
|
|
|
* use of this partition ID was, not the new use.
|
|
|
|
*/
|
|
|
|
asm volatile("ptesync" : : : "memory");
|
|
|
|
if (old & PATB_HR) {
|
|
|
|
asm volatile(PPC_TLBIE_5(%0,%1,2,0,1) : :
|
|
|
|
"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
|
|
|
|
asm volatile(PPC_TLBIE_5(%0,%1,2,1,1) : :
|
|
|
|
"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
|
|
|
|
trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 1);
|
|
|
|
} else {
|
|
|
|
asm volatile(PPC_TLBIE_5(%0,%1,2,0,0) : :
|
|
|
|
"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
|
|
|
|
trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 0);
|
|
|
|
}
|
|
|
|
/* do we need fixup here ?*/
|
|
|
|
asm volatile("eieio; tlbsync; ptesync" : : : "memory");
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mmu_partition_table_set_entry);
|
2018-04-16 18:27:20 +07:00
|
|
|
|
2018-04-16 18:27:22 +07:00
|
|
|
static pmd_t *get_pmd_from_cache(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
void *pmd_frag, *ret;
|
|
|
|
|
2018-11-29 21:06:53 +07:00
|
|
|
if (PMD_FRAG_NR == 1)
|
|
|
|
return NULL;
|
|
|
|
|
2018-04-16 18:27:22 +07:00
|
|
|
spin_lock(&mm->page_table_lock);
|
|
|
|
ret = mm->context.pmd_frag;
|
|
|
|
if (ret) {
|
|
|
|
pmd_frag = ret + PMD_FRAG_SIZE;
|
|
|
|
/*
|
|
|
|
* If we have taken up all the fragments mark PTE page NULL
|
|
|
|
*/
|
|
|
|
if (((unsigned long)pmd_frag & ~PAGE_MASK) == 0)
|
|
|
|
pmd_frag = NULL;
|
|
|
|
mm->context.pmd_frag = pmd_frag;
|
|
|
|
}
|
|
|
|
spin_unlock(&mm->page_table_lock);
|
|
|
|
return (pmd_t *)ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pmd_t *__alloc_for_pmdcache(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
void *ret = NULL;
|
|
|
|
struct page *page;
|
|
|
|
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO;
|
|
|
|
|
|
|
|
if (mm == &init_mm)
|
|
|
|
gfp &= ~__GFP_ACCOUNT;
|
|
|
|
page = alloc_page(gfp);
|
|
|
|
if (!page)
|
|
|
|
return NULL;
|
|
|
|
if (!pgtable_pmd_page_ctor(page)) {
|
|
|
|
__free_pages(page, 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-27 18:48:17 +07:00
|
|
|
atomic_set(&page->pt_frag_refcount, 1);
|
|
|
|
|
2018-04-16 18:27:22 +07:00
|
|
|
ret = page_address(page);
|
|
|
|
/*
|
|
|
|
* if we support only one fragment just return the
|
|
|
|
* allocated page.
|
|
|
|
*/
|
|
|
|
if (PMD_FRAG_NR == 1)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
spin_lock(&mm->page_table_lock);
|
|
|
|
/*
|
|
|
|
* If we find pgtable_page set, we return
|
|
|
|
* the allocated page with single fragement
|
|
|
|
* count.
|
|
|
|
*/
|
|
|
|
if (likely(!mm->context.pmd_frag)) {
|
2018-07-27 18:48:17 +07:00
|
|
|
atomic_set(&page->pt_frag_refcount, PMD_FRAG_NR);
|
2018-04-16 18:27:22 +07:00
|
|
|
mm->context.pmd_frag = ret + PMD_FRAG_SIZE;
|
|
|
|
}
|
|
|
|
spin_unlock(&mm->page_table_lock);
|
|
|
|
|
|
|
|
return (pmd_t *)ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmd_t *pmd_fragment_alloc(struct mm_struct *mm, unsigned long vmaddr)
|
|
|
|
{
|
|
|
|
pmd_t *pmd;
|
|
|
|
|
|
|
|
pmd = get_pmd_from_cache(mm);
|
|
|
|
if (pmd)
|
|
|
|
return pmd;
|
|
|
|
|
|
|
|
return __alloc_for_pmdcache(mm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pmd_fragment_free(unsigned long *pmd)
|
|
|
|
{
|
|
|
|
struct page *page = virt_to_page(pmd);
|
|
|
|
|
2018-07-27 18:48:17 +07:00
|
|
|
BUG_ON(atomic_read(&page->pt_frag_refcount) <= 0);
|
|
|
|
if (atomic_dec_and_test(&page->pt_frag_refcount)) {
|
2018-04-16 18:27:22 +07:00
|
|
|
pgtable_pmd_page_dtor(page);
|
2018-07-27 18:48:17 +07:00
|
|
|
__free_page(page);
|
2018-04-16 18:27:22 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-16 18:27:21 +07:00
|
|
|
static inline void pgtable_free(void *table, int index)
|
|
|
|
{
|
|
|
|
switch (index) {
|
|
|
|
case PTE_INDEX:
|
|
|
|
pte_fragment_free(table, 0);
|
|
|
|
break;
|
|
|
|
case PMD_INDEX:
|
2018-04-16 18:27:23 +07:00
|
|
|
pmd_fragment_free(table);
|
2018-04-16 18:27:21 +07:00
|
|
|
break;
|
|
|
|
case PUD_INDEX:
|
|
|
|
kmem_cache_free(PGT_CACHE(PUD_CACHE_INDEX), table);
|
|
|
|
break;
|
2018-06-14 17:31:52 +07:00
|
|
|
#if defined(CONFIG_PPC_4K_PAGES) && defined(CONFIG_HUGETLB_PAGE)
|
|
|
|
/* 16M hugepd directory at pud level */
|
|
|
|
case HTLB_16M_INDEX:
|
|
|
|
BUILD_BUG_ON(H_16M_CACHE_INDEX <= 0);
|
|
|
|
kmem_cache_free(PGT_CACHE(H_16M_CACHE_INDEX), table);
|
|
|
|
break;
|
|
|
|
/* 16G hugepd directory at the pgd level */
|
|
|
|
case HTLB_16G_INDEX:
|
|
|
|
BUILD_BUG_ON(H_16G_CACHE_INDEX <= 0);
|
|
|
|
kmem_cache_free(PGT_CACHE(H_16G_CACHE_INDEX), table);
|
|
|
|
break;
|
|
|
|
#endif
|
2018-04-16 18:27:21 +07:00
|
|
|
/* We don't free pgd table via RCU callback */
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-16 18:27:19 +07:00
|
|
|
#ifdef CONFIG_SMP
|
2018-04-16 18:27:21 +07:00
|
|
|
void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int index)
|
2018-04-16 18:27:19 +07:00
|
|
|
{
|
|
|
|
unsigned long pgf = (unsigned long)table;
|
|
|
|
|
2018-04-16 18:27:21 +07:00
|
|
|
BUG_ON(index > MAX_PGTABLE_INDEX_SIZE);
|
|
|
|
pgf |= index;
|
2018-04-16 18:27:19 +07:00
|
|
|
tlb_remove_table(tlb, (void *)pgf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __tlb_remove_table(void *_table)
|
|
|
|
{
|
|
|
|
void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
|
2018-04-16 18:27:21 +07:00
|
|
|
unsigned int index = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
|
2018-04-16 18:27:19 +07:00
|
|
|
|
2018-04-16 18:27:21 +07:00
|
|
|
return pgtable_free(table, index);
|
2018-04-16 18:27:19 +07:00
|
|
|
}
|
|
|
|
#else
|
2018-04-16 18:27:21 +07:00
|
|
|
void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int index)
|
2018-04-16 18:27:19 +07:00
|
|
|
{
|
2018-04-16 18:27:21 +07:00
|
|
|
return pgtable_free(table, index);
|
2018-04-16 18:27:19 +07:00
|
|
|
}
|
|
|
|
#endif
|
2018-08-13 12:44:57 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
atomic_long_t direct_pages_count[MMU_PAGE_COUNT];
|
|
|
|
|
|
|
|
void arch_report_meminfo(struct seq_file *m)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Hash maps the memory with one size mmu_linear_psize.
|
|
|
|
* So don't bother to print these on hash
|
|
|
|
*/
|
|
|
|
if (!radix_enabled())
|
|
|
|
return;
|
|
|
|
seq_printf(m, "DirectMap4k: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[MMU_PAGE_4K]) << 2);
|
|
|
|
seq_printf(m, "DirectMap64k: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[MMU_PAGE_64K]) << 6);
|
|
|
|
seq_printf(m, "DirectMap2M: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[MMU_PAGE_2M]) << 11);
|
|
|
|
seq_printf(m, "DirectMap1G: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[MMU_PAGE_1G]) << 20);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
2019-01-23 13:21:38 +07:00
|
|
|
|
2019-03-06 06:46:33 +07:00
|
|
|
pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr,
|
|
|
|
pte_t *ptep)
|
|
|
|
{
|
|
|
|
unsigned long pte_val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the _PAGE_PRESENT so that no hardware parallel update is
|
|
|
|
* possible. Also keep the pte_present true so that we don't take
|
|
|
|
* wrong fault.
|
|
|
|
*/
|
|
|
|
pte_val = pte_update(vma->vm_mm, addr, ptep, _PAGE_PRESENT, _PAGE_INVALID, 0);
|
|
|
|
|
|
|
|
return __pte(pte_val);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr,
|
|
|
|
pte_t *ptep, pte_t old_pte, pte_t pte)
|
|
|
|
{
|
|
|
|
if (radix_enabled())
|
|
|
|
return radix__ptep_modify_prot_commit(vma, addr,
|
|
|
|
ptep, old_pte, pte);
|
|
|
|
set_pte_at(vma->vm_mm, addr, ptep, pte);
|
|
|
|
}
|
|
|
|
|
2019-01-23 13:21:38 +07:00
|
|
|
/*
|
|
|
|
* For hash translation mode, we use the deposited table to store hash slot
|
|
|
|
* information and they are stored at PTRS_PER_PMD offset from related pmd
|
|
|
|
* location. Hence a pmd move requires deposit and withdraw.
|
|
|
|
*
|
|
|
|
* For radix translation with split pmd ptl, we store the deposited table in the
|
|
|
|
* pmd page. Hence if we have different pmd page we need to withdraw during pmd
|
|
|
|
* move.
|
|
|
|
*
|
|
|
|
* With hash we use deposited table always irrespective of anon or not.
|
|
|
|
* With radix we use deposited table only for anonymous mapping.
|
|
|
|
*/
|
|
|
|
int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
|
|
|
|
struct spinlock *old_pmd_ptl,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
if (radix_enabled())
|
|
|
|
return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|