// SPDX-License-Identifier: GPL-2.0-or-later1/*2* This file contains the routines for TLB flushing.3* On machines where the MMU uses a hash table to store virtual to4* physical translations, these routines flush entries from the5* hash table also.6* -- paulus7*8* Derived from arch/ppc/mm/init.c:9* Copyright (C) 1995-1996 Gary Thomas ([email protected])10*11* Modifications by Paul Mackerras (PowerMac) ([email protected])12* and Cort Dougan (PReP) ([email protected])13* Copyright (C) 1996 Paul Mackerras14*15* Derived from "arch/i386/mm/init.c"16* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds17*/1819#include <linux/kernel.h>20#include <linux/mm.h>21#include <linux/init.h>22#include <linux/highmem.h>23#include <linux/pagemap.h>24#include <linux/export.h>2526#include <asm/tlbflush.h>27#include <asm/tlb.h>2829#include <mm/mmu_decl.h>3031/*32* TLB flushing:33*34* - flush_tlb_mm(mm) flushes the specified mm context TLB's35* - flush_tlb_page(vma, vmaddr) flushes one page36* - flush_tlb_range(vma, start, end) flushes a range of pages37* - flush_tlb_kernel_range(start, end) flushes kernel pages38*39* since the hardware hash table functions as an extension of the40* tlb as far as the linux tables are concerned, flush it too.41* -- Cort42*/4344/*45* For each address in the range, find the pte for the address46* and check _PAGE_HASHPTE bit; if it is set, find and destroy47* the corresponding HPTE.48*/49void hash__flush_range(struct mm_struct *mm, unsigned long start, unsigned long end)50{51pmd_t *pmd;52unsigned long pmd_end;53int count;54unsigned int ctx = mm->context.id;5556start &= PAGE_MASK;57if (start >= end)58return;59end = (end - 1) | ~PAGE_MASK;60pmd = pmd_off(mm, start);61for (;;) {62pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;63if (pmd_end > end)64pmd_end = end;65if (!pmd_none(*pmd)) {66count = ((pmd_end - start) >> PAGE_SHIFT) + 1;67flush_hash_pages(ctx, start, pmd_val(*pmd), count);68}69if (pmd_end == end)70break;71start = pmd_end + 1;72++pmd;73}74}75EXPORT_SYMBOL(hash__flush_range);7677/*78* Flush all the (user) entries for the address space described by mm.79*/80void hash__flush_tlb_mm(struct mm_struct *mm)81{82struct vm_area_struct *mp;83VMA_ITERATOR(vmi, mm, 0);8485/*86* It is safe to iterate the vmas when called from dup_mmap,87* holding mmap_lock. It would also be safe from unmap_region88* or exit_mmap, but not from vmtruncate on SMP - but it seems89* dup_mmap is the only SMP case which gets here.90*/91for_each_vma(vmi, mp)92hash__flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);93}94EXPORT_SYMBOL(hash__flush_tlb_mm);9596void hash__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)97{98struct mm_struct *mm;99pmd_t *pmd;100101mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;102pmd = pmd_off(mm, vmaddr);103if (!pmd_none(*pmd))104flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);105}106EXPORT_SYMBOL(hash__flush_tlb_page);107108109