[PATCH] x86: PARAVIRT: add hooks to intercept mm creation and destruction
authorJeremy Fitzhardinge <jeremy@goop.org>
Wed, 2 May 2007 17:27:14 +0000 (19:27 +0200)
committerAndi Kleen <andi@basil.nowhere.org>
Wed, 2 May 2007 17:27:14 +0000 (19:27 +0200)
Add hooks to allow a paravirt implementation to track the lifetime of
an mm.  Paravirtualization requires three hooks, but only two are
needed in common code.  They are:

arch_dup_mmap, which is called when a new mmap is created at fork

arch_exit_mmap, which is called when the last process reference to an
  mm is dropped, which typically happens on exit and exec.

The third hook is activate_mm, which is called from the arch-specific
activate_mm() macro/function, and so doesn't need stub versions for
other architectures.  It's called when an mm is first used.

Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: linux-arch@vger.kernel.org
Cc: James Bottomley <James.Bottomley@SteelEye.com>
Acked-by: Ingo Molnar <mingo@elte.hu>
30 files changed:
arch/i386/kernel/paravirt.c
include/asm-alpha/mmu_context.h
include/asm-arm/mmu_context.h
include/asm-arm26/mmu_context.h
include/asm-avr32/mmu_context.h
include/asm-cris/mmu_context.h
include/asm-frv/mmu_context.h
include/asm-generic/mm_hooks.h [new file with mode: 0644]
include/asm-h8300/mmu_context.h
include/asm-i386/mmu_context.h
include/asm-i386/paravirt.h
include/asm-ia64/mmu_context.h
include/asm-m32r/mmu_context.h
include/asm-m68k/mmu_context.h
include/asm-m68knommu/mmu_context.h
include/asm-mips/mmu_context.h
include/asm-parisc/mmu_context.h
include/asm-powerpc/mmu_context.h
include/asm-ppc/mmu_context.h
include/asm-s390/mmu_context.h
include/asm-sh/mmu_context.h
include/asm-sh64/mmu_context.h
include/asm-sparc/mmu_context.h
include/asm-sparc64/mmu_context.h
include/asm-um/mmu_context.h
include/asm-v850/mmu_context.h
include/asm-x86_64/mmu_context.h
include/asm-xtensa/mmu_context.h
kernel/fork.c
mm/mmap.c

index 2040a831d5b3b23a2c0c81fbcc3b963356e7787e..54cc14d997404652add938ce81299583ec500b8d 100644 (file)
@@ -237,6 +237,10 @@ struct paravirt_ops paravirt_ops = {
        .irq_enable_sysexit = native_irq_enable_sysexit,
        .iret = native_iret,
 
+       .dup_mmap = paravirt_nop,
+       .exit_mmap = paravirt_nop,
+       .activate_mm = paravirt_nop,
+
        .startup_ipi_hook = paravirt_nop,
 };
 
index fe249e9d3360041a31f4399358f9d2c13253b9d5..0bd7bd2ccb9022e91281668055e5c9e7b91785b2 100644 (file)
@@ -10,6 +10,7 @@
 #include <asm/system.h>
 #include <asm/machvec.h>
 #include <asm/compiler.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * Force a context reload. This is needed when we change the page
index d1a65b1edcaab236f0a65706380f60e85d26fc04..f8755c818b5462549e39ed8bd0102ae3b02ed0a0 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/compiler.h>
 #include <asm/cacheflush.h>
 #include <asm/proc-fns.h>
+#include <asm-generic/mm_hooks.h>
 
 void __check_kvm_seq(struct mm_struct *mm);
 
index 1a929bfe5c3ace600c9a6071e661157aa30b1324..16c821f81b8ddb664549640458e102d4b66f39bc 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef __ASM_ARM_MMU_CONTEXT_H
 #define __ASM_ARM_MMU_CONTEXT_H
 
+#include <asm-generic/mm_hooks.h>
+
 #define init_new_context(tsk,mm)       0
 #define destroy_context(mm)            do { } while(0)
 
index 31add1ae8089c6776c9651c8f54d968bd37a2df3..c37c391faef6b0f67d50cbe1bfed504dbdc9d36f 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/tlbflush.h>
 #include <asm/pgalloc.h>
 #include <asm/sysreg.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * The MMU "context" consists of two things:
index e6e659dc757be7e0d3aa6e025c61b1f7913a352e..72ba08dcfd18c1336d19d2ef66893bd7658a8a4b 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __CRIS_MMU_CONTEXT_H
 #define __CRIS_MMU_CONTEXT_H
 
+#include <asm-generic/mm_hooks.h>
+
 extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
 extern void get_mmu_context(struct mm_struct *mm);
 extern void destroy_context(struct mm_struct *mm);
index 72edcaaccd5de30d7b126520d218f360ef3696fb..c7daa395156a1b30a8a6b58269f94cca3dd3462d 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/setup.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
+#include <asm-generic/mm_hooks.h>
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
diff --git a/include/asm-generic/mm_hooks.h b/include/asm-generic/mm_hooks.h
new file mode 100644 (file)
index 0000000..67dea81
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Define generic no-op hooks for arch_dup_mmap and arch_exit_mmap, to
+ * be included in asm-FOO/mmu_context.h for any arch FOO which doesn't
+ * need to hook these.
+ */
+#ifndef _ASM_GENERIC_MM_HOOKS_H
+#define _ASM_GENERIC_MM_HOOKS_H
+
+static inline void arch_dup_mmap(struct mm_struct *oldmm,
+                                struct mm_struct *mm)
+{
+}
+
+static inline void arch_exit_mmap(struct mm_struct *mm)
+{
+}
+
+#endif /* _ASM_GENERIC_MM_HOOKS_H */
index 5c165f7bee0edb4123bc015d4092ac71f4cf4071..f44b730da54d3c229e3007556282a11a655269fa 100644 (file)
@@ -4,6 +4,7 @@
 #include <asm/setup.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
+#include <asm-generic/mm_hooks.h>
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
index e6aa30f8de5b6d47666894711d39492b2774eaed..8198d1cca1f31264dc6b0ee4da90cdd0c13cd323 100644 (file)
@@ -5,6 +5,16 @@
 #include <asm/atomic.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
+#include <asm/paravirt.h>
+#ifndef CONFIG_PARAVIRT
+#include <asm-generic/mm_hooks.h>
+
+static inline void paravirt_activate_mm(struct mm_struct *prev,
+                                       struct mm_struct *next)
+{
+}
+#endif /* !CONFIG_PARAVIRT */
+
 
 /*
  * Used for LDT copy/destruction.
@@ -65,7 +75,10 @@ static inline void switch_mm(struct mm_struct *prev,
 #define deactivate_mm(tsk, mm)                 \
        asm("movl %0,%%gs": :"r" (0));
 
-#define activate_mm(prev, next) \
-       switch_mm((prev),(next),NULL)
+#define activate_mm(prev, next)                                \
+       do {                                            \
+               paravirt_activate_mm(prev, next);       \
+               switch_mm((prev),(next),NULL);          \
+       } while(0);
 
 #endif
index f93599dc7756d1b1237ccf35cd31f1339267acf2..61c03f1e0c29b53065460564f05ecb961a2fa66e 100644 (file)
@@ -119,6 +119,12 @@ struct paravirt_ops
 
        void (*io_delay)(void);
 
+       void (*activate_mm)(struct mm_struct *prev,
+                           struct mm_struct *next);
+       void (*dup_mmap)(struct mm_struct *oldmm,
+                        struct mm_struct *mm);
+       void (*exit_mmap)(struct mm_struct *mm);
+
 #ifdef CONFIG_X86_LOCAL_APIC
        void (*apic_write)(unsigned long reg, unsigned long v);
        void (*apic_write_atomic)(unsigned long reg, unsigned long v);
@@ -395,6 +401,23 @@ static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
 }
 #endif
 
+static inline void paravirt_activate_mm(struct mm_struct *prev,
+                                       struct mm_struct *next)
+{
+       paravirt_ops.activate_mm(prev, next);
+}
+
+static inline void arch_dup_mmap(struct mm_struct *oldmm,
+                                struct mm_struct *mm)
+{
+       paravirt_ops.dup_mmap(oldmm, mm);
+}
+
+static inline void arch_exit_mmap(struct mm_struct *mm)
+{
+       paravirt_ops.exit_mmap(mm);
+}
+
 #define __flush_tlb() paravirt_ops.flush_tlb_user()
 #define __flush_tlb_global() paravirt_ops.flush_tlb_kernel()
 #define __flush_tlb_single(addr) paravirt_ops.flush_tlb_single(addr)
index b5c65081a3aab49bc051b7209c03d0ca54122160..cef2400983fafe3fd1961895a4d355f11a14d34b 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/spinlock.h>
 
 #include <asm/processor.h>
+#include <asm-generic/mm_hooks.h>
 
 struct ia64_ctx {
        spinlock_t lock;
index 1f40d4a0acf1a4acd6d0a3764f5b9f09b9439a78..91909e5dd9d0a300b5a32ddb4e930c7bbae21066 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/pgalloc.h>
 #include <asm/mmu.h>
 #include <asm/tlbflush.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * Cache of MMU context last used.
index 231d11bd8e320921d6d869eef47edba1c4d52118..894dacbcee145df5c79b147393c7282a9edfef06 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __M68K_MMU_CONTEXT_H
 #define __M68K_MMU_CONTEXT_H
 
+#include <asm-generic/mm_hooks.h>
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
index 6c077d3a2572c32bb6eaab0319fe5e24ceedeaa5..9ccee4278c977dd924aead4d6bead5e58b236d99 100644 (file)
@@ -4,6 +4,7 @@
 #include <asm/setup.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
+#include <asm-generic/mm_hooks.h>
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
index fe065d6070ca3885b4f4f3f9467a87de01fed0e8..65024ffd78799ada089bbbf3ca9de0993022c123 100644 (file)
@@ -20,6 +20,7 @@
 #include <asm/mipsmtregs.h>
 #include <asm/smtc.h>
 #endif /* SMTC */
+#include <asm-generic/mm_hooks.h>
 
 /*
  * For the fast tlb miss handlers, we keep a per cpu array of pointers
index 9c05836239a2c97b1ccf52ed73059b36d598e3f6..bad690298f0c01fe89a740d2829b8b33f5316f54 100644 (file)
@@ -5,6 +5,7 @@
 #include <asm/atomic.h>
 #include <asm/pgalloc.h>
 #include <asm/pgtable.h>
+#include <asm-generic/mm_hooks.h>
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
index 083ac917bd293b4be1640d50efdad07272260117..c0d7795e3d257d8eb3172b3d506a9d904ad6eee0 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/mm.h>  
 #include <asm/mmu.h>   
 #include <asm/cputable.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * Copyright (C) 2001 PPC 64 Team, IBM Corp
index 2bc8589cc45130b9f223f0fb172dbb1b5a12894c..a6441a063e5d7c20d1553e79aa898814052fe1d9 100644 (file)
@@ -6,6 +6,7 @@
 #include <asm/bitops.h>
 #include <asm/mmu.h>
 #include <asm/cputable.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * On 32-bit PowerPC 6xx/7xx/7xxx CPUs, we use a set of 16 VSIDs
index 1d21da220d49b8779ad3e916d67c54dfc1f73547..501cb9b0631460b0e2694d43ce4d9c32c6518b0a 100644 (file)
@@ -10,6 +10,8 @@
 #define __S390_MMU_CONTEXT_H
 
 #include <asm/pgalloc.h>
+#include <asm-generic/mm_hooks.h>
+
 /*
  * get a new mmu context.. S390 don't know about contexts.
  */
index 342024425b7df7a484e32fadb8796f089dd111c9..01acaaae975182ed225aee6c2fa7f9e62952cf0c 100644 (file)
@@ -12,6 +12,7 @@
 #include <asm/tlbflush.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * The MMU "context" consists of two things:
index 8c860dab2d0e6554b9b21329dc26c79f79da0249..507bf72bb8e10b13f8bbf0dd82069fa297124f59 100644 (file)
@@ -27,7 +27,7 @@
 extern unsigned long mmu_context_cache;
 
 #include <asm/page.h>
-
+#include <asm-generic/mm_hooks.h>
 
 /* Current mm's pgd */
 extern pgd_t *mmu_pdtp_cache;
index ed1e01d04d21d4bf62e63fb035543ddb407564f0..671a997b9e6961d4f543347b46266773c5abf622 100644 (file)
@@ -5,6 +5,8 @@
 
 #ifndef __ASSEMBLY__
 
+#include <asm-generic/mm_hooks.h>
+
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
 }
index 2337eb48771908ca86f94a1a5d4cba3d42c0e43d..8d129032013e9b3e8fcf35a040f5438dab02959a 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/spinlock.h>
 #include <asm/system.h>
 #include <asm/spitfire.h>
+#include <asm-generic/mm_hooks.h>
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
index f709c784bf1296e21de0a33175e403e86a974df6..9aa4b44e8cc1658653a0eb2f0f8383752f88313c 100644 (file)
@@ -6,6 +6,8 @@
 #ifndef __UM_MMU_CONTEXT_H
 #define __UM_MMU_CONTEXT_H
 
+#include <asm-generic/mm_hooks.h>
+
 #include "linux/sched.h"
 #include "choose-mode.h"
 #include "um_mmu.h"
index f521c8050d3cdc3ea2c325656d4478c299402c6f..01daacd5474efcc821b57a04ca3b9239e43be444 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __V850_MMU_CONTEXT_H__
 #define __V850_MMU_CONTEXT_H__
 
+#include <asm-generic/mm_hooks.h>
+
 #define destroy_context(mm)            ((void)0)
 #define init_new_context(tsk,mm)       0
 #define switch_mm(prev,next,tsk)       ((void)0)
index af03b9f852d650eec292f0b8eced273a23bcaca8..0cce83a78378ec20a12a348c8b907d4b2386a6cf 100644 (file)
@@ -7,6 +7,7 @@
 #include <asm/pda.h>
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
+#include <asm-generic/mm_hooks.h>
 
 /*
  * possibly do the LDT unload here?
index f14851f086c39db5cb6fe0e7892a7278f050772f..92f948392ebccede88123965b1d71bd91c1a48ca 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/pgtable.h>
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
+#include <asm-generic/mm_hooks.h>
 
 #define XCHAL_MMU_ASID_BITS    8
 
index 6af959c034d892a360f4196ed3b981a51890f92a..ffccefb28b6a3d1680ba32e38130fd1b96b0007c 100644 (file)
@@ -286,6 +286,8 @@ static inline int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
                if (retval)
                        goto out;
        }
+       /* a new mm has just been created */
+       arch_dup_mmap(oldmm, mm);
        retval = 0;
 out:
        up_write(&mm->mmap_sem);
index 84f997da78d70e607578afac5a87b64362b12558..88da687bde89fdc51b367c1728d330b3321568ab 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -29,6 +29,7 @@
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
 #include <asm/tlb.h>
+#include <asm/mmu_context.h>
 
 #ifndef arch_mmap_check
 #define arch_mmap_check(addr, len, flags)      (0)
@@ -1979,6 +1980,9 @@ void exit_mmap(struct mm_struct *mm)
        unsigned long nr_accounted = 0;
        unsigned long end;
 
+       /* mm's last user has gone, and its about to be pulled down */
+       arch_exit_mmap(mm);
+
        lru_add_drain();
        flush_cache_mm(mm);
        tlb = tlb_gather_mmu(mm, 1);