3 * Generic TLB shootdown code
5 * Copyright 2001 Red Hat, Inc.
6 * Based on code from mm/memory.c Copyright Linus Torvalds and others.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 #ifndef _ASM_GENERIC__TLB_H
14 #define _ASM_GENERIC__TLB_H
16 #include <linux/config.h>
19 /* aim for something that fits in the L1 cache */
20 #define FREE_PTE_NR 508
22 /* mmu_gather_t is an opaque type used by the mm code for passing around any
23 * data needed by arch specific code for tlb_remove_page. This structure can
24 * be per-CPU or per-MM as the page table lock is held for the duration of TLB
27 typedef struct free_pte_ctx {
29 unsigned long nr; /* set to ~0UL means fast mode */
30 unsigned long start_addr, end_addr;
31 pte_t ptes[FREE_PTE_NR];
34 /* Users of the generic TLB shootdown code must declare this storage space. */
35 extern mmu_gather_t mmu_gathers[NR_CPUS];
38 * Return a pointer to an initialized mmu_gather_t.
40 static inline mmu_gather_t *tlb_gather_mmu(struct mm_struct *mm)
42 mmu_gather_t *tlb = &mmu_gathers[smp_processor_id()];
45 /* Use fast mode if there is only one user of this mm (this process) */
46 tlb->nr = (atomic_read(&(mm)->mm_users) == 1) ? ~0UL : 0UL;
50 /* void tlb_remove_page(mmu_gather_t *tlb, pte_t *ptep, unsigned long addr)
51 * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)), while
52 * handling the additional races in SMP caused by other CPUs caching valid
53 * mappings in their TLBs.
55 #define tlb_remove_page(ctxp, pte, addr) do {\
56 /* Handle the common case fast, first. */\
57 if ((ctxp)->nr == ~0UL) {\
58 pte_t __pte = *(pte);\
64 (ctxp)->start_addr = (addr);\
65 (ctxp)->ptes[(ctxp)->nr++] = ptep_get_and_clear(pte);\
66 (ctxp)->end_addr = (addr) + PAGE_SIZE;\
67 if ((ctxp)->nr >= FREE_PTE_NR)\
68 tlb_finish_mmu((ctxp), 0, 0);\
72 * Called at the end of the shootdown operation to free up any resources
73 * that were required. The page talbe lock is still held at this point.
75 static inline void tlb_finish_mmu(struct free_pte_ctx *ctx, unsigned long start, unsigned long end)
79 /* Handle the fast case first. */
80 if (ctx->nr == ~0UL) {
81 flush_tlb_range(ctx->mm, start, end);
87 flush_tlb_range(ctx->mm, ctx->start_addr, ctx->end_addr);
88 for (i=0; i < nr; i++) {
89 pte_t pte = ctx->ptes[i];
96 /* The uniprocessor functions are quite simple and are inline macros in an
97 * attempt to get gcc to generate optimal code since this code is run on each
98 * page in a process at exit.
100 typedef struct mm_struct mmu_gather_t;
102 #define tlb_gather_mmu(mm) (mm)
103 #define tlb_finish_mmu(tlb, start, end) flush_tlb_range(tlb, start, end)
104 #define tlb_remove_page(tlb, ptep, addr) do {\
105 pte_t __pte = *(ptep);\
113 #endif /* _ASM_GENERIC__TLB_H */