mmu_context.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 2009 Red Hat, Inc.
  2. *
  3. * See ../COPYING for licensing terms.
  4. */
  5. #include <linux/mm.h>
  6. #include <linux/mmu_context.h>
  7. #include <linux/export.h>
  8. #include <linux/sched.h>
  9. #include <asm/mmu_context.h>
  10. /*
  11. * use_mm
  12. * Makes the calling kernel thread take on the specified
  13. * mm context.
  14. * (Note: this routine is intended to be called only
  15. * from a kernel thread context)
  16. */
  17. void use_mm(struct mm_struct *mm)
  18. {
  19. struct mm_struct *active_mm;
  20. struct task_struct *tsk = current;
  21. task_lock(tsk);
  22. active_mm = tsk->active_mm;
  23. if (active_mm != mm) {
  24. atomic_inc(&mm->mm_count);
  25. tsk->active_mm = mm;
  26. }
  27. tsk->mm = mm;
  28. switch_mm(active_mm, mm, tsk);
  29. task_unlock(tsk);
  30. if (active_mm != mm)
  31. mmdrop(active_mm);
  32. }
  33. EXPORT_SYMBOL_GPL(use_mm);
  34. /*
  35. * unuse_mm
  36. * Reverses the effect of use_mm, i.e. releases the
  37. * specified mm context which was earlier taken on
  38. * by the calling kernel thread
  39. * (Note: this routine is intended to be called only
  40. * from a kernel thread context)
  41. */
  42. void unuse_mm(struct mm_struct *mm)
  43. {
  44. struct task_struct *tsk = current;
  45. task_lock(tsk);
  46. sync_mm_rss(mm);
  47. tsk->mm = NULL;
  48. /* active_mm is still 'mm' */
  49. enter_lazy_tlb(mm, tsk);
  50. task_unlock(tsk);
  51. }
  52. EXPORT_SYMBOL_GPL(unuse_mm);