Skip to content

Commit c9ae1b1

Browse files
jgross1bp3tk0v
authored andcommitted
x86/paravirt: Merge activate_mm() and dup_mmap() callbacks
The two paravirt callbacks .mmu.activate_mm() and .mmu.dup_mmap() are sharing the same implementations in all cases: for Xen PV guests they are pinning the PGD of the new mm_struct, and for all other cases they are a NOP. In the end, both callbacks are meant to register an address space with the underlying hypervisor, so there needs to be only a single callback for that purpose. So merge them to a common callback .mmu.enter_mmap() (in contrast to the corresponding already existing .mmu.exit_mmap()). As the first parameter of the old callbacks isn't used, drop it from the replacement one. [ bp: Remove last occurrence of paravirt_activate_mm() in asm/mmu_context.h ] Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Reviewed-by: Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> Link: https://lore.kernel.org/r/20230207075902.7539-1-jgross@suse.com
1 parent fe15c26 commit c9ae1b1

6 files changed

Lines changed: 11 additions & 38 deletions

File tree

arch/x86/include/asm/mmu_context.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616

1717
extern atomic64_t last_mm_ctx_id;
1818

19-
#ifndef CONFIG_PARAVIRT_XXL
20-
static inline void paravirt_activate_mm(struct mm_struct *prev,
21-
struct mm_struct *next)
22-
{
23-
}
24-
#endif /* !CONFIG_PARAVIRT_XXL */
25-
2619
#ifdef CONFIG_PERF_EVENTS
2720
DECLARE_STATIC_KEY_FALSE(rdpmc_never_available_key);
2821
DECLARE_STATIC_KEY_FALSE(rdpmc_always_available_key);
@@ -135,7 +128,7 @@ extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
135128

136129
#define activate_mm(prev, next) \
137130
do { \
138-
paravirt_activate_mm((prev), (next)); \
131+
paravirt_enter_mmap(next); \
139132
switch_mm((prev), (next), NULL); \
140133
} while (0);
141134

@@ -168,7 +161,7 @@ static inline void arch_dup_pkeys(struct mm_struct *oldmm,
168161
static inline int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
169162
{
170163
arch_dup_pkeys(oldmm, mm);
171-
paravirt_arch_dup_mmap(oldmm, mm);
164+
paravirt_enter_mmap(mm);
172165
return ldt_dup_context(oldmm, mm);
173166
}
174167

arch/x86/include/asm/paravirt.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,9 @@ static inline void tss_update_io_bitmap(void)
334334
}
335335
#endif
336336

337-
static inline void paravirt_activate_mm(struct mm_struct *prev,
338-
struct mm_struct *next)
337+
static inline void paravirt_enter_mmap(struct mm_struct *next)
339338
{
340-
PVOP_VCALL2(mmu.activate_mm, prev, next);
341-
}
342-
343-
static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
344-
struct mm_struct *mm)
345-
{
346-
PVOP_VCALL2(mmu.dup_mmap, oldmm, mm);
339+
PVOP_VCALL1(mmu.enter_mmap, next);
347340
}
348341

349342
static inline int paravirt_pgd_alloc(struct mm_struct *mm)
@@ -789,8 +782,7 @@ extern void default_banner(void);
789782

790783
#ifndef __ASSEMBLY__
791784
#ifndef CONFIG_PARAVIRT_XXL
792-
static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
793-
struct mm_struct *mm)
785+
static inline void paravirt_enter_mmap(struct mm_struct *mm)
794786
{
795787
}
796788
#endif

arch/x86/include/asm/paravirt_types.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,8 @@ struct pv_mmu_ops {
164164
unsigned long (*read_cr3)(void);
165165
void (*write_cr3)(unsigned long);
166166

167-
/* Hooks for intercepting the creation/use of an mm_struct. */
168-
void (*activate_mm)(struct mm_struct *prev,
169-
struct mm_struct *next);
170-
void (*dup_mmap)(struct mm_struct *oldmm,
171-
struct mm_struct *mm);
167+
/* Hook for intercepting the creation/use of an mm_struct. */
168+
void (*enter_mmap)(struct mm_struct *mm);
172169

173170
/* Hooks for allocating and freeing a pagetable top-level */
174171
int (*pgd_alloc)(struct mm_struct *mm);

arch/x86/kernel/paravirt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ struct paravirt_patch_template pv_ops = {
363363
.mmu.make_pte = PTE_IDENT,
364364
.mmu.make_pgd = PTE_IDENT,
365365

366-
.mmu.dup_mmap = paravirt_nop,
367-
.mmu.activate_mm = paravirt_nop,
366+
.mmu.enter_mmap = paravirt_nop,
368367

369368
.mmu.lazy_mode = {
370369
.enter = paravirt_nop,

arch/x86/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ void __init poking_init(void)
806806
BUG_ON(!poking_mm);
807807

808808
/* Xen PV guests need the PGD to be pinned. */
809-
paravirt_arch_dup_mmap(NULL, poking_mm);
809+
paravirt_enter_mmap(poking_mm);
810810

811811
/*
812812
* Randomize the poking address, but make sure that the following page

arch/x86/xen/mmu_pv.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -885,14 +885,7 @@ void xen_mm_unpin_all(void)
885885
spin_unlock(&pgd_lock);
886886
}
887887

888-
static void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next)
889-
{
890-
spin_lock(&next->page_table_lock);
891-
xen_pgd_pin(next);
892-
spin_unlock(&next->page_table_lock);
893-
}
894-
895-
static void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
888+
static void xen_enter_mmap(struct mm_struct *mm)
896889
{
897890
spin_lock(&mm->page_table_lock);
898891
xen_pgd_pin(mm);
@@ -2153,8 +2146,7 @@ static const typeof(pv_ops) xen_mmu_ops __initconst = {
21532146
.make_p4d = PV_CALLEE_SAVE(xen_make_p4d),
21542147
#endif
21552148

2156-
.activate_mm = xen_activate_mm,
2157-
.dup_mmap = xen_dup_mmap,
2149+
.enter_mmap = xen_enter_mmap,
21582150
.exit_mmap = xen_exit_mmap,
21592151

21602152
.lazy_mode = {

0 commit comments

Comments
 (0)