Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * This file contains the routines for TLB flushing.
0004  * On machines where the MMU uses a hash table to store virtual to
0005  * physical translations, these routines flush entries from the
0006  * hash table also.
0007  *  -- paulus
0008  *
0009  *  Derived from arch/ppc/mm/init.c:
0010  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
0011  *
0012  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
0013  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
0014  *    Copyright (C) 1996 Paul Mackerras
0015  *
0016  *  Derived from "arch/i386/mm/init.c"
0017  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
0018  */
0019 
0020 #include <linux/kernel.h>
0021 #include <linux/mm.h>
0022 #include <linux/init.h>
0023 #include <linux/highmem.h>
0024 #include <linux/pagemap.h>
0025 #include <linux/export.h>
0026 
0027 #include <asm/tlbflush.h>
0028 #include <asm/tlb.h>
0029 
0030 #include <mm/mmu_decl.h>
0031 
0032 /*
0033  * TLB flushing:
0034  *
0035  *  - flush_tlb_mm(mm) flushes the specified mm context TLB's
0036  *  - flush_tlb_page(vma, vmaddr) flushes one page
0037  *  - flush_tlb_range(vma, start, end) flushes a range of pages
0038  *  - flush_tlb_kernel_range(start, end) flushes kernel pages
0039  *
0040  * since the hardware hash table functions as an extension of the
0041  * tlb as far as the linux tables are concerned, flush it too.
0042  *    -- Cort
0043  */
0044 
0045 /*
0046  * For each address in the range, find the pte for the address
0047  * and check _PAGE_HASHPTE bit; if it is set, find and destroy
0048  * the corresponding HPTE.
0049  */
0050 void hash__flush_range(struct mm_struct *mm, unsigned long start, unsigned long end)
0051 {
0052     pmd_t *pmd;
0053     unsigned long pmd_end;
0054     int count;
0055     unsigned int ctx = mm->context.id;
0056 
0057     start &= PAGE_MASK;
0058     if (start >= end)
0059         return;
0060     end = (end - 1) | ~PAGE_MASK;
0061     pmd = pmd_off(mm, start);
0062     for (;;) {
0063         pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;
0064         if (pmd_end > end)
0065             pmd_end = end;
0066         if (!pmd_none(*pmd)) {
0067             count = ((pmd_end - start) >> PAGE_SHIFT) + 1;
0068             flush_hash_pages(ctx, start, pmd_val(*pmd), count);
0069         }
0070         if (pmd_end == end)
0071             break;
0072         start = pmd_end + 1;
0073         ++pmd;
0074     }
0075 }
0076 EXPORT_SYMBOL(hash__flush_range);
0077 
0078 /*
0079  * Flush all the (user) entries for the address space described by mm.
0080  */
0081 void hash__flush_tlb_mm(struct mm_struct *mm)
0082 {
0083     struct vm_area_struct *mp;
0084 
0085     /*
0086      * It is safe to go down the mm's list of vmas when called
0087      * from dup_mmap, holding mmap_lock.  It would also be safe from
0088      * unmap_region or exit_mmap, but not from vmtruncate on SMP -
0089      * but it seems dup_mmap is the only SMP case which gets here.
0090      */
0091     for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
0092         hash__flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
0093 }
0094 EXPORT_SYMBOL(hash__flush_tlb_mm);
0095 
0096 void hash__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
0097 {
0098     struct mm_struct *mm;
0099     pmd_t *pmd;
0100 
0101     mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;
0102     pmd = pmd_off(mm, vmaddr);
0103     if (!pmd_none(*pmd))
0104         flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);
0105 }
0106 EXPORT_SYMBOL(hash__flush_tlb_page);