mmu_context.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/module.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. * Called by the retry thread execute retries within the
  15. * iocb issuer's mm context, so that copy_from/to_user
  16. * operations work seamlessly for aio.
  17. * (Note: this routine is intended to be called only
  18. * from a kernel thread context)
  19. */
  20. void use_mm(struct mm_struct *mm)
  21. {
  22. struct mm_struct *active_mm;
  23. struct task_struct *tsk = current;
  24. task_lock(tsk);
  25. active_mm = tsk->active_mm;
  26. if (active_mm != mm) {
  27. atomic_inc(&mm->mm_count);
  28. tsk->active_mm = mm;
  29. }
  30. tsk->mm = mm;
  31. switch_mm(active_mm, mm, tsk);
  32. task_unlock(tsk);
  33. if (active_mm != mm)
  34. mmdrop(active_mm);
  35. }
  36. EXPORT_SYMBOL_GPL(use_mm);
  37. /*
  38. * unuse_mm
  39. * Reverses the effect of use_mm, i.e. releases the
  40. * specified mm context which was earlier taken on
  41. * by the calling kernel thread
  42. * (Note: this routine is intended to be called only
  43. * from a kernel thread context)
  44. */
  45. void unuse_mm(struct mm_struct *mm)
  46. {
  47. struct task_struct *tsk = current;
  48. task_lock(tsk);
  49. sync_mm_rss(tsk, mm);
  50. tsk->mm = NULL;
  51. /* active_mm is still 'mm' */
  52. enter_lazy_tlb(mm, tsk);
  53. task_unlock(tsk);
  54. }
  55. EXPORT_SYMBOL_GPL(unuse_mm);