Commit c9ae1b10 authored by Juergen Gross's avatar Juergen Gross Committed by Borislav Petkov (AMD)

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: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: default avatarSrivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu>
Link: https://lore.kernel.org/r/20230207075902.7539-1-jgross@suse.com
parent fe15c26e
...@@ -16,13 +16,6 @@ ...@@ -16,13 +16,6 @@
extern atomic64_t last_mm_ctx_id; extern atomic64_t last_mm_ctx_id;
#ifndef CONFIG_PARAVIRT_XXL
static inline void paravirt_activate_mm(struct mm_struct *prev,
struct mm_struct *next)
{
}
#endif /* !CONFIG_PARAVIRT_XXL */
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
DECLARE_STATIC_KEY_FALSE(rdpmc_never_available_key); DECLARE_STATIC_KEY_FALSE(rdpmc_never_available_key);
DECLARE_STATIC_KEY_FALSE(rdpmc_always_available_key); 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, ...@@ -135,7 +128,7 @@ extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
#define activate_mm(prev, next) \ #define activate_mm(prev, next) \
do { \ do { \
paravirt_activate_mm((prev), (next)); \ paravirt_enter_mmap(next); \
switch_mm((prev), (next), NULL); \ switch_mm((prev), (next), NULL); \
} while (0); } while (0);
...@@ -168,7 +161,7 @@ static inline void arch_dup_pkeys(struct mm_struct *oldmm, ...@@ -168,7 +161,7 @@ static inline void arch_dup_pkeys(struct mm_struct *oldmm,
static inline int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) static inline int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
{ {
arch_dup_pkeys(oldmm, mm); arch_dup_pkeys(oldmm, mm);
paravirt_arch_dup_mmap(oldmm, mm); paravirt_enter_mmap(mm);
return ldt_dup_context(oldmm, mm); return ldt_dup_context(oldmm, mm);
} }
......
...@@ -334,16 +334,9 @@ static inline void tss_update_io_bitmap(void) ...@@ -334,16 +334,9 @@ static inline void tss_update_io_bitmap(void)
} }
#endif #endif
static inline void paravirt_activate_mm(struct mm_struct *prev, static inline void paravirt_enter_mmap(struct mm_struct *next)
struct mm_struct *next)
{ {
PVOP_VCALL2(mmu.activate_mm, prev, next); PVOP_VCALL1(mmu.enter_mmap, next);
}
static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
struct mm_struct *mm)
{
PVOP_VCALL2(mmu.dup_mmap, oldmm, mm);
} }
static inline int paravirt_pgd_alloc(struct mm_struct *mm) static inline int paravirt_pgd_alloc(struct mm_struct *mm)
...@@ -789,8 +782,7 @@ extern void default_banner(void); ...@@ -789,8 +782,7 @@ extern void default_banner(void);
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#ifndef CONFIG_PARAVIRT_XXL #ifndef CONFIG_PARAVIRT_XXL
static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm, static inline void paravirt_enter_mmap(struct mm_struct *mm)
struct mm_struct *mm)
{ {
} }
#endif #endif
......
...@@ -164,11 +164,8 @@ struct pv_mmu_ops { ...@@ -164,11 +164,8 @@ struct pv_mmu_ops {
unsigned long (*read_cr3)(void); unsigned long (*read_cr3)(void);
void (*write_cr3)(unsigned long); void (*write_cr3)(unsigned long);
/* Hooks for intercepting the creation/use of an mm_struct. */ /* Hook for intercepting the creation/use of an mm_struct. */
void (*activate_mm)(struct mm_struct *prev, void (*enter_mmap)(struct mm_struct *mm);
struct mm_struct *next);
void (*dup_mmap)(struct mm_struct *oldmm,
struct mm_struct *mm);
/* Hooks for allocating and freeing a pagetable top-level */ /* Hooks for allocating and freeing a pagetable top-level */
int (*pgd_alloc)(struct mm_struct *mm); int (*pgd_alloc)(struct mm_struct *mm);
......
...@@ -363,8 +363,7 @@ struct paravirt_patch_template pv_ops = { ...@@ -363,8 +363,7 @@ struct paravirt_patch_template pv_ops = {
.mmu.make_pte = PTE_IDENT, .mmu.make_pte = PTE_IDENT,
.mmu.make_pgd = PTE_IDENT, .mmu.make_pgd = PTE_IDENT,
.mmu.dup_mmap = paravirt_nop, .mmu.enter_mmap = paravirt_nop,
.mmu.activate_mm = paravirt_nop,
.mmu.lazy_mode = { .mmu.lazy_mode = {
.enter = paravirt_nop, .enter = paravirt_nop,
......
...@@ -806,7 +806,7 @@ void __init poking_init(void) ...@@ -806,7 +806,7 @@ void __init poking_init(void)
BUG_ON(!poking_mm); BUG_ON(!poking_mm);
/* Xen PV guests need the PGD to be pinned. */ /* Xen PV guests need the PGD to be pinned. */
paravirt_arch_dup_mmap(NULL, poking_mm); paravirt_enter_mmap(poking_mm);
/* /*
* Randomize the poking address, but make sure that the following page * Randomize the poking address, but make sure that the following page
......
...@@ -885,14 +885,7 @@ void xen_mm_unpin_all(void) ...@@ -885,14 +885,7 @@ void xen_mm_unpin_all(void)
spin_unlock(&pgd_lock); spin_unlock(&pgd_lock);
} }
static void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next) static void xen_enter_mmap(struct mm_struct *mm)
{
spin_lock(&next->page_table_lock);
xen_pgd_pin(next);
spin_unlock(&next->page_table_lock);
}
static void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
{ {
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
xen_pgd_pin(mm); xen_pgd_pin(mm);
...@@ -2153,8 +2146,7 @@ static const typeof(pv_ops) xen_mmu_ops __initconst = { ...@@ -2153,8 +2146,7 @@ static const typeof(pv_ops) xen_mmu_ops __initconst = {
.make_p4d = PV_CALLEE_SAVE(xen_make_p4d), .make_p4d = PV_CALLEE_SAVE(xen_make_p4d),
#endif #endif
.activate_mm = xen_activate_mm, .enter_mmap = xen_enter_mmap,
.dup_mmap = xen_dup_mmap,
.exit_mmap = xen_exit_mmap, .exit_mmap = xen_exit_mmap,
.lazy_mode = { .lazy_mode = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment