| 0/0 |
2026/10/21 00:58 |
flow |
assessment-security |
1h08m
Results: map[DenialOfService:true Explanation:### Security Impact Analysis
#### 1. Vulnerability Mechanism
The warning occurs in `__rxe_cleanup()`
(`drivers/infiniband/sw/rxe/rxe_pool.c:212`) when destroying an RXE Queue Pair
(`struct rxe_qp`) during RDS connection shutdown (`rds_shutdown_worker` ->
`rds_conn_shutdown` -> `rds_ib_conn_path_shutdown` -> `rdma_destroy_qp` ->
`ib_destroy_qp_user` -> `rxe_destroy_qp`):
```c
xa_ret = xa_erase(xa, elem->index);
WARN_ON(xa_err(xa_ret));
/* if this is the last call to rxe_put complete the
* object can berelleased safely. Otherwise wait until
* the last reference is dropped. Lookups via xarray
* cannot add references since the object is already
* removed from the xarray.
*/
__rxe_put(elem);
if (sleepable) {
if (!completion_done(&elem->complete)) {
ret = wait_for_completion_timeout(&elem->complete,
msecs_to_jiffies(50000));
if (WARN_ON(!ret))
err = -ETIMEDOUT;
}
}
if (pool->cleanup)
pool->cleanup(elem);
```
When `elem->complete` is not signaled within 50 seconds (`ret == 0`), at least
one reference to `qp` (`elem->ref_cnt`) is still held (for example, by a
scheduled or stalled `rxe_wq` task, an undrained packet queued in `qp->req_pkts`
/ `qp->resp_pkts`, or an in-flight `sk_buff` with destructor `rxe_skb_tx_dtor`).
#### 2. Exploitability (`Exploitable: true`)
Although the report itself is a `WARN_ON(!ret)` upon timeout, what happens
immediately after the warning in production builds makes this a **Use-After-Free
(UAF)** vulnerability:
1. Even when `wait_for_completion_timeout()` times out and sets `err =
-ETIMEDOUT`, `__rxe_cleanup()` still proceeds to invoke `pool->cleanup(elem)`
(`rxe_qp_cleanup` -> `rxe_qp_do_cleanup`), which tears down the QP's internal
state, queues, and pointers while another reference holder still exists.
2. In `rxe_destroy_qp()` (`drivers/infiniband/sw/rxe/rxe_verbs.c:650-668`), the
error returned by `rxe_cleanup(qp)` is logged via `rxe_err_qp()` and then
ignoredβ`rxe_destroy_qp()` unconditionally returns `0`:
```c
ret = rxe_cleanup(qp);
if (ret)
rxe_err_qp(qp, "cleanup failed, err = %d\n", ret);
...
return 0;
```
3. Because `destroy_qp` returns `0`, `ib_destroy_qp_user()`
(`drivers/infiniband/core/verbs.c:2182, 2204`) immediately frees the `qp`
allocation via `kfree(qp)`.
4. When the outstanding reference holder (e.g., `rxe_skb_tx_dtor`, `do_task` on
`rxe_wq`, or timer/packet cleanup) subsequently accesses `qp` or calls
`rxe_put(qp)`, it operates on freed slab memory, causing a Use-After-Free.
#### 3. Denial of Service (`DenialOfService: true`)
Each timeout blocks the `krds_cp_wq` workqueue worker for 50 seconds
(`msecs_to_jiffies(50000)`), accompanied by CPU softlockups (`Tainted:
[L]=SOFTLOCKUP`), and ultimately corrupts kernel memory when the
still-referenced `struct rxe_qp` is freed.
#### 4. Accessibility (`Unprivileged: true`, `UserNamespace: true`)
When an RXE device is present on the system:
- Opening an `AF_RDS` socket (`rds_create()` in `net/rds/af_rds.c`) requires no
capabilities (`socket(AF_RDS, SOCK_SEQPACKET, 0)`). Any unprivileged local user
can bind and initiate/drop RDS connections over the RXE transport.
- Additionally, RDMA user verbs character devices (`/dev/infiniband/uverbs*` and
`/dev/infiniband/rdma_cm`) are created with `0666` permissions by default,
allowing unprivileged userspace processes (and processes inside user namespaces)
to directly create and destroy RXE QPs. Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/10/21 00:58 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/10/21 00:58 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/3f6eb11e634c7f0e76893d1bf9745a0ef46d922a]
|
| 3/1 |
2026/10/21 00:58 |
action |
kernel-builder |
31m
Results: map[KernelObj:/app/workdir/cache/build/465adf1d7a57dcb9eb51851487eac8b8b5434a7b]
|
| 4/1 |
2026/10/21 01:30 |
action |
codesearch-prepare |
23m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/10/21 01:53 |
agent |
expert |
14m
Model:
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
------------[ cut here ]------------
!ret
WARNING: drivers/infiniband/sw/rxe/rxe_pool.c:212 at __rxe_cleanup+0x311/0x350 drivers/infiniband/sw/rxe/rxe_pool.c:212, CPU#0: kworker/u8:9/3389
Modules linked in:
CPU: 0 UID: 0 PID: 3389 Comm: kworker/u8:9 Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2026
Workqueue: krds_cp_wq#0/0 rds_shutdown_worker
RIP: 0010:__rxe_cleanup+0x311/0x350 drivers/infiniband/sw/rxe/rxe_pool.c:212
Code: f7 be 03 00 00 00 e8 7e 15 e8 fb 40 84 ed 0f 85 26 fe ff ff e9 5b fe ff ff e8 5b 89 cf f8 90 0f 0b 90 eb 09 e8 50 89 cf f8 90 <0f> 0b 90 41 be 92 ff ff ff e9 47 ff ff ff 44 89 f1 80 e1 07 80 c1
RSP: 0018:ffffc9000f2ff6d0 EFLAGS: 00010293
RAX: ffffffff88f888b0 RBX: ffff88807f162250 RCX: ffff888034160000
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000001 R08: ffffffff917a757f R09: 1ffffffff22f4eaf
R10: dffffc0000000000 R11: fffffbfff22f4eb0 R12: ffff88807e7615a0
R13: 00000000ffffffff R14: 0000000000000000 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff888123abf000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ffd5380382c CR3: 000000003558f000 CR4: 0000000000350ef0
Call Trace:
<TASK>
rxe_destroy_qp+0x74/0x270 drivers/infiniband/sw/rxe/rxe_verbs.c:661
ib_destroy_qp_user+0x354/0x5a0 drivers/infiniband/core/verbs.c:2182
ib_destroy_qp include/rdma/ib_verbs.h:4103 [inline]
rdma_destroy_qp+0xd0/0x250 drivers/infiniband/core/cma.c:1170
rds_ib_conn_path_shutdown+0x9bd/0x1820 net/rds/ib_cm.c:1113
rds_conn_shutdown+0x477/0xb20 net/rds/connection.c:440
process_one_work kernel/workqueue.c:3396 [inline]
process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3479
worker_thread+0xa47/0xfb0 kernel/workqueue.c:3560
kthread+0x38b/0x480 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Reply: ### Security Impact Analysis
#### 1. Vulnerability Mechanism
The warning occurs in `__rxe_cleanup()` (`drivers/infiniband/sw/rxe/rxe_pool.c:212`) when destroying an RXE Queue Pair (`struct rxe_qp`) during RDS connection shutdown (`rds_shutdown_worker` -> `rds_conn_shutdown` -> `rds_ib_conn_path_shutdown` -> `rdma_destroy_qp` -> `ib_destroy_qp_user` -> `rxe_destroy_qp`):
```c
xa_ret = xa_erase(xa, elem->index);
WARN_ON(xa_err(xa_ret));
/* if this is the last call to rxe_put complete the
* object can berelleased safely. Otherwise wait until
* the last reference is dropped. Lookups via xarray
* cannot add references since the object is already
* removed from the xarray.
*/
__rxe_put(elem);
if (sleepable) {
if (!completion_done(&elem->complete)) {
ret = wait_for_completion_timeout(&elem->complete,
msecs_to_jiffies(50000));
if (WARN_ON(!ret))
err = -ETIMEDOUT;
}
}
if (pool->cleanup)
pool->cleanup(elem);
```
When `elem->complete` is not signaled within 50 seconds (`ret == 0`), at least one reference to `qp` (`elem->ref_cnt`) is still held (for example, by a scheduled or stalled `rxe_wq` task, an undrained packet queued in `qp->req_pkts` / `qp->resp_pkts`, or an in-flight `sk_buff` with destructor `rxe_skb_tx_dtor`).
#### 2. Exploitability (`Exploitable: true`)
Although the report itself is a `WARN_ON(!ret)` upon timeout, what happens immediately after the warning in production builds makes this a **Use-After-Free (UAF)** vulnerability:
1. Even when `wait_for_completion_timeout()` times out and sets `err = -ETIMEDOUT`, `__rxe_cleanup()` still proceeds to invoke `pool->cleanup(elem)` (`rxe_qp_cleanup` -> `rxe_qp_do_cleanup`), which tears down the QP's internal state, queues, and pointers while another reference holder still exists.
2. In `rxe_destroy_qp()` (`drivers/infiniband/sw/rxe/rxe_verbs.c:650-668`), the error returned by `rxe_cleanup(qp)` is logged via `rxe_err_qp()` and then ignoredβ`rxe_destroy_qp()` unconditionally returns `0`:
```c
ret = rxe_cleanup(qp);
if (ret)
rxe_err_qp(qp, "cleanup failed, err = %d\n", ret);
...
return 0;
```
3. Because `destroy_qp` returns `0`, `ib_destroy_qp_user()` (`drivers/infiniband/core/verbs.c:2182, 2204`) immediately frees the `qp` allocation via `kfree(qp)`.
4. When the outstanding reference holder (e.g., `rxe_skb_tx_dtor`, `do_task` on `rxe_wq`, or timer/packet cleanup) subsequently accesses `qp` or calls `rxe_put(qp)`, it operates on freed slab memory, causing a Use-After-Free.
#### 3. Denial of Service (`DenialOfService: true`)
Each timeout blocks the `krds_cp_wq` workqueue worker for 50 seconds (`msecs_to_jiffies(50000)`), accompanied by CPU softlockups (`Tainted: [L]=SOFTLOCKUP`), and ultimately corrupts kernel memory when the still-referenced `struct rxe_qp` is freed.
#### 4. Accessibility (`Unprivileged: true`, `UserNamespace: true`)
When an RXE device is present on the system:
- Opening an `AF_RDS` socket (`rds_create()` in `net/rds/af_rds.c`) requires no capabilities (`socket(AF_RDS, SOCK_SEQPACKET, 0)`). Any unprivileged local user can bind and initiate/drop RDS connections over the RXE transport.
- Additionally, RDMA user verbs character devices (`/dev/infiniband/uverbs*` and `/dev/infiniband/rdma_cm`) are created with `0666` permissions by default, allowing unprivileged userspace processes (and processes inside user namespaces) to directly create and destroy RXE QPs.
|
| 6/2 |
2026/10/21 01:53 |
llm |
expert |
0m
Model:
Tokens:
input: 7376
output: 183
thoughts: 98
Thoughts: **Initial Bug Triage and Code Navigation**
My first step in tackling this bug is to get a lay of the land. I need to understand the context, which means diving into the bug report and the code that's likely involved. I'm starting by bookmarking the key files I need to examine: `drivers/infiniband/sw/rxe/rxe_pool.c`, `drivers/infiniband/sw/rxe/rxe_verbs.c`, `net/rds/ib_cm.c`, and `net/rds/connection.c`. These seem like the core components handling the relevant logic. To efficiently navigate and understand these files, I'll be leveraging `codesearch-definition-source` to trace function definitions and identify dependencies, and `read-file` to get the actual content and inspect the implementation details.
|
| 7/2 |
2026/10/21 01:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_pool.c Name:__rxe_cleanup]
Results: map[SourceCode: 177: int __rxe_cleanup(struct rxe_pool_elem *elem, bool sleepable)
178: {
179: struct rxe_pool *pool = elem->pool;
180: struct xarray *xa = &pool->xa;
181: int ret, err = 0;
182: void *xa_ret;
183:
184: if (sleepable)
185: might_sleep();
186:
187: /* erase xarray entry to prevent looking up
188: * the pool elem from its index
189: */
190: xa_ret = xa_erase(xa, elem->index);
191: WARN_ON(xa_err(xa_ret));
192:
193: /* if this is the last call to rxe_put complete the
194: * object. It is safe to touch obj->elem after this since
195: * it is freed below
196: */
197: __rxe_put(elem);
198:
199: /* wait until all references to the object have been
200: * dropped before final object specific cleanup and
201: * return to rdma-core
202: */
203: if (sleepable) {
204: if (!completion_done(&elem->complete)) {
205: ret = wait_for_completion_timeout(&elem->complete,
206: msecs_to_jiffies(50000));
207:
208: /* Shouldn't happen. There are still references to
209: * the object but, rather than deadlock, free the
210: * object or pass back to rdma-core.
211: */
212: if (WARN_ON(!ret))
213: err = -ETIMEDOUT;
214: }
215: } else {
216: unsigned long until = jiffies + RXE_POOL_TIMEOUT;
217:
218: /* AH objects are unique in that the destroy_ah verb
219: * can be called in atomic context. This delay
220: * replaces the wait_for_completion call above
221: * when the destroy_ah call is not sleepable
222: */
223: while (!completion_done(&elem->complete) &&
224: time_before(jiffies, until))
225: mdelay(1);
226:
227: if (WARN_ON(!completion_done(&elem->complete)))
228: err = -ETIMEDOUT;
229: }
230:
231: if (pool->cleanup)
232: pool->cleanup(elem);
233:
234: atomic_dec(&pool->num_elem);
235:
236: return err;
237: }
SourceFile:drivers/infiniband/sw/rxe/rxe_pool.c]
|
| 8/2 |
2026/10/21 01:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_verbs.c Name:rxe_destroy_qp]
Results: map[SourceCode: 650: static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
651: {
652: struct rxe_qp *qp = to_rqp(ibqp);
653: int err;
654:
655: err = rxe_qp_chk_destroy(qp);
656: if (err) {
657: rxe_dbg_qp(qp, "unable to destroy qp, err = %d\n", err);
658: goto err_out;
659: }
660:
661: err = rxe_cleanup(qp);
662: if (err)
663: rxe_err_qp(qp, "cleanup failed, err = %d\n", err);
664:
665: return 0;
666:
667: err_out:
668: rxe_err_qp(qp, "returned err = %d\n", err);
669: return err;
670: }
SourceFile:drivers/infiniband/sw/rxe/rxe_verbs.c]
|
| 9/2 |
2026/10/21 01:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/rds/ib_cm.c Name:rds_ib_conn_path_shutdown]
Results: map[SourceCode:1059: /*
1060: * This is so careful about only cleaning up resources that were built up
1061: * so that it can be called at any point during startup. In fact it
1062: * can be called multiple times for a given connection.
1063: */
1064: void rds_ib_conn_path_shutdown(struct rds_conn_path *cp)
1065: {
1066: struct rds_connection *conn = cp->cp_conn;
1067: struct rds_ib_connection *ic = conn->c_transport_data;
1068: int err = 0;
1069:
1070: rdsdebug("cm %p pd %p cq %p %p qp %p\n", ic->i_cm_id,
1071: ic->i_pd, ic->i_send_cq, ic->i_recv_cq,
1072: ic->i_cm_id ? ic->i_cm_id->qp : NULL);
1073:
1074: if (ic->i_cm_id) {
1075: rdsdebug("disconnecting cm %p\n", ic->i_cm_id);
1076: err = rdma_disconnect(ic->i_cm_id);
1077: if (err) {
1078: /* Actually this may happen quite frequently, when
1079: * an outgoing connect raced with an incoming connect.
1080: */
1081: rdsdebug("failed to disconnect, cm: %p err %d\n",
1082: ic->i_cm_id, err);
1083: }
1084:
1085: /* kick off "flush_worker" for all pools in order to reap
1086: * all FRMR registrations that are still marked "FRMR_IS_INUSE"
1087: */
1088: rds_ib_flush_mrs();
1089:
1090: /*
1091: * We want to wait for tx and rx completion to finish
1092: * before we tear down the connection, but we have to be
1093: * careful not to get stuck waiting on a send ring that
1094: * only has unsignaled sends in it. We've shutdown new
1095: * sends before getting here so by waiting for signaled
1096: * sends to complete we're ensured that there will be no
1097: * more tx processing.
1098: */
1099: while (!wait_event_timeout(rds_ib_ring_empty_wait,
1100: rds_ib_conn_path_shutdown_check_wait(cp) == 0,
1101: msecs_to_jiffies(1000))) {
1102: tasklet_schedule(&ic->i_send_tasklet);
1103: tasklet_schedule(&ic->i_recv_tasklet);
1104: }
1105:
1106: tasklet_kill(&ic->i_send_tasklet);
1107: tasklet_kill(&ic->i_recv_tasklet);
1108:
1109: atomic_set(&ic->i_cq_quiesce, 1);
1110:
1111: /* first destroy the ib state that generates callbacks */
1112: if (ic->i_cm_id->qp)
1113: rdma_destroy_qp(ic->i_cm_id);
1114: if (ic->i_send_cq) {
1115: if (ic->rds_ibdev)
1116: ibdev_put_vector(ic->rds_ibdev, ic->i_scq_vector);
1117: ib_destroy_cq(ic->i_send_cq);
1118: }
1119:
1120: if (ic->i_recv_cq) {
1121: if (ic->rds_ibdev)
1122: ibdev_put_vector(ic->rds_ibdev, ic->i_rcq_vector);
1123: ib_destroy_cq(ic->i_recv_cq);
1124: }
1125:
1126: if (ic->rds_ibdev) {
1127: /* then free the resources that ib callbacks use */
1128: if (ic->i_send_hdrs) {
1129: rds_dma_hdrs_free(ic->rds_ibdev,
1130: ic->i_send_hdrs,
1131: ic->i_send_hdrs_dma,
1132: ic->i_send_ring.w_nr,
1133: DMA_TO_DEVICE);
1134: ic->i_send_hdrs = NULL;
1135: ic->i_send_hdrs_dma = NULL;
1136: }
1137:
1138: if (ic->i_recv_hdrs) {
1139: rds_dma_hdrs_free(ic->rds_ibdev,
1140: ic->i_recv_hdrs,
1141: ic->i_recv_hdrs_dma,
1142: ic->i_recv_ring.w_nr,
1143: DMA_FROM_DEVICE);
1144: ic->i_recv_hdrs = NULL;
1145: ic->i_recv_hdrs_dma = NULL;
1146: }
1147:
1148: if (ic->i_ack) {
1149: rds_dma_hdr_free(ic->rds_ibdev->dev, ic->i_ack,
1150: ic->i_ack_dma, DMA_TO_DEVICE);
1151: ic->i_ack = NULL;
1152: }
1153: } else {
1154: WARN_ON(ic->i_send_hdrs);
1155: WARN_ON(ic->i_send_hdrs_dma);
1156: WARN_ON(ic->i_recv_hdrs);
1157: WARN_ON(ic->i_recv_hdrs_dma);
1158: WARN_ON(ic->i_ack);
1159: }
1160:
1161: if (ic->i_sends)
1162: rds_ib_send_clear_ring(ic);
1163: if (ic->i_recvs)
1164: rds_ib_recv_clear_ring(ic);
1165:
1166: rdma_destroy_id(ic->i_cm_id);
1167:
1168: /*
1169: * Move connection back to the nodev list.
1170: */
1171: if (ic->rds_ibdev)
1172: rds_ib_remove_conn(ic->rds_ibdev, conn);
1173:
1174: ic->i_cm_id = NULL;
1175: ic->i_pd = NULL;
1176: ic->i_send_cq = NULL;
1177: ic->i_recv_cq = NULL;
1178: }
1179: BUG_ON(ic->rds_ibdev);
1180:
1181: /* Clear pending transmit */
1182: if (ic->i_data_op) {
1183: struct rds_message *rm;
1184:
1185: rm = container_of(ic->i_data_op, struct rds_message, data);
1186: rds_message_put(rm);
1187: ic->i_data_op = NULL;
1188: }
1189:
1190: /* Clear the ACK state */
1191: clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
1192: #ifdef KERNEL_HAS_ATOMIC64
1193: atomic64_set(&ic->i_ack_next, 0);
1194: #else
1195: ic->i_ack_next = 0;
1196: #endif
1197: ic->i_ack_recv = 0;
1198:
1199: /* Clear flow control state */
1200: ic->i_flowctl = 0;
1201: atomic_set(&ic->i_credits, 0);
1202:
1203: /* Re-init rings, but retain sizes. */
1204: rds_ib_ring_init(&ic->i_send_ring, ic->i_send_ring.w_nr);
1205: rds_ib_ring_init(&ic->i_recv_ring, ic->i_recv_ring.w_nr);
1206:
1207: if (ic->i_ibinc) {
1208: rds_inc_put(&ic->i_ibinc->ii_inc);
1209: ic->i_ibinc = NULL;
1210: }
1211:
1212: vfree(ic->i_sends);
1213: ic->i_sends = NULL;
1214: vfree(ic->i_recvs);
1215: ic->i_recvs = NULL;
1216: ic->i_active_side = false;
1217: }
SourceFile:net/rds/ib_cm.c]
|
| 10/2 |
2026/10/21 01:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/rds/connection.c Name:rds_conn_shutdown]
Results: map[SourceCode: 398: void rds_conn_shutdown(struct rds_conn_path *cp)
399: {
400: struct rds_connection *conn = cp->cp_conn;
401:
402: /* shut it down unless it's down already */
403: if (!rds_conn_path_transition(cp, RDS_CONN_DOWN, RDS_CONN_DOWN)) {
404: /*
405: * Quiesce the connection mgmt handlers before we start tearing
406: * things down. We don't hold the mutex for the entire
407: * duration of the shutdown operation, else we may be
408: * deadlocking with the CM handler. Instead, the CM event
409: * handler is supposed to check for state DISCONNECTING
410: */
411: mutex_lock(&cp->cp_cm_lock);
412: if (!rds_conn_path_transition(cp, RDS_CONN_UP,
413: RDS_CONN_DISCONNECTING) &&
414: !rds_conn_path_transition(cp, RDS_CONN_ERROR,
415: RDS_CONN_DISCONNECTING) &&
416: !rds_conn_path_transition(cp, RDS_CONN_RESETTING,
417: RDS_CONN_DISCONNECTING)) {
418: rds_conn_path_error(cp,
419: "shutdown called in state %d\n",
420: atomic_read(&cp->cp_state));
421: mutex_unlock(&cp->cp_cm_lock);
422: return;
423: }
424: mutex_unlock(&cp->cp_cm_lock);
425:
426: /* Quiesce the transmit and receive-refill paths by
427: * acquiring their bit locks, not merely waiting for
428: * them to be released: with a plain wait, either path
429: * can re-take its lock the instant after we sample it
430: * clear and then run concurrently with the transport
431: * shutdown and the path reset below. Holding both
432: * locks across the teardown makes that structurally
433: * impossible.
434: */
435: wait_event(cp->cp_waitq,
436: !test_and_set_bit_lock(RDS_IN_XMIT, &cp->cp_flags));
437: wait_event(cp->cp_waitq,
438: !test_and_set_bit(RDS_RECV_REFILL, &cp->cp_flags));
439:
440: conn->c_trans->conn_path_shutdown(cp);
441: rds_conn_path_reset(cp);
442:
443: /* Release the two locks and wake any waiter (e.g.
444: * rds_tcp_reset_callbacks()) that blocked on them while
445: * we held them. The unlock orders the transport's ring
446: * re-initialization and the path reset above before
447: * either bit is seen clear. rds_conn_path_reset() leaves
448: * both bits alone: ownership ends here, not inside the
449: * reset.
450: */
451: clear_bit_unlock(RDS_IN_XMIT, &cp->cp_flags);
452: clear_bit_unlock(RDS_RECV_REFILL, &cp->cp_flags);
453: wake_up_all(&cp->cp_waitq);
454:
455: if (!rds_conn_path_transition(cp, RDS_CONN_DISCONNECTING,
456: RDS_CONN_DOWN)) {
457: /* The path was dropped again while we tore it
458: * down: by a socket state-change callback in
459: * irq context on receipt of a FIN, or by an
460: * accept that claimed the path just before a
461: * drop put it back to RDS_CONN_ERROR and then
462: * installed a fresh socket on it. Unless a
463: * pending destroy suppressed it, the drop also
464: * queued another shutdown pass, and that pass
465: * must run, because it is what tears down
466: * whatever attached to the path after the
467: * transport shutdown above sampled its state.
468: * Consuming the RDS_CONN_ERROR here would turn
469: * that pass into a no-op: leave the state
470: * alone, and let the pass finish the job.
471: *
472: * Quiesce the reconnect timer before bailing
473: * out, though. When a pending destroy did
474: * suppress the queue, no later pass runs, and
475: * rds_conn_path_destroy() is about to flush
476: * cp_down_w and free the path: it must not
477: * find cp_conn_w still armed. A successor
478: * pass, when there is one, re-arms the
479: * reconnect from its own tail.
480: */
481: cancel_delayed_work_sync(&cp->cp_conn_w);
482: clear_bit(RDS_RECONNECT_PENDING, &cp->cp_flags);
483:
484: if (rds_conn_path_state(cp) == RDS_CONN_ERROR)
485: return;
486: /* No current cp_state writer leaves a
487: * DISCONNECTING path in any state but
488: * RDS_CONN_ERROR; report loudly if one ever
489: * does.
490: */
491: rds_conn_path_error(cp, "%s: failed to transition "
492: "to state DOWN, current state "
493: "is %d\n", __func__,
494: atomic_read(&cp->cp_state));
495: return;
496: }
497: }
498:
499: /* Then reconnect if it's still live.
500: * The passive side of an IB loopback connection is never added
501: * to the conn hash, so we never trigger a reconnect on this
502: * conn - the reconnect is always triggered by the active peer. */
503: cancel_delayed_work_sync(&cp->cp_conn_w);
504:
505: clear_bit(RDS_RECONNECT_PENDING, &cp->cp_flags);
506: rcu_read_lock();
507: if (!hlist_unhashed(&conn->c_hash_node)) {
508: rcu_read_unlock();
509: if (conn->c_trans->t_mp_capable &&
510: cp->cp_index == 0)
511: rds_send_ping(conn, 0);
512: rds_queue_reconnect(cp);
513: } else {
514: rcu_read_unlock();
515: }
516:
517: /* we do not hold the socket lock here but it is safe because
518: * fan-out is disabled when calling conn_slots_available()
519: */
520: if (conn->c_trans->conn_slots_available)
521: conn->c_trans->conn_slots_available(conn, false);
522: }
SourceFile:net/rds/connection.c]
|
| 11/2 |
2026/10/21 01:53 |
llm |
expert |
0m
Model:
Tokens:
input: 13681
output: 142
thoughts: 798
Thoughts: **A Deep Dive into the `rxe_cleanup` Mechanism and Potential Deadlock Scenarios**
As I scrutinize the `__rxe_cleanup` function within `drivers/infiniband/sw/rxe/rxe_pool.c`, a concerning pattern emerges, particularly concerning the handling of timeouts during completion waits. My immediate thought process centers on lines 203-215, where a `sleepable` operation might involve waiting for a completion event via `wait_for_completion_timeout`. The critical observation comes when this timeout *does* occur, indicated by `ret == 0`. In this scenario, `WARN_ON(!ret)` is triggered, and crucially, `err` is set to `-ETIMEDOUT`. Yet, despite this error indication, the `pool->cleanup(elem)` function is *still* invoked.
This is where my alarm bells start ringing. I then cross-reference this with the behavior in `rxe_destroy_qp` (line 661). Here, `rxe_cleanup(qp)` is called, and even if it returns an error like `-ETIMEDOUT`, `rxe_destroy_qp` proceeds to return `0`. This is highly problematic. The subsequent call to `ib_destroy_qp_user` (which I'm inferring is the ultimate consumer of `rxe_destroy_qp`'s return value) will then interpret a `0` return as success and proceed to `kfree(qp)`.
The comment at line 208 in `__rxe_cleanup` β "Shouldn't happen. There are still references to the object but, rather than deadlock, free the object or pass back to rdma-core" β is particularly striking. It explicitly acknowledges a situation where there *shouldn't* be remaining references, yet the code is designed to prevent a deadlock by freeing the object or returning it. My concern is that if `pool->cleanup(elem)` is called *after* a timeout, and that timeout implies outstanding references that weren't resolved, then `kfree(qp)` is being called while those references might still be active. This smells like a potential use-after-free or a double-free waiting to happen.
This leads me to a series of pressing questions:
* **What are these outstanding references?** I need to meticulously trace the `rxe_get` and `rxe_put` calls related to `qp` (or `elem`) to understand what's keeping the object alive from the perspective of `wait_for_completion_timeout`.
* **Why did `elem->complete` not complete within 50 seconds?** A 50-second timeout is substantial. This strongly suggests a deeper issue, possibly a deadlock or a fundamental logic error elsewhere that prevents the completion event from being signaled.
* **What is the actual impact of `pool->cleanup(elem)` being called in this timed-out state?** Does it inadvertently decrement reference counts that are still expected to be held? Does it perform actions that are unsafe when the object is considered "timed out"?
* **And finally, the bug report mention of `Tainted: [L]=SOFTLOCKUP` is a red flag.** This might be a direct consequence of the deadlock I'm suspecting. If the kernel is soft-locked, it points towards a scenario where a process is stuck waiting indefinitely, which aligns with the timeout behavior I'm seeing and the potential for unresolved references.
To get to the bottom of this, my next steps involve a deep dive into `drivers/infiniband/sw/rxe/rxe_qp.c`, `drivers/infiniband/sw/rxe/rxe_pool.c`, and `drivers/infiniband/core/verbs.c` to understand the entire lifecycle of `qp` objects, their reference counting, and the completion signaling mechanisms. I need to understand how `rxe_qp` cleanup is supposed to interact with `rxe_pool` cleanup, and critically, why a timeout is occurring in the first place.
|
| 12/2 |
2026/10/21 01:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/verbs.c Name:ib_destroy_qp_user]
Results: map[SourceCode:2155: int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)
2156: {
2157: const struct ib_gid_attr *alt_path_sgid_attr = qp->alt_path_sgid_attr;
2158: const struct ib_gid_attr *av_sgid_attr = qp->av_sgid_attr;
2159: struct ib_qp_security *sec;
2160: struct ib_comp_cntr *cc;
2161: unsigned long index;
2162: int ret;
2163:
2164: WARN_ON_ONCE(qp->mrs_used > 0);
2165:
2166: if (atomic_read(&qp->usecnt))
2167: return -EBUSY;
2168:
2169: if (qp->real_qp != qp)
2170: return __ib_destroy_shared_qp(qp);
2171:
2172: rdma_restrack_begin_del(&qp->res);
2173:
2174: sec = qp->qp_sec;
2175: if (sec)
2176: ib_destroy_qp_security_begin(sec);
2177:
2178: if (!qp->uobject)
2179: rdma_rw_cleanup_mrs(qp);
2180:
2181: rdma_counter_unbind_qp(qp, qp->port, true);
2182: ret = qp->device->ops.destroy_qp(qp, udata);
2183: if (ret) {
2184: if (sec)
2185: ib_destroy_qp_security_abort(sec);
2186: rdma_restrack_abort_del(&qp->res);
2187: return ret;
2188: }
2189:
2190: if (alt_path_sgid_attr)
2191: rdma_put_gid_attr(alt_path_sgid_attr);
2192: if (av_sgid_attr)
2193: rdma_put_gid_attr(av_sgid_attr);
2194:
2195: xa_for_each(&qp->comp_cntrs, index, cc)
2196: atomic_dec(&cc->usecnt);
2197: xa_destroy(&qp->comp_cntrs);
2198:
2199: ib_qp_usecnt_dec(qp);
2200: if (sec)
2201: ib_destroy_qp_security_end(sec);
2202:
2203: rdma_restrack_commit_del(&qp->res);
2204: kfree(qp);
2205: return ret;
2206: }
SourceFile:drivers/infiniband/core/verbs.c]
|
| 13/2 |
2026/10/21 01:54 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:drivers/infiniband/sw/rxe/rxe_qp.c]
Results: map[Entities:[map[Kind:function Name:__qp_chk_state] map[Kind:function Name:alloc_rd_atomic_resources] map[Kind:function Name:cleanup_rd_atomic_resources] map[Kind:function Name:free_rd_atomic_resource] map[Kind:function Name:free_rd_atomic_resources] map[Kind:function Name:rxe_init_rq] map[Kind:function Name:rxe_init_sq] map[Kind:function Name:rxe_qp_chk_attr] map[Kind:function Name:rxe_qp_chk_cap] map[Kind:function Name:rxe_qp_chk_destroy] map[Kind:function Name:rxe_qp_chk_init] map[Kind:function Name:rxe_qp_cleanup] map[Kind:function Name:rxe_qp_do_cleanup] map[Kind:function Name:rxe_qp_error] map[Kind:function Name:rxe_qp_from_attr] map[Kind:function Name:rxe_qp_from_init] map[Kind:function Name:rxe_qp_init_misc] map[Kind:function Name:rxe_qp_init_req] map[Kind:function Name:rxe_qp_init_resp] map[Kind:function Name:rxe_qp_reset] map[Kind:function Name:rxe_qp_sqd] map[Kind:function Name:rxe_qp_to_attr] map[Kind:function Name:rxe_qp_to_init] map[Kind:function Name:rxe_reclassify_send_socket] map[Kind:global_variable Name:qps2str]]]
|
| 14/2 |
2026/10/21 01:54 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c IncludeSnippetLines:20 Name:rxe_qp_cleanup]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:rxe_type_info SourceFile:drivers/infiniband/sw/rxe/rxe_pool.c SourceLine:58 SourceSnippet: 38: .name = "ah",
39: .size = sizeof(struct rxe_ah),
40: .elem_offset = offsetof(struct rxe_ah, elem),
41: .min_index = RXE_MIN_AH_INDEX,
42: .max_index = RXE_MAX_AH_INDEX,
43: .max_elem = RXE_MAX_AH,
44: },
45: [RXE_TYPE_SRQ] = {
46: .name = "srq",
47: .size = sizeof(struct rxe_srq),
48: .elem_offset = offsetof(struct rxe_srq, elem),
49: .cleanup = rxe_srq_cleanup,
50: .min_index = RXE_MIN_SRQ_INDEX,
51: .max_index = RXE_MAX_SRQ_INDEX,
52: .max_elem = RXE_MAX_SRQ,
53: },
54: [RXE_TYPE_QP] = {
55: .name = "qp",
56: .size = sizeof(struct rxe_qp),
57: .elem_offset = offsetof(struct rxe_qp, elem),
58: .cleanup = rxe_qp_cleanup,
59: .min_index = RXE_MIN_QP_INDEX,
60: .max_index = RXE_MAX_QP_INDEX,
61: .max_elem = RXE_MAX_QP,
62: },
63: [RXE_TYPE_CQ] = {
64: .name = "cq",
65: .size = sizeof(struct rxe_cq),
66: .elem_offset = offsetof(struct rxe_cq, elem),
67: .cleanup = rxe_cq_cleanup,
68: .min_index = 1,
69: .max_index = RXE_MAX_CQ,
70: .max_elem = RXE_MAX_CQ,
71: },
72: [RXE_TYPE_MR] = {
73: .name = "mr",
74: .size = sizeof(struct rxe_mr),
75: .elem_offset = offsetof(struct rxe_mr, elem),
76: .cleanup = rxe_mr_cleanup,
77: .min_index = RXE_MIN_MR_INDEX,
78: .max_index = RXE_MAX_MR_INDEX,
]] TruncatedOutput:false]
|
| 15/2 |
2026/10/21 01:54 |
llm |
expert |
0m
Model:
Tokens:
input: 16737
output: 155
thoughts: 54
Thoughts: **My Deep Dive into RXE QP Cleanup Logic**
Alright, so my immediate focus is to really get a handle on how the Request Event eXtension (RXE) handles the cleanup of Queue Pairs (QPs). I'm going to zero in on three specific functions within `drivers/infiniband/sw/rxe/rxe_qp.c`: `rxe_qp_cleanup`, `rxe_qp_do_cleanup`, and `rxe_qp_chk_destroy`. My goal here is to trace the execution flow and understand the state transitions and resource deallocations involved as a QP is being dismantled. I want to see what dependencies are checked, what internal structures are freed, and what the final state of the QP is after this process is complete. Essentially, I'm looking for the nitty-gritty of how the RXE driver ensures a clean exit for a QP, preventing any lingering resources or memory leaks.
|
| 16/2 |
2026/10/21 01:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c Name:rxe_qp_cleanup]
Results: map[SourceCode: 931: /* called when the last reference to the qp is dropped */
932: void rxe_qp_cleanup(struct rxe_pool_elem *elem)
933: {
934: struct rxe_qp *qp = container_of(elem, typeof(*qp), elem);
935:
936: execute_in_process_context(rxe_qp_do_cleanup, &qp->cleanup_work);
937: }
SourceFile:drivers/infiniband/sw/rxe/rxe_qp.c]
|
| 17/2 |
2026/10/21 01:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c Name:rxe_qp_do_cleanup]
Results: map[SourceCode: 864: /* called when the last reference to the qp is dropped */
865: static void rxe_qp_do_cleanup(struct work_struct *work)
866: {
867: struct rxe_qp *qp = container_of(work, typeof(*qp), cleanup_work.work);
868: unsigned long flags;
869:
870: spin_lock_irqsave(&qp->state_lock, flags);
871: qp->valid = 0;
872: spin_unlock_irqrestore(&qp->state_lock, flags);
873: qp->qp_timeout_jiffies = 0;
874:
875: /* In the function timer_setup, .function is initialized. If .function
876: * is NULL, it indicates the function timer_setup is not called, the
877: * timer is not initialized. Or else, the timer is initialized.
878: */
879: if (qp_type(qp) == IB_QPT_RC && qp->retrans_timer.function &&
880: qp->rnr_nak_timer.function) {
881: timer_delete_sync(&qp->retrans_timer);
882: timer_delete_sync(&qp->rnr_nak_timer);
883: }
884:
885: if (qp->recv_task.func)
886: rxe_cleanup_task(&qp->recv_task);
887:
888: if (qp->send_task.func)
889: rxe_cleanup_task(&qp->send_task);
890:
891: /* flush out any receive wr's or pending requests */
892: rxe_sender(qp);
893: rxe_receiver(qp);
894:
895: if (qp->sq.queue)
896: rxe_queue_cleanup(qp->sq.queue);
897:
898: if (qp->srq)
899: rxe_put(qp->srq);
900:
901: if (qp->rq.queue)
902: rxe_queue_cleanup(qp->rq.queue);
903:
904: if (qp->scq) {
905: atomic_dec(&qp->scq->num_wq);
906: rxe_put(qp->scq);
907: }
908:
909: if (qp->rcq) {
910: atomic_dec(&qp->rcq->num_wq);
911: rxe_put(qp->rcq);
912: }
913:
914: if (qp->pd)
915: rxe_put(qp->pd);
916:
917: if (qp->resp.mr)
918: rxe_put(qp->resp.mr);
919:
920: free_rd_atomic_resources(qp);
921:
922: if (qp->sk) {
923: if (qp_type(qp) == IB_QPT_RC)
924: sk_dst_reset(qp->sk->sk);
925:
926: kernel_sock_shutdown(qp->sk, SHUT_RDWR);
927: sock_release(qp->sk);
928: }
929: }
SourceFile:drivers/infiniband/sw/rxe/rxe_qp.c]
|
| 18/2 |
2026/10/21 01:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c Name:rxe_qp_chk_destroy]
Results: map[SourceCode: 850: int rxe_qp_chk_destroy(struct rxe_qp *qp)
851: {
852: /* See IBA o10-2.2.3
853: * An attempt to destroy a QP while attached to a mcast group
854: * will fail immediately.
855: */
856: if (atomic_read(&qp->mcg_num)) {
857: rxe_dbg_qp(qp, "Attempt to destroy while attached to multicast group\n");
858: return -EBUSY;
859: }
860:
861: return 0;
862: }
SourceFile:drivers/infiniband/sw/rxe/rxe_qp.c]
|
| 19/2 |
2026/10/21 01:54 |
llm |
expert |
0m
Model:
Tokens:
input: 18373
output: 55
thoughts: 428
Thoughts: **My Thought Process Unpacking `rxe_qp_do_cleanup` and Reference Counting**
WHOA! My attention has been firmly grabbed by this `rxe_qp_do_cleanup` function. As I dive into its usage, a crucial observation immediately jumps out: it appears to be *exclusively* called within `pool->cleanup(elem)`, which, in turn, is invoked *after* a `wait_for_completion_timeout(&elem->complete, ...)` operation. This sequence strikes me as peculiar and warrants a closer examination.
WAIT A SECOND! This timing suggests that by the time `rxe_qp_do_cleanup` is executed, the object it operates on (`elem`) should, theoretically, be in a state where all external references have been released. But the preceding `wait_for_completion_timeout` implies that there *might* still be outstanding references that need to complete. This is the crux of my current confusion.
Let's scrutinize the `__rxe_cleanup` function itself, as it directly precedes the `pool->cleanup` call. I see this key section:
```c
/* if this is the last call to rxe_put complete the
* object. It is safe to touch obj->elem after this since
* it is freed below
*/
__rxe_put(elem);
/* wait until all references to the object have been
* dropped before final object specific cleanup and
* return to rdma-core
*/
if (sleepable) {
if (!completion_done(&elem->complete)) {
ret = wait_for_completion_timeout(&elem->complete,
msecs_to_jiffies(50000));
/* Shouldn't happen. There are still references to
* the object but, rather than deadlock, free the
* object or pass back to rdma-core.
*/
if (WARN_ON(!ret))
err = -ETIMEDOUT;
}
}
...
if (pool->cleanup)
pool->cleanup(elem);
```
The comment "// if this is the last call to rxe_put complete the object" is significant. It implies that `__rxe_put(elem)` is intended to be the final decrement of the reference count. Following this, the `wait_for_completion_timeout` is there to ensure that *all* outstanding references are indeed dropped before the final cleanup, which includes `pool->cleanup(elem)` (and therefore `rxe_qp_do_cleanup`). The `WARN_ON(!ret)` further reinforces that a failure to complete within the timeout is an unexpected and problematic situation.
This leads me to the central question that is currently occupying my thoughts: **What exactly holds references to `qp` (via `rxe_get` or `rxe_alloc` calls that increment the `qp` reference count) *before* `rxe_qp_do_cleanup` is called?** If `__rxe_put` is supposed to be the last `rxe_put` and the `wait_for_completion_timeout` is to ensure all references are gone, then there must be some other mechanisms or code paths that are acquiring references to the `qp` object that I haven't yet identified and that are still active when `rxe_qp_do_cleanup` is about to be executed.
To answer this, my next logical step is to meticulously search for all instances where the `qp` reference count is incremented. I need to find every call to `rxe_get` and `rxe_pool_get_index` (as these seem to be the primary mechanisms for acquiring references in this context), as well as any other functions that might be acquiring a reference to `qp` through `rxe_alloc` or similar operations. My plan is to perform a comprehensive grep across the `drivers/infiniband/sw/rxe/` directory to identify all these reference-acquiring points and understand their lifecycles in relation to the cleanup process. This will be crucial in understanding how references can persist until this late stage and whether there are any race conditions or logic gaps.
|
| 20/2 |
2026/10/21 01:54 |
tool |
grepper |
0m
Args: map[Expression:rxe_get|rxe_put|rxe_pool_get_index PathPrefixes:[drivers/infiniband/sw/rxe/]]
Results: map[Output:
Full output is too long, showing 200 out of 597 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (20 files in total):
drivers/infiniband/sw/rxe/rxe.c:1
drivers/infiniband/sw/rxe/rxe.h:1
drivers/infiniband/sw/rxe/rxe_av.c:4
drivers/infiniband/sw/rxe/rxe_comp.c:4
drivers/infiniband/sw/rxe/rxe_loc.h:2
drivers/infiniband/sw/rxe/rxe_mad.c:8
drivers/infiniband/sw/rxe/rxe_mcast.c:5
drivers/infiniband/sw/rxe/rxe_mr.c:10
drivers/infiniband/sw/rxe/rxe_mw.c:19
drivers/infiniband/sw/rxe/rxe_net.c:6
drivers/infiniband/sw/rxe/rxe_odp.c:5
drivers/infiniband/sw/rxe/rxe_pool.c:5
drivers/infiniband/sw/rxe/rxe_pool.h:5
drivers/infiniband/sw/rxe/rxe_qp.c:14
drivers/infiniband/sw/rxe/rxe_recv.c:5
drivers/infiniband/sw/rxe/rxe_req.c:6
drivers/infiniband/sw/rxe/rxe_resp.c:17
drivers/infiniband/sw/rxe/rxe_srq.c:1
drivers/infiniband/sw/rxe/rxe_task.c:3
drivers/infiniband/sw/rxe/rxe_verbs.c:10
drivers/infiniband/sw/rxe/rxe.c=220=static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)
--
drivers/infiniband/sw/rxe/rxe.c-230-
drivers/infiniband/sw/rxe/rxe.c:231: rxe = rxe_get_dev_from_net(ndev);
drivers/infiniband/sw/rxe/rxe.c-232- if (rxe) {
--
drivers/infiniband/sw/rxe/rxe.h=107=void rxe_rcv(struct sk_buff *skb);
--
drivers/infiniband/sw/rxe/rxe.h-109-/* The caller must do a matching ib_device_put(&dev->ib_dev) */
drivers/infiniband/sw/rxe/rxe.h:110:static inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev)
drivers/infiniband/sw/rxe/rxe.h-111-{
--
drivers/infiniband/sw/rxe/rxe_av.c=103=void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr)
--
drivers/infiniband/sw/rxe/rxe_av.c-130-
drivers/infiniband/sw/rxe/rxe_av.c:131:struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt, struct rxe_ah **ahp)
drivers/infiniband/sw/rxe/rxe_av.c-132-{
--
drivers/infiniband/sw/rxe/rxe_av.c-150- /* only new user provider or kernel client */
drivers/infiniband/sw/rxe/rxe_av.c:151: ah = rxe_pool_get_index(&pkt->rxe->ah_pool, ah_num);
drivers/infiniband/sw/rxe/rxe_av.c-152- if (!ah) {
--
drivers/infiniband/sw/rxe/rxe_av.c-158- rxe_dbg_qp(pkt->qp, "PDs don't match for AH and QP\n");
drivers/infiniband/sw/rxe/rxe_av.c:159: rxe_put(ah);
drivers/infiniband/sw/rxe/rxe_av.c-160- return NULL;
--
drivers/infiniband/sw/rxe/rxe_av.c-165- else
drivers/infiniband/sw/rxe/rxe_av.c:166: rxe_put(ah);
drivers/infiniband/sw/rxe/rxe_av.c-167-
--
drivers/infiniband/sw/rxe/rxe_comp.c=115=void retransmit_timer(struct timer_list *t)
--
drivers/infiniband/sw/rxe/rxe_comp.c-121-
drivers/infiniband/sw/rxe/rxe_comp.c:122: if (!rxe_get(qp))
drivers/infiniband/sw/rxe/rxe_comp.c-123- return;
--
drivers/infiniband/sw/rxe/rxe_comp.c-129- spin_unlock_irqrestore(&qp->state_lock, flags);
drivers/infiniband/sw/rxe/rxe_comp.c:130: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_comp.c-131-}
--
drivers/infiniband/sw/rxe/rxe_comp.c=548=static void drain_resp_pkts(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_comp.c-552- while ((skb = skb_dequeue(&qp->resp_pkts))) {
drivers/infiniband/sw/rxe/rxe_comp.c:553: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_comp.c-554- kfree_skb(skb);
--
drivers/infiniband/sw/rxe/rxe_comp.c=608=static void free_pkt(struct rxe_pkt_info *pkt)
--
drivers/infiniband/sw/rxe/rxe_comp.c-614- kfree_skb(skb);
drivers/infiniband/sw/rxe/rxe_comp.c:615: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_comp.c-616- ib_device_put(dev);
--
drivers/infiniband/sw/rxe/rxe_loc.h=17=void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr);
drivers/infiniband/sw/rxe/rxe_loc.h:18:struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt, struct rxe_ah **ahp);
drivers/infiniband/sw/rxe/rxe_loc.h-19-
--
drivers/infiniband/sw/rxe/rxe_loc.h=54=int rxe_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
--
drivers/infiniband/sw/rxe/rxe_loc.h-56-/* rxe_mr.c */
drivers/infiniband/sw/rxe/rxe_loc.h:57:u8 rxe_get_next_key(u32 last_key);
drivers/infiniband/sw/rxe/rxe_loc.h-58-void rxe_mr_init(int access, struct rxe_mr *mr);
--
drivers/infiniband/sw/rxe/rxe_mad.c-9-
drivers/infiniband/sw/rxe/rxe_mad.c:10:static int rxe_get_pma_info(struct ib_mad *out)
drivers/infiniband/sw/rxe/rxe_mad.c-11-{
--
drivers/infiniband/sw/rxe/rxe_mad.c-19-
drivers/infiniband/sw/rxe/rxe_mad.c:20:static int rxe_get_pma_counters(struct rxe_dev *rxe, struct ib_mad *out)
drivers/infiniband/sw/rxe/rxe_mad.c-21-{
--
drivers/infiniband/sw/rxe/rxe_mad.c-32-
drivers/infiniband/sw/rxe/rxe_mad.c:33:static int rxe_get_pma_counters_ext(struct rxe_dev *rxe, struct ib_mad *out)
drivers/infiniband/sw/rxe/rxe_mad.c-34-{
--
drivers/infiniband/sw/rxe/rxe_mad.c-53-
drivers/infiniband/sw/rxe/rxe_mad.c:54:static int rxe_get_perf_mgmt(struct rxe_dev *rxe, const struct ib_mad *in, struct ib_mad *out)
drivers/infiniband/sw/rxe/rxe_mad.c-55-{
--
drivers/infiniband/sw/rxe/rxe_mad.c-57- case IB_PMA_CLASS_PORT_INFO:
drivers/infiniband/sw/rxe/rxe_mad.c:58: return rxe_get_pma_info(out);
drivers/infiniband/sw/rxe/rxe_mad.c-59-
drivers/infiniband/sw/rxe/rxe_mad.c-60- case IB_PMA_PORT_COUNTERS:
drivers/infiniband/sw/rxe/rxe_mad.c:61: return rxe_get_pma_counters(rxe, out);
drivers/infiniband/sw/rxe/rxe_mad.c-62-
drivers/infiniband/sw/rxe/rxe_mad.c-63- case IB_PMA_PORT_COUNTERS_EXT:
drivers/infiniband/sw/rxe/rxe_mad.c:64: return rxe_get_pma_counters_ext(rxe, out);
drivers/infiniband/sw/rxe/rxe_mad.c-65-
--
drivers/infiniband/sw/rxe/rxe_mad.c=72=int rxe_process_mad(struct ib_device *ibdev, int mad_flags, u32 port_num,
--
drivers/infiniband/sw/rxe/rxe_mad.c-87- if (method == IB_MGMT_METHOD_GET)
drivers/infiniband/sw/rxe/rxe_mad.c:88: return rxe_get_perf_mgmt(rxe, in, out);
drivers/infiniband/sw/rxe/rxe_mad.c-89- break;
--
drivers/infiniband/sw/rxe/rxe_mcast.c=197=static void __rxe_publish_mcg(struct rxe_mcg *mcg)
--
drivers/infiniband/sw/rxe/rxe_mcast.c-210-/**
drivers/infiniband/sw/rxe/rxe_mcast.c:211: * rxe_get_mcg - lookup or allocate a mcg
drivers/infiniband/sw/rxe/rxe_mcast.c-212- * @rxe: rxe device object
--
drivers/infiniband/sw/rxe/rxe_mcast.c-216- */
drivers/infiniband/sw/rxe/rxe_mcast.c:217:static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid)
drivers/infiniband/sw/rxe/rxe_mcast.c-218-{
--
drivers/infiniband/sw/rxe/rxe_mcast.c=334=static int __rxe_init_mca(struct rxe_qp *qp, struct rxe_mcg *mcg,
--
drivers/infiniband/sw/rxe/rxe_mcast.c-354-
drivers/infiniband/sw/rxe/rxe_mcast.c:355: rxe_get(qp);
drivers/infiniband/sw/rxe/rxe_mcast.c-356- mca->qp = qp;
--
drivers/infiniband/sw/rxe/rxe_mcast.c=417=static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg)
--
drivers/infiniband/sw/rxe/rxe_mcast.c-423- atomic_dec(&mca->qp->mcg_num);
drivers/infiniband/sw/rxe/rxe_mcast.c:424: rxe_put(mca->qp);
drivers/infiniband/sw/rxe/rxe_mcast.c-425-
--
drivers/infiniband/sw/rxe/rxe_mcast.c=473=int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
--
drivers/infiniband/sw/rxe/rxe_mcast.c-480- /* takes a ref on mcg if successful */
drivers/infiniband/sw/rxe/rxe_mcast.c:481: mcg = rxe_get_mcg(rxe, mgid);
drivers/infiniband/sw/rxe/rxe_mcast.c-482- if (IS_ERR(mcg))
--
drivers/infiniband/sw/rxe/rxe_mr.c-15- */
drivers/infiniband/sw/rxe/rxe_mr.c:16:u8 rxe_get_next_key(u32 last_key)
drivers/infiniband/sw/rxe/rxe_mr.c-17-{
--
drivers/infiniband/sw/rxe/rxe_mr.c=49=void rxe_mr_init(int access, struct rxe_mr *mr)
drivers/infiniband/sw/rxe/rxe_mr.c-50-{
drivers/infiniband/sw/rxe/rxe_mr.c:51: u32 key = mr->elem.index << 8 | rxe_get_next_key(-1);
drivers/infiniband/sw/rxe/rxe_mr.c-52-
--
drivers/infiniband/sw/rxe/rxe_mr.c=416=int copy_data(
--
drivers/infiniband/sw/rxe/rxe_mr.c-452- if (mr) {
drivers/infiniband/sw/rxe/rxe_mr.c:453: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_mr.c-454- mr = NULL;
--
drivers/infiniband/sw/rxe/rxe_mr.c-496- if (mr)
drivers/infiniband/sw/rxe/rxe_mr.c:497: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_mr.c-498-
--
drivers/infiniband/sw/rxe/rxe_mr.c-502- if (mr)
drivers/infiniband/sw/rxe/rxe_mr.c:503: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_mr.c-504-err1:
--
drivers/infiniband/sw/rxe/rxe_mr.c=702=struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key,
--
drivers/infiniband/sw/rxe/rxe_mr.c-708-
drivers/infiniband/sw/rxe/rxe_mr.c:709: mr = rxe_pool_get_index(&rxe->mr_pool, index);
drivers/infiniband/sw/rxe/rxe_mr.c-710- if (!mr)
--
drivers/infiniband/sw/rxe/rxe_mr.c-716- mr->state != RXE_MR_STATE_VALID)) {
drivers/infiniband/sw/rxe/rxe_mr.c:717: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_mr.c-718- mr = NULL;
--
drivers/infiniband/sw/rxe/rxe_mr.c=724=int rxe_invalidate_mr(struct rxe_qp *qp, u32 key)
--
drivers/infiniband/sw/rxe/rxe_mr.c-730-
drivers/infiniband/sw/rxe/rxe_mr.c:731: mr = rxe_pool_get_index(&rxe->mr_pool, key >> 8);
drivers/infiniband/sw/rxe/rxe_mr.c-732- if (!mr) {
--
drivers/infiniband/sw/rxe/rxe_mr.c-761-err_drop_ref:
drivers/infiniband/sw/rxe/rxe_mr.c:762: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_mr.c-763-err:
--
drivers/infiniband/sw/rxe/rxe_mr.c=808=void rxe_mr_cleanup(struct rxe_pool_elem *elem)
--
drivers/infiniband/sw/rxe/rxe_mr.c-811-
drivers/infiniband/sw/rxe/rxe_mr.c:812: rxe_put(mr_pd(mr));
drivers/infiniband/sw/rxe/rxe_mr.c-813- ib_umem_release(mr->umem);
--
drivers/infiniband/sw/rxe/rxe_mw.c=16=int rxe_alloc_mw(struct ib_mw *ibmw, struct ib_udata *udata)
--
drivers/infiniband/sw/rxe/rxe_mw.c-22-
drivers/infiniband/sw/rxe/rxe_mw.c:23: rxe_get(pd);
drivers/infiniband/sw/rxe/rxe_mw.c-24-
--
drivers/infiniband/sw/rxe/rxe_mw.c-26- if (ret) {
drivers/infiniband/sw/rxe/rxe_mw.c:27: rxe_put(pd);
drivers/infiniband/sw/rxe/rxe_mw.c-28- return ret;
--
drivers/infiniband/sw/rxe/rxe_mw.c-30-
drivers/infiniband/sw/rxe/rxe_mw.c:31: mw->rkey = ibmw->rkey = (mw->elem.index << 8) | rxe_get_next_key(-1);
drivers/infiniband/sw/rxe/rxe_mw.c-32- mw->state = (mw->ibmw.type == IB_MW_TYPE_2) ?
--
drivers/infiniband/sw/rxe/rxe_mw.c=139=static void rxe_do_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe,
--
drivers/infiniband/sw/rxe/rxe_mw.c-150- if (mw->mr) {
drivers/infiniband/sw/rxe/rxe_mw.c:151: rxe_put(mw->mr);
drivers/infiniband/sw/rxe/rxe_mw.c-152- atomic_dec(&mw->mr->num_mw);
--
drivers/infiniband/sw/rxe/rxe_mw.c-158- atomic_inc(&mr->num_mw);
drivers/infiniband/sw/rxe/rxe_mw.c:159: rxe_get(mr);
drivers/infiniband/sw/rxe/rxe_mw.c-160- }
--
drivers/infiniband/sw/rxe/rxe_mw.c-162- if (mw->ibmw.type == IB_MW_TYPE_2) {
drivers/infiniband/sw/rxe/rxe_mw.c:163: rxe_get(qp);
drivers/infiniband/sw/rxe/rxe_mw.c-164- mw->qp = qp;
--
drivers/infiniband/sw/rxe/rxe_mw.c=168=int rxe_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe)
]
|
| 21/2 |
2026/10/21 01:54 |
llm |
expert |
0m
Model:
Tokens:
input: 24259
output: 181
thoughts: 43
Thoughts: **My Thought Process on Inspecting `drivers/infiniband/sw/rxe/`**
Alright, given the context of our ongoing investigation, my next immediate step is to broaden my scope within the `drivers/infiniband/sw/rxe/` directory. Specifically, I want to systematically examine all the files residing there for any occurrences of the function names `rxe_get`, `rxe_put`, and `rxe_pool_get_index`. This isn't just a casual scan; I'm looking for these specific identifiers because they strongly suggest operations related to memory pool management and data transfer within the RXE (RDMA emulation) driver. My hypothesis is that by understanding how these core functions are implemented and utilized across various files in this directory, I'll gain crucial insights into the internal workings of the RXE's memory allocation, deallocation, and potentially the underlying data path mechanisms. This focused search is designed to uncover any patterns, dependencies, or even subtle variations in their usage that might shed light on performance characteristics or potential areas for optimization.
|
| 22/2 |
2026/10/21 01:54 |
tool |
grepper |
0m
Args: map[Expression:rxe_get|rxe_put|rxe_pool_get_index PathPrefixes:[drivers/infiniband/sw/rxe/rxe_net.c drivers/infiniband/sw/rxe/rxe_qp.c drivers/infiniband/sw/rxe/rxe_recv.c drivers/infiniband/sw/rxe/rxe_req.c drivers/infiniband/sw/rxe/rxe_resp.c drivers/infiniband/sw/rxe/rxe_task.c drivers/infiniband/sw/rxe/rxe_verbs.c]]
Results: map[Output:
Full output is too long, showing 200 out of 270 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (7 files in total):
drivers/infiniband/sw/rxe/rxe_net.c:6
drivers/infiniband/sw/rxe/rxe_qp.c:14
drivers/infiniband/sw/rxe/rxe_recv.c:5
drivers/infiniband/sw/rxe/rxe_req.c:6
drivers/infiniband/sw/rxe/rxe_resp.c:17
drivers/infiniband/sw/rxe/rxe_task.c:3
drivers/infiniband/sw/rxe/rxe_verbs.c:10
drivers/infiniband/sw/rxe/rxe_net.c=219=static int rxe_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
--
drivers/infiniband/sw/rxe/rxe_net.c-228- */
drivers/infiniband/sw/rxe/rxe_net.c:229: rxe = rxe_get_dev_from_net(ndev);
drivers/infiniband/sw/rxe/rxe_net.c-230- if (!rxe && is_vlan_dev(ndev))
drivers/infiniband/sw/rxe/rxe_net.c:231: rxe = rxe_get_dev_from_net(vlan_dev_real_dev(ndev));
drivers/infiniband/sw/rxe/rxe_net.c-232- if (!rxe)
--
drivers/infiniband/sw/rxe/rxe_net.c=432=static void rxe_skb_tx_dtor(struct sk_buff *skb)
--
drivers/infiniband/sw/rxe/rxe_net.c-441-
drivers/infiniband/sw/rxe/rxe_net.c:442: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_net.c-443- sock_put(skb->sk);
--
drivers/infiniband/sw/rxe/rxe_net.c=446=static int rxe_send(struct sk_buff *skb, struct rxe_pkt_info *pkt)
--
drivers/infiniband/sw/rxe/rxe_net.c-453- skb->destructor = rxe_skb_tx_dtor;
drivers/infiniband/sw/rxe/rxe_net.c:454: rxe_get(pkt->qp);
drivers/infiniband/sw/rxe/rxe_net.c-455- atomic_inc(&pkt->qp->skb_out);
--
drivers/infiniband/sw/rxe/rxe_net.c=468=static int rxe_loopback(struct sk_buff *skb, struct rxe_pkt_info *pkt)
--
drivers/infiniband/sw/rxe/rxe_net.c-476- skb->destructor = rxe_skb_tx_dtor;
drivers/infiniband/sw/rxe/rxe_net.c:477: rxe_get(pkt->qp);
drivers/infiniband/sw/rxe/rxe_net.c-478- atomic_inc(&pkt->qp->skb_out);
--
drivers/infiniband/sw/rxe/rxe_net.c=713=static int rxe_notify(struct notifier_block *not_blk,
--
drivers/infiniband/sw/rxe/rxe_net.c-717- struct net_device *ndev = netdev_notifier_info_to_dev(arg);
drivers/infiniband/sw/rxe/rxe_net.c:718: struct rxe_dev *rxe = rxe_get_dev_from_net(ndev);
drivers/infiniband/sw/rxe/rxe_net.c-719-
--
drivers/infiniband/sw/rxe/rxe_qp.c=398=int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
--
drivers/infiniband/sw/rxe/rxe_qp.c-409-
drivers/infiniband/sw/rxe/rxe_qp.c:410: rxe_get(pd);
drivers/infiniband/sw/rxe/rxe_qp.c:411: rxe_get(rcq);
drivers/infiniband/sw/rxe/rxe_qp.c:412: rxe_get(scq);
drivers/infiniband/sw/rxe/rxe_qp.c-413- if (srq)
drivers/infiniband/sw/rxe/rxe_qp.c:414: rxe_get(srq);
drivers/infiniband/sw/rxe/rxe_qp.c-415-
--
drivers/infiniband/sw/rxe/rxe_qp.c-453- if (srq)
drivers/infiniband/sw/rxe/rxe_qp.c:454: rxe_put(srq);
drivers/infiniband/sw/rxe/rxe_qp.c:455: rxe_put(scq);
drivers/infiniband/sw/rxe/rxe_qp.c:456: rxe_put(rcq);
drivers/infiniband/sw/rxe/rxe_qp.c:457: rxe_put(pd);
drivers/infiniband/sw/rxe/rxe_qp.c-458-
--
drivers/infiniband/sw/rxe/rxe_qp.c=563=static void rxe_qp_reset(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_qp.c-590- if (qp->resp.mr) {
drivers/infiniband/sw/rxe/rxe_qp.c:591: rxe_put(qp->resp.mr);
drivers/infiniband/sw/rxe/rxe_qp.c-592- qp->resp.mr = NULL;
--
drivers/infiniband/sw/rxe/rxe_qp.c=865=static void rxe_qp_do_cleanup(struct work_struct *work)
--
drivers/infiniband/sw/rxe/rxe_qp.c-898- if (qp->srq)
drivers/infiniband/sw/rxe/rxe_qp.c:899: rxe_put(qp->srq);
drivers/infiniband/sw/rxe/rxe_qp.c-900-
--
drivers/infiniband/sw/rxe/rxe_qp.c-905- atomic_dec(&qp->scq->num_wq);
drivers/infiniband/sw/rxe/rxe_qp.c:906: rxe_put(qp->scq);
drivers/infiniband/sw/rxe/rxe_qp.c-907- }
--
drivers/infiniband/sw/rxe/rxe_qp.c-910- atomic_dec(&qp->rcq->num_wq);
drivers/infiniband/sw/rxe/rxe_qp.c:911: rxe_put(qp->rcq);
drivers/infiniband/sw/rxe/rxe_qp.c-912- }
--
drivers/infiniband/sw/rxe/rxe_qp.c-914- if (qp->pd)
drivers/infiniband/sw/rxe/rxe_qp.c:915: rxe_put(qp->pd);
drivers/infiniband/sw/rxe/rxe_qp.c-916-
drivers/infiniband/sw/rxe/rxe_qp.c-917- if (qp->resp.mr)
drivers/infiniband/sw/rxe/rxe_qp.c:918: rxe_put(qp->resp.mr);
drivers/infiniband/sw/rxe/rxe_qp.c-919-
--
drivers/infiniband/sw/rxe/rxe_recv.c=135=static int hdr_check(struct rxe_pkt_info *pkt)
--
drivers/infiniband/sw/rxe/rxe_recv.c-152-
drivers/infiniband/sw/rxe/rxe_recv.c:153: qp = rxe_pool_get_index(&rxe->qp_pool, index);
drivers/infiniband/sw/rxe/rxe_recv.c-154- if (unlikely(!qp))
--
drivers/infiniband/sw/rxe/rxe_recv.c-176-err2:
drivers/infiniband/sw/rxe/rxe_recv.c:177: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_recv.c-178-err1:
--
drivers/infiniband/sw/rxe/rxe_recv.c=190=static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
--
drivers/infiniband/sw/rxe/rxe_recv.c-247- cpkt->qp = qp;
drivers/infiniband/sw/rxe/rxe_recv.c:248: rxe_get(qp);
drivers/infiniband/sw/rxe/rxe_recv.c-249- rxe_rcv_pkt(cpkt, cskb);
--
drivers/infiniband/sw/rxe/rxe_recv.c-251- pkt->qp = qp;
drivers/infiniband/sw/rxe/rxe_recv.c:252: rxe_get(qp);
drivers/infiniband/sw/rxe/rxe_recv.c-253- rxe_rcv_pkt(pkt, skb);
--
drivers/infiniband/sw/rxe/rxe_recv.c=316=void rxe_rcv(struct sk_buff *skb)
--
drivers/infiniband/sw/rxe/rxe_recv.c-368- if (pkt->qp)
drivers/infiniband/sw/rxe/rxe_recv.c:369: rxe_put(pkt->qp);
drivers/infiniband/sw/rxe/rxe_recv.c-370-
--
drivers/infiniband/sw/rxe/rxe_req.c=98=void rnr_nak_timer(struct timer_list *t)
--
drivers/infiniband/sw/rxe/rxe_req.c-104-
drivers/infiniband/sw/rxe/rxe_req.c:105: if (!rxe_get(qp))
drivers/infiniband/sw/rxe/rxe_req.c-106- return;
--
drivers/infiniband/sw/rxe/rxe_req.c-114- spin_unlock_irqrestore(&qp->state_lock, flags);
drivers/infiniband/sw/rxe/rxe_req.c:115: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_req.c-116-}
--
drivers/infiniband/sw/rxe/rxe_req.c=642=int rxe_requester(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_req.c-790-
drivers/infiniband/sw/rxe/rxe_req.c:791: av = rxe_get_av(&pkt, &ah);
drivers/infiniband/sw/rxe/rxe_req.c-792- if (unlikely(!av)) {
--
drivers/infiniband/sw/rxe/rxe_req.c-802- if (ah)
drivers/infiniband/sw/rxe/rxe_req.c:803: rxe_put(ah);
drivers/infiniband/sw/rxe/rxe_req.c-804- goto err;
--
drivers/infiniband/sw/rxe/rxe_req.c-815- if (ah)
drivers/infiniband/sw/rxe/rxe_req.c:816: rxe_put(ah);
drivers/infiniband/sw/rxe/rxe_req.c-817- goto err;
--
drivers/infiniband/sw/rxe/rxe_req.c-820- if (ah)
drivers/infiniband/sw/rxe/rxe_req.c:821: rxe_put(ah);
drivers/infiniband/sw/rxe/rxe_req.c-822-
--
drivers/infiniband/sw/rxe/rxe_resp.c=260=static enum resp_states get_srq_wqe(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-312-
drivers/infiniband/sw/rxe/rxe_resp.c:313:static enum resp_states rxe_get_recv_wqe(struct rxe_qp *qp)
drivers/infiniband/sw/rxe/rxe_resp.c-314-{
--
drivers/infiniband/sw/rxe/rxe_resp.c=336=static enum resp_states check_resource(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-355-
drivers/infiniband/sw/rxe/rxe_resp.c:356: return rxe_get_recv_wqe(qp);
drivers/infiniband/sw/rxe/rxe_resp.c-357- }
--
drivers/infiniband/sw/rxe/rxe_resp.c=467=static enum resp_states check_rkey(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-539-
drivers/infiniband/sw/rxe/rxe_resp.c:540: rxe_get(mr);
drivers/infiniband/sw/rxe/rxe_resp.c:541: rxe_put(mw);
drivers/infiniband/sw/rxe/rxe_resp.c-542- mw = NULL;
--
drivers/infiniband/sw/rxe/rxe_resp.c-606- if (mr)
drivers/infiniband/sw/rxe/rxe_resp.c:607: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_resp.c-608- if (mw)
drivers/infiniband/sw/rxe/rxe_resp.c:609: rxe_put(mw);
drivers/infiniband/sw/rxe/rxe_resp.c-610-
--
drivers/infiniband/sw/rxe/rxe_resp.c=893=static struct rxe_mr *rxe_recheck_mr(struct rxe_qp *qp, u32 rkey)
--
drivers/infiniband/sw/rxe/rxe_resp.c-899- if (rkey_is_mw(rkey)) {
drivers/infiniband/sw/rxe/rxe_resp.c:900: mw = rxe_pool_get_index(&rxe->mw_pool, rkey >> 8);
drivers/infiniband/sw/rxe/rxe_resp.c-901- if (!mw)
--
drivers/infiniband/sw/rxe/rxe_resp.c-906- !mr || mr->state != RXE_MR_STATE_VALID) {
drivers/infiniband/sw/rxe/rxe_resp.c:907: rxe_put(mw);
drivers/infiniband/sw/rxe/rxe_resp.c-908- return NULL;
--
drivers/infiniband/sw/rxe/rxe_resp.c-910-
drivers/infiniband/sw/rxe/rxe_resp.c:911: rxe_get(mr);
drivers/infiniband/sw/rxe/rxe_resp.c:912: rxe_put(mw);
drivers/infiniband/sw/rxe/rxe_resp.c-913-
--
drivers/infiniband/sw/rxe/rxe_resp.c-916-
drivers/infiniband/sw/rxe/rxe_resp.c:917: mr = rxe_pool_get_index(&rxe->mr_pool, rkey >> 8);
drivers/infiniband/sw/rxe/rxe_resp.c-918- if (!mr)
--
drivers/infiniband/sw/rxe/rxe_resp.c-921- if (mr->rkey != rkey || mr->state != RXE_MR_STATE_VALID) {
drivers/infiniband/sw/rxe/rxe_resp.c:922: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_resp.c-923- return NULL;
--
drivers/infiniband/sw/rxe/rxe_resp.c=932=static enum resp_states read_reply(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-1031- if (mr)
drivers/infiniband/sw/rxe/rxe_resp.c:1032: rxe_put(mr);
drivers/infiniband/sw/rxe/rxe_resp.c-1033- return state;
--
drivers/infiniband/sw/rxe/rxe_resp.c=1307=static enum resp_states cleanup(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-1313- skb = skb_dequeue(&qp->req_pkts);
drivers/infiniband/sw/rxe/rxe_resp.c:1314: rxe_put(qp);
drivers/infiniband/sw/rxe/rxe_resp.c-1315- kfree_skb(skb);
--
drivers/infiniband/sw/rxe/rxe_resp.c-1319- if (qp->resp.mr) {
drivers/infiniband/sw/rxe/rxe_resp.c:1320: rxe_put(qp->resp.mr);
drivers/infiniband/sw/rxe/rxe_resp.c-1321- qp->resp.mr = NULL;
--
drivers/infiniband/sw/rxe/rxe_resp.c=1467=static enum resp_states do_class_d1e_error(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1492- if (qp->resp.mr) {
drivers/infiniband/sw/rxe/rxe_resp.c:1493: rxe_put(qp->resp.mr);
drivers/infiniband/sw/rxe/rxe_resp.c-1494- qp->resp.mr = NULL;
--
]
|
| 23/2 |
2026/10/21 01:54 |
llm |
expert |
0m
Model:
Tokens:
input: 29538
output: 195
thoughts: 65
Thoughts: **A Deep Dive into the RoCEv2 Implementation**
My current focus is on understanding the intricate workings of the RoCEv2 implementation, specifically how it handles received packets and manages completion queues. I've identified key files that are crucial for this analysis: `rxe_task.c`, `rxe_verbs.c`, `rxe_recv.c`, `rxe_resp.c`, and `rxe_comp.c`. My plan is to meticulously examine the code within the approximate line range of 1300-1500 in `rxe_recv.c` and `rxe_resp.c`, as I suspect these sections will reveal the core logic for packet reception, response generation, and the subsequent signaling of completion events. By stepping through these areas, I aim to gain a comprehensive understanding of the data flow from the network interface card (NIC) up to the user-space application, paying close attention to how received data is processed, how acknowledgments are formulated, and how the completion queues are populated to inform the application of completed operations.
|
| 24/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_task.c FirstLine:1 LineCount:100]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2: /*
3: * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4: * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5: */
6:
7: #include "rxe.h"
8:
9: struct workqueue_struct *rxe_wq;
10:
11: int rxe_alloc_wq(void)
12: {
13: rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE);
14: if (!rxe_wq)
15: return -ENOMEM;
16:
17: return 0;
18: }
19:
20: void rxe_destroy_wq(void)
21: {
22: destroy_workqueue(rxe_wq);
23: }
24:
25: /* Check if task is idle i.e. not running, not scheduled in
26: * work queue and not draining. If so move to busy to
27: * reserve a slot in do_task() by setting to busy and taking
28: * a qp reference to cover the gap from now until the task finishes.
29: * state will move out of busy if task returns a non zero value
30: * in do_task(). If state is already busy it is raised to armed
31: * to indicate to do_task that additional pass should be made
32: * over the task.
33: * Context: caller should hold task->lock.
34: * Returns: true if state transitioned from idle to busy else false.
35: */
36: static bool __reserve_if_idle(struct rxe_task *task)
37: {
38: WARN_ON(rxe_read(task->qp) <= 0);
39:
40: if (task->state == TASK_STATE_IDLE) {
41: rxe_get(task->qp);
42: task->state = TASK_STATE_BUSY;
43: task->num_sched++;
44: return true;
45: }
46:
47: if (task->state == TASK_STATE_BUSY)
48: task->state = TASK_STATE_ARMED;
49:
50: return false;
51: }
52:
53: /* check if task is idle or drained and not currently
54: * scheduled in the work queue. This routine is
55: * called by rxe_cleanup_task or rxe_disable_task to
56: * see if the queue is empty.
57: * Context: caller should hold task->lock.
58: * Returns true if done else false.
59: */
60: static bool __is_done(struct rxe_task *task)
61: {
62: if (work_pending(&task->work))
63: return false;
64:
65: if (task->state == TASK_STATE_IDLE ||
66: task->state == TASK_STATE_DRAINED) {
67: return true;
68: }
69:
70: return false;
71: }
72:
73: /* a locked version of __is_done */
74: static bool is_done(struct rxe_task *task)
75: {
76: unsigned long flags;
77: int done;
78:
79: spin_lock_irqsave(&task->lock, flags);
80: done = __is_done(task);
81: spin_unlock_irqrestore(&task->lock, flags);
82:
83: return done;
84: }
85:
86: /* do_task is a wrapper for the three tasks (requester,
87: * completer, responder) and calls them in a loop until
88: * they return a non-zero value. It is called indirectly
89: * when rxe_sched_task schedules the task. They must
90: * call __reserve_if_idle to move the task to busy before
91: * calling or scheduling. The task can also be moved to
92: * drained or invalid by calls to rxe_cleanup_task or
93: * rxe_disable_task. In that case tasks which get here
94: * are not executed but just flushed. The tasks are
95: * designed to look to see if there is work to do and
96: * then do part of it before returning here with a return
97: * value of zero until all the work has been consumed then
98: * it returns a non-zero value.
99: * The number of times the task can be run is limited by
100: * max iterations so one task cannot hold the cpu forever.
]
|
| 25/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_task.c FirstLine:101 LineCount:100]
Results: map[Contents: 101: * If the limit is hit and work remains the task is rescheduled.
102: */
103: static void do_task(struct rxe_task *task)
104: {
105: unsigned int iterations;
106: unsigned long flags;
107: int resched = 0;
108: int cont;
109: int ret;
110:
111: WARN_ON(rxe_read(task->qp) <= 0);
112:
113: spin_lock_irqsave(&task->lock, flags);
114: if (task->state >= TASK_STATE_DRAINED) {
115: rxe_put(task->qp);
116: task->num_done++;
117: spin_unlock_irqrestore(&task->lock, flags);
118: return;
119: }
120: spin_unlock_irqrestore(&task->lock, flags);
121:
122: do {
123: iterations = RXE_MAX_ITERATIONS;
124: cont = 0;
125:
126: do {
127: ret = task->func(task->qp);
128: } while (ret == 0 && iterations-- > 0);
129:
130: spin_lock_irqsave(&task->lock, flags);
131: /* we're not done yet but we ran out of iterations.
132: * yield the cpu and reschedule the task
133: */
134: if (!ret) {
135: if (task->state != TASK_STATE_DRAINING) {
136: task->state = TASK_STATE_IDLE;
137: resched = 1;
138: } else {
139: cont = 1;
140: }
141: goto exit;
142: }
143:
144: switch (task->state) {
145: case TASK_STATE_BUSY:
146: task->state = TASK_STATE_IDLE;
147: break;
148:
149: /* someone tried to schedule the task while we
150: * were running, keep going
151: */
152: case TASK_STATE_ARMED:
153: task->state = TASK_STATE_BUSY;
154: cont = 1;
155: break;
156:
157: case TASK_STATE_DRAINING:
158: task->state = TASK_STATE_DRAINED;
159: break;
160:
161: default:
162: WARN_ON(1);
163: rxe_dbg_qp(task->qp, "unexpected task state = %d\n",
164: task->state);
165: task->state = TASK_STATE_IDLE;
166: }
167:
168: exit:
169: if (!cont) {
170: task->num_done++;
171: if (WARN_ON(task->num_done != task->num_sched))
172: rxe_dbg_qp(
173: task->qp,
174: "%ld tasks scheduled, %ld tasks done\n",
175: task->num_sched, task->num_done);
176: }
177: spin_unlock_irqrestore(&task->lock, flags);
178: } while (cont);
179:
180: task->ret = ret;
181:
182: if (resched)
183: rxe_sched_task(task);
184:
185: rxe_put(task->qp);
186: }
187:
188: /* wrapper around do_task to fix argument for work queue */
189: static void do_work(struct work_struct *work)
190: {
191: do_task(container_of(work, struct rxe_task, work));
192: }
193:
194: int rxe_init_task(struct rxe_task *task, struct rxe_qp *qp,
195: int (*func)(struct rxe_qp *))
196: {
197: WARN_ON(rxe_read(qp) <= 0);
198:
199: task->qp = qp;
200: task->func = func;
]
|
| 26/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_recv.c FirstLine:220 LineCount:100]
Results: map[Contents: 220: /* validate qp for incoming packet */
221: err = check_type_state(rxe, pkt, qp);
222: if (err)
223: continue;
224:
225: err = check_keys(rxe, pkt, bth_qpn(pkt), qp);
226: if (err)
227: continue;
228:
229: /* for all but the last QP create a new clone of the
230: * skb and pass to the QP. Pass the original skb to
231: * the last QP in the list.
232: */
233: if (mca->qp_list.next != &mcg->qp_list) {
234: struct sk_buff *cskb;
235: struct rxe_pkt_info *cpkt;
236:
237: cskb = skb_clone(skb, GFP_ATOMIC);
238: if (unlikely(!cskb))
239: continue;
240:
241: if (WARN_ON(!ib_device_try_get(&rxe->ib_dev))) {
242: kfree_skb(cskb);
243: break;
244: }
245:
246: cpkt = SKB_TO_PKT(cskb);
247: cpkt->qp = qp;
248: rxe_get(qp);
249: rxe_rcv_pkt(cpkt, cskb);
250: } else {
251: pkt->qp = qp;
252: rxe_get(qp);
253: rxe_rcv_pkt(pkt, skb);
254: skb = NULL; /* mark consumed */
255: }
256: }
257:
258: spin_unlock_bh(&rxe->mcg_lock);
259:
260: kref_put(&mcg->ref_cnt, rxe_cleanup_mcg);
261:
262: if (likely(!skb))
263: return;
264:
265: /* This only occurs if one of the checks fails on the last
266: * QP in the list above
267: */
268:
269: drop:
270: kfree_skb(skb);
271: ib_device_put(&rxe->ib_dev);
272: }
273:
274: /**
275: * rxe_chk_dgid - validate destination IP address
276: * @rxe: rxe device that received packet
277: * @skb: the received packet buffer
278: *
279: * Accept any loopback packets
280: * Extract IP address from packet and
281: * Accept if multicast packet
282: * Accept if matches an SGID table entry
283: */
284: static int rxe_chk_dgid(struct rxe_dev *rxe, struct sk_buff *skb)
285: {
286: struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
287: const struct ib_gid_attr *gid_attr;
288: union ib_gid dgid;
289: union ib_gid *pdgid;
290:
291: if (pkt->mask & RXE_LOOPBACK_MASK)
292: return 0;
293:
294: if (skb->protocol == htons(ETH_P_IP)) {
295: ipv6_addr_set_v4mapped(ip_hdr(skb)->daddr,
296: (struct in6_addr *)&dgid);
297: pdgid = &dgid;
298: } else {
299: pdgid = (union ib_gid *)&ipv6_hdr(skb)->daddr;
300: }
301:
302: if (rdma_is_multicast_addr((struct in6_addr *)pdgid))
303: return 0;
304:
305: gid_attr = rdma_find_gid_by_port(&rxe->ib_dev, pdgid,
306: IB_GID_TYPE_ROCE_UDP_ENCAP,
307: 1, skb->dev);
308: if (IS_ERR(gid_attr))
309: return PTR_ERR(gid_attr);
310:
311: rdma_put_gid_attr(gid_attr);
312: return 0;
313: }
314:
315: /* rxe_rcv is called from the interface driver */
316: void rxe_rcv(struct sk_buff *skb)
317: {
318: int err;
319: struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
]
|
| 27/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:1290 LineCount:100]
Results: map[Contents:1290: struct rxe_pkt_info *pkt)
1291: {
1292: if (qp_type(qp) != IB_QPT_RC)
1293: return RESPST_CLEANUP;
1294:
1295: if (qp->resp.aeth_syndrome != AETH_ACK_UNLIMITED)
1296: send_ack(qp, qp->resp.aeth_syndrome, pkt->psn);
1297: else if (pkt->mask & RXE_ATOMIC_MASK)
1298: send_atomic_ack(qp, AETH_ACK_UNLIMITED, pkt->psn);
1299: else if (pkt->mask & (RXE_FLUSH_MASK | RXE_ATOMIC_WRITE_MASK))
1300: send_read_response_ack(qp, AETH_ACK_UNLIMITED, pkt->psn);
1301: else if (bth_ack(pkt))
1302: send_ack(qp, AETH_ACK_UNLIMITED, pkt->psn);
1303:
1304: return RESPST_CLEANUP;
1305: }
1306:
1307: static enum resp_states cleanup(struct rxe_qp *qp,
1308: struct rxe_pkt_info *pkt)
1309: {
1310: struct sk_buff *skb;
1311:
1312: if (pkt) {
1313: skb = skb_dequeue(&qp->req_pkts);
1314: rxe_put(qp);
1315: kfree_skb(skb);
1316: ib_device_put(qp->ibqp.device);
1317: }
1318:
1319: if (qp->resp.mr) {
1320: rxe_put(qp->resp.mr);
1321: qp->resp.mr = NULL;
1322: }
1323:
1324: return RESPST_DONE;
1325: }
1326:
1327: static struct resp_res *find_resource(struct rxe_qp *qp, u32 psn)
1328: {
1329: int i;
1330:
1331: for (i = 0; i < qp->attr.max_dest_rd_atomic; i++) {
1332: struct resp_res *res = &qp->resp.resources[i];
1333:
1334: if (res->type == 0)
1335: continue;
1336:
1337: if (psn_compare(psn, res->first_psn) >= 0 &&
1338: psn_compare(psn, res->last_psn) <= 0) {
1339: return res;
1340: }
1341: }
1342:
1343: return NULL;
1344: }
1345:
1346: static enum resp_states duplicate_request(struct rxe_qp *qp,
1347: struct rxe_pkt_info *pkt)
1348: {
1349: enum resp_states rc;
1350: u32 prev_psn = (qp->resp.ack_psn - 1) & BTH_PSN_MASK;
1351:
1352: if (pkt->mask & RXE_SEND_MASK ||
1353: pkt->mask & RXE_WRITE_MASK) {
1354: /* SEND. Ack again and cleanup. C9-105. */
1355: send_ack(qp, AETH_ACK_UNLIMITED, prev_psn);
1356: return RESPST_CLEANUP;
1357: } else if (pkt->mask & RXE_FLUSH_MASK) {
1358: struct resp_res *res;
1359:
1360: /* Find the operation in our list of responder resources. */
1361: res = find_resource(qp, pkt->psn);
1362: if (res) {
1363: res->replay = 1;
1364: res->cur_psn = pkt->psn;
1365: qp->resp.res = res;
1366: rc = RESPST_PROCESS_FLUSH;
1367: goto out;
1368: }
1369:
1370: /* Resource not found. Class D error. Drop the request. */
1371: rc = RESPST_CLEANUP;
1372: goto out;
1373: } else if (pkt->mask & RXE_READ_MASK) {
1374: struct resp_res *res;
1375:
1376: res = find_resource(qp, pkt->psn);
1377: if (!res) {
1378: /* Resource not found. Class D error. Drop the
1379: * request.
1380: */
1381: rc = RESPST_CLEANUP;
1382: goto out;
1383: } else {
1384: /* Ensure this new request is the same as the previous
1385: * one or a subset of it.
1386: */
1387: u64 iova = reth_va(pkt);
1388: u32 resid = reth_len(pkt);
1389:
]
|
| 28/2 |
2026/10/21 01:54 |
llm |
expert |
0m
Model:
Tokens:
input: 35509
output: 194
thoughts: 142
Thoughts: **My Immediate Realization and Plan of Action**
Okay, hold on a second! Something significant has just struck me, and I need to pivot my focus entirely to understanding a critical aspect of this system. My immediate thought process is to dive deep into the packet reception and Quality of Service (QP) management logic.
Specifically, I need to meticulously examine the `rxe_recv.c` file. My primary objective is to understand precisely what happens when a packet is received. I'm zeroing in on the `rxe_rcv_pkt` function and will be reading lines 130-220 to grasp the initial handling of incoming data. Following that, I'll jump to lines 315-380 in the same file to see how the received packet is further processed or managed.
Concurrently, I need to investigate the asynchronous task handling within `rxe_task.c`, particularly in lines 200-350. I suspect this is where a lot of the ongoing processing and state management for received packets or QP operations occurs.
Finally, and crucially, I must understand the lifecycle and error handling of the Quality of Service (QP) itself. This means a deep dive into `rxe_qp.c` to ascertain how a QP is reset, how errors are detected and propagated, and the exact sequence of operations during its destruction.
My plan is clear: read `rxe_recv.c`, `rxe_task.c`, and `rxe_qp.c` with these specific sections in mind to build a comprehensive mental model of these core operations.
|
| 29/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_recv.c FirstLine:130 LineCount:95]
Results: map[Contents: 130: }
131:
132: return 0;
133: }
134:
135: static int hdr_check(struct rxe_pkt_info *pkt)
136: {
137: struct rxe_dev *rxe = pkt->rxe;
138: struct rxe_port *port = &rxe->port;
139: struct rxe_qp *qp = NULL;
140: u32 qpn = bth_qpn(pkt);
141: int index;
142: int err;
143:
144: if (unlikely(bth_tver(pkt) != BTH_TVER))
145: goto err1;
146:
147: if (unlikely(qpn == 0))
148: goto err1;
149:
150: if (qpn != IB_MULTICAST_QPN) {
151: index = (qpn == 1) ? port->qp_gsi_index : qpn;
152:
153: qp = rxe_pool_get_index(&rxe->qp_pool, index);
154: if (unlikely(!qp))
155: goto err1;
156:
157: err = check_type_state(rxe, pkt, qp);
158: if (unlikely(err))
159: goto err2;
160:
161: err = check_addr(rxe, pkt, qp);
162: if (unlikely(err))
163: goto err2;
164:
165: err = check_keys(rxe, pkt, qpn, qp);
166: if (unlikely(err))
167: goto err2;
168: } else {
169: if (unlikely((pkt->mask & RXE_GRH_MASK) == 0))
170: goto err1;
171: }
172:
173: pkt->qp = qp;
174: return 0;
175:
176: err2:
177: rxe_put(qp);
178: err1:
179: return -EINVAL;
180: }
181:
182: static inline void rxe_rcv_pkt(struct rxe_pkt_info *pkt, struct sk_buff *skb)
183: {
184: if (pkt->mask & RXE_REQ_MASK)
185: rxe_resp_queue_pkt(pkt->qp, skb);
186: else
187: rxe_comp_queue_pkt(pkt->qp, skb);
188: }
189:
190: static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
191: {
192: struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
193: struct rxe_mcg *mcg;
194: struct rxe_mca *mca;
195: struct rxe_qp *qp;
196: union ib_gid dgid;
197: int err;
198:
199: if (skb->protocol == htons(ETH_P_IP))
200: ipv6_addr_set_v4mapped(ip_hdr(skb)->daddr,
201: (struct in6_addr *)&dgid);
202: else if (skb->protocol == htons(ETH_P_IPV6))
203: memcpy(&dgid, &ipv6_hdr(skb)->daddr, sizeof(dgid));
204:
205: /* lookup mcast group corresponding to mgid, takes a ref */
206: mcg = rxe_lookup_mcg(rxe, &dgid);
207: if (!mcg)
208: goto drop; /* mcast group not registered */
209:
210: spin_lock_bh(&rxe->mcg_lock);
211:
212: /* this is unreliable datagram service so we let
213: * failures to deliver a multicast packet to a
214: * single QP happen and just move on and try
215: * the rest of them on the list
216: */
217: list_for_each_entry(mca, &mcg->qp_list, qp_list) {
218: qp = mca->qp;
219:
220: /* validate qp for incoming packet */
221: err = check_type_state(rxe, pkt, qp);
222: if (err)
223: continue;
224:
]
|
| 30/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_recv.c FirstLine:315 LineCount:75]
Results: map[Contents: 315: /* rxe_rcv is called from the interface driver */
316: void rxe_rcv(struct sk_buff *skb)
317: {
318: int err;
319: struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
320: struct rxe_dev *rxe = pkt->rxe;
321: unsigned int skblen = skb->len - skb_network_offset(skb);
322:
323: if (unlikely(skb->len < RXE_BTH_BYTES))
324: goto drop;
325:
326: if (rxe_chk_dgid(rxe, skb) < 0)
327: goto drop;
328:
329: pkt->opcode = bth_opcode(pkt);
330: pkt->psn = bth_psn(pkt);
331: pkt->qp = NULL;
332: pkt->mask |= rxe_opcode[pkt->opcode].mask;
333:
334: /*
335: * Unknown opcodes have a zero-initialized rxe_opcode[] entry, so
336: * both mask and length are 0. Reject them before any length math:
337: * rxe_icrc_hdr() would otherwise compute length - RXE_BTH_BYTES
338: * and pass the underflowed value to rxe_crc32(), producing an
339: * out-of-bounds read.
340: */
341: if (unlikely(!rxe_opcode[pkt->opcode].mask ||
342: !rxe_opcode[pkt->opcode].length))
343: goto drop;
344:
345: if (unlikely(pkt->paylen < header_size(pkt) + bth_pad(pkt) +
346: RXE_ICRC_SIZE))
347: goto drop;
348:
349: err = hdr_check(pkt);
350: if (unlikely(err))
351: goto drop;
352:
353: err = rxe_icrc_check(skb, pkt);
354: if (unlikely(err))
355: goto drop;
356:
357: rxe_counter_add(rxe, RXE_CNT_RCVD_BYTES, skblen);
358: rxe_counter_inc(rxe, RXE_CNT_RCVD_PKTS);
359:
360: if (unlikely(bth_qpn(pkt) == IB_MULTICAST_QPN))
361: rxe_rcv_mcast_pkt(rxe, skb);
362: else
363: rxe_rcv_pkt(pkt, skb);
364:
365: return;
366:
367: drop:
368: if (pkt->qp)
369: rxe_put(pkt->qp);
370:
371: kfree_skb(skb);
372: ib_device_put(&rxe->ib_dev);
373: }
]
|
| 31/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_task.c FirstLine:200 LineCount:150]
Results: map[Contents: 200: task->func = func;
201: task->state = TASK_STATE_IDLE;
202: spin_lock_init(&task->lock);
203: INIT_WORK(&task->work, do_work);
204:
205: return 0;
206: }
207:
208: /* rxe_cleanup_task is only called from rxe_do_qp_cleanup in
209: * process context. The qp is already completed with no
210: * remaining references. Once the queue is drained the
211: * task is moved to invalid and returns. The qp cleanup
212: * code then calls the task functions directly without
213: * using the task struct to drain any late arriving packets
214: * or work requests.
215: */
216: void rxe_cleanup_task(struct rxe_task *task)
217: {
218: unsigned long flags;
219:
220: spin_lock_irqsave(&task->lock, flags);
221: if (!__is_done(task) && task->state < TASK_STATE_DRAINED) {
222: task->state = TASK_STATE_DRAINING;
223: } else {
224: task->state = TASK_STATE_INVALID;
225: spin_unlock_irqrestore(&task->lock, flags);
226: return;
227: }
228: spin_unlock_irqrestore(&task->lock, flags);
229:
230: /* now the task cannot be scheduled or run just wait
231: * for the previously scheduled tasks to finish.
232: */
233: while (!is_done(task))
234: cond_resched();
235:
236: spin_lock_irqsave(&task->lock, flags);
237: task->state = TASK_STATE_INVALID;
238: spin_unlock_irqrestore(&task->lock, flags);
239: }
240:
241: /* schedule the task to run later as a work queue entry.
242: * the queue_work call can be called holding
243: * the lock.
244: */
245: void rxe_sched_task(struct rxe_task *task)
246: {
247: unsigned long flags;
248:
249: WARN_ON(rxe_read(task->qp) <= 0);
250:
251: spin_lock_irqsave(&task->lock, flags);
252: if (__reserve_if_idle(task))
253: queue_work(rxe_wq, &task->work);
254: spin_unlock_irqrestore(&task->lock, flags);
255: }
256:
257: /* rxe_disable/enable_task are only called from
258: * rxe_modify_qp in process context. Task is moved
259: * to the drained state by do_task.
260: */
261: void rxe_disable_task(struct rxe_task *task)
262: {
263: unsigned long flags;
264:
265: WARN_ON(rxe_read(task->qp) <= 0);
266:
267: spin_lock_irqsave(&task->lock, flags);
268: if (!__is_done(task) && task->state < TASK_STATE_DRAINED) {
269: task->state = TASK_STATE_DRAINING;
270: } else {
271: task->state = TASK_STATE_DRAINED;
272: spin_unlock_irqrestore(&task->lock, flags);
273: return;
274: }
275: spin_unlock_irqrestore(&task->lock, flags);
276:
277: while (!is_done(task))
278: cond_resched();
279:
280: spin_lock_irqsave(&task->lock, flags);
281: task->state = TASK_STATE_DRAINED;
282: spin_unlock_irqrestore(&task->lock, flags);
283: }
284:
285: void rxe_enable_task(struct rxe_task *task)
286: {
287: unsigned long flags;
288:
289: WARN_ON(rxe_read(task->qp) <= 0);
290:
291: spin_lock_irqsave(&task->lock, flags);
292: if (task->state == TASK_STATE_INVALID) {
293: spin_unlock_irqrestore(&task->lock, flags);
294: return;
295: }
296:
297: task->state = TASK_STATE_IDLE;
298: spin_unlock_irqrestore(&task->lock, flags);
299: }
]
|
| 32/2 |
2026/10/21 01:54 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_qp.c FirstLine:550 LineCount:100]
Results: map[Contents: 550: rxe_dbg_qp(qp, "invalid timeout %d > 31\n",
551: attr->timeout);
552: goto err1;
553: }
554: }
555:
556: return 0;
557:
558: err1:
559: return -EINVAL;
560: }
561:
562: /* move the qp to the reset state */
563: static void rxe_qp_reset(struct rxe_qp *qp)
564: {
565: /* stop tasks from running */
566: rxe_disable_task(&qp->recv_task);
567: rxe_disable_task(&qp->send_task);
568:
569: /* drain work and packet queuesc */
570: rxe_sender(qp);
571: rxe_receiver(qp);
572:
573: if (qp->rq.queue)
574: rxe_queue_reset(qp->rq.queue);
575: if (qp->sq.queue)
576: rxe_queue_reset(qp->sq.queue);
577:
578: /* cleanup attributes */
579: atomic_set(&qp->ssn, 0);
580: qp->req.opcode = -1;
581: qp->req.need_retry = 0;
582: qp->req.wait_for_rnr_timer = 0;
583: qp->req.noack_pkts = 0;
584: qp->resp.msn = 0;
585: qp->resp.opcode = -1;
586: qp->resp.drop_msg = 0;
587: qp->resp.goto_error = 0;
588: qp->resp.sent_psn_nak = 0;
589:
590: if (qp->resp.mr) {
591: rxe_put(qp->resp.mr);
592: qp->resp.mr = NULL;
593: }
594:
595: cleanup_rd_atomic_resources(qp);
596:
597: /* reenable tasks */
598: rxe_enable_task(&qp->recv_task);
599: rxe_enable_task(&qp->send_task);
600: }
601:
602: /* move the qp to the error state */
603: void rxe_qp_error(struct rxe_qp *qp)
604: {
605: unsigned long flags;
606:
607: spin_lock_irqsave(&qp->state_lock, flags);
608: qp->attr.qp_state = IB_QPS_ERR;
609:
610: /* drain work and packet queues */
611: rxe_sched_task(&qp->recv_task);
612: rxe_sched_task(&qp->send_task);
613: spin_unlock_irqrestore(&qp->state_lock, flags);
614: }
615:
616: static void rxe_qp_sqd(struct rxe_qp *qp, struct ib_qp_attr *attr,
617: int mask)
618: {
619: unsigned long flags;
620:
621: spin_lock_irqsave(&qp->state_lock, flags);
622: qp->attr.sq_draining = 1;
623: rxe_sched_task(&qp->send_task);
624: spin_unlock_irqrestore(&qp->state_lock, flags);
625: }
626:
627: /* caller should hold qp->state_lock */
628: static int __qp_chk_state(struct rxe_qp *qp, struct ib_qp_attr *attr,
629: int mask)
630: {
631: enum ib_qp_state cur_state;
632: enum ib_qp_state new_state;
633:
634: cur_state = (mask & IB_QP_CUR_STATE) ?
635: attr->cur_qp_state : qp->attr.qp_state;
636: new_state = (mask & IB_QP_STATE) ?
637: attr->qp_state : cur_state;
638:
639: if (!ib_modify_qp_is_ok(cur_state, new_state, qp_type(qp), mask))
640: return -EINVAL;
641:
642: if (mask & IB_QP_STATE && cur_state == IB_QPS_SQD) {
643: if (qp->attr.sq_draining && new_state != IB_QPS_ERR)
644: return -EINVAL;
645: }
646:
647: return 0;
648: }
649:
]
|
| 33/2 |
2026/10/21 01:54 |
llm |
expert |
0m
Model:
Tokens:
input: 41099
output: 200
thoughts: 532
Thoughts: **A Deep Dive into RXE QP Destruction and Reference Counting**
I was reviewing the `rxe_destroy_qp` function and suddenly had a moment of intense scrutiny when comparing `rxe_qp_do_cleanup` with `__rxe_cleanup`. This led me down a rabbit hole of tracing the QP destruction process. When `rxe_destroy_qp(qp)` is invoked, my initial thought is to understand what happens under the hood.
The process begins with `rxe_qp_chk_destroy(qp)` for sanity checks, followed by `rxe_cleanup(qp)`. Now, the crux of my investigation lies within `rxe_cleanup`. I see it performs several critical actions:
1. It calls `xa_erase(xa, elem->index)`. My immediate interpretation is that this is designed to prevent *new* lookups of this specific `qp` from the `qp_pool`. This is a crucial step in preventing further access to a QP that is slated for destruction.
2. Next, `__rxe_put(elem)` is called. This action signifies dropping the *initial* reference to the `qp`. I understand this to be the reference that was acquired when the `qp` was initially allocated, likely during its creation via `rxe_alloc`.
3. Then comes the `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))`. This is a critical synchronization point. It tells me that the system is waiting for *all other outstanding references* to the `qp` to be released. This is the mechanism that ensures no lingering operations can interfere with the destruction process.
4. Finally, `pool->cleanup(elem)` is executed. This is where the custom cleanup logic for the specific pool is invoked, which in this context, translates to `rxe_qp_cleanup(elem)`. This, in turn, calls `rxe_qp_do_cleanup`. My initial reading of `rxe_qp_do_cleanup` shows it performing tasks like:
* `rxe_cleanup_task(&qp->recv_task);` if `qp->recv_task.func` is set.
* `rxe_cleanup_task(&qp->send_task);` if `qp->send_task.func` is set.
* `rxe_sender(qp);`
* `rxe_receiver(qp);`
This is where a second, more significant wave of confusion hit me. I'm looking at `rxe_qp_do_cleanup` calling `rxe_cleanup_task`, `rxe_sender(qp)`, and `rxe_receiver(qp)` *after* the `wait_for_completion_timeout` has supposedly ensured all other references are gone. This seems counterintuitive at first glance.
My mind immediately races to reconcile this. The only logical explanation I can arrive at is that these operations (`rxe_cleanup_task`, `rxe_sender`, `rxe_receiver`) themselves must be taking additional references to the `qp`. I hypothesize that when a packet is queued on `qp->req_pkts` or `qp->resp_pkts` (which happens during `rxe_resp_queue_pkt` or `rxe_comp_queue_pkt`), or when `send_task` or `recv_task` are scheduled to run, a `qp` reference is acquired using `rxe_get(qp)`.
To confirm this hypothesis, my next step is absolutely to dive into the implementations of `rxe_resp_queue_pkt`, `rxe_comp_queue_pkt`, `rxe_sender`, and `rxe_receiver` themselves. I need to read their code meticulously to see precisely where and how these `rxe_get(qp)` calls are made. This will be the key to understanding the precise lifecycle and reference management during QP destruction.
|
| 34/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_resp.c Name:rxe_resp_queue_pkt]
Results: map[SourceCode: 50: /* rxe_recv calls here to add a request packet to the input queue */
51: void rxe_resp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb)
52: {
53: skb_queue_tail(&qp->req_pkts, skb);
54: rxe_sched_task(&qp->recv_task);
55: }
SourceFile:drivers/infiniband/sw/rxe/rxe_resp.c]
|
| 35/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_comp.c Name:rxe_comp_queue_pkt]
Results: map[SourceCode: 133: void rxe_comp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb)
134: {
135: rxe_counter_inc(SKB_TO_PKT(skb)->rxe, RXE_CNT_SENDER_SCHED);
136: skb_queue_tail(&qp->resp_pkts, skb);
137: rxe_sched_task(&qp->send_task);
138: }
SourceFile:drivers/infiniband/sw/rxe/rxe_comp.c]
|
| 36/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c Name:rxe_sender]
Results: map[SourceCode: 851: int rxe_sender(struct rxe_qp *qp)
852: {
853: int req_ret;
854: int comp_ret;
855:
856: /* process the send queue */
857: req_ret = rxe_requester(qp);
858:
859: /* process the response queue */
860: comp_ret = rxe_completer(qp);
861:
862: /* exit the task loop if both requester and completer
863: * are ready
864: */
865: return (req_ret && comp_ret) ? -EAGAIN : 0;
866: }
SourceFile:drivers/infiniband/sw/rxe/rxe_req.c]
|
| 37/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c Name:rxe_receiver]
Results: map[SourceCode:1571: int rxe_receiver(struct rxe_qp *qp)
1572: {
1573: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
1574: enum resp_states state;
1575: struct rxe_pkt_info *pkt = NULL;
1576: int ret;
1577: unsigned long flags;
1578:
1579: spin_lock_irqsave(&qp->state_lock, flags);
1580: if (!qp->valid || qp_state(qp) == IB_QPS_ERR ||
1581: qp_state(qp) == IB_QPS_RESET) {
1582: bool notify = qp->valid && (qp_state(qp) == IB_QPS_ERR);
1583:
1584: drain_req_pkts(qp);
1585: flush_recv_queue(qp, notify);
1586: spin_unlock_irqrestore(&qp->state_lock, flags);
1587: goto exit;
1588: }
1589: spin_unlock_irqrestore(&qp->state_lock, flags);
1590:
1591: qp->resp.aeth_syndrome = AETH_ACK_UNLIMITED;
1592:
1593: state = RESPST_GET_REQ;
1594:
1595: while (1) {
1596: rxe_dbg_qp(qp, "state = %s\n", resp_state_name[state]);
1597: switch (state) {
1598: case RESPST_GET_REQ:
1599: state = get_req(qp, &pkt);
1600: break;
1601: case RESPST_CHK_PSN:
1602: state = check_psn(qp, pkt);
1603: break;
1604: case RESPST_CHK_OP_SEQ:
1605: state = check_op_seq(qp, pkt);
1606: break;
1607: case RESPST_CHK_OP_VALID:
1608: state = check_op_valid(qp, pkt);
1609: break;
1610: case RESPST_CHK_RESOURCE:
1611: state = check_resource(qp, pkt);
1612: break;
1613: case RESPST_CHK_LENGTH:
1614: state = rxe_resp_check_length(qp, pkt);
1615: break;
1616: case RESPST_CHK_RKEY:
1617: state = check_rkey(qp, pkt);
1618: break;
1619: case RESPST_EXECUTE:
1620: state = execute(qp, pkt);
1621: break;
1622: case RESPST_COMPLETE:
1623: state = do_complete(qp, pkt);
1624: break;
1625: case RESPST_READ_REPLY:
1626: state = read_reply(qp, pkt);
1627: break;
1628: case RESPST_ATOMIC_REPLY:
1629: state = atomic_reply(qp, pkt);
1630: break;
1631: case RESPST_ATOMIC_WRITE_REPLY:
1632: state = atomic_write_reply(qp, pkt);
1633: break;
1634: case RESPST_PROCESS_FLUSH:
1635: state = process_flush(qp, pkt);
1636: break;
1637: case RESPST_ACKNOWLEDGE:
1638: state = acknowledge(qp, pkt);
1639: break;
1640: case RESPST_CLEANUP:
1641: state = cleanup(qp, pkt);
1642: break;
1643: case RESPST_DUPLICATE_REQUEST:
1644: state = duplicate_request(qp, pkt);
1645: break;
1646: case RESPST_ERR_PSN_OUT_OF_SEQ:
1647: /* RC only - Class B. Drop packet. */
1648: send_ack(qp, AETH_NAK_PSN_SEQ_ERROR, qp->resp.psn);
1649: state = RESPST_CLEANUP;
1650: break;
1651:
1652: case RESPST_ERR_TOO_MANY_RDMA_ATM_REQ:
1653: case RESPST_ERR_MISSING_OPCODE_FIRST:
1654: case RESPST_ERR_MISSING_OPCODE_LAST_C:
1655: case RESPST_ERR_UNSUPPORTED_OPCODE:
1656: case RESPST_ERR_MISALIGNED_ATOMIC:
1657: /* RC Only - Class C. */
1658: do_class_ac_error(qp, AETH_NAK_INVALID_REQ,
1659: IB_WC_REM_INV_REQ_ERR);
1660: state = RESPST_COMPLETE;
1661: break;
1662:
1663: case RESPST_ERR_MISSING_OPCODE_LAST_D1E:
1664: state = do_class_d1e_error(qp);
1665: break;
1666: case RESPST_ERR_RNR:
1667: if (qp_type(qp) == IB_QPT_RC) {
1668: rxe_counter_inc(rxe, RXE_CNT_SND_RNR);
1669: /* RC - class B */
1670: send_ack(qp, AETH_RNR_NAK |
1671: (~AETH_TYPE_MASK &
1672: qp->attr.min_rnr_timer),
1673: pkt->psn);
1674: } else {
1675: /* UD/UC - class D */
1676: qp->resp.drop_msg = 1;
1677: }
1678: state = RESPST_CLEANUP;
1679: break;
1680:
1681: case RESPST_ERR_RKEY_VIOLATION_EVENT:
1682: if (qp_type(qp) == IB_QPT_RC)
1683: do_qp_event(qp, IB_EVENT_QP_ACCESS_ERR);
1684:
1685: state = RESPST_ERR_RKEY_VIOLATION;
1686: break;
1687:
1688: case RESPST_ERR_RKEY_VIOLATION:
1689: if (qp_type(qp) == IB_QPT_RC) {
1690: /* Class C */
1691: do_class_ac_error(qp, AETH_NAK_REM_ACC_ERR,
1692: IB_WC_REM_ACCESS_ERR);
1693: state = RESPST_COMPLETE;
1694: } else {
1695: qp->resp.drop_msg = 1;
1696: if (qp->srq) {
1697: /* UC/SRQ Class D */
1698: qp->resp.status = IB_WC_REM_ACCESS_ERR;
1699: state = RESPST_COMPLETE;
1700: } else {
1701: /* UC/non-SRQ Class E. */
1702: state = RESPST_CLEANUP;
1703: }
1704: }
1705: break;
1706:
1707: case RESPST_ERR_INVALIDATE_RKEY:
1708: /* RC - Class J. */
1709: qp->resp.goto_error = 1;
1710: qp->resp.status = IB_WC_REM_INV_REQ_ERR;
1711: state = RESPST_COMPLETE;
1712: break;
1713:
1714: case RESPST_ERR_LENGTH:
1715: if (qp_type(qp) == IB_QPT_RC) {
1716: /* Class C */
1717: do_class_ac_error(qp, AETH_NAK_INVALID_REQ,
1718: IB_WC_REM_INV_REQ_ERR);
1719: state = RESPST_COMPLETE;
1720: } else if (qp->srq) {
1721: /* UC/UD - class E */
1722: qp->resp.status = IB_WC_REM_INV_REQ_ERR;
1723: state = RESPST_COMPLETE;
1724: } else {
1725: /* UC/UD - class D */
1726: qp->resp.drop_msg = 1;
1727: state = RESPST_CLEANUP;
1728: }
1729: break;
1730:
1731: case RESPST_ERR_MALFORMED_WQE:
1732: /* All, Class A. */
1733: do_class_ac_error(qp, AETH_NAK_REM_OP_ERR,
1734: IB_WC_LOC_QP_OP_ERR);
1735: state = RESPST_COMPLETE;
1736: break;
1737:
1738: case RESPST_ERR_CQ_OVERFLOW:
1739: /* All - Class G */
1740: state = RESPST_ERROR;
1741: break;
1742:
1743: case RESPST_DONE:
1744: if (qp->resp.goto_error) {
1745: state = RESPST_ERROR;
1746: break;
1747: }
1748:
1749: goto done;
1750:
1751: case RESPST_EXIT:
1752: if (qp->resp.goto_error) {
1753: state = RESPST_ERROR;
1754: break;
1755: }
1756:
1757: goto exit;
1758:
1759: case RESPST_ERROR:
1760: qp->resp.goto_error = 0;
1761: rxe_dbg_qp(qp, "moved to error state\n");
1762: rxe_qp_error(qp);
1763: goto exit;
1764:
1765: default:
1766: WARN_ON_ONCE(1);
1767: }
1768: }
1769:
1770: /* A non-zero return value will cause rxe_do_task to
1771: * exit its loop and end the work item. A zero return
1772: * will continue looping and return to rxe_responder
1773: */
1774: done:
1775: ret = 0;
1776: goto out;
1777: exit:
1778: ret = -EAGAIN;
1779: out:
1780: return ret;
1781: }
SourceFile:drivers/infiniband/sw/rxe/rxe_resp.c]
|
| 38/2 |
2026/10/21 01:55 |
llm |
expert |
0m
Model:
Tokens:
input: 45527
output: 199
thoughts: 101
Thoughts: **My Thought Process Unfolding**
Hold on a minute! I'm scrutinizing the code and these function names are screaming at me: `rxe_receiver`, `rxe_requester`, `rxe_completer`, `rxe_qp_reset`, and `rxe_modify_qp`. This immediately triggers a deep dive into the core logic. My instinct is to first understand the fundamental roles of the `rxe_requester` and `rxe_completer` modules. Concurrently, I need to examine how QP attributes are translated into an internal representation, which points me to `rxe_qp_from_attr` within `rxe_qp.c`. Finally, to grasp the dynamic state management of the QP, the `rxe_modify_qp` function in `rxe_verbs.c` is a critical piece of the puzzle. My goal here is to build a comprehensive understanding of the request/completion flow and the QP state transitions as mediated by these key components.
|
| 39/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_verbs.c Name:rxe_modify_qp]
Results: map[SourceCode: 601: static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
602: int mask, struct ib_udata *udata)
603: {
604: struct rxe_dev *rxe = to_rdev(ibqp->device);
605: struct rxe_qp *qp = to_rqp(ibqp);
606: int err;
607:
608: if (mask & ~IB_QP_ATTR_STANDARD_BITS) {
609: err = -EOPNOTSUPP;
610: rxe_dbg_qp(qp, "unsupported mask = 0x%x, err = %d\n",
611: mask, err);
612: goto err_out;
613: }
614:
615: err = rxe_qp_chk_attr(rxe, qp, attr, mask);
616: if (err) {
617: rxe_dbg_qp(qp, "bad mask/attr, err = %d\n", err);
618: goto err_out;
619: }
620:
621: err = rxe_qp_from_attr(qp, attr, mask, udata);
622: if (err) {
623: rxe_dbg_qp(qp, "modify qp failed, err = %d\n", err);
624: goto err_out;
625: }
626:
627: if ((mask & IB_QP_AV) && (attr->ah_attr.ah_flags & IB_AH_GRH))
628: qp->src_port = rdma_get_udp_sport(attr->ah_attr.grh.flow_label,
629: qp->ibqp.qp_num,
630: qp->attr.dest_qp_num);
631:
632: return 0;
633:
634: err_out:
635: rxe_err_qp(qp, "returned err = %d\n", err);
636: return err;
637: }
SourceFile:drivers/infiniband/sw/rxe/rxe_verbs.c]
|
| 40/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_qp.c Name:rxe_qp_from_attr]
Results: map[SourceCode: 660: /* called by the modify qp verb */
661: int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,
662: struct ib_udata *udata)
663: {
664: int err;
665:
666: if (mask & IB_QP_CUR_STATE)
667: qp->attr.cur_qp_state = attr->qp_state;
668:
669: if (mask & IB_QP_STATE) {
670: unsigned long flags;
671:
672: spin_lock_irqsave(&qp->state_lock, flags);
673: err = __qp_chk_state(qp, attr, mask);
674: if (!err) {
675: qp->attr.qp_state = attr->qp_state;
676: rxe_dbg_qp(qp, "state -> %s\n",
677: qps2str[attr->qp_state]);
678: }
679: spin_unlock_irqrestore(&qp->state_lock, flags);
680:
681: if (err)
682: return err;
683:
684: switch (attr->qp_state) {
685: case IB_QPS_RESET:
686: rxe_qp_reset(qp);
687: break;
688: case IB_QPS_SQD:
689: rxe_qp_sqd(qp, attr, mask);
690: break;
691: case IB_QPS_ERR:
692: rxe_qp_error(qp);
693: break;
694: default:
695: break;
696: }
697: }
698:
699: if (mask & IB_QP_MAX_QP_RD_ATOMIC) {
700: int max_rd_atomic = attr->max_rd_atomic ?
701: roundup_pow_of_two(attr->max_rd_atomic) : 0;
702:
703: qp->attr.max_rd_atomic = max_rd_atomic;
704: atomic_set(&qp->req.rd_atomic, max_rd_atomic);
705: }
706:
707: if (mask & IB_QP_MAX_DEST_RD_ATOMIC) {
708: int max_dest_rd_atomic = attr->max_dest_rd_atomic ?
709: roundup_pow_of_two(attr->max_dest_rd_atomic) : 0;
710:
711: /*
712: * Not gated by IB_QP_STATE, so the responder task is live.
713: * Quiesce recv_task like rxe_qp_reset() before swapping the
714: * rd_atomic array, so rxe_receiver() cannot race the free/
715: * realloc.
716: */
717: rxe_disable_task(&qp->recv_task);
718: free_rd_atomic_resources(qp);
719: qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;
720: err = alloc_rd_atomic_resources(qp, max_dest_rd_atomic);
721: /*
722: * On ENOMEM leave recv_task quiesced: qp->resp.resources is
723: * NULL and rxe_prepare_res()/find_resource() would deref it.
724: * Re-enable only after a fresh array is installed.
725: */
726: if (err)
727: return err;
728: rxe_enable_task(&qp->recv_task);
729: }
730:
731: if (mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
732: qp->attr.en_sqd_async_notify = attr->en_sqd_async_notify;
733:
734: if (mask & IB_QP_ACCESS_FLAGS)
735: qp->attr.qp_access_flags = attr->qp_access_flags;
736:
737: if (mask & IB_QP_PKEY_INDEX)
738: qp->attr.pkey_index = attr->pkey_index;
739:
740: if (mask & IB_QP_PORT)
741: qp->attr.port_num = attr->port_num;
742:
743: if (mask & IB_QP_QKEY)
744: qp->attr.qkey = attr->qkey;
745:
746: if (mask & IB_QP_AV)
747: rxe_init_av(&attr->ah_attr, &qp->pri_av);
748:
749: if (mask & IB_QP_ALT_PATH) {
750: rxe_init_av(&attr->alt_ah_attr, &qp->alt_av);
751: qp->attr.alt_port_num = attr->alt_port_num;
752: qp->attr.alt_pkey_index = attr->alt_pkey_index;
753: qp->attr.alt_timeout = attr->alt_timeout;
754: }
755:
756: if (mask & IB_QP_PATH_MTU) {
757: qp->attr.path_mtu = attr->path_mtu;
758: qp->mtu = ib_mtu_enum_to_int(attr->path_mtu);
759: }
760:
761: if (mask & IB_QP_TIMEOUT) {
762: qp->attr.timeout = attr->timeout;
763: if (attr->timeout == 0) {
764: qp->qp_timeout_jiffies = 0;
765: } else {
766: /* According to the spec, timeout = 4.096 * 2 ^ attr->timeout [us] */
767: int j = nsecs_to_jiffies(4096ULL << attr->timeout);
768:
769: qp->qp_timeout_jiffies = j ? j : 1;
770: }
771: }
772:
773: if (mask & IB_QP_RETRY_CNT) {
774: qp->attr.retry_cnt = attr->retry_cnt;
775: qp->comp.retry_cnt = attr->retry_cnt;
776: rxe_dbg_qp(qp, "set retry count = %d\n", attr->retry_cnt);
777: }
778:
779: if (mask & IB_QP_RNR_RETRY) {
780: qp->attr.rnr_retry = attr->rnr_retry;
781: qp->comp.rnr_retry = attr->rnr_retry;
782: rxe_dbg_qp(qp, "set rnr retry count = %d\n", attr->rnr_retry);
783: }
784:
785: if (mask & IB_QP_RQ_PSN) {
786: qp->attr.rq_psn = (attr->rq_psn & BTH_PSN_MASK);
787: qp->resp.psn = qp->attr.rq_psn;
788: rxe_dbg_qp(qp, "set resp psn = 0x%x\n", qp->resp.psn);
789: }
790:
791: if (mask & IB_QP_MIN_RNR_TIMER) {
792: qp->attr.min_rnr_timer = attr->min_rnr_timer;
793: rxe_dbg_qp(qp, "set min rnr timer = 0x%x\n",
794: attr->min_rnr_timer);
795: }
796:
797: if (mask & IB_QP_SQ_PSN) {
798: qp->attr.sq_psn = (attr->sq_psn & BTH_PSN_MASK);
799: qp->req.psn = qp->attr.sq_psn;
800: qp->comp.psn = qp->attr.sq_psn;
801: rxe_dbg_qp(qp, "set req psn = 0x%x\n", qp->req.psn);
802: }
803:
804: if (mask & IB_QP_PATH_MIG_STATE)
805: qp->attr.path_mig_state = attr->path_mig_state;
806:
807: if (mask & IB_QP_DEST_QPN)
808: qp->attr.dest_qp_num = attr->dest_qp_num;
809:
810: return 0;
811: }
SourceFile:drivers/infiniband/sw/rxe/rxe_qp.c]
|
| 41/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_comp.c Name:rxe_completer]
Results: map[SourceCode: 641: int rxe_completer(struct rxe_qp *qp)
642: {
643: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
644: struct rxe_send_wqe *wqe = NULL;
645: struct sk_buff *skb = NULL;
646: struct rxe_pkt_info *pkt = NULL;
647: enum comp_state state;
648: int ret;
649: unsigned long flags;
650:
651: qp->req.again = 0;
652:
653: spin_lock_irqsave(&qp->state_lock, flags);
654: if (!qp->valid || qp_state(qp) == IB_QPS_ERR ||
655: qp_state(qp) == IB_QPS_RESET) {
656: bool notify = qp->valid && (qp_state(qp) == IB_QPS_ERR);
657:
658: drain_resp_pkts(qp);
659: flush_send_queue(qp, notify);
660: spin_unlock_irqrestore(&qp->state_lock, flags);
661: goto exit;
662: }
663: spin_unlock_irqrestore(&qp->state_lock, flags);
664:
665: if (qp->comp.timeout) {
666: qp->comp.timeout_retry = 1;
667: qp->comp.timeout = 0;
668: } else {
669: qp->comp.timeout_retry = 0;
670: }
671:
672: if (qp->req.need_retry)
673: goto exit;
674:
675: state = COMPST_GET_ACK;
676:
677: while (1) {
678: rxe_dbg_qp(qp, "state = %s\n", comp_state_name[state]);
679: switch (state) {
680: case COMPST_GET_ACK:
681: skb = skb_dequeue(&qp->resp_pkts);
682: if (skb) {
683: pkt = SKB_TO_PKT(skb);
684: qp->comp.timeout_retry = 0;
685: }
686: state = COMPST_GET_WQE;
687: break;
688:
689: case COMPST_GET_WQE:
690: state = get_wqe(qp, pkt, &wqe);
691: break;
692:
693: case COMPST_CHECK_PSN:
694: state = check_psn(qp, pkt, wqe);
695: break;
696:
697: case COMPST_CHECK_ACK:
698: state = check_ack(qp, pkt, wqe);
699: break;
700:
701: case COMPST_READ:
702: state = do_read(qp, pkt, wqe);
703: break;
704:
705: case COMPST_ATOMIC:
706: state = do_atomic(qp, pkt, wqe);
707: break;
708:
709: case COMPST_WRITE_SEND:
710: if (wqe->state == wqe_state_pending &&
711: wqe->last_psn == pkt->psn)
712: state = COMPST_COMP_ACK;
713: else
714: state = COMPST_UPDATE_COMP;
715: break;
716:
717: case COMPST_COMP_ACK:
718: state = complete_ack(qp, pkt, wqe);
719: break;
720:
721: case COMPST_COMP_WQE:
722: state = complete_wqe(qp, pkt, wqe);
723: break;
724:
725: case COMPST_UPDATE_COMP:
726: if (pkt->mask & RXE_END_MASK)
727: qp->comp.opcode = -1;
728: else
729: qp->comp.opcode = pkt->opcode;
730:
731: if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
732: qp->comp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
733:
734: if (qp->req.wait_psn) {
735: qp->req.wait_psn = 0;
736: qp->req.again = 1;
737: }
738:
739: state = COMPST_DONE;
740: break;
741:
742: case COMPST_DONE:
743: goto done;
744:
745: case COMPST_EXIT:
746: if (qp->comp.timeout_retry && wqe) {
747: state = COMPST_ERROR_RETRY;
748: break;
749: }
750:
751: reset_retry_timer(qp);
752: goto exit;
753:
754: case COMPST_ERROR_RETRY:
755: /* we come here if the retry timer fired and we did
756: * not receive a response packet. try to retry the send
757: * queue if that makes sense and the limits have not
758: * been exceeded. remember that some timeouts are
759: * spurious since we do not reset the timer but kick
760: * it down the road or let it expire
761: */
762:
763: /* there is nothing to retry in this case */
764: if (!wqe || (wqe->state == wqe_state_posted))
765: goto exit;
766:
767: /* if we've started a retry, don't start another
768: * retry sequence, unless this is a timeout.
769: */
770: if (qp->comp.started_retry &&
771: !qp->comp.timeout_retry)
772: goto done;
773:
774: if (qp->comp.retry_cnt > 0) {
775: if (qp->comp.retry_cnt != 7)
776: qp->comp.retry_cnt--;
777:
778: /* no point in retrying if we have already
779: * seen the last ack that the requester could
780: * have caused
781: */
782: if (psn_compare(qp->req.psn,
783: qp->comp.psn) > 0) {
784: /* tell the requester to retry the
785: * send queue next time around
786: */
787: rxe_counter_inc(rxe,
788: RXE_CNT_COMP_RETRY);
789: qp->req.need_retry = 1;
790: qp->comp.started_retry = 1;
791: qp->req.again = 1;
792: }
793: goto done;
794:
795: } else {
796: rxe_counter_inc(rxe, RXE_CNT_RETRY_EXCEEDED);
797: wqe->status = IB_WC_RETRY_EXC_ERR;
798: state = COMPST_ERROR;
799: }
800: break;
801:
802: case COMPST_RNR_RETRY:
803: /* we come here if we received an RNR NAK */
804: if (qp->comp.rnr_retry > 0) {
805: if (qp->comp.rnr_retry != 7)
806: qp->comp.rnr_retry--;
807:
808: /* don't start a retry flow until the
809: * rnr timer has fired
810: */
811: qp->req.wait_for_rnr_timer = 1;
812: rxe_dbg_qp(qp, "set rnr nak timer\n");
813: // TODO who protects from destroy_qp??
814: mod_timer(&qp->rnr_nak_timer,
815: jiffies + rnrnak_jiffies(aeth_syn(pkt)
816: & ~AETH_TYPE_MASK));
817: goto exit;
818: } else {
819: rxe_counter_inc(rxe,
820: RXE_CNT_RNR_RETRY_EXCEEDED);
821: wqe->status = IB_WC_RNR_RETRY_EXC_ERR;
822: state = COMPST_ERROR;
823: }
824: break;
825:
826: case COMPST_ERROR:
827: WARN_ON_ONCE(wqe->status == IB_WC_SUCCESS);
828: do_complete(qp, wqe);
829: rxe_qp_error(qp);
830: goto exit;
831: }
832: }
833:
834: /* A non-zero return value will cause rxe_do_task to
835: * exit its loop and end the work item. A zero return
836: * will continue looping and return to rxe_completer
837: */
838: done:
839: ret = 0;
840: goto out;
841: exit:
842: ret = (qp->req.again) ? 0 : -EAGAIN;
843: out:
844: qp->req.again = 0;
845: if (pkt)
846: free_pkt(pkt);
847: return ret;
848: }
SourceFile:drivers/infiniband/sw/rxe/rxe_comp.c]
|
| 42/2 |
2026/10/21 01:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/sw/rxe/rxe_req.c Name:rxe_requester]
Results: map[SourceCode: 642: int rxe_requester(struct rxe_qp *qp)
643: {
644: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
645: struct rxe_pkt_info pkt;
646: struct sk_buff *skb;
647: struct rxe_send_wqe *wqe;
648: enum rxe_hdr_mask mask;
649: u32 payload;
650: int mtu;
651: int opcode;
652: int err;
653: int ret;
654: struct rxe_queue *q = qp->sq.queue;
655: struct rxe_ah *ah;
656: struct rxe_av *av;
657: unsigned long flags;
658:
659: spin_lock_irqsave(&qp->state_lock, flags);
660: if (unlikely(!qp->valid)) {
661: spin_unlock_irqrestore(&qp->state_lock, flags);
662: goto exit;
663: }
664:
665: if (unlikely(qp_state(qp) == IB_QPS_ERR)) {
666: wqe = __req_next_wqe(qp);
667: spin_unlock_irqrestore(&qp->state_lock, flags);
668: if (wqe) {
669: wqe->status = IB_WC_WR_FLUSH_ERR;
670: goto err;
671: } else {
672: goto exit;
673: }
674: }
675:
676: if (unlikely(qp_state(qp) == IB_QPS_RESET)) {
677: qp->req.wqe_index = queue_get_consumer(q,
678: QUEUE_TYPE_FROM_CLIENT);
679: qp->req.opcode = -1;
680: qp->req.need_rd_atomic = 0;
681: qp->req.wait_psn = 0;
682: qp->req.need_retry = 0;
683: qp->req.wait_for_rnr_timer = 0;
684: spin_unlock_irqrestore(&qp->state_lock, flags);
685: goto exit;
686: }
687: spin_unlock_irqrestore(&qp->state_lock, flags);
688:
689: /* we come here if the retransmit timer has fired
690: * or if the rnr timer has fired. If the retransmit
691: * timer fires while we are processing an RNR NAK wait
692: * until the rnr timer has fired before starting the
693: * retry flow
694: */
695: if (unlikely(qp->req.need_retry && !qp->req.wait_for_rnr_timer)) {
696: req_retry(qp);
697: qp->req.need_retry = 0;
698: }
699:
700: wqe = req_next_wqe(qp);
701: if (unlikely(!wqe))
702: goto exit;
703:
704: /*
705: * Don't trust user space data: a user QP's WQE comes from an mmap'd
706: * ring, so num_sge/cur_sge are attacker-controlled. Bound num_sge like
707: * get_srq_wqe(); bound cur_sge only when payload exists (dma.resid),
708: * since copy_data() skips dma->sge[] on a zero-length copy (all a
709: * max_sge == 0 QP can post).
710: */
711: if (unlikely(wqe->dma.num_sge > qp->sq.max_sge ||
712: (wqe->dma.resid &&
713: wqe->dma.cur_sge >= qp->sq.max_sge))) {
714: rxe_dbg_qp(qp, "invalid num_sge/cur_sge in send wqe\n");
715: wqe->status = IB_WC_LOC_QP_OP_ERR;
716: goto err;
717: }
718:
719: if (rxe_wqe_is_fenced(qp, wqe)) {
720: qp->req.wait_fence = 1;
721: goto exit;
722: }
723:
724: if (wqe->mask & WR_LOCAL_OP_MASK) {
725: err = rxe_do_local_ops(qp, wqe);
726: if (unlikely(err))
727: goto err;
728: else
729: goto done;
730: }
731:
732: if (unlikely(qp_type(qp) == IB_QPT_RC &&
733: psn_compare(qp->req.psn, (qp->comp.psn +
734: RXE_MAX_UNACKED_PSNS)) > 0)) {
735: qp->req.wait_psn = 1;
736: goto exit;
737: }
738:
739: /* Limit the number of inflight SKBs per QP */
740: if (unlikely(atomic_read(&qp->skb_out) >
741: RXE_INFLIGHT_SKBS_PER_QP_HIGH)) {
742: qp->need_req_skb = 1;
743: goto exit;
744: }
745:
746: opcode = next_opcode(qp, wqe, wqe->wr.opcode);
747: if (unlikely(opcode < 0)) {
748: wqe->status = IB_WC_LOC_QP_OP_ERR;
749: goto err;
750: }
751:
752: mask = rxe_opcode[opcode].mask;
753: if (unlikely(mask & (RXE_READ_OR_ATOMIC_MASK |
754: RXE_ATOMIC_WRITE_MASK))) {
755: if (check_init_depth(qp, wqe))
756: goto exit;
757: }
758:
759: mtu = get_mtu(qp);
760: payload = (mask & (RXE_WRITE_OR_SEND_MASK | RXE_ATOMIC_WRITE_MASK)) ?
761: wqe->dma.resid : 0;
762: if (payload > mtu) {
763: if (qp_type(qp) == IB_QPT_UD) {
764: /* C10-93.1.1: If the total sum of all the buffer lengths specified for a
765: * UD message exceeds the MTU of the port as returned by QueryHCA, the CI
766: * shall not emit any packets for this message. Further, the CI shall not
767: * generate an error due to this condition.
768: */
769:
770: /* fake a successful UD send */
771: wqe->first_psn = qp->req.psn;
772: wqe->last_psn = qp->req.psn;
773: qp->req.psn = (qp->req.psn + 1) & BTH_PSN_MASK;
774: qp->req.opcode = IB_OPCODE_UD_SEND_ONLY;
775: qp->req.wqe_index = queue_next_index(qp->sq.queue,
776: qp->req.wqe_index);
777: wqe->state = wqe_state_done;
778: wqe->status = IB_WC_SUCCESS;
779: goto done;
780: }
781: payload = mtu;
782: }
783:
784: pkt.rxe = rxe;
785: pkt.opcode = opcode;
786: pkt.qp = qp;
787: pkt.psn = qp->req.psn;
788: pkt.mask = rxe_opcode[opcode].mask;
789: pkt.wqe = wqe;
790:
791: av = rxe_get_av(&pkt, &ah);
792: if (unlikely(!av)) {
793: rxe_dbg_qp(qp, "Failed no address vector\n");
794: wqe->status = IB_WC_LOC_QP_OP_ERR;
795: goto err;
796: }
797:
798: skb = init_req_packet(qp, av, wqe, opcode, payload, &pkt);
799: if (unlikely(!skb)) {
800: rxe_dbg_qp(qp, "Failed allocating skb\n");
801: wqe->status = IB_WC_LOC_QP_OP_ERR;
802: if (ah)
803: rxe_put(ah);
804: goto err;
805: }
806:
807: err = finish_packet(qp, av, wqe, &pkt, skb, payload);
808: if (unlikely(err)) {
809: rxe_dbg_qp(qp, "Error during finish packet\n");
810: if (err == -EFAULT)
811: wqe->status = IB_WC_LOC_PROT_ERR;
812: else
813: wqe->status = IB_WC_LOC_QP_OP_ERR;
814: kfree_skb(skb);
815: if (ah)
816: rxe_put(ah);
817: goto err;
818: }
819:
820: if (ah)
821: rxe_put(ah);
822:
823: err = rxe_xmit_packet(qp, &pkt, skb);
824: if (err) {
825: wqe->status = IB_WC_LOC_QP_OP_ERR;
826: goto err;
827: }
828:
829: update_wqe_state(qp, wqe, &pkt);
830: update_wqe_psn(qp, wqe, &pkt, payload);
831: update_state(qp, &pkt);
832:
833: /* A non-zero return value will cause rxe_do_task to
834: * exit its loop and end the work item. A zero return
835: * will continue looping and return to rxe_requester
836: */
837: done:
838: ret = 0;
839: goto out;
840: err:
841: /* update wqe_index for each wqe completion */
842: qp->req.wqe_index = queue_next_index(qp->sq.queue, qp->req.wqe_index);
843: wqe->state = wqe_state_error;
844: rxe_qp_error(qp);
845: exit:
846: ret = -EAGAIN;
847: out:
848: return ret;
849: }
SourceFile:drivers/infiniband/sw/rxe/rxe_req.c]
|
| 43/2 |
2026/10/21 01:55 |
llm |
expert |
0m
Model:
Tokens:
input: 55430
output: 90
thoughts: 3091
Thoughts: **A Deep Dive into the RXE QP Lifecycle and Potential Reference Leaks During Destruction**
I've been looking very closely at the `rxe_destroy_qp` function and its implications. My immediate thought upon reviewing `rxe_destroy_qp(qp)` was: "Does this function transition the QP to `IB_QPS_ERR` or `IB_QPS_RESET`, or invalidate `qp->valid = 0` *before* it calls `rxe_cleanup(qp)`?"
Diving into the `rxe_destroy_qp` implementation in `drivers/infiniband/sw/rxe/rxe_verbs.c`, I see it first calls `rxe_qp_chk_destroy(qp)`, handles any errors, and then calls `rxe_cleanup(qp)`. The return value of `rxe_cleanup` is what's ultimately returned by `rxe_destroy_qp`.
Now, let's examine `rxe_qp_do_cleanup` in `drivers/infiniband/sw/rxe/rxe_qp.c`. I noticed that `qp->valid = 0` is *only* set within `rxe_qp_do_cleanup`. Further investigation reveals that `rxe_qp_do_cleanup` is *exclusively* called by `pool->cleanup(elem)`. And crucially, `pool->cleanup(elem)` is only invoked within `__rxe_cleanup` *after* a `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))`.
This led me to a critical question: "Why would `elem->complete` *not* be signaled when `__rxe_cleanup` is waiting for it?" This suggests a potential deadlock or a race condition where the completion is never signaled.
To understand this better, I decided to trace *every single instance* where a reference on the QP (`elem->ref_cnt`) is held. My goal is to pinpoint where these references might be acquired but not properly released, especially in the context of destruction.
Here's what I've identified so far regarding QP reference acquisition:
1. **Initial Reference:** At `rxe_alloc`, `kref_init(&elem->ref_cnt)` sets the reference count to 1. This reference is eventually dropped by `__rxe_put(elem)` at line 197 of `__rxe_cleanup`. This seems standard.
2. **Multicast Group Attachment:** `__rxe_init_mca` calls `rxe_get(qp)`. The `rxe_qp_chk_destroy` function checks `atomic_read(&qp->mcg_num)` and returns `-EBUSY` if it's non-zero. This implies that if a QP is part of a multicast group, it cannot be destroyed. I need to verify if `mcg_num` is incremented atomically or under a lock, but for the RDS RC QP in our stack trace, this might not be the direct cause.
3. **Type 2 Memory Window Binding (`rxe_do_bind_mw`):** If a Type 2 MW is bound to a QP, `rxe_get(qp)` is called, and `mw->qp` holds a pointer to the QP. The `rxe_qp_chk_destroy` function *doesn't even check for bound Type 2 MWs*, which is a concern. Although RDS might not use Type 2 MWs, other userspace or kernel components could, leading to a reference leak here. The reference is held until the MW is invalidated or deallocated.
4. **Outgoing Packets (`rxe_send` / `rxe_loopback`):** When an outgoing `skb` is processed, `rxe_get(pkt->qp)` is called, and `atomic_inc(&pkt->qp->skb_out)` is performed. The destructor for the `skb`, `rxe_skb_tx_dtor`, holds this `rxe_get(qp)` reference until `kfree_skb(skb)` is called. This means any `skb` stuck in a socket queue, netdev queue, or loopback queue will prevent the QP from being destroyed.
5. **Incoming Packets (`rxe_rcv`):**
* For incoming packets, `rxe_pool_get_index(&rxe->qp_pool, index)` (which implicitly calls `rxe_get(qp)`) is called by `hdr_check`, or `rxe_get(qp)` is called directly by `rxe_rcv_mcast_pkt`.
* These packets are then queued onto either `qp->req_pkts` (for response packets, handled by `rxe_receiver` and `drain_req_pkts`) or `qp->resp_pkts` (for completion packets, handled by `rxe_completer` and `drain_resp_pkts`).
* The critical question here is: **When is the `rxe_get(qp)` from `hdr_check` dropped?**
* For `req_pkts`, it's dropped in `cleanup()` in `rxe_resp.c` during packet processing, or in `drain_req_pkts(qp)` when `!qp->valid || qp_state(qp) == IB_QPS_ERR || qp_state(qp) == IB_QPS_RESET`.
* For `resp_pkts`, it's dropped in `free_pkt(pkt)` at the end of `rxe_completer(qp)` during packet processing, or in `drain_resp_pkts(qp)` when `!qp->valid || qp_state(qp) == IB_QPS_ERR || qp_state(qp) == IB_QPS_RESET`.
This leads me to a significant concern, particularly highlighted by the `rxe_completer` function in `drivers/infiniband/sw/rxe/rxe_comp.c`.
Consider the logic within `rxe_completer`:
```c
if (qp->req.need_retry)
goto exit;
```
And then the `COMPST_RNR_RETRY` state:
```c
case COMPST_RNR_RETRY:
if (qp->comp.rnr_retry > 0) {
// ... decrement retry count ...
qp->req.wait_for_rnr_timer = 1;
rxe_dbg_qp(qp, "set rnr nak timer\n");
// TODO who protects from destroy_qp??
mod_timer(&qp->rnr_nak_timer, ...);
goto exit;
```
The problem arises when `qp->req.need_retry` becomes true, or when `COMPST_RNR_RETRY` causes a jump to `goto exit`. If `qp->resp_pkts` is *not empty* at this point, and the QP is *not yet* in `IB_QPS_ERR` or `IB_QPS_RESET` (meaning `qp->valid` is still 1 because `qp->valid = 0` is only set *after* the `wait_for_completion_timeout` in `__rxe_cleanup`), `rxe_completer` *stops processing* packets from `qp->resp_pkts`.
This creates a situation where:
* Packets remain in `qp->resp_pkts`.
* Each packet in `qp->resp_pkts` holds a reference via `rxe_get(qp)`.
* The `rxe_completer` function is halted, preventing further processing and thus preventing the release of these references.
* If `rxe_destroy_qp` is called while this state exists (i.e., `qp->resp_pkts` is non-empty, `qp->valid` is still 1, and the `wait_for_completion_timeout` hasn't completed or has timed out due to the stalled processing), `rxe_cleanup` might be called, but `rxe_qp_do_cleanup` (where `qp->valid` is set to 0) might not be reached if the completion event never fires.
This is a critical path I need to investigate further. I'm particularly interested in what happens if `rxe_destroy_qp` is invoked when the QP is in `IB_QPS_RTS` or `IB_QPS_SQD` or `IB_QPS_INIT` or `IB_QPS_RTR`, and there are pending packets or stalled processing.
Looking at the provided call trace, the crash occurs within `__rxe_cleanup` at line 212, indicating the cleanup process itself is failing. The context is `rds_ib_conn_path_shutdown` calling `rdma_destroy_qp`. I need to examine what `rdma_disconnect` does on RXE to see if it exacerbates this issue by, for example, not properly flushing pending work before initiating QP destruction. My hypothesis is that a combination of stalled packet processing in `rxe_completer` and premature destruction attempts is leading to the `wait_for_completion_timeout` never completing, thus preventing `qp->valid = 0` from being set and potentially causing a reference leak or a deadlock during the destruction sequence.
|
| 44/2 |
2026/10/21 01:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:rdma_disconnect]
Results: map[SourceCode:4826: int rdma_disconnect(struct rdma_cm_id *id)
4827: {
4828: struct rdma_id_private *id_priv;
4829: int ret;
4830:
4831: id_priv = container_of(id, struct rdma_id_private, id);
4832: if (!id_priv->cm_id.ib)
4833: return -EINVAL;
4834:
4835: if (rdma_cap_ib_cm(id->device, id->port_num)) {
4836: ret = cma_modify_qp_err(id_priv);
4837: if (ret)
4838: goto out;
4839: /* Initiate or respond to a disconnect. */
4840: trace_cm_disconnect(id_priv);
4841: if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) {
4842: if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0))
4843: trace_cm_sent_drep(id_priv);
4844: } else {
4845: trace_cm_sent_dreq(id_priv);
4846: }
4847: } else if (rdma_cap_iw_cm(id->device, id->port_num)) {
4848: ret = iw_cm_disconnect(id_priv->cm_id.iw, 0);
4849: } else
4850: ret = -EINVAL;
4851:
4852: out:
4853: return ret;
4854: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 45/2 |
2026/10/21 01:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:rdma_destroy_qp]
Results: map[SourceCode:1163: void rdma_destroy_qp(struct rdma_cm_id *id)
1164: {
1165: struct rdma_id_private *id_priv;
1166:
1167: id_priv = container_of(id, struct rdma_id_private, id);
1168: trace_cm_qp_destroy(id_priv);
1169: mutex_lock(&id_priv->qp_mutex);
1170: ib_destroy_qp(id_priv->id.qp);
1171: id_priv->id.qp = NULL;
1172: mutex_unlock(&id_priv->qp_mutex);
1173: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 46/2 |
2026/10/21 01:56 |
llm |
expert |
0m
Model:
Tokens:
input: 59353
output: 65
thoughts: 758
Thoughts: **The RDMA Disconnect and the Softlockup Conundrum**
I'm trying to get a handle on why `rdma_disconnect` behaves the way it does, especially in certain scenarios. My initial thought is about how it handles cases where the underlying IB connection (`cm_id.ib`) isn't established yet. If `!id_priv->cm_id.ib` β which can happen if `rdma_resolve_addr` or `rdma_resolve_route` haven't kicked in to create it, or if the port number isn't set β `rdma_disconnect` just bails out with `-EINVAL`. It doesn't even bother trying to put the QP in an error state via `cma_modify_qp_err`. Now, for RDS specifically, I know `rds_ib_setup_qp` is called later, when `cm_id.ib` *does* exist, so that part seems to have its own flow.
But when `cma_modify_qp_err(id_priv)` *is* called, it leads to `ib_modify_qp` transitioning the QP to `IB_QPS_ERR`. This, in turn, triggers `rxe_qp_error(qp)`. My focus then shifts to what `rxe_qp_error` does. It locks down the QP's state, sets it to `IB_QPS_ERR`, and critically, it schedules the receive and send tasks: `rxe_sched_task(&qp->recv_task)` and `rxe_sched_task(&qp->send_task)`.
This is where my curiosity piqued. Iβm asking myself, "What exactly does `rxe_sched_task` do?" Digging into its implementation, I see it acquires a lock, then calls `__reserve_if_idle(task)`. And `__reserve_if_idle`? If the task is in an `IDLE` state, it grabs a reference to the QP (`rxe_get(task->qp)`) and marks the task as `BUSY`, incrementing a counter. Crucially, it also queues a work item (`&task->work`) to be processed by `rxe_wq`.
My understanding now is that `rxe_sched_task` is essentially a mechanism to acquire a QP reference and schedule the actual work for the QP's send and receive queues onto a workqueue (`rxe_wq`). The corresponding `rxe_put(task->qp)` only happens when the work item on `rxe_wq` *actually runs and finishes* in the `do_task` function.
This is the core of my current puzzle: why did `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))` in `__rxe_cleanup` time out in the first place? If `rxe_qp_error` is scheduling work, and that work involves `rxe_get` and queuing a task, then the timeout implies that the work item on `rxe_wq` *never finished*. This is highly unusual, especially for a 50-second timeout.
The fact that the kernel is tainted with `Tainted: [L]=SOFTLOCKUP` is a massive red flag, directly pointing towards a softlockup situation in the `rxe_wq` processing or within the `do_task` function itself. It suggests that the work being done is either taking an extraordinarily long time, or it's stuck in a loop, preventing the `rxe_put` from ever being called and thus causing the `__rxe_cleanup` to hang indefinitely.
My immediate next steps are to scrutinize the recent git log for changes within `drivers/infiniband/sw/rxe/` and `net/rds/`. I need to identify any modifications that could potentially introduce a deadlock, a refcount leak within the QP's lifecycle, or a situation where `rxe_wq` or `do_task` might get stuck, leading to this softlockup and the subsequent timeout in cleanup. I suspect a race condition or a bug in the task execution path on `rxe_wq`.
|
| 47/2 |
2026/10/21 01:57 |
tool |
git-log |
0m
Args: map[Count:30 PathPrefix:drivers/infiniband/sw/rxe/]
Results: map[Output:1caceeb2d74b RDMA/rxe: insert mcg into mcg_tree only after rxe_mcast_add() succeeds
769001ce838d RDMA/rxe: Restore HMM_PFN_WRITE check in ODP write paths
d10e2a08799e RDMA/rxe: Fix integer overflow in mr_check_range() leading to OOB access
ae36a5b609ae RDMA/rxe: validate access flags before swapping the MR's PD
de329533792a RDMA/rxe: Fix OOB in free_rd_atomic_resources()
51f2c8d2c99f RDMA/rxe: Fix UAF in ODP init error-handling path
acf9cbb06f1f RDMA/rxe: Implement disassociate_ucontext callback
22fe73aef39f RDMA/rxe: Allow queue VMAs to outlive ucontexts
5329647dad1b net: Use helpers to get/set UDP len tree-wide
fbf03a08679e RDMA: Use ib_no_udata_io() in query_device callbacks
126c757e4cd4 RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]
6f7014237405 RDMA/rxe: Fix responder UAF on IB_QP_MAX_DEST_RD_ATOMIC modify_qp
9eab9eb22259 RDMA/rxe: Reject unimplemented implicit ODP cleanly
15ae32c4a355 RDMA/rxe: Avoid reprocessing the current packet after the QP enters the error state
eebd08d91ddb RDMA: Change capability fields in ib_device_attr from int to u32
fbbe1d5cd7d4 RDMA/rxe: Check PDs for memory window binds
badad6fad60d RDMA: During rereg_mr ensure that REREG_ACCESS is compatible
bad4e98893af RDMA: Update the query_device() op
d6ab440240a0 RDMA/rxe: Copy WQE to local buffer in non-SRQ receive path
22b8fbded65b RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe
af841056860d RDMA/umem: Rename ib_umem_get() to ib_umem_get_va()
ded0abacdc16 RDMA/rxe: Fix typos in comments
35744ab3d03c RDMA/rxe: Fix a use-after-free problem in rxe_mmap
1648bcf1ed5c RDMA/rxe: support perf mgmt GET method
ed7e5e4a932a RDMA/rxe: add SENT/RCVD bytes
dd677609753c RDMA/rxe: remove rxe_ib_device_get_netdev() and RXE_PORT
2cba193628fe udp_tunnel: Pass struct sock to setup_udp_tunnel_sock().
944bfc1b1c6f udp_tunnel: Pass struct sock to udp_tunnel_sock_release().
1114c87aa6f1 RDMA/rxe: Reject non-8-byte ATOMIC_WRITE payloads
4c6f86d85d03 RDMA/rxe: Reject unknown opcodes before ICRC processing
]
|
| 48/2 |
2026/10/21 01:57 |
tool |
git-log |
0m
Args: map[Count:30 PathPrefix:net/rds/]
Results: map[Output:98d446b7c013 net/rds: don't let the rdma_cm destroy an id RDS still owns on route failure
492ba6ac1b1f net: rds: fix uninitialized trans dereference in CM event handler
ba3d1f480c7a net/rds: size a connection's path set by the transport it ends up with
58eb1b3325ed rds: ib: Clear the sg list when mapping an MR fails
f97d8c7bab78 rds: ib: use rds_conn_drop() on protocol version mismatch
2ac09b5353fe net/rds: fix tcp stream corruption with large pages
3a2c4d55e32a treewide: refresh kmalloc_obj() conversions
260c6308fe2e net/rds: don't let rds_conn_shutdown() consume a concurrent drop
813f3582ac7a net/rds: acquire the fastpath locks in rds_conn_shutdown()
02c5f9dc2efd net/rds: acquire RDS_IN_XMIT in rds_tcp_reset_callbacks()
e8e60d74fec4 net/rds: tcp: don't force RDS_CONN_RESETTING over a concurrent shutdown
103c4b13c4f5 net/rds: clear cp_flags bits individually in rds_conn_path_reset()
17c4476dbb9c net/rds: use clear_bit_unlock() in release_refill()
6d0c8b707391 net/rds: use wq_has_sleeper() in release_in_xmit()
d4f484661961 net/rds: use wq_has_sleeper() in rds_cong_map_updated()
68b3d4dbaf20 net/rds: clear i_rx_lat_trace in rds_inc_path_init()
ff8376b2458d net/rds: initialize i_conn_path in rds_inc_init()
a364a7c168d0 net/rds: reinitialize to_be_dropped on rds_send_xmit() restart
2bb824660ef8 rds: synchronize info callbacks with module unload
a507023e6ff1 net/rds: unpin MR pages with unpin_user_pages_dirty_lock()
eb8a59a17f4a net/rds: fix rds_message leak in the rds_send_xmit() drop path
9079adef042c net/rds: hold the socket while an rds_mr references it
d100966325f7 net/rds: don't use unpin_user_pages_dirty_lock() from atomic context
04026c998c24 net/rds: use krealloc_array() for iovector growth
78f75d632f74 rds: tcp: hold the RCU lock across ipv6_chk_addr() in rds_tcp_laddr_check()
167e54c703cc rds: tcp: unregister sysctl before tearing down listen socket
9c805e592a29 rds: Fix inet6_addr_lst NULL dereference when IPv6 is disabled
5521ae71e32a rds: drop incoming messages that cross network namespace boundaries
eebd08d91ddb RDMA: Change capability fields in ib_device_attr from int to u32
e5c00023270e net: rds: check cmsg_len before reading rds_rdma_args in size pass
]
|
| 49/2 |
2026/10/21 01:57 |
llm |
expert |
0m
Model:
Tokens:
input: 61954
output: 117
thoughts: 171
Thoughts: **A Sudden Realization Dawns**
Wait a minute! My attention has just been drawn to some very recent commits in the `drivers/infiniband/sw/rxe/` directory. I'm looking at `15ae32c4a355`, titled "RDMA/rxe: Avoid reprocessing the current packet after the QP enters the error state," and `6f7014237405`, which states "RDMA/rxe: Fix responder UAF on IB_QP_MAX_DEST_RD_ATOMIC modify_qp." These seem like critical fixes, especially the UAF (Use-After-Free) in the responder path, which is always a concern. Before I dive too deep into them, I want to get a comprehensive understanding of the context and impact. To do that, I'm going to use `git-show` to examine these two commits, along with `98d446b7c013`, `f97d8c7bab78`, and `813f3582ac7a`. This will allow me to trace the evolution of this area, understand the problem that led to these changes, and verify that the proposed solutions adequately address the underlying issues.
|
| 50/2 |
2026/10/21 01:57 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 15ae32c4a3551c4c9da457370bdfdd65d171e512
Author: Allison Henderson <achender@kernel.org>
Date: Sat Jul 11 09:54:19 2026 -0700
RDMA/rxe: Avoid reprocessing the current packet after the QP enters the error state
When do_complete() finds the QP in the error state it returns
RESPST_CHK_RESOURCE. Before commit 49dc9c1f0c7e ("RDMA/rxe: Cleanup
reset state handling in rxe_resp.c") this was the flush loop:
check_resource() had an error-state branch that fetched each remaining
recv WQE and completed it with IB_WC_WR_FLUSH_ERR, without touching
the current packet. That commit removed the error-state branch from
check_resource() (draining is now done at rxe_receiver() entry) but
kept the do_complete() error-state return.
As a result, when a QP moves to the error state while a packet is
being completed - e.g. an rdma_cm disconnect racing with receive
processing - the responder state machine loops back into the request
processing chain with the already-completed packet still in hand:
check_resource() fetches a fresh recv WQE, execute()/send_data_in()
copies the same packet payload again, do_complete() posts another
IB_WC_SUCCESS CQE (qp->resp.status is still 0), and control returns
to the error-state check. The loop re-executes the same packet once
per posted recv WQE (observed: ~1000 duplicate IB_WC_SUCCESS
completions of one SEND, one per ~8us, matching the RQ occupancy)
until the RQ is exhausted, after which qp->resp.wqe is NULL and
send_data_in() dereferences it:
BUG: kernel NULL pointer dereference, address: 0000000000000014
Workqueue: rxe_wq do_work
RIP: copy_data+0x29/0x1f0
Call Trace:
send_data_in+0x25/0x50
rxe_receiver+0xf36/0x1dd0
The duplicate completions are indistinguishable from real receives to
the ULP. During an rds stress test, the message was accepted as new and
delivered the same datagram to user space hundreds of times, corrupting
the stream; any ULP that relies on RC exactly-once delivery is affected.
A live packet reaching the error-state check in do_complete() has
been executed and completed exactly once and must be consumed, not
re-processed. Return RESPST_CLEANUP for it (dequeue and free); keep
returning RESPST_CHK_RESOURCE for the pkt == NULL case.
Fixes: 49dc9c1f0c7e ("RDMA/rxe: Cleanup reset state handling in rxe_resp.c")
Assisted-by: Claude-Code:claude-fable-5
Signed-off-by: Allison Henderson <achender@kernel.org>
Link: https://patch.msgid.link/20260711165419.13486-1-achender@kernel.org
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c
index d8cbdfa70cdb..02b16e2b49b8 100644
--- a/drivers/infiniband/sw/rxe/rxe_resp.c
+++ b/drivers/infiniband/sw/rxe/rxe_resp.c
@@ -1217,7 +1217,14 @@ static enum resp_states do_complete(struct rxe_qp *qp,
spin_lock_irqsave(&qp->state_lock, flags);
if (unlikely(qp_state(qp) == IB_QPS_ERR)) {
spin_unlock_irqrestore(&qp->state_lock, flags);
- return RESPST_CHK_RESOURCE;
+ /* The packet was executed and completed before the QP
+ * moved to ERROR; it must be consumed exactly once.
+ * Re-entering the request chain with the stale packet
+ * would copy it into every remaining recv WQE as a new
+ * completion. Remaining WQEs are flushed by the drain
+ * path at rxe_receiver() entry.
+ */
+ return pkt ? RESPST_CLEANUP : RESPST_CHK_RESOURCE;
}
spin_unlock_irqrestore(&qp->state_lock, flags);
]
|
| 51/2 |
2026/10/21 01:57 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 6f7014237405e7f032b5c53a82d9eccf6161c291
Author: Ibrahim Hashimov <security@auditcode.ai>
Date: Sun Jul 12 14:17:20 2026 +0200
RDMA/rxe: Fix responder UAF on IB_QP_MAX_DEST_RD_ATOMIC modify_qp
rxe_qp_from_attr() handles IB_QP_MAX_DEST_RD_ATOMIC outside the
IB_QP_STATE path, so it holds no state_lock and runs while the responder
task rxe_receiver() (recv_task on rxe_wq) is live. A modify_qp() setting
only that attribute calls free_rd_atomic_resources() then
alloc_rd_atomic_resources(), swapping qp->resp.resources[] while
rxe_prepare_res()/find_resource() walk it; free_rd_atomic_resources()
also leaves the cached pointer qp->resp.res dangling. A local
unprivileged user can race the free/realloc into a use-after-free in
rxe_receiver() (local DoS).
Drain recv_task around the swap with rxe_disable_task()/rxe_enable_task(),
as rxe_qp_reset() already does when tearing this array down, re-enabling
only after alloc_rd_atomic_resources() succeeds so the responder never
resumes against a NULL qp->resp.resources on the ENOMEM path. Also clear
qp->resp.res in free_rd_atomic_resources(), like the rxe_resp.c
completion paths.
Reproduced under KASAN; the slab-use-after-free in rxe_receiver() is gone.
Fixes: 8700e3e7c485 ("Soft RoCE driver")
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Signed-off-by: Ibrahim Hashimov <security@auditcode.ai>
Link: https://patch.msgid.link/20260712121720.78001-1-security@auditcode.ai
Assisted-by: AuditCode-AI:2026.07
Signed-off-by: Leon Romanovsky <leon@kernel.org>
diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c
index 7a0529a17992..ec2cfb12559a 100644
--- a/drivers/infiniband/sw/rxe/rxe_qp.c
+++ b/drivers/infiniband/sw/rxe/rxe_qp.c
@@ -172,6 +172,7 @@ static void free_rd_atomic_resources(struct rxe_qp *qp)
}
kfree(qp->resp.resources);
qp->resp.resources = NULL;
+ qp->resp.res = NULL;
}
}
@@ -709,11 +710,23 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,
qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;
+ /*
+ * Not gated by IB_QP_STATE, so the responder task is live.
+ * Quiesce recv_task like rxe_qp_reset() before swapping the
+ * rd_atomic array, so rxe_receiver() cannot race the free/
+ * realloc.
+ */
+ rxe_disable_task(&qp->recv_task);
free_rd_atomic_resources(qp);
-
err = alloc_rd_atomic_resources(qp, max_dest_rd_atomic);
+ /*
+ * On ENOMEM leave recv_task quiesced: qp->resp.resources is
+ * NULL and rxe_prepare_res()/find_resource() would deref it.
+ * Re-enable only after a fresh array is installed.
+ */
if (err)
return err;
+ rxe_enable_task(&qp->recv_task);
}
if (mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
]
|
| 52/2 |
2026/10/21 01:57 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 98d446b7c013254a8a7b49720557676a3a851fde
Author: Allison Henderson <achender@kernel.org>
Date: Sat Oct 3 09:34:08 2026 -0700
net/rds: don't let the rdma_cm destroy an id RDS still owns on route failure
rds_rdma_cm_event_handler_cmn() hands the return value of
rdma_resolve_route() straight back to the rdma_cm on
RDMA_CM_EVENT_ADDR_RESOLVED. A synchronous failure there - -ENOMEM
from the route work allocation, an SA query that cannot be set up, a
RoCE route with no usable device - makes addr_handler() destroy the
id the event was delivered on. That id is ic->i_cm_id, and nothing
clears the pointer: the connection sits in RDS_CONN_CONNECTING with a
freed id until its shutdown calls rdma_disconnect() and
rdma_destroy_id() on it.
The ROUTE_RESOLVED case already avoids this: rds_ib_cm_initiate_connect()
forces a zero return while ic->i_cm_id == cm_id, as the comment there
explains. Do the same here - drop the connection and return 0 - so
the id stays RDS's to destroy from the shutdown, and the reconnect
gets a fresh one.
Fixes: 55b7ed0b582f ("RDS: Common RDMA transport code")
Assisted-by: LLM
Signed-off-by: Allison Henderson <achender@kernel.org>
Link: https://patch.msgid.link/20261003163408.250568-3-achender@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c
index 09cc2ba23570..7be38be1228e 100644
--- a/net/rds/rdma_transport.c
+++ b/net/rds/rdma_transport.c
@@ -107,9 +107,19 @@ static int rds_rdma_cm_event_handler_cmn(struct rdma_cm_id *cm_id,
}
rdma_set_service_type(cm_id, conn->c_tos);
rdma_set_min_rnr_timer(cm_id, IB_RNR_TIMER_000_32);
- /* XXX do we need to clean up if this fails? */
ret = rdma_resolve_route(cm_id,
RDS_RDMA_RESOLVE_TIMEOUT_MS);
+ if (ret) {
+ /* A non-zero return has the rdma_cm destroy
+ * the id, but it is still ic->i_cm_id, which
+ * the connection's shutdown would then
+ * disconnect and destroy again. Drop the
+ * connection and keep the id for that
+ * shutdown.
+ */
+ rds_conn_drop(conn);
+ ret = 0;
+ }
}
break;
]
|
| 53/2 |
2026/10/21 01:57 |
tool |
git-show |
0m
Args:
Results: map[Output:commit f97d8c7bab7843631206a114986c9059da03efeb
Author: Aohan Mei <henrymei@tencent.com>
Date: Fri Sep 11 15:34:32 2026 +0800
rds: ib: use rds_conn_drop() on protocol version mismatch
rds_ib_cm_connect_complete() runs from the RDMA-CM event handler with
conn->c_cm_lock held. When the peer negotiates a protocol version
older than RDS_PROTOCOL_COMPAT_VERSION, the handler calls
rds_conn_destroy(), which is only safe in the rmmod path: it
synchronously tears the connection down and flush_work()es the
shutdown work cp_down_w.
That shutdown work (rds_conn_shutdown()) needs cp_cm_lock, which is
the very lock the event handler still holds, so the flush never
completes: the two workers wait on each other and the RDS connection
workqueues stall for good.
All other RDMA-CM failure paths (REJECTED, CONNECT_ERROR,
DISCONNECTED) use rds_conn_drop(), which marks the connection
RDS_CONN_ERROR and schedules the shutdown work asynchronously. Use
it here as well.
Fixes: f147dd9ecabf ("RDS/IB: Disallow connections less than RDS 3.1")
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Cc: stable@vger.kernel.org
Reviewed-by: Allison Henderson <achender@kernel.org>
Signed-off-by: Aohan Mei <henrymei@tencent.com>
Link: https://patch.msgid.link/20260911073436.3542080-1-ljp1205831794@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index 4feb0edc360c..6e3110a04ae6 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -115,7 +115,7 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even
&conn->c_laddr, &conn->c_faddr,
RDS_PROTOCOL_MAJOR(conn->c_version),
RDS_PROTOCOL_MINOR(conn->c_version));
- rds_conn_destroy(conn);
+ rds_conn_drop(conn);
return;
}
}
]
|
| 54/2 |
2026/10/21 01:57 |
llm |
expert |
0m
Model:
Tokens:
input: 66148
output: 150
thoughts: 379
Thoughts: **A Critical Insight in the RXE Response Path**
Okay, I need to pause and really think through this. I just stumbled upon a change in commit `15ae32c4a355` related to `rxe_resp.c`, specifically within the `do_complete` function. This is a crucial part of the InfiniBand software receiver (RXE) implementation, dealing with how responses are processed and completed.
My attention was immediately drawn to a conditional change involving the QP (Queue Pair) state. Previously, if the QP was found to be in the `IB_QPS_ERR` state, the function would simply return `RESPST_CHK_RESOURCE`. However, the new logic introduces a crucial distinction: it now checks if a `pkt` (packet) is present. If a `pkt` exists, it returns `RESPST_CLEANUP`; otherwise, it falls back to `RESPST_CHK_RESOURCE`.
This seems like a very deliberate and important modification. The added comment is key here. It explains that if the packet was already executed and completed *before* the QP transitioned to an error state, we need to ensure it's consumed exactly once. The concern is that re-processing this "stale" packet in the request chain could lead to it being copied into multiple remaining receive Work Queue Elements (WQEs) as a new completion. This would be incorrect behavior, essentially creating phantom completions. The comment also points out that any remaining WQEs are handled by a "drain path" at `rxe_receiver()` entry, which suggests this `RESPST_CLEANUP` path is specifically for dealing with the immediate completion of the current packet while preventing further incorrect processing.
This refinement feels like it addresses a subtle but significant race condition or state management issue. By differentiating between the presence of a packet and the QP's error state, the code is ensuring that completed packets are correctly accounted for even in error scenarios, preventing duplicate completions and maintaining the integrity of the WQE processing. Itβs a clever way to handle the exact moment of completion relative to the QP error transition.
|
| 55/2 |
2026/10/21 01:57 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:1150 LineCount:100]
Results: map[Contents:1150: qp->resp.length : wqe->dma.length - wqe->dma.resid;
1151:
1152: /* fields after byte_len are different between kernel and user
1153: * space
1154: */
1155: if (qp->rcq->is_user) {
1156: uwc->wc_flags = IB_WC_GRH;
1157:
1158: if (pkt->mask & RXE_IMMDT_MASK) {
1159: uwc->wc_flags |= IB_WC_WITH_IMM;
1160: uwc->ex.imm_data = immdt_imm(pkt);
1161: }
1162:
1163: if (pkt->mask & RXE_IETH_MASK) {
1164: uwc->wc_flags |= IB_WC_WITH_INVALIDATE;
1165: uwc->ex.invalidate_rkey = ieth_rkey(pkt);
1166: }
1167:
1168: if (pkt->mask & RXE_DETH_MASK)
1169: uwc->src_qp = deth_sqp(pkt);
1170:
1171: uwc->port_num = qp->attr.port_num;
1172: } else {
1173: struct sk_buff *skb = PKT_TO_SKB(pkt);
1174:
1175: wc->wc_flags = IB_WC_GRH | IB_WC_WITH_NETWORK_HDR_TYPE;
1176: if (skb->protocol == htons(ETH_P_IP))
1177: wc->network_hdr_type = RDMA_NETWORK_IPV4;
1178: else
1179: wc->network_hdr_type = RDMA_NETWORK_IPV6;
1180:
1181: if (is_vlan_dev(skb->dev)) {
1182: wc->wc_flags |= IB_WC_WITH_VLAN;
1183: wc->vlan_id = vlan_dev_vlan_id(skb->dev);
1184: }
1185:
1186: if (pkt->mask & RXE_IMMDT_MASK) {
1187: wc->wc_flags |= IB_WC_WITH_IMM;
1188: wc->ex.imm_data = immdt_imm(pkt);
1189: }
1190:
1191: if (pkt->mask & RXE_IETH_MASK) {
1192: wc->wc_flags |= IB_WC_WITH_INVALIDATE;
1193: wc->ex.invalidate_rkey = ieth_rkey(pkt);
1194: }
1195:
1196: if (pkt->mask & RXE_DETH_MASK)
1197: wc->src_qp = deth_sqp(pkt);
1198:
1199: wc->port_num = qp->attr.port_num;
1200: }
1201: } else {
1202: if (wc->status != IB_WC_WR_FLUSH_ERR)
1203: rxe_err_qp(qp, "non-flush error status = %d\n",
1204: wc->status);
1205: }
1206:
1207: /* have copy for srq and reference for !srq */
1208: if (!qp->srq)
1209: queue_advance_consumer(qp->rq.queue, QUEUE_TYPE_FROM_CLIENT);
1210:
1211: qp->resp.wqe = NULL;
1212:
1213: if (rxe_cq_post(qp->rcq, &cqe, pkt ? bth_se(pkt) : 1))
1214: return RESPST_ERR_CQ_OVERFLOW;
1215:
1216: finish:
1217: spin_lock_irqsave(&qp->state_lock, flags);
1218: if (unlikely(qp_state(qp) == IB_QPS_ERR)) {
1219: spin_unlock_irqrestore(&qp->state_lock, flags);
1220: /* The packet was executed and completed before the QP
1221: * moved to ERROR; it must be consumed exactly once.
1222: * Re-entering the request chain with the stale packet
1223: * would copy it into every remaining recv WQE as a new
1224: * completion. Remaining WQEs are flushed by the drain
1225: * path at rxe_receiver() entry.
1226: */
1227: return pkt ? RESPST_CLEANUP : RESPST_CHK_RESOURCE;
1228: }
1229: spin_unlock_irqrestore(&qp->state_lock, flags);
1230:
1231: if (unlikely(!pkt))
1232: return RESPST_DONE;
1233: if (qp_type(qp) == IB_QPT_RC)
1234: return RESPST_ACKNOWLEDGE;
1235: else
1236: return RESPST_CLEANUP;
1237: }
1238:
1239:
1240: static int send_common_ack(struct rxe_qp *qp, u8 syndrome, u32 psn,
1241: int opcode, const char *msg)
1242: {
1243: int err;
1244: struct rxe_pkt_info ack_pkt;
1245: struct sk_buff *skb;
1246:
1247: skb = prepare_ack_packet(qp, &ack_pkt, opcode, 0, psn, syndrome);
1248: if (!skb)
1249: return -ENOMEM;
]
|
| 56/2 |
2026/10/21 01:57 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:1450 LineCount:120]
Results: map[Contents:1450: if (ibqp->event_handler) {
1451: rxe_dbg_qp(qp, "reporting QP event %d\n", etype);
1452: ibqp->event_handler(&event, ibqp->qp_context);
1453: }
1454: }
1455:
1456: /* Process a class A or C. Both are treated the same in this implementation. */
1457: static void do_class_ac_error(struct rxe_qp *qp, u8 syndrome,
1458: enum ib_wc_status status)
1459: {
1460: qp->resp.aeth_syndrome = syndrome;
1461: qp->resp.status = status;
1462:
1463: /* indicate that we should go through the ERROR state */
1464: qp->resp.goto_error = 1;
1465: }
1466:
1467: static enum resp_states do_class_d1e_error(struct rxe_qp *qp)
1468: {
1469: /* UC */
1470: if (qp->srq) {
1471: /* Class E */
1472: qp->resp.drop_msg = 1;
1473: if (qp->resp.wqe) {
1474: qp->resp.status = IB_WC_REM_INV_REQ_ERR;
1475: return RESPST_COMPLETE;
1476: } else {
1477: return RESPST_CLEANUP;
1478: }
1479: } else {
1480: /* Class D1. This packet may be the start of a
1481: * new message and could be valid. The previous
1482: * message is invalid and ignored. reset the
1483: * recv wr to its original state
1484: */
1485: if (qp->resp.wqe) {
1486: qp->resp.wqe->dma.resid = qp->resp.wqe->dma.length;
1487: qp->resp.wqe->dma.cur_sge = 0;
1488: qp->resp.wqe->dma.sge_offset = 0;
1489: qp->resp.opcode = -1;
1490: }
1491:
1492: if (qp->resp.mr) {
1493: rxe_put(qp->resp.mr);
1494: qp->resp.mr = NULL;
1495: }
1496:
1497: return RESPST_CLEANUP;
1498: }
1499: }
1500:
1501: /* drain incoming request packet queue */
1502: static void drain_req_pkts(struct rxe_qp *qp)
1503: {
1504: struct sk_buff *skb;
1505:
1506: while ((skb = skb_dequeue(&qp->req_pkts))) {
1507: rxe_put(qp);
1508: kfree_skb(skb);
1509: ib_device_put(qp->ibqp.device);
1510: }
1511: }
1512:
1513: /* complete receive wqe with flush error */
1514: static int flush_recv_wqe(struct rxe_qp *qp, struct rxe_recv_wqe *wqe)
1515: {
1516: struct rxe_cqe cqe = {};
1517: struct ib_wc *wc = &cqe.ibwc;
1518: struct ib_uverbs_wc *uwc = &cqe.uibwc;
1519: int err;
1520:
1521: if (qp->rcq->is_user) {
1522: uwc->wr_id = wqe->wr_id;
1523: uwc->status = IB_WC_WR_FLUSH_ERR;
1524: uwc->qp_num = qp_num(qp);
1525: } else {
1526: wc->wr_id = wqe->wr_id;
1527: wc->status = IB_WC_WR_FLUSH_ERR;
1528: wc->qp = &qp->ibqp;
1529: }
1530:
1531: err = rxe_cq_post(qp->rcq, &cqe, 0);
1532: if (err)
1533: rxe_dbg_cq(qp->rcq, "post cq failed err = %d\n", err);
1534:
1535: return err;
1536: }
1537:
1538: /* drain and optionally complete the receive queue
1539: * if unable to complete a wqe stop completing and
1540: * just flush the remaining wqes
1541: */
1542: static void flush_recv_queue(struct rxe_qp *qp, bool notify)
1543: {
1544: struct rxe_queue *q = qp->rq.queue;
1545: struct rxe_recv_wqe *wqe;
1546: int err;
1547:
1548: if (qp->srq) {
1549: if (notify && qp->ibqp.event_handler)
]
|
| 57/2 |
2026/10/21 01:57 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:330 LineCount:100]
Results: map[Contents: 330: memcpy(&qp->resp.srq_wqe, wqe, size);
331:
332: qp->resp.wqe = &qp->resp.srq_wqe.wqe;
333: return RESPST_CHK_LENGTH;
334: }
335:
336: static enum resp_states check_resource(struct rxe_qp *qp,
337: struct rxe_pkt_info *pkt)
338: {
339: struct rxe_srq *srq = qp->srq;
340:
341: if (pkt->mask & (RXE_READ_OR_ATOMIC_MASK | RXE_ATOMIC_WRITE_MASK)) {
342: /* it is the requesters job to not send
343: * too many read/atomic ops, we just
344: * recycle the responder resource queue
345: */
346: if (likely(qp->attr.max_dest_rd_atomic > 0))
347: return RESPST_CHK_LENGTH;
348: else
349: return RESPST_ERR_TOO_MANY_RDMA_ATM_REQ;
350: }
351:
352: if (pkt->mask & RXE_RWR_MASK) {
353: if (srq)
354: return get_srq_wqe(qp);
355:
356: return rxe_get_recv_wqe(qp);
357: }
358:
359: return RESPST_CHK_LENGTH;
360: }
361:
362: static enum resp_states rxe_resp_check_length(struct rxe_qp *qp,
363: struct rxe_pkt_info *pkt)
364: {
365: /*
366: * See IBA C9-92
367: * For UD QPs we only check if the packet will fit in the
368: * receive buffer later. For RDMA operations additional
369: * length checks are performed in check_rkey.
370: */
371: if ((qp_type(qp) == IB_QPT_GSI) || (qp_type(qp) == IB_QPT_UD)) {
372: unsigned int payload = payload_size(pkt);
373: unsigned int recv_buffer_len = 0;
374: int i;
375:
376: for (i = 0; i < qp->resp.wqe->dma.num_sge; i++)
377: recv_buffer_len += qp->resp.wqe->dma.sge[i].length;
378: if (payload + sizeof(union rdma_network_hdr) > recv_buffer_len) {
379: rxe_dbg_qp(qp, "The receive buffer is too small for this UD packet.\n");
380: return RESPST_ERR_LENGTH;
381: }
382: }
383:
384: if (pkt->mask & RXE_PAYLOAD_MASK && ((qp_type(qp) == IB_QPT_RC) ||
385: (qp_type(qp) == IB_QPT_UC))) {
386: unsigned int mtu = qp->mtu;
387: unsigned int payload = payload_size(pkt);
388:
389: if ((pkt->mask & RXE_START_MASK) &&
390: (pkt->mask & RXE_END_MASK)) {
391: if (unlikely(payload > mtu)) {
392: rxe_dbg_qp(qp, "only packet too long\n");
393: return RESPST_ERR_LENGTH;
394: }
395: } else if ((pkt->mask & RXE_START_MASK) ||
396: (pkt->mask & RXE_MIDDLE_MASK)) {
397: if (unlikely(payload != mtu)) {
398: rxe_dbg_qp(qp, "first or middle packet not mtu\n");
399: return RESPST_ERR_LENGTH;
400: }
401: } else if (pkt->mask & RXE_END_MASK) {
402: if (unlikely((payload == 0) || (payload > mtu))) {
403: rxe_dbg_qp(qp, "last packet zero or too long\n");
404: return RESPST_ERR_LENGTH;
405: }
406: }
407: }
408:
409: /* See IBA C9-94 */
410: if (pkt->mask & RXE_RETH_MASK) {
411: if (reth_len(pkt) > (1U << 31)) {
412: rxe_dbg_qp(qp, "dma length too long\n");
413: return RESPST_ERR_LENGTH;
414: }
415: }
416:
417: if (pkt->mask & RXE_RDMA_OP_MASK)
418: return RESPST_CHK_RKEY;
419: else
420: return RESPST_EXECUTE;
421: }
422:
423: /* if the reth length field is zero we can assume nothing
424: * about the rkey value and should not validate or use it.
425: * Instead set qp->resp.rkey to 0 which is an invalid rkey
426: * value since the minimum index part is 1.
427: */
428: static void qp_resp_from_reth(struct rxe_qp *qp, struct rxe_pkt_info *pkt)
429: {
]
|
| 58/2 |
2026/10/21 01:57 |
llm |
expert |
0m
Model:
Tokens:
input: 71469
output: 98
thoughts: 360
Thoughts: **A Critical Inquiry into `do_complete` and Packet Handling in `rxe_resp.c`**
My immediate thought process began with a sharp jolt of surprise and a demand for attention directed at a specific point in the code: line 1227 of `drivers/infiniband/sw/rxe/rxe_resp.c`, within the `do_complete` function. I saw the `finish:` label and the subsequent lock/unlock sequence. My mind immediately raced to a crucial "what if" scenario: what if the `pkt` argument passed to `do_complete` is `NULL` at this juncture?
This hypothetical then led to a more pointed question: under what circumstances could `do_complete` be invoked with `pkt == NULL`, or, more broadly, when would execution within `do_complete` actually *reach* the `finish:` label without a valid packet being processed? To answer this, I realized the necessity of a comprehensive understanding, demanding that I examine the *entirety* of the `do_complete` function. Furthermore, to grasp the context and flow that might lead to this specific `finish:` block, I knew I had to meticulously review the preceding sections of the `rxe_resp.c` file, specifically lines 1 to 330 and then a substantial chunk from 900 to 1160. This focused dive is essential to fully trace the execution path and identify any potential edge cases where the `pkt` might be absent when the `finish:` label is encountered.
|
| 59/2 |
2026/10/21 01:58 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:1 LineCount:130]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2: /*
3: * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4: * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5: */
6:
7: #include <linux/skbuff.h>
8:
9: #include "rxe.h"
10: #include "rxe_loc.h"
11: #include "rxe_queue.h"
12:
13: static char *resp_state_name[] = {
14: [RESPST_NONE] = "NONE",
15: [RESPST_GET_REQ] = "GET_REQ",
16: [RESPST_CHK_PSN] = "CHK_PSN",
17: [RESPST_CHK_OP_SEQ] = "CHK_OP_SEQ",
18: [RESPST_CHK_OP_VALID] = "CHK_OP_VALID",
19: [RESPST_CHK_RESOURCE] = "CHK_RESOURCE",
20: [RESPST_CHK_LENGTH] = "CHK_LENGTH",
21: [RESPST_CHK_RKEY] = "CHK_RKEY",
22: [RESPST_EXECUTE] = "EXECUTE",
23: [RESPST_READ_REPLY] = "READ_REPLY",
24: [RESPST_ATOMIC_REPLY] = "ATOMIC_REPLY",
25: [RESPST_ATOMIC_WRITE_REPLY] = "ATOMIC_WRITE_REPLY",
26: [RESPST_PROCESS_FLUSH] = "PROCESS_FLUSH",
27: [RESPST_COMPLETE] = "COMPLETE",
28: [RESPST_ACKNOWLEDGE] = "ACKNOWLEDGE",
29: [RESPST_CLEANUP] = "CLEANUP",
30: [RESPST_DUPLICATE_REQUEST] = "DUPLICATE_REQUEST",
31: [RESPST_ERR_MALFORMED_WQE] = "ERR_MALFORMED_WQE",
32: [RESPST_ERR_UNSUPPORTED_OPCODE] = "ERR_UNSUPPORTED_OPCODE",
33: [RESPST_ERR_MISALIGNED_ATOMIC] = "ERR_MISALIGNED_ATOMIC",
34: [RESPST_ERR_PSN_OUT_OF_SEQ] = "ERR_PSN_OUT_OF_SEQ",
35: [RESPST_ERR_MISSING_OPCODE_FIRST] = "ERR_MISSING_OPCODE_FIRST",
36: [RESPST_ERR_MISSING_OPCODE_LAST_C] = "ERR_MISSING_OPCODE_LAST_C",
37: [RESPST_ERR_MISSING_OPCODE_LAST_D1E] = "ERR_MISSING_OPCODE_LAST_D1E",
38: [RESPST_ERR_TOO_MANY_RDMA_ATM_REQ] = "ERR_TOO_MANY_RDMA_ATM_REQ",
39: [RESPST_ERR_RNR] = "ERR_RNR",
40: [RESPST_ERR_RKEY_VIOLATION_EVENT] = "ERR_RKEY_VIOLATION_EVENT",
41: [RESPST_ERR_RKEY_VIOLATION] = "ERR_RKEY_VIOLATION",
42: [RESPST_ERR_INVALIDATE_RKEY] = "ERR_INVALIDATE_RKEY_VIOLATION",
43: [RESPST_ERR_LENGTH] = "ERR_LENGTH",
44: [RESPST_ERR_CQ_OVERFLOW] = "ERR_CQ_OVERFLOW",
45: [RESPST_ERROR] = "ERROR",
46: [RESPST_DONE] = "DONE",
47: [RESPST_EXIT] = "EXIT",
48: };
49:
50: /* rxe_recv calls here to add a request packet to the input queue */
51: void rxe_resp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb)
52: {
53: skb_queue_tail(&qp->req_pkts, skb);
54: rxe_sched_task(&qp->recv_task);
55: }
56:
57: static inline enum resp_states get_req(struct rxe_qp *qp,
58: struct rxe_pkt_info **pkt_p)
59: {
60: struct sk_buff *skb;
61:
62: skb = skb_peek(&qp->req_pkts);
63: if (!skb)
64: return RESPST_EXIT;
65:
66: *pkt_p = SKB_TO_PKT(skb);
67:
68: return (qp->resp.res) ? RESPST_READ_REPLY : RESPST_CHK_PSN;
69: }
70:
71: static enum resp_states check_psn(struct rxe_qp *qp,
72: struct rxe_pkt_info *pkt)
73: {
74: int diff = psn_compare(pkt->psn, qp->resp.psn);
75: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
76:
77: switch (qp_type(qp)) {
78: case IB_QPT_RC:
79: if (diff > 0) {
80: if (qp->resp.sent_psn_nak)
81: return RESPST_CLEANUP;
82:
83: qp->resp.sent_psn_nak = 1;
84: rxe_counter_inc(rxe, RXE_CNT_OUT_OF_SEQ_REQ);
85: return RESPST_ERR_PSN_OUT_OF_SEQ;
86:
87: } else if (diff < 0) {
88: rxe_counter_inc(rxe, RXE_CNT_DUP_REQ);
89: return RESPST_DUPLICATE_REQUEST;
90: }
91:
92: if (qp->resp.sent_psn_nak)
93: qp->resp.sent_psn_nak = 0;
94:
95: break;
96:
97: case IB_QPT_UC:
98: if (qp->resp.drop_msg || diff != 0) {
99: if (pkt->mask & RXE_START_MASK) {
100: qp->resp.drop_msg = 0;
]
|
| 60/2 |
2026/10/21 01:58 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:950 LineCount:200]
Results: map[Contents: 950: if (res->state == rdatm_res_state_new) {
951: if (!res->replay || qp->resp.length == 0) {
952: /* if length == 0 mr will be NULL (is ok)
953: * otherwise qp->resp.mr holds a ref on mr
954: * which we transfer to mr and drop below.
955: */
956: mr = qp->resp.mr;
957: qp->resp.mr = NULL;
958: } else {
959: mr = rxe_recheck_mr(qp, res->read.rkey);
960: if (!mr)
961: return RESPST_ERR_RKEY_VIOLATION;
962: }
963:
964: if (res->read.resid <= mtu)
965: opcode = IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY;
966: else
967: opcode = IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST;
968: } else {
969: /* re-lookup mr from rkey on all later packets.
970: * length will be non-zero. This can fail if someone
971: * modifies or destroys the mr since the first packet.
972: */
973: mr = rxe_recheck_mr(qp, res->read.rkey);
974: if (!mr)
975: return RESPST_ERR_RKEY_VIOLATION;
976:
977: if (res->read.resid > mtu)
978: opcode = IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE;
979: else
980: opcode = IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST;
981: }
982:
983: res->state = rdatm_res_state_next;
984:
985: payload = min_t(int, res->read.resid, mtu);
986:
987: skb = prepare_ack_packet(qp, &ack_pkt, opcode, payload,
988: res->cur_psn, AETH_ACK_UNLIMITED);
989: if (!skb) {
990: state = RESPST_ERR_RNR;
991: goto err_out;
992: }
993:
994: err = rxe_mr_copy(mr, res->read.va, payload_addr(&ack_pkt),
995: payload, RXE_FROM_MR_OBJ);
996: if (err) {
997: kfree_skb(skb);
998: state = RESPST_ERR_RKEY_VIOLATION;
999: goto err_out;
1000: }
1001:
1002: if (bth_pad(&ack_pkt)) {
1003: u8 *pad = payload_addr(&ack_pkt) + payload;
1004:
1005: memset(pad, 0, bth_pad(&ack_pkt));
1006: }
1007:
1008: /* rxe_xmit_packet always consumes the skb */
1009: err = rxe_xmit_packet(qp, &ack_pkt, skb);
1010: if (err) {
1011: state = RESPST_ERR_RNR;
1012: goto err_out;
1013: }
1014:
1015: res->read.va += payload;
1016: res->read.resid -= payload;
1017: res->cur_psn = (res->cur_psn + 1) & BTH_PSN_MASK;
1018:
1019: if (res->read.resid > 0) {
1020: state = RESPST_DONE;
1021: } else {
1022: qp->resp.res = NULL;
1023: if (!res->replay)
1024: qp->resp.opcode = -1;
1025: if (psn_compare(res->cur_psn, qp->resp.psn) >= 0)
1026: qp->resp.psn = res->cur_psn;
1027: state = RESPST_CLEANUP;
1028: }
1029:
1030: err_out:
1031: if (mr)
1032: rxe_put(mr);
1033: return state;
1034: }
1035:
1036: static int invalidate_rkey(struct rxe_qp *qp, u32 rkey)
1037: {
1038: if (rkey_is_mw(rkey))
1039: return rxe_invalidate_mw(qp, rkey);
1040: else
1041: return rxe_invalidate_mr(qp, rkey);
1042: }
1043:
1044: /* Executes a new request. A retried request never reach that function (send
1045: * and writes are discarded, and reads and atomics are retried elsewhere.
1046: */
1047: static enum resp_states execute(struct rxe_qp *qp, struct rxe_pkt_info *pkt)
1048: {
1049: enum resp_states err;
]
|
| 61/2 |
2026/10/21 01:58 |
llm |
expert |
0m
Model:
Tokens:
input: 75289
output: 53
thoughts: 38
Thoughts: **My Thought Process Regarding `rxe_resp.c` Lines 1050-1160**
Alright, I've just delved into lines 1050 through 1160 of `drivers/infiniband/sw/rxe/rxe_resp.c`. My primary objective here is to fully grasp the flow and logic concerning the *response* path within the RXE (RDMA-CM Emulation) driver. Given my expertise in this domain, I'm particularly focused on how incoming RDMA messages are handled, specifically those that necessitate a response from the driver's perspective.
As I scan these lines, I'm looking for the critical junctures where the driver acknowledges receipt of a request, initiates the processing of that request, and subsequently prepares or queues up the corresponding response. I'm not just reading code; I'm tracing the execution path, visualizing the state changes of the relevant data structures β likely RDMA Connection Management (RCM) or specific RXE packet structures β and anticipating potential race conditions or error handling scenarios.
I'm paying close attention to the function calls and data manipulations. What are the key data structures being passed around? Are we dealing with incoming work queue (WQE) descriptors, completion queue (CQ) entries, or perhaps internal state machines for managing connection state and pending operations? I'm also keenly interested in how the driver manages the lifecycle of these requests and responses, from initial reception to final acknowledgment or completion.
Specifically, I'm analyzing the logic for:
* **Request reception and identification:** How does the code determine that an incoming packet is indeed a response-requiring operation? What flags or message types are being checked?
* **State management:** What internal states are being transitioned? Are we moving from an 'awaiting response' state to a 'response being prepared' or 'response sent' state? I'm thinking about how the driver keeps track of ongoing operations that require a reply.
* **Response generation:** What information is being assembled for the response? Is it simply an acknowledgment, or does it contain data or status updates related to the original request? I'm trying to understand the composition of the outgoing response packet or message.
* **Queuing and transmission:** How is the response handed off for actual transmission? Is it directly enqueued to a transmit queue, or is there an intermediate buffering or scheduling mechanism?
* **Error handling:** I'm always on the lookout for how errors are detected and handled. What happens if a response cannot be generated or sent? Are there timeouts, retries, or specific error codes being set?
My expectation is that this section of code will reveal the intricate dance of packet processing, state machine transitions, and resource management that underpins the RXE driver's ability to emulate RDMA behavior for applications that rely on it. I'm eager to see how the low-level packet manipulation translates into the higher-level RDMA semantics.
|
| 62/2 |
2026/10/21 01:58 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:1050 LineCount:110]
Results: map[Contents:1050: struct sk_buff *skb = PKT_TO_SKB(pkt);
1051: union rdma_network_hdr hdr;
1052:
1053: if (pkt->mask & RXE_SEND_MASK) {
1054: if (qp_type(qp) == IB_QPT_UD ||
1055: qp_type(qp) == IB_QPT_GSI) {
1056: if (skb->protocol == htons(ETH_P_IP)) {
1057: memset(&hdr.reserved, 0,
1058: sizeof(hdr.reserved));
1059: memcpy(&hdr.roce4grh, ip_hdr(skb),
1060: sizeof(hdr.roce4grh));
1061: err = send_data_in(qp, &hdr, sizeof(hdr));
1062: } else {
1063: err = send_data_in(qp, ipv6_hdr(skb),
1064: sizeof(hdr));
1065: }
1066: if (err)
1067: return err;
1068: }
1069: err = send_data_in(qp, payload_addr(pkt), payload_size(pkt));
1070: if (err)
1071: return err;
1072: } else if (pkt->mask & RXE_WRITE_MASK) {
1073: err = write_data_in(qp, pkt);
1074: if (err)
1075: return err;
1076: } else if (pkt->mask & RXE_READ_MASK) {
1077: /* For RDMA Read we can increment the msn now. See C9-148. */
1078: qp->resp.msn++;
1079: return RESPST_READ_REPLY;
1080: } else if (pkt->mask & RXE_ATOMIC_MASK) {
1081: return RESPST_ATOMIC_REPLY;
1082: } else if (pkt->mask & RXE_ATOMIC_WRITE_MASK) {
1083: return RESPST_ATOMIC_WRITE_REPLY;
1084: } else if (pkt->mask & RXE_FLUSH_MASK) {
1085: return RESPST_PROCESS_FLUSH;
1086: } else {
1087: /* Unreachable */
1088: WARN_ON_ONCE(1);
1089: }
1090:
1091: if (pkt->mask & RXE_IETH_MASK) {
1092: u32 rkey = ieth_rkey(pkt);
1093:
1094: err = invalidate_rkey(qp, rkey);
1095: if (err)
1096: return RESPST_ERR_INVALIDATE_RKEY;
1097: }
1098:
1099: if (pkt->mask & RXE_END_MASK)
1100: /* We successfully processed this new request. */
1101: qp->resp.msn++;
1102:
1103: /* next expected psn, read handles this separately */
1104: qp->resp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
1105: qp->resp.ack_psn = qp->resp.psn;
1106:
1107: qp->resp.opcode = pkt->opcode;
1108: qp->resp.status = IB_WC_SUCCESS;
1109:
1110: if (pkt->mask & RXE_COMP_MASK)
1111: return RESPST_COMPLETE;
1112: else if (qp_type(qp) == IB_QPT_RC)
1113: return RESPST_ACKNOWLEDGE;
1114: else
1115: return RESPST_CLEANUP;
1116: }
1117:
1118: static enum resp_states do_complete(struct rxe_qp *qp,
1119: struct rxe_pkt_info *pkt)
1120: {
1121: struct rxe_cqe cqe;
1122: struct ib_wc *wc = &cqe.ibwc;
1123: struct ib_uverbs_wc *uwc = &cqe.uibwc;
1124: struct rxe_recv_wqe *wqe = qp->resp.wqe;
1125: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
1126: unsigned long flags;
1127:
1128: if (!wqe)
1129: goto finish;
1130:
1131: memset(&cqe, 0, sizeof(cqe));
1132:
1133: if (qp->rcq->is_user) {
1134: uwc->status = qp->resp.status;
1135: uwc->qp_num = qp->ibqp.qp_num;
1136: uwc->wr_id = wqe->wr_id;
1137: } else {
1138: wc->status = qp->resp.status;
1139: wc->qp = &qp->ibqp;
1140: wc->wr_id = wqe->wr_id;
1141: }
1142:
1143: if (wc->status == IB_WC_SUCCESS) {
1144: rxe_counter_inc(rxe, RXE_CNT_RDMA_RECV);
1145: wc->opcode = (pkt->mask & RXE_IMMDT_MASK &&
1146: pkt->mask & RXE_WRITE_MASK) ?
1147: IB_WC_RECV_RDMA_WITH_IMM : IB_WC_RECV;
1148: wc->byte_len = (pkt->mask & RXE_IMMDT_MASK &&
1149: pkt->mask & RXE_WRITE_MASK) ?
]
|
| 63/2 |
2026/10/21 01:58 |
llm |
expert |
1m
Model:
Tokens:
input: 77045
output: 44
thoughts: 1708
Thoughts: **The Mystery of the Softlockup and the 50-Second Wait**
I'm trying to unravel why I'm hitting a `SOFTLOCKUP` with a `Tainted` kernel, specifically a timeout in `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))` within the `__rxe_cleanup` function. This timeout, lasting a staggering 50 seconds, is clearly the root cause of the softlockup. My immediate thought is to scrutinize every loop within the `rxe` and `rds` subsystems to pinpoint where this delay originates.
Diving into `rds_ib_conn_path_shutdown`, I observe a `while (!wait_event_timeout(...))` loop (lines 1099-1101). Crucially, this loop *completes* successfully before reaching line 1113, where `rdma_destroy_qp(ic->i_cm_id)` is called. This means the event it was waiting for, `rds_ib_ring_empty_wait`, was satisfied.
Then, things get interesting. After `rdma_disconnect(ic->i_cm_id)` is called, I start to wonder about its success or failure. If `rdma_disconnect` *succeeds*, it leads to `cma_modify_qp_err(id_priv)` setting the QP state to `IB_QPS_ERR`. Subsequently, the send and receive rings empty (or were already empty), and `rds_ib_conn_path_shutdown` proceeds to call `rdma_destroy_qp`. This path eventually leads to `rxe_destroy_qp` and then `rxe_cleanup`, which in turn calls `__rxe_cleanup(&qp->elem, true)`.
Inside `__rxe_cleanup`, I see `__rxe_put(elem)` followed by a check: `if (!completion_done(&elem->complete))`. If this condition is true, the problematic `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))` is invoked. The fact that this times out after 50 seconds is what triggers the `WARN_ON(!ret)` at `drivers/infiniband/sw/rxe/rxe_pool.c:212`, and thus the softlockup.
Looking at the crash registers, specifically at `__rxe_cleanup+0x311/0x350`, I'm still faced with the same question: why did that 50-second timeout occur? This leads me to two primary hypotheses:
1. **Reference Leak:** A reference count on the `qp` (`elem->ref_cnt`) was leaked, meaning it was never decremented while the `qp` was still considered "alive."
2. **Stuck Task/Thread:** A task or thread holding a reference on the `qp` is either stuck in an infinite loop (the softlockup itself) or is blocked indefinitely, preventing the reference from being released.
I need to investigate both of these possibilities thoroughly. For the reference leak scenario, I'll be meticulously examining every call site for `rxe_get(qp)` and `rxe_pool_get_index(&rxe->qp_pool, ...)` to see if any code path could potentially fail to drop a `qp` reference or hold onto it for an unreasonable duration, specifically until `rxe_qp_do_cleanup`.
This thought process then leads me to a crucial realization: could something be holding a reference on the `qp` that is *only* released in `rxe_qp_do_cleanup` (or when the `qp` enters `IB_QPS_ERR`/`IB_QPS_RESET`), and could `rxe_qp_do_cleanup` *only* be called *after* `elem->complete` has completed? This seems like a critical dependency to verify.
My next line of inquiry then focuses on the state of `qp` when `rxe_destroy_qp(qp)` is called. Specifically, I need to understand under what circumstances `qp` is *not* in `IB_QPS_ERR`. This brings me back to the `rdma_disconnect` call in `rds_ib_conn_path_shutdown`. If `rdma_disconnect` fails, why would it fail? The comment hints that it might fail if `!id_priv->cm_id.ib`, meaning the `ib` structure wasn't yet allocated. The question then becomes: if `cm_id.ib` isn't allocated, has `ic->i_cm_id->qp` been created yet? I'll be digging into where `rds_ib_setup_qp` or `rdma_create_qp` are called within the `net/rds/` directory to answer this.
|
| 64/2 |
2026/10/21 01:59 |
tool |
grepper |
0m
Args: map[Expression:rds_ib_setup_qp|rdma_create_qp PathPrefixes:[net/rds/]]
Results: map[Output:net/rds/ib_cm.c=466=static struct rds_header **rds_dma_hdrs_alloc(struct rds_ib_device *dev,
--
net/rds/ib_cm.c-501- */
net/rds/ib_cm.c:502:static int rds_ib_setup_qp(struct rds_connection *conn)
net/rds/ib_cm.c-503-{
--
net/rds/ib_cm.c-599- */
net/rds/ib_cm.c:600: ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr);
net/rds/ib_cm.c-601- if (ret) {
net/rds/ib_cm.c:602: rdsdebug("rdma_create_qp failed: %d\n", ret);
net/rds/ib_cm.c-603- goto recv_cq_out;
--
net/rds/ib_cm.c=783=int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
--
net/rds/ib_cm.c-910-
net/rds/ib_cm.c:911: err = rds_ib_setup_qp(conn);
net/rds/ib_cm.c-912- if (err) {
net/rds/ib_cm.c:913: rds_ib_conn_error(conn, "rds_ib_setup_qp failed (%d)\n", err);
net/rds/ib_cm.c-914- goto out;
--
net/rds/ib_cm.c=936=int rds_ib_cm_initiate_connect(struct rdma_cm_id *cm_id, bool isv6)
--
net/rds/ib_cm.c-948-
net/rds/ib_cm.c:949: ret = rds_ib_setup_qp(conn);
net/rds/ib_cm.c-950- if (ret) {
net/rds/ib_cm.c:951: rds_ib_conn_error(conn, "rds_ib_setup_qp failed (%d)\n", ret);
net/rds/ib_cm.c-952- goto out;
]
|
| 65/2 |
2026/10/21 01:59 |
llm |
expert |
0m
Model:
Tokens:
input: 79403
output: 43
thoughts: 58
Thoughts: **A Sudden Realization - A Deep Dive into RDS IB CM Connection Initiation**
My mind just did a sharp turn! I was sifting through the code, likely working on some aspect of RDMA, and then it hit me: I need to scrutinize the `rds_ib_cm_initiate_connect` function within the `net/rds/ib_cm.c` file. Specifically, I'm zeroing in on the critical section from lines 900 to 990. This is where the heart of initiating an InfiniBand Connection Manager (CM) connection for RDS lies, and I have a hunch there's something crucial to understand or perhaps even a potential issue lurking within those lines. My expert brain demands a granular understanding of this process.
|
| 66/2 |
2026/10/21 01:59 |
tool |
read-file |
0m
Args: map[File:net/rds/ib_cm.c FirstLine:900 LineCount:90]
Results: map[Contents: 900:
901: BUG_ON(cm_id->context);
902: BUG_ON(ic->i_cm_id);
903:
904: ic->i_cm_id = cm_id;
905: cm_id->context = conn;
906:
907: /* We got halfway through setting up the ib_connection, if we
908: * fail now, we have to take the long route out of this mess. */
909: destroy = 0;
910:
911: err = rds_ib_setup_qp(conn);
912: if (err) {
913: rds_ib_conn_error(conn, "rds_ib_setup_qp failed (%d)\n", err);
914: goto out;
915: }
916:
917: rds_ib_cm_fill_conn_param(conn, &conn_param, &dp_rep, version,
918: event->param.conn.responder_resources,
919: event->param.conn.initiator_depth, isv6);
920:
921: rdma_set_min_rnr_timer(cm_id, IB_RNR_TIMER_000_32);
922: /* rdma_accept() calls rdma_reject() internally if it fails */
923: if (rdma_accept(cm_id, &conn_param))
924: rds_ib_conn_error(conn, "rdma_accept failed\n");
925:
926: out:
927: if (conn)
928: mutex_unlock(&conn->c_cm_lock);
929: if (err)
930: rdma_reject(cm_id, &err, sizeof(int),
931: IB_CM_REJ_CONSUMER_DEFINED);
932: return destroy;
933: }
934:
935:
936: int rds_ib_cm_initiate_connect(struct rdma_cm_id *cm_id, bool isv6)
937: {
938: struct rds_connection *conn = cm_id->context;
939: struct rds_ib_connection *ic = conn->c_transport_data;
940: struct rdma_conn_param conn_param;
941: union rds_ib_conn_priv dp;
942: int ret;
943:
944: /* If the peer doesn't do protocol negotiation, we must
945: * default to RDSv3.0 */
946: rds_ib_set_protocol(conn, RDS_PROTOCOL_4_1);
947: ic->i_flowctl = rds_ib_sysctl_flow_control; /* advertise flow control */
948:
949: ret = rds_ib_setup_qp(conn);
950: if (ret) {
951: rds_ib_conn_error(conn, "rds_ib_setup_qp failed (%d)\n", ret);
952: goto out;
953: }
954:
955: rds_ib_cm_fill_conn_param(conn, &conn_param, &dp,
956: conn->c_proposed_version,
957: UINT_MAX, UINT_MAX, isv6);
958: ret = rdma_connect_locked(cm_id, &conn_param);
959: if (ret)
960: rds_ib_conn_error(conn, "rdma_connect_locked failed (%d)\n",
961: ret);
962:
963: out:
964: /* Beware - returning non-zero tells the rdma_cm to destroy
965: * the cm_id. We should certainly not do it as long as we still
966: * "own" the cm_id. */
967: if (ret) {
968: if (ic->i_cm_id == cm_id)
969: ret = 0;
970: }
971: ic->i_active_side = true;
972: return ret;
973: }
974:
975: int rds_ib_conn_path_connect(struct rds_conn_path *cp)
976: {
977: struct rds_connection *conn = cp->cp_conn;
978: struct sockaddr_storage src, dest;
979: rdma_cm_event_handler handler;
980: struct rds_ib_connection *ic;
981: int ret;
982:
983: ic = conn->c_transport_data;
984:
985: /* XXX I wonder what affect the port space has */
986: /* delegate cm event handler to rdma_transport */
987: #if IS_ENABLED(CONFIG_IPV6)
988: if (conn->c_isv6)
989: handler = rds6_rdma_cm_event_handler;
]
|
| 67/2 |
2026/10/21 01:59 |
llm |
expert |
0m
Model:
Tokens:
input: 80975
output: 44
thoughts: 294
Thoughts: **My Real-Time Processing of the RDMA Connection Establishment Flow**
Okay, hold on a moment β a critical thought just struck me as I was examining the code flow around `rds_ib_cm_initiate_connect`. I noticed it's being invoked upon receiving an `RDMA_CM_EVENT_ROUTE_RESOLVED` event. This immediately triggered a detailed look into its internal workings.
My primary focus then shifted to the sequence of events within `rds_ib_cm_initiate_connect`. The very first step involves a call to `rds_ib_setup_qp(conn)`, which in turn invokes `rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr)`. What's crucial here is that `rdma_create_qp` not only creates the Queue Pair (QP) but also automatically transitions it to the `IB_QPS_INIT` state. This is a fundamental part of the QP lifecycle.
Following this, the code proceeds to `rdma_connect_locked(cm_id, &conn_param)`. This function, as I understand it, is responsible for establishing the connection parameters and is expected to create the `id_priv->cm_id.ib` structure.
Now, here's where the potential for a race condition or an unexpected path emerged in my thinking. I started to ponder what would happen if `rdma_connect_locked` were to fail for some reason. More critically, what if `rds_ib_conn_path_shutdown` were to execute *before* `rdma_connect_locked` successfully creates the `id_priv->cm_id.ib` structure? In such a scenario, the QP would be left hanging in the `IB_QPS_INIT` state, with no pending operations or queueing possible. This seems like a suboptimal and potentially problematic state.
Conversely, I then considered the "happy path." What if `rdma_connect_locked` *succeeds* as intended, and subsequently, an `RDMA_CM_EVENT_ESTABLISHED` event is received, leading to the execution of `rds_ib_cm_connect_complete`? To fully grasp this positive outcome, I immediately decided that I needed to delve into the specifics of `rds_ib_cm_connect_complete` as implemented in `net/rds/ib_cm.c`, specifically reviewing lines 1 to 260. This detailed examination would clarify how the successful connection establishment is handled and what states are managed thereafter.
|
| 68/2 |
2026/10/21 02:00 |
tool |
read-file |
0m
Args: map[File:net/rds/ib_cm.c FirstLine:100 LineCount:160]
Results: map[Contents: 100: major = dp->ricp_v4.dp_protocol_major;
101: minor = dp->ricp_v4.dp_protocol_minor;
102: credit = dp->ricp_v4.dp_credit;
103: ack_seq = get_unaligned(&dp->ricp_v4.dp_ack_seq);
104: }
105:
106: /* make sure it isn't empty data */
107: if (major) {
108: rds_ib_set_protocol(conn, RDS_PROTOCOL(major, minor));
109: rds_ib_set_flow_control(conn, be32_to_cpu(credit));
110: }
111:
112: if (conn->c_version < RDS_PROTOCOL_VERSION) {
113: if (conn->c_version != RDS_PROTOCOL_COMPAT_VERSION) {
114: pr_notice("RDS/IB: Connection <%pI6c,%pI6c> version %u.%u no longer supported\n",
115: &conn->c_laddr, &conn->c_faddr,
116: RDS_PROTOCOL_MAJOR(conn->c_version),
117: RDS_PROTOCOL_MINOR(conn->c_version));
118: rds_conn_drop(conn);
119: return;
120: }
121: }
122:
123: pr_notice("RDS/IB: %s conn connected <%pI6c,%pI6c,%d> version %u.%u%s\n",
124: ic->i_active_side ? "Active" : "Passive",
125: &conn->c_laddr, &conn->c_faddr, conn->c_tos,
126: RDS_PROTOCOL_MAJOR(conn->c_version),
127: RDS_PROTOCOL_MINOR(conn->c_version),
128: ic->i_flowctl ? ", flow control" : "");
129:
130: /* receive sl from the peer */
131: ic->i_sl = ic->i_cm_id->route.path_rec->sl;
132:
133: atomic_set(&ic->i_cq_quiesce, 0);
134:
135: /* Init rings and fill recv. this needs to wait until protocol
136: * negotiation is complete, since ring layout is different
137: * from 3.1 to 4.1.
138: */
139: rds_ib_send_init_ring(ic);
140: rds_ib_recv_init_ring(ic);
141: /* Post receive buffers - as a side effect, this will update
142: * the posted credit count. */
143: rds_ib_recv_refill(conn, 1, GFP_KERNEL);
144:
145: /* update ib_device with this local ipaddr */
146: err = rds_ib_update_ipaddr(ic->rds_ibdev, &conn->c_laddr);
147: if (err)
148: printk(KERN_ERR "rds_ib_update_ipaddr failed (%d)\n",
149: err);
150:
151: /* If the peer gave us the last packet it saw, process this as if
152: * we had received a regular ACK. */
153: if (dp) {
154: if (ack_seq)
155: rds_send_drop_acked(conn, be64_to_cpu(ack_seq),
156: NULL);
157: }
158:
159: conn->c_proposed_version = conn->c_version;
160: rds_connect_complete(conn);
161: }
162:
163: static void rds_ib_cm_fill_conn_param(struct rds_connection *conn,
164: struct rdma_conn_param *conn_param,
165: union rds_ib_conn_priv *dp,
166: u32 protocol_version,
167: u32 max_responder_resources,
168: u32 max_initiator_depth,
169: bool isv6)
170: {
171: struct rds_ib_connection *ic = conn->c_transport_data;
172: struct rds_ib_device *rds_ibdev = ic->rds_ibdev;
173:
174: memset(conn_param, 0, sizeof(struct rdma_conn_param));
175:
176: conn_param->responder_resources = min3(rds_ibdev->max_responder_resources,
177: max_responder_resources, U8_MAX);
178: conn_param->initiator_depth = min3(rds_ibdev->max_initiator_depth,
179: max_initiator_depth, U8_MAX);
180: conn_param->retry_count = min(rds_ib_retry_count, 7U);
181: conn_param->rnr_retry_count = 7;
182:
183: if (dp) {
184: memset(dp, 0, sizeof(*dp));
185: if (isv6) {
186: dp->ricp_v6.dp_saddr = conn->c_laddr;
187: dp->ricp_v6.dp_daddr = conn->c_faddr;
188: dp->ricp_v6.dp_protocol_major =
189: RDS_PROTOCOL_MAJOR(protocol_version);
190: dp->ricp_v6.dp_protocol_minor =
191: RDS_PROTOCOL_MINOR(protocol_version);
192: dp->ricp_v6.dp_protocol_minor_mask =
193: cpu_to_be16(RDS_IB_SUPPORTED_PROTOCOLS);
194: dp->ricp_v6.dp_ack_seq =
195: cpu_to_be64(rds_ib_piggyb_ack(ic));
196: dp->ricp_v6.dp_cmn.ricpc_dp_toss = conn->c_tos;
197:
198: conn_param->private_data = &dp->ricp_v6;
199: conn_param->private_data_len = sizeof(dp->ricp_v6);
]
|
| 69/2 |
2026/10/21 02:00 |
llm |
expert |
0m
Model:
Tokens:
input: 83171
output: 54
thoughts: 93
Thoughts: **A Sudden Realization Regarding Response State Handling**
Hold on a moment β something just struck me! I was reviewing the `do_complete` function within `drivers/infiniband/sw/rxe/rxe_resp.c`, and a potential issue or an important detail caught my eye. My immediate thought is that I need to thoroughly examine *all* the ways `RESPST_COMPLETE` is reached within this specific function. It's not enough to just look at one call site; I need to trace every possible execution path that leads to `RESPST_COMPLETE` being set or passed to `do_complete(qp, pkt)`. To do this effectively, I'm going to perform a targeted search for `RESPST_COMPLETE` directly within `drivers/infiniband/sw/rxe/rxe_resp.c`. This granular examination will help me ensure I'm not missing any subtle interactions or edge cases in how we're managing the response state.
|
| 70/2 |
2026/10/21 02:00 |
tool |
grepper |
0m
Args: map[Expression:RESPST_COMPLETE|RESPST_CHK_RESOURCE PathPrefixes:[drivers/infiniband/sw/rxe/rxe_resp.c]]
Results: map[Output:drivers/infiniband/sw/rxe/rxe_resp.c=13=static char *resp_state_name[] = {
--
drivers/infiniband/sw/rxe/rxe_resp.c-18- [RESPST_CHK_OP_VALID] = "CHK_OP_VALID",
drivers/infiniband/sw/rxe/rxe_resp.c:19: [RESPST_CHK_RESOURCE] = "CHK_RESOURCE",
drivers/infiniband/sw/rxe/rxe_resp.c-20- [RESPST_CHK_LENGTH] = "CHK_LENGTH",
--
drivers/infiniband/sw/rxe/rxe_resp.c-26- [RESPST_PROCESS_FLUSH] = "PROCESS_FLUSH",
drivers/infiniband/sw/rxe/rxe_resp.c:27: [RESPST_COMPLETE] = "COMPLETE",
drivers/infiniband/sw/rxe/rxe_resp.c-28- [RESPST_ACKNOWLEDGE] = "ACKNOWLEDGE",
--
drivers/infiniband/sw/rxe/rxe_resp.c=229=static enum resp_states check_op_valid(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-256-
drivers/infiniband/sw/rxe/rxe_resp.c:257: return RESPST_CHK_RESOURCE;
drivers/infiniband/sw/rxe/rxe_resp.c-258-}
--
drivers/infiniband/sw/rxe/rxe_resp.c=1047=static enum resp_states execute(struct rxe_qp *qp, struct rxe_pkt_info *pkt)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1110- if (pkt->mask & RXE_COMP_MASK)
drivers/infiniband/sw/rxe/rxe_resp.c:1111: return RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1112- else if (qp_type(qp) == IB_QPT_RC)
--
drivers/infiniband/sw/rxe/rxe_resp.c=1118=static enum resp_states do_complete(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-1226- */
drivers/infiniband/sw/rxe/rxe_resp.c:1227: return pkt ? RESPST_CLEANUP : RESPST_CHK_RESOURCE;
drivers/infiniband/sw/rxe/rxe_resp.c-1228- }
--
drivers/infiniband/sw/rxe/rxe_resp.c=1467=static enum resp_states do_class_d1e_error(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1474- qp->resp.status = IB_WC_REM_INV_REQ_ERR;
drivers/infiniband/sw/rxe/rxe_resp.c:1475: return RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1476- } else {
--
drivers/infiniband/sw/rxe/rxe_resp.c=1571=int rxe_receiver(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1609- break;
drivers/infiniband/sw/rxe/rxe_resp.c:1610: case RESPST_CHK_RESOURCE:
drivers/infiniband/sw/rxe/rxe_resp.c-1611- state = check_resource(qp, pkt);
--
drivers/infiniband/sw/rxe/rxe_resp.c-1621- break;
drivers/infiniband/sw/rxe/rxe_resp.c:1622: case RESPST_COMPLETE:
drivers/infiniband/sw/rxe/rxe_resp.c-1623- state = do_complete(qp, pkt);
--
drivers/infiniband/sw/rxe/rxe_resp.c-1659- IB_WC_REM_INV_REQ_ERR);
drivers/infiniband/sw/rxe/rxe_resp.c:1660: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1661- break;
--
drivers/infiniband/sw/rxe/rxe_resp.c-1692- IB_WC_REM_ACCESS_ERR);
drivers/infiniband/sw/rxe/rxe_resp.c:1693: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1694- } else {
--
drivers/infiniband/sw/rxe/rxe_resp.c-1698- qp->resp.status = IB_WC_REM_ACCESS_ERR;
drivers/infiniband/sw/rxe/rxe_resp.c:1699: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1700- } else {
--
drivers/infiniband/sw/rxe/rxe_resp.c-1710- qp->resp.status = IB_WC_REM_INV_REQ_ERR;
drivers/infiniband/sw/rxe/rxe_resp.c:1711: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1712- break;
--
drivers/infiniband/sw/rxe/rxe_resp.c-1718- IB_WC_REM_INV_REQ_ERR);
drivers/infiniband/sw/rxe/rxe_resp.c:1719: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1720- } else if (qp->srq) {
--
drivers/infiniband/sw/rxe/rxe_resp.c-1722- qp->resp.status = IB_WC_REM_INV_REQ_ERR;
drivers/infiniband/sw/rxe/rxe_resp.c:1723: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1724- } else {
--
drivers/infiniband/sw/rxe/rxe_resp.c-1734- IB_WC_LOC_QP_OP_ERR);
drivers/infiniband/sw/rxe/rxe_resp.c:1735: state = RESPST_COMPLETE;
drivers/infiniband/sw/rxe/rxe_resp.c-1736- break;
]
|
| 71/2 |
2026/10/21 02:00 |
llm |
expert |
0m
Model:
Tokens:
input: 85123
output: 49
thoughts: 93
Thoughts: **My Thought Process Unraveling a Softlockup in the Infiniband/RDS Codebase**
Okay, hold on a minute. My immediate reaction upon seeing `Tainted: [L]=SOFTLOCKUP` in this bug report is a jolt of alarm. A softlockup, especially in this context, immediately signals a critical and potentially insidious issue within the kernel. My mind immediately jumps to, "Where could a softlockup possibly be occurring?" This isn't a trivial error; it implies a part of the system has become unresponsive, and the kernel is unable to recover.
Given the traceback or the context that likely led to this report, my focus immediately narrows to the specific areas mentioned in the bug report β `drivers/infiniband/sw/rxe/` and `net/rds/`. These are highly performance-sensitive and complex subsystems, and a softlockup here could have significant implications.
My next logical step is to systematically investigate potential culprits within these directories. The most common breeding ground for deadlocks and livelocks, which often manifest as softlockups, are infinite loops. Therefore, my thought process immediately targets all `while` loops within these critical code paths. I need to ensure that no loop is unintentionally executing indefinitely under certain conditions.
To achieve this, my immediate action would be to perform a targeted `grep` for `while` specifically within the `drivers/infiniband/sw/rxe/` and `net/rds/` directories. This isn't a casual scan; it's a focused, diagnostic effort. I'll be scrutinizing each `while` loop I find, looking for potential race conditions, incorrect loop termination conditions, or any logic that could lead to starvation of other critical processes or the kernel's ability to schedule. This is where I'll be spending my immediate investigative energy.
|
| 72/2 |
2026/10/21 02:00 |
tool |
grepper |
0m
Args: map[Expression:\bwhile\b PathPrefixes:[drivers/infiniband/sw/rxe/ net/rds/]]
Results: map[Output:
Full output is too long, showing 200 out of 656 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (35 files in total):
drivers/infiniband/sw/rxe/rxe_comp.c:3
drivers/infiniband/sw/rxe/rxe_mcast.c:5
drivers/infiniband/sw/rxe/rxe_mmap.c:1
drivers/infiniband/sw/rxe/rxe_mr.c:8
drivers/infiniband/sw/rxe/rxe_odp.c:4
drivers/infiniband/sw/rxe/rxe_pool.c:1
drivers/infiniband/sw/rxe/rxe_qp.c:3
drivers/infiniband/sw/rxe/rxe_queue.c:1
drivers/infiniband/sw/rxe/rxe_req.c:2
drivers/infiniband/sw/rxe/rxe_resp.c:3
drivers/infiniband/sw/rxe/rxe_task.c:5
drivers/infiniband/sw/rxe/rxe_verbs.c:5
net/rds/bind.c:1
net/rds/cong.c:2
net/rds/connection.c:5
net/rds/ib.c:1
net/rds/ib_cm.c:6
net/rds/ib_frmr.c:4
net/rds/ib_rdma.c:3
net/rds/ib_recv.c:6
net/rds/ib_send.c:1
net/rds/info.c:3
net/rds/message.c:5
net/rds/page.c:1
net/rds/rdma.c:2
net/rds/rdma_transport.c:2
net/rds/rds.h:4
net/rds/recv.c:5
net/rds/send.c:11
net/rds/tcp.c:6
net/rds/tcp_connect.c:4
net/rds/tcp_recv.c:2
net/rds/tcp_send.c:1
net/rds/threads.c:1
net/rds/transport.c:1
drivers/infiniband/sw/rxe/rxe_comp.c=548=static void drain_resp_pkts(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_comp.c-551-
drivers/infiniband/sw/rxe/rxe_comp.c:552: while ((skb = skb_dequeue(&qp->resp_pkts))) {
drivers/infiniband/sw/rxe/rxe_comp.c-553- rxe_put(qp);
--
drivers/infiniband/sw/rxe/rxe_comp.c=588=static void flush_send_queue(struct rxe_qp *qp, bool notify)
--
drivers/infiniband/sw/rxe/rxe_comp.c-597-
drivers/infiniband/sw/rxe/rxe_comp.c:598: while ((wqe = queue_head(q, q->type))) {
drivers/infiniband/sw/rxe/rxe_comp.c-599- if (notify) {
--
drivers/infiniband/sw/rxe/rxe_comp.c=641=int rxe_completer(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_comp.c-676-
drivers/infiniband/sw/rxe/rxe_comp.c:677: while (1) {
drivers/infiniband/sw/rxe/rxe_comp.c-678- rxe_dbg_qp(qp, "state = %s\n", comp_state_name[state]);
--
drivers/infiniband/sw/rxe/rxe_mcast.c=81=static void __rxe_insert_mcg(struct rxe_mcg *mcg)
--
drivers/infiniband/sw/rxe/rxe_mcast.c-88-
drivers/infiniband/sw/rxe/rxe_mcast.c:89: while (*link) {
drivers/infiniband/sw/rxe/rxe_mcast.c-90- node = *link;
--
drivers/infiniband/sw/rxe/rxe_mcast.c=110=static void __rxe_remove_mcg(struct rxe_mcg *mcg)
--
drivers/infiniband/sw/rxe/rxe_mcast.c-115-/**
drivers/infiniband/sw/rxe/rxe_mcast.c:116: * __rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock
drivers/infiniband/sw/rxe/rxe_mcast.c-117- * @rxe: rxe device object
--
drivers/infiniband/sw/rxe/rxe_mcast.c=123=static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,
--
drivers/infiniband/sw/rxe/rxe_mcast.c-132-
drivers/infiniband/sw/rxe/rxe_mcast.c:133: while (node) {
drivers/infiniband/sw/rxe/rxe_mcast.c-134- mcg = rb_entry(node, struct rxe_mcg, node);
--
drivers/infiniband/sw/rxe/rxe_mcast.c=217=static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid)
--
drivers/infiniband/sw/rxe/rxe_mcast.c-243-
drivers/infiniband/sw/rxe/rxe_mcast.c:244: /* program the multicast address while mcg is still private, before
drivers/infiniband/sw/rxe/rxe_mcast.c-245- * it is inserted into mcg_tree. dev_mc_add() may sleep so this must
--
drivers/infiniband/sw/rxe/rxe_mcast.c-255- spin_lock_bh(&rxe->mcg_lock);
drivers/infiniband/sw/rxe/rxe_mcast.c:256: /* re-check to see if someone else just added it while we were adding
drivers/infiniband/sw/rxe/rxe_mcast.c-257- * the multicast address; if so use theirs and drop ours
--
drivers/infiniband/sw/rxe/rxe_mmap.c=38=int rxe_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
--
drivers/infiniband/sw/rxe/rxe_mmap.c-72- /*
drivers/infiniband/sw/rxe/rxe_mmap.c:73: * Increment refcount and check whether it is being freed atm while
drivers/infiniband/sw/rxe/rxe_mmap.c-74- * holding lock to prevent UAF
--
drivers/infiniband/sw/rxe/rxe_mr.c=16=u8 rxe_get_next_key(u32 last_key)
--
drivers/infiniband/sw/rxe/rxe_mr.c-21- get_random_bytes(&key, 1);
drivers/infiniband/sw/rxe/rxe_mr.c:22: } while (key == last_key);
drivers/infiniband/sw/rxe/rxe_mr.c-23-
--
drivers/infiniband/sw/rxe/rxe_mr.c=127=static int rxe_mr_fill_pages_from_sgt(struct rxe_mr *mr, struct sg_table *sgt)
--
drivers/infiniband/sw/rxe/rxe_mr.c-138-
drivers/infiniband/sw/rxe/rxe_mr.c:139: while (true) {
drivers/infiniband/sw/rxe/rxe_mr.c-140- page = sg_page_iter_page(&sg_iter);
--
drivers/infiniband/sw/rxe/rxe_mr.c=326=static int rxe_mr_copy_xarray(struct rxe_mr *mr, u64 iova, void *addr,
--
drivers/infiniband/sw/rxe/rxe_mr.c-331-
drivers/infiniband/sw/rxe/rxe_mr.c:332: while (length) {
drivers/infiniband/sw/rxe/rxe_mr.c-333- unsigned long index = rxe_mr_iova_to_index(mr, iova);
--
drivers/infiniband/sw/rxe/rxe_mr.c=358=static void rxe_mr_copy_dma(struct rxe_mr *mr, u64 dma_addr, void *addr,
--
drivers/infiniband/sw/rxe/rxe_mr.c-365-
drivers/infiniband/sw/rxe/rxe_mr.c:366: while (length) {
drivers/infiniband/sw/rxe/rxe_mr.c-367- page = ib_virt_dma_to_page(dma_addr);
--
drivers/infiniband/sw/rxe/rxe_mr.c=416=int copy_data(
--
drivers/infiniband/sw/rxe/rxe_mr.c-447-
drivers/infiniband/sw/rxe/rxe_mr.c:448: while (length > 0) {
drivers/infiniband/sw/rxe/rxe_mr.c-449- bytes = length;
--
drivers/infiniband/sw/rxe/rxe_mr.c=508=static int rxe_mr_flush_pmem_iova(struct rxe_mr *mr, u64 iova, unsigned int length)
--
drivers/infiniband/sw/rxe/rxe_mr.c-517-
drivers/infiniband/sw/rxe/rxe_mr.c:518: while (length > 0) {
drivers/infiniband/sw/rxe/rxe_mr.c-519- unsigned long index = rxe_mr_iova_to_index(mr, iova);
--
drivers/infiniband/sw/rxe/rxe_mr.c=669=int advance_dma_data(struct rxe_dma_info *dma, unsigned int length)
--
drivers/infiniband/sw/rxe/rxe_mr.c-674-
drivers/infiniband/sw/rxe/rxe_mr.c:675: while (length) {
drivers/infiniband/sw/rxe/rxe_mr.c-676- unsigned int bytes;
--
drivers/infiniband/sw/rxe/rxe_mr.c=724=int rxe_invalidate_mr(struct rxe_qp *qp, u32 key)
--
drivers/infiniband/sw/rxe/rxe_mr.c-746- if (atomic_read(&mr->num_mw) > 0) {
drivers/infiniband/sw/rxe/rxe_mr.c:747: rxe_dbg_mr(mr, "Attempt to invalidate an MR while bound to MWs\n");
drivers/infiniband/sw/rxe/rxe_mr.c-748- ret = -EINVAL;
--
drivers/infiniband/sw/rxe/rxe_odp.c=122=static inline bool rxe_check_pagefault(struct ib_umem_odp *umem_odp, u64 iova,
--
drivers/infiniband/sw/rxe/rxe_odp.c-135- /* Skim through all pages that are to be accessed. */
drivers/infiniband/sw/rxe/rxe_odp.c:136: while (addr < iova + length) {
drivers/infiniband/sw/rxe/rxe_odp.c-137- idx = (addr - ib_umem_start(umem_odp)) >> umem_odp->page_shift;
--
drivers/infiniband/sw/rxe/rxe_odp.c=191=static int __rxe_odp_mr_copy(struct rxe_mr *mr, u64 iova, void *addr,
--
drivers/infiniband/sw/rxe/rxe_odp.c-202-
drivers/infiniband/sw/rxe/rxe_odp.c:203: while (length > 0) {
drivers/infiniband/sw/rxe/rxe_odp.c-204- u8 *src, *dest;
--
drivers/infiniband/sw/rxe/rxe_odp.c=332=int rxe_odp_flush_pmem_iova(struct rxe_mr *mr, u64 iova,
--
drivers/infiniband/sw/rxe/rxe_odp.c-348-
drivers/infiniband/sw/rxe/rxe_odp.c:349: while (length > 0) {
drivers/infiniband/sw/rxe/rxe_odp.c-350- index = rxe_odp_iova_to_index(umem_odp, iova);
--
drivers/infiniband/sw/rxe/rxe_odp.c=505=static int rxe_ib_advise_mr_prefetch(struct ib_pd *ibpd,
--
drivers/infiniband/sw/rxe/rxe_odp.c-555- /* rollback reference counts for the invalid request */
drivers/infiniband/sw/rxe/rxe_odp.c:556: while (i > 0) {
drivers/infiniband/sw/rxe/rxe_odp.c-557- i--;
--
drivers/infiniband/sw/rxe/rxe_pool.c=177=int __rxe_cleanup(struct rxe_pool_elem *elem, bool sleepable)
--
drivers/infiniband/sw/rxe/rxe_pool.c-222- */
drivers/infiniband/sw/rxe/rxe_pool.c:223: while (!completion_done(&elem->complete) &&
drivers/infiniband/sw/rxe/rxe_pool.c-224- time_before(jiffies, until))
--
drivers/infiniband/sw/rxe/rxe_qp.c=284=static int rxe_qp_init_req(struct rxe_dev *rxe, struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_qp.c-300- * the source QPN. this spreads traffic for different QPs
drivers/infiniband/sw/rxe/rxe_qp.c:301: * across different NIC RX queues (while using a single
drivers/infiniband/sw/rxe/rxe_qp.c-302- * flow for a given QP to maintain packet order).
--
drivers/infiniband/sw/rxe/rxe_qp.c=850=int rxe_qp_chk_destroy(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_qp.c-852- /* See IBA o10-2.2.3
drivers/infiniband/sw/rxe/rxe_qp.c:853: * An attempt to destroy a QP while attached to a mcast group
drivers/infiniband/sw/rxe/rxe_qp.c-854- * will fail immediately.
--
drivers/infiniband/sw/rxe/rxe_qp.c-856- if (atomic_read(&qp->mcg_num)) {
drivers/infiniband/sw/rxe/rxe_qp.c:857: rxe_dbg_qp(qp, "Attempt to destroy while attached to multicast group\n");
drivers/infiniband/sw/rxe/rxe_qp.c-858- return -EBUSY;
--
drivers/infiniband/sw/rxe/rxe_queue.c=110=static int resize_finish(struct rxe_queue *q, struct rxe_queue *new_q,
--
drivers/infiniband/sw/rxe/rxe_queue.c-124-
drivers/infiniband/sw/rxe/rxe_queue.c:125: while ((prod - cons) & q->index_mask) {
drivers/infiniband/sw/rxe/rxe_queue.c-126- memcpy(queue_addr_from_index(new_q, new_prod),
--
drivers/infiniband/sw/rxe/rxe_req.c=118=static void req_check_sq_drain_done(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_req.c-158- return;
drivers/infiniband/sw/rxe/rxe_req.c:159: } while (0);
drivers/infiniband/sw/rxe/rxe_req.c-160- }
--
drivers/infiniband/sw/rxe/rxe_req.c=642=int rxe_requester(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_req.c-690- * or if the rnr timer has fired. If the retransmit
drivers/infiniband/sw/rxe/rxe_req.c:691: * timer fires while we are processing an RNR NAK wait
drivers/infiniband/sw/rxe/rxe_req.c-692- * until the rnr timer has fired before starting the
--
drivers/infiniband/sw/rxe/rxe_resp.c=1502=static void drain_req_pkts(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1505-
drivers/infiniband/sw/rxe/rxe_resp.c:1506: while ((skb = skb_dequeue(&qp->req_pkts))) {
drivers/infiniband/sw/rxe/rxe_resp.c-1507- rxe_put(qp);
--
drivers/infiniband/sw/rxe/rxe_resp.c=1542=static void flush_recv_queue(struct rxe_qp *qp, bool notify)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1558-
drivers/infiniband/sw/rxe/rxe_resp.c:1559: while ((wqe = queue_head(q, q->type))) {
drivers/infiniband/sw/rxe/rxe_resp.c-1560- if (notify) {
--
drivers/infiniband/sw/rxe/rxe_resp.c=1571=int rxe_receiver(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1594-
drivers/infiniband/sw/rxe/rxe_resp.c:1595: while (1) {
drivers/infiniband/sw/rxe/rxe_resp.c-1596- rxe_dbg_qp(qp, "state = %s\n", resp_state_name[state]);
--
drivers/infiniband/sw/rxe/rxe_task.c=103=static void do_task(struct rxe_task *task)
--
drivers/infiniband/sw/rxe/rxe_task.c-127- ret = task->func(task->qp);
drivers/infiniband/sw/rxe/rxe_task.c:128: } while (ret == 0 && iterations-- > 0);
drivers/infiniband/sw/rxe/rxe_task.c-129-
--
drivers/infiniband/sw/rxe/rxe_task.c-148-
drivers/infiniband/sw/rxe/rxe_task.c:149: /* someone tried to schedule the task while we
drivers/infiniband/sw/rxe/rxe_task.c-150- * were running, keep going
--
drivers/infiniband/sw/rxe/rxe_task.c-177- spin_unlock_irqrestore(&task->lock, flags);
drivers/infiniband/sw/rxe/rxe_task.c:178: } while (cont);
drivers/infiniband/sw/rxe/rxe_task.c-179-
--
drivers/infiniband/sw/rxe/rxe_task.c=216=void rxe_cleanup_task(struct rxe_task *task)
--
drivers/infiniband/sw/rxe/rxe_task.c-232- */
drivers/infiniband/sw/rxe/rxe_task.c:233: while (!is_done(task))
]
|
| 73/2 |
2026/10/21 02:00 |
llm |
expert |
0m
Model:
Tokens:
input: 90723
output: 101
thoughts: 1068
Thoughts: **My Deep Dive into the Infiniband RXE Receiver Loop**
Alright, a critical thought just struck me: could the `while (1)` loops in the `rxe_receiver(qp)`, `rxe_completer(qp)`, or `do_task(task)` functions potentially run forever? This is a high-stakes question for system stability, so I need to meticulously analyze this.
My immediate focus is on `rxe_receiver(qp)`. I'm recalling a specific commit, `15ae32c4a355`, that seems relevant. Looking at the `finish` label within this function, I see code that handles the `IB_QPS_ERR` state. The crucial part here is the `return pkt ? RESPST_CLEANUP : RESPST_CHK_RESOURCE;` line. This makes me wonder: is it *ever* possible for `pkt` to be `NULL` when this point is reached? My current understanding is that `get_req(qp, &pkt)` is responsible for acquiring `pkt`, and if it fails to get a request, it returns `RESPST_EXIT`. This implies `pkt` should always be valid when we're processing replies, unless an early exit occurs.
To definitively answer the "forever loop" question, I need to trace every possible state transition within the `rxe_receiver(qp)`'s `while (1)` loop. Let's break down the flow:
* **`RESPST_GET_REQ`**: This is the entry point, where `get_req(qp, &pkt)` is called. It can lead to `RESPST_EXIT` (which would break the loop) or transition to `RESPST_READ_REPLY` or `RESPST_CHK_PSN`.
* **`RESPST_CHK_PSN`**: Here, `check_psn(qp, pkt)` is evaluated. Potential outcomes include `RESPST_CLEANUP`, `RESPST_ERR_PSN_OUT_OF_SEQ`, `RESPST_DUPLICATE_REQUEST`, or `RESPST_CHK_OP_SEQ`. Notably, `RESPST_CLEANUP` would likely terminate processing for this packet.
* **`RESPST_CHK_OP_SEQ`**: This involves `check_op_seq(qp, pkt)`. Possible transitions are `RESPST_CHK_OP_VALID`, `RESPST_ERR_MISSING_OPCODE_FIRST`, `RESPST_ERR_MISSING_OPCODE_LAST_C`, or `RESPST_ERR_MISSING_OPCODE_LAST_D1E`.
* **`RESPST_CHK_OP_VALID`**: `check_op_valid(qp, pkt)` determines if the operation is supported. It can lead to `RESPST_CHK_RESOURCE` or `RESPST_ERR_UNSUPPORTED_OPCODE`.
* **`RESPST_CHK_RESOURCE`**: Resource checks are performed by `check_resource(qp, pkt)`. This can lead to `RESPST_CHK_LENGTH`, `RESPST_ERR_TOO_MANY_RDMA_ATM_REQ`, or involve `get_srq_wqe(qp)` and `rxe_get_recv_wqe(qp)`.
* **`RESPST_CHK_LENGTH`**: `rxe_resp_check_length(qp, pkt)` validates the packet length. Outcomes include `RESPST_ERR_LENGTH`, `RESPST_CHK_RKEY`, or `RESPST_EXECUTE`.
* **`RESPST_CHK_RKEY`**: `check_rkey(qp, pkt)` verifies the R_Key. This can result in `RESPST_EXECUTE`, `RESPST_ERR_RKEY_VIOLATION`, `RESPST_ERR_RKEY_VIOLATION_EVENT`, `RESPST_ERR_MISALIGNED_ATOMIC`, `RESPST_ERR_LENGTH`, or `RESPST_ERR_MALFORMED_WQE`.
* **`RESPST_EXECUTE`**: This is where the actual operation is performed via `execute(qp, pkt)`. The return states are diverse: `RESPST_READ_REPLY`, `RESPST_ATOMIC_REPLY`, `RESPST_ATOMIC_WRITE_REPLY`, `RESPST_PROCESS_FLUSH`, `RESPST_ERR_INVALIDATE_RKEY`, `RESPST_COMPLETE`, `RESPST_ACKNOWLEDGE`, `RESPST_CLEANUP`. It can also return error states like `RESPST_ERR_MALFORMED_WQE`, `RESPST_ERR_LENGTH`, `RESPST_ERR_RKEY_VIOLATION` from `send_data_in`/`write_data_in` operations.
* **`RESPST_COMPLETE`**: Handled by `do_complete(qp, pkt)`. Possible returns are `RESPST_ERR_CQ_OVERFLOW`, `RESPST_CLEANUP`, `RESPST_ACKNOWLEDGE`, or `RESPST_DONE`.
* **`RESPST_READ_REPLY`**: Processed by `read_reply(qp, pkt)`. Potential outcomes include `RESPST_ERR_RKEY_VIOLATION`, `RESPST_ERR_RNR`, `RESPST_DONE`, or `RESPST_CLEANUP`.
* **`RESPST_ATOMIC_REPLY`**, **`RESPST_ATOMIC_WRITE_REPLY`**, **`RESPST_PROCESS_FLUSH`**: I need to examine the specific return paths for these states.
To solidify my understanding and ensure no infinite loops are lurking, I will be scrutinizing lines 750 to 950 and 1350 to 1450 of `drivers/infiniband/sw/rxe/rxe_resp.c` to understand precisely what these particular reply handling functions return and whether they can indeed lead back into the `while(1)` loop indefinitely without an eventual exit or error condition. This systematic trace is essential for validating the robustness of the RXE receiver.
|
| 74/2 |
2026/10/21 02:00 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:750 LineCount:150]
Results: map[Contents: 750:
751: if (!res->replay) {
752: u64 iova = qp->resp.va + qp->resp.offset;
753:
754: if (is_odp_mr(mr))
755: err = rxe_odp_atomic_op(mr, iova, pkt->opcode,
756: atmeth_comp(pkt),
757: atmeth_swap_add(pkt),
758: &res->atomic.orig_val);
759: else
760: err = rxe_mr_do_atomic_op(mr, iova, pkt->opcode,
761: atmeth_comp(pkt),
762: atmeth_swap_add(pkt),
763: &res->atomic.orig_val);
764: if (err)
765: return err;
766:
767: qp->resp.msn++;
768:
769: /* next expected psn, read handles this separately */
770: qp->resp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
771: qp->resp.ack_psn = qp->resp.psn;
772:
773: qp->resp.opcode = pkt->opcode;
774: qp->resp.status = IB_WC_SUCCESS;
775: }
776:
777: return RESPST_ACKNOWLEDGE;
778: }
779:
780: static enum resp_states atomic_write_reply(struct rxe_qp *qp,
781: struct rxe_pkt_info *pkt)
782: {
783: struct resp_res *res = qp->resp.res;
784: struct rxe_mr *mr;
785: u64 value;
786: u64 iova;
787: int err;
788:
789: if (!res) {
790: res = rxe_prepare_res(qp, pkt, RXE_ATOMIC_WRITE_MASK);
791: qp->resp.res = res;
792: }
793:
794: if (res->replay)
795: return RESPST_ACKNOWLEDGE;
796:
797: mr = qp->resp.mr;
798: value = *(u64 *)payload_addr(pkt);
799: iova = qp->resp.va + qp->resp.offset;
800:
801: /* See IBA oA19-28 */
802: if (unlikely(mr->state != RXE_MR_STATE_VALID)) {
803: rxe_dbg_mr(mr, "mr not in valid state\n");
804: return RESPST_ERR_RKEY_VIOLATION;
805: }
806:
807: if (is_odp_mr(mr))
808: err = rxe_odp_do_atomic_write(mr, iova, value);
809: else
810: err = rxe_mr_do_atomic_write(mr, iova, value);
811: if (err)
812: return err;
813:
814: qp->resp.resid = 0;
815: qp->resp.msn++;
816:
817: /* next expected psn, read handles this separately */
818: qp->resp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
819: qp->resp.ack_psn = qp->resp.psn;
820:
821: qp->resp.opcode = pkt->opcode;
822: qp->resp.status = IB_WC_SUCCESS;
823:
824: return RESPST_ACKNOWLEDGE;
825: }
826:
827: static struct sk_buff *prepare_ack_packet(struct rxe_qp *qp,
828: struct rxe_pkt_info *ack,
829: int opcode,
830: int payload,
831: u32 psn,
832: u8 syndrome)
833: {
834: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
835: struct sk_buff *skb;
836: int paylen;
837: int pad;
838: int err;
839:
840: /*
841: * allocate packet
842: */
843: pad = (-payload) & 0x3;
844: paylen = rxe_opcode[opcode].length + payload + pad + RXE_ICRC_SIZE;
845:
846: skb = rxe_init_packet(rxe, &qp->pri_av, paylen, ack);
847: if (!skb)
848: return NULL;
849:
]
|
| 75/2 |
2026/10/21 02:00 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_resp.c FirstLine:1350 LineCount:100]
Results: map[Contents:1350: u32 prev_psn = (qp->resp.ack_psn - 1) & BTH_PSN_MASK;
1351:
1352: if (pkt->mask & RXE_SEND_MASK ||
1353: pkt->mask & RXE_WRITE_MASK) {
1354: /* SEND. Ack again and cleanup. C9-105. */
1355: send_ack(qp, AETH_ACK_UNLIMITED, prev_psn);
1356: return RESPST_CLEANUP;
1357: } else if (pkt->mask & RXE_FLUSH_MASK) {
1358: struct resp_res *res;
1359:
1360: /* Find the operation in our list of responder resources. */
1361: res = find_resource(qp, pkt->psn);
1362: if (res) {
1363: res->replay = 1;
1364: res->cur_psn = pkt->psn;
1365: qp->resp.res = res;
1366: rc = RESPST_PROCESS_FLUSH;
1367: goto out;
1368: }
1369:
1370: /* Resource not found. Class D error. Drop the request. */
1371: rc = RESPST_CLEANUP;
1372: goto out;
1373: } else if (pkt->mask & RXE_READ_MASK) {
1374: struct resp_res *res;
1375:
1376: res = find_resource(qp, pkt->psn);
1377: if (!res) {
1378: /* Resource not found. Class D error. Drop the
1379: * request.
1380: */
1381: rc = RESPST_CLEANUP;
1382: goto out;
1383: } else {
1384: /* Ensure this new request is the same as the previous
1385: * one or a subset of it.
1386: */
1387: u64 iova = reth_va(pkt);
1388: u32 resid = reth_len(pkt);
1389:
1390: if (iova < res->read.va_org ||
1391: resid > res->read.length ||
1392: (iova + resid) > (res->read.va_org +
1393: res->read.length)) {
1394: rc = RESPST_CLEANUP;
1395: goto out;
1396: }
1397:
1398: if (reth_rkey(pkt) != res->read.rkey) {
1399: rc = RESPST_CLEANUP;
1400: goto out;
1401: }
1402:
1403: res->cur_psn = pkt->psn;
1404: res->state = (pkt->psn == res->first_psn) ?
1405: rdatm_res_state_new :
1406: rdatm_res_state_replay;
1407: res->replay = 1;
1408:
1409: /* Reset the resource, except length. */
1410: res->read.va_org = iova;
1411: res->read.va = iova;
1412: res->read.resid = resid;
1413:
1414: /* Replay the RDMA read reply. */
1415: qp->resp.res = res;
1416: rc = RESPST_READ_REPLY;
1417: goto out;
1418: }
1419: } else {
1420: struct resp_res *res;
1421:
1422: /* Find the operation in our list of responder resources. */
1423: res = find_resource(qp, pkt->psn);
1424: if (res) {
1425: res->replay = 1;
1426: res->cur_psn = pkt->psn;
1427: qp->resp.res = res;
1428: rc = pkt->mask & RXE_ATOMIC_MASK ?
1429: RESPST_ATOMIC_REPLY :
1430: RESPST_ATOMIC_WRITE_REPLY;
1431: goto out;
1432: }
1433:
1434: /* Resource not found. Class D error. Drop the request. */
1435: rc = RESPST_CLEANUP;
1436: goto out;
1437: }
1438: out:
1439: return rc;
1440: }
1441:
1442: static void do_qp_event(struct rxe_qp *qp, enum ib_event_type etype)
1443: {
1444: struct ib_event event;
1445: struct ib_qp *ibqp = &qp->ibqp;
1446:
1447: event.event = etype;
1448: event.device = ibqp->device;
1449: event.element.qp = ibqp;
]
|
| 76/2 |
2026/10/21 02:00 |
llm |
expert |
0m
Model:
Tokens:
input: 94833
output: 50
thoughts: 1849
Thoughts: **My Thoughts on `rxe_resp.c` and Potential Issues**
Okay, I've been digging into the `read_reply` function in `drivers/infiniband/sw/rxe/rxe_resp.c`, specifically looking at lines 932-1034, and I've stumbled upon something quite concerning. My initial focus was on the handling of RDMA READ requests.
Let's trace the execution path. When `res->read.resid` is still greater than zero after preparing an ACK packet (`prepare_ack_packet`) and attempting to transmit it (`rxe_xmit_packet`), the function returns `RESPST_DONE` (lines 1019-1020). Now, this is critical. By returning `RESPST_DONE` without proceeding to `RESPST_CLEANUP`, I realize that the original RDMA READ request `skb` remains at the head of `qp->req_pkts`. Crucially, `qp->resp.res` also remains non-NULL, implying that the read operation is considered incomplete from the receiver's perspective.
Then, in `rxe_receiver`, when `RESPST_DONE` is encountered, it simply jumps to `done`, effectively causing `rxe_receiver` to return `0`. This `0` return value then propagates to `do_task`. The `do_task` loop, with its `RXE_MAX_ITERATIONS` limit (1024), will continue to call the task function.
Here's where it gets potentially problematic: if an RDMA READ request is for a very large payload, like 2GB (which is `2^31`), and considering an MTU of 1024, this translates to an enormous number of packets β approximately 2,097,152 packets. If `read_reply` is repeatedly returning `RESPST_DONE` for these large reads, the `qp->req_pkts` queue will grow, and `qp->resp.res` will remain set.
Furthermore, I've noticed a disparity in how inflight SKBs are handled. The `rxe_requester` function checks `atomic_read(&qp->skb_out) > RXE_INFLIGHT_SKBS_PER_QP_HIGH`, but `read_reply` does *not* perform this check. This means `read_reply` could potentially continue to enqueue packets without this backpressure mechanism, exacerbating the issue.
Now, let's consider the error paths. If `prepare_ack_packet` or `rxe_xmit_packet` fails within `read_reply` (lines 989-992 and 1010-1013), the function returns `RESPST_ERR_RNR`. In `rxe_receiver`, this leads to `RESPST_CLEANUP`. The `cleanup` function, when called with a `pkt` argument, dequeues an `skb` from `qp->req_pkts` and calls `rxe_put(qp)`.
However, I've spotted another flaw here. When `read_reply` returns `RESPST_ERR_RNR` (or `RESPST_ERR_RKEY_VIOLATION` for UC), the `qp->resp.res` pointer is *not* cleared. It remains non-NULL. This is a serious issue because on the *next* packet processed by `get_req` from `qp->req_pkts`, the logic `return (qp->resp.res) ? RESPST_READ_REPLY : RESPST_CHK_PSN;` will incorrectly assume a READ REPLY is still pending, even though the previous transmit operation failed and the resource might not be truly ready. This state corruption seems like a prime candidate for causing hangs or timeouts.
My current line of inquiry is to determine the exact root cause of the `__rxe_cleanup` timeout observed in `rds_ib_conn_path_shutdown`. I'm convinced it's related to these state management issues within `read_reply` and how `qp` references (`elem->ref_cnt`) are being held or not released properly. I need to meticulously examine every place where a `qp` reference is managed and understand why `elem->complete` might not be signaling its completion. I'm currently diving into `drivers/infiniband/sw/rxe/rxe_pool.c` to get a clearer picture of the reference counting and completion signaling mechanisms.
|
| 77/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_pool.c FirstLine:1 LineCount:240]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2: /*
3: * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4: * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5: */
6:
7: #include "rxe.h"
8:
9: #define RXE_POOL_TIMEOUT (200)
10: #define RXE_POOL_ALIGN (16)
11:
12: static const struct rxe_type_info {
13: const char *name;
14: size_t size;
15: size_t elem_offset;
16: void (*cleanup)(struct rxe_pool_elem *elem);
17: u32 min_index;
18: u32 max_index;
19: u32 max_elem;
20: } rxe_type_info[RXE_NUM_TYPES] = {
21: [RXE_TYPE_UC] = {
22: .name = "uc",
23: .size = sizeof(struct rxe_ucontext),
24: .elem_offset = offsetof(struct rxe_ucontext, elem),
25: .min_index = 1,
26: .max_index = RXE_MAX_UCONTEXT,
27: .max_elem = RXE_MAX_UCONTEXT,
28: },
29: [RXE_TYPE_PD] = {
30: .name = "pd",
31: .size = sizeof(struct rxe_pd),
32: .elem_offset = offsetof(struct rxe_pd, elem),
33: .min_index = 1,
34: .max_index = RXE_MAX_PD,
35: .max_elem = RXE_MAX_PD,
36: },
37: [RXE_TYPE_AH] = {
38: .name = "ah",
39: .size = sizeof(struct rxe_ah),
40: .elem_offset = offsetof(struct rxe_ah, elem),
41: .min_index = RXE_MIN_AH_INDEX,
42: .max_index = RXE_MAX_AH_INDEX,
43: .max_elem = RXE_MAX_AH,
44: },
45: [RXE_TYPE_SRQ] = {
46: .name = "srq",
47: .size = sizeof(struct rxe_srq),
48: .elem_offset = offsetof(struct rxe_srq, elem),
49: .cleanup = rxe_srq_cleanup,
50: .min_index = RXE_MIN_SRQ_INDEX,
51: .max_index = RXE_MAX_SRQ_INDEX,
52: .max_elem = RXE_MAX_SRQ,
53: },
54: [RXE_TYPE_QP] = {
55: .name = "qp",
56: .size = sizeof(struct rxe_qp),
57: .elem_offset = offsetof(struct rxe_qp, elem),
58: .cleanup = rxe_qp_cleanup,
59: .min_index = RXE_MIN_QP_INDEX,
60: .max_index = RXE_MAX_QP_INDEX,
61: .max_elem = RXE_MAX_QP,
62: },
63: [RXE_TYPE_CQ] = {
64: .name = "cq",
65: .size = sizeof(struct rxe_cq),
66: .elem_offset = offsetof(struct rxe_cq, elem),
67: .cleanup = rxe_cq_cleanup,
68: .min_index = 1,
69: .max_index = RXE_MAX_CQ,
70: .max_elem = RXE_MAX_CQ,
71: },
72: [RXE_TYPE_MR] = {
73: .name = "mr",
74: .size = sizeof(struct rxe_mr),
75: .elem_offset = offsetof(struct rxe_mr, elem),
76: .cleanup = rxe_mr_cleanup,
77: .min_index = RXE_MIN_MR_INDEX,
78: .max_index = RXE_MAX_MR_INDEX,
79: .max_elem = RXE_MAX_MR,
80: },
81: [RXE_TYPE_MW] = {
82: .name = "mw",
83: .size = sizeof(struct rxe_mw),
84: .elem_offset = offsetof(struct rxe_mw, elem),
85: .cleanup = rxe_mw_cleanup,
86: .min_index = RXE_MIN_MW_INDEX,
87: .max_index = RXE_MAX_MW_INDEX,
88: .max_elem = RXE_MAX_MW,
89: },
90: };
91:
92: void rxe_pool_init(struct rxe_dev *rxe, struct rxe_pool *pool,
93: enum rxe_elem_type type)
94: {
95: const struct rxe_type_info *info = &rxe_type_info[type];
96:
97: memset(pool, 0, sizeof(*pool));
98:
99: pool->rxe = rxe;
100: pool->name = info->name;
]
|
| 78/2 |
2026/10/21 02:01 |
llm |
expert |
0m
Model:
Tokens:
input: 98364
output: 97
thoughts: 55
Thoughts: **My Thought Process Regarding `rxe_pool.c` and `rxe_pool.h`**
Alright, so my immediate inclination is to dive into the core logic of memory management within the RXE driver, specifically focusing on the pooling mechanisms. I'm zeroing in on lines 101 to 180 of `drivers/infiniband/sw/rxe/rxe_pool.c` and its corresponding header, `drivers/infiniband/sw/rxe/rxe_pool.h`. My goal here is to understand precisely *how* these memory pools are structured and managed. I want to see the granular details of allocation and deallocation, the underlying data structures being used, and any potential optimizations or limitations inherent in this design.
Specifically, I'm looking to dissect the functions responsible for acquiring and releasing memory chunks. What are the data structures that underpin these pools? Are we talking about simple linked lists, more complex tree structures, or something else entirely? I need to grasp the mechanics of how an element is fetched from the pool and, crucially, how it's returned. I'm also interested in any error handling or boundary conditions that might be present. For instance, what happens when a pool is exhausted, or when an invalid pointer is attempted to be returned? Understanding these edge cases is vital for a robust system.
Furthermore, I'll be scrutinizing `rxe_pool.h` to see the public interface and the data definitions. This will give me the blueprint of the pool's structure and the types of objects it manages. How are these objects defined? What attributes do they possess that are relevant to the pooling mechanism? Are there any specific alignment requirements or size constraints that the pool design caters to? My aim is to build a comprehensive mental model of this memory management subsystem, understanding its strengths, weaknesses, and its role within the broader RXE architecture. I'm essentially trying to get a feel for the engineering decisions that led to this particular implementation of memory pooling.
|
| 79/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_pool.c FirstLine:101 LineCount:80]
Results: map[Contents: 101: pool->type = type;
102: pool->max_elem = info->max_elem;
103: pool->elem_size = ALIGN(info->size, RXE_POOL_ALIGN);
104: pool->elem_offset = info->elem_offset;
105: pool->cleanup = info->cleanup;
106:
107: atomic_set(&pool->num_elem, 0);
108:
109: xa_init_flags(&pool->xa, XA_FLAGS_ALLOC);
110: pool->limit.min = info->min_index;
111: pool->limit.max = info->max_index;
112: }
113:
114: void rxe_pool_cleanup(struct rxe_pool *pool)
115: {
116: WARN_ON(!xa_empty(&pool->xa));
117: }
118:
119: int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem,
120: bool sleepable)
121: {
122: int err = -EINVAL;
123: gfp_t gfp_flags;
124:
125: if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
126: goto err_cnt;
127:
128: elem->pool = pool;
129: elem->obj = (u8 *)elem - pool->elem_offset;
130: kref_init(&elem->ref_cnt);
131: init_completion(&elem->complete);
132:
133: /* AH objects are unique in that the create_ah verb
134: * can be called in atomic context. If the create_ah
135: * call is not sleepable use GFP_ATOMIC.
136: */
137: gfp_flags = sleepable ? GFP_KERNEL : GFP_ATOMIC;
138:
139: if (sleepable)
140: might_sleep();
141: err = xa_alloc_cyclic(&pool->xa, &elem->index, NULL, pool->limit,
142: &pool->next, gfp_flags);
143: if (err < 0)
144: goto err_cnt;
145:
146: return 0;
147:
148: err_cnt:
149: atomic_dec(&pool->num_elem);
150: return err;
151: }
152:
153: void *rxe_pool_get_index(struct rxe_pool *pool, u32 index)
154: {
155: struct rxe_pool_elem *elem;
156: struct xarray *xa = &pool->xa;
157: void *obj;
158:
159: rcu_read_lock();
160: elem = xa_load(xa, index);
161: if (elem && kref_get_unless_zero(&elem->ref_cnt))
162: obj = elem->obj;
163: else
164: obj = NULL;
165: rcu_read_unlock();
166:
167: return obj;
168: }
169:
170: static void rxe_elem_release(struct kref *kref)
171: {
172: struct rxe_pool_elem *elem = container_of(kref, typeof(*elem), ref_cnt);
173:
174: complete(&elem->complete);
175: }
176:
177: int __rxe_cleanup(struct rxe_pool_elem *elem, bool sleepable)
178: {
179: struct rxe_pool *pool = elem->pool;
180: struct xarray *xa = &pool->xa;
]
|
| 80/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_pool.h FirstLine:1 LineCount:100]
Results: map[Contents: 1: /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2: /*
3: * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4: * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5: */
6:
7: #ifndef RXE_POOL_H
8: #define RXE_POOL_H
9:
10: enum rxe_elem_type {
11: RXE_TYPE_UC,
12: RXE_TYPE_PD,
13: RXE_TYPE_AH,
14: RXE_TYPE_SRQ,
15: RXE_TYPE_QP,
16: RXE_TYPE_CQ,
17: RXE_TYPE_MR,
18: RXE_TYPE_MW,
19: RXE_NUM_TYPES, /* keep me last */
20: };
21:
22: struct rxe_pool_elem {
23: struct rxe_pool *pool;
24: void *obj;
25: struct kref ref_cnt;
26: struct list_head list;
27: struct completion complete;
28: u32 index;
29: };
30:
31: struct rxe_pool {
32: struct rxe_dev *rxe;
33: const char *name;
34: void (*cleanup)(struct rxe_pool_elem *elem);
35: enum rxe_elem_type type;
36:
37: unsigned int max_elem;
38: atomic_t num_elem;
39: size_t elem_size;
40: size_t elem_offset;
41:
42: struct xarray xa;
43: struct xa_limit limit;
44: u32 next;
45: };
46:
47: /* initialize a pool of objects with given limit on
48: * number of elements. gets parameters from rxe_type_info
49: * pool elements will be allocated out of a slab cache
50: */
51: void rxe_pool_init(struct rxe_dev *rxe, struct rxe_pool *pool,
52: enum rxe_elem_type type);
53:
54: /* free resources from object pool */
55: void rxe_pool_cleanup(struct rxe_pool *pool);
56:
57: /* connect already allocated object to pool */
58: int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem,
59: bool sleepable);
60: #define rxe_add_to_pool(pool, obj) __rxe_add_to_pool(pool, &(obj)->elem, true)
61: #define rxe_add_to_pool_ah(pool, obj, sleepable) __rxe_add_to_pool(pool, \
62: &(obj)->elem, sleepable)
63:
64: /* lookup an indexed object from index. takes a reference on object */
65: void *rxe_pool_get_index(struct rxe_pool *pool, u32 index);
66:
67: int __rxe_get(struct rxe_pool_elem *elem);
68: #define rxe_get(obj) __rxe_get(&(obj)->elem)
69:
70: int __rxe_put(struct rxe_pool_elem *elem);
71: #define rxe_put(obj) __rxe_put(&(obj)->elem)
72:
73: int __rxe_cleanup(struct rxe_pool_elem *elem, bool sleepable);
74: #define rxe_cleanup(obj) __rxe_cleanup(&(obj)->elem, true)
75: #define rxe_cleanup_ah(obj, sleepable) __rxe_cleanup(&(obj)->elem, sleepable)
76:
77: #define rxe_read(obj) kref_read(&(obj)->elem.ref_cnt)
78:
79: void __rxe_finalize(struct rxe_pool_elem *elem);
80: #define rxe_finalize(obj) __rxe_finalize(&(obj)->elem)
81:
82: #endif /* RXE_POOL_H */
]
|
| 81/2 |
2026/10/21 02:01 |
llm |
expert |
0m
Model:
Tokens:
input: 100946
output: 51
thoughts: 41
Thoughts: **A Deep Dive into `rxe_pool.c` and the Revelation Within**
My mind, always searching for elegance and efficiency in our systems, was recently snagged by a seemingly small detail in `drivers/infiniband/sw/rxe/rxe_pool.c`. I found myself pausing, a sudden jolt of curiosity, urging me to investigate the code from line 238 onwards. There's a certain thrill in that moment of realization, when a pattern emerges or a potential optimization leaps out from the lines of code. I felt an immediate imperative to scrutinize that section, to understand the mechanics and the underlying logic that governs it. It was an instinct, born from years of wrestling with complex systems, that this particular segment held significance. I was drawn to its specific implementation, eager to decode its purpose and to see what insights it might offer into our overall design.
|
| 82/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_pool.c FirstLine:230 LineCount:60]
Results: map[Contents: 230:
231: if (pool->cleanup)
232: pool->cleanup(elem);
233:
234: atomic_dec(&pool->num_elem);
235:
236: return err;
237: }
238:
239: int __rxe_get(struct rxe_pool_elem *elem)
240: {
241: return kref_get_unless_zero(&elem->ref_cnt);
242: }
243:
244: int __rxe_put(struct rxe_pool_elem *elem)
245: {
246: return kref_put(&elem->ref_cnt, rxe_elem_release);
247: }
248:
249: void __rxe_finalize(struct rxe_pool_elem *elem)
250: {
251: void *xa_ret;
252:
253: xa_ret = xa_store(&elem->pool->xa, elem->index, elem, GFP_KERNEL);
254: WARN_ON(xa_err(xa_ret));
255: }
]
|
| 83/2 |
2026/10/21 02:01 |
llm |
expert |
0m
Model:
Tokens:
input: 101397
output: 196
thoughts: 1357
Thoughts: **My Thought Process Unpacked: A Deep Dive into RXE Task Scheduling and Resource Management**
Hold on a moment. I've been looking closely at how tasks are managed within the RXE (RDMA Emulation) framework, and something about the reference counting and state transitions caught my eye.
First, I examined `__rxe_get`. It's a straightforward helper function that increments the reference count on a pool element (`elem`) unless that count is already zero. This is a standard mechanism for managing object lifetimes, ensuring an object isn't deallocated while it's still in use.
Then, I pivoted to `rxe_task.c` and specifically the `__reserve_if_idle` function. This function is critical for managing the lifecycle of a task. A key observation here is the `WARN_ON(rxe_read(task->qp) <= 0);`. This tells me that for a task to even consider becoming busy, the associated Queue Pair (QP) must have a positive reference count. If the task is `TASK_STATE_IDLE`, it calls `rxe_get(task->qp)` to increment the QP's reference count, then sets the task's state to `TASK_STATE_BUSY` and increments `task->num_sched`. This seems to be the point where a task claims a QP and signals its intention to work on it.
Next, I traced this into `rxe_sched_task`. This function is responsible for actually queuing a task for execution. It acquires a spinlock, calls `__reserve_if_idle`, and if `__reserve_if_idle` returns true (meaning the task was successfully transitioned from `IDLE` to `BUSY` and the QP's reference count was incremented), it then queues the task's work item to be processed by `rxe_wq`. Finally, it releases the spinlock. This entire sequence is designed to safely transition a task to a busy state and schedule its execution, ensuring that the underlying QP is properly referenced during this transition.
Now, here's where things get really interesting. I'm looking at the interaction between `rxe_sched_task` and `do_task`, particularly in `drivers/infiniband/sw/rxe/rxe_task.c`. I've carefully re-read lines 36-51 (which contains `__reserve_if_idle`) and lines 130-186 (the `do_task` function itself).
Let's re-examine `__reserve_if_idle`:
If a task is `TASK_STATE_IDLE`, it increments the QP reference, becomes `TASK_STATE_BUSY`, and returns `true`.
If a task is `TASK_STATE_BUSY`, it transitions to `TASK_STATE_ARMED` and returns `false`.
Now, let's dissect `do_task` (lines 130-186):
The core loop (lines 126-128) repeatedly calls `task->func(task->qp)` up to `RXE_MAX_ITERATIONS`.
The critical part for me is what happens *after* this loop, specifically when `ret` (the return value of `task->func`) is `0`.
Lines 134-141: If `ret` is `0` and the task is *not* `TASK_STATE_DRAINING`:
- The task's state is reset to `TASK_STATE_IDLE`.
- `resched` is set to `1`, indicating the task should be rescheduled.
- The function exits the inner `do-while` loop via `goto exit;`.
Lines 169-176 (within the `exit:` label): If `cont` is false (which it generally will be if we didn't hit the `TASK_STATE_DRAINING` case):
- `task->num_done` is incremented.
- A `WARN_ON` checks if `task->num_done` equals `task->num_sched`. This is a crucial sanity check for resource management.
Line 185: Finally, `rxe_put(task->qp)` is called. This decrements the QP's reference count.
This sequence implies that when `task->func(task->qp)` returns `0`, the task effectively "completes" its current execution cycle. It gets put back into an `IDLE` state, marked for rescheduling, and importantly, the QP's reference count is decremented by `rxe_put`.
Now, the really significant "Wait a minute!" moment: What happens when `task->func(task->qp)` *consistently* returns `0`? This means the task never makes progress in its core processing logic, or it signals completion/inability to proceed.
I'm looking at the `rxe_sender(qp)` function as a prime candidate for a `task->func` that might return `0`. The logic there is:
`return (req_ret && comp_ret) ? -EAGAIN : 0;`
This means `rxe_sender(qp)` returns `0` if *either* `req_ret` is `0` *or* `comp_ret` is `0`.
My next crucial step is to understand the conditions under which `rxe_completer(qp)` returns `0`. I need to meticulously examine all execution paths within `rxe_completer(qp)` that lead to a return value of `0`. This includes paths that explicitly `goto done:` (where `done:` typically returns `0`) or set `qp->req.again = 1` (which would also result in an effective `0` return from `rxe_sender` via the `? -EAGAIN : 0` ternary, but the primary question is about *why* it returns 0 directly). I'm specifically focusing on lines 150 to 848 of `rxe_comp.c` for this detailed analysis. This will help me pinpoint exactly what triggers a task to repeatedly signal completion or inability to proceed, leading to its rescheduling and the associated QP reference count decrements.
|
| 84/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_comp.c FirstLine:150 LineCount:100]
Results: map[Contents: 150: *wqe_p = wqe;
151:
152: /* no WQE or requester has not started it yet */
153: if (!wqe || wqe->state == wqe_state_posted)
154: return pkt ? COMPST_DONE : COMPST_EXIT;
155:
156: /* WQE does not require an ack */
157: if (wqe->state == wqe_state_done)
158: return COMPST_COMP_WQE;
159:
160: /* WQE caused an error */
161: if (wqe->state == wqe_state_error)
162: return COMPST_ERROR;
163:
164: /* we have a WQE, if we also have an ack check its PSN */
165: return pkt ? COMPST_CHECK_PSN : COMPST_EXIT;
166: }
167:
168: static inline void reset_retry_counters(struct rxe_qp *qp)
169: {
170: qp->comp.retry_cnt = qp->attr.retry_cnt;
171: qp->comp.rnr_retry = qp->attr.rnr_retry;
172: qp->comp.started_retry = 0;
173: }
174:
175: static inline enum comp_state check_psn(struct rxe_qp *qp,
176: struct rxe_pkt_info *pkt,
177: struct rxe_send_wqe *wqe)
178: {
179: s32 diff;
180:
181: /* check to see if response is past the oldest WQE. if it is, complete
182: * send/write or error read/atomic
183: */
184: diff = psn_compare(pkt->psn, wqe->last_psn);
185: if (diff > 0) {
186: if (wqe->state == wqe_state_pending) {
187: if (wqe->mask & WR_ATOMIC_OR_READ_MASK)
188: return COMPST_ERROR_RETRY;
189:
190: reset_retry_counters(qp);
191: return COMPST_COMP_WQE;
192: } else {
193: return COMPST_DONE;
194: }
195: }
196:
197: /* compare response packet to expected response */
198: diff = psn_compare(pkt->psn, qp->comp.psn);
199: if (diff < 0) {
200: /* response is most likely a retried packet if it matches an
201: * uncompleted WQE go complete it else ignore it
202: */
203: if (pkt->psn == wqe->last_psn)
204: return COMPST_COMP_ACK;
205: else if (pkt->opcode == IB_OPCODE_RC_ACKNOWLEDGE &&
206: (qp->comp.opcode == IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST ||
207: qp->comp.opcode == IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE))
208: return COMPST_CHECK_ACK;
209: else
210: return COMPST_DONE;
211: } else if ((diff > 0) && (wqe->mask & WR_ATOMIC_OR_READ_MASK)) {
212: return COMPST_DONE;
213: } else {
214: return COMPST_CHECK_ACK;
215: }
216: }
217:
218: static inline enum comp_state check_ack(struct rxe_qp *qp,
219: struct rxe_pkt_info *pkt,
220: struct rxe_send_wqe *wqe)
221: {
222: unsigned int mask = pkt->mask;
223: u8 syn;
224: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
225:
226: /* Check the sequence only */
227: switch (qp->comp.opcode) {
228: case -1:
229: /* Will catch all *_ONLY cases. */
230: if (!(mask & RXE_START_MASK))
231: return COMPST_ERROR;
232:
233: break;
234:
235: case IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST:
236: case IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE:
237: /* Check NAK code to handle a remote error */
238: if (pkt->opcode == IB_OPCODE_RC_ACKNOWLEDGE)
239: break;
240:
241: if (pkt->opcode != IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE &&
242: pkt->opcode != IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST) {
243: /* read retries of partial data may restart from
244: * read response first or response only.
245: */
246: if ((pkt->psn == wqe->first_psn &&
247: pkt->opcode ==
248: IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) ||
249: (wqe->first_psn == wqe->last_psn &&
]
|
| 85/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_comp.c FirstLine:250 LineCount:100]
Results: map[Contents: 250: pkt->opcode ==
251: IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY))
252: break;
253:
254: return COMPST_ERROR;
255: }
256: break;
257: default:
258: WARN_ON_ONCE(1);
259: }
260:
261: /* Check operation validity. */
262: switch (pkt->opcode) {
263: case IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST:
264: case IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST:
265: case IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY:
266: syn = aeth_syn(pkt);
267:
268: if ((syn & AETH_TYPE_MASK) != AETH_ACK)
269: return COMPST_ERROR;
270:
271: if (wqe->wr.opcode == IB_WR_ATOMIC_WRITE)
272: return COMPST_WRITE_SEND;
273:
274: fallthrough;
275: /* (IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE doesn't have an AETH)
276: */
277: case IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE:
278: if (wqe->wr.opcode != IB_WR_RDMA_READ &&
279: wqe->wr.opcode != IB_WR_RDMA_READ_WITH_INV &&
280: wqe->wr.opcode != IB_WR_FLUSH) {
281: wqe->status = IB_WC_FATAL_ERR;
282: return COMPST_ERROR;
283: }
284: reset_retry_counters(qp);
285: return COMPST_READ;
286:
287: case IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE:
288: syn = aeth_syn(pkt);
289:
290: if ((syn & AETH_TYPE_MASK) != AETH_ACK)
291: return COMPST_ERROR;
292:
293: if (wqe->wr.opcode != IB_WR_ATOMIC_CMP_AND_SWP &&
294: wqe->wr.opcode != IB_WR_ATOMIC_FETCH_AND_ADD)
295: return COMPST_ERROR;
296: reset_retry_counters(qp);
297: return COMPST_ATOMIC;
298:
299: case IB_OPCODE_RC_ACKNOWLEDGE:
300: syn = aeth_syn(pkt);
301: switch (syn & AETH_TYPE_MASK) {
302: case AETH_ACK:
303: reset_retry_counters(qp);
304: return COMPST_WRITE_SEND;
305:
306: case AETH_RNR_NAK:
307: rxe_counter_inc(rxe, RXE_CNT_RCV_RNR);
308: return COMPST_RNR_RETRY;
309:
310: case AETH_NAK:
311: switch (syn) {
312: case AETH_NAK_PSN_SEQ_ERROR:
313: /* a nak implicitly acks all packets with psns
314: * before
315: */
316: if (psn_compare(pkt->psn, qp->comp.psn) > 0) {
317: rxe_counter_inc(rxe,
318: RXE_CNT_RCV_SEQ_ERR);
319: qp->comp.psn = pkt->psn;
320: if (qp->req.wait_psn) {
321: qp->req.wait_psn = 0;
322: qp->req.again = 1;
323: }
324: }
325: return COMPST_ERROR_RETRY;
326:
327: case AETH_NAK_INVALID_REQ:
328: wqe->status = IB_WC_REM_INV_REQ_ERR;
329: return COMPST_ERROR;
330:
331: case AETH_NAK_REM_ACC_ERR:
332: wqe->status = IB_WC_REM_ACCESS_ERR;
333: return COMPST_ERROR;
334:
335: case AETH_NAK_REM_OP_ERR:
336: wqe->status = IB_WC_REM_OP_ERR;
337: return COMPST_ERROR;
338:
339: default:
340: rxe_dbg_qp(qp, "unexpected nak %x\n", syn);
341: wqe->status = IB_WC_REM_OP_ERR;
342: return COMPST_ERROR;
343: }
344:
345: default:
346: return COMPST_ERROR;
347: }
348: break;
349:
]
|
| 86/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_comp.c FirstLine:350 LineCount:100]
Results: map[Contents: 350: default:
351: rxe_dbg_qp(qp, "unexpected opcode\n");
352: }
353:
354: return COMPST_ERROR;
355: }
356:
357: static inline enum comp_state do_read(struct rxe_qp *qp,
358: struct rxe_pkt_info *pkt,
359: struct rxe_send_wqe *wqe)
360: {
361: int ret;
362:
363: ret = copy_data(qp->pd, IB_ACCESS_LOCAL_WRITE,
364: &wqe->dma, payload_addr(pkt),
365: payload_size(pkt), RXE_TO_MR_OBJ);
366: if (ret) {
367: wqe->status = IB_WC_LOC_PROT_ERR;
368: return COMPST_ERROR;
369: }
370:
371: if (wqe->dma.resid == 0 && (pkt->mask & RXE_END_MASK))
372: return COMPST_COMP_ACK;
373:
374: return COMPST_UPDATE_COMP;
375: }
376:
377: static inline enum comp_state do_atomic(struct rxe_qp *qp,
378: struct rxe_pkt_info *pkt,
379: struct rxe_send_wqe *wqe)
380: {
381: int ret;
382:
383: u64 atomic_orig = atmack_orig(pkt);
384:
385: ret = copy_data(qp->pd, IB_ACCESS_LOCAL_WRITE,
386: &wqe->dma, &atomic_orig,
387: sizeof(u64), RXE_TO_MR_OBJ);
388: if (ret) {
389: wqe->status = IB_WC_LOC_PROT_ERR;
390: return COMPST_ERROR;
391: }
392:
393: return COMPST_COMP_ACK;
394: }
395:
396: static void make_send_cqe(struct rxe_qp *qp, struct rxe_send_wqe *wqe,
397: struct rxe_cqe *cqe)
398: {
399: struct ib_wc *wc = &cqe->ibwc;
400: struct ib_uverbs_wc *uwc = &cqe->uibwc;
401:
402: memset(cqe, 0, sizeof(*cqe));
403:
404: if (!qp->is_user) {
405: wc->wr_id = wqe->wr.wr_id;
406: wc->status = wqe->status;
407: wc->qp = &qp->ibqp;
408: } else {
409: uwc->wr_id = wqe->wr.wr_id;
410: uwc->status = wqe->status;
411: uwc->qp_num = qp->ibqp.qp_num;
412: }
413:
414: if (wqe->status == IB_WC_SUCCESS) {
415: if (!qp->is_user) {
416: wc->opcode = wr_to_wc_opcode(wqe->wr.opcode);
417: if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
418: wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
419: wc->wc_flags = IB_WC_WITH_IMM;
420: wc->byte_len = wqe->dma.length;
421: } else {
422: uwc->opcode = wr_to_wc_opcode(wqe->wr.opcode);
423: if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
424: wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
425: uwc->wc_flags = IB_WC_WITH_IMM;
426: uwc->byte_len = wqe->dma.length;
427: }
428: } else {
429: if (wqe->status != IB_WC_WR_FLUSH_ERR)
430: rxe_err_qp(qp, "non-flush error status = %d\n",
431: wqe->status);
432: }
433: }
434:
435: /*
436: * IBA Spec. Section 10.7.3.1 SIGNALED COMPLETIONS
437: * ---------8<---------8<-------------
438: * ...Note that if a completion error occurs, a Work Completion
439: * will always be generated, even if the signaling
440: * indicator requests an Unsignaled Completion.
441: * ---------8<---------8<-------------
442: */
443: static void do_complete(struct rxe_qp *qp, struct rxe_send_wqe *wqe)
444: {
445: struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
446: struct rxe_cqe cqe;
447: bool post;
448:
449: /* do we need to post a completion */
]
|
| 87/2 |
2026/10/21 02:01 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_comp.c FirstLine:450 LineCount:100]
Results: map[Contents: 450: post = ((qp->sq_sig_type == IB_SIGNAL_ALL_WR) ||
451: (wqe->wr.send_flags & IB_SEND_SIGNALED) ||
452: wqe->status != IB_WC_SUCCESS);
453:
454: if (post)
455: make_send_cqe(qp, wqe, &cqe);
456:
457: queue_advance_consumer(qp->sq.queue, QUEUE_TYPE_FROM_CLIENT);
458:
459: if (post)
460: rxe_cq_post(qp->scq, &cqe, 0);
461:
462: if (wqe->wr.opcode == IB_WR_SEND ||
463: wqe->wr.opcode == IB_WR_SEND_WITH_IMM ||
464: wqe->wr.opcode == IB_WR_SEND_WITH_INV)
465: rxe_counter_inc(rxe, RXE_CNT_RDMA_SEND);
466:
467: /*
468: * we completed something so let req run again
469: * if it is trying to fence
470: */
471: if (qp->req.wait_fence) {
472: qp->req.wait_fence = 0;
473: qp->req.again = 1;
474: }
475: }
476:
477: static void comp_check_sq_drain_done(struct rxe_qp *qp)
478: {
479: unsigned long flags;
480:
481: spin_lock_irqsave(&qp->state_lock, flags);
482: if (unlikely(qp_state(qp) == IB_QPS_SQD)) {
483: if (qp->attr.sq_draining && qp->comp.psn == qp->req.psn) {
484: qp->attr.sq_draining = 0;
485: spin_unlock_irqrestore(&qp->state_lock, flags);
486:
487: if (qp->ibqp.event_handler) {
488: struct ib_event ev;
489:
490: ev.device = qp->ibqp.device;
491: ev.element.qp = &qp->ibqp;
492: ev.event = IB_EVENT_SQ_DRAINED;
493: qp->ibqp.event_handler(&ev,
494: qp->ibqp.qp_context);
495: }
496: return;
497: }
498: }
499: spin_unlock_irqrestore(&qp->state_lock, flags);
500: }
501:
502: static inline enum comp_state complete_ack(struct rxe_qp *qp,
503: struct rxe_pkt_info *pkt,
504: struct rxe_send_wqe *wqe)
505: {
506: if (wqe->has_rd_atomic) {
507: wqe->has_rd_atomic = 0;
508: atomic_inc(&qp->req.rd_atomic);
509: if (qp->req.need_rd_atomic) {
510: qp->comp.timeout_retry = 0;
511: qp->req.need_rd_atomic = 0;
512: qp->req.again = 1;
513: }
514: }
515:
516: comp_check_sq_drain_done(qp);
517:
518: do_complete(qp, wqe);
519:
520: if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
521: return COMPST_UPDATE_COMP;
522: else
523: return COMPST_DONE;
524: }
525:
526: static inline enum comp_state complete_wqe(struct rxe_qp *qp,
527: struct rxe_pkt_info *pkt,
528: struct rxe_send_wqe *wqe)
529: {
530: if (pkt && wqe->state == wqe_state_pending) {
531: if (psn_compare(wqe->last_psn, qp->comp.psn) >= 0) {
532: qp->comp.psn = (wqe->last_psn + 1) & BTH_PSN_MASK;
533: qp->comp.opcode = -1;
534: }
535:
536: if (qp->req.wait_psn) {
537: qp->req.wait_psn = 0;
538: qp->req.again = 1;
539: }
540: }
541:
542: do_complete(qp, wqe);
543:
544: return COMPST_GET_WQE;
545: }
546:
547: /* drain incoming response packet queue */
548: static void drain_resp_pkts(struct rxe_qp *qp)
549: {
]
|
| 88/2 |
2026/10/21 02:01 |
llm |
expert |
0m
Model:
Tokens:
input: 109200
output: 50
thoughts: 848
Thoughts: **My Thoughts on `rxe_completer` and State Transitions**
Okay, I need to really pause and examine this `rxe_completer` function in `drivers/infiniband/sw/rxe/rxe_comp.c`. My immediate focus is tracing what happens when a packet (`pkt`) is `NULL`, which implies that the `resp_pkts` queue for the queue pair (`qp`) is empty.
My initial steps in tracing this scenario lead me to these observations:
1. The state machine within `rxe_completer` begins by setting `state = COMPST_GET_ACK;`.
2. The next operation is `skb = skb_dequeue(&qp->resp_pkts);`. Since `qp->resp_pkts` is empty, `skb` will be `NULL`, and consequently, `pkt` will also be `NULL`. The state then transitions to `state = COMPST_GET_WQE;`.
3. The function then proceeds to `state = get_wqe(qp, pkt, &wqe)`. I need to carefully review lines 139-166 of `drivers/infiniband/sw/rxe/rxe_comp.c` for the logic within `get_wqe`:
* If there's no `wqe` or the `wqe` is in `wqe_state_posted`, it returns `COMPST_DONE` if `pkt` is *not* `NULL`, but importantly, it returns `COMPST_EXIT` if `pkt` *is* `NULL`.
* If the `wqe` is in `wqe_state_done` (meaning it doesn't require an ACK), it returns `COMPST_COMP_WQE`.
* If the `wqe` is in `wqe_state_error`, it returns `COMPST_ERROR`.
* Otherwise, if a `wqe` is present and `pkt` is present, it returns `COMPST_CHECK_PSN`; if a `wqe` is present but `pkt` is `NULL`, it returns `COMPST_EXIT`.
4. So, let's assume we have a `wqe` that is in `wqe_state_pending` and `pkt` is `NULL`. Based on the logic in `get_wqe` (specifically the last `return` statement), the return value in this scenario will be `COMPST_EXIT`.
5. Now I need to look at how `COMPST_EXIT` is handled within the `rxe_completer` function, specifically in the `case COMPST_EXIT:` block (lines 745-795).
* Inside `COMPST_EXIT`, there's a check: `if (qp->comp.timeout_retry && wqe)`. If this condition is true, the state becomes `COMPST_ERROR_RETRY`.
* If the above condition is false, the code executes `reset_retry_timer(qp);` and then `goto exit;`.
Hold on a minute! My attention is drawn to `reset_retry_timer(qp)` at line 751. This function is called *before* the `goto exit;`. To understand the implications, I need to get a broader view and read lines 1 to 150 of `drivers/infiniband/sw/rxe/rxe_comp.c` to grasp the context and purpose of this timer reset and its potential impact on subsequent operations or retry mechanisms within the `rxe` driver. My current understanding is that when `resp_pkts` is empty and a pending `wqe` is encountered, the process should transition to an exit state, and a retry timer is being reset as part of this exit path.
|
| 89/2 |
2026/10/21 02:02 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_comp.c FirstLine:1 LineCount:150]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2: /*
3: * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4: * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5: */
6:
7: #include <linux/skbuff.h>
8:
9: #include "rxe.h"
10: #include "rxe_loc.h"
11: #include "rxe_queue.h"
12: #include "rxe_task.h"
13:
14: enum comp_state {
15: COMPST_GET_ACK,
16: COMPST_GET_WQE,
17: COMPST_COMP_WQE,
18: COMPST_COMP_ACK,
19: COMPST_CHECK_PSN,
20: COMPST_CHECK_ACK,
21: COMPST_READ,
22: COMPST_ATOMIC,
23: COMPST_WRITE_SEND,
24: COMPST_UPDATE_COMP,
25: COMPST_ERROR_RETRY,
26: COMPST_RNR_RETRY,
27: COMPST_ERROR,
28: COMPST_EXIT, /* We have an issue, and we want to rerun the completer */
29: COMPST_DONE, /* The completer finished successflly */
30: };
31:
32: static char *comp_state_name[] = {
33: [COMPST_GET_ACK] = "GET ACK",
34: [COMPST_GET_WQE] = "GET WQE",
35: [COMPST_COMP_WQE] = "COMP WQE",
36: [COMPST_COMP_ACK] = "COMP ACK",
37: [COMPST_CHECK_PSN] = "CHECK PSN",
38: [COMPST_CHECK_ACK] = "CHECK ACK",
39: [COMPST_READ] = "READ",
40: [COMPST_ATOMIC] = "ATOMIC",
41: [COMPST_WRITE_SEND] = "WRITE/SEND",
42: [COMPST_UPDATE_COMP] = "UPDATE COMP",
43: [COMPST_ERROR_RETRY] = "ERROR RETRY",
44: [COMPST_RNR_RETRY] = "RNR RETRY",
45: [COMPST_ERROR] = "ERROR",
46: [COMPST_EXIT] = "EXIT",
47: [COMPST_DONE] = "DONE",
48: };
49:
50: static unsigned long rnrnak_usec[32] = {
51: [IB_RNR_TIMER_655_36] = 655360,
52: [IB_RNR_TIMER_000_01] = 10,
53: [IB_RNR_TIMER_000_02] = 20,
54: [IB_RNR_TIMER_000_03] = 30,
55: [IB_RNR_TIMER_000_04] = 40,
56: [IB_RNR_TIMER_000_06] = 60,
57: [IB_RNR_TIMER_000_08] = 80,
58: [IB_RNR_TIMER_000_12] = 120,
59: [IB_RNR_TIMER_000_16] = 160,
60: [IB_RNR_TIMER_000_24] = 240,
61: [IB_RNR_TIMER_000_32] = 320,
62: [IB_RNR_TIMER_000_48] = 480,
63: [IB_RNR_TIMER_000_64] = 640,
64: [IB_RNR_TIMER_000_96] = 960,
65: [IB_RNR_TIMER_001_28] = 1280,
66: [IB_RNR_TIMER_001_92] = 1920,
67: [IB_RNR_TIMER_002_56] = 2560,
68: [IB_RNR_TIMER_003_84] = 3840,
69: [IB_RNR_TIMER_005_12] = 5120,
70: [IB_RNR_TIMER_007_68] = 7680,
71: [IB_RNR_TIMER_010_24] = 10240,
72: [IB_RNR_TIMER_015_36] = 15360,
73: [IB_RNR_TIMER_020_48] = 20480,
74: [IB_RNR_TIMER_030_72] = 30720,
75: [IB_RNR_TIMER_040_96] = 40960,
76: [IB_RNR_TIMER_061_44] = 61410,
77: [IB_RNR_TIMER_081_92] = 81920,
78: [IB_RNR_TIMER_122_88] = 122880,
79: [IB_RNR_TIMER_163_84] = 163840,
80: [IB_RNR_TIMER_245_76] = 245760,
81: [IB_RNR_TIMER_327_68] = 327680,
82: [IB_RNR_TIMER_491_52] = 491520,
83: };
84:
85: static inline unsigned long rnrnak_jiffies(u8 timeout)
86: {
87: return max_t(unsigned long,
88: usecs_to_jiffies(rnrnak_usec[timeout]), 1);
89: }
90:
91: static enum ib_wc_opcode wr_to_wc_opcode(enum ib_wr_opcode opcode)
92: {
93: switch (opcode) {
94: case IB_WR_RDMA_WRITE: return IB_WC_RDMA_WRITE;
95: case IB_WR_RDMA_WRITE_WITH_IMM: return IB_WC_RDMA_WRITE;
96: case IB_WR_SEND: return IB_WC_SEND;
97: case IB_WR_SEND_WITH_IMM: return IB_WC_SEND;
98: case IB_WR_RDMA_READ: return IB_WC_RDMA_READ;
99: case IB_WR_ATOMIC_CMP_AND_SWP: return IB_WC_COMP_SWAP;
100: case IB_WR_ATOMIC_FETCH_AND_ADD: return IB_WC_FETCH_ADD;
]
|
| 90/2 |
2026/10/21 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 112103
output: 50
thoughts: 4161
Thoughts: **A Deep Dive into the RXE Cleanup Timeout Conundrum**
This is maddening! I'm trying to get to the bottom of why `__rxe_cleanup` is timing out in `rxe_destroy_qp`, and it's a winding path. My first instinct was to cast a wide net, checking *everywhere* `qp` is referenced and where `rxe_wq` is active. But then, looking back at the bug report, a stark anomaly jumped out at me.
Here I am, staring at this log:
```
WARNING: drivers/infiniband/sw/rxe/rxe_pool.c:212 at __rxe_cleanup+0x311/0x350 drivers/infiniband/sw/rxe/rxe_pool.c:212, CPU#0: kworker/u8:9/3389
Modules linked in:
CPU: 0 UID: 0 PID: 3389 Comm: kworker/u8:9 Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2026
Workqueue: krds_cp_wq#0/0 rds_shutdown_worker
```
And it hit me: why is `kworker/u8:9` running `rds_shutdown_worker` on `krds_cp_wq#0/0`? The name `krds_cp_wq#0/0` screams "UNBOUND workqueue," and `u8:9` is precisely the unbound worker pool! This immediately made me question `rxe_wq`.
A quick peek at `drivers/infiniband/sw/rxe/rxe_task.c` confirmed my suspicion:
```c
int rxe_alloc_wq(void)
{
rxe_wq = alloc_workqueue("rxe_wq", WQ_UNBOUND, WQ_MAX_ACTIVE);
if (!rxe_wq)
return -ENOMEM;
return 0;
}
```
Yes, `rxe_wq` is *also* an unbound workqueue! This is where things get interesting. The `Tainted: [L]=SOFTLOCKUP` flag in a syzkaller VM with multiple CPUs (or a single CPU feeding unbound pools) suggests a potential deadlock or a long-running, non-responsive task. What if a task within `rxe_wq`, or one of its dependents like `rxe_qp_reset`, or even the `rds` component, is spinning endlessly, causing a soft lockup and preventing other work from progressing?
I'm now laser-focused on any situation where `rxe` or `rds` might be spinning in a loop or susceptible to a soft lockup, *while holding a reference to a `qp`* or somehow blocking `rxe_wq` from its necessary operations.
My attention then turned to `rxe_cleanup_task` and `rxe_disable_task` in `drivers/infiniband/sw/rxe/rxe_task.c`. The `while (!is_done(task)) cond_resched();` loop there is a prime suspect. When is `rxe_disable_task` even called? It's invoked within `rxe_qp_reset(qp)` and `rxe_qp_from_attr(qp)` (specifically when dealing with `IB_QP_MAX_DEST_RD_ATOMIC`).
Let's dissect `rxe_disable_task` more closely:
```c
void rxe_disable_task(struct rxe_task *task)
{
unsigned long flags;
WARN_ON(rxe_read(task->qp) <= 0); // This is crucial - reference count check
spin_lock_irqsave(&task->lock, flags);
if (!__is_done(task) && task->state < TASK_STATE_DRAINED) {
task->state = TASK_STATE_DRAINING;
} else {
task->state = TASK_STATE_DRAINED;
spin_unlock_irqrestore(&task->lock, flags);
return;
}
spin_unlock_irqrestore(&task->lock, flags);
while (!is_done(task)) // The potential endless loop
cond_resched();
spin_lock_irqsave(&task->lock, flags);
task->state = TASK_STATE_DRAINED;
spin_unlock_irqrestore(&task->lock, flags);
}
```
Here's a critical realization: what happens when `rxe_sched_task(task)` is called and then `rxe_disable_task(task)` is invoked concurrently? `rxe_sched_task` calls `__reserve_if_idle`, which increments `qp->elem.ref_cnt` and sets `task->state = TASK_STATE_BUSY`, then queues the work. If `rxe_disable_task` is called *while* the work is pending or the task is busy, it can set `task->state = TASK_STATE_DRAINING`. Then, the `while (!is_done(task)) cond_resched();` loop in `rxe_disable_task` starts.
The problem lies in `__is_done(task)` and how `do_task` behaves. `__is_done` checks `work_pending(&task->work)` and task states. When `do_task` runs on `rxe_wq` and finds `task->state == TASK_STATE_DRAINING`, it enters a critical path. If `ret == 0` (meaning the task function didn't complete its work in one go), and the state is `TASK_STATE_DRAINING`, `do_task` sets `cont = 1` and *doesn't yield the CPU*. It enters an *internal* loop (`while (cont)`) within `do_task` itself, effectively spinning without rescheduling until `ret != 0`. This can easily lead to a soft lockup if `ret` never becomes non-zero.
And this is where it gets even more tangled. Consider the change in `rxe_qp_from_attr` introduced by commit `6f7014237405`:
```c
if (mask & IB_QP_MAX_DEST_RD_ATOMIC) {
int max_dest_rd_atomic = attr->max_dest_rd_atomic ?
roundup_pow_of_two(attr->max_dest_rd_atomic) : 0;
rxe_disable_task(&qp->recv_task); // Sets state to DRAINED
free_rd_atomic_resources(qp);
qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;
err = alloc_rd_atomic_resources(qp, max_dest_rd_atomic);
if (err) // If allocation fails, recv_task remains DRAINED
return err;
rxe_enable_task(&qp->recv_task); // Only sets state to IDLE, doesn't schedule
}
```
If `alloc_rd_atomic_resources` fails, `qp->recv_task` remains in `TASK_STATE_DRAINED`. Now, when a packet arrives for this `qp` and `rxe_rcv` calls `rxe_resp_queue_pkt`, it then calls `rxe_sched_task(&qp->recv_task)`. However, `__reserve_if_idle` for a `TASK_STATE_DRAINED` task *does nothing* β it doesn't schedule the task. The packets are queued in `qp->req_pkts`, and critically, *each packet holds an `rxe_get(qp)` reference*.
The problem compounds when `rxe_destroy_qp(qp)` is called. It waits for the `qp`'s reference count to be zero before proceeding to `rxe_qp_do_cleanup`, which is the *only other place* that calls `rxe_receiver(qp)` to drain `qp->req_pkts`. If `qp->recv_task` is stuck in `DRAINED` (or `DRAINING`), and packets are queued, `rxe_receiver` is never effectively called to process them, leading to a permanently elevated reference count.
This isn't just about `recv_task`. I'm now digging into `rxe_completer(qp)`. It appears that if `qp->req.need_retry` is set (indicating a retry scenario) or if the QP enters `COMPST_RNR_RETRY` and arms a timer, `rxe_completer` can return `EAGAIN` *without dequeuing all packets from `qp->resp_pkts`*. Any remaining `skb`s in `qp->resp_pkts` will also hold an `rxe_get(qp)` reference.
The core of the issue seems to be this: there are scenarios where packets get queued in `qp->req_pkts` or `qp->resp_pkts`, each holding a reference to the `qp`, but the mechanisms designed to drain these queues (like `rxe_receiver` and `rxe_completer`) can become blocked or exit prematurely. This leaves the `qp`'s reference count elevated indefinitely, causing `rxe_destroy_qp` to time out while waiting for that count to drop to zero.
And I'm not done yet. I need to scrutinize what happens when a packet arrives in `rxe_rcv` *after* `rxe_qp_error(qp)` has been called. The interaction between error handling and subsequent packet reception is also a strong contender for a race condition.
|
| 91/2 |
2026/10/21 02:03 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_recv.c FirstLine:1 LineCount:140]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2: /*
3: * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4: * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5: */
6:
7: #include <linux/skbuff.h>
8:
9: #include "rxe.h"
10: #include "rxe_loc.h"
11:
12: /* check that QP matches packet opcode type and is in a valid state */
13: static int check_type_state(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
14: struct rxe_qp *qp)
15: {
16: unsigned int pkt_type;
17: unsigned long flags;
18:
19: if (unlikely(!qp->valid))
20: return -EINVAL;
21:
22: pkt_type = pkt->opcode & 0xe0;
23:
24: switch (qp_type(qp)) {
25: case IB_QPT_RC:
26: if (unlikely(pkt_type != IB_OPCODE_RC))
27: return -EINVAL;
28: break;
29: case IB_QPT_UC:
30: if (unlikely(pkt_type != IB_OPCODE_UC))
31: return -EINVAL;
32: break;
33: case IB_QPT_UD:
34: case IB_QPT_GSI:
35: if (unlikely(pkt_type != IB_OPCODE_UD))
36: return -EINVAL;
37: break;
38: default:
39: return -EINVAL;
40: }
41:
42: spin_lock_irqsave(&qp->state_lock, flags);
43: if (pkt->mask & RXE_REQ_MASK) {
44: if (unlikely(qp_state(qp) < IB_QPS_RTR)) {
45: spin_unlock_irqrestore(&qp->state_lock, flags);
46: return -EINVAL;
47: }
48: } else {
49: if (unlikely(qp_state(qp) < IB_QPS_RTS)) {
50: spin_unlock_irqrestore(&qp->state_lock, flags);
51: return -EINVAL;
52: }
53: }
54: spin_unlock_irqrestore(&qp->state_lock, flags);
55:
56: return 0;
57: }
58:
59: static void set_bad_pkey_cntr(struct rxe_port *port)
60: {
61: spin_lock_bh(&port->port_lock);
62: port->attr.bad_pkey_cntr = min((u32)0xffff,
63: port->attr.bad_pkey_cntr + 1);
64: spin_unlock_bh(&port->port_lock);
65: }
66:
67: static void set_qkey_viol_cntr(struct rxe_port *port)
68: {
69: spin_lock_bh(&port->port_lock);
70: port->attr.qkey_viol_cntr = min((u32)0xffff,
71: port->attr.qkey_viol_cntr + 1);
72: spin_unlock_bh(&port->port_lock);
73: }
74:
75: static int check_keys(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
76: u32 qpn, struct rxe_qp *qp)
77: {
78: struct rxe_port *port = &rxe->port;
79: u16 pkey = bth_pkey(pkt);
80:
81: pkt->pkey_index = 0;
82:
83: if (!pkey_match(pkey, IB_DEFAULT_PKEY_FULL)) {
84: set_bad_pkey_cntr(port);
85: return -EINVAL;
86: }
87:
88: if (qp_type(qp) == IB_QPT_UD || qp_type(qp) == IB_QPT_GSI) {
89: u32 qkey = (qpn == 1) ? GSI_QKEY : qp->attr.qkey;
90:
91: if (unlikely(deth_qkey(pkt) != qkey)) {
92: set_qkey_viol_cntr(port);
93: return -EINVAL;
94: }
95: }
96:
97: return 0;
98: }
99:
100: static int check_addr(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
]
|
| 92/2 |
2026/10/21 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 117726
output: 47
thoughts: 3046
Thoughts: **A Deep Dive into QP Reference Counting and State Transitions in RXE**
I've been scrutinizing the `check_type_state` function within `drivers/infiniband/sw/rxe/rxe_recv.c`, specifically how it handles different Queue Pair (QP) states. My immediate thought was to compare the enum values: `IB_QPS_RTR` (Ready to Receive), `IB_QPS_RTS` (Ready to Send), and importantly, `IB_QPS_ERR` (Error). Upon checking the `enum ib_qp_state`, I found `IB_QPS_ERR` is `6`, which is greater than or equal to `IB_QPS_RTS` (`3`). This is a critical observation.
The implication is that if a packet arrives when the QP is in the `IB_QPS_ERR` state, `check_type_state` would incorrectly return `0` (success). This would lead to the packet being queued in `qp->req_pkts` or `qp->resp_pkts`, followed by a call to `rxe_sched_task`. This feels like a potential race condition, especially when considering the interaction with `rxe_rcv` and `__rxe_cleanup`. If `rxe_rcv` were to look up the QP in `hdr_check` *before* `__rxe_cleanup` removes it and calls `__rxe_put`, the reference count on the QP element (`elem->ref_cnt`) would still be greater than one, allowing `rxe_sched_task` to proceed even after the QP is supposed to be cleaned up.
My concerns are amplified when I consider `rxe_rcv_mcast_pkt`. It seems to walk the `mcg->qp_list` and calls `rxe_get(qp)` without an explicit check for a null return. While `rxe_qp_chk_destroy` does check `mcg_num`, this still raises questions about robust reference management in multicast scenarios.
The core of my current investigation is: **What exactly holds a reference to a QP (or prevents its `elem.complete` from finalizing) when `rxe_destroy_qp` is invoked?** To answer this, I've painstakingly cataloged every instance of `rxe_get(qp)` or `rxe_pool_get_index(&rxe->qp_pool, ...)` within the entire kernel. I've focused on the `drivers/infiniband/sw/rxe/` directory, and the list appears to be complete, comprising seven specific locations.
Let me enumerate these seven critical points where a QP's reference count is incremented:
1. **`rxe_comp.c:122` (`retransmit_timer`):** This timer increments the QP reference before scheduling the send task and decrements it afterward.
2. **`rxe_req.c:105` (`rnr_nak_timer`):** Similar to the retransmit timer, this increments the reference before scheduling the send task and decrements it post-execution.
3. **`rxe_mcast.c:355` (`__rxe_init_mca`):** This is an initialization function for multicast, which calls `rxe_get(qp)`.
4. **`rxe_mw.c:163` (`rxe_do_bind_mw`):** Specifically for IB_MW_TYPE_2 Memory Windows, this function increments the QP reference.
5. **`rxe_net.c:454` (`rxe_send`) and `rxe_net.c:477` (`rxe_loopback`):** For outgoing packets, these functions increment the QP reference and an atomic counter for outstanding SKBs.
6. **`rxe_recv.c:153` (`hdr_check`) and `rxe_recv.c:248,252` (`rxe_rcv_mcast_pkt`):** Incoming SKBs are queued to `qp->req_pkts` or `qp->resp_pkts`.
7. **`rxe_task.c:41` (`__reserve_if_idle`):** When a task is transitioning from idle to busy, its QP reference is incremented.
Given that RDS (which I'm focused on) does *not* utilize multicast (`__rxe_init_mca`) nor Type 2 MWs (`rxe_do_bind_mw`), the lingering references in `rxe_destroy_qp` when `__rxe_cleanup` times out must originate from one of the remaining five points:
* **Outgoing SKBs:** Either from `rxe_send` or `rxe_loopback`.
* **Queued Incoming SKBs:** Those residing in `qp->req_pkts` or `qp->resp_pkts` after `hdr_check`.
* **Active Tasks:** Specifically, the `qp->send_task` or `qp->recv_task` being in a `BUSY` or similar state, managed by `__reserve_if_idle`.
My current line of inquiry is dissecting these three possibilities further. I'm particularly scrutinizing the behavior of `rxe_receiver(qp)` when a QP enters an error state. The function `rxe_qp_error(qp)` is called, setting the state to `IB_QPS_ERR` and scheduling the receive task. However, it then exits via `goto exit;`. This is where I'm seeing a potential issue: if the receive task is in a busy state when `rxe_qp_error` is called, `rxe_sched_task` will re-arm it. This means `rxe_receiver(qp)` will be called again, but this time it will correctly invoke `drain_req_pkts(qp)` because `qp_state(qp) == IB_QPS_ERR`. This suggests that SKBs in `qp->req_pkts` might be correctly handled even in error states.
However, I'm still digging into whether `RESPST_DONE` can be reached in `rxe_receiver(qp)` without an intervening `RESPST_CLEANUP`, which would be crucial for understanding how SKBs might be retained and prevent QP destruction. I'm currently performing a detailed grep of `RESPST_DONE` occurrences within `drivers/infiniband/sw/rxe/rxe_resp.c` to fully trace these paths.
|
| 93/2 |
2026/10/21 02:03 |
tool |
grepper |
0m
Args: map[Expression:RESPST_DONE PathPrefixes:[drivers/infiniband/sw/rxe/rxe_resp.c]]
Results: map[Output:drivers/infiniband/sw/rxe/rxe_resp.c=13=static char *resp_state_name[] = {
--
drivers/infiniband/sw/rxe/rxe_resp.c-45- [RESPST_ERROR] = "ERROR",
drivers/infiniband/sw/rxe/rxe_resp.c:46: [RESPST_DONE] = "DONE",
drivers/infiniband/sw/rxe/rxe_resp.c-47- [RESPST_EXIT] = "EXIT",
--
drivers/infiniband/sw/rxe/rxe_resp.c=932=static enum resp_states read_reply(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-1019- if (res->read.resid > 0) {
drivers/infiniband/sw/rxe/rxe_resp.c:1020: state = RESPST_DONE;
drivers/infiniband/sw/rxe/rxe_resp.c-1021- } else {
--
drivers/infiniband/sw/rxe/rxe_resp.c=1118=static enum resp_states do_complete(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-1231- if (unlikely(!pkt))
drivers/infiniband/sw/rxe/rxe_resp.c:1232: return RESPST_DONE;
drivers/infiniband/sw/rxe/rxe_resp.c-1233- if (qp_type(qp) == IB_QPT_RC)
--
drivers/infiniband/sw/rxe/rxe_resp.c=1307=static enum resp_states cleanup(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-1323-
drivers/infiniband/sw/rxe/rxe_resp.c:1324: return RESPST_DONE;
drivers/infiniband/sw/rxe/rxe_resp.c-1325-}
--
drivers/infiniband/sw/rxe/rxe_resp.c=1571=int rxe_receiver(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1742-
drivers/infiniband/sw/rxe/rxe_resp.c:1743: case RESPST_DONE:
drivers/infiniband/sw/rxe/rxe_resp.c-1744- if (qp->resp.goto_error) {
]
|
| 94/2 |
2026/10/21 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 121516
output: 47
thoughts: 52
Thoughts: **My Thought Process:**
I was reviewing the code, and a specific scenario just popped into my head: what happens if we encounter `RESPST_EXIT` within `rxe_resp.c`? It's a critical state, and I need to be absolutely sure of its handling. To get to the bottom of this, my immediate next step is to perform a comprehensive search. I'll be using `grep` specifically on the `drivers/infiniband/sw/rxe/rxe_resp.c` file for any occurrences of `RESPST_EXIT`. This will allow me to trace its usage, understand the code paths that lead to it, and ultimately verify its correct management within the response handling logic.
|
| 95/2 |
2026/10/21 02:04 |
tool |
grepper |
0m
Args: map[Expression:RESPST_EXIT PathPrefixes:[drivers/infiniband/sw/rxe/rxe_resp.c]]
Results: map[Output:drivers/infiniband/sw/rxe/rxe_resp.c=13=static char *resp_state_name[] = {
--
drivers/infiniband/sw/rxe/rxe_resp.c-46- [RESPST_DONE] = "DONE",
drivers/infiniband/sw/rxe/rxe_resp.c:47: [RESPST_EXIT] = "EXIT",
drivers/infiniband/sw/rxe/rxe_resp.c-48-};
--
drivers/infiniband/sw/rxe/rxe_resp.c=57=static inline enum resp_states get_req(struct rxe_qp *qp,
--
drivers/infiniband/sw/rxe/rxe_resp.c-63- if (!skb)
drivers/infiniband/sw/rxe/rxe_resp.c:64: return RESPST_EXIT;
drivers/infiniband/sw/rxe/rxe_resp.c-65-
--
drivers/infiniband/sw/rxe/rxe_resp.c=1571=int rxe_receiver(struct rxe_qp *qp)
--
drivers/infiniband/sw/rxe/rxe_resp.c-1750-
drivers/infiniband/sw/rxe/rxe_resp.c:1751: case RESPST_EXIT:
drivers/infiniband/sw/rxe/rxe_resp.c-1752- if (qp->resp.goto_error) {
]
|
| 96/2 |
2026/10/21 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 122012
output: 48
thoughts: 1502
Thoughts: **My Thought Process on the Infiniband RXE Error State and QP Reference Counting**
Okay, I've stumbled upon something that needs a deep dive, and it's all centered around this `RESPST_ERROR` state in the `rxe_resp.c` driver, specifically within the `rxe_receiver` function. I'm trying to trace the lifecycle of a QP (Queue Pair) when it transitions into this error state, and I've hit a crucial question: when `rxe_receiver(qp)` enters `RESPST_ERROR`, specifically due to `RESPST_ERR_CQ_OVERFLOW` or when `qp->resp.goto_error` is set, did it actually run through `RESPST_CLEANUP` beforehand?
My initial suspicion is that it might not, and this is where things get complicated. I'm looking at the `do_complete` function, and I see this snippet:
```c
1213: if (rxe_cq_post(qp->rcq, &cqe, pkt ? bth_se(pkt) : 1))
1214: return RESPST_ERR_CQ_OVERFLOW;
```
And then, in `rxe_receiver` itself, the `RESPST_ERR_CQ_OVERFLOW` case directly transitions to `RESPST_ERROR`:
```c
1738: case RESPST_ERR_CQ_OVERFLOW:
1739: /* All - Class G */
1740: state = RESPST_ERROR;
1741: break;
```
Finally, within `RESPST_ERROR`:
```c1759: case RESPST_ERROR:
1760: qp->resp.goto_error = 0;
1761: rxe_dbg_qp(qp, "moved to error state\n");
1762: rxe_qp_error(qp);
1763: goto exit;
```
Now, the critical distinction I'm making is *how* `rxe_receiver` is called. If it's called directly, for example, from `rxe_qp_reset` or `rxe_qp_do_cleanup`, then `rxe_qp_error` is responsible for scheduling `recv_task`. However, if it's called from `do_task`, `rxe_qp_error` simply sets `recv_task.state = TASK_STATE_ARMED`. This means `do_task` will loop and call `rxe_receiver` again. The *next* time `rxe_receiver` is called, it will see that `qp_state(qp) == IB_QPS_ERR`, and that will trigger `drain_req_pkts(qp)`.
This is where my alarm bells are ringing: what if `qp->resp.mr` was still holding a reference (a refcount) when `RESPST_ERR_CQ_OVERFLOW` occurred, or even when `drain_req_pkts(qp)` was subsequently executed? I've noted that `qp->resp.mr` actually holds a reference on the `mr` (Memory Region), *not* on the `qp` itself. This is a crucial detail.
So, my focus shifts: what *does* hold a reference on the `qp`? I've identified three primary mechanisms within RDS (Reliable Datagram Service) that can retain a reference on a `qp`:
1. **The `send_task` or `recv_task`:** This happens when `__reserve_if_idle` has previously called `rxe_get(task->qp)`.
2. **The `qp->req_pkts` or `qp->resp_pkts` queues:** This is due to `hdr_check` having called `rxe_pool_get_index(&rxe->qp_pool, index)`.
3. **`rxe_send` / `rxe_loopback` operations:** This occurs when `rxe_get(pkt->qp)` is called for an outgoing `skb` where `skb->destructor` is set to `rxe_skb_tx_dtor`.
My immediate, overwhelming thought is: I need to thoroughly examine *all three* of these scenarios. The core question I'm trying to answer is: why would *any* of these reference mechanisms still be holding onto a `qp` reference a significant time (I'm thinking upwards of 50 seconds) after `rxe_destroy_qp` has initiated its process?
To answer this, I'm now diving into specific call paths. I'm looking at `rds_ib_conn_path_shutdown`, and specifically what happens *before* `rdma_destroy_qp(ic->i_cm_id)` is invoked. Looking at `net/rds/ib_cm.c`, I see this:
```c1074: if (ic->i_cm_id) {
1075: rdsdebug("disconnecting cm %p\n", ic->i_cm_id);
1076: err = rdma_disconnect(ic->i_cm_id);
1077: if (err) {
1078: /* Actually this may happen quite frequently, when
1079: * an outgoing connect raced with an incoming connect.
1080: */
1081: rdsdebug("failed to disconnect, cm: %p err %d\n",
1082: ic->i_cm_id, err);
1083: }
```
This immediately brings me to another "WAIT A SECOND!" moment. Lines 1076-1083 are critical. When exactly does `rdma_disconnect(ic->i_cm_id)` return an error (i.e., `err != 0`)? To figure that out, I need to trace into `rdma_disconnect` itself, which is in `drivers/infiniband/core/cma.c`:
```c
int rdma_disconnect(struct rdma_cm_id *id)
{
struct rdma_id_private *id_priv;
int ret;
id_priv = container_of(id, struct rdma_id_private, id);
if (!id_priv->cm_id.ib)
return -EINVAL;
if (rdma_cap_ib_cm(id->device, id->port_num)) {
ret = cma_modify_qp_err(id_priv);
...
```
This leads me to a very specific and perhaps tricky question: when is `id_priv->cm_id.ib` NULL, but simultaneously `ic->i_cm_id->qp` is *not* NULL? This inconsistency would be a prime suspect for the error condition.
To investigate this further, I'm looking at `rds_ib_cm_initiate_connect` in `net/rds/ib_cm.c`:
```c
ret = rds_ib_setup_qp(conn);
if (ret) {
rds_ib_conn_error(conn, "rds_ib_setup_qp failed (%d)\n", ret);
goto out;
}
rds_ib_cm_fill_conn_param(conn, &conn_param, &dp,
conn->c_proposed_version,
UINT_MAX, UINT_MAX, isv6);
ret = rdma_connect_locked(cm_id, &conn_param);
```
And within `rds_ib_setup_qp(conn)`, the call to `rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr)` is what I need to scrutinize next. My thought process is now to deep-dive into what `rdma_create_qp` in `drivers/infiniband/core/cma.c` actually does and how it sets up the initial state that could lead to the observed issues later.
|
| 97/2 |
2026/10/21 02:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/cma.c Name:rdma_create_qp]
Results: map[SourceCode:1123: int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
1124: struct ib_qp_init_attr *qp_init_attr)
1125: {
1126: struct rdma_id_private *id_priv;
1127: struct ib_qp *qp;
1128: int ret;
1129:
1130: id_priv = container_of(id, struct rdma_id_private, id);
1131: if (id->device != pd->device) {
1132: ret = -EINVAL;
1133: goto out_err;
1134: }
1135:
1136: qp_init_attr->port_num = id->port_num;
1137: qp = ib_create_qp(pd, qp_init_attr);
1138: if (IS_ERR(qp)) {
1139: ret = PTR_ERR(qp);
1140: goto out_err;
1141: }
1142:
1143: if (id->qp_type == IB_QPT_UD)
1144: ret = cma_init_ud_qp(id_priv, qp);
1145: else
1146: ret = cma_init_conn_qp(id_priv, qp);
1147: if (ret)
1148: goto out_destroy;
1149:
1150: id->qp = qp;
1151: id_priv->qp_num = qp->qp_num;
1152: id_priv->srq = (qp->srq != NULL);
1153: trace_cm_qp_create(id_priv, pd, qp_init_attr, 0);
1154: return 0;
1155: out_destroy:
1156: ib_destroy_qp(qp);
1157: out_err:
1158: trace_cm_qp_create(id_priv, pd, qp_init_attr, ret);
1159: return ret;
1160: }
SourceFile:drivers/infiniband/core/cma.c]
|
| 98/2 |
2026/10/21 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 124191
output: 46
thoughts: 50
Thoughts: **A Deep Dive into `rds_ib_setup_qp`'s Operational Footprint**
My initial thought, upon encountering the `rds_ib_setup_qp` function within `net/rds/ib_cm.c`, is to meticulously scrutinize its operational scope. Specifically, I need to determine whether this function, as part of the RDS (Reliable Datagram Service) over InfiniBand (IB) implementation, initiates any Work Requests (WRs) or schedules any deferred tasks. This level of detail is critical for understanding the full lifecycle and interdependencies of connection establishment and queue pair (QP) setup in this context. My immediate next step, therefore, is to engage directly with the source code of `rds_ib_setup_qp` to ascertain the presence and nature of any such postings or scheduling activities.
|
| 99/2 |
2026/10/21 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/rds/ib_cm.c Name:rds_ib_setup_qp]
Results: map[SourceCode: 498: /*
499: * This needs to be very careful to not leave IS_ERR pointers around for
500: * cleanup to trip over.
501: */
502: static int rds_ib_setup_qp(struct rds_connection *conn)
503: {
504: struct rds_ib_connection *ic = conn->c_transport_data;
505: struct ib_device *dev = ic->i_cm_id->device;
506: struct ib_qp_init_attr attr;
507: struct ib_cq_init_attr cq_attr = {};
508: struct rds_ib_device *rds_ibdev;
509: unsigned long max_wrs;
510: int ret, fr_queue_space;
511:
512: /*
513: * It's normal to see a null device if an incoming connection races
514: * with device removal, so we don't print a warning.
515: */
516: rds_ibdev = rds_ib_get_client_data(dev);
517: if (!rds_ibdev)
518: return -EOPNOTSUPP;
519:
520: /* The fr_queue_space is currently set to 512, to add extra space on
521: * completion queue and send queue. This extra space is used for FRWR
522: * registration and invalidation work requests
523: */
524: fr_queue_space = RDS_IB_DEFAULT_FR_WR;
525:
526: /* add the conn now so that connection establishment has the dev */
527: rds_ib_add_conn(rds_ibdev, conn);
528:
529: max_wrs = rds_ibdev->max_wrs < rds_ib_sysctl_max_send_wr + 1 ?
530: rds_ibdev->max_wrs - 1 : rds_ib_sysctl_max_send_wr;
531: if (ic->i_send_ring.w_nr != max_wrs)
532: rds_ib_ring_resize(&ic->i_send_ring, max_wrs);
533:
534: max_wrs = rds_ibdev->max_wrs < rds_ib_sysctl_max_recv_wr + 1 ?
535: rds_ibdev->max_wrs - 1 : rds_ib_sysctl_max_recv_wr;
536: if (ic->i_recv_ring.w_nr != max_wrs)
537: rds_ib_ring_resize(&ic->i_recv_ring, max_wrs);
538:
539: /* Protection domain and memory range */
540: ic->i_pd = rds_ibdev->pd;
541:
542: ic->i_scq_vector = ibdev_get_unused_vector(rds_ibdev);
543: cq_attr.cqe = ic->i_send_ring.w_nr + fr_queue_space + 1;
544: cq_attr.comp_vector = ic->i_scq_vector;
545: ic->i_send_cq = ib_create_cq(dev, rds_ib_cq_comp_handler_send,
546: rds_ib_cq_event_handler, conn,
547: &cq_attr);
548: if (IS_ERR(ic->i_send_cq)) {
549: ret = PTR_ERR(ic->i_send_cq);
550: ic->i_send_cq = NULL;
551: ibdev_put_vector(rds_ibdev, ic->i_scq_vector);
552: rdsdebug("ib_create_cq send failed: %d\n", ret);
553: goto rds_ibdev_out;
554: }
555:
556: ic->i_rcq_vector = ibdev_get_unused_vector(rds_ibdev);
557: cq_attr.cqe = ic->i_recv_ring.w_nr;
558: cq_attr.comp_vector = ic->i_rcq_vector;
559: ic->i_recv_cq = ib_create_cq(dev, rds_ib_cq_comp_handler_recv,
560: rds_ib_cq_event_handler, conn,
561: &cq_attr);
562: if (IS_ERR(ic->i_recv_cq)) {
563: ret = PTR_ERR(ic->i_recv_cq);
564: ic->i_recv_cq = NULL;
565: ibdev_put_vector(rds_ibdev, ic->i_rcq_vector);
566: rdsdebug("ib_create_cq recv failed: %d\n", ret);
567: goto send_cq_out;
568: }
569:
570: ret = ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP);
571: if (ret) {
572: rdsdebug("ib_req_notify_cq send failed: %d\n", ret);
573: goto recv_cq_out;
574: }
575:
576: ret = ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
577: if (ret) {
578: rdsdebug("ib_req_notify_cq recv failed: %d\n", ret);
579: goto recv_cq_out;
580: }
581:
582: /* XXX negotiate max send/recv with remote? */
583: memset(&attr, 0, sizeof(attr));
584: attr.event_handler = rds_ib_qp_event_handler;
585: attr.qp_context = conn;
586: /* + 1 to allow for the single ack message */
587: attr.cap.max_send_wr = ic->i_send_ring.w_nr + fr_queue_space + 1;
588: attr.cap.max_recv_wr = ic->i_recv_ring.w_nr + 1;
589: attr.cap.max_send_sge = rds_ibdev->max_sge;
590: attr.cap.max_recv_sge = RDS_IB_RECV_SGE;
591: attr.sq_sig_type = IB_SIGNAL_REQ_WR;
592: attr.qp_type = IB_QPT_RC;
593: attr.send_cq = ic->i_send_cq;
594: attr.recv_cq = ic->i_recv_cq;
595:
596: /*
597: * XXX this can fail if max_*_wr is too large? Are we supposed
598: * to back off until we get a value that the hardware can support?
599: */
600: ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr);
601: if (ret) {
602: rdsdebug("rdma_create_qp failed: %d\n", ret);
603: goto recv_cq_out;
604: }
605:
606: ic->i_send_hdrs = rds_dma_hdrs_alloc(rds_ibdev, &ic->i_send_hdrs_dma,
607: ic->i_send_ring.w_nr,
608: DMA_TO_DEVICE);
609: if (!ic->i_send_hdrs) {
610: ret = -ENOMEM;
611: rdsdebug("DMA send hdrs alloc failed\n");
612: goto qp_out;
613: }
614:
615: ic->i_recv_hdrs = rds_dma_hdrs_alloc(rds_ibdev, &ic->i_recv_hdrs_dma,
616: ic->i_recv_ring.w_nr,
617: DMA_FROM_DEVICE);
618: if (!ic->i_recv_hdrs) {
619: ret = -ENOMEM;
620: rdsdebug("DMA recv hdrs alloc failed\n");
621: goto send_hdrs_dma_out;
622: }
623:
624: ic->i_ack = rds_dma_hdr_alloc(rds_ibdev->dev, &ic->i_ack_dma,
625: DMA_TO_DEVICE);
626: if (!ic->i_ack) {
627: ret = -ENOMEM;
628: rdsdebug("DMA ack header alloc failed\n");
629: goto recv_hdrs_dma_out;
630: }
631:
632: ic->i_sends = vzalloc_node(array_size(sizeof(struct rds_ib_send_work),
633: ic->i_send_ring.w_nr),
634: ibdev_to_node(dev));
635: if (!ic->i_sends) {
636: ret = -ENOMEM;
637: rdsdebug("send allocation failed\n");
638: goto ack_dma_out;
639: }
640:
641: ic->i_recvs = vzalloc_node(array_size(sizeof(struct rds_ib_recv_work),
642: ic->i_recv_ring.w_nr),
643: ibdev_to_node(dev));
644: if (!ic->i_recvs) {
645: ret = -ENOMEM;
646: rdsdebug("recv allocation failed\n");
647: goto sends_out;
648: }
649:
650: rds_ib_recv_init_ack(ic);
651:
652: rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd,
653: ic->i_send_cq, ic->i_recv_cq);
654:
655: goto out;
656:
657: sends_out:
658: vfree(ic->i_sends);
659: ic->i_sends = NULL;
660:
661: ack_dma_out:
662: rds_dma_hdr_free(rds_ibdev->dev, ic->i_ack, ic->i_ack_dma,
663: DMA_TO_DEVICE);
664: ic->i_ack = NULL;
665:
666: recv_hdrs_dma_out:
667: rds_dma_hdrs_free(rds_ibdev, ic->i_recv_hdrs, ic->i_recv_hdrs_dma,
668: ic->i_recv_ring.w_nr, DMA_FROM_DEVICE);
669: ic->i_recv_hdrs = NULL;
670: ic->i_recv_hdrs_dma = NULL;
671:
672: send_hdrs_dma_out:
673: rds_dma_hdrs_free(rds_ibdev, ic->i_send_hdrs, ic->i_send_hdrs_dma,
674: ic->i_send_ring.w_nr, DMA_TO_DEVICE);
675: ic->i_send_hdrs = NULL;
676: ic->i_send_hdrs_dma = NULL;
677:
678: qp_out:
679: rdma_destroy_qp(ic->i_cm_id);
680: recv_cq_out:
681: ib_destroy_cq(ic->i_recv_cq);
682: ic->i_recv_cq = NULL;
683: send_cq_out:
684: ib_destroy_cq(ic->i_send_cq);
685: ic->i_send_cq = NULL;
686: rds_ibdev_out:
687: rds_ib_remove_conn(rds_ibdev, conn);
688: out:
689: rds_ib_dev_put(rds_ibdev);
690:
691: return ret;
692: }
SourceFile:net/rds/ib_cm.c]
|
| 100/2 |
2026/10/21 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 127861
output: 44
thoughts: 238
Thoughts: **A Deep Dive into RDS/IB Connection Handling and Protocol Versioning**
My current train of thought has me scrutinizing the intricacies of the RDS (Reliable Datagram Service) over InfiniBand (IB) connection establishment process, specifically focusing on how protocol versions are managed and enforced.
My attention was immediately drawn to a specific section within the `rds_ib_cm_connect_complete` function in `net/rds/ib_cm.c`, lines 112-121. This snippet is critical because it's where the system checks for protocol version compatibility *after* a connection has been initiated and is nearing completion. I see a conditional block that first checks if the incoming connection's version (`conn->c_version`) is *less than* the currently supported RDS protocol version (`RDS_PROTOCOL_VERSION`).
Within that block, there's a further, more stringent check: `if (conn->c_version != RDS_PROTOCOL_COMPAT_VERSION)`. This is the crucial part. It means that while older, but still compatible, versions might be tolerated to a degree, any version that isn't *exactly* the designated compatible version, *and* is also older than the current primary version, is a no-go. The consequence of this mismatch is clear: a `pr_notice` is logged informing the administrator about the unsupported version, and then `rds_conn_drop(conn)` is called, effectively terminating the connection. This is a deliberate and important safeguard to prevent connections with potentially incompatible or known problematic protocol versions from proceeding.
This observation then naturally leads me to consider the *initiation* side of this version negotiation. If `rds_ib_cm_connect_complete` is handling the *completion*, what logic governs the *initial* connection attempt and its version proposal? That's why my thoughts are now firmly fixed on the `rds_ib_cm_handle_connect` function, also within `net/rds/ib_cm.c`. I need to examine lines 783-933 of that function to understand the full picture of how protocol versions are exchanged and validated from the very beginning of the connection lifecycle. My hypothesis is that `rds_ib_cm_handle_connect` is where the connection's proposed version is determined and potentially compared against the local system's capabilities, setting the stage for the checks I just observed in `rds_ib_cm_connect_complete`. I'm eager to see how the initial version negotiation and handshake are implemented there, and how potential incompatibilities are flagged or handled *before* the connection reaches its final stages.
|
| 101/2 |
2026/10/21 02:05 |
tool |
read-file |
0m
Args: map[File:net/rds/ib_cm.c FirstLine:783 LineCount:150]
Results: map[Contents: 783: int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
784: struct rdma_cm_event *event, bool isv6)
785: {
786: __be64 lguid = cm_id->route.path_rec->sgid.global.interface_id;
787: __be64 fguid = cm_id->route.path_rec->dgid.global.interface_id;
788: const struct rds_ib_conn_priv_cmn *dp_cmn;
789: struct rds_connection *conn = NULL;
790: struct rds_ib_connection *ic = NULL;
791: struct rdma_conn_param conn_param;
792: const union rds_ib_conn_priv *dp;
793: union rds_ib_conn_priv dp_rep;
794: struct in6_addr s_mapped_addr;
795: struct in6_addr d_mapped_addr;
796: const struct in6_addr *saddr6;
797: const struct in6_addr *daddr6;
798: int destroy = 1;
799: u32 ifindex = 0;
800: u32 version;
801: int err = 1;
802:
803: /* Check whether the remote protocol version matches ours. */
804: version = rds_ib_protocol_compatible(event, isv6);
805: if (!version) {
806: err = RDS_RDMA_REJ_INCOMPAT;
807: goto out;
808: }
809:
810: dp = event->param.conn.private_data;
811: if (isv6) {
812: #if IS_ENABLED(CONFIG_IPV6)
813: if (!ipv6_mod_enabled()) {
814: err = -EOPNOTSUPP;
815: goto out;
816: }
817: dp_cmn = &dp->ricp_v6.dp_cmn;
818: saddr6 = &dp->ricp_v6.dp_saddr;
819: daddr6 = &dp->ricp_v6.dp_daddr;
820: /* If either address is link local, need to find the
821: * interface index in order to create a proper RDS
822: * connection.
823: */
824: if (ipv6_addr_type(daddr6) & IPV6_ADDR_LINKLOCAL) {
825: /* Using init_net for now .. */
826: ifindex = __rds_find_ifindex(&init_net, daddr6);
827: /* No index found... Need to bail out. */
828: if (ifindex == 0) {
829: err = -EOPNOTSUPP;
830: goto out;
831: }
832: } else if (ipv6_addr_type(saddr6) & IPV6_ADDR_LINKLOCAL) {
833: /* Use our address to find the correct index. */
834: ifindex = __rds_find_ifindex(&init_net, daddr6);
835: /* No index found... Need to bail out. */
836: if (ifindex == 0) {
837: err = -EOPNOTSUPP;
838: goto out;
839: }
840: }
841: #else
842: err = -EOPNOTSUPP;
843: goto out;
844: #endif
845: } else {
846: dp_cmn = &dp->ricp_v4.dp_cmn;
847: ipv6_addr_set_v4mapped(dp->ricp_v4.dp_saddr, &s_mapped_addr);
848: ipv6_addr_set_v4mapped(dp->ricp_v4.dp_daddr, &d_mapped_addr);
849: saddr6 = &s_mapped_addr;
850: daddr6 = &d_mapped_addr;
851: }
852:
853: rdsdebug("saddr %pI6c daddr %pI6c RDSv%u.%u lguid 0x%llx fguid 0x%llx, tos:%d\n",
854: saddr6, daddr6, RDS_PROTOCOL_MAJOR(version),
855: RDS_PROTOCOL_MINOR(version),
856: (unsigned long long)be64_to_cpu(lguid),
857: (unsigned long long)be64_to_cpu(fguid), dp_cmn->ricpc_dp_toss);
858:
859: /* RDS/IB is not currently netns aware, thus init_net */
860: conn = rds_conn_create(&init_net, daddr6, saddr6,
861: &rds_ib_transport, dp_cmn->ricpc_dp_toss,
862: GFP_KERNEL, ifindex);
863: if (IS_ERR(conn)) {
864: rdsdebug("rds_conn_create failed (%ld)\n", PTR_ERR(conn));
865: conn = NULL;
866: goto out;
867: }
868:
869: /*
870: * The connection request may occur while the
871: * previous connection exist, e.g. in case of failover.
872: * But as connections may be initiated simultaneously
873: * by both hosts, we have a random backoff mechanism -
874: * see the comment above rds_queue_reconnect()
875: */
876: mutex_lock(&conn->c_cm_lock);
877: if (!rds_conn_transition(conn, RDS_CONN_DOWN, RDS_CONN_CONNECTING)) {
878: if (rds_conn_state(conn) == RDS_CONN_UP) {
879: rdsdebug("incoming connect while connecting\n");
880: rds_conn_drop(conn);
881: rds_ib_stats_inc(s_ib_listen_closed_stale);
882: } else
]
|
| 102/2 |
2026/10/21 02:05 |
llm |
expert-compressor |
0m
Model:
Reply: ### 1. Approaches Tried and Results
* **Crash report analysis:**
- Bug: `WARNING: drivers/infiniband/sw/rxe/rxe_pool.c:212 at __rxe_cleanup+0x311/0x350`
- Stack: `rds_shutdown_worker` -> `rds_conn_shutdown` -> `rds_ib_conn_path_shutdown` -> `rdma_destroy_qp` -> `ib_destroy_qp` -> `ib_destroy_qp_user` -> `rxe_destroy_qp` -> `__rxe_cleanup`.
- Kernel flags: `Tainted: [L]=SOFTLOCKUP`, warning condition triggered: `WARN_ON(!ret)` at line 212 of `rxe_pool.c`.
- Cause of warning: `ret = wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))` returned 0 (timeout after 50 seconds waiting for `elem->complete`).
* **Source inspection of `__rxe_cleanup` and `rxe_destroy_qp`:**
- In `__rxe_cleanup` (`drivers/infiniband/sw/rxe/rxe_pool.c:177`):
- `xa_erase(xa, elem->index);`
- `__rxe_put(elem);` (drops initial allocation refcount).
- If `sleepable`, checks `if (!completion_done(&elem->complete))` and calls `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000));`.
- If timed out (`!ret`), emits `WARN_ON(!ret)` and sets `err = -ETIMEDOUT`.
- Regardless of timeout, `pool->cleanup(elem)` is executed (`rxe_qp_cleanup` -> `execute_in_process_context(rxe_qp_do_cleanup, ...)`).
- In `rxe_destroy_qp` (`drivers/infiniband/sw/rxe/rxe_verbs.c:650`):
- Calls `rxe_cleanup(qp)`. If it returns error, logs with `rxe_err_qp` but returns 0 anyway!
- In `ib_destroy_qp_user` (`drivers/infiniband/core/verbs.c:2155`):
- If `destroy_qp` returns 0, it calls `kfree(qp)`.
* **Investigation of QP refcounting and tasks (`rxe_task.c`, `rxe_resp.c`, `rxe_comp.c`, `rxe_net.c`, `rxe_qp.c`):**
- Traced how references to `qp` (`elem->ref_cnt`) are acquired and released:
- Outgoing skbs (`rxe_send` / `rxe_loopback`): `rxe_get(pkt->qp)` in `rxe_send`, dropped in `rxe_skb_tx_dtor`.
- Incoming skbs (`rxe_rcv` / `hdr_check`): `rxe_pool_get_index(&rxe->qp_pool, ...)` takes ref; queued into `qp->req_pkts` or `qp->resp_pkts`.
- Workqueue tasks: `rxe_sched_task()` -> `__reserve_if_idle()` takes `rxe_get(task->qp)`. Dropped in `do_task` when task completes.
- Timers: `retransmit_timer`, `rnr_nak_timer` take `rxe_get(qp)` when firing and drop upon exit.
- Type 2 MW: `rxe_do_bind_mw` takes `rxe_get(qp)`.
- Multicast: `__rxe_init_mca` takes `rxe_get(qp)`.
- Examined `rxe_qp_do_cleanup`:
- Cleans up timers, tasks (`rxe_cleanup_task`), calls `rxe_sender`, `rxe_receiver`, frees queues, drops PD/CQ/SRQ refs, frees rd_atomic resources.
* **Git log analysis on recent changes:**
- Commit `15ae32c4a355`: "RDMA/rxe: Avoid reprocessing the current packet after the QP enters the error state" fixed duplicate packet reprocessing when entering error state during `do_complete()`.
- Commit `6f7014237405`: "RDMA/rxe: Fix responder UAF on IB_QP_MAX_DEST_RD_ATOMIC modify_qp".
- Commit `98d446b7c013`: "net/rds: don't let the rdma_cm destroy an id RDS still owns on route failure".
- Commit `f97d8c7bab78`: "rds: ib: use rds_conn_drop() on protocol version mismatch".
---
### 2. Verified Facts
* **The Warning / Bug Mechanism:**
- `drivers/infiniband/sw/rxe/rxe_pool.c:212`:
```c
if (!completion_done(&elem->complete)) {
ret = wait_for_completion_timeout(&elem->complete,
msecs_to_jiffies(50000));
if (WARN_ON(!ret))
err = -ETIMEDOUT;
}
```
- When a QP is destroyed via `rxe_destroy_qp()`, `elem->complete` was NOT signaled even after 50,000 ms (50 seconds).
- This indicates at least one outstanding reference to `qp` (`kref_read(&elem->ref_cnt) > 0`) remained held.
- Crucially: after `WARN_ON(!ret)`, `__rxe_cleanup` still calls `pool->cleanup(elem)` (`rxe_qp_cleanup`), and `rxe_destroy_qp` returns 0.
- Subsequently, `ib_destroy_qp_user` calls `kfree(qp)`.
- If another thread or workqueue or timer still holds a reference to `qp`, accessing `qp` or calling `rxe_put(qp)` after `kfree(qp)` is a Use-After-Free (UAF).
- Furthermore, during the 50s blocking wait in `wait_for_completion_timeout`, the kernel was tainted with `[L]=SOFTLOCKUP`, indicating CPU lockup or stalled worker thread.
* **RDS Transport Context:**
- Triggered in `kworker/u8:9` executing `rds_shutdown_worker` -> `rds_conn_shutdown` -> `rds_ib_conn_path_shutdown`.
- In `rds_ib_conn_path_shutdown`:
- Calls `rdma_disconnect(ic->i_cm_id)`.
- Flushes MRs: `rds_ib_flush_mrs()`.
- Waits for rings to empty: `wait_event_timeout(rds_ib_ring_empty_wait, ...)`.
- Kills tasklets, sets quiesce.
- Calls `rdma_destroy_qp(ic->i_cm_id)`.
* **Refcount completion design in `rxe_pool.c`:**
- When `rxe_put(qp)` drops the refcount to 0, `kref_put` calls `rxe_elem_release`, which calls `complete(&elem->complete)`.
- The timeout means refcount never hit 0 within 50 seconds.
---
### 3. Open Hypotheses / Theories
1. **Stuck / Leaked QP Reference in RXE:**
- Why was a reference held?
- Case A: An incoming packet queued on `qp->req_pkts` or `qp->resp_pkts` was never processed or dequeued. If the QP wasn't transitioned to `IB_QPS_ERR` or `IB_QPS_RESET` before `rxe_cleanup` (or if `rdma_disconnect` failed or didn't set error state), `rxe_completer` or `rxe_receiver` did not drain the queue, and `rxe_qp_do_cleanup` (which drains them) is only scheduled *after* the wait! This is a circular dependency: `__rxe_cleanup` waits for all refs to be dropped before calling `rxe_qp_cleanup`, but packets sitting in `req_pkts` or `resp_pkts` hold refs that are only drained in `rxe_qp_do_cleanup` if the QP was not put into ERR state beforehand!
- Case B: Inflight skb in network layer or UDP tunnel socket holding `rxe_skb_tx_dtor` ref.
- Case C: A task (`send_task` or `recv_task`) is stuck on `rxe_wq` in an infinite loop or deadlock, keeping `task->state == TASK_STATE_BUSY` and holding `rxe_get(qp)`. This would also explain the `SOFTLOCKUP`.
- Case D: A race between `rxe_sched_task` and task execution where `rxe_put(qp)` is lost or deferred indefinitely.
2. **Exploitability and Impact Assessment:**
- **Exploitation:** When `wait_for_completion_timeout` times out, `kfree(qp)` is executed while refcount is still non-zero. When the entity holding the reference eventually drops it (or accesses `qp`), memory corruption / UAF occurs.
- **Denial of Service:** Guaranteed DoS: 50-second hang of RDS shutdown worker (`wait_for_completion_timeout`), CPU softlockup warning, followed by UAF / crash.
- **Reachability / Privileges:**
- How is RDS / RXE reached?
- Does unprivileged user have access to AF_RDS sockets? (`socket(AF_RDS, ...)`).
- Does RXE require `rdma link add` (which requires CAP_NET_ADMIN)?
- Can RDS trigger connections or can incoming network traffic trigger this?
- Need to check capability checks on RDS socket creation and RDMA/RXE device creation.
---
### 4. Critical File Paths and Code Details
* `drivers/infiniband/sw/rxe/rxe_pool.c`:
- `__rxe_cleanup()` (lines 177-236):
```c
xa_ret = xa_erase(xa, elem->index);
__rxe_put(elem);
if (sleepable) {
if (!completion_done(&elem->complete)) {
ret = wait_for_completion_timeout(&elem->complete,
msecs_to_jiffies(50000));
if (WARN_ON(!ret))
err = -ETIMEDOUT;
}
}
if (pool->cleanup)
pool->cleanup(elem);
```
* `drivers/infiniband/sw/rxe/rxe_verbs.c`:
- `rxe_destroy_qp()` (lines 650-670): ignores `rxe_cleanup()` error return and returns 0.
* `drivers/infiniband/core/verbs.c`:
- `ib_destroy_qp_user()` (lines 2182, 2204): calls `qp->device->ops.destroy_qp(qp, udata)`. If 0 returned, executes `kfree(qp);`.
* `net/rds/af_rds.c` & `net/rds/connection.c` & `net/rds/ib_cm.c`:
- Need to check socket creation permissions for `AF_RDS`.
---
### 5. Potential Reasoning Loops / Tool Redundancy Warning
- Avoid repeatedly searching for general `while` loops across the entire tree; 656 lines of `while` was overwhelming and mostly irrelevant.
- Focus specifically on:
1. Accessibility: who can open RDS sockets, configure RXE devices, and trigger connection shutdown?
2. The exact mechanism of the leak/hang (is `AF_RDS` restricted to unprivileged users? Does RXE require root to set up interfaces?).
---
### 6. Next Steps
1. Check accessibility of `AF_RDS` socket creation: inspect `rds_create()` in `net/rds/af_rds.c` to see if unprivileged users can open `socket(AF_RDS, SOCK_SEQPACKET, 0)` without capabilities.
2. Check how RXE devices are created: does it require `rdma link add ... type rxe` (which requires `CAP_NET_ADMIN`) or are they auto-created or present in configs?
3. Check `ns_capable` / `capable` in RDS and RXE setup.
4. Check whether ingress network Ethernet packets (remote trigger) can trigger this via RDS over RXE.
5. Determine whether `kfree(qp)` with remaining references constitutes Use-After-Free (exploitable memory safety issue).
6. Fill in the dimensions and invoke `set-results`.
Tokens:
input: 106872
output: 3036
thoughts: 0
|
| 103/2 |
2026/10/21 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 49686
output: 123
thoughts: 735
Thoughts: **My Thought Process on the Security Analysis Dimensions**
Alright, I need to take a step back and systematically break down the security implications of this bug. I've already grasped the core technical mechanism and its immediate consequences, which is a solid foundation.
First, I need to solidify my understanding of the bug's lifecycle. I'm looking at `__rxe_cleanup` within `drivers/infiniband/sw/rxe/rxe_pool.c`. The critical path here is when `rxe_destroy_qp` is invoked downstream from `rds_ib_conn_path_shutdown`, `rdma_destroy_qp`, and `ib_destroy_qp_user`. What happens is `__rxe_cleanup` removes the Qualified Packet (QP) from the pool's xarray and decrements its initial reference count (`__rxe_put(elem)`). Then, it enters a waiting loop, specifically `wait_for_completion_timeout(&elem->complete, msecs_to_jiffies(50000))`, aiming to ensure all other references to this QP have been released before proceeding.
The problem arises when this wait times out. I've identified several scenarios where a reference could remain: a stuck or busy `rxe_wq` task, a system-wide `SOFTLOCKUP` indicated by `Tainted: [L]=SOFTLOCKUP`, an undrained packet residing in `req_pkts` or `resp_pkts`, or an ongoing `skb` transmission managed by `rxe_skb_tx_dtor`. When this timeout occurs, the function `WARN_ON(!ret)` is triggered, and an error `err = -ETIMEDOUT` is set.
The truly insidious part is that even after this timeout and error, `__rxe_cleanup` *doesn't stop*. It proceeds to call `pool->cleanup(elem)`, which is `rxe_qp_cleanup`. More critically, the calling function, `rxe_destroy_qp`, *ignores the return value* of `rxe_cleanup(qp)` and, bewilderingly, returns `0` to `ib_destroy_qp_user`. This leads to `ib_destroy_qp_user` (found in `drivers/infiniband/core/verbs.c`) proceeding to call `kfree(qp)`. At this point, outstanding references to the `qp` still exist β perhaps within an `skb` destructor like `rxe_skb_tx_dtor`, a queued packet, or a running `rxe_task`. When any of these components subsequently try to access the `qp` or call `rxe_put(qp)`, they will encounter a **Use-After-Free (UAF)** on the `struct rxe_qp`. This is the core vulnerability.
Now, to fully assess the security posture, I need to dive into the *accessibility* and *trigger* dimensions. This means understanding how an attacker could actually initiate this sequence of events.
First, I need to examine `net/rds/af_rds.c`. My primary question here is: Can an unprivileged user, without elevated privileges, create an `AF_RDS` socket and then successfully trigger RDS connections? This is a key pathway to user-space interaction.
Second, I'll be looking at `drivers/infiniband/sw/rxe/rxe_net.c` and `drivers/infiniband/core/nldev.c`. I need to understand the mechanics of creating an RXE device itself. Specifically, how is it done? Is it via `rdma link add ... type rxe`? And what capabilities are required for this? Is the RXE device aware of network namespaces, or is it confined to the `init_net` namespace, effectively requiring `CAP_NET_ADMIN` to configure? This will tell me about the privilege requirements for setting up the vulnerable component.
Finally, I need to consider the possibility of external network triggers. Can ingress network traffic β specifically Ethernet frames destined for RoCEv2 UDP port 4791 β actually trigger this UAF if RDS and RXE are active and configured on the system? This would be a particularly concerning attack vector if exploitable without prior system access.
To achieve this, I plan to analyze `net/rds/af_rds.c` around the `rds_create` function and `drivers/infiniband/core/nldev.c` around the `nldev_newlink` function in a consolidated effort. This will allow me to map out the creation and connection pathways for RDS and RXE.
|
| 104/2 |
2026/10/21 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/rds/af_rds.c Name:rds_create]
Results: map[SourceCode: 704: static int rds_create(struct net *net, struct socket *sock, int protocol,
705: int kern)
706: {
707: struct sock *sk;
708:
709: if (sock->type != SOCK_SEQPACKET || protocol)
710: return -ESOCKTNOSUPPORT;
711:
712: sk = sk_alloc(net, AF_RDS, GFP_KERNEL, &rds_proto, kern);
713: if (!sk)
714: return -ENOMEM;
715:
716: return __rds_create(sock, sk, protocol);
717: }
SourceFile:net/rds/af_rds.c]
|
| 105/2 |
2026/10/21 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/infiniband/core/nldev.c Name:nldev_newlink]
Results: map[SourceCode:1818: static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
1819: struct netlink_ext_ack *extack)
1820: {
1821: struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
1822: char ibdev_name[IB_DEVICE_NAME_MAX];
1823: const struct rdma_link_ops *ops;
1824: char ndev_name[IFNAMSIZ];
1825: struct net_device *ndev;
1826: char type[IFNAMSIZ];
1827: int err;
1828:
1829: err = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
1830: nldev_policy, extack);
1831: if (err || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
1832: !tb[RDMA_NLDEV_ATTR_LINK_TYPE] || !tb[RDMA_NLDEV_ATTR_NDEV_NAME])
1833: return -EINVAL;
1834:
1835: nla_strscpy(ibdev_name, tb[RDMA_NLDEV_ATTR_DEV_NAME],
1836: sizeof(ibdev_name));
1837: if (strchr(ibdev_name, '%') || strlen(ibdev_name) == 0)
1838: return -EINVAL;
1839:
1840: nla_strscpy(type, tb[RDMA_NLDEV_ATTR_LINK_TYPE], sizeof(type));
1841: nla_strscpy(ndev_name, tb[RDMA_NLDEV_ATTR_NDEV_NAME],
1842: sizeof(ndev_name));
1843:
1844: ndev = dev_get_by_name(sock_net(skb->sk), ndev_name);
1845: if (!ndev)
1846: return -ENODEV;
1847:
1848: down_read(&link_ops_rwsem);
1849: ops = link_ops_get(type);
1850: #ifdef CONFIG_MODULES
1851: if (!ops) {
1852: up_read(&link_ops_rwsem);
1853: request_module("rdma-link-%s", type);
1854: down_read(&link_ops_rwsem);
1855: ops = link_ops_get(type);
1856: }
1857: #endif
1858: err = ops ? ops->newlink(ibdev_name, ndev) : -EINVAL;
1859: up_read(&link_ops_rwsem);
1860: dev_put(ndev);
1861:
1862: return err;
1863: }
SourceFile:drivers/infiniband/core/nldev.c]
|
| 106/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:net/rds/ib.c FirstLine:1 LineCount:100]
Results: map[Contents: 1: /*
2: * Copyright (c) 2006, 2019 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This software is available to you under a choice of one of two
5: * licenses. You may choose to be licensed under the terms of the GNU
6: * General Public License (GPL) Version 2, available from the file
7: * COPYING in the main directory of this source tree, or the
8: * OpenIB.org BSD license below:
9: *
10: * Redistribution and use in source and binary forms, with or
11: * without modification, are permitted provided that the following
12: * conditions are met:
13: *
14: * - Redistributions of source code must retain the above
15: * copyright notice, this list of conditions and the following
16: * disclaimer.
17: *
18: * - Redistributions in binary form must reproduce the above
19: * copyright notice, this list of conditions and the following
20: * disclaimer in the documentation and/or other materials
21: * provided with the distribution.
22: *
23: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26: * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27: * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28: * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29: * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30: * SOFTWARE.
31: *
32: */
33: #include <linux/kernel.h>
34: #include <linux/in.h>
35: #include <linux/if.h>
36: #include <linux/netdevice.h>
37: #include <linux/inetdevice.h>
38: #include <linux/if_arp.h>
39: #include <linux/delay.h>
40: #include <linux/slab.h>
41: #include <linux/module.h>
42: #include <net/addrconf.h>
43:
44: #include "rds_single_path.h"
45: #include "rds.h"
46: #include "ib.h"
47: #include "ib_mr.h"
48:
49: static unsigned int rds_ib_mr_1m_pool_size = RDS_MR_1M_POOL_SIZE;
50: static unsigned int rds_ib_mr_8k_pool_size = RDS_MR_8K_POOL_SIZE;
51: unsigned int rds_ib_retry_count = RDS_IB_DEFAULT_RETRY_COUNT;
52: static atomic_t rds_ib_unloading;
53:
54: module_param(rds_ib_mr_1m_pool_size, int, 0444);
55: MODULE_PARM_DESC(rds_ib_mr_1m_pool_size, " Max number of 1M mr per HCA");
56: module_param(rds_ib_mr_8k_pool_size, int, 0444);
57: MODULE_PARM_DESC(rds_ib_mr_8k_pool_size, " Max number of 8K mr per HCA");
58: module_param(rds_ib_retry_count, int, 0444);
59: MODULE_PARM_DESC(rds_ib_retry_count, " Number of hw retries before reporting an error");
60:
61: /*
62: * we have a clumsy combination of RCU and a rwsem protecting this list
63: * because it is used both in the get_mr fast path and while blocking in
64: * the FMR flushing path.
65: */
66: DECLARE_RWSEM(rds_ib_devices_lock);
67: struct list_head rds_ib_devices;
68:
69: /* NOTE: if also grabbing ibdev lock, grab this first */
70: DEFINE_SPINLOCK(ib_nodev_conns_lock);
71: LIST_HEAD(ib_nodev_conns);
72:
73: static void rds_ib_nodev_connect(void)
74: {
75: struct rds_ib_connection *ic;
76:
77: spin_lock(&ib_nodev_conns_lock);
78: list_for_each_entry(ic, &ib_nodev_conns, ib_node)
79: rds_conn_connect_if_down(ic->conn);
80: spin_unlock(&ib_nodev_conns_lock);
81: }
82:
83: static void rds_ib_dev_shutdown(struct rds_ib_device *rds_ibdev)
84: {
85: struct rds_ib_connection *ic;
86: unsigned long flags;
87:
88: spin_lock_irqsave(&rds_ibdev->spinlock, flags);
89: list_for_each_entry(ic, &rds_ibdev->conn_list, ib_node)
90: rds_conn_path_drop(&ic->conn->c_path[0], true);
91: spin_unlock_irqrestore(&rds_ibdev->spinlock, flags);
92: }
93:
94: /*
95: * rds_ib_destroy_mr_pool() blocks on a few things and mrs drop references
96: * from interrupt context so we push freing off into a work struct in krdsd.
97: */
98: static void rds_ib_dev_free(struct work_struct *work)
99: {
100: struct rds_ib_ipaddr *i_ipaddr, *i_next;
]
|
| 107/2 |
2026/10/21 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 53298
output: 95
thoughts: 114
Thoughts: **Investigating Netlink Permissions and RXE Device Creation**
My current line of inquiry is focused on understanding the intricacies of netlink permissions, specifically concerning the `nldev_newlink` operation within the `drivers/infiniband/core/nldev.c` file. I need to meticulously examine the netlink permissions associated with this particular operation to ascertain its security implications and how it might be leveraged.
Concurrently, I am keen to explore the mechanisms by which `rxe` (RDMA-CM over Ethernet) devices can be instantiated. My immediate thought is to investigate whether this device creation is primarily driven by the `rxe_param_set_add` function or if `nldev_newlink` plays a more direct role. To gain a comprehensive understanding, I plan to delve into the code, specifically reading lines 2500-2620 of `drivers/infiniband/core/nldev.c` and subsequently examining the relevant code within `drivers/infiniband/sw/rxe/rxe.c`. This dual approach will allow me to connect the netlink interface with the underlying `rxe` device management logic.
|
| 108/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/nldev.c FirstLine:2500 LineCount:120]
Results: map[Contents:2500: goto err_msg;
2501: }
2502:
2503: if ((mode == RDMA_COUNTER_MODE_AUTO) &&
2504: nla_put_u8(msg, RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED, opcnt)) {
2505: ret = -EMSGSIZE;
2506: goto err_msg;
2507: }
2508:
2509: nlmsg_end(msg, nlh);
2510: ib_device_put(device);
2511: return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);
2512:
2513: err_msg:
2514: nlmsg_free(msg);
2515: err:
2516: ib_device_put(device);
2517: return ret;
2518: }
2519:
2520: static int nldev_stat_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
2521: struct netlink_ext_ack *extack)
2522: {
2523: struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
2524: int ret;
2525:
2526: ret = __nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
2527: nldev_policy, NL_VALIDATE_LIBERAL, extack);
2528: if (ret)
2529: return -EINVAL;
2530:
2531: if (!tb[RDMA_NLDEV_ATTR_STAT_RES])
2532: return stat_get_doit_default_counter(skb, nlh, extack, tb);
2533:
2534: switch (nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_RES])) {
2535: case RDMA_NLDEV_ATTR_RES_QP:
2536: ret = stat_get_doit_qp(skb, nlh, extack, tb);
2537: break;
2538: case RDMA_NLDEV_ATTR_RES_MR:
2539: ret = res_get_common_doit(skb, nlh, extack, RDMA_RESTRACK_MR,
2540: fill_stat_mr_entry);
2541: break;
2542: default:
2543: ret = -EINVAL;
2544: break;
2545: }
2546:
2547: return ret;
2548: }
2549:
2550: static int nldev_stat_get_dumpit(struct sk_buff *skb,
2551: struct netlink_callback *cb)
2552: {
2553: struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
2554: int ret;
2555:
2556: ret = __nlmsg_parse(cb->nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
2557: nldev_policy, NL_VALIDATE_LIBERAL, NULL);
2558: if (ret || !tb[RDMA_NLDEV_ATTR_STAT_RES])
2559: return -EINVAL;
2560:
2561: switch (nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_RES])) {
2562: case RDMA_NLDEV_ATTR_RES_QP:
2563: ret = nldev_res_get_counter_dumpit(skb, cb);
2564: break;
2565: case RDMA_NLDEV_ATTR_RES_MR:
2566: ret = res_get_common_dumpit(skb, cb, RDMA_RESTRACK_MR,
2567: fill_stat_mr_entry);
2568: break;
2569: default:
2570: ret = -EINVAL;
2571: break;
2572: }
2573:
2574: return ret;
2575: }
2576:
2577: static int nldev_stat_get_counter_status_doit(struct sk_buff *skb,
2578: struct nlmsghdr *nlh,
2579: struct netlink_ext_ack *extack)
2580: {
2581: struct nlattr *tb[RDMA_NLDEV_ATTR_MAX], *table, *entry;
2582: struct rdma_hw_stats *stats;
2583: struct ib_device *device;
2584: struct sk_buff *msg;
2585: u32 devid, port;
2586: int ret, i;
2587:
2588: ret = __nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
2589: nldev_policy, NL_VALIDATE_LIBERAL, extack);
2590: if (ret || !tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
2591: !tb[RDMA_NLDEV_ATTR_PORT_INDEX])
2592: return -EINVAL;
2593:
2594: devid = nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
2595: device = ib_device_get_by_index(sock_net(skb->sk), devid);
2596: if (!device)
2597: return -EINVAL;
2598:
2599: port = nla_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
]
|
| 109/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe.c FirstLine:200 LineCount:150]
Results: map[Contents: 200:
201: port->attr.active_mtu = mtu;
202: port->mtu_cap = ib_mtu_enum_to_int(mtu);
203: }
204:
205: static struct rdma_link_ops rxe_link_ops;
206:
207: /* called by ifc layer to create new rxe device.
208: * The caller should allocate memory for rxe by calling ib_alloc_device.
209: */
210: int rxe_add(struct rxe_dev *rxe, unsigned int mtu, const char *ibdev_name,
211: struct net_device *ndev)
212: {
213: rxe_init(rxe, ndev);
214: rxe_set_mtu(rxe, mtu);
215: rxe->ib_dev.link_ops = &rxe_link_ops;
216:
217: return rxe_register_device(rxe, ibdev_name, ndev);
218: }
219:
220: static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)
221: {
222: struct rxe_dev *rxe;
223: int err = 0;
224:
225: if (is_vlan_dev(ndev)) {
226: rxe_err("rxe creation allowed on top of a real device only\n");
227: err = -EPERM;
228: goto err;
229: }
230:
231: rxe = rxe_get_dev_from_net(ndev);
232: if (rxe) {
233: ib_device_put(&rxe->ib_dev);
234: rxe_err_dev(rxe, "already configured on %s\n", ndev->name);
235: err = -EEXIST;
236: goto err;
237: }
238:
239: err = rxe_net_init(ndev);
240: if (err)
241: return err;
242:
243: err = rxe_net_add(ibdev_name, ndev);
244: if (err) {
245: rxe_err("failed to add %s\n", ndev->name);
246: goto err;
247: }
248: err:
249: return err;
250: }
251:
252: static int rxe_dellink(struct ib_device *dev)
253: {
254: rxe_net_del(dev);
255:
256: return 0;
257: }
258:
259: static struct rdma_link_ops rxe_link_ops = {
260: .type = "rxe",
261: .newlink = rxe_newlink,
262: .dellink = rxe_dellink,
263: };
264:
265: static int __init rxe_module_init(void)
266: {
267: int err;
268:
269: err = rxe_alloc_wq();
270: if (err)
271: return err;
272:
273: err = rxe_namespace_init();
274: if (err)
275: goto err_destroy_wq;
276:
277: err = rxe_register_notifier();
278: if (err)
279: goto err_namespace_exit;
280:
281: rdma_link_register(&rxe_link_ops);
282:
283: pr_info("loaded\n");
284: return 0;
285:
286: err_namespace_exit:
287: rxe_namespace_exit();
288: err_destroy_wq:
289: rxe_destroy_wq();
290: return err;
291: }
292:
293: static void __exit rxe_module_exit(void)
294: {
295: rdma_link_unregister(&rxe_link_ops);
296: ib_unregister_driver(RDMA_DRIVER_RXE);
297: rxe_net_exit();
298: rxe_destroy_wq();
299:
]
|
| 110/2 |
2026/10/21 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 56526
output: 131
thoughts: 126
Thoughts: **My Thought Process Regarding Infiniband Netlink Device Creation Permissions**
Okay, so I've been looking into the mechanisms that govern the creation and management of Infiniband network devices, specifically focusing on the `RDMA_NLDEV_CMD_NEWLINK` command. My primary objective here is to understand how the system verifies the necessary capabilities, particularly `RDMA_NL_ADMIN_PERM`, before allowing a new link to be established. To do this, I've been examining the relevant code sections within the Linux kernel.
My investigation started with `drivers/infiniband/core/nldev.c`. I'm sifting through lines 2620 to 2750, which I anticipate will contain the core logic for handling the `RDMA_NLDEV_CMD_NEWLINK` command. I'm looking for the explicit checks that are performed here to ensure that the requesting process possesses the administrative privileges required. This would likely involve looking for calls to permission-checking functions or flags that are evaluated.
Concurrently, I'm also diving into `drivers/infiniband/core/netlink.c`. This file is crucial because it's the entry point for netlink messages, and `RDMA_NLDEV_CMD_NEWLINK` is a netlink command. My aim is to trace how this command is received and then passed to the appropriate handlers, and specifically to identify where the `RDMA_NL_ADMIN_PERM` capability check is integrated into this netlink processing pipeline. Is it checked at the netlink layer itself, or is it delegated to the `nldev.c` module?
Beyond just the command handling, I'm also deeply concerned about the underlying device node permissions. It's essential to know whether unprivileged users can even access or interact with `/dev/infiniband/uverbs*` devices in a way that might circumvent the intended administrative controls. This leads me to `drivers/infiniband/core/uverbs_main.c`. This is where the user-space interface to the Infiniband hardware is typically managed, and I'm scrutinizing it for how device node permissions and modes are set. I need to confirm if the default configuration allows broad access or if it's sufficiently restrictive to prevent unauthorized `NEWLINK` operations. My hypothesis is that a secure implementation would restrict direct access to these devices to privileged users or processes that have explicitly been granted permissions.
|
| 111/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/nldev.c FirstLine:2620 LineCount:130]
Results: map[Contents:2620: 0, 0);
2621:
2622: ret = -EMSGSIZE;
2623: if (!nlh || fill_nldev_handle(msg, device) ||
2624: nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port))
2625: goto err_msg;
2626:
2627: table = nla_nest_start(msg, RDMA_NLDEV_ATTR_STAT_HWCOUNTERS);
2628: if (!table)
2629: goto err_msg;
2630:
2631: mutex_lock(&stats->lock);
2632: for (i = 0; i < stats->num_counters; i++) {
2633: entry = nla_nest_start(msg,
2634: RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY);
2635: if (!entry)
2636: goto err_msg_table;
2637:
2638: if (nla_put_string(msg,
2639: RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME,
2640: stats->descs[i].name) ||
2641: nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_HWCOUNTER_INDEX, i))
2642: goto err_msg_entry;
2643:
2644: if ((stats->descs[i].flags & IB_STAT_FLAG_OPTIONAL) &&
2645: (nla_put_u8(msg, RDMA_NLDEV_ATTR_STAT_HWCOUNTER_DYNAMIC,
2646: !test_bit(i, stats->is_disabled))))
2647: goto err_msg_entry;
2648:
2649: nla_nest_end(msg, entry);
2650: }
2651: mutex_unlock(&stats->lock);
2652:
2653: nla_nest_end(msg, table);
2654: nlmsg_end(msg, nlh);
2655: ib_device_put(device);
2656: return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);
2657:
2658: err_msg_entry:
2659: nla_nest_cancel(msg, entry);
2660: err_msg_table:
2661: mutex_unlock(&stats->lock);
2662: nla_nest_cancel(msg, table);
2663: err_msg:
2664: nlmsg_free(msg);
2665: err:
2666: ib_device_put(device);
2667: return ret;
2668: }
2669:
2670: static int nldev_newdev(struct sk_buff *skb, struct nlmsghdr *nlh,
2671: struct netlink_ext_ack *extack)
2672: {
2673: struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
2674: enum rdma_nl_dev_type type;
2675: struct ib_device *parent;
2676: char name[IFNAMSIZ] = {};
2677: u32 parentid;
2678: int ret;
2679:
2680: ret = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
2681: nldev_policy, extack);
2682: if (ret || !tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
2683: !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_DEV_TYPE])
2684: return -EINVAL;
2685:
2686: nla_strscpy(name, tb[RDMA_NLDEV_ATTR_DEV_NAME], sizeof(name));
2687: type = nla_get_u8(tb[RDMA_NLDEV_ATTR_DEV_TYPE]);
2688: parentid = nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
2689: parent = ib_device_get_by_index(sock_net(skb->sk), parentid);
2690: if (!parent)
2691: return -EINVAL;
2692:
2693: ret = ib_add_sub_device(parent, type, name);
2694: ib_device_put(parent);
2695:
2696: return ret;
2697: }
2698:
2699: static int nldev_deldev(struct sk_buff *skb, struct nlmsghdr *nlh,
2700: struct netlink_ext_ack *extack)
2701: {
2702: struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
2703: struct ib_device *device;
2704: u32 devid;
2705: int ret;
2706:
2707: ret = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
2708: nldev_policy, extack);
2709: if (ret || !tb[RDMA_NLDEV_ATTR_DEV_INDEX])
2710: return -EINVAL;
2711:
2712: devid = nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
2713: device = ib_device_get_by_index(sock_net(skb->sk), devid);
2714: if (!device)
2715: return -EINVAL;
2716:
2717: return ib_del_sub_device_and_put(device);
2718: }
2719:
]
|
| 112/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/netlink.c FirstLine:150 LineCount:100]
Results: map[Contents: 150: EXPORT_SYMBOL(ibnl_put_attr);
151:
152: static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
153: struct netlink_ext_ack *extack)
154: {
155: int type = nlh->nlmsg_type;
156: unsigned int index = RDMA_NL_GET_CLIENT(type);
157: unsigned int op = RDMA_NL_GET_OP(type);
158: const struct rdma_nl_cbs *cb_table;
159: int err = -EINVAL;
160:
161: if (!is_nl_msg_valid(index, op))
162: return -EINVAL;
163:
164: down_read(&rdma_nl_types[index].sem);
165: cb_table = get_cb_table(skb, index, op);
166: if (!cb_table)
167: goto done;
168:
169: if ((cb_table[op].flags & RDMA_NL_ADMIN_PERM) &&
170: !netlink_capable(skb, CAP_NET_ADMIN)) {
171: err = -EPERM;
172: goto done;
173: }
174:
175: /*
176: * LS responses overload the 0x100 (NLM_F_ROOT) flag. Don't
177: * mistakenly call the .dump() function.
178: */
179: if (index == RDMA_NL_LS) {
180: if (cb_table[op].doit)
181: err = cb_table[op].doit(skb, nlh, extack);
182: goto done;
183: }
184: /* FIXME: Convert IWCM to properly handle doit callbacks */
185: if ((nlh->nlmsg_flags & NLM_F_DUMP) || index == RDMA_NL_IWCM) {
186: struct netlink_dump_control c = {
187: .dump = cb_table[op].dump,
188: };
189: if (c.dump)
190: err = netlink_dump_start(skb->sk, skb, nlh, &c);
191: goto done;
192: }
193:
194: if (cb_table[op].doit)
195: err = cb_table[op].doit(skb, nlh, extack);
196: done:
197: up_read(&rdma_nl_types[index].sem);
198: return err;
199: }
200:
201: /*
202: * This function is similar to netlink_rcv_skb with one exception:
203: * It calls to the callback for the netlink messages without NLM_F_REQUEST
204: * flag. These messages are intended for RDMA_NL_LS consumer, so it is allowed
205: * for that consumer only.
206: */
207: static int rdma_nl_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
208: struct nlmsghdr *,
209: struct netlink_ext_ack *))
210: {
211: struct netlink_ext_ack extack = {};
212: struct nlmsghdr *nlh;
213: int err;
214:
215: while (skb->len >= nlmsg_total_size(0)) {
216: int msglen;
217:
218: nlh = nlmsg_hdr(skb);
219: err = 0;
220:
221: if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len)
222: return 0;
223:
224: /*
225: * Generally speaking, the only requests are handled
226: * by the kernel, but RDMA_NL_LS is different, because it
227: * runs backward netlink scheme. Kernel initiates messages
228: * and waits for reply with data to keep pathrecord cache
229: * in sync.
230: */
231: if (!(nlh->nlmsg_flags & NLM_F_REQUEST) &&
232: (RDMA_NL_GET_CLIENT(nlh->nlmsg_type) != RDMA_NL_LS))
233: goto ack;
234:
235: /* Skip control messages */
236: if (nlh->nlmsg_type < NLMSG_MIN_TYPE)
237: goto ack;
238:
239: err = cb(skb, nlh, &extack);
240: if (err == -EINTR)
241: goto skip;
242:
243: ack:
244: if (nlh->nlmsg_flags & NLM_F_ACK || err)
245: netlink_ack(skb, nlh, err, &extack);
246:
247: skip:
248: msglen = NLMSG_ALIGN(nlh->nlmsg_len);
249: if (msglen > skb->len)
]
|
| 113/2 |
2026/10/21 02:06 |
tool |
grepper |
0m
Args: map[Expression:devnode|MODE|0666 PathPrefixes:[drivers/infiniband/core/]]
Results: map[Output:
Full output is too long, showing 200 out of 262 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (10 files in total):
drivers/infiniband/core/cache.c:2
drivers/infiniband/core/core_priv.h:2
drivers/infiniband/core/counters.c:21
drivers/infiniband/core/nldev.c:24
drivers/infiniband/core/roce_gid_mgmt.c:3
drivers/infiniband/core/ucaps.c:2
drivers/infiniband/core/ucma.c:1
drivers/infiniband/core/user_mad.c:2
drivers/infiniband/core/uverbs_cmd.c:1
drivers/infiniband/core/uverbs_main.c:3
drivers/infiniband/core/cache.c=823=void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u32 port,
--
drivers/infiniband/core/cache.c-844-
drivers/infiniband/core/cache.c:845: if (mode == IB_CACHE_GID_DEFAULT_MODE_SET) {
drivers/infiniband/core/cache.c-846- make_default_gid(ndev, &gid);
--
drivers/infiniband/core/cache.c-848- &gid_attr, mask, true);
drivers/infiniband/core/cache.c:849: } else if (mode == IB_CACHE_GID_DEFAULT_MODE_DELETE) {
drivers/infiniband/core/cache.c-850- _ib_cache_gid_del(ib_dev, port, &gid,
--
drivers/infiniband/core/core_priv.h=123=enum ib_cache_gid_default_mode {
drivers/infiniband/core/core_priv.h:124: IB_CACHE_GID_DEFAULT_MODE_SET,
drivers/infiniband/core/core_priv.h:125: IB_CACHE_GID_DEFAULT_MODE_DELETE
drivers/infiniband/core/core_priv.h-126-};
--
drivers/infiniband/core/counters.c-10-
drivers/infiniband/core/counters.c:11:#define ALL_AUTO_MODE_MASKS (RDMA_COUNTER_MASK_QP_TYPE | RDMA_COUNTER_MASK_PID)
drivers/infiniband/core/counters.c-12-
drivers/infiniband/core/counters.c=13=static int __counter_set_mode(struct rdma_port_counter *port_counter,
--
drivers/infiniband/core/counters.c-17-{
drivers/infiniband/core/counters.c:18: if (new_mode == RDMA_COUNTER_MODE_AUTO) {
drivers/infiniband/core/counters.c:19: if (new_mask & (~ALL_AUTO_MODE_MASKS))
drivers/infiniband/core/counters.c-20- return -EINVAL;
--
drivers/infiniband/core/counters.c=44=int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port,
--
drivers/infiniband/core/counters.c-58- if (mask)
drivers/infiniband/core/counters.c:59: mode = RDMA_COUNTER_MODE_AUTO;
drivers/infiniband/core/counters.c-60- else
drivers/infiniband/core/counters.c:61: mode = (port_counter->num_counters) ? RDMA_COUNTER_MODE_MANUAL :
drivers/infiniband/core/counters.c:62: RDMA_COUNTER_MODE_NONE;
drivers/infiniband/core/counters.c-63-
--
drivers/infiniband/core/counters.c=82=static void auto_mode_init_counter(struct rdma_counter *counter,
--
drivers/infiniband/core/counters.c-87-
drivers/infiniband/core/counters.c:88: counter->mode.mode = RDMA_COUNTER_MODE_AUTO;
drivers/infiniband/core/counters.c-89- counter->mode.mask = new_mask;
--
drivers/infiniband/core/counters.c=145=static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
--
drivers/infiniband/core/counters.c-173- switch (mode) {
drivers/infiniband/core/counters.c:174: case RDMA_COUNTER_MODE_MANUAL:
drivers/infiniband/core/counters.c:175: ret = __counter_set_mode(port_counter, RDMA_COUNTER_MODE_MANUAL,
drivers/infiniband/core/counters.c-176- 0, bind_opcnt);
--
drivers/infiniband/core/counters.c-181- break;
drivers/infiniband/core/counters.c:182: case RDMA_COUNTER_MODE_AUTO:
drivers/infiniband/core/counters.c-183- auto_mode_init_counter(counter, qp, port_counter->mode.mask);
--
drivers/infiniband/core/counters.c-210- if (!port_counter->num_counters &&
drivers/infiniband/core/counters.c:211: port_counter->mode.mode == RDMA_COUNTER_MODE_MANUAL)
drivers/infiniband/core/counters.c:212: __counter_set_mode(port_counter, RDMA_COUNTER_MODE_NONE, 0,
drivers/infiniband/core/counters.c-213- false);
--
drivers/infiniband/core/counters.c=223=static void rdma_counter_free(struct rdma_counter *counter)
--
drivers/infiniband/core/counters.c-230- if (!port_counter->num_counters &&
drivers/infiniband/core/counters.c:231: (port_counter->mode.mode == RDMA_COUNTER_MODE_MANUAL))
drivers/infiniband/core/counters.c:232: __counter_set_mode(port_counter, RDMA_COUNTER_MODE_NONE, 0,
drivers/infiniband/core/counters.c-233- false);
--
drivers/infiniband/core/counters.c=340=int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port)
--
drivers/infiniband/core/counters.c-353- port_counter = &dev->port_data[port].port_counter;
drivers/infiniband/core/counters.c:354: if (port_counter->mode.mode != RDMA_COUNTER_MODE_AUTO)
drivers/infiniband/core/counters.c-355- return 0;
--
drivers/infiniband/core/counters.c-364- } else {
drivers/infiniband/core/counters.c:365: counter = alloc_and_bind(dev, port, qp, RDMA_COUNTER_MODE_AUTO,
drivers/infiniband/core/counters.c-366- port_counter->mode.bind_opcnt);
--
drivers/infiniband/core/counters.c=503=int rdma_counter_bind_qpn(struct ib_device *dev, u32 port,
--
drivers/infiniband/core/counters.c-511- port_counter = &dev->port_data[port].port_counter;
drivers/infiniband/core/counters.c:512: if (port_counter->mode.mode == RDMA_COUNTER_MODE_AUTO)
drivers/infiniband/core/counters.c-513- return -EINVAL;
--
drivers/infiniband/core/counters.c=553=int rdma_counter_bind_qpn_alloc(struct ib_device *dev, u32 port,
--
drivers/infiniband/core/counters.c-567-
drivers/infiniband/core/counters.c:568: if (port_counter->mode.mode == RDMA_COUNTER_MODE_AUTO)
drivers/infiniband/core/counters.c-569- return -EINVAL;
--
drivers/infiniband/core/counters.c-579-
drivers/infiniband/core/counters.c:580: counter = alloc_and_bind(dev, port, qp, RDMA_COUNTER_MODE_MANUAL, true);
drivers/infiniband/core/counters.c-581- if (!counter) {
--
drivers/infiniband/core/counters.c=600=int rdma_counter_unbind_qpn(struct ib_device *dev, u32 port,
--
drivers/infiniband/core/counters.c-620- if (!qp->counter || qp->counter->id != counter_id ||
drivers/infiniband/core/counters.c:621: port_counter->mode.mode != RDMA_COUNTER_MODE_MANUAL) {
drivers/infiniband/core/counters.c-622- ret = -EINVAL;
--
drivers/infiniband/core/counters.c=648=void rdma_counter_init(struct ib_device *dev)
--
drivers/infiniband/core/counters.c-657- port_counter = &dev->port_data[port].port_counter;
drivers/infiniband/core/counters.c:658: port_counter->mode.mode = RDMA_COUNTER_MODE_NONE;
drivers/infiniband/core/counters.c-659- mutex_init(&port_counter->lock);
--
drivers/infiniband/core/nldev.c=62=static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
--
drivers/infiniband/core/nldev.c-153- [RDMA_NLDEV_ATTR_SUBNET_PREFIX] = { .type = NLA_U64 },
drivers/infiniband/core/nldev.c:154: [RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK] = { .type = NLA_U32 },
drivers/infiniband/core/nldev.c:155: [RDMA_NLDEV_ATTR_STAT_MODE] = { .type = NLA_U32 },
drivers/infiniband/core/nldev.c-156- [RDMA_NLDEV_ATTR_STAT_RES] = { .type = NLA_U32 },
--
drivers/infiniband/core/nldev.c-166- [RDMA_NLDEV_NET_NS_FD] = { .type = NLA_U32 },
drivers/infiniband/core/nldev.c:167: [RDMA_NLDEV_SYS_ATTR_NETNS_MODE] = { .type = NLA_U8 },
drivers/infiniband/core/nldev.c-168- [RDMA_NLDEV_SYS_ATTR_COPY_ON_FORK] = { .type = NLA_U8 },
--
drivers/infiniband/core/nldev.c-170- [RDMA_NLDEV_ATTR_STAT_HWCOUNTER_DYNAMIC] = { .type = NLA_U8 },
drivers/infiniband/core/nldev.c:171: [RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE] = { .type = NLA_U8 },
drivers/infiniband/core/nldev.c-172- [RDMA_NLDEV_ATTR_DRIVER_DETAILS] = { .type = NLA_U8 },
--
drivers/infiniband/core/nldev.c=950=static int fill_stat_counter_mode(struct sk_buff *msg,
--
drivers/infiniband/core/nldev.c-954-
drivers/infiniband/core/nldev.c:955: if (nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_MODE, m->mode))
drivers/infiniband/core/nldev.c-956- return -EMSGSIZE;
drivers/infiniband/core/nldev.c-957-
drivers/infiniband/core/nldev.c:958: if (m->mode == RDMA_COUNTER_MODE_AUTO) {
drivers/infiniband/core/nldev.c-959- if ((m->mask & RDMA_COUNTER_MASK_QP_TYPE) &&
--
drivers/infiniband/core/nldev.c=1994=static int nldev_sys_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
--
drivers/infiniband/core/nldev.c-2018-
drivers/infiniband/core/nldev.c:2019: err = nla_put_u8(msg, RDMA_NLDEV_SYS_ATTR_NETNS_MODE,
drivers/infiniband/core/nldev.c-2020- (u8)ib_devices_shared_netns);
--
drivers/infiniband/core/nldev.c-2025-
drivers/infiniband/core/nldev.c:2026: err = nla_put_u8(msg, RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE,
drivers/infiniband/core/nldev.c-2027- (u8)privileged_qkey);
--
drivers/infiniband/core/nldev.c-2032-
drivers/infiniband/core/nldev.c:2033: err = nla_put_u8(msg, RDMA_NLDEV_SYS_ATTR_MONITOR_MODE, 1);
drivers/infiniband/core/nldev.c-2034- if (err) {
--
drivers/infiniband/core/nldev.c=2054=static int nldev_set_sys_set_netns_doit(struct nlattr *tb[])
--
drivers/infiniband/core/nldev.c-2058-
drivers/infiniband/core/nldev.c:2059: enable = nla_get_u8(tb[RDMA_NLDEV_SYS_ATTR_NETNS_MODE]);
drivers/infiniband/core/nldev.c-2060- /* Only 0 and 1 are supported */
--
drivers/infiniband/core/nldev.c=2068=static int nldev_set_sys_set_pqkey_doit(struct nlattr *tb[])
--
drivers/infiniband/core/nldev.c-2071-
drivers/infiniband/core/nldev.c:2072: enable = nla_get_u8(tb[RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE]);
drivers/infiniband/core/nldev.c-2073- /* Only 0 and 1 are supported */
--
drivers/infiniband/core/nldev.c=2081=static int nldev_set_sys_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
--
drivers/infiniband/core/nldev.c-2091-
drivers/infiniband/core/nldev.c:2092: if (tb[RDMA_NLDEV_SYS_ATTR_NETNS_MODE])
drivers/infiniband/core/nldev.c-2093- return nldev_set_sys_set_netns_doit(tb);
drivers/infiniband/core/nldev.c-2094-
drivers/infiniband/core/nldev.c:2095: if (tb[RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE])
drivers/infiniband/core/nldev.c-2096- return nldev_set_sys_set_pqkey_doit(tb);
--
drivers/infiniband/core/nldev.c=2102=static int nldev_stat_set_mode_doit(struct sk_buff *msg,
--
drivers/infiniband/core/nldev.c-2119-
drivers/infiniband/core/nldev.c:2120: mode = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_MODE]);
drivers/infiniband/core/nldev.c:2121: if (mode == RDMA_COUNTER_MODE_AUTO) {
drivers/infiniband/core/nldev.c:2122: if (tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK])
drivers/infiniband/core/nldev.c-2123- mask = nla_get_u32(
drivers/infiniband/core/nldev.c:2124: tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK]);
drivers/infiniband/core/nldev.c-2125- return rdma_counter_set_auto_mode(device, port, mask, opcnt,
--
drivers/infiniband/core/nldev.c=2207=static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
--
drivers/infiniband/core/nldev.c-2232-
drivers/infiniband/core/nldev.c:2233: if (!tb[RDMA_NLDEV_ATTR_STAT_MODE] &&
drivers/infiniband/core/nldev.c-2234- !tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS]) {
--
drivers/infiniband/core/nldev.c-2253-
drivers/infiniband/core/nldev.c:2254: if (tb[RDMA_NLDEV_ATTR_STAT_MODE]) {
drivers/infiniband/core/nldev.c-2255- ret = nldev_stat_set_mode_doit(msg, extack, tb, device, port);
--
drivers/infiniband/core/nldev.c=2441=stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,
--
drivers/infiniband/core/nldev.c-2455-
drivers/infiniband/core/nldev.c:2456: if (!tb[RDMA_NLDEV_ATTR_STAT_MODE] ||
drivers/infiniband/core/nldev.c-2457- !tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_PORT_INDEX])
--
drivers/infiniband/core/nldev.c-2491- nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port) ||
drivers/infiniband/core/nldev.c:2492: nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_MODE, mode)) {
drivers/infiniband/core/nldev.c-2493- ret = -EMSGSIZE;
--
drivers/infiniband/core/nldev.c-2496-
drivers/infiniband/core/nldev.c:2497: if ((mode == RDMA_COUNTER_MODE_AUTO) &&
drivers/infiniband/core/nldev.c:2498: nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK, mask)) {
drivers/infiniband/core/nldev.c-2499- ret = -EMSGSIZE;
--
drivers/infiniband/core/nldev.c-2502-
drivers/infiniband/core/nldev.c:2503: if ((mode == RDMA_COUNTER_MODE_AUTO) &&
drivers/infiniband/core/nldev.c-2504- nla_put_u8(msg, RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED, opcnt)) {
--
drivers/infiniband/core/roce_gid_mgmt.c=297=static void bond_delete_netdev_default_gids(struct ib_device *ib_dev,
]
|
| 114/2 |
2026/10/21 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 65340
output: 94
thoughts: 60
Thoughts: **My Deep Dive into Infiniband Device and Uverbs Logic**
Alright, so I've been sifting through some core Infiniband code, specifically focusing on how the network layer devices are handled and how the user-space verbs interface (`uverbs`) is managed. My intention was to get a solid grasp on the critical logic within a particular range of lines in both `drivers/infiniband/core/nldev.c` and `drivers/infiniband/core/uverbs_main.c`.
In `drivers/infiniband/core/nldev.c`, from line 2720 to 2820, I was really zeroing in on the device-related operations. I wanted to understand the intricacies of how the Infiniband hardware is represented and managed at the kernel level. This likely involves looking at structures that define the device, how it's enumerated and registered, and perhaps the core functions that interact with the hardware itself β think initialization, state management, and how it's exposed to the rest of the Infiniband subsystem. My expectation here is to see how the kernel maps the physical hardware to a logical representation that can be utilized by the software stack. I'm particularly interested in any logic that deals with resource allocation or configuration for the device itself, as this is often a critical and complex area.
Then, I shifted my focus to `drivers/infiniband/core/uverbs_main.c`, specifically lines 1240 to 1310. This section, I anticipate, is where the magic happens for user-space interactions. The `uverbs` interface is the primary way user applications leverage Infiniband capabilities. I'm looking for the code that handles the establishment of connections, the creation of memory regions for data transfer (like RDMA), and the management of queue pairs (QPs) β the fundamental communication endpoints. The specific lines I'm examining probably cover some aspect of the `uverbs` event handling, or perhaps the core logic for initiating or completing operations initiated by user-space. Understanding this part is crucial for grasping how applications can efficiently and directly interact with the Infiniband hardware without going through the full kernel networking stack for every operation. I'm trying to pinpoint the mechanisms that ensure safe and performant data movement and communication from the user's perspective.
|
| 115/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/nldev.c FirstLine:2720 LineCount:100]
Results: map[Contents:2720: static int fill_frmr_pool_key(struct sk_buff *msg, struct ib_frmr_key *key)
2721: {
2722: struct nlattr *key_attr;
2723:
2724: key_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_FRMR_POOL_KEY);
2725: if (!key_attr)
2726: return -EMSGSIZE;
2727:
2728: if (nla_put_u8(msg, RDMA_NLDEV_ATTR_FRMR_POOL_KEY_ATS, key->ats))
2729: goto err;
2730: if (nla_put_u32(msg, RDMA_NLDEV_ATTR_FRMR_POOL_KEY_ACCESS_FLAGS,
2731: key->access_flags))
2732: goto err;
2733: if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_FRMR_POOL_KEY_VENDOR_KEY,
2734: key->vendor_key, RDMA_NLDEV_ATTR_PAD))
2735: goto err;
2736: if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_FRMR_POOL_KEY_NUM_DMA_BLOCKS,
2737: key->num_dma_blocks, RDMA_NLDEV_ATTR_PAD))
2738: goto err;
2739:
2740: if (key->kernel_vendor_key &&
2741: nla_put_u64_64bit(msg,
2742: RDMA_NLDEV_ATTR_FRMR_POOL_KEY_KERNEL_VENDOR_KEY,
2743: key->kernel_vendor_key, RDMA_NLDEV_ATTR_PAD))
2744: goto err;
2745:
2746: nla_nest_end(msg, key_attr);
2747: return 0;
2748:
2749: err:
2750: return -EMSGSIZE;
2751: }
2752:
2753: static int fill_frmr_pool_entry(struct sk_buff *msg, struct ib_frmr_pool *pool)
2754: {
2755: if (fill_frmr_pool_key(msg, &pool->key))
2756: return -EMSGSIZE;
2757:
2758: spin_lock(&pool->lock);
2759: if (nla_put_u32(msg, RDMA_NLDEV_ATTR_FRMR_POOL_QUEUE_HANDLES,
2760: pool->queue.ci + pool->inactive_queue.ci))
2761: goto err_unlock;
2762: if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_FRMR_POOL_MAX_IN_USE,
2763: pool->max_in_use, RDMA_NLDEV_ATTR_PAD))
2764: goto err_unlock;
2765: if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_FRMR_POOL_IN_USE,
2766: pool->in_use, RDMA_NLDEV_ATTR_PAD))
2767: goto err_unlock;
2768: if (nla_put_u32(msg, RDMA_NLDEV_ATTR_FRMR_POOL_PINNED_HANDLES,
2769: pool->pinned_handles))
2770: goto err_unlock;
2771: spin_unlock(&pool->lock);
2772:
2773: return 0;
2774:
2775: err_unlock:
2776: spin_unlock(&pool->lock);
2777: return -EMSGSIZE;
2778: }
2779:
2780: static int nldev_frmr_pools_parse_key(struct nlattr *tb[],
2781: struct ib_frmr_key *key,
2782: struct netlink_ext_ack *extack)
2783: {
2784: if (tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_ATS])
2785: key->ats = nla_get_u8(tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_ATS]);
2786:
2787: if (tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_ACCESS_FLAGS])
2788: key->access_flags = nla_get_u32(
2789: tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_ACCESS_FLAGS]);
2790:
2791: if (tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_VENDOR_KEY])
2792: key->vendor_key = nla_get_u64(
2793: tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_VENDOR_KEY]);
2794:
2795: if (tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_NUM_DMA_BLOCKS])
2796: key->num_dma_blocks = nla_get_u64(
2797: tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_NUM_DMA_BLOCKS]);
2798:
2799: if (tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY_KERNEL_VENDOR_KEY])
2800: return -EINVAL;
2801:
2802: return 0;
2803: }
2804:
2805: static int nldev_frmr_pools_set_pinned(struct ib_device *device,
2806: struct nlattr *tb[],
2807: struct netlink_ext_ack *extack)
2808: {
2809: struct nlattr *key_tb[RDMA_NLDEV_ATTR_MAX];
2810: struct ib_frmr_key key = { 0 };
2811: u32 pinned_handles = 0;
2812: int err = 0;
2813:
2814: pinned_handles =
2815: nla_get_u32(tb[RDMA_NLDEV_ATTR_FRMR_POOL_PINNED_HANDLES]);
2816:
2817: if (!tb[RDMA_NLDEV_ATTR_FRMR_POOL_KEY])
2818: return -EINVAL;
2819:
]
|
| 116/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/uverbs_main.c FirstLine:1240 LineCount:80]
Results: map[Contents:1240: * uverbs_cleanup_ufile, as it might end up indirectly calling
1241: * uverbs_close, for example due to freeing the resources (e.g
1242: * mmput).
1243: */
1244: mutex_unlock(&uverbs_dev->lists_mutex);
1245:
1246: uverbs_destroy_ufile_hw(file, RDMA_REMOVE_DRIVER_REMOVE);
1247: kref_put(&file->ref, ib_uverbs_release_file);
1248:
1249: mutex_lock(&uverbs_dev->lists_mutex);
1250: }
1251: mutex_unlock(&uverbs_dev->lists_mutex);
1252:
1253: uverbs_disassociate_api(uverbs_dev->uapi);
1254: }
1255:
1256: static void ib_uverbs_remove_one(struct ib_device *device, void *client_data)
1257: {
1258: struct ib_uverbs_device *uverbs_dev = client_data;
1259: int wait_clients = 1;
1260:
1261: cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev);
1262: ida_free(&uverbs_ida, uverbs_dev->devnum);
1263:
1264: if (device->ops.disassociate_ucontext) {
1265: /* We disassociate HW resources and immediately return.
1266: * Userspace will see a EIO errno for all future access.
1267: * Upon returning, ib_device may be freed internally and is not
1268: * valid any more.
1269: * uverbs_device is still available until all clients close
1270: * their files, then the uverbs device ref count will be zero
1271: * and its resources will be freed.
1272: * Note: At this point no more files can be opened since the
1273: * cdev was deleted, however active clients can still issue
1274: * commands and close their open files.
1275: */
1276: ib_uverbs_free_hw_resources(uverbs_dev, device);
1277: wait_clients = 0;
1278: }
1279:
1280: if (refcount_dec_and_test(&uverbs_dev->refcount))
1281: ib_uverbs_comp_dev(uverbs_dev);
1282: if (wait_clients)
1283: wait_for_completion(&uverbs_dev->comp);
1284:
1285: put_device(&uverbs_dev->dev);
1286: }
1287:
1288: static int __init ib_uverbs_init(void)
1289: {
1290: int ret;
1291:
1292: ret = register_chrdev_region(IB_UVERBS_BASE_DEV,
1293: IB_UVERBS_NUM_FIXED_MINOR,
1294: "infiniband_verbs");
1295: if (ret) {
1296: pr_err("user_verbs: couldn't register device number\n");
1297: goto out;
1298: }
1299:
1300: ret = alloc_chrdev_region(&dynamic_uverbs_dev, 0,
1301: IB_UVERBS_NUM_DYNAMIC_MINOR,
1302: "infiniband_verbs");
1303: if (ret) {
1304: pr_err("couldn't register dynamic device number\n");
1305: goto out_alloc;
1306: }
1307:
1308: ret = class_register(&uverbs_class);
1309: if (ret) {
1310: pr_err("user_verbs: couldn't create class infiniband_verbs\n");
1311: goto out_chrdev;
1312: }
1313:
1314: ret = class_create_file(&uverbs_class, &class_attr_abi_version.attr);
1315: if (ret) {
1316: pr_err("user_verbs: couldn't create abi_version attribute\n");
1317: goto out_class;
1318: }
1319:
]
|
| 117/2 |
2026/10/21 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 68604
output: 94
thoughts: 56
Thoughts: **My Thought Process on Inspecting `nldev.c` and `uverbs_class`**
Alright, my immediate thought is to delve into the details of this request. The user wants me to examine the tail end of `drivers/infiniband/core/nldev.c`, specifically around line 2900, and then cross-reference that with the `uverbs_class` structure definition found in `drivers/infiniband/core/uverbs_main.c`. This suggests a need to understand how netlink device (nldev) operations, particularly at their conclusion or perhaps during tear-down/cleanup, interact with or are represented by the `uverbs_class`.
My mental model here is that `nldev.c` is likely handling the lower-level aspects of Netlink device management within the Infiniband subsystem. The reference to "end of the file" around line 2900 implies I should be looking for exit points, cleanup routines, or perhaps finalization logic for Netlink devices. This could involve releasing resources, unregistering handlers, or signaling completion of certain operations.
Simultaneously, I need to understand the role of `uverbs_class`. My expertise tells me that `uverbs` (User Verbs) are the user-space interface for interacting with verbs-based hardware, like InfiniBand and RoCE. The `uverbs_class` structure is almost certainly the kernel's internal representation of this user-space interface, acting as a central point for managing and dispatching user-space requests to the underlying hardware. It likely contains function pointers, data structures, and state information related to the `uverbs` API.
Therefore, my thinking is that by looking at the end of `nldev.c` and the `uverbs_class`, I'm trying to establish a connection: how do the Netlink device management functions, as they conclude their work, relate to the overall `uverbs` subsystem's structure and its operational lifecycle? Are there specific `uverbs_class` members that are being invoked, updated, or perhaps released as part of the Netlink device's finalization? This could involve understanding how Netlink events or configurations are translated into `uverbs` operations, or how `uverbs` resources tied to a Netlink device are being cleaned up.
My objective is to see if the Netlink device's lifecycle management, as defined in `nldev.c`, is directly integrated with or relies upon the `uverbs_class` for its proper termination and resource management. It's about tracing the flow of control and data, particularly at the point where a Netlink device's interaction with the `uverbs` layer is concluded.
|
| 118/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/nldev.c FirstLine:2900 LineCount:100]
Results: map[Contents:2900: skb, RDMA_NLDEV_ATTR_FRMR_POOL_ENTRY);
2901: if (!entry_attr) {
2902: ret = -EMSGSIZE;
2903: goto end_msg;
2904: }
2905:
2906: if (fill_frmr_pool_entry(skb, pool)) {
2907: nla_nest_cancel(skb, entry_attr);
2908: ret = -EMSGSIZE;
2909: goto end_msg;
2910: }
2911:
2912: nla_nest_end(skb, entry_attr);
2913: idx++;
2914: }
2915: end_msg:
2916: read_unlock(&pools->rb_lock);
2917:
2918: nla_nest_end(skb, table_attr);
2919: nlmsg_end(skb, nlh);
2920: cb->args[0] = idx;
2921:
2922: /*
2923: * No more entries to fill, cancel the message and
2924: * return 0 to mark end of dumpit.
2925: */
2926: if (!filled)
2927: goto err;
2928:
2929: ib_device_put(device);
2930: return skb->len;
2931:
2932: err:
2933: nlmsg_cancel(skb, nlh);
2934: ib_device_put(device);
2935: return ret;
2936: }
2937:
2938: static int nldev_frmr_pools_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
2939: struct netlink_ext_ack *extack)
2940: {
2941: struct ib_device *device;
2942: struct nlattr **tb;
2943: u32 aging_period;
2944: int err;
2945:
2946: tb = kzalloc_objs(*tb, RDMA_NLDEV_ATTR_MAX);
2947: if (!tb)
2948: return -ENOMEM;
2949:
2950: err = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1, nldev_policy,
2951: extack);
2952: if (err)
2953: goto free_tb;
2954:
2955: if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX]) {
2956: err = -EINVAL;
2957: goto free_tb;
2958: }
2959:
2960: device = ib_device_get_by_index(
2961: sock_net(skb->sk), nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]));
2962: if (!device) {
2963: err = -EINVAL;
2964: goto free_tb;
2965: }
2966:
2967: if (tb[RDMA_NLDEV_ATTR_FRMR_POOLS_AGING_PERIOD]) {
2968: aging_period = nla_get_u32(
2969: tb[RDMA_NLDEV_ATTR_FRMR_POOLS_AGING_PERIOD]);
2970: err = ib_frmr_pools_set_aging_period(device, aging_period);
2971: goto done;
2972: }
2973:
2974: if (tb[RDMA_NLDEV_ATTR_FRMR_POOL_PINNED_HANDLES])
2975: err = nldev_frmr_pools_set_pinned(device, tb, extack);
2976:
2977: done:
2978: ib_device_put(device);
2979: free_tb:
2980: kfree(tb);
2981: return err;
2982: }
2983:
2984: static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
2985: [RDMA_NLDEV_CMD_GET] = {
2986: .doit = nldev_get_doit,
2987: .dump = nldev_get_dumpit,
2988: },
2989: [RDMA_NLDEV_CMD_GET_CHARDEV] = {
2990: .doit = nldev_get_chardev,
2991: },
2992: [RDMA_NLDEV_CMD_SET] = {
2993: .doit = nldev_set_doit,
2994: .flags = RDMA_NL_ADMIN_PERM,
2995: },
2996: [RDMA_NLDEV_CMD_NEWLINK] = {
2997: .doit = nldev_newlink,
2998: .flags = RDMA_NL_ADMIN_PERM,
2999: },
]
|
| 119/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/uverbs_main.c FirstLine:1150 LineCount:90]
Results: map[Contents:1150: int devnum;
1151: dev_t base;
1152: struct ib_uverbs_device *uverbs_dev;
1153: int ret;
1154:
1155: if (!device->ops.alloc_ucontext ||
1156: device->type == RDMA_DEVICE_TYPE_SMI)
1157: return -EOPNOTSUPP;
1158:
1159: uverbs_dev = kzalloc_obj(*uverbs_dev);
1160: if (!uverbs_dev)
1161: return -ENOMEM;
1162:
1163: ret = init_srcu_struct(&uverbs_dev->disassociate_srcu);
1164: if (ret) {
1165: kfree(uverbs_dev);
1166: return -ENOMEM;
1167: }
1168:
1169: device_initialize(&uverbs_dev->dev);
1170: uverbs_dev->dev.class = &uverbs_class;
1171: uverbs_dev->dev.parent = device->dev.parent;
1172: uverbs_dev->dev.release = ib_uverbs_release_dev;
1173: uverbs_dev->groups[0] = &dev_attr_group;
1174: uverbs_dev->dev.groups = uverbs_dev->groups;
1175: refcount_set(&uverbs_dev->refcount, 1);
1176: init_completion(&uverbs_dev->comp);
1177: uverbs_dev->xrcd_tree = RB_ROOT;
1178: mutex_init(&uverbs_dev->xrcd_tree_mutex);
1179: mutex_init(&uverbs_dev->lists_mutex);
1180: INIT_LIST_HEAD(&uverbs_dev->uverbs_file_list);
1181: rcu_assign_pointer(uverbs_dev->ib_dev, device);
1182: uverbs_dev->num_comp_vectors = device->num_comp_vectors;
1183:
1184: devnum = ida_alloc_max(&uverbs_ida, IB_UVERBS_MAX_DEVICES - 1,
1185: GFP_KERNEL);
1186: if (devnum < 0) {
1187: ret = -ENOMEM;
1188: goto err;
1189: }
1190: uverbs_dev->devnum = devnum;
1191: if (devnum >= IB_UVERBS_NUM_FIXED_MINOR)
1192: base = dynamic_uverbs_dev + devnum - IB_UVERBS_NUM_FIXED_MINOR;
1193: else
1194: base = IB_UVERBS_BASE_DEV + devnum;
1195:
1196: ret = ib_uverbs_create_uapi(device, uverbs_dev);
1197: if (ret)
1198: goto err_uapi;
1199:
1200: uverbs_dev->dev.devt = base;
1201: dev_set_name(&uverbs_dev->dev, "uverbs%d", uverbs_dev->devnum);
1202:
1203: cdev_init(&uverbs_dev->cdev,
1204: device->ops.mmap ? &uverbs_mmap_fops : &uverbs_fops);
1205: uverbs_dev->cdev.owner = THIS_MODULE;
1206:
1207: ret = cdev_device_add(&uverbs_dev->cdev, &uverbs_dev->dev);
1208: if (ret)
1209: goto err_uapi;
1210:
1211: ib_set_client_data(device, &uverbs_client, uverbs_dev);
1212: return 0;
1213:
1214: err_uapi:
1215: ida_free(&uverbs_ida, devnum);
1216: err:
1217: if (refcount_dec_and_test(&uverbs_dev->refcount))
1218: ib_uverbs_comp_dev(uverbs_dev);
1219: wait_for_completion(&uverbs_dev->comp);
1220: put_device(&uverbs_dev->dev);
1221: return ret;
1222: }
1223:
1224: static void ib_uverbs_free_hw_resources(struct ib_uverbs_device *uverbs_dev,
1225: struct ib_device *ib_dev)
1226: {
1227: struct ib_uverbs_file *file;
1228:
1229: /* Pending running commands to terminate */
1230: uverbs_disassociate_api_pre(uverbs_dev);
1231:
1232: mutex_lock(&uverbs_dev->lists_mutex);
1233: while (!list_empty(&uverbs_dev->uverbs_file_list)) {
1234: file = list_first_entry(&uverbs_dev->uverbs_file_list,
1235: struct ib_uverbs_file, list);
1236: list_del_init(&file->list);
1237: kref_get(&file->ref);
1238:
1239: /* We must release the mutex before going ahead and calling
]
|
| 120/2 |
2026/10/21 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 71763
output: 97
thoughts: 116
Thoughts: **My Investigation into `uverbs_devnode` and `rxe` User Namespace Compatibility**
Right, so my initial thought is to dive deep into the specifics of `uverbs_devnode` within the `drivers/infiniband/core/uverbs_main.c` file. I want to meticulously examine the code section from lines 1100 to 1150, as that seems like the most pertinent area for understanding its behavior and potential implications. My hypothesis is that by dissecting this specific block, I'll gain crucial insights into how these user-level verbs devices are managed and initialized.
Concurrently, I need to shift my focus to the `rxe` implementation, specifically the `rxe_net_init` function located in `drivers/infiniband/sw/rxe/rxe_net.c`. The core question I'm trying to answer here is whether the `rxe` (RDMA subsystem emulation) can actually be instantiated and operate within a user namespace. My suspicion is that it might be restricted to the `init_net` namespace, and I need to confirm or refute this. Understanding this distinction is critical for determining the flexibility and deployment possibilities of `rxe` in more constrained or isolated environments. Essentially, I'm trying to map out the boundaries of where `rxe` can live and how it interacts with network namespaces.
|
| 121/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/core/uverbs_main.c FirstLine:1100 LineCount:50]
Results: map[Contents:1100: }
1101: static DEVICE_ATTR_RO(ibdev);
1102:
1103: static ssize_t abi_version_show(struct device *device,
1104: struct device_attribute *attr, char *buf)
1105: {
1106: struct ib_uverbs_device *dev =
1107: container_of(device, struct ib_uverbs_device, dev);
1108: int ret = -ENODEV;
1109: int srcu_key;
1110: struct ib_device *ib_dev;
1111:
1112: srcu_key = srcu_read_lock(&dev->disassociate_srcu);
1113: ib_dev = srcu_dereference(dev->ib_dev, &dev->disassociate_srcu);
1114: if (ib_dev)
1115: ret = sysfs_emit(buf, "%u\n", ib_dev->ops.uverbs_abi_ver);
1116: srcu_read_unlock(&dev->disassociate_srcu, srcu_key);
1117:
1118: return ret;
1119: }
1120: static DEVICE_ATTR_RO(abi_version);
1121:
1122: static struct attribute *ib_dev_attrs[] = {
1123: &dev_attr_abi_version.attr,
1124: &dev_attr_ibdev.attr,
1125: NULL,
1126: };
1127:
1128: static const struct attribute_group dev_attr_group = {
1129: .attrs = ib_dev_attrs,
1130: };
1131:
1132: static CLASS_ATTR_STRING(abi_version, S_IRUGO,
1133: __stringify(IB_USER_VERBS_ABI_VERSION));
1134:
1135: static int ib_uverbs_create_uapi(struct ib_device *device,
1136: struct ib_uverbs_device *uverbs_dev)
1137: {
1138: struct uverbs_api *uapi;
1139:
1140: uapi = uverbs_alloc_api(device);
1141: if (IS_ERR(uapi))
1142: return PTR_ERR(uapi);
1143:
1144: uverbs_dev->uapi = uapi;
1145: return 0;
1146: }
1147:
1148: static int ib_uverbs_add_one(struct ib_device *device)
1149: {
]
|
| 122/2 |
2026/10/21 02:06 |
tool |
read-file |
0m
Args: map[File:drivers/infiniband/sw/rxe/rxe_net.c FirstLine:550 LineCount:100]
Results: map[Contents: 550:
551: if (av->network_type == RXE_NETWORK_TYPE_IPV4)
552: hdr_len = ETH_HLEN + sizeof(struct udphdr) +
553: sizeof(struct iphdr);
554: else
555: hdr_len = ETH_HLEN + sizeof(struct udphdr) +
556: sizeof(struct ipv6hdr);
557:
558: rcu_read_lock();
559: ndev = rdma_read_gid_attr_ndev_rcu(attr);
560: if (IS_ERR(ndev)) {
561: rcu_read_unlock();
562: goto out;
563: }
564: skb = alloc_skb(paylen + hdr_len + LL_RESERVED_SPACE(ndev),
565: GFP_ATOMIC);
566:
567: if (unlikely(!skb)) {
568: rcu_read_unlock();
569: goto out;
570: }
571:
572: /* Add time stamp to skb. */
573: skb->tstamp = ktime_get();
574:
575: skb_reserve(skb, hdr_len + LL_RESERVED_SPACE(ndev));
576:
577: /* FIXME: hold reference to this netdev until life of this skb. */
578: skb->dev = ndev;
579: rcu_read_unlock();
580:
581: if (av->network_type == RXE_NETWORK_TYPE_IPV4)
582: skb->protocol = htons(ETH_P_IP);
583: else
584: skb->protocol = htons(ETH_P_IPV6);
585:
586: pkt->rxe = rxe;
587: pkt->port_num = port_num;
588: pkt->hdr = skb_put(skb, paylen);
589: pkt->mask |= RXE_GRH_MASK;
590:
591: out:
592: rdma_put_gid_attr(attr);
593: return skb;
594: }
595:
596: /*
597: * this is required by rxe_cfg to match rxe devices in
598: * /sys/class/infiniband up with their underlying ethernet devices
599: */
600: const char *rxe_parent_name(struct rxe_dev *rxe, unsigned int port_num)
601: {
602: struct net_device *ndev;
603: char *ndev_name;
604:
605: ndev = ib_device_get_netdev(&rxe->ib_dev, 1);
606: if (!ndev)
607: return NULL;
608: ndev_name = ndev->name;
609: dev_put(ndev);
610:
611: return ndev_name;
612: }
613:
614: int rxe_net_add(const char *ibdev_name, struct net_device *ndev)
615: {
616: int err;
617: struct rxe_dev *rxe = NULL;
618:
619: rxe = ib_alloc_device(rxe_dev, ib_dev);
620: if (!rxe)
621: return -ENOMEM;
622:
623: ib_mark_name_assigned_by_user(&rxe->ib_dev);
624:
625: err = rxe_add(rxe, ndev->mtu, ibdev_name, ndev);
626: if (err) {
627: ib_dealloc_device(&rxe->ib_dev);
628: return err;
629: }
630:
631: return 0;
632: }
633:
634: static void rxe_sock_put(struct sock *sk,
635: void (*set_sk)(struct net *, struct sock *),
636: struct net *net)
637: {
638: if (refcount_read(&sk->sk_refcnt) > SK_REF_FOR_TUNNEL) {
639: __sock_put(sk);
640: } else {
641: rxe_release_udp_tunnel(sk);
642: sk = NULL;
643: set_sk(net, sk);
644: }
645: }
646:
647: void rxe_net_del(struct ib_device *dev)
648: {
649: struct net_device *ndev;
]
|
| 123/2 |
2026/10/21 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 74173
output: 71
thoughts: 1689
Thoughts: **My Thought Process Regarding the RXE/RDS Vulnerability**
My initial focus was on understanding how privilege escalation might occur within the Infiniband and RDS (Reliable Datagram Sockets) subsystems, particularly concerning the RXE (RDMA Emulation) driver. I started by examining the `netlink_capable` function in `drivers/infiniband/core/netlink.c`. My immediate observation was that the check for `CAP_NET_ADMIN` was being performed against the global `init_user_ns`, not against the specific network namespace (`netlink_net_capable`). This raised a red flag.
Then, I considered the common scenario where an RXE device is already configured on the system. This led me to question how an unprivileged user could exploit this. My investigation branched into a few key areas:
First, I looked into `AF_RDS` sockets. The `rds_create` function in `net/rds/af_rds.c` showed no capability checks for creating `AF_RDS` sockets. This is a critical finding: any unprivileged user can create an `AF_RDS` socket, bind it to a local IP address backed by the RXE device, and then initiate connection setup or shutdown. This directly impacts the RDS/IB connection management, including `rds_ib_cm_initiate_connect`, `rds_ib_cm_handle_connect`, `rds_conn_shutdown`, `rds_ib_conn_path_shutdown`, and ultimately `rdma_destroy_qp` and `rxe_destroy_qp`.
Second, I examined the device node permissions. I found that `/dev/infiniband/uverbs*` and `/dev/infiniband/rdma_cm` both have `0666` permissions. This means unprivileged userspace processes can directly interact with these devices, allowing them to create, use, and destroy RXE QPs (Queue Pairs) through functions like `ib_destroy_qp_user` which leads to `rxe_destroy_qp` and then `__rxe_cleanup`.
Third, I considered the possibility of a remote network trigger. I recalled that RXE (Soft-RoCE/RoCEv2) encapsulates RDMA packets over UDP port 4791. RDS over IB also listens on RDMA CM for incoming connections and processes incoming RoCEv2 UDP packets. This led me to ponder if a remote peer could initiate an RDS-IB connection, send RoCEv2 packets, and then drop the connection, effectively triggering the QP destruction process via `rds_conn_drop` and `rds_shutdown_worker` down to `rdma_destroy_qp`.
However, I needed to understand the 50-second timeout observed in the syzkaller report. The `wait_for_completion_timeout` in `__rxe_cleanup()` seemed central to this. I also noted the `Tainted: [L]=SOFTLOCKUP` in the crash report, which pointed to a local issue rather than purely remote network activity. I reasoned that while RoCEv2 packets are processed over Ethernet, reliably triggering that specific 50-second timeout from remote traffic alone is less probable than local unprivileged processes causing lock contention or races.
This led me to a crucial realization about exploitability: the timeout in `__rxe_cleanup` occurs when a `struct rxe_qp` is being cleaned up, but references to it are still held. Despite the `-ETIMEDOUT` error, `__rxe_cleanup` proceeds to call `pool->cleanup(elem)` and `rxe_destroy_qp()`. The latter ignores the timeout error and returns `0` to `ib_destroy_qp_user()`. This function then immediately calls `kfree(qp)`. When the remaining reference holder finally tries to access `qp` or call `rxe_put(qp)`, a Use-After-Free (UAF) vulnerability is triggered.
Given these findings, I began to categorize the vulnerability:
* **Exploitable**: Absolutely. The UAF on `struct rxe_qp` is a direct consequence of the timeout and subsequent cleanup logic.
* **DenialOfService**: Clearly yes. The 50-second stall of the `krds_cp_wq` workqueue, the softlockups, and the kernel UAF crash all constitute a denial of service.
* **Unprivileged**: Definitely true. The lack of capability checks for `AF_RDS` sockets and the permissive device node permissions make this accessible to unprivileged users.
* **UserNamespace**: Since it's accessible from unprivileged processes, it's naturally accessible from within user namespaces.
* **VMGuestTrigger / VMHostTrigger**: These were ruled out as not being related to KVM or confidential computing issues.
* **NetworkTrigger / RemoteTrigger / PeripheralTrigger / FilesystemTrigger**: I concluded that while RoCEv2 involves networking, the specific timeout mechanism that leads to the UAF is more likely triggered by local interactions than purely remote network traffic. Therefore, `NetworkTrigger` and `RemoteTrigger` were set to `false`. The other trigger types were also deemed not applicable.
With this detailed analysis complete, I felt confident in setting the results and proceeding.
|
| 124/2 |
2026/10/21 02:07 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 125/2 |
2026/10/21 02:07 |
llm |
expert |
0m
Model:
Tokens:
input: 76000
output: 1094
thoughts: 14
Thoughts: **My Thought Process Leading to the Final Response**
Alright, I've reached the point where I'm confident and ready to articulate my final analysis and the reasoning behind it. This has been a thorough exploration, and now I'm prepared to present my conclusions.
|
| 126/1 |
2026/10/21 02:07 |
action |
format-explanation |
0m
Results: map[Explanation:### Security Impact Analysis
#### 1. Vulnerability Mechanism
The warning occurs in `__rxe_cleanup()`
(`drivers/infiniband/sw/rxe/rxe_pool.c:212`) when destroying an RXE Queue Pair
(`struct rxe_qp`) during RDS connection shutdown (`rds_shutdown_worker` ->
`rds_conn_shutdown` -> `rds_ib_conn_path_shutdown` -> `rdma_destroy_qp` ->
`ib_destroy_qp_user` -> `rxe_destroy_qp`):
```c
xa_ret = xa_erase(xa, elem->index);
WARN_ON(xa_err(xa_ret));
/* if this is the last call to rxe_put complete the
* object can berelleased safely. Otherwise wait until
* the last reference is dropped. Lookups via xarray
* cannot add references since the object is already
* removed from the xarray.
*/
__rxe_put(elem);
if (sleepable) {
if (!completion_done(&elem->complete)) {
ret = wait_for_completion_timeout(&elem->complete,
msecs_to_jiffies(50000));
if (WARN_ON(!ret))
err = -ETIMEDOUT;
}
}
if (pool->cleanup)
pool->cleanup(elem);
```
When `elem->complete` is not signaled within 50 seconds (`ret == 0`), at least
one reference to `qp` (`elem->ref_cnt`) is still held (for example, by a
scheduled or stalled `rxe_wq` task, an undrained packet queued in `qp->req_pkts`
/ `qp->resp_pkts`, or an in-flight `sk_buff` with destructor `rxe_skb_tx_dtor`).
#### 2. Exploitability (`Exploitable: true`)
Although the report itself is a `WARN_ON(!ret)` upon timeout, what happens
immediately after the warning in production builds makes this a **Use-After-Free
(UAF)** vulnerability:
1. Even when `wait_for_completion_timeout()` times out and sets `err =
-ETIMEDOUT`, `__rxe_cleanup()` still proceeds to invoke `pool->cleanup(elem)`
(`rxe_qp_cleanup` -> `rxe_qp_do_cleanup`), which tears down the QP's internal
state, queues, and pointers while another reference holder still exists.
2. In `rxe_destroy_qp()` (`drivers/infiniband/sw/rxe/rxe_verbs.c:650-668`), the
error returned by `rxe_cleanup(qp)` is logged via `rxe_err_qp()` and then
ignoredβ`rxe_destroy_qp()` unconditionally returns `0`:
```c
ret = rxe_cleanup(qp);
if (ret)
rxe_err_qp(qp, "cleanup failed, err = %d\n", ret);
...
return 0;
```
3. Because `destroy_qp` returns `0`, `ib_destroy_qp_user()`
(`drivers/infiniband/core/verbs.c:2182, 2204`) immediately frees the `qp`
allocation via `kfree(qp)`.
4. When the outstanding reference holder (e.g., `rxe_skb_tx_dtor`, `do_task` on
`rxe_wq`, or timer/packet cleanup) subsequently accesses `qp` or calls
`rxe_put(qp)`, it operates on freed slab memory, causing a Use-After-Free.
#### 3. Denial of Service (`DenialOfService: true`)
Each timeout blocks the `krds_cp_wq` workqueue worker for 50 seconds
(`msecs_to_jiffies(50000)`), accompanied by CPU softlockups (`Tainted:
[L]=SOFTLOCKUP`), and ultimately corrupts kernel memory when the
still-referenced `struct rxe_qp` is freed.
#### 4. Accessibility (`Unprivileged: true`, `UserNamespace: true`)
When an RXE device is present on the system:
- Opening an `AF_RDS` socket (`rds_create()` in `net/rds/af_rds.c`) requires no
capabilities (`socket(AF_RDS, SOCK_SEQPACKET, 0)`). Any unprivileged local user
can bind and initiate/drop RDS connections over the RXE transport.
- Additionally, RDMA user verbs character devices (`/dev/infiniband/uverbs*` and
`/dev/infiniband/rdma_cm`) are created with `0666` permissions by default,
allowing unprivileged userspace processes (and processes inside user namespaces)
to directly create and destroy RXE QPs.]
|