mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-22 15:22:57 +07:00
5694cecdb0
In the end, we ended up with quite a lot more than I expected: - Support for ARMv8.3 Pointer Authentication in userspace (CRIU and kernel-side support to come later) - Support for per-thread stack canaries, pending an update to GCC that is currently undergoing review - Support for kexec_file_load(), which permits secure boot of a kexec payload but also happens to improve the performance of kexec dramatically because we can avoid the sucky purgatory code from userspace. Kdump will come later (requires updates to libfdt). - Optimisation of our dynamic CPU feature framework, so that all detected features are enabled via a single stop_machine() invocation - KPTI whitelisting of Cortex-A CPUs unaffected by Meltdown, so that they can benefit from global TLB entries when KASLR is not in use - 52-bit virtual addressing for userspace (kernel remains 48-bit) - Patch in LSE atomics for per-cpu atomic operations - Custom preempt.h implementation to avoid unconditional calls to preempt_schedule() from preempt_enable() - Support for the new 'SB' Speculation Barrier instruction - Vectorised implementation of XOR checksumming and CRC32 optimisations - Workaround for Cortex-A76 erratum #1165522 - Improved compatibility with Clang/LLD - Support for TX2 system PMUS for profiling the L3 cache and DMC - Reflect read-only permissions in the linear map by default - Ensure MMIO reads are ordered with subsequent calls to Xdelay() - Initial support for memory hotplug - Tweak the threshold when we invalidate the TLB by-ASID, so that mremap() performance is improved for ranges spanning multiple PMDs. - Minor refactoring and cleanups -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABCgAGBQJcE4TmAAoJELescNyEwWM0Nr0H/iaU7/wQSzHyNXtZoImyKTul Blu2ga4/EqUrTU7AVVfmkl/3NBILWlgQVpY6tH6EfXQuvnxqD7CizbHyLdyO+z0S B5PsFUH2GLMNAi48AUNqGqkgb2knFbg+T+9IimijDBkKg1G/KhQnRg6bXX32mLJv Une8oshUPBVJMsHN1AcQknzKariuoE3u0SgJ+eOZ9yA2ZwKxP4yy1SkDt3xQrtI0 lojeRjxcyjTP1oGRNZC+BWUtGOT35p7y6cGTnBd/4TlqBGz5wVAJUcdoxnZ6JYVR O8+ob9zU+4I0+SKt80s7pTLqQiL9rxkKZ5joWK1pr1g9e0s5N5yoETXKFHgJYP8= =sYdt -----END PGP SIGNATURE----- Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux Pull arm64 festive updates from Will Deacon: "In the end, we ended up with quite a lot more than I expected: - Support for ARMv8.3 Pointer Authentication in userspace (CRIU and kernel-side support to come later) - Support for per-thread stack canaries, pending an update to GCC that is currently undergoing review - Support for kexec_file_load(), which permits secure boot of a kexec payload but also happens to improve the performance of kexec dramatically because we can avoid the sucky purgatory code from userspace. Kdump will come later (requires updates to libfdt). - Optimisation of our dynamic CPU feature framework, so that all detected features are enabled via a single stop_machine() invocation - KPTI whitelisting of Cortex-A CPUs unaffected by Meltdown, so that they can benefit from global TLB entries when KASLR is not in use - 52-bit virtual addressing for userspace (kernel remains 48-bit) - Patch in LSE atomics for per-cpu atomic operations - Custom preempt.h implementation to avoid unconditional calls to preempt_schedule() from preempt_enable() - Support for the new 'SB' Speculation Barrier instruction - Vectorised implementation of XOR checksumming and CRC32 optimisations - Workaround for Cortex-A76 erratum #1165522 - Improved compatibility with Clang/LLD - Support for TX2 system PMUS for profiling the L3 cache and DMC - Reflect read-only permissions in the linear map by default - Ensure MMIO reads are ordered with subsequent calls to Xdelay() - Initial support for memory hotplug - Tweak the threshold when we invalidate the TLB by-ASID, so that mremap() performance is improved for ranges spanning multiple PMDs. - Minor refactoring and cleanups" * tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (125 commits) arm64: kaslr: print PHYS_OFFSET in dump_kernel_offset() arm64: sysreg: Use _BITUL() when defining register bits arm64: cpufeature: Rework ptr auth hwcaps using multi_entry_cap_matches arm64: cpufeature: Reduce number of pointer auth CPU caps from 6 to 4 arm64: docs: document pointer authentication arm64: ptr auth: Move per-thread keys from thread_info to thread_struct arm64: enable pointer authentication arm64: add prctl control for resetting ptrauth keys arm64: perf: strip PAC when unwinding userspace arm64: expose user PAC bit positions via ptrace arm64: add basic pointer authentication support arm64/cpufeature: detect pointer authentication arm64: Don't trap host pointer auth use to EL2 arm64/kvm: hide ptrauth from guests arm64/kvm: consistently handle host HCR_EL2 flags arm64: add pointer authentication register bits arm64: add comments about EC exception levels arm64: perf: Treat EXCLUDE_EL* bit definitions as unsigned arm64: kpti: Whitelist Cortex-A CPUs that don't implement the CSV3 field arm64: enable per-task stack canaries ...
266 lines
7.5 KiB
C
266 lines
7.5 KiB
C
/*
|
|
* 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__
|
|
|
|
#include <linux/mm_types.h>
|
|
#include <linux/sched.h>
|
|
#include <asm/cputype.h>
|
|
#include <asm/mmu.h>
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
#define __TLBI_0(op, arg) asm ("tlbi " #op "\n" \
|
|
ALTERNATIVE("nop\n nop", \
|
|
"dsb ish\n tlbi " #op, \
|
|
ARM64_WORKAROUND_REPEAT_TLBI, \
|
|
CONFIG_ARM64_WORKAROUND_REPEAT_TLBI) \
|
|
: : )
|
|
|
|
#define __TLBI_1(op, arg) asm ("tlbi " #op ", %0\n" \
|
|
ALTERNATIVE("nop\n nop", \
|
|
"dsb ish\n tlbi " #op ", %0", \
|
|
ARM64_WORKAROUND_REPEAT_TLBI, \
|
|
CONFIG_ARM64_WORKAROUND_REPEAT_TLBI) \
|
|
: : "r" (arg))
|
|
|
|
#define __TLBI_N(op, arg, n, ...) __TLBI_##n(op, arg)
|
|
|
|
#define __tlbi(op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)
|
|
|
|
#define __tlbi_user(op, arg) do { \
|
|
if (arm64_kernel_unmapped_at_el0()) \
|
|
__tlbi(op, (arg) | USER_ASID_FLAG); \
|
|
} while (0)
|
|
|
|
/* 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; \
|
|
})
|
|
|
|
/*
|
|
* TLB Invalidation
|
|
* ================
|
|
*
|
|
* This header file implements the low-level TLB invalidation routines
|
|
* (sometimes referred to as "flushing" in the kernel) for arm64.
|
|
*
|
|
* Every invalidation operation uses the following template:
|
|
*
|
|
* 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
|
|
*
|
|
*
|
|
* The following functions form part of the "core" TLB invalidation API,
|
|
* as documented in Documentation/core-api/cachetlb.rst:
|
|
*
|
|
* flush_tlb_all()
|
|
* Invalidate the entire TLB (kernel + user) on all CPUs
|
|
*
|
|
* 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.
|
|
*/
|
|
static inline void local_flush_tlb_all(void)
|
|
{
|
|
dsb(nshst);
|
|
__tlbi(vmalle1);
|
|
dsb(nsh);
|
|
isb();
|
|
}
|
|
|
|
static inline void flush_tlb_all(void)
|
|
{
|
|
dsb(ishst);
|
|
__tlbi(vmalle1is);
|
|
dsb(ish);
|
|
isb();
|
|
}
|
|
|
|
static inline void flush_tlb_mm(struct mm_struct *mm)
|
|
{
|
|
unsigned long asid = __TLBI_VADDR(0, ASID(mm));
|
|
|
|
dsb(ishst);
|
|
__tlbi(aside1is, asid);
|
|
__tlbi_user(aside1is, asid);
|
|
dsb(ish);
|
|
}
|
|
|
|
static inline void flush_tlb_page_nosync(struct vm_area_struct *vma,
|
|
unsigned long uaddr)
|
|
{
|
|
unsigned long addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm));
|
|
|
|
dsb(ishst);
|
|
__tlbi(vale1is, addr);
|
|
__tlbi_user(vale1is, addr);
|
|
}
|
|
|
|
static inline void flush_tlb_page(struct vm_area_struct *vma,
|
|
unsigned long uaddr)
|
|
{
|
|
flush_tlb_page_nosync(vma, uaddr);
|
|
dsb(ish);
|
|
}
|
|
|
|
/*
|
|
* This is meant to avoid soft lock-ups on large TLB flushing ranges and not
|
|
* necessarily a performance improvement.
|
|
*/
|
|
#define MAX_TLBI_OPS PTRS_PER_PTE
|
|
|
|
static inline void __flush_tlb_range(struct vm_area_struct *vma,
|
|
unsigned long start, unsigned long end,
|
|
unsigned long stride, bool last_level)
|
|
{
|
|
unsigned long asid = ASID(vma->vm_mm);
|
|
unsigned long addr;
|
|
|
|
if ((end - start) >= (MAX_TLBI_OPS * stride)) {
|
|
flush_tlb_mm(vma->vm_mm);
|
|
return;
|
|
}
|
|
|
|
/* Convert the stride into units of 4k */
|
|
stride >>= 12;
|
|
|
|
start = __TLBI_VADDR(start, asid);
|
|
end = __TLBI_VADDR(end, asid);
|
|
|
|
dsb(ishst);
|
|
for (addr = start; addr < end; addr += stride) {
|
|
if (last_level) {
|
|
__tlbi(vale1is, addr);
|
|
__tlbi_user(vale1is, addr);
|
|
} else {
|
|
__tlbi(vae1is, addr);
|
|
__tlbi_user(vae1is, addr);
|
|
}
|
|
}
|
|
dsb(ish);
|
|
}
|
|
|
|
static inline void flush_tlb_range(struct vm_area_struct *vma,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
/*
|
|
* We cannot use leaf-only invalidation here, since we may be invalidating
|
|
* table entries as part of collapsing hugepages or moving page tables.
|
|
*/
|
|
__flush_tlb_range(vma, start, end, PAGE_SIZE, false);
|
|
}
|
|
|
|
static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
|
|
{
|
|
unsigned long addr;
|
|
|
|
if ((end - start) > (MAX_TLBI_OPS * PAGE_SIZE)) {
|
|
flush_tlb_all();
|
|
return;
|
|
}
|
|
|
|
start = __TLBI_VADDR(start, 0);
|
|
end = __TLBI_VADDR(end, 0);
|
|
|
|
dsb(ishst);
|
|
for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
|
|
__tlbi(vaale1is, addr);
|
|
dsb(ish);
|
|
isb();
|
|
}
|
|
|
|
/*
|
|
* Used to invalidate the TLB (walk caches) corresponding to intermediate page
|
|
* table levels (pgd/pud/pmd).
|
|
*/
|
|
static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)
|
|
{
|
|
unsigned long addr = __TLBI_VADDR(kaddr, 0);
|
|
|
|
dsb(ishst);
|
|
__tlbi(vaae1is, addr);
|
|
dsb(ish);
|
|
}
|
|
#endif
|
|
|
|
#endif
|