mmu.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_MMU_H
  6. #define __ASM_MMU_H
  7. #include <asm/cputype.h>
  8. #define MMCF_AARCH32 0x1 /* mm context flag for AArch32 executables */
  9. #define USER_ASID_BIT 48
  10. #define USER_ASID_FLAG (UL(1) << USER_ASID_BIT)
  11. #define TTBR_ASID_MASK (UL(0xffff) << 48)
  12. #ifndef __ASSEMBLY__
  13. #include <linux/refcount.h>
  14. #include <asm/cpufeature.h>
  15. typedef struct {
  16. atomic64_t id;
  17. #ifdef CONFIG_COMPAT
  18. void *sigpage;
  19. #endif
  20. refcount_t pinned;
  21. void *vdso;
  22. unsigned long flags;
  23. } mm_context_t;
  24. /*
  25. * We use atomic64_read() here because the ASID for an 'mm_struct' can
  26. * be reallocated when scheduling one of its threads following a
  27. * rollover event (see new_context() and flush_context()). In this case,
  28. * a concurrent TLBI (e.g. via try_to_unmap_one() and ptep_clear_flush())
  29. * may use a stale ASID. This is fine in principle as the new ASID is
  30. * guaranteed to be clean in the TLB, but the TLBI routines have to take
  31. * care to handle the following race:
  32. *
  33. * CPU 0 CPU 1 CPU 2
  34. *
  35. * // ptep_clear_flush(mm)
  36. * xchg_relaxed(pte, 0)
  37. * DSB ISHST
  38. * old = ASID(mm)
  39. * | <rollover>
  40. * | new = new_context(mm)
  41. * \-----------------> atomic_set(mm->context.id, new)
  42. * cpu_switch_mm(mm)
  43. * // Hardware walk of pte using new ASID
  44. * TLBI(old)
  45. *
  46. * In this scenario, the barrier on CPU 0 and the dependency on CPU 1
  47. * ensure that the page-table walker on CPU 1 *must* see the invalid PTE
  48. * written by CPU 0.
  49. */
  50. #define ASID(mm) (atomic64_read(&(mm)->context.id) & 0xffff)
  51. static inline bool arm64_kernel_unmapped_at_el0(void)
  52. {
  53. return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
  54. }
  55. extern void arm64_memblock_init(void);
  56. extern void paging_init(void);
  57. extern void bootmem_init(void);
  58. extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt);
  59. extern void init_mem_pgprot(void);
  60. extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
  61. unsigned long virt, phys_addr_t size,
  62. pgprot_t prot, bool page_mappings_only);
  63. extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
  64. extern void mark_linear_text_alias_ro(void);
  65. extern bool kaslr_requires_kpti(void);
  66. #define INIT_MM_CONTEXT(name) \
  67. .pgd = init_pg_dir,
  68. #endif /* !__ASSEMBLY__ */
  69. #endif