2012-03-05 18:49:28 +07:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/include/asm/tlb.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 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_TLB_H
|
|
|
|
#define __ASM_TLB_H
|
|
|
|
|
2014-10-10 05:29:23 +07:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
|
|
|
|
static inline void __tlb_remove_table(void *_table)
|
|
|
|
{
|
|
|
|
free_page_and_swap_cache((struct page *)_table);
|
|
|
|
}
|
|
|
|
|
2018-09-04 18:18:15 +07:00
|
|
|
#define tlb_flush tlb_flush
|
2018-08-24 06:23:04 +07:00
|
|
|
static void tlb_flush(struct mmu_gather *tlb);
|
|
|
|
|
2014-10-29 17:03:09 +07:00
|
|
|
#include <asm-generic/tlb.h>
|
|
|
|
|
2012-03-05 18:49:28 +07:00
|
|
|
static inline void tlb_flush(struct mmu_gather *tlb)
|
|
|
|
{
|
mm: do not initialize TLB stack vma's with vma_init()
Commit 2c4541e24c55 ("mm: use vma_init() to initialize VMAs on stack and
data segments") tried to initialize various left-over ad-hoc vma's
"properly", but actually made things worse for the temporary vma's used
for TLB flushing.
vma_init() doesn't actually initialize all of the vma, just a few
fields, so doing something like
- struct vm_area_struct vma = { .vm_mm = tlb->mm, };
+ struct vm_area_struct vma;
+
+ vma_init(&vma, tlb->mm);
was actually very bad: instead of having a nicely initialized vma with
every field but "vm_mm" zeroed, you'd have an entirely uninitialized vma
with only a couple of fields initialized. And they weren't even fields
that the code in question mostly cared about.
The flush_tlb_range() function takes a "struct vma" rather than a
"struct mm_struct", because a few architectures actually care about what
kind of range it is - being able to only do an ITLB flush if it's a
range that doesn't have data accesses enabled, for example. And all the
normal users already have the vma for doing the range invalidation.
But a few people want to call flush_tlb_range() with a range they just
made up, so they also end up using a made-up vma. x86 just has a
special "flush_tlb_mm_range()" function for this, but other
architectures (arm and ia64) do the "use fake vma" thing instead, and
thus got caught up in the vma_init() changes.
At the same time, the TLB flushing code really doesn't care about most
other fields in the vma, so vma_init() is just unnecessary and
pointless.
This fixes things by having an explicit "this is just an initializer for
the TLB flush" initializer macro, which is used by the arm/arm64/ia64
people who mis-use this interface with just a dummy vma.
Fixes: 2c4541e24c55 ("mm: use vma_init() to initialize VMAs on stack and data segments")
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-02 03:43:38 +07:00
|
|
|
struct vm_area_struct vma = TLB_FLUSH_VMA(tlb->mm, 0);
|
2018-08-24 03:08:31 +07:00
|
|
|
bool last_level = !tlb->freed_tables;
|
|
|
|
unsigned long stride = tlb_get_unmap_size(tlb);
|
2015-10-07 00:46:26 +07:00
|
|
|
|
|
|
|
/*
|
2018-08-24 03:08:31 +07:00
|
|
|
* If we're tearing down the address space then we only care about
|
|
|
|
* invalidating the walk-cache, since the ASID allocator won't
|
|
|
|
* reallocate our ASID without invalidating the entire TLB.
|
2015-10-07 00:46:26 +07:00
|
|
|
*/
|
2018-08-24 03:08:31 +07:00
|
|
|
if (tlb->fullmm) {
|
|
|
|
if (!last_level)
|
|
|
|
flush_tlb_mm(tlb->mm);
|
2015-10-07 00:46:26 +07:00
|
|
|
return;
|
2018-08-24 03:08:31 +07:00
|
|
|
}
|
2015-10-07 00:46:26 +07:00
|
|
|
|
2018-08-24 03:08:31 +07:00
|
|
|
__flush_tlb_range(&vma, tlb->start, tlb->end, stride, last_level);
|
2012-03-05 18:49:28 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
|
2014-02-11 22:22:01 +07:00
|
|
|
unsigned long addr)
|
2012-03-05 18:49:28 +07:00
|
|
|
{
|
|
|
|
pgtable_page_dtor(pte);
|
2018-08-24 01:48:44 +07:00
|
|
|
tlb_remove_table(tlb, pte);
|
2012-03-05 18:49:28 +07:00
|
|
|
}
|
|
|
|
|
2015-04-15 05:45:39 +07:00
|
|
|
#if CONFIG_PGTABLE_LEVELS > 2
|
2012-03-05 18:49:28 +07:00
|
|
|
static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
|
|
|
|
unsigned long addr)
|
|
|
|
{
|
2019-03-12 07:57:49 +07:00
|
|
|
struct page *page = virt_to_page(pmdp);
|
|
|
|
|
|
|
|
pgtable_pmd_page_dtor(page);
|
|
|
|
tlb_remove_table(tlb, page);
|
2012-03-05 18:49:28 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-15 05:45:39 +07:00
|
|
|
#if CONFIG_PGTABLE_LEVELS > 3
|
2014-05-12 16:40:51 +07:00
|
|
|
static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp,
|
|
|
|
unsigned long addr)
|
|
|
|
{
|
2018-08-24 01:48:44 +07:00
|
|
|
tlb_remove_table(tlb, virt_to_page(pudp));
|
2014-05-12 16:40:51 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 18:49:28 +07:00
|
|
|
#endif
|