core_locking.txt 4.0 KB

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