user_verbs.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ======================
  2. Userspace verbs access
  3. ======================
  4. The ib_uverbs module, built by enabling CONFIG_INFINIBAND_USER_VERBS,
  5. enables direct userspace access to IB hardware via "verbs," as
  6. described in chapter 11 of the InfiniBand Architecture Specification.
  7. To use the verbs, the libibverbs library, available from
  8. https://github.com/linux-rdma/rdma-core, is required. libibverbs contains a
  9. device-independent API for using the ib_uverbs interface.
  10. libibverbs also requires appropriate device-dependent kernel and
  11. userspace driver for your InfiniBand hardware. For example, to use
  12. a Mellanox HCA, you will need the ib_mthca kernel module and the
  13. libmthca userspace driver be installed.
  14. User-kernel communication
  15. =========================
  16. Userspace communicates with the kernel for slow path, resource
  17. management operations via the /dev/infiniband/uverbsN character
  18. devices. Fast path operations are typically performed by writing
  19. directly to hardware registers mmap()ed into userspace, with no
  20. system call or context switch into the kernel.
  21. Commands are sent to the kernel via write()s on these device files.
  22. The ABI is defined in drivers/infiniband/include/ib_user_verbs.h.
  23. The structs for commands that require a response from the kernel
  24. contain a 64-bit field used to pass a pointer to an output buffer.
  25. Status is returned to userspace as the return value of the write()
  26. system call.
  27. Resource management
  28. ===================
  29. Since creation and destruction of all IB resources is done by
  30. commands passed through a file descriptor, the kernel can keep track
  31. of which resources are attached to a given userspace context. The
  32. ib_uverbs module maintains idr tables that are used to translate
  33. between kernel pointers and opaque userspace handles, so that kernel
  34. pointers are never exposed to userspace and userspace cannot trick
  35. the kernel into following a bogus pointer.
  36. This also allows the kernel to clean up when a process exits and
  37. prevent one process from touching another process's resources.
  38. Memory pinning
  39. ==============
  40. Direct userspace I/O requires that memory regions that are potential
  41. I/O targets be kept resident at the same physical address. The
  42. ib_uverbs module manages pinning and unpinning memory regions via
  43. get_user_pages() and put_page() calls. It also accounts for the
  44. amount of memory pinned in the process's pinned_vm, and checks that
  45. unprivileged processes do not exceed their RLIMIT_MEMLOCK limit.
  46. Pages that are pinned multiple times are counted each time they are
  47. pinned, so the value of pinned_vm may be an overestimate of the
  48. number of pages pinned by a process.
  49. /dev files
  50. ==========
  51. To create the appropriate character device files automatically with
  52. udev, a rule like::
  53. KERNEL=="uverbs*", NAME="infiniband/%k"
  54. can be used. This will create device nodes named::
  55. /dev/infiniband/uverbs0
  56. and so on. Since the InfiniBand userspace verbs should be safe for
  57. use by non-privileged processes, it may be useful to add an
  58. appropriate MODE or GROUP to the udev rule.