linux-4.6.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. --- /dev/null
  2. +++ b/kernel/nv-mm.h
  3. @@ -0,0 +1,55 @@
  4. +/*******************************************************************************
  5. + Copyright (c) 2016 NVIDIA Corporation
  6. +
  7. + Permission is hereby granted, free of charge, to any person obtaining a copy
  8. + of this software and associated documentation files (the "Software"), to
  9. + deal in the Software without restriction, including without limitation the
  10. + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  11. + sell copies of the Software, and to permit persons to whom the Software is
  12. + furnished to do so, subject to the following conditions:
  13. +
  14. + The above copyright notice and this permission notice shall be
  15. + included in all copies or substantial portions of the Software.
  16. +
  17. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. + DEALINGS IN THE SOFTWARE.
  24. +
  25. +*******************************************************************************/
  26. +#ifndef __NV_MM_H__
  27. +#define __NV_MM_H__
  28. +
  29. +/* get_user_pages_remote() was added by:
  30. + * 2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
  31. + *
  32. + * The very next commit (cde70140fed8429acf7a14e2e2cbd3e329036653)
  33. + * deprecated the 8-argument version of get_user_pages for the
  34. + * non-remote case (calling get_user_pages with current and current->mm).
  35. + *
  36. + * The guidelines are: call NV_GET_USER_PAGES_REMOTE if you need the 8-argument
  37. + * version that uses something other than current and current->mm. Use
  38. + * NV_GET_USER_PAGES if you are refering to current and current->mm.
  39. + *
  40. +* Note that get_user_pages_remote() requires the caller to hold a reference on
  41. +* the task_struct (if non-NULL) and the mm_struct. This will always be true
  42. +* when using current and current->mm. If the kernel passes the driver a vma
  43. +* via driver callback, the kernel holds a reference on vma->vm_mm over that
  44. +* callback.
  45. + */
  46. +
  47. +#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT)
  48. + #define NV_GET_USER_PAGES get_user_pages
  49. + #define NV_GET_USER_PAGES_REMOTE get_user_pages_remote
  50. +#else
  51. + #define NV_GET_USER_PAGES(start, nr_pages, write, force, pages, vmas) \
  52. + get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
  53. +
  54. + #define NV_GET_USER_PAGES_REMOTE get_user_pages
  55. +#endif
  56. +
  57. +
  58. +#endif // __NV_MM_H__
  59. --- a/kernel/nv-mlock.c
  60. +++ b/kernel/nv-mlock.c
  61. @@ -13,6 +13,7 @@
  62. #include "os-interface.h"
  63. #include "nv-linux.h"
  64. +#include "nv-mm.h"
  65. RM_STATUS NV_API_CALL nv_lock_user_pages(
  66. nv_state_t *nv,
  67. @@ -49,7 +50,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
  68. }
  69. down_read(&mm->mmap_sem);
  70. - ret = get_user_pages(current, mm, (unsigned long)address,
  71. + ret = NV_GET_USER_PAGES((unsigned long)address,
  72. page_count, write, force, user_pages, NULL);
  73. up_read(&mm->mmap_sem);
  74. pinned = ret;
  75. @@ -62,7 +62,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
  76. else if (pinned < page_count)
  77. {
  78. for (i = 0; i < pinned; i++)
  79. - page_cache_release(user_pages[i]);
  80. + put_page(user_pages[i]);
  81. os_free_mem(user_pages);
  82. return RM_ERR_INVALID_ADDRESS;
  83. }
  84. @@ -81,7 +81,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
  85. {
  86. pci_unmap_page(dev, pte_array[j],
  87. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  88. - page_cache_release(user_pages[j]);
  89. + put_page(user_pages[j]);
  90. }
  91. os_free_mem(user_pages);
  92. return RM_ERR_OPERATING_SYSTEM;
  93. @@ -114,7 +114,7 @@ RM_STATUS NV_API_CALL os_unlock_user_pages(
  94. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  95. if (write)
  96. set_page_dirty_lock(user_pages[i]);
  97. - page_cache_release(user_pages[i]);
  98. + put_page(user_pages[i]);
  99. }
  100. os_free_mem(user_pages);
  101. diff --git a/kernel/conftest.sh.orig b/kernel/conftest.sh
  102. index d01488b..308ea8a 100755
  103. --- a/kernel/conftest.sh
  104. +++ b/kernel/conftest.sh
  105. @@ -1525,6 +1525,23 @@ compile_test() {
  106. compile_check_conftest "$CODE" "NV_NODE_END_PFN_PRESENT" "" "functions"
  107. ;;
  108. +
  109. + get_user_pages_remote)
  110. + #
  111. + # Determine if the function get_user_pages_remote() is
  112. + # present.
  113. + #
  114. + # get_user_pages_remote() was added by:
  115. + # 2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
  116. + #
  117. + CODE="
  118. + #include <linux/mm.h>
  119. + int conftest_get_user_pages_remote(void) {
  120. + get_user_pages_remote();
  121. + }"
  122. +
  123. + compile_check_conftest "$CODE" "NV_GET_USER_PAGES_REMOTE_PRESENT" "" "functions"
  124. + ;;
  125. esac
  126. }
  127. --- a/kernel/Makefile.kbuild
  128. +++ b/kernel/Makefile.kbuild
  129. @@ -187,7 +187,8 @@ COMPILE_TESTS = \
  130. drm_pci_set_busid \
  131. write_cr4 \
  132. for_each_online_node \
  133. - node_end_pfn
  134. + node_end_pfn \
  135. + get_user_pages_remote
  136. #
  137. # CFLAGS dependent on the type of builds (e.g. single/muliple module, debug)