Skip to content

Commit 127ac91

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/tlb: Move __flush_tlb_one_user() 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 third step, move _flush_tlb_one_user() 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 cd30d26 commit 127ac91

File tree

5 files changed

+59
-58
lines changed

5 files changed

+59
-58
lines changed

arch/x86/include/asm/paravirt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static inline void slow_down_io(void)
4949

5050
void native_flush_tlb_local(void);
5151
void native_flush_tlb_global(void);
52+
void native_flush_tlb_one_user(unsigned long addr);
5253

5354
static inline void __flush_tlb_local(void)
5455
{

arch/x86/include/asm/tlbflush.h

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,10 @@ static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
142142

143143
void flush_tlb_local(void);
144144
void flush_tlb_global(void);
145+
void flush_tlb_one_user(unsigned long addr);
145146

146147
#ifdef CONFIG_PARAVIRT
147148
#include <asm/paravirt.h>
148-
#else
149-
#define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr)
150149
#endif
151150

152151
struct tlb_context {
@@ -345,54 +344,6 @@ static inline void cr4_set_bits_and_update_boot(unsigned long mask)
345344

346345
extern void initialize_tlbstate_and_flush(void);
347346

348-
/*
349-
* Given an ASID, flush the corresponding user ASID. We can delay this
350-
* until the next time we switch to it.
351-
*
352-
* See SWITCH_TO_USER_CR3.
353-
*/
354-
static inline void invalidate_user_asid(u16 asid)
355-
{
356-
/* There is no user ASID if address space separation is off */
357-
if (!IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION))
358-
return;
359-
360-
/*
361-
* We only have a single ASID if PCID is off and the CR3
362-
* write will have flushed it.
363-
*/
364-
if (!cpu_feature_enabled(X86_FEATURE_PCID))
365-
return;
366-
367-
if (!static_cpu_has(X86_FEATURE_PTI))
368-
return;
369-
370-
__set_bit(kern_pcid(asid),
371-
(unsigned long *)this_cpu_ptr(&cpu_tlbstate.user_pcid_flush_mask));
372-
}
373-
374-
/*
375-
* flush one page in the user mapping
376-
*/
377-
static inline void __native_flush_tlb_one_user(unsigned long addr)
378-
{
379-
u32 loaded_mm_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid);
380-
381-
asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
382-
383-
if (!static_cpu_has(X86_FEATURE_PTI))
384-
return;
385-
386-
/*
387-
* Some platforms #GP if we call invpcid(type=1/2) before CR4.PCIDE=1.
388-
* Just use invalidate_user_asid() in case we are called early.
389-
*/
390-
if (!this_cpu_has(X86_FEATURE_INVPCID_SINGLE))
391-
invalidate_user_asid(loaded_mm_asid);
392-
else
393-
invpcid_flush_one(user_pcid(loaded_mm_asid), addr);
394-
}
395-
396347
/*
397348
* flush everything
398349
*/
@@ -432,7 +383,7 @@ static inline void __flush_tlb_one_kernel(unsigned long addr)
432383
* kernel address space and for its usermode counterpart, but it does
433384
* not flush it for other address spaces.
434385
*/
435-
__flush_tlb_one_user(addr);
386+
flush_tlb_one_user(addr);
436387

437388
if (!static_cpu_has(X86_FEATURE_PTI))
438389
return;

arch/x86/kernel/paravirt.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ unsigned paravirt_patch_insns(void *insn_buff, unsigned len,
160160
return insn_len;
161161
}
162162

163-
static void native_flush_tlb_one_user(unsigned long addr)
164-
{
165-
__native_flush_tlb_one_user(addr);
166-
}
167-
168163
struct static_key paravirt_steal_enabled;
169164
struct static_key paravirt_steal_rq_enabled;
170165

arch/x86/mm/tlb.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# define STATIC_NOPV static
2525
# define __flush_tlb_local native_flush_tlb_local
2626
# define __flush_tlb_global native_flush_tlb_global
27+
# define __flush_tlb_one_user(addr) native_flush_tlb_one_user(addr)
2728
#endif
2829

2930
/*
@@ -118,6 +119,32 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen,
118119
*need_flush = true;
119120
}
120121

122+
/*
123+
* Given an ASID, flush the corresponding user ASID. We can delay this
124+
* until the next time we switch to it.
125+
*
126+
* See SWITCH_TO_USER_CR3.
127+
*/
128+
static inline void invalidate_user_asid(u16 asid)
129+
{
130+
/* There is no user ASID if address space separation is off */
131+
if (!IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION))
132+
return;
133+
134+
/*
135+
* We only have a single ASID if PCID is off and the CR3
136+
* write will have flushed it.
137+
*/
138+
if (!cpu_feature_enabled(X86_FEATURE_PCID))
139+
return;
140+
141+
if (!static_cpu_has(X86_FEATURE_PTI))
142+
return;
143+
144+
__set_bit(kern_pcid(asid),
145+
(unsigned long *)this_cpu_ptr(&cpu_tlbstate.user_pcid_flush_mask));
146+
}
147+
121148
static void load_new_mm_cr3(pgd_t *pgdir, u16 new_asid, bool need_flush)
122149
{
123150
unsigned long new_mm_cr3;
@@ -645,7 +672,7 @@ static void flush_tlb_func_common(const struct flush_tlb_info *f,
645672
unsigned long addr = f->start;
646673

647674
while (addr < f->end) {
648-
__flush_tlb_one_user(addr);
675+
flush_tlb_one_user(addr);
649676
addr += 1UL << f->stride_shift;
650677
}
651678
if (local)
@@ -891,6 +918,33 @@ unsigned long __get_current_cr3_fast(void)
891918
}
892919
EXPORT_SYMBOL_GPL(__get_current_cr3_fast);
893920

921+
/*
922+
* Flush one page in the user mapping
923+
*/
924+
STATIC_NOPV void native_flush_tlb_one_user(unsigned long addr)
925+
{
926+
u32 loaded_mm_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid);
927+
928+
asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
929+
930+
if (!static_cpu_has(X86_FEATURE_PTI))
931+
return;
932+
933+
/*
934+
* Some platforms #GP if we call invpcid(type=1/2) before CR4.PCIDE=1.
935+
* Just use invalidate_user_asid() in case we are called early.
936+
*/
937+
if (!this_cpu_has(X86_FEATURE_INVPCID_SINGLE))
938+
invalidate_user_asid(loaded_mm_asid);
939+
else
940+
invpcid_flush_one(user_pcid(loaded_mm_asid), addr);
941+
}
942+
943+
void flush_tlb_one_user(unsigned long addr)
944+
{
945+
__flush_tlb_one_user(addr);
946+
}
947+
894948
/*
895949
* Flush everything
896950
*/

arch/x86/platform/uv/tlb_uv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static void bau_process_message(struct msg_desc *mdp, struct bau_control *bcp,
296296
flush_tlb_local();
297297
stat->d_alltlb++;
298298
} else {
299-
__flush_tlb_one_user(msg->address);
299+
flush_tlb_one_user(msg->address);
300300
stat->d_onetlb++;
301301
}
302302
stat->d_requestee++;

0 commit comments

Comments
 (0)