spu_syscalls.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SPU file system -- system call stubs
  4. *
  5. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  6. * (C) Copyright 2006-2007, IBM Corporation
  7. *
  8. * Author: Arnd Bergmann <arndb@de.ibm.com>
  9. */
  10. #include <linux/file.h>
  11. #include <linux/fs.h>
  12. #include <linux/module.h>
  13. #include <linux/syscalls.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/binfmts.h>
  16. #include <asm/spu.h>
  17. /* protected by rcu */
  18. static struct spufs_calls *spufs_calls;
  19. #ifdef CONFIG_SPU_FS_MODULE
  20. static inline struct spufs_calls *spufs_calls_get(void)
  21. {
  22. struct spufs_calls *calls = NULL;
  23. rcu_read_lock();
  24. calls = rcu_dereference(spufs_calls);
  25. if (calls && !try_module_get(calls->owner))
  26. calls = NULL;
  27. rcu_read_unlock();
  28. return calls;
  29. }
  30. static inline void spufs_calls_put(struct spufs_calls *calls)
  31. {
  32. BUG_ON(calls != spufs_calls);
  33. /* we don't need to rcu this, as we hold a reference to the module */
  34. module_put(spufs_calls->owner);
  35. }
  36. #else /* !defined CONFIG_SPU_FS_MODULE */
  37. static inline struct spufs_calls *spufs_calls_get(void)
  38. {
  39. return spufs_calls;
  40. }
  41. static inline void spufs_calls_put(struct spufs_calls *calls) { }
  42. #endif /* CONFIG_SPU_FS_MODULE */
  43. SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
  44. umode_t, mode, int, neighbor_fd)
  45. {
  46. long ret;
  47. struct spufs_calls *calls;
  48. calls = spufs_calls_get();
  49. if (!calls)
  50. return -ENOSYS;
  51. if (flags & SPU_CREATE_AFFINITY_SPU) {
  52. struct fd neighbor = fdget(neighbor_fd);
  53. ret = -EBADF;
  54. if (fd_file(neighbor)) {
  55. ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
  56. fdput(neighbor);
  57. }
  58. } else
  59. ret = calls->create_thread(name, flags, mode, NULL);
  60. spufs_calls_put(calls);
  61. return ret;
  62. }
  63. SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)
  64. {
  65. long ret;
  66. struct fd arg;
  67. struct spufs_calls *calls;
  68. calls = spufs_calls_get();
  69. if (!calls)
  70. return -ENOSYS;
  71. ret = -EBADF;
  72. arg = fdget(fd);
  73. if (fd_file(arg)) {
  74. ret = calls->spu_run(fd_file(arg), unpc, ustatus);
  75. fdput(arg);
  76. }
  77. spufs_calls_put(calls);
  78. return ret;
  79. }
  80. #ifdef CONFIG_COREDUMP
  81. int elf_coredump_extra_notes_size(void)
  82. {
  83. struct spufs_calls *calls;
  84. int ret;
  85. calls = spufs_calls_get();
  86. if (!calls)
  87. return 0;
  88. ret = calls->coredump_extra_notes_size();
  89. spufs_calls_put(calls);
  90. return ret;
  91. }
  92. int elf_coredump_extra_notes_write(struct coredump_params *cprm)
  93. {
  94. struct spufs_calls *calls;
  95. int ret;
  96. calls = spufs_calls_get();
  97. if (!calls)
  98. return 0;
  99. ret = calls->coredump_extra_notes_write(cprm);
  100. spufs_calls_put(calls);
  101. return ret;
  102. }
  103. #endif
  104. void notify_spus_active(void)
  105. {
  106. struct spufs_calls *calls;
  107. calls = spufs_calls_get();
  108. if (!calls)
  109. return;
  110. calls->notify_spus_active();
  111. spufs_calls_put(calls);
  112. return;
  113. }
  114. int register_spu_syscalls(struct spufs_calls *calls)
  115. {
  116. if (spufs_calls)
  117. return -EBUSY;
  118. rcu_assign_pointer(spufs_calls, calls);
  119. return 0;
  120. }
  121. EXPORT_SYMBOL_GPL(register_spu_syscalls);
  122. void unregister_spu_syscalls(struct spufs_calls *calls)
  123. {
  124. BUG_ON(spufs_calls->owner != calls->owner);
  125. RCU_INIT_POINTER(spufs_calls, NULL);
  126. synchronize_rcu();
  127. }
  128. EXPORT_SYMBOL_GPL(unregister_spu_syscalls);