[01/24] asm-generic: add generic versions of mmu context functions
diff mbox series

Message ID 20200728033405.78469-2-npiggin@gmail.com
State New
Headers show
Series
  • Use asm-generic for mmu_context no-op functions
Related show

Commit Message

Nicholas Piggin July 28, 2020, 3:33 a.m. UTC
Many of these are no-ops on many architectures, so extend mmu_context.h
to cover MMU and NOMMU, and split the NOMMU bits out to nommu_context.h

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/microblaze/include/asm/mmu_context.h |  2 +-
 arch/sh/include/asm/mmu_context.h         |  2 +-
 include/asm-generic/mmu_context.h         | 57 +++++++++++++++++------
 include/asm-generic/nommu_context.h       | 19 ++++++++
 4 files changed, 64 insertions(+), 16 deletions(-)
 create mode 100644 include/asm-generic/nommu_context.h

Comments

Vineet Gupta July 28, 2020, 4:01 a.m. UTC | #1
On 7/27/20 8:33 PM, Nicholas Piggin wrote:
> Many of these are no-ops on many architectures, so extend mmu_context.h
> to cover MMU and NOMMU, and split the NOMMU bits out to nommu_context.h
> 

> -static inline void switch_mm(struct mm_struct *prev,
> -			struct mm_struct *next,
> -			struct task_struct *tsk)
> +/**
> + * activate_mm - called after exec switches the current task to a new mm, to switch to it
> + * @prev_mm: previous mm of this task
> + * @next_mm: new mm
> + */
> +#ifndef activate_mm
> +static inline void activate_mm(struct mm_struct *prev_mm,
> +			       struct mm_struct *next_mm)
>  {
> +	switch_mm(prev_mm, next_mm, current);
>  }
> +#endif

Is activate_mm() really needed now. It seems most arches have
   activate_mm(p, n) -> switch_mm(p, n, NULL)

And if we are passing current, that can be pushed inside switch_mm()

>  
> -static inline void activate_mm(struct mm_struct *prev_mm,
> -			       struct mm_struct *next_mm)
kernel test robot July 28, 2020, 5:53 a.m. UTC | #2
Hi Nicholas,

I love your patch! Yet something to improve:

[auto build test ERROR on openrisc/for-next]
[also build test ERROR on sparc/master linus/master asm-generic/master v5.8-rc7 next-20200727]
[cannot apply to nios2/for-linus]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nicholas-Piggin/Use-asm-generic-for-mmu_context-no-op-functions/20200728-113854
base:   https://github.com/openrisc/linux.git for-next
config: c6x-allyesconfig (attached as .config)
compiler: c6x-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=c6x 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from ./arch/c6x/include/generated/asm/mmu_context.h:1,
                    from include/linux/mmu_context.h:5,
                    from kernel//sched/sched.h:54,
                    from kernel//sched/core.c:9:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
>> include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   cc1: some warnings being treated as errors
--
   In file included from ./arch/c6x/include/generated/asm/mmu_context.h:1,
                    from include/linux/mmu_context.h:5,
                    from kernel//sched/sched.h:54,
                    from kernel//sched/rt.c:6:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
>> include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   kernel//sched/rt.c: At top level:
   kernel//sched/rt.c:668:6: warning: no previous prototype for 'sched_rt_bandwidth_account' [-Wmissing-prototypes]
     668 | bool sched_rt_bandwidth_account(struct rt_rq *rt_rq)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/switch_mm +59 include/asm-generic/mmu_context.h

    49	
    50	/**
    51	 * activate_mm - called after exec switches the current task to a new mm, to switch to it
    52	 * @prev_mm: previous mm of this task
    53	 * @next_mm: new mm
    54	 */
    55	#ifndef activate_mm
    56	static inline void activate_mm(struct mm_struct *prev_mm,
    57				       struct mm_struct *next_mm)
    58	{
  > 59		switch_mm(prev_mm, next_mm, current);
    60	}
    61	#endif
    62	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Nicholas Piggin July 28, 2020, 10:37 a.m. UTC | #3
Excerpts from Vineet Gupta's message of July 28, 2020 2:01 pm:
> On 7/27/20 8:33 PM, Nicholas Piggin wrote:
>> Many of these are no-ops on many architectures, so extend mmu_context.h
>> to cover MMU and NOMMU, and split the NOMMU bits out to nommu_context.h
>> 
> 
>> -static inline void switch_mm(struct mm_struct *prev,
>> -			struct mm_struct *next,
>> -			struct task_struct *tsk)
>> +/**
>> + * activate_mm - called after exec switches the current task to a new mm, to switch to it
>> + * @prev_mm: previous mm of this task
>> + * @next_mm: new mm
>> + */
>> +#ifndef activate_mm
>> +static inline void activate_mm(struct mm_struct *prev_mm,
>> +			       struct mm_struct *next_mm)
>>  {
>> +	switch_mm(prev_mm, next_mm, current);
>>  }
>> +#endif
> 
> Is activate_mm() really needed now. It seems most arches have
>    activate_mm(p, n) -> switch_mm(p, n, NULL)
> 
> And if we are passing current, that can be pushed inside switch_mm()

Thanks for taking a look, I think there may be more consolidation
like this possible, and certainly some of the arch patches could
have gone a bit further.

I wanted to be fairly careful to make only quite trivial changes
(only the obvious no-ops) for the first iteration, but once this
is in the tree it should become a fair bit easier to do some
of your suggestions.

There's a few things that make activate_mm->switch_mm not quite
simple - alpha, nios2, parisc, s390, maybe x86.

Thanks,
Nick
kernel test robot July 28, 2020, 11:52 p.m. UTC | #4
Hi Nicholas,

I love your patch! Yet something to improve:

[auto build test ERROR on openrisc/for-next]
[also build test ERROR on sparc-next/master sparc/master linus/master asm-generic/master xtensa/for_next v5.8-rc7 next-20200728]
[cannot apply to nios2/for-linus]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nicholas-Piggin/Use-asm-generic-for-mmu_context-no-op-functions/20200728-113854
base:   https://github.com/openrisc/linux.git for-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/process_32.c:26:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/process_32.c:26:
   include/asm-generic/nommu_context.h: At top level:
   include/asm-generic/nommu_context.h:13:20: error: conflicting types for 'switch_mm' [-Werror]
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/process_32.c:26:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   cc1: all warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/setup.c:44:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/setup.c:44:
   include/asm-generic/nommu_context.h: At top level:
   include/asm-generic/nommu_context.h:13:20: error: conflicting types for 'switch_mm' [-Werror]
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/setup.c:44:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   arch/sh/kernel/setup.c:248:12: error: no previous prototype for 'sh_fdt_init' [-Werror=missing-prototypes]
     248 | void __ref sh_fdt_init(phys_addr_t dt_phys)
         |            ^~~~~~~~~~~
   cc1: all warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/hw_breakpoint.c:21:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/hw_breakpoint.c:21:
   include/asm-generic/nommu_context.h: At top level:
   include/asm-generic/nommu_context.h:13:20: error: conflicting types for 'switch_mm' [-Werror]
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/hw_breakpoint.c:21:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   arch/sh/kernel/hw_breakpoint.c:135:5: error: no previous prototype for 'arch_bp_generic_fields' [-Werror=missing-prototypes]
     135 | int arch_bp_generic_fields(int sh_len, int sh_type,
         |     ^~~~~~~~~~~~~~~~~~~~~~
   cc1: all warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/cpu/init.c:14:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/cpu/init.c:14:
   include/asm-generic/nommu_context.h: At top level:
>> include/asm-generic/nommu_context.h:13:20: warning: conflicting types for 'switch_mm'
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from arch/sh/kernel/cpu/init.c:14:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   arch/sh/kernel/cpu/init.c:99:29: warning: no previous prototype for 'l2_cache_init' [-Wmissing-prototypes]
      99 | void __attribute__ ((weak)) l2_cache_init(void)
         |                             ^~~~~~~~~~~~~
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from kernel/fork.c:101:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from kernel/fork.c:101:
   include/asm-generic/nommu_context.h: At top level:
>> include/asm-generic/nommu_context.h:13:20: warning: conflicting types for 'switch_mm'
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from kernel/fork.c:101:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from kernel/exit.c:69:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from kernel/exit.c:69:
   include/asm-generic/nommu_context.h: At top level:
>> include/asm-generic/nommu_context.h:13:20: warning: conflicting types for 'switch_mm'
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from kernel/exit.c:69:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   kernel/exit.c:1714:13: warning: no previous prototype for 'abort' [-Wmissing-prototypes]
    1714 | __weak void abort(void)
         |             ^~~~~
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from include/linux/mmu_context.h:5,
                    from kernel/sched/sched.h:54,
                    from kernel/sched/rt.c:6:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from include/linux/mmu_context.h:5,
                    from kernel/sched/sched.h:54,
                    from kernel/sched/rt.c:6:
   include/asm-generic/nommu_context.h: At top level:
>> include/asm-generic/nommu_context.h:13:20: warning: conflicting types for 'switch_mm'
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from include/linux/mmu_context.h:5,
                    from kernel/sched/sched.h:54,
                    from kernel/sched/rt.c:6:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   kernel/sched/rt.c:668:6: warning: no previous prototype for 'sched_rt_bandwidth_account' [-Wmissing-prototypes]
     668 | bool sched_rt_bandwidth_account(struct rt_rq *rt_rq)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from mm/nommu.c:43:
   include/asm-generic/mmu_context.h: In function 'activate_mm':
   include/asm-generic/mmu_context.h:59:2: error: implicit declaration of function 'switch_mm' [-Werror=implicit-function-declaration]
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   In file included from arch/sh/include/asm/mmu_context.h:137,
                    from mm/nommu.c:43:
   include/asm-generic/nommu_context.h: At top level:
>> include/asm-generic/nommu_context.h:13:20: warning: conflicting types for 'switch_mm'
      13 | static inline void switch_mm(struct mm_struct *prev,
         |                    ^~~~~~~~~
>> include/asm-generic/nommu_context.h:13:20: error: static declaration of 'switch_mm' follows non-static declaration
   In file included from include/asm-generic/nommu_context.h:11,
                    from arch/sh/include/asm/mmu_context.h:137,
                    from mm/nommu.c:43:
   include/asm-generic/mmu_context.h:59:2: note: previous implicit declaration of 'switch_mm' was here
      59 |  switch_mm(prev_mm, next_mm, current);
         |  ^~~~~~~~~
   mm/nommu.c:1665:15: warning: no previous prototype for 'arch_get_unmapped_area' [-Wmissing-prototypes]
    1665 | unsigned long arch_get_unmapped_area(struct file *file, unsigned long addr,
         |               ^~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/switch_mm +13 include/asm-generic/nommu_context.h

    12	
  > 13	static inline void switch_mm(struct mm_struct *prev,
    14				struct mm_struct *next,
    15				struct task_struct *tsk)
    16	{
    17	}
    18	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Nicholas Piggin Aug. 26, 2020, 1:59 p.m. UTC | #5
Excerpts from Vineet Gupta's message of July 28, 2020 2:01 pm:
> On 7/27/20 8:33 PM, Nicholas Piggin wrote:
>> Many of these are no-ops on many architectures, so extend mmu_context.h
>> to cover MMU and NOMMU, and split the NOMMU bits out to nommu_context.h
>> 
> 
>> -static inline void switch_mm(struct mm_struct *prev,
>> -			struct mm_struct *next,
>> -			struct task_struct *tsk)
>> +/**
>> + * activate_mm - called after exec switches the current task to a new mm, to switch to it
>> + * @prev_mm: previous mm of this task
>> + * @next_mm: new mm
>> + */
>> +#ifndef activate_mm
>> +static inline void activate_mm(struct mm_struct *prev_mm,
>> +			       struct mm_struct *next_mm)
>>  {
>> +	switch_mm(prev_mm, next_mm, current);
>>  }
>> +#endif
> 
> Is activate_mm() really needed now. It seems most arches have
>    activate_mm(p, n) -> switch_mm(p, n, NULL)

Alpha, nios2, parisc, s390, um, x86 have non-trivial differences,
so it seems to be still needed.

Thanks,
Nick

Patch
diff mbox series

diff --git a/arch/microblaze/include/asm/mmu_context.h b/arch/microblaze/include/asm/mmu_context.h
index f74f9da07fdc..34004efb3def 100644
--- a/arch/microblaze/include/asm/mmu_context.h
+++ b/arch/microblaze/include/asm/mmu_context.h
@@ -2,5 +2,5 @@ 
 #ifdef CONFIG_MMU
 # include <asm/mmu_context_mm.h>
 #else
-# include <asm-generic/mmu_context.h>
+# include <asm-generic/nommu_context.h>
 #endif
diff --git a/arch/sh/include/asm/mmu_context.h b/arch/sh/include/asm/mmu_context.h
index 48e67d544d53..9470d17c71c2 100644
--- a/arch/sh/include/asm/mmu_context.h
+++ b/arch/sh/include/asm/mmu_context.h
@@ -134,7 +134,7 @@  static inline void switch_mm(struct mm_struct *prev,
 #define set_TTB(pgd)			do { } while (0)
 #define get_TTB()			(0)
 
-#include <asm-generic/mmu_context.h>
+#include <asm-generic/nommu_context.h>
 
 #endif /* CONFIG_MMU */
 
diff --git a/include/asm-generic/mmu_context.h b/include/asm-generic/mmu_context.h
index 6be9106fb6fb..86cea80a50df 100644
--- a/include/asm-generic/mmu_context.h
+++ b/include/asm-generic/mmu_context.h
@@ -3,44 +3,73 @@ 
 #define __ASM_GENERIC_MMU_CONTEXT_H
 
 /*
- * Generic hooks for NOMMU architectures, which do not need to do
- * anything special here.
+ * Generic hooks to implement no-op functionality.
  */
 
-#include <asm-generic/mm_hooks.h>
-
 struct task_struct;
 struct mm_struct;
 
+/*
+ * enter_lazy_tlb - Called when "tsk" is about to enter lazy TLB mode.
+ *
+ * @mm:  the currently active mm context which is becoming lazy
+ * @tsk: task which is entering lazy tlb
+ *
+ * tsk->mm will be NULL
+ */
+#ifndef enter_lazy_tlb
 static inline void enter_lazy_tlb(struct mm_struct *mm,
 			struct task_struct *tsk)
 {
 }
+#endif
 
+/**
+ * init_new_context - Initialize context of a new mm_struct.
+ * @tsk: task struct for the mm
+ * @mm:  the new mm struct
+ */
+#ifndef init_new_context
 static inline int init_new_context(struct task_struct *tsk,
 			struct mm_struct *mm)
 {
 	return 0;
 }
+#endif
 
+/**
+ * destroy_context - Undo init_new_context when the mm is going away
+ * @mm: old mm struct
+ */
+#ifndef destroy_context
 static inline void destroy_context(struct mm_struct *mm)
 {
 }
+#endif
 
-static inline void deactivate_mm(struct task_struct *task,
-			struct mm_struct *mm)
-{
-}
-
-static inline void switch_mm(struct mm_struct *prev,
-			struct mm_struct *next,
-			struct task_struct *tsk)
+/**
+ * activate_mm - called after exec switches the current task to a new mm, to switch to it
+ * @prev_mm: previous mm of this task
+ * @next_mm: new mm
+ */
+#ifndef activate_mm
+static inline void activate_mm(struct mm_struct *prev_mm,
+			       struct mm_struct *next_mm)
 {
+	switch_mm(prev_mm, next_mm, current);
 }
+#endif
 
-static inline void activate_mm(struct mm_struct *prev_mm,
-			       struct mm_struct *next_mm)
+/**
+ * dectivate_mm - called when an mm is released after exit or exec switches away from it
+ * @tsk: the task
+ * @mm:  the old mm
+ */
+#ifndef deactivate_mm
+static inline void deactivate_mm(struct task_struct *tsk,
+			struct mm_struct *mm)
 {
 }
+#endif
 
 #endif /* __ASM_GENERIC_MMU_CONTEXT_H */
diff --git a/include/asm-generic/nommu_context.h b/include/asm-generic/nommu_context.h
new file mode 100644
index 000000000000..72b8d8b1d81e
--- /dev/null
+++ b/include/asm-generic/nommu_context.h
@@ -0,0 +1,19 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_GENERIC_NOMMU_H
+#define __ASM_GENERIC_NOMMU_H
+
+/*
+ * Generic hooks for NOMMU architectures, which do not need to do
+ * anything special here.
+ */
+
+#include <asm-generic/mm_hooks.h>
+#include <asm-generic/mmu_context.h>
+
+static inline void switch_mm(struct mm_struct *prev,
+			struct mm_struct *next,
+			struct task_struct *tsk)
+{
+}
+
+#endif /* __ASM_GENERIC_NOMMU_H */