core_locking.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ===========================
  2. InfiniBand Midlayer Locking
  3. ===========================
  4. This guide is an attempt to make explicit the locking assumptions
  5. made by the InfiniBand midlayer. It describes the requirements on
  6. both low-level drivers that sit below the midlayer and upper level
  7. protocols that use the midlayer.
  8. Sleeping and interrupt context
  9. ==============================
  10. With the following exceptions, a low-level driver implementation of
  11. all of the methods in struct ib_device may sleep. The exceptions
  12. are any methods from the list:
  13. - create_ah
  14. - modify_ah
  15. - query_ah
  16. - destroy_ah
  17. - post_send
  18. - post_recv
  19. - poll_cq
  20. - req_notify_cq
  21. which may not sleep and must be callable from any context.
  22. The corresponding functions exported to upper level protocol
  23. consumers:
  24. - rdma_create_ah
  25. - rdma_modify_ah
  26. - rdma_query_ah
  27. - rdma_destroy_ah
  28. - ib_post_send
  29. - ib_post_recv
  30. - ib_req_notify_cq
  31. are therefore safe to call from any context.
  32. In addition, the function
  33. - ib_dispatch_event
  34. used by low-level drivers to dispatch asynchronous events through
  35. the midlayer is also safe to call from any context.
  36. Reentrancy
  37. ----------
  38. All of the methods in struct ib_device exported by a low-level
  39. driver must be fully reentrant. The low-level driver is required to
  40. perform all synchronization necessary to maintain consistency, even
  41. if multiple function calls using the same object are run
  42. simultaneously.
  43. The IB midlayer does not perform any serialization of function calls.
  44. Because low-level drivers are reentrant, upper level protocol
  45. consumers are not required to perform any serialization. However,
  46. some serialization may be required to get sensible results. For
  47. example, a consumer may safely call ib_poll_cq() on multiple CPUs
  48. simultaneously. However, the ordering of the work completion
  49. information between different calls of ib_poll_cq() is not defined.
  50. Callbacks
  51. ---------
  52. A low-level driver must not perform a callback directly from the
  53. same callchain as an ib_device method call. For example, it is not
  54. allowed for a low-level driver to call a consumer's completion event
  55. handler directly from its post_send method. Instead, the low-level
  56. driver should defer this callback by, for example, scheduling a
  57. tasklet to perform the callback.
  58. The low-level driver is responsible for ensuring that multiple
  59. completion event handlers for the same CQ are not called
  60. simultaneously. The driver must guarantee that only one CQ event
  61. handler for a given CQ is running at a time. In other words, the
  62. following situation is not allowed::
  63. CPU1 CPU2
  64. low-level driver ->
  65. consumer CQ event callback:
  66. /* ... */
  67. ib_req_notify_cq(cq, ...);
  68. low-level driver ->
  69. /* ... */ consumer CQ event callback:
  70. /* ... */
  71. return from CQ event handler
  72. The context in which completion event and asynchronous event
  73. callbacks run is not defined. Depending on the low-level driver, it
  74. may be process context, softirq context, or interrupt context.
  75. Upper level protocol consumers may not sleep in a callback.
  76. Hot-plug
  77. --------
  78. A low-level driver announces that a device is ready for use by
  79. consumers when it calls ib_register_device(), all initialization
  80. must be complete before this call. The device must remain usable
  81. until the driver's call to ib_unregister_device() has returned.
  82. A low-level driver must call ib_register_device() and
  83. ib_unregister_device() from process context. It must not hold any
  84. semaphores that could cause deadlock if a consumer calls back into
  85. the driver across these calls.
  86. An upper level protocol consumer may begin using an IB device as
  87. soon as the add method of its struct ib_client is called for that
  88. device. A consumer must finish all cleanup and free all resources
  89. relating to a device before returning from the remove method.
  90. A consumer is permitted to sleep in its add and remove methods.