← Documents Documentation/infiniband/core_locking.rst GitHub 원문 ↗

Linux 6.18.37 · InfiniBand

InfiniBand Midlayer Locking

InfiniBand ib_device의 sleep·재진입 규칙, CQ callback 직렬화와 hot-plug 수명 주기를 설명합니다.

Source pathDocumentation/infiniband/core_locking.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

core_locking.rst:1-116

InfiniBand midlayer는 호출을 직렬화하지 않으므로 low-level driver가 완전한 재진입성과 동기화를 보장해야 합니다. 일부 method는 어떤 context에서도 호출 가능해야 하고, 같은 CQ callback은 동시에 실행할 수 없으며, 등록·해제 경계에서 driver와 consumer의 resource 수명이 엄격히 이어져야 합니다.

문서 개요
항목내용
SourceDocumentation/infiniband/core_locking.rst
분량116 source lines
Non-sleeping methods8
Callback rule같은 CQ handler 직렬화

원문 분량과 핵심 대상을 요약합니다.

핵심 흐름
Method context 분류Driver 내부 synchronizationCallback deferred executionCQ handler 직렬화Hot-plug cleanup 완료

적용 순서를 압축합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

InfiniBand midlayer 잠금 가정

1-9

이 안내서는 InfiniBand midlayer가 전제로 하는 잠금 가정을 명시하려는 문서입니다.

Midlayer 아래에 위치한 low-level driver와 midlayer를 사용하는 upper-level protocol 양쪽에 대한 요구사항을 설명합니다.

InfiniBand locking 책임
계층문서가 규정하는 대상
Low-level driver`ib_device` 구현, callback·hot-plug 동기화
IB midlayer호출 전달, 자체 serialization 없음
Upper-level protocol호출 context와 callback 제약 준수

Midlayer 위·아래 구성요소의 역할을 구분합니다.

===========================
InfiniBand Midlayer Locking
===========================

  This guide is an attempt to make explicit the locking assumptions
  made by the InfiniBand midlayer.  It describes the requirements on
  both low-level drivers that sit below the midlayer and upper level
  protocols that use the midlayer.

Sleep 가능 여부와 호출 context

10-47

아래 예외를 제외하면 low-level driver가 구현한 `struct ib_device`의 모든 method는 sleep할 수 있습니다.

Sleep할 수 없는 `ib_device` methods
순서Method
1`create_ah`
2`modify_ah`
3`query_ah`
4`destroy_ah`
5`post_send`
6`post_recv`
7`poll_cq`
8`req_notify_cq`

어떤 context에서도 호출 가능해야 하는 여덟 method입니다.

이 여덟 method는 sleep하면 안 되며 어떤 context에서도 호출할 수 있어야 합니다.

이에 대응해 upper-level protocol consumer에 export되는 함수도 어떤 context에서나 안전하게 호출할 수 있습니다.

모든 context에서 안전한 exported functions
Low-level methodExported function
`create_ah``rdma_create_ah`
`modify_ah``rdma_modify_ah`
`query_ah``rdma_query_ah`
`destroy_ah``rdma_destroy_ah`
`post_send``ib_post_send`
`post_recv``ib_post_recv`
`req_notify_cq``ib_req_notify_cq`

Low-level non-sleeping method에 대응하는 일곱 consumer API입니다.

Low-level driver가 midlayer를 통해 asynchronous event를 dispatch하는 데 사용하는 `ib_dispatch_event`도 어떤 context에서나 안전하게 호출할 수 있습니다.

호출 context 판단
`struct ib_device` method 확인예외 목록 8개에 있으면 sleep 금지어떤 context에서도 호출 가능하게 구현대응 exported API도 any-context safeAsync dispatch는 `ib_dispatch_event` 사용

Sleep 가능 여부를 method별로 판단하는 흐름입니다.

Sleeping and interrupt context
==============================

  With the following exceptions, a low-level driver implementation of
  all of the methods in struct ib_device may sleep.  The exceptions
  are any methods from the list:

    - create_ah
    - modify_ah
    - query_ah
    - destroy_ah
    - post_send
    - post_recv
    - poll_cq
    - req_notify_cq

  which may not sleep and must be callable from any context.

  The corresponding functions exported to upper level protocol
  consumers:

    - rdma_create_ah
    - rdma_modify_ah
    - rdma_query_ah
    - rdma_destroy_ah
    - ib_post_send
    - ib_post_recv
    - ib_req_notify_cq

  are therefore safe to call from any context.

  In addition, the function

    - ib_dispatch_event

  used by low-level drivers to dispatch asynchronous events through
  the midlayer is also safe to call from any context.

완전한 재진입성과 호출 순서

48-65

Low-level driver가 export하는 `struct ib_device`의 모든 method는 완전하게 reentrant해야 합니다.

같은 객체를 사용하는 여러 함수 호출이 동시에 실행되더라도 일관성을 유지하는 데 필요한 모든 synchronization은 low-level driver가 수행해야 합니다.

IB midlayer는 함수 호출을 전혀 직렬화하지 않습니다.

Low-level driver가 reentrant하므로 upper-level protocol consumer는 serialization을 수행할 의무가 없습니다. 다만 의미 있는 결과를 얻기 위해 일부 직렬화가 필요할 수 있습니다.

예를 들어 consumer는 여러 CPU에서 `ib_poll_cq()`를 동시에 호출해도 안전하지만, 서로 다른 `ib_poll_cq()` 호출이 반환하는 work completion 정보의 순서는 정의되어 있지 않습니다.

재진입성과 serialization
주체·호출요구사항·보장
Low-level driver모든 `ib_device` method 완전 reentrant
IB midlayerFunction call serialization 수행하지 않음
Upper-level consumer안전성 위한 serialization 불필요
동시 `ib_poll_cq()`호출 안전, call 간 completion 순서 미정의

안전성 책임과 결과 순서 보장 여부를 구분합니다.

동시 호출 처리
여러 CPU가 같은 object method 호출Midlayer는 그대로 전달Driver 내부 synchronization 적용일관성 유지필요한 경우 consumer가 결과 의미를 위해 추가 serialization

같은 객체에 대한 병렬 호출이 처리되는 원칙입니다.

Reentrancy
----------

  All of the methods in struct ib_device exported by a low-level
  driver must be fully reentrant.  The low-level driver is required to
  perform all synchronization necessary to maintain consistency, even
  if multiple function calls using the same object are run
  simultaneously.

  The IB midlayer does not perform any serialization of function calls.

  Because low-level drivers are reentrant, upper level protocol
  consumers are not required to perform any serialization.  However,
  some serialization may be required to get sensible results.  For
  example, a consumer may safely call ib_poll_cq() on multiple CPUs
  simultaneously.  However, the ordering of the work completion
  information between different calls of ib_poll_cq() is not defined.

Callback 지연·CQ 직렬화·실행 context

66-97

Low-level driver는 `ib_device` method 호출과 같은 callchain에서 callback을 직접 실행하면 안 됩니다.

예를 들어 `post_send` method에서 consumer의 completion event handler를 직접 호출할 수 없습니다. 대신 tasklet을 schedule하는 등의 방법으로 callback을 지연해야 합니다.

올바른 completion callback 전달
Consumer가 `post_send` 같은 method 호출Low-level driver가 요청 처리같은 callchain에서는 callback 금지Tasklet 등 deferred mechanism schedule별도 실행에서 completion callback 호출

같은 callchain의 직접 callback을 피하는 흐름입니다.

Low-level driver는 같은 CQ에 대한 여러 completion event handler가 동시에 호출되지 않도록 해야 합니다. 특정 CQ에서는 언제나 CQ event handler 하나만 실행 중이어야 합니다.

금지된 동시 CQ callback 시나리오
단계CPU1CPU2
1Low-level driver가 consumer CQ event callback 진입대기
2Callback 내부 작업대기
3`ib_req_notify_cq(cq, ...)` 호출대기
4첫 callback이 아직 반환하지 않음Low-level driver가 같은 CQ callback 진입
5첫 CQ event handler 반환두 번째 callback 실행 중

원문의 CPU1/CPU2 ASCII 타임라인을 단계별 병렬 표로 재구성했습니다.

위 표처럼 CPU1의 handler가 반환하기 전에 CPU2에서 같은 CQ의 handler가 시작되는 상황은 허용되지 않습니다.

Completion event와 asynchronous event callback이 실행되는 context는 정의되어 있지 않습니다. Low-level driver에 따라 process context, softirq context, interrupt context일 수 있습니다.

Upper-level protocol consumer는 callback 안에서 sleep하면 안 됩니다.

Callback context 규칙
항목규칙
가능한 contextProcess, softirq, interrupt
정확한 contextLow-level driver에 따라 달라지며 미정의
Consumer callbackSleep 금지
같은 CQEvent handler 동시 실행 금지

실행 가능한 context와 consumer 제약입니다.

Callbacks
---------

  A low-level driver must not perform a callback directly from the
  same callchain as an ib_device method call.  For example, it is not
  allowed for a low-level driver to call a consumer's completion event
  handler directly from its post_send method.  Instead, the low-level
  driver should defer this callback by, for example, scheduling a
  tasklet to perform the callback.

  The low-level driver is responsible for ensuring that multiple
  completion event handlers for the same CQ are not called
  simultaneously.  The driver must guarantee that only one CQ event
  handler for a given CQ is running at a time.  In other words, the
  following situation is not allowed::

          CPU1                                    CPU2

    low-level driver ->
      consumer CQ event callback:
        /* ... */
        ib_req_notify_cq(cq, ...);
                                          low-level driver ->
        /* ... */                           consumer CQ event callback:
                                              /* ... */
        return from CQ event handler

  The context in which completion event and asynchronous event
  callbacks run is not defined.  Depending on the low-level driver, it
  may be process context, softirq context, or interrupt context.
  Upper level protocol consumers may not sleep in a callback.

장치 등록·해제와 consumer 정리

98-116

Low-level driver는 `ib_register_device()`를 호출할 때 consumer에게 장치 사용 준비가 끝났음을 알립니다. 이 호출 전에 모든 초기화를 완료해야 합니다.

장치는 driver의 `ib_unregister_device()` 호출이 반환할 때까지 계속 사용할 수 있어야 합니다.

Low-level driver는 `ib_register_device()`와 `ib_unregister_device()`를 process context에서 호출해야 합니다.

이 호출 구간에서 consumer가 driver로 callback할 때 deadlock을 일으킬 수 있는 semaphore를 잡고 있으면 안 됩니다.

Upper-level protocol consumer는 해당 장치에 대해 `struct ib_client`의 `add` method가 호출되는 즉시 IB 장치를 사용할 수 있습니다.

Consumer는 `remove` method에서 반환하기 전에 장치와 관련된 모든 정리를 끝내고 모든 resource를 해제해야 합니다.

Consumer는 `add`와 `remove` method 안에서 sleep할 수 있습니다.

InfiniBand hot-plug 계약
단계Low-level driverUpper-level consumer
등록 전모든 initialization 완료아직 사용하지 않음
`ib_register_device()`Process context, deadlock semaphore 금지`add` 호출 뒤 사용 시작
등록 상태장치를 usable 상태로 유지장치 사용
`remove`Unregister 진행반환 전 cleanup·resource free 완료
`ib_unregister_device()` 반환이후 장치 사용 종료 가능장치 참조 없음

Driver와 consumer의 수명 주기 책임을 비교합니다.

IB 장치 hot-plug 수명 주기
Driver가 장치 initialization 완료Process context에서 `ib_register_device()`Consumer `ib_client.add` 호출·사용 시작Consumer `remove`에서 cleanup·free`ib_unregister_device()` 반환까지 장치 usable 유지

초기화부터 consumer 정리와 unregister 완료까지의 순서입니다.

Hot-plug
--------

  A low-level driver announces that a device is ready for use by
  consumers when it calls ib_register_device(), all initialization
  must be complete before this call.  The device must remain usable
  until the driver's call to ib_unregister_device() has returned.

  A low-level driver must call ib_register_device() and
  ib_unregister_device() from process context.  It must not hold any
  semaphores that could cause deadlock if a consumer calls back into
  the driver across these calls.

  An upper level protocol consumer may begin using an IB device as
  soon as the add method of its struct ib_client is called for that
  device.  A consumer must finish all cleanup and free all resources
  relating to a device before returning from the remove method.

  A consumer is permitted to sleep in its add and remove methods.