Skip to content

Commit 58430c5

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/tlb: Move __flush_tlb_one_kernel() out of line
cpu_tlbstate is exported because various TLB-related functions need access to it, but cpu_tlbstate is sensitive information which should only be accessed by well-contained kernel functions and not be directly exposed to modules. As a fourth step, move __flush_tlb_one_kernel() out of line and hide the native function. The latter can be static when CONFIG_PARAVIRT is disabled. Consolidate the name space while at it and remove the pointless extra wrapper in the paravirt code. No functional change. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 127ac91 commit 58430c5

File tree

8 files changed

+40
-47
lines changed

8 files changed

+40
-47
lines changed

arch/x86/include/asm/pgtable_32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void sync_initial_page_table(void);
6060
#define kpte_clear_flush(ptep, vaddr) \
6161
do { \
6262
pte_clear(&init_mm, (vaddr), (ptep)); \
63-
__flush_tlb_one_kernel((vaddr)); \
63+
flush_tlb_one_kernel((vaddr)); \
6464
} while (0)
6565

6666
#endif /* !__ASSEMBLY__ */

arch/x86/include/asm/tlbflush.h

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
143143
void flush_tlb_local(void);
144144
void flush_tlb_global(void);
145145
void flush_tlb_one_user(unsigned long addr);
146+
void flush_tlb_one_kernel(unsigned long addr);
146147

147148
#ifdef CONFIG_PARAVIRT
148149
#include <asm/paravirt.h>
@@ -317,14 +318,6 @@ static inline void cr4_clear_bits(unsigned long mask)
317318
local_irq_restore(flags);
318319
}
319320

320-
/*
321-
* Mark all other ASIDs as invalid, preserves the current.
322-
*/
323-
static inline void invalidate_other_asid(void)
324-
{
325-
this_cpu_write(cpu_tlbstate.invalidate_other, true);
326-
}
327-
328321
/*
329322
* Save some of cr4 feature set we're using (e.g. Pentium 4MB
330323
* enable and PPro Global page enable), so that any CPU's that boot
@@ -365,38 +358,6 @@ static inline void __flush_tlb_all(void)
365358
}
366359
}
367360

368-
/*
369-
* flush one page in the kernel mapping
370-
*/
371-
static inline void __flush_tlb_one_kernel(unsigned long addr)
372-
{
373-
count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE);
374-
375-
/*
376-
* If PTI is off, then __flush_tlb_one_user() is just INVLPG or its
377-
* paravirt equivalent. Even with PCID, this is sufficient: we only
378-
* use PCID if we also use global PTEs for the kernel mapping, and
379-
* INVLPG flushes global translations across all address spaces.
380-
*
381-
* If PTI is on, then the kernel is mapped with non-global PTEs, and
382-
* __flush_tlb_one_user() will flush the given address for the current
383-
* kernel address space and for its usermode counterpart, but it does
384-
* not flush it for other address spaces.
385-
*/
386-
flush_tlb_one_user(addr);
387-
388-
if (!static_cpu_has(X86_FEATURE_PTI))
389-
return;
390-
391-
/*
392-
* See above. We need to propagate the flush to all other address
393-
* spaces. In principle, we only need to propagate it to kernelmode
394-
* address spaces, but the extra bookkeeping we would need is not
395-
* worth it.
396-
*/
397-
invalidate_other_asid();
398-
}
399-
400361
#define TLB_FLUSH_ALL -1UL
401362

402363
/*

arch/x86/mm/init_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static void __set_pte_vaddr(pud_t *pud, unsigned long vaddr, pte_t new_pte)
298298
* It's enough to flush this one mapping.
299299
* (PGE mappings get flushed as well)
300300
*/
301-
__flush_tlb_one_kernel(vaddr);
301+
flush_tlb_one_kernel(vaddr);
302302
}
303303

304304
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
@@ -885,5 +885,5 @@ void __init __early_set_fixmap(enum fixed_addresses idx,
885885
set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
886886
else
887887
pte_clear(&init_mm, addr, pte);
888-
__flush_tlb_one_kernel(addr);
888+
flush_tlb_one_kernel(addr);
889889
}

arch/x86/mm/kmmio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int clear_page_presence(struct kmmio_fault_page *f, bool clear)
173173
return -1;
174174
}
175175

176-
__flush_tlb_one_kernel(f->addr);
176+
flush_tlb_one_kernel(f->addr);
177177
return 0;
178178
}
179179

arch/x86/mm/pat/set_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static void __cpa_flush_tlb(void *data)
345345
unsigned int i;
346346

347347
for (i = 0; i < cpa->numpages; i++)
348-
__flush_tlb_one_kernel(fix_addr(__cpa_addr(cpa, i)));
348+
flush_tlb_one_kernel(fix_addr(__cpa_addr(cpa, i)));
349349
}
350350

351351
static void cpa_flush(struct cpa_data *data, int cache)

arch/x86/mm/pgtable_32.c

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

7070
unsigned long __FIXADDR_TOP = 0xfffff000;

arch/x86/mm/tlb.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ static void do_kernel_range_flush(void *info)
876876

877877
/* flush range by one by one 'invlpg' */
878878
for (addr = f->start; addr < f->end; addr += PAGE_SIZE)
879-
__flush_tlb_one_kernel(addr);
879+
flush_tlb_one_kernel(addr);
880880
}
881881

882882
void flush_tlb_kernel_range(unsigned long start, unsigned long end)
@@ -918,6 +918,38 @@ unsigned long __get_current_cr3_fast(void)
918918
}
919919
EXPORT_SYMBOL_GPL(__get_current_cr3_fast);
920920

921+
/*
922+
* Flush one page in the kernel mapping
923+
*/
924+
void flush_tlb_one_kernel(unsigned long addr)
925+
{
926+
count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE);
927+
928+
/*
929+
* If PTI is off, then __flush_tlb_one_user() is just INVLPG or its
930+
* paravirt equivalent. Even with PCID, this is sufficient: we only
931+
* use PCID if we also use global PTEs for the kernel mapping, and
932+
* INVLPG flushes global translations across all address spaces.
933+
*
934+
* If PTI is on, then the kernel is mapped with non-global PTEs, and
935+
* __flush_tlb_one_user() will flush the given address for the current
936+
* kernel address space and for its usermode counterpart, but it does
937+
* not flush it for other address spaces.
938+
*/
939+
flush_tlb_one_user(addr);
940+
941+
if (!static_cpu_has(X86_FEATURE_PTI))
942+
return;
943+
944+
/*
945+
* See above. We need to propagate the flush to all other address
946+
* spaces. In principle, we only need to propagate it to kernelmode
947+
* address spaces, but the extra bookkeeping we would need is not
948+
* worth it.
949+
*/
950+
this_cpu_write(cpu_tlbstate.invalidate_other, true);
951+
}
952+
921953
/*
922954
* Flush one page in the user mapping
923955
*/

0 commit comments

Comments
 (0)