Skip to content

Commit 208beef

Browse files
amlutogregkh
authored andcommitted
x86/mm: Rename flush_tlb_single() and flush_tlb_one() to __flush_tlb_one_[user|kernel]()
commit 1299ef1 upstream. flush_tlb_single() and flush_tlb_one() sound almost identical, but they really mean "flush one user translation" and "flush one kernel translation". Rename them to flush_tlb_one_user() and flush_tlb_one_kernel() to make the semantics more obvious. [ I was looking at some PTI-related code, and the flush-one-address code is unnecessarily hard to understand because the names of the helpers are uninformative. This came up during PTI review, but no one got around to doing it. ] Signed-off-by: Andy Lutomirski <luto@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Eduardo Valentin <eduval@amazon.com> Cc: Hugh Dickins <hughd@google.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Kees Cook <keescook@google.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Linux-MM <linux-mm@kvack.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Link: http://lkml.kernel.org/r/3303b02e3c3d049dc5235d5651e0ae6d29a34354.1517414378.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d6d0c0a commit 208beef

14 files changed

Lines changed: 40 additions & 27 deletions

File tree

‎arch/x86/include/asm/paravirt.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ static inline void __flush_tlb_global(void)
297297
{
298298
PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
299299
}
300-
static inline void __flush_tlb_single(unsigned long addr)
300+
static inline void __flush_tlb_one_user(unsigned long addr)
301301
{
302-
PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
302+
PVOP_VCALL1(pv_mmu_ops.flush_tlb_one_user, addr);
303303
}
304304

305305
static inline void flush_tlb_others(const struct cpumask *cpumask,

‎arch/x86/include/asm/paravirt_types.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ struct pv_mmu_ops {
217217
/* TLB operations */
218218
void (*flush_tlb_user)(void);
219219
void (*flush_tlb_kernel)(void);
220-
void (*flush_tlb_single)(unsigned long addr);
220+
void (*flush_tlb_one_user)(unsigned long addr);
221221
void (*flush_tlb_others)(const struct cpumask *cpus,
222222
const struct flush_tlb_info *info);
223223

‎arch/x86/include/asm/pgtable_32.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void paging_init(void);
6161
#define kpte_clear_flush(ptep, vaddr) \
6262
do { \
6363
pte_clear(&init_mm, (vaddr), (ptep)); \
64-
__flush_tlb_one((vaddr)); \
64+
__flush_tlb_one_kernel((vaddr)); \
6565
} while (0)
6666

6767
#endif /* !__ASSEMBLY__ */

‎arch/x86/include/asm/tlbflush.h‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
140140
#else
141141
#define __flush_tlb() __native_flush_tlb()
142142
#define __flush_tlb_global() __native_flush_tlb_global()
143-
#define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
143+
#define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr)
144144
#endif
145145

146146
static inline bool tlb_defer_switch_to_init_mm(void)
@@ -397,7 +397,7 @@ static inline void __native_flush_tlb_global(void)
397397
/*
398398
* flush one page in the user mapping
399399
*/
400-
static inline void __native_flush_tlb_single(unsigned long addr)
400+
static inline void __native_flush_tlb_one_user(unsigned long addr)
401401
{
402402
u32 loaded_mm_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid);
403403

@@ -434,18 +434,31 @@ static inline void __flush_tlb_all(void)
434434
/*
435435
* flush one page in the kernel mapping
436436
*/
437-
static inline void __flush_tlb_one(unsigned long addr)
437+
static inline void __flush_tlb_one_kernel(unsigned long addr)
438438
{
439439
count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE);
440-
__flush_tlb_single(addr);
440+
441+
/*
442+
* If PTI is off, then __flush_tlb_one_user() is just INVLPG or its
443+
* paravirt equivalent. Even with PCID, this is sufficient: we only
444+
* use PCID if we also use global PTEs for the kernel mapping, and
445+
* INVLPG flushes global translations across all address spaces.
446+
*
447+
* If PTI is on, then the kernel is mapped with non-global PTEs, and
448+
* __flush_tlb_one_user() will flush the given address for the current
449+
* kernel address space and for its usermode counterpart, but it does
450+
* not flush it for other address spaces.
451+
*/
452+
__flush_tlb_one_user(addr);
441453

442454
if (!static_cpu_has(X86_FEATURE_PTI))
443455
return;
444456

445457
/*
446-
* __flush_tlb_single() will have cleared the TLB entry for this ASID,
447-
* but since kernel space is replicated across all, we must also
448-
* invalidate all others.
458+
* See above. We need to propagate the flush to all other address
459+
* spaces. In principle, we only need to propagate it to kernelmode
460+
* address spaces, but the extra bookkeeping we would need is not
461+
* worth it.
449462
*/
450463
invalidate_other_asid();
451464
}

‎arch/x86/kernel/acpi/apei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ void arch_apei_report_mem_error(int sev, struct cper_sec_mem_err *mem_err)
5555

5656
void arch_apei_flush_tlb_one(unsigned long addr)
5757
{
58-
__flush_tlb_one(addr);
58+
__flush_tlb_one_kernel(addr);
5959
}

‎arch/x86/kernel/paravirt.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ static void native_flush_tlb_global(void)
190190
__native_flush_tlb_global();
191191
}
192192

193-
static void native_flush_tlb_single(unsigned long addr)
193+
static void native_flush_tlb_one_user(unsigned long addr)
194194
{
195-
__native_flush_tlb_single(addr);
195+
__native_flush_tlb_one_user(addr);
196196
}
197197

198198
struct static_key paravirt_steal_enabled;
@@ -391,7 +391,7 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = {
391391

392392
.flush_tlb_user = native_flush_tlb,
393393
.flush_tlb_kernel = native_flush_tlb_global,
394-
.flush_tlb_single = native_flush_tlb_single,
394+
.flush_tlb_one_user = native_flush_tlb_one_user,
395395
.flush_tlb_others = native_flush_tlb_others,
396396

397397
.pgd_alloc = __paravirt_pgd_alloc,

‎arch/x86/mm/init_64.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static void __set_pte_vaddr(pud_t *pud, unsigned long vaddr, pte_t new_pte)
256256
* It's enough to flush this one mapping.
257257
* (PGE mappings get flushed as well)
258258
*/
259-
__flush_tlb_one(vaddr);
259+
__flush_tlb_one_kernel(vaddr);
260260
}
261261

262262
void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte)

‎arch/x86/mm/ioremap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,5 +749,5 @@ void __init __early_set_fixmap(enum fixed_addresses idx,
749749
set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
750750
else
751751
pte_clear(&init_mm, addr, pte);
752-
__flush_tlb_one(addr);
752+
__flush_tlb_one_kernel(addr);
753753
}

‎arch/x86/mm/kmmio.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int clear_page_presence(struct kmmio_fault_page *f, bool clear)
168168
return -1;
169169
}
170170

171-
__flush_tlb_one(f->addr);
171+
__flush_tlb_one_kernel(f->addr);
172172
return 0;
173173
}
174174

‎arch/x86/mm/pgtable_32.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
6363
* It's enough to flush this one mapping.
6464
* (PGE mappings get flushed as well)
6565
*/
66-
__flush_tlb_one(vaddr);
66+
__flush_tlb_one_kernel(vaddr);
6767
}
6868

6969
unsigned long __FIXADDR_TOP = 0xfffff000;

0 commit comments

Comments
 (0)