Skip to content

Commit 8c5cc19

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/tlb: Uninline __get_current_cr3_fast()
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. In preparation for unexporting cpu_tlbstate move __get_current_cr3_fast() into the x86 TLB management 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]> Acked-by: Andy Lutomirski <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 325518e commit 8c5cc19

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

arch/x86/include/asm/mmu_context.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,7 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
225225
return __pkru_allows_pkey(vma_pkey(vma), write);
226226
}
227227

228-
/*
229-
* This can be used from process context to figure out what the value of
230-
* CR3 is without needing to do a (slow) __read_cr3().
231-
*
232-
* It's intended to be used for code like KVM that sneakily changes CR3
233-
* and needs to restore it. It needs to be used very carefully.
234-
*/
235-
static inline unsigned long __get_current_cr3_fast(void)
236-
{
237-
unsigned long cr3 = build_cr3(this_cpu_read(cpu_tlbstate.loaded_mm)->pgd,
238-
this_cpu_read(cpu_tlbstate.loaded_mm_asid));
239-
240-
/* For now, be very restrictive about when this can be called. */
241-
VM_WARN_ON(in_nmi() || preemptible());
242-
243-
VM_BUG_ON(cr3 != __read_cr3());
244-
return cr3;
245-
}
228+
unsigned long __get_current_cr3_fast(void);
246229

247230
typedef struct {
248231
struct mm_struct *mm;

arch/x86/mm/tlb.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,26 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end)
843843
}
844844
}
845845

846+
/*
847+
* This can be used from process context to figure out what the value of
848+
* CR3 is without needing to do a (slow) __read_cr3().
849+
*
850+
* It's intended to be used for code like KVM that sneakily changes CR3
851+
* and needs to restore it. It needs to be used very carefully.
852+
*/
853+
unsigned long __get_current_cr3_fast(void)
854+
{
855+
unsigned long cr3 = build_cr3(this_cpu_read(cpu_tlbstate.loaded_mm)->pgd,
856+
this_cpu_read(cpu_tlbstate.loaded_mm_asid));
857+
858+
/* For now, be very restrictive about when this can be called. */
859+
VM_WARN_ON(in_nmi() || preemptible());
860+
861+
VM_BUG_ON(cr3 != __read_cr3());
862+
return cr3;
863+
}
864+
EXPORT_SYMBOL_GPL(__get_current_cr3_fast);
865+
846866
/*
847867
* arch_tlbbatch_flush() performs a full TLB flush regardless of the active mm.
848868
* This means that the 'struct flush_tlb_info' that describes which mappings to

0 commit comments

Comments
 (0)