mmu_context_64.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * MMU context allocation for 64-bit kernels.
  3. *
  4. * Copyright (C) 2004 Anton Blanchard, IBM Corp. <anton@samba.org>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <linux/mm.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/idr.h>
  20. #include <asm/mmu_context.h>
  21. static DEFINE_SPINLOCK(mmu_context_lock);
  22. static DEFINE_IDR(mmu_context_idr);
  23. int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  24. {
  25. int index;
  26. int err;
  27. again:
  28. if (!idr_pre_get(&mmu_context_idr, GFP_KERNEL))
  29. return -ENOMEM;
  30. spin_lock(&mmu_context_lock);
  31. err = idr_get_new_above(&mmu_context_idr, NULL, 1, &index);
  32. spin_unlock(&mmu_context_lock);
  33. if (err == -EAGAIN)
  34. goto again;
  35. else if (err)
  36. return err;
  37. if (index > MAX_CONTEXT) {
  38. spin_lock(&mmu_context_lock);
  39. idr_remove(&mmu_context_idr, index);
  40. spin_unlock(&mmu_context_lock);
  41. return -ENOMEM;
  42. }
  43. /* The old code would re-promote on fork, we don't do that
  44. * when using slices as it could cause problem promoting slices
  45. * that have been forced down to 4K
  46. */
  47. if (slice_mm_new_context(mm))
  48. slice_set_user_psize(mm, mmu_virtual_psize);
  49. mm->context.id = index;
  50. return 0;
  51. }
  52. void destroy_context(struct mm_struct *mm)
  53. {
  54. spin_lock(&mmu_context_lock);
  55. idr_remove(&mmu_context_idr, mm->context.id);
  56. spin_unlock(&mmu_context_lock);
  57. mm->context.id = NO_CONTEXT;
  58. }