Skip to content

Commit bfe3d8f

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/tlb: Restrict access to tlbstate
Hide tlbstate, flush_tlb_info and related helpers when tlbflush.h is included from a module. Modules have absolutely no business with these internals. 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 8a29204 commit bfe3d8f

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

arch/x86/include/asm/tlbflush.h

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,46 @@
1313
#include <asm/pti.h>
1414
#include <asm/processor-flags.h>
1515

16-
struct flush_tlb_info;
17-
1816
void __flush_tlb_all(void);
19-
void flush_tlb_local(void);
20-
void flush_tlb_one_user(unsigned long addr);
21-
void flush_tlb_one_kernel(unsigned long addr);
22-
void flush_tlb_others(const struct cpumask *cpumask,
23-
const struct flush_tlb_info *info);
2417

25-
#ifdef CONFIG_PARAVIRT
26-
#include <asm/paravirt.h>
27-
#endif
18+
#define TLB_FLUSH_ALL -1UL
19+
20+
void cr4_update_irqsoff(unsigned long set, unsigned long clear);
21+
unsigned long cr4_read_shadow(void);
22+
23+
/* Set in this cpu's CR4. */
24+
static inline void cr4_set_bits_irqsoff(unsigned long mask)
25+
{
26+
cr4_update_irqsoff(mask, 0);
27+
}
2828

29+
/* Clear in this cpu's CR4. */
30+
static inline void cr4_clear_bits_irqsoff(unsigned long mask)
31+
{
32+
cr4_update_irqsoff(0, mask);
33+
}
34+
35+
/* Set in this cpu's CR4. */
36+
static inline void cr4_set_bits(unsigned long mask)
37+
{
38+
unsigned long flags;
39+
40+
local_irq_save(flags);
41+
cr4_set_bits_irqsoff(mask);
42+
local_irq_restore(flags);
43+
}
44+
45+
/* Clear in this cpu's CR4. */
46+
static inline void cr4_clear_bits(unsigned long mask)
47+
{
48+
unsigned long flags;
49+
50+
local_irq_save(flags);
51+
cr4_clear_bits_irqsoff(mask);
52+
local_irq_restore(flags);
53+
}
54+
55+
#ifndef MODULE
2956
/*
3057
* 6 because 6 should be plenty and struct tlb_state will fit in two cache
3158
* lines.
@@ -129,54 +156,17 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
129156
bool nmi_uaccess_okay(void);
130157
#define nmi_uaccess_okay nmi_uaccess_okay
131158

132-
void cr4_update_irqsoff(unsigned long set, unsigned long clear);
133-
unsigned long cr4_read_shadow(void);
134-
135159
/* Initialize cr4 shadow for this CPU. */
136160
static inline void cr4_init_shadow(void)
137161
{
138162
this_cpu_write(cpu_tlbstate.cr4, __read_cr4());
139163
}
140164

141-
/* Set in this cpu's CR4. */
142-
static inline void cr4_set_bits_irqsoff(unsigned long mask)
143-
{
144-
cr4_update_irqsoff(mask, 0);
145-
}
146-
147-
/* Clear in this cpu's CR4. */
148-
static inline void cr4_clear_bits_irqsoff(unsigned long mask)
149-
{
150-
cr4_update_irqsoff(0, mask);
151-
}
152-
153-
/* Set in this cpu's CR4. */
154-
static inline void cr4_set_bits(unsigned long mask)
155-
{
156-
unsigned long flags;
157-
158-
local_irq_save(flags);
159-
cr4_set_bits_irqsoff(mask);
160-
local_irq_restore(flags);
161-
}
162-
163-
/* Clear in this cpu's CR4. */
164-
static inline void cr4_clear_bits(unsigned long mask)
165-
{
166-
unsigned long flags;
167-
168-
local_irq_save(flags);
169-
cr4_clear_bits_irqsoff(mask);
170-
local_irq_restore(flags);
171-
}
172-
173165
extern unsigned long mmu_cr4_features;
174166
extern u32 *trampoline_cr4_features;
175167

176168
extern void initialize_tlbstate_and_flush(void);
177169

178-
#define TLB_FLUSH_ALL -1UL
179-
180170
/*
181171
* TLB flushing:
182172
*
@@ -215,6 +205,16 @@ struct flush_tlb_info {
215205
bool freed_tables;
216206
};
217207

208+
void flush_tlb_local(void);
209+
void flush_tlb_one_user(unsigned long addr);
210+
void flush_tlb_one_kernel(unsigned long addr);
211+
void flush_tlb_others(const struct cpumask *cpumask,
212+
const struct flush_tlb_info *info);
213+
214+
#ifdef CONFIG_PARAVIRT
215+
#include <asm/paravirt.h>
216+
#endif
217+
218218
#define flush_tlb_mm(mm) \
219219
flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL, true)
220220

@@ -255,4 +255,6 @@ static inline void arch_tlbbatch_add_mm(struct arch_tlbflush_unmap_batch *batch,
255255

256256
extern void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch);
257257

258+
#endif /* !MODULE */
259+
258260
#endif /* _ASM_X86_TLBFLUSH_H */

arch/x86/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate) = {
992992
.next_asid = 1,
993993
.cr4 = ~0UL, /* fail hard if we screw up cr4 shadow initialization */
994994
};
995-
EXPORT_PER_CPU_SYMBOL(cpu_tlbstate);
996995

997996
void update_cache_mode_entry(unsigned entry, enum page_cache_mode cache)
998997
{

0 commit comments

Comments
 (0)