2012-03-05 11:49:28 +00:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/include/asm/tlbflush.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2003 Russell King
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_TLBFLUSH_H
|
|
|
|
#define __ASM_TLBFLUSH_H
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2018-10-29 09:25:58 +00:00
|
|
|
#include <linux/mm_types.h>
|
2012-03-05 11:49:28 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <asm/cputype.h>
|
2017-08-10 13:13:33 +00:00
|
|
|
#include <asm/mmu.h>
|
2012-03-05 11:49:28 +00:00
|
|
|
|
2016-09-13 10:16:06 +00:00
|
|
|
/*
|
|
|
|
* Raw TLBI operations.
|
|
|
|
*
|
|
|
|
* Where necessary, use the __tlbi() macro to avoid asm()
|
|
|
|
* boilerplate. Drivers and most kernel code should use the TLB
|
|
|
|
* management routines in preference to the macro below.
|
|
|
|
*
|
|
|
|
* The macro can be used as __tlbi(op) or __tlbi(op, arg), depending
|
|
|
|
* on whether a particular TLBI operation takes an argument or
|
|
|
|
* not. The macros handles invoking the asm with or without the
|
|
|
|
* register argument as appropriate.
|
|
|
|
*/
|
2017-01-31 17:50:19 +00:00
|
|
|
#define __TLBI_0(op, arg) asm ("tlbi " #op "\n" \
|
|
|
|
ALTERNATIVE("nop\n nop", \
|
|
|
|
"dsb ish\n tlbi " #op, \
|
|
|
|
ARM64_WORKAROUND_REPEAT_TLBI, \
|
2018-11-19 11:27:28 +00:00
|
|
|
CONFIG_ARM64_WORKAROUND_REPEAT_TLBI) \
|
2017-01-31 17:50:19 +00:00
|
|
|
: : )
|
|
|
|
|
|
|
|
#define __TLBI_1(op, arg) asm ("tlbi " #op ", %0\n" \
|
|
|
|
ALTERNATIVE("nop\n nop", \
|
|
|
|
"dsb ish\n tlbi " #op ", %0", \
|
|
|
|
ARM64_WORKAROUND_REPEAT_TLBI, \
|
2018-11-19 11:27:28 +00:00
|
|
|
CONFIG_ARM64_WORKAROUND_REPEAT_TLBI) \
|
2017-01-31 17:50:19 +00:00
|
|
|
: : "r" (arg))
|
|
|
|
|
|
|
|
#define __TLBI_N(op, arg, n, ...) __TLBI_##n(op, arg)
|
2016-09-13 10:16:06 +00:00
|
|
|
|
|
|
|
#define __tlbi(op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)
|
|
|
|
|
2017-08-10 13:13:33 +00:00
|
|
|
#define __tlbi_user(op, arg) do { \
|
|
|
|
if (arm64_kernel_unmapped_at_el0()) \
|
|
|
|
__tlbi(op, (arg) | USER_ASID_FLAG); \
|
|
|
|
} while (0)
|
|
|
|
|
2018-03-28 01:55:32 +00:00
|
|
|
/* This macro creates a properly formatted VA operand for the TLBI */
|
|
|
|
#define __TLBI_VADDR(addr, asid) \
|
|
|
|
({ \
|
|
|
|
unsigned long __ta = (addr) >> 12; \
|
|
|
|
__ta &= GENMASK_ULL(43, 0); \
|
|
|
|
__ta |= (unsigned long)(asid) << 48; \
|
|
|
|
__ta; \
|
|
|
|
})
|
|
|
|
|
2012-03-05 11:49:28 +00:00
|
|
|
/*
|
2018-08-28 13:52:17 +00:00
|
|
|
* TLB Invalidation
|
|
|
|
* ================
|
2012-03-05 11:49:28 +00:00
|
|
|
*
|
2018-08-28 13:52:17 +00:00
|
|
|
* This header file implements the low-level TLB invalidation routines
|
|
|
|
* (sometimes referred to as "flushing" in the kernel) for arm64.
|
2012-03-05 11:49:28 +00:00
|
|
|
*
|
2018-08-28 13:52:17 +00:00
|
|
|
* Every invalidation operation uses the following template:
|
2012-03-05 11:49:28 +00:00
|
|
|
*
|
2018-08-28 13:52:17 +00:00
|
|
|
* DSB ISHST // Ensure prior page-table updates have completed
|
|
|
|
* TLBI ... // Invalidate the TLB
|
|
|
|
* DSB ISH // Ensure the TLB invalidation has completed
|
|
|
|
* if (invalidated kernel mappings)
|
|
|
|
* ISB // Discard any instructions fetched from the old mapping
|
2012-03-05 11:49:28 +00:00
|
|
|
*
|
|
|
|
*
|
2018-08-28 13:52:17 +00:00
|
|
|
* The following functions form part of the "core" TLB invalidation API,
|
|
|
|
* as documented in Documentation/core-api/cachetlb.rst:
|
2012-03-05 11:49:28 +00:00
|
|
|
*
|
2018-08-28 13:52:17 +00:00
|
|
|
* flush_tlb_all()
|
|
|
|
* Invalidate the entire TLB (kernel + user) on all CPUs
|
2012-03-05 11:49:28 +00:00
|
|
|
*
|
2018-08-28 13:52:17 +00:00
|
|
|
* flush_tlb_mm(mm)
|
|
|
|
* Invalidate an entire user address space on all CPUs.
|
|
|
|
* The 'mm' argument identifies the ASID to invalidate.
|
|
|
|
*
|
|
|
|
* flush_tlb_range(vma, start, end)
|
|
|
|
* Invalidate the virtual-address range '[start, end)' on all
|
|
|
|
* CPUs for the user address space corresponding to 'vma->mm'.
|
|
|
|
* Note that this operation also invalidates any walk-cache
|
|
|
|
* entries associated with translations for the specified address
|
|
|
|
* range.
|
|
|
|
*
|
|
|
|
* flush_tlb_kernel_range(start, end)
|
|
|
|
* Same as flush_tlb_range(..., start, end), but applies to
|
|
|
|
* kernel mappings rather than a particular user address space.
|
|
|
|
* Whilst not explicitly documented, this function is used when
|
|
|
|
* unmapping pages from vmalloc/io space.
|
|
|
|
*
|
|
|
|
* flush_tlb_page(vma, addr)
|
|
|
|
* Invalidate a single user mapping for address 'addr' in the
|
|
|
|
* address space corresponding to 'vma->mm'. Note that this
|
|
|
|
* operation only invalidates a single, last-level page-table
|
|
|
|
* entry and therefore does not affect any walk-caches.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Next, we have some undocumented invalidation routines that you probably
|
|
|
|
* don't want to call unless you know what you're doing:
|
|
|
|
*
|
|
|
|
* local_flush_tlb_all()
|
|
|
|
* Same as flush_tlb_all(), but only applies to the calling CPU.
|
|
|
|
*
|
|
|
|
* __flush_tlb_kernel_pgtable(addr)
|
|
|
|
* Invalidate a single kernel mapping for address 'addr' on all
|
|
|
|
* CPUs, ensuring that any walk-cache entries associated with the
|
|
|
|
* translation are also invalidated.
|
|
|
|
*
|
|
|
|
* __flush_tlb_range(vma, start, end, stride, last_level)
|
|
|
|
* Invalidate the virtual-address range '[start, end)' on all
|
|
|
|
* CPUs for the user address space corresponding to 'vma->mm'.
|
|
|
|
* The invalidation operations are issued at a granularity
|
|
|
|
* determined by 'stride' and only affect any walk-cache entries
|
|
|
|
* if 'last_level' is equal to false.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Finally, take a look at asm/tlb.h to see how tlb_flush() is implemented
|
|
|
|
* on top of these routines, since that is our interface to the mmu_gather
|
|
|
|
* API as used by munmap() and friends.
|
2012-03-05 11:49:28 +00:00
|
|
|
*/
|
2015-10-06 17:46:23 +00:00
|
|
|
static inline void local_flush_tlb_all(void)
|
|
|
|
{
|
|
|
|
dsb(nshst);
|
2016-09-13 10:16:06 +00:00
|
|
|
__tlbi(vmalle1);
|
2015-10-06 17:46:23 +00:00
|
|
|
dsb(nsh);
|
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:28 +00:00
|
|
|
static inline void flush_tlb_all(void)
|
|
|
|
{
|
2014-05-02 15:24:10 +00:00
|
|
|
dsb(ishst);
|
2016-09-13 10:16:06 +00:00
|
|
|
__tlbi(vmalle1is);
|
2014-05-02 15:24:10 +00:00
|
|
|
dsb(ish);
|
2012-03-05 11:49:28 +00:00
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flush_tlb_mm(struct mm_struct *mm)
|
|
|
|
{
|
2018-03-28 01:55:32 +00:00
|
|
|
unsigned long asid = __TLBI_VADDR(0, ASID(mm));
|
2012-03-05 11:49:28 +00:00
|
|
|
|
2014-05-02 15:24:10 +00:00
|
|
|
dsb(ishst);
|
2016-09-13 10:16:06 +00:00
|
|
|
__tlbi(aside1is, asid);
|
2017-08-10 13:13:33 +00:00
|
|
|
__tlbi_user(aside1is, asid);
|
2014-05-02 15:24:10 +00:00
|
|
|
dsb(ish);
|
2012-03-05 11:49:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 09:25:58 +00:00
|
|
|
static inline void flush_tlb_page_nosync(struct vm_area_struct *vma,
|
|
|
|
unsigned long uaddr)
|
2012-03-05 11:49:28 +00:00
|
|
|
{
|
2018-03-28 01:55:32 +00:00
|
|
|
unsigned long addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm));
|
2012-03-05 11:49:28 +00:00
|
|
|
|
2014-05-02 15:24:10 +00:00
|
|
|
dsb(ishst);
|
2016-09-13 10:16:06 +00:00
|
|
|
__tlbi(vale1is, addr);
|
2017-08-10 13:13:33 +00:00
|
|
|
__tlbi_user(vale1is, addr);
|
2018-10-29 09:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flush_tlb_page(struct vm_area_struct *vma,
|
|
|
|
unsigned long uaddr)
|
|
|
|
{
|
|
|
|
flush_tlb_page_nosync(vma, uaddr);
|
2014-05-02 15:24:10 +00:00
|
|
|
dsb(ish);
|
2012-03-05 11:49:28 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 08:59:55 +00:00
|
|
|
/*
|
|
|
|
* This is meant to avoid soft lock-ups on large TLB flushing ranges and not
|
|
|
|
* necessarily a performance improvement.
|
|
|
|
*/
|
2018-11-19 18:08:49 +00:00
|
|
|
#define MAX_TLBI_OPS PTRS_PER_PTE
|
2015-07-24 08:59:55 +00:00
|
|
|
|
2015-03-18 11:28:06 +00:00
|
|
|
static inline void __flush_tlb_range(struct vm_area_struct *vma,
|
|
|
|
unsigned long start, unsigned long end,
|
2018-08-23 18:26:21 +00:00
|
|
|
unsigned long stride, bool last_level)
|
2014-05-02 13:49:00 +00:00
|
|
|
{
|
2018-03-28 01:55:32 +00:00
|
|
|
unsigned long asid = ASID(vma->vm_mm);
|
2014-05-02 13:49:00 +00:00
|
|
|
unsigned long addr;
|
2015-07-24 08:59:55 +00:00
|
|
|
|
2018-11-19 18:08:49 +00:00
|
|
|
if ((end - start) >= (MAX_TLBI_OPS * stride)) {
|
2015-07-24 08:59:55 +00:00
|
|
|
flush_tlb_mm(vma->vm_mm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-23 18:26:21 +00:00
|
|
|
/* Convert the stride into units of 4k */
|
|
|
|
stride >>= 12;
|
|
|
|
|
2018-03-28 01:55:32 +00:00
|
|
|
start = __TLBI_VADDR(start, asid);
|
|
|
|
end = __TLBI_VADDR(end, asid);
|
2014-05-02 13:49:00 +00:00
|
|
|
|
|
|
|
dsb(ishst);
|
2018-08-23 18:26:21 +00:00
|
|
|
for (addr = start; addr < end; addr += stride) {
|
2017-08-10 13:13:33 +00:00
|
|
|
if (last_level) {
|
2016-09-13 10:16:06 +00:00
|
|
|
__tlbi(vale1is, addr);
|
2017-08-10 13:13:33 +00:00
|
|
|
__tlbi_user(vale1is, addr);
|
|
|
|
} else {
|
2016-09-13 10:16:06 +00:00
|
|
|
__tlbi(vae1is, addr);
|
2017-08-10 13:13:33 +00:00
|
|
|
__tlbi_user(vae1is, addr);
|
|
|
|
}
|
2015-03-18 11:28:06 +00:00
|
|
|
}
|
2014-05-02 13:49:00 +00:00
|
|
|
dsb(ish);
|
|
|
|
}
|
|
|
|
|
2015-03-18 11:28:06 +00:00
|
|
|
static inline void flush_tlb_range(struct vm_area_struct *vma,
|
|
|
|
unsigned long start, unsigned long end)
|
|
|
|
{
|
2018-08-23 18:08:15 +00:00
|
|
|
/*
|
|
|
|
* We cannot use leaf-only invalidation here, since we may be invalidating
|
|
|
|
* table entries as part of collapsing hugepages or moving page tables.
|
|
|
|
*/
|
2018-08-23 18:26:21 +00:00
|
|
|
__flush_tlb_range(vma, start, end, PAGE_SIZE, false);
|
2015-03-18 11:28:06 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 08:59:55 +00:00
|
|
|
static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
|
2014-05-02 13:49:00 +00:00
|
|
|
{
|
|
|
|
unsigned long addr;
|
2015-07-24 08:59:55 +00:00
|
|
|
|
2018-08-23 18:26:21 +00:00
|
|
|
if ((end - start) > (MAX_TLBI_OPS * PAGE_SIZE)) {
|
2015-07-24 08:59:55 +00:00
|
|
|
flush_tlb_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-28 01:55:32 +00:00
|
|
|
start = __TLBI_VADDR(start, 0);
|
|
|
|
end = __TLBI_VADDR(end, 0);
|
2014-05-02 13:49:00 +00:00
|
|
|
|
|
|
|
dsb(ishst);
|
|
|
|
for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
|
2018-08-22 20:23:05 +00:00
|
|
|
__tlbi(vaale1is, addr);
|
2014-05-02 13:49:00 +00:00
|
|
|
dsb(ish);
|
2014-06-09 10:55:03 +00:00
|
|
|
isb();
|
2014-05-02 13:49:00 +00:00
|
|
|
}
|
2012-03-05 11:49:28 +00:00
|
|
|
|
2015-03-11 12:20:39 +00:00
|
|
|
/*
|
|
|
|
* Used to invalidate the TLB (walk caches) corresponding to intermediate page
|
|
|
|
* table levels (pgd/pud/pmd).
|
|
|
|
*/
|
2018-06-06 07:01:20 +00:00
|
|
|
static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)
|
|
|
|
{
|
|
|
|
unsigned long addr = __TLBI_VADDR(kaddr, 0);
|
|
|
|
|
2018-08-22 20:40:30 +00:00
|
|
|
dsb(ishst);
|
2018-06-06 07:01:20 +00:00
|
|
|
__tlbi(vaae1is, addr);
|
|
|
|
dsb(ish);
|
|
|
|
}
|
2012-03-05 11:49:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|