Skip to content

Commit 15397e3

Browse files
ryanhrobctmarinas
authored andcommitted
arm64: mm: Wrap flush_tlb_page() around __do_flush_tlb_range()
Flushing a page from the tlb is just a special case of flushing a range. So let's rework flush_tlb_page() so that it simply wraps __do_flush_tlb_range(). While at it, let's also update the API to take the same flags that we use when flushing a range. This allows us to delete all the ugly "_nosync", "_local" and "_nonotify" variants. Thanks to constant folding, all of the complex looping and tlbi-by-range options get eliminated so that the generated code for flush_tlb_page() looks very similar to the previous version. Reviewed-by: Linu Cherian <linu.cherian@arm.com> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 0477fc5 commit 15397e3

3 files changed

Lines changed: 29 additions & 60 deletions

File tree

arch/arm64/include/asm/pgtable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ static inline void arch_leave_lazy_mmu_mode(void)
101101
* entries exist.
102102
*/
103103
#define flush_tlb_fix_spurious_fault(vma, address, ptep) \
104-
local_flush_tlb_page_nonotify(vma, address)
104+
__flush_tlb_page(vma, address, TLBF_NOBROADCAST | TLBF_NONOTIFY)
105105

106106
#define flush_tlb_fix_spurious_fault_pmd(vma, address, pmdp) \
107-
local_flush_tlb_page_nonotify(vma, address)
107+
__flush_tlb_page(vma, address, TLBF_NOBROADCAST | TLBF_NONOTIFY)
108108

109109
/*
110110
* ZERO_PAGE is a global shared page that is always zero: used
@@ -1320,7 +1320,7 @@ static inline int __ptep_clear_flush_young(struct vm_area_struct *vma,
13201320
* context-switch, which provides a DSB to complete the TLB
13211321
* invalidation.
13221322
*/
1323-
flush_tlb_page_nosync(vma, address);
1323+
__flush_tlb_page(vma, address, TLBF_NOSYNC);
13241324
}
13251325

13261326
return young;

arch/arm64/include/asm/tlbflush.h

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ static inline void __tlbi_sync_s1ish_hyp(void)
269269
* unmapping pages from vmalloc/io space.
270270
*
271271
* flush_tlb_page(vma, addr)
272-
* Invalidate a single user mapping for address 'addr' in the
273-
* address space corresponding to 'vma->mm'. Note that this
274-
* operation only invalidates a single, last-level page-table
275-
* entry and therefore does not affect any walk-caches.
272+
* Equivalent to __flush_tlb_page(..., flags=TLBF_NONE)
276273
*
277274
*
278275
* Next, we have some undocumented invalidation routines that you probably
@@ -300,13 +297,14 @@ static inline void __tlbi_sync_s1ish_hyp(void)
300297
* TLBF_NOSYNC (don't issue trailing dsb) and TLBF_NOBROADCAST
301298
* (only perform the invalidation for the local cpu).
302299
*
303-
* local_flush_tlb_page(vma, addr)
304-
* Local variant of flush_tlb_page(). Stale TLB entries may
305-
* remain in remote CPUs.
306-
*
307-
* local_flush_tlb_page_nonotify(vma, addr)
308-
* Same as local_flush_tlb_page() except MMU notifier will not be
309-
* called.
300+
* __flush_tlb_page(vma, addr, flags)
301+
* Invalidate a single user mapping for address 'addr' in the
302+
* address space corresponding to 'vma->mm'. Note that this
303+
* operation only invalidates a single, last-level page-table entry
304+
* and therefore does not affect any walk-caches. flags may contain
305+
* any combination of TLBF_NONOTIFY (don't call mmu notifiers),
306+
* TLBF_NOSYNC (don't issue trailing dsb) and TLBF_NOBROADCAST
307+
* (only perform the invalidation for the local cpu).
310308
*
311309
* Finally, take a look at asm/tlb.h to see how tlb_flush() is implemented
312310
* on top of these routines, since that is our interface to the mmu_gather
@@ -340,51 +338,6 @@ static inline void flush_tlb_mm(struct mm_struct *mm)
340338
mmu_notifier_arch_invalidate_secondary_tlbs(mm, 0, -1UL);
341339
}
342340

343-
static inline void __local_flush_tlb_page_nonotify_nosync(struct mm_struct *mm,
344-
unsigned long uaddr)
345-
{
346-
dsb(nshst);
347-
__tlbi_level_asid(vale1, uaddr, TLBI_TTL_UNKNOWN, ASID(mm));
348-
}
349-
350-
static inline void local_flush_tlb_page_nonotify(struct vm_area_struct *vma,
351-
unsigned long uaddr)
352-
{
353-
__local_flush_tlb_page_nonotify_nosync(vma->vm_mm, uaddr);
354-
dsb(nsh);
355-
}
356-
357-
static inline void local_flush_tlb_page(struct vm_area_struct *vma,
358-
unsigned long uaddr)
359-
{
360-
__local_flush_tlb_page_nonotify_nosync(vma->vm_mm, uaddr);
361-
mmu_notifier_arch_invalidate_secondary_tlbs(vma->vm_mm, uaddr & PAGE_MASK,
362-
(uaddr & PAGE_MASK) + PAGE_SIZE);
363-
dsb(nsh);
364-
}
365-
366-
static inline void __flush_tlb_page_nosync(struct mm_struct *mm,
367-
unsigned long uaddr)
368-
{
369-
dsb(ishst);
370-
__tlbi_level_asid(vale1is, uaddr, TLBI_TTL_UNKNOWN, ASID(mm));
371-
mmu_notifier_arch_invalidate_secondary_tlbs(mm, uaddr & PAGE_MASK,
372-
(uaddr & PAGE_MASK) + PAGE_SIZE);
373-
}
374-
375-
static inline void flush_tlb_page_nosync(struct vm_area_struct *vma,
376-
unsigned long uaddr)
377-
{
378-
return __flush_tlb_page_nosync(vma->vm_mm, uaddr);
379-
}
380-
381-
static inline void flush_tlb_page(struct vm_area_struct *vma,
382-
unsigned long uaddr)
383-
{
384-
flush_tlb_page_nosync(vma, uaddr);
385-
__tlbi_sync_s1ish();
386-
}
387-
388341
static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm)
389342
{
390343
return true;
@@ -632,6 +585,22 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
632585
__flush_tlb_range(vma, start, end, PAGE_SIZE, TLBI_TTL_UNKNOWN, TLBF_NONE);
633586
}
634587

588+
static inline void __flush_tlb_page(struct vm_area_struct *vma,
589+
unsigned long uaddr, tlbf_t flags)
590+
{
591+
unsigned long start = round_down(uaddr, PAGE_SIZE);
592+
unsigned long end = start + PAGE_SIZE;
593+
594+
__do_flush_tlb_range(vma, start, end, PAGE_SIZE, TLBI_TTL_UNKNOWN,
595+
TLBF_NOWALKCACHE | flags);
596+
}
597+
598+
static inline void flush_tlb_page(struct vm_area_struct *vma,
599+
unsigned long uaddr)
600+
{
601+
__flush_tlb_page(vma, uaddr, TLBF_NONE);
602+
}
603+
635604
static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
636605
{
637606
const unsigned long stride = PAGE_SIZE;

arch/arm64/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int __ptep_set_access_flags(struct vm_area_struct *vma,
239239
* flush_tlb_fix_spurious_fault().
240240
*/
241241
if (dirty)
242-
local_flush_tlb_page(vma, address);
242+
__flush_tlb_page(vma, address, TLBF_NOBROADCAST);
243243
return 1;
244244
}
245245

0 commit comments

Comments
 (0)