| 0/0 |
2026/02/23 14:47 |
flow |
assessment-kcsan |
3m
Results: map[Benign:true Confident:true Explanation:The data race occurs between `smc_switch_to_fallback()` (write) and `smc_poll()` (read) on the `smc->use_fallback` field in `struct smc_sock`. This field is a boolean flag that indicates whether the SMC socket should delegate its operations to the underlying TCP socket (`clcsock`).
### Analysis:
1. **Nature of the Flag**: `use_fallback` is a simple status flag. It is initialized to `false` and typically transitions to `true` once when SMC determines that RDMA communication is not possible (e.g., during connection establishment or due to an error).
2. **Safety of the Access**:
* In `smc_switch_to_fallback()`, the flag is set to `true` while holding the `clcsock_release_lock`.
* In `smc_poll()`, the flag is checked without a lock to decide whether to use SMC-specific polling logic or to delegate to the underlying TCP socket's `poll` implementation (`smc->clcsock->ops->poll`).
* The `clcsock` itself is allocated during `smc_create()` and is guaranteed to be valid as long as the `smc_sock` is alive. Since `smc_poll()` is called via a file descriptor, the socket's reference count ensures it won't be destroyed during the call.
3. **Impact of the Race**:
* If `smc_poll()` reads `use_fallback` as `false` while it is being changed to `true`, it will proceed with SMC-specific polling logic. This logic checks the SMC connection state and return a mask.
* If it reads `true`, it delegates to the TCP socket.
* In either case, the result is a valid poll mask. Because `poll` is inherently racy (the state can change immediately after the function returns), missing a state transition for one `poll` cycle is generally acceptable in the network stack.
* The SMC implementation ensures that after a fallback transition, appropriate wakeups (like `sk_write_space`) are triggered. This ensures that any process waiting in `poll` will be woken up and will see the updated `use_fallback` state in the subsequent `poll` call.
4. **Memory Consistency**: On the reported x86_64 architecture, a 1-byte write/read is atomic. There is no risk of "tearing" or seeing an invalid value. The compiler is unlikely to optimize this in a way that causes a crash, as the flag is only used for a simple branch.
### Conclusion:
The data race is **benign**. It is a common pattern in the Linux kernel to use such flags for state transitions without heavy locking in performance-critical paths like `poll`. While using `READ_ONCE()` and `WRITE_ONCE()` would be recommended to satisfy KCSAN and prevent theoretical compiler optimizations, the current code does not lead to memory corruption, crashes, or incorrect behavior that wouldn't be resolved by the next `poll` cycle.]
|
| 1/1 |
2026/02/23 14:47 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/src/27f21913e25601ec14bf9550912fa548052d7893]
|
| 2/1 |
2026/02/23 14:47 |
action |
kernel-builder |
0m
Results: map[KernelObj:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/build/f610a99703320fc3f40bbab112bbaf5fc74c9413]
|
| 3/1 |
2026/02/23 14:47 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 4/1 |
2026/02/23 14:47 |
agent |
expert |
3m
Model:
Results: map[Benign:true Confident:true]
Instruction:
You are an experienced Linux kernel developer tasked with determining if the given kernel
data race is benign or not. The data race report is from KCSAN tool.
It contains 2 stack traces of the memory accesses that constitute a data race.
A "benign" data races are on a simple int/bool variable or similar field,
and the accesses are not supposed to be protected by any mutual exclusion primitives.
Common examples of such "benign" data races are accesses to various flags fields,
statistics counters, and similar. A "benign" data race does not lead to memory corruption/crash
with a conservative compiler that compiles memory accesses to primitive types
effectively as atomic.
A non-benign (or "harmful" data race) can lead to corruption/crash even with
a conservative compiler that compiles memory accesses to primitive types
effectively as atomic. A common example of a "harmful" data races is race on
a complex container (list/hashmap/etc), where accesses are supposed to be protected
by a mutual exclusion primitive.
Also consider races that happen at the same time with the given one.
If there is no synchronization in between, other memory accesses in the involved threads
race with each other if they access the same memory. For example, if both threads execute:
some_struct->have_elements = true;
list_add(new_node, &some_struct->list_head);
the race on some_struct->have_elements may appear benign, however it also implies there
is a race on some_struct->list_head which is not benign, since the list is not thread-safe.
Take into account that on 32-bit systems 64-bit memory accesses may be split into two accesses,
and thus even with a conservative compiler may not be fully atomic. However, such races may
still be benign depending on how writes are done, and how read data is used.
In the final reply explain why you think the given data race is benign or is harmful.
Use the provided tools to confirm any assumptions, variables/fields being accessed, etc.
In particular, don't make assumptions about the kernel source code,
use codesearch tools to read the actual source code.
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 data race report is:
==================================================================
BUG: KCSAN: data-race in smc_poll / smc_switch_to_fallback
write to 0xffff88810a188e4d of 1 bytes by task 19015 on cpu 0:
smc_switch_to_fallback+0x5a/0x7f0 net/smc/af_smc.c:927
smc_sendmsg+0xce/0x2f0 net/smc/af_smc.c:2797
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x5af/0x600 net/socket.c:2592
___sys_sendmsg+0x195/0x1e0 net/socket.c:2646
__sys_sendmsg net/socket.c:2678 [inline]
__do_sys_sendmsg net/socket.c:2683 [inline]
__se_sys_sendmsg net/socket.c:2681 [inline]
__x64_sys_sendmsg+0xd4/0x160 net/socket.c:2681
x64_sys_call+0x194c/0x3020 arch/x86/include/generated/asm/syscalls_64.h:47
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x12c/0x370 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
read to 0xffff88810a188e4d of 1 bytes by task 19013 on cpu 1:
smc_poll+0x275/0x530 net/smc/af_smc.c:2898
sock_poll+0x21c/0x240 net/socket.c:1443
vfs_poll include/linux/poll.h:82 [inline]
__io_arm_poll_handler+0x1ec/0xc30 io_uring/poll.c:581
io_poll_add+0x69/0xf0 io_uring/poll.c:899
__io_issue_sqe+0xfd/0x2d0 io_uring/io_uring.c:1384
io_issue_sqe+0x206/0xc00 io_uring/io_uring.c:1407
io_queue_sqe io_uring/io_uring.c:1634 [inline]
io_submit_sqe io_uring/io_uring.c:1920 [inline]
io_submit_sqes+0x7fb/0x1270 io_uring/io_uring.c:2043
__do_sys_io_uring_enter io_uring/io_uring.c:2603 [inline]
__se_sys_io_uring_enter+0x1c9/0xf50 io_uring/io_uring.c:2538
__x64_sys_io_uring_enter+0x78/0x90 io_uring/io_uring.c:2538
x64_sys_call+0x1e16/0x3020 arch/x86/include/generated/asm/syscalls_64.h:427
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x12c/0x370 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x00 -> 0x01
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 19013 Comm: syz.7.4546 Tainted: G W syzkaller #0 PREEMPT(full)
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2026
==================================================================
Reply: The data race occurs between `smc_switch_to_fallback()` (write) and `smc_poll()` (read) on the `smc->use_fallback` field in `struct smc_sock`. This field is a boolean flag that indicates whether the SMC socket should delegate its operations to the underlying TCP socket (`clcsock`).
### Analysis:
1. **Nature of the Flag**: `use_fallback` is a simple status flag. It is initialized to `false` and typically transitions to `true` once when SMC determines that RDMA communication is not possible (e.g., during connection establishment or due to an error).
2. **Safety of the Access**:
* In `smc_switch_to_fallback()`, the flag is set to `true` while holding the `clcsock_release_lock`.
* In `smc_poll()`, the flag is checked without a lock to decide whether to use SMC-specific polling logic or to delegate to the underlying TCP socket's `poll` implementation (`smc->clcsock->ops->poll`).
* The `clcsock` itself is allocated during `smc_create()` and is guaranteed to be valid as long as the `smc_sock` is alive. Since `smc_poll()` is called via a file descriptor, the socket's reference count ensures it won't be destroyed during the call.
3. **Impact of the Race**:
* If `smc_poll()` reads `use_fallback` as `false` while it is being changed to `true`, it will proceed with SMC-specific polling logic. This logic checks the SMC connection state and return a mask.
* If it reads `true`, it delegates to the TCP socket.
* In either case, the result is a valid poll mask. Because `poll` is inherently racy (the state can change immediately after the function returns), missing a state transition for one `poll` cycle is generally acceptable in the network stack.
* The SMC implementation ensures that after a fallback transition, appropriate wakeups (like `sk_write_space`) are triggered. This ensures that any process waiting in `poll` will be woken up and will see the updated `use_fallback` state in the subsequent `poll` call.
4. **Memory Consistency**: On the reported x86_64 architecture, a 1-byte write/read is atomic. There is no risk of "tearing" or seeing an invalid value. The compiler is unlikely to optimize this in a way that causes a crash, as the flag is only used for a simple branch.
### Conclusion:
The data race is **benign**. It is a common pattern in the Linux kernel to use such flags for state transitions without heavy locking in performance-critical paths like `poll`. While using `READ_ONCE()` and `WRITE_ONCE()` would be recommended to satisfy KCSAN and prevent theoretical compiler optimizations, the current code does not lead to memory corruption, crashes, or incorrect behavior that wouldn't be resolved by the next `poll` cycle.
|
| 5/2 |
2026/02/23 14:47 |
llm |
expert |
0m
Model:
Tokens:
input: 4171
output: 92
thoughts: 219
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Analyzing a Data Race in the SMC Subsystem**
Alright, this report flags a data race, a write/read conflict, between `smc_switch_to_fallback` and `smc_poll`. They're both hitting a single byte at `0xffff88810a188e4d`. The value flipped from `0x00` to `0x01`. Time to dig in. I need to understand what's going on here.
First things first, I'll need to locate those functions in the `net/smc/af_smc.c` file. The report gives the offset information: `smc_switch_to_fallback+0x5a/0x7f0 net/smc/af_smc.c:927` and `smc_poll+0x275/0x530 net/smc/af_smc.c:2898`. Got it.
Now, I'm going to pull up the source code for both functions and quickly identify the lines where they are accessing the shared field. I'll need to understand the control flow, the data dependencies, and the locking involved in each function to determine the root cause. I'll use `codesearch-definition-source` to get a precise view of these functions in their full context. Knowing the file and line numbers is a great start, but I need the broader picture.
|
| 6/2 |
2026/02/23 14:47 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:smc_switch_to_fallback]
Results: map[SourceCode: 917: static int smc_switch_to_fallback(struct smc_sock *smc, int reason_code)
918: {
919: int rc = 0;
920:
921: mutex_lock(&smc->clcsock_release_lock);
922: if (!smc->clcsock) {
923: rc = -EBADF;
924: goto out;
925: }
926:
927: smc->use_fallback = true;
928: smc->fallback_rsn = reason_code;
929: smc_stat_fallback(smc);
930: trace_smc_switch_to_fallback(smc, reason_code);
931: if (smc->sk.sk_socket && smc->sk.sk_socket->file) {
932: smc->clcsock->file = smc->sk.sk_socket->file;
933: smc->clcsock->file->private_data = smc->clcsock;
934: smc->clcsock->wq.fasync_list =
935: smc->sk.sk_socket->wq.fasync_list;
936: smc->sk.sk_socket->wq.fasync_list = NULL;
937:
938: /* There might be some wait entries remaining
939: * in smc sk->sk_wq and they should be woken up
940: * as clcsock's wait queue is woken up.
941: */
942: smc_fback_replace_callbacks(smc);
943: }
944: out:
945: mutex_unlock(&smc->clcsock_release_lock);
946: return rc;
947: }
SourceFile:net/smc/af_smc.c]
|
| 7/2 |
2026/02/23 14:47 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:smc_poll]
Results: map[SourceCode:2872: __poll_t smc_poll(struct file *file, struct socket *sock,
2873: poll_table *wait)
2874: {
2875: struct sock *sk = sock->sk;
2876: struct smc_sock *smc;
2877: __poll_t mask = 0;
2878:
2879: if (!sk)
2880: return EPOLLNVAL;
2881:
2882: smc = smc_sk(sock->sk);
2883: if (smc->use_fallback) {
2884: /* delegate to CLC child sock */
2885: mask = smc->clcsock->ops->poll(file, smc->clcsock, wait);
2886: sk->sk_err = smc->clcsock->sk->sk_err;
2887: } else {
2888: if (sk->sk_state != SMC_CLOSED)
2889: sock_poll_wait(file, sock, wait);
2890: if (sk->sk_err)
2891: mask |= EPOLLERR;
2892: if ((sk->sk_shutdown == SHUTDOWN_MASK) ||
2893: (sk->sk_state == SMC_CLOSED))
2894: mask |= EPOLLHUP;
2895: if (sk->sk_state == SMC_LISTEN) {
2896: /* woken up by sk_data_ready in smc_listen_work() */
2897: mask |= smc_accept_poll(sk);
2898: } else if (smc->use_fallback) { /* as result of connect_work()*/
2899: mask |= smc->clcsock->ops->poll(file, smc->clcsock,
2900: wait);
2901: sk->sk_err = smc->clcsock->sk->sk_err;
2902: } else {
2903: if ((sk->sk_state != SMC_INIT &&
2904: atomic_read(&smc->conn.sndbuf_space)) ||
2905: sk->sk_shutdown & SEND_SHUTDOWN) {
2906: mask |= EPOLLOUT | EPOLLWRNORM;
2907: } else {
2908: sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
2909: set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
2910:
2911: if (sk->sk_state != SMC_INIT) {
2912: /* Race breaker the same way as tcp_poll(). */
2913: smp_mb__after_atomic();
2914: if (atomic_read(&smc->conn.sndbuf_space))
2915: mask |= EPOLLOUT | EPOLLWRNORM;
2916: }
2917: }
2918: if (atomic_read(&smc->conn.bytes_to_rcv))
2919: mask |= EPOLLIN | EPOLLRDNORM;
2920: if (sk->sk_shutdown & RCV_SHUTDOWN)
2921: mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
2922: if (sk->sk_state == SMC_APPCLOSEWAIT1)
2923: mask |= EPOLLIN;
2924: if (smc->conn.urg_state == SMC_URG_VALID)
2925: mask |= EPOLLPRI;
2926: }
2927: }
2928:
2929: return mask;
2930: }
SourceFile:net/smc/af_smc.c]
|
| 8/2 |
2026/02/23 14:47 |
llm |
expert |
0m
Model:
Tokens:
input: 6399
output: 49
thoughts: 600
Thoughts: **Analyzing a Potential Race Condition in the SMC Driver**
Okay, so I'm looking at this SMC driver code and immediately my attention is drawn to `smc->use_fallback`. The logs are pointing at a change in `use_fallback` from `false` (0x00) to `true` (0x01) within `smc_poll` at line 2898. This is interesting because `smc_switch_to_fallback` is where that flag gets flipped, indicating a move from RDMA to standard TCP (`clcsock`).
The core of the problem, as I see it, is that `smc_poll` checks `smc->use_fallback` twice – once at line 2883 and again at 2898. If it reads `false` at line 2883, it *then* checks again at 2898. This seems ripe for a race. If `smc_switch_to_fallback` sets `use_fallback` to `true` between those two checks, the first read will be stale. This could cause `smc_poll` to incorrectly execute SMC-specific logic (lines 2903-2926) when it *should* be delegating to `clcsock`.
I know `smc_switch_to_fallback` acquires `smc->clcsock_release_lock`, but `smc_poll` isn't using any explicit synchronization around its access to `smc->use_fallback`. That's the smoking gun for a race condition.
The question is, how harmful is this? If `smc_poll` misses the transition, it could return an incorrect poll mask, based on the SMC state when it should be returning the mask based on the underlying TCP socket. However, this is further complicated by the fact that `smc_switch_to_fallback` also calls `smc_fback_replace_callbacks(smc)`. This callback replacement, I suspect, might be the critical piece of the puzzle. I need to check how it works and what kind of state it manages to fully understand the impact of a missed transition. This is the next logical step to understand the true impact of this possible race.
|
| 9/2 |
2026/02/23 14:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:smc_fback_replace_callbacks]
Results: map[SourceCode: 898: static void smc_fback_replace_callbacks(struct smc_sock *smc)
899: {
900: struct sock *clcsk = smc->clcsock->sk;
901:
902: write_lock_bh(&clcsk->sk_callback_lock);
903: clcsk->sk_user_data = (void *)((uintptr_t)smc | SK_USER_DATA_NOCOPY);
904:
905: smc_clcsock_replace_cb(&clcsk->sk_state_change, smc_fback_state_change,
906: &smc->clcsk_state_change);
907: smc_clcsock_replace_cb(&clcsk->sk_data_ready, smc_fback_data_ready,
908: &smc->clcsk_data_ready);
909: smc_clcsock_replace_cb(&clcsk->sk_write_space, smc_fback_write_space,
910: &smc->clcsk_write_space);
911: smc_clcsock_replace_cb(&clcsk->sk_error_report, smc_fback_error_report,
912: &smc->clcsk_error_report);
913:
914: write_unlock_bh(&clcsk->sk_callback_lock);
915: }
SourceFile:net/smc/af_smc.c]
|
| 10/2 |
2026/02/23 14:48 |
llm |
expert |
0m
Model:
Tokens:
input: 7974
output: 39
thoughts: 945
Thoughts: **Analyzing a Potential Data Race in `smc_poll`**
Okay, so I'm digging into this `smc_poll` function, which is ultimately called from `vfs_poll` via `sock_poll`. The core issue seems to be around the `use_fallback` flag and how it's used to decide whether to delegate polling to the child socket (`clcsock`) or use the SMC-specific polling logic.
Here's the problem: `smc_poll` reads `use_fallback` *twice*. The first read at line 2883 determines the initial path. If `use_fallback` is `false`, it'll continue down a separate code path. But, and this is the crux, there's a second read at line 2898. The tricky part is that if `use_fallback` transitions from `false` to `true` *between* those two reads, we have a problem.
Specifically, if the first read at 2883 is `false`, the code initially prepares to use SMC-specific logic. However, if `use_fallback` becomes `true` before line 2898, it *still* delegates to the `clcsock` anyway. This seems fine on the surface because eventually, it delegates.
The bigger worry arises if *both* reads of `use_fallback` are `false`. In this case, `smc_poll` uses its own logic, checking `smc->conn.sndbuf_space` and `smc->conn.bytes_to_rcv`. This is where it gets dangerous. If we're in fallback mode, these `smc->conn` values *might not* be updated anymore because the `clcsock` handles the actual data transfer. The state of `smc->conn` becomes stale.
The KCSAN report confirms this suspicion, highlighting a data race: a write to the `use_fallback` memory location by `smc_switch_to_fallback` (setting it to `true`), and a read from the same location by `smc_poll` at line 2898.
Initially, I wasn't super worried. `use_fallback` is a simple boolean, so the compiler's optimizations are probably not going to be that aggressive. Also, `poll` itself is inherently racy – the state can change after the call returns. But the report highlights it.
The danger is that if we return a poll mask based on `smc->conn` (which might be outdated), while the actual data is in `clcsock`. This could mean that the caller might not be notified about new data or available space. But, this is *transient*, as subsequent polls should see `use_fallback == true`. However, the KCSAN report still indicates there's a very real data race here, which means memory barriers or atomic operations are needed to guarantee correct behavior and prevent the compiler from making unsafe assumptions. I need to check where `use_fallback` is defined in `struct smc_sock`.
|
| 11/2 |
2026/02/23 14:48 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:net/smc/af_smc.c Name:smc_sock]
Results: map[Fields:[map[Name: OffsetBits:0 SizeBits:8512] map[Name:clcsock OffsetBits:8512 SizeBits:64] map[Name:clcsk_state_change OffsetBits:8576 SizeBits:64] map[Name:clcsk_data_ready OffsetBits:8640 SizeBits:64] map[Name:clcsk_write_space OffsetBits:8704 SizeBits:64] map[Name:clcsk_error_report OffsetBits:8768 SizeBits:64] map[Name:conn OffsetBits:8832 SizeBits:4096] map[Name:listen_smc OffsetBits:12928 SizeBits:64] map[Name:connect_work OffsetBits:12992 SizeBits:256] map[Name:tcp_listen_work OffsetBits:13248 SizeBits:256] map[Name:smc_listen_work OffsetBits:13504 SizeBits:256] map[Name:accept_q OffsetBits:13760 SizeBits:128] map[Name:accept_q_lock OffsetBits:13888 SizeBits:32] map[Name:limit_smc_hs OffsetBits:13920 SizeBits:8] map[Name:use_fallback OffsetBits:13928 SizeBits:8] map[Name:fallback_rsn OffsetBits:13952 SizeBits:32] map[Name:peer_diagnosis OffsetBits:13984 SizeBits:32] map[Name:queued_smc_hs OffsetBits:14016 SizeBits:32] map[Name:af_ops OffsetBits:14080 SizeBits:640] map[Name:ori_af_ops OffsetBits:14720 SizeBits:64] map[Name:sockopt_defer_accept OffsetBits:14784 SizeBits:32] map[Name:wait_close_tx_prepared OffsetBits:14816 SizeBits:1] map[Name:connect_nonblock OffsetBits:14817 SizeBits:1] map[Name:clcsock_release_lock OffsetBits:14848 SizeBits:256]]]
|
| 12/2 |
2026/02/23 14:48 |
llm |
expert |
0m
Model:
Tokens:
input: 10220
output: 43
thoughts: 935
Thoughts: **Analyzing a Potential Race Condition in SMC Fallback Handling**
Okay, so I'm looking at this `use_fallback` flag at offset 13928 bits, or 1741 bytes. It's a single byte. My immediate thought is, "Okay, this seems small, what are the implications?". I see it used in `smc_poll` like this:
```c
2883: if (smc->use_fallback) {
...
2898: } else if (smc->use_fallback) { /* as result of connect_work()*/
```
The worry here is the compiler could optimize and read `smc->use_fallback` only once. If that happens, and the flag changes in between the reads, we might miss the update. But, realistically, even if that happens, the `smc_poll` function will just return based on the cached value of that `use_fallback` flag. So, it feels like a benign race on a status flag; no immediate red flags, but let's keep going.
My next question is whether there's any other state that must be consistent with `use_fallback`. Let's look at where it gets set: `smc_switch_to_fallback`.
```c
927: smc->use_fallback = true;
928: smc->fallback_rsn = reason_code;
929: smc_stat_fallback(smc);
930: trace_smc_switch_to_fallback(smc, reason_code);
931: if (smc->sk.sk_socket && smc->sk.sk_socket->file) {
932: smc->clcsock->file = smc->sk.sk_socket->file;
933: smc->clcsock->file->private_data = smc->clcsock;
...
942: smc_fback_replace_callbacks(smc);
943: }
```
Now, it looks like `smc_poll` relies on `smc->clcsock` if `use_fallback` is `true`. `smc->clcsock` gets set up during the socket creation or the connection process. If `use_fallback` is true, then `smc_poll` will call the poll operation of the `smc->clcsock` object. I think `smc_poll` assumes that if `use_fallback` is true, then `smc->clcsock` is valid.
It seems like in `smc_switch_to_fallback` there is a check for `if (!smc->clcsock)`. So maybe the check is fine. However, then the race comes in because `smc_poll` doesn't do a `NULL` check before dereferencing `smc->clcsock` and calling the poll operation.
The core of the issue is this race condition. If `smc_poll` reads `use_fallback` as `true`, it goes ahead and calls `clcsock->ops->poll`. But, if `smc_switch_to_fallback` is *also* running, it might still be in the middle of updating `smc->clcsock->file` or replacing the callbacks. And that makes me pause: `smc_poll` is passing `file` to `clcsock->ops->poll`.
Specifically, in `smc_switch_to_fallback`:
```c
932: smc->clcsock->file = smc->sk.sk_socket->file;
933: smc->clcsock->file->private_data = smc->clcsock;
```
This is where the `file`'s `private_data` is changing. It's being set to point to the `clcsock` instead of the `smc_sock`. Then I remind myself: `smc_poll` is called with the original `file` and `sock`. `sock` is `smc->sk.sk_socket`.
If `smc_poll` calls `clcsock->ops->poll(file, smc->clcsock, wait)`, the original `file` is passed. Most poll implementations I know, like `tcp_poll`, use the *socket* (`sock`, in this case `smc->sk.sk_socket`) passed to the poll function, not the `file`. Let me quickly confirm this by checking `
|
| 13/2 |
2026/02/23 14:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/ipv4/tcp_ipv4.c IncludeLines:true Name:tcp_poll]
Results: map[SourceCode: 534: /*
535: * Wait for a TCP event.
536: *
537: * Note that we don't need to lock the socket, as the upper poll layers
538: * take care of normal races (between the test and the event) and we don't
539: * go look at any of the socket buffers directly.
540: */
541: __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
542: {
543: __poll_t mask;
544: struct sock *sk = sock->sk;
545: const struct tcp_sock *tp = tcp_sk(sk);
546: u8 shutdown;
547: int state;
548:
549: sock_poll_wait(file, sock, wait);
550:
551: state = inet_sk_state_load(sk);
552: if (state == TCP_LISTEN)
553: return inet_csk_listen_poll(sk);
554:
555: /* Socket is not locked. We are protected from async events
556: * by poll logic and correct handling of state changes
557: * made by other threads is impossible in any case.
558: */
559:
560: mask = 0;
561:
562: /*
563: * EPOLLHUP is certainly not done right. But poll() doesn't
564: * have a notion of HUP in just one direction, and for a
565: * socket the read side is more interesting.
566: *
567: * Some poll() documentation says that EPOLLHUP is incompatible
568: * with the EPOLLOUT/POLLWR flags, so somebody should check this
569: * all. But careful, it tends to be safer to return too many
570: * bits than too few, and you can easily break real applications
571: * if you don't tell them that something has hung up!
572: *
573: * Check-me.
574: *
575: * Check number 1. EPOLLHUP is _UNMASKABLE_ event (see UNIX98 and
576: * our fs/select.c). It means that after we received EOF,
577: * poll always returns immediately, making impossible poll() on write()
578: * in state CLOSE_WAIT. One solution is evident --- to set EPOLLHUP
579: * if and only if shutdown has been made in both directions.
580: * Actually, it is interesting to look how Solaris and DUX
581: * solve this dilemma. I would prefer, if EPOLLHUP were maskable,
582: * then we could set it on SND_SHUTDOWN. BTW examples given
583: * in Stevens' books assume exactly this behaviour, it explains
584: * why EPOLLHUP is incompatible with EPOLLOUT. --ANK
585: *
586: * NOTE. Check for TCP_CLOSE is added. The goal is to prevent
587: * blocking on fresh not-connected or disconnected socket. --ANK
588: */
589: shutdown = READ_ONCE(sk->sk_shutdown);
590: if (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE)
591: mask |= EPOLLHUP;
592: if (shutdown & RCV_SHUTDOWN)
593: mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
594:
595: /* Connected or passive Fast Open socket? */
596: if (state != TCP_SYN_SENT &&
597: (state != TCP_SYN_RECV || rcu_access_pointer(tp->fastopen_rsk))) {
598: int target = sock_rcvlowat(sk, 0, INT_MAX);
599: u16 urg_data = READ_ONCE(tp->urg_data);
600:
601: if (unlikely(urg_data) &&
602: READ_ONCE(tp->urg_seq) == READ_ONCE(tp->copied_seq) &&
603: !sock_flag(sk, SOCK_URGINLINE))
604: target++;
605:
606: if (tcp_stream_is_readable(sk, target))
607: mask |= EPOLLIN | EPOLLRDNORM;
608:
609: if (!(shutdown & SEND_SHUTDOWN)) {
610: if (__sk_stream_is_writeable(sk, 1)) {
611: mask |= EPOLLOUT | EPOLLWRNORM;
612: } else { /* send SIGIO later */
613: sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
614: set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
615:
616: /* Race breaker. If space is freed after
617: * wspace test but before the flags are set,
618: * IO signal will be lost. Memory barrier
619: * pairs with the input side.
620: */
621: smp_mb__after_atomic();
622: if (__sk_stream_is_writeable(sk, 1))
623: mask |= EPOLLOUT | EPOLLWRNORM;
624: }
625: } else
626: mask |= EPOLLOUT | EPOLLWRNORM;
627:
628: if (urg_data & TCP_URG_VALID)
629: mask |= EPOLLPRI;
630: } else if (state == TCP_SYN_SENT &&
631: inet_test_bit(DEFER_CONNECT, sk)) {
632: /* Active TCP fastopen socket with defer_connect
633: * Return EPOLLOUT so application can call write()
634: * in order for kernel to generate SYN+data
635: */
636: mask |= EPOLLOUT | EPOLLWRNORM;
637: }
638: /* This barrier is coupled with smp_wmb() in tcp_done_with_error() */
639: smp_rmb();
640: if (READ_ONCE(sk->sk_err) ||
641: !skb_queue_empty_lockless(&sk->sk_error_queue))
642: mask |= EPOLLERR;
643:
644: return mask;
645: }
SourceFile:net/ipv4/tcp.c]
|
| 14/2 |
2026/02/23 14:48 |
llm |
expert |
0m
Model:
Tokens:
input: 14113
output: 44
thoughts: 386
Thoughts: **Analyzing the `smc_poll` Function**
Okay, so I'm thinking through this `smc_poll` function. It's pretty clear that `tcp_poll` uses `sock->sk`, as expected. Now, in `smc_poll`, when it's delegating the polling operation, it's passing `smc->clcsock` as the `sock` argument, specifically here:
```c
2885: mask = smc->clcsock->ops->poll(file, smc->clcsock, wait);
```
The question that arises is how changes to `smc->clcsock->file`, potentially triggered by `smc_switch_to_fallback` concurrent execution, affect `smc_poll`. However, it doesn't appear that `smc_poll` actually *uses* that field. It primarily cares about `smc->clcsock` itself.
The race condition around `use_fallback` seems to be about the chosen code path. If the SMC path is erroneously taken when it *should* have been fallback, the returned mask might be slightly off. But, since `poll` is inherently racy anyway, a bit of imprecision probably isn't the end of the world.
Wait, I need to consider a more complex race. Could `smc_poll` read `use_fallback == false` at line 2883, then the value flip to `true`, and then read `use_fallback == true` again at 2898? If that happens, then it will call `smc->clcsock->ops->poll`, and I believe this will be fine.
But what if it reads `false` at *both* of those points, but it's actually in fallback? That would lead it to using SMC logic. The SMC path is where things get interesting, using `smc->conn.sndbuf_space` and `smc->conn.bytes_to_rcv`. If we're actually in fallback, these might not be updated correctly. But, if we *just* switched to fallback, they should still hold the values from before the switch, right?
The last thing I need to check is whether there is any possibility of a NULL pointer dereference. The key here is `smc->clcsock`. I believe it's initialized in `smc_create`, but I really need to verify that to be 100% sure. I'll double-check `smc_create`'s implementation.
|
| 15/2 |
2026/02/23 14:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:smc_create]
Results: map[SourceCode:3360: static int smc_create(struct net *net, struct socket *sock, int protocol,
3361: int kern)
3362: {
3363: int family = (protocol == SMCPROTO_SMC6) ? PF_INET6 : PF_INET;
3364: struct sock *sk;
3365: int rc;
3366:
3367: rc = -ESOCKTNOSUPPORT;
3368: if (sock->type != SOCK_STREAM)
3369: goto out;
3370:
3371: rc = -EPROTONOSUPPORT;
3372: if (protocol != SMCPROTO_SMC && protocol != SMCPROTO_SMC6)
3373: goto out;
3374:
3375: rc = -ENOBUFS;
3376: sock->ops = &smc_sock_ops;
3377: sock->state = SS_UNCONNECTED;
3378: sk = smc_sock_alloc(net, sock, protocol);
3379: if (!sk)
3380: goto out;
3381:
3382: rc = smc_create_clcsk(net, sk, family);
3383: if (rc) {
3384: sk_common_release(sk);
3385: sock->sk = NULL;
3386: }
3387: out:
3388: return rc;
3389: }
SourceFile:net/smc/af_smc.c]
|
| 16/2 |
2026/02/23 14:48 |
llm |
expert |
0m
Model:
Tokens:
input: 15539
output: 48
thoughts: 63
Thoughts: Here's my take on the process, playing the role of the expert:
**Analyzing `smc_create_clcsk` Allocation**
Alright, so the code's calling `smc_create_clcsk`. My initial thought is that this function is responsible for allocating the `smc->clcsock` structure. That's a pretty fundamental operation in the SMC (Shared Memory Communications) networking context. I need to understand what this `clcsock` represents and how it fits into the overall data flow. The parameters are passed as 'net' (likely the network namespace) , 'sk' (probably the underlying socket), and 'family'. This suggests that the function likely initializes and sets up the necessary socket-specific context for this connection. I want to check how the return code `rc` is used and if any cleanup actions are implemented. Let's dig into the details of `smc_create_clcsk` to ensure everything is initialized correctly, any failure cases are handled, and resources are allocated as expected. I need to make sure there are no memory leaks or resource allocation issues here.
|
| 17/2 |
2026/02/23 14:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:smc_create_clcsk]
Results: map[SourceCode:3340: int smc_create_clcsk(struct net *net, struct sock *sk, int family)
3341: {
3342: struct smc_sock *smc = smc_sk(sk);
3343: int rc;
3344:
3345: rc = sock_create_kern(net, family, SOCK_STREAM, IPPROTO_TCP,
3346: &smc->clcsock);
3347: if (rc)
3348: return rc;
3349:
3350: /* smc_clcsock_release() does not wait smc->clcsock->sk's
3351: * destruction; its sk_state might not be TCP_CLOSE after
3352: * smc->sk is close()d, and TCP timers can be fired later,
3353: * which need net ref.
3354: */
3355: sk = smc->clcsock->sk;
3356: sk_net_refcnt_upgrade(sk);
3357: return 0;
3358: }
SourceFile:net/smc/af_smc.c]
|
| 18/2 |
2026/02/23 14:48 |
llm |
expert |
0m
Model:
Tokens:
input: 16223
output: 46
thoughts: 3464
Thoughts: **Analyzing the smc_poll and fallback mechanism for potential race conditions.**
Alright, let's break this down. It looks like the core issue revolves around how the `smc_poll` function interacts with the fallback mechanism, specifically when the `use_fallback` flag is set to true. The concern is a potential NULL pointer dereference on `smc->clcsock` if `smc_clcsock_release` runs concurrently, setting it to NULL after the check in `smc_poll` at line 2883 but before line 2885, where it's used.
My initial thought was the locking, or lack thereof. `smc_poll` doesn't appear to hold the `clcsock_release_lock`. However, on further reflection, if `smc_release` *were* called while `smc_poll` was running, that'd be a problem but shouldn't happen because the file descriptor has a reference. `smc_release` calls `smc_clcsock_release` and `smc_clcsock_release` is called when the last reference to the `struct socket` is gone.
The race is likely on the `use_fallback` flag, which can change concurrently with `smc_poll`. KCSAN is flagging this because it's unsynchronized. In kernel practice, for booleans like this, `READ_ONCE` and `WRITE_ONCE` are often used to prevent compiler optimizations from causing problems, though a single-byte `bool` is likely atomic.
Now, looking deeper at the code, particularly the double check of `use_fallback` within `smc_poll`, it's clear the design anticipates `use_fallback` potentially changing mid-execution, which is why it's re-checked. The comment at line 2898 suggests it's a consequence of the `connect_work` which also calls `smc_switch_to_fallback`. The use of `READ_ONCE` would be ideal in these circumstances to prevent a compiler from assuming the value doesn't change.
So if `smc_poll` reads `true` but `smc_switch_to_fallback` hasn't completely finished, the worry is a partially initialized `smc->clcsock`. But the code in `smc_switch_to_fallback` checks `clcsock` is valid. `smc->clcsock->ops` is set upon creation, so the only concern I see is what happens to the callbacks of the sock.
If we delegate to the `clcsock->ops->poll` function, we pass the same wait queue that `smc_poll` is using. That is correct. The other callbacks are replaced, which are for waking up other processes.
My final thought is this race is likely benign, from the perspective of memory corruption. However, for KCSAN, `READ_ONCE`/`WRITE_ONCE` should probably be used on `use_fallback` to eliminate an unsynchronized access. The true concern is that `smc_connect_work` can be running concurrently, so the code is being run on the same `smc_sock` object from multiple threads.
|
| 19/2 |
2026/02/23 14:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:smc_connect_work]
Results: map[SourceCode:1595: static void smc_connect_work(struct work_struct *work)
1596: {
1597: struct smc_sock *smc = container_of(work, struct smc_sock,
1598: connect_work);
1599: long timeo = READ_ONCE(smc->sk.sk_sndtimeo);
1600: int rc = 0;
1601:
1602: if (!timeo)
1603: timeo = MAX_SCHEDULE_TIMEOUT;
1604: lock_sock(smc->clcsock->sk);
1605: if (smc->clcsock->sk->sk_err) {
1606: smc->sk.sk_err = smc->clcsock->sk->sk_err;
1607: } else if ((1 << smc->clcsock->sk->sk_state) &
1608: (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
1609: rc = sk_stream_wait_connect(smc->clcsock->sk, &timeo);
1610: if ((rc == -EPIPE) &&
1611: ((1 << smc->clcsock->sk->sk_state) &
1612: (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)))
1613: rc = 0;
1614: }
1615: release_sock(smc->clcsock->sk);
1616: lock_sock(&smc->sk);
1617: if (rc != 0 || smc->sk.sk_err) {
1618: smc->sk.sk_state = SMC_CLOSED;
1619: if (rc == -EPIPE || rc == -EAGAIN)
1620: smc->sk.sk_err = EPIPE;
1621: else if (rc == -ECONNREFUSED)
1622: smc->sk.sk_err = ECONNREFUSED;
1623: else if (signal_pending(current))
1624: smc->sk.sk_err = -sock_intr_errno(timeo);
1625: sock_put(&smc->sk); /* passive closing */
1626: goto out;
1627: }
1628:
1629: rc = __smc_connect(smc);
1630: if (rc < 0)
1631: smc->sk.sk_err = -rc;
1632:
1633: out:
1634: if (!sock_flag(&smc->sk, SOCK_DEAD)) {
1635: if (smc->sk.sk_err) {
1636: smc->sk.sk_state_change(&smc->sk);
1637: } else { /* allow polling before and after fallback decision */
1638: smc->clcsock->sk->sk_write_space(smc->clcsock->sk);
1639: smc->sk.sk_write_space(&smc->sk);
1640: }
1641: }
1642: release_sock(&smc->sk);
1643: }
SourceFile:net/smc/af_smc.c]
|
| 20/2 |
2026/02/23 14:49 |
llm |
expert |
0m
Model:
Tokens:
input: 21346
output: 45
thoughts: 28
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and written as if they were my own immediate processing:
**Diving into the SMC Connection Process**
Alright, so `smc_connect_work` kicks things off. My immediate instinct is to look at the function call it makes, which is `__smc_connect`. The name implies this is where the *real* connection establishment is happening. Let's see what we can glean from `__smc_connect` itself. I'm assuming that `smc_connect_work` is likely just a wrapper or perhaps some work queue interface to handle the connection asynchronously. But let's get into the low-level details of how we're actually making this connection.
|
| 21/2 |
2026/02/23 14:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/af_smc.c IncludeLines:true Name:__smc_connect]
Results: map[SourceCode:1504: /* perform steps before actually connecting */
1505: static int __smc_connect(struct smc_sock *smc)
1506: {
1507: u8 version = smc_ism_is_v2_capable() ? SMC_V2 : SMC_V1;
1508: struct smc_clc_msg_accept_confirm *aclc;
1509: struct smc_init_info *ini = NULL;
1510: u8 *buf = NULL;
1511: int rc = 0;
1512:
1513: if (smc->use_fallback)
1514: return smc_connect_fallback(smc, smc->fallback_rsn);
1515:
1516: /* if peer has not signalled SMC-capability, fall back */
1517: if (!tcp_sk(smc->clcsock->sk)->syn_smc)
1518: return smc_connect_fallback(smc, SMC_CLC_DECL_PEERNOSMC);
1519:
1520: /* IPSec connections opt out of SMC optimizations */
1521: if (using_ipsec(smc))
1522: return smc_connect_decline_fallback(smc, SMC_CLC_DECL_IPSEC,
1523: version);
1524:
1525: ini = kzalloc(sizeof(*ini), GFP_KERNEL);
1526: if (!ini)
1527: return smc_connect_decline_fallback(smc, SMC_CLC_DECL_MEM,
1528: version);
1529:
1530: ini->smcd_version = SMC_V1 | SMC_V2;
1531: ini->smcr_version = SMC_V1 | SMC_V2;
1532: ini->smc_type_v1 = SMC_TYPE_B;
1533: ini->smc_type_v2 = SMC_TYPE_B;
1534:
1535: /* get vlan id from IP device */
1536: if (smc_vlan_by_tcpsk(smc->clcsock, ini)) {
1537: ini->smcd_version &= ~SMC_V1;
1538: ini->smcr_version = 0;
1539: ini->smc_type_v1 = SMC_TYPE_N;
1540: }
1541:
1542: rc = smc_find_proposal_devices(smc, ini);
1543: if (rc)
1544: goto fallback;
1545:
1546: buf = kzalloc(SMC_CLC_MAX_ACCEPT_LEN, GFP_KERNEL);
1547: if (!buf) {
1548: rc = SMC_CLC_DECL_MEM;
1549: goto fallback;
1550: }
1551: aclc = (struct smc_clc_msg_accept_confirm *)buf;
1552:
1553: /* perform CLC handshake */
1554: rc = smc_connect_clc(smc, aclc, ini);
1555: if (rc) {
1556: /* -EAGAIN on timeout, see tcp_recvmsg() */
1557: if (rc == -EAGAIN) {
1558: rc = -ETIMEDOUT;
1559: smc->sk.sk_err = ETIMEDOUT;
1560: }
1561: goto vlan_cleanup;
1562: }
1563:
1564: /* check if smc modes and versions of CLC proposal and accept match */
1565: rc = smc_connect_check_aclc(ini, aclc);
1566: version = aclc->hdr.version == SMC_V1 ? SMC_V1 : SMC_V2;
1567: if (rc)
1568: goto vlan_cleanup;
1569:
1570: /* depending on previous steps, connect using rdma or ism */
1571: if (aclc->hdr.typev1 == SMC_TYPE_R) {
1572: ini->smcr_version = version;
1573: rc = smc_connect_rdma(smc, aclc, ini);
1574: } else if (aclc->hdr.typev1 == SMC_TYPE_D) {
1575: ini->smcd_version = version;
1576: rc = smc_connect_ism(smc, aclc, ini);
1577: }
1578: if (rc)
1579: goto vlan_cleanup;
1580:
1581: SMC_STAT_CLNT_SUCC_INC(sock_net(smc->clcsock->sk), aclc);
1582: smc_connect_ism_vlan_cleanup(ini);
1583: kfree(buf);
1584: kfree(ini);
1585: return 0;
1586:
1587: vlan_cleanup:
1588: smc_connect_ism_vlan_cleanup(ini);
1589: kfree(buf);
1590: fallback:
1591: kfree(ini);
1592: return smc_connect_decline_fallback(smc, rc, version);
1593: }
SourceFile:net/smc/af_smc.c]
|
| 22/2 |
2026/02/23 14:49 |
llm |
expert |
1m
Model:
Tokens:
input: 23104
output: 26
thoughts: 10660
Thoughts: **Analysis of a Potential Data Race in SMC Fallback Mechanism**
Okay, here's the deal, as I understand it. I've been looking closely at this reported data race involving the `smc_poll` function and the `smc_switch_to_fallback` function in the Linux kernel's SMC (Shared Memory Communications) code. The race centers around the `use_fallback` flag within the `smc_sock` structure.
The core of the issue is this: `__smc_connect` can trigger a fallback to TCP using the `smc_switch_to_fallback` function. This sets a few things, most importantly, `smc->use_fallback` to true, and then later replaces callbacks with tcp ones. Now, `smc_poll` is called in the same context as `__smc_connect` and `smc_switch_to_fallback`, and we've got a classic race condition. It's perfectly conceivable that `smc_poll` could read `use_fallback` *after* `smc_switch_to_fallback` has been called but *before* `smc->use_fallback` has been set to true, or even when the TCP callback replacement hasn't finished yet.
If `smc_poll` reads `use_fallback` as `false`, it continues with its regular SMC-specific logic. But what happens if, *during* the execution of the SMC code, `smc_switch_to_fallback` completes and *then* the poll continues? Well, it's possible that on the next `poll` call, the `use_fallback` flag might be set. It's also possible that it would stay false if a compiler caches the boolean. We also need to consider what happens if `smc_poll` is interrupted, the flag changes, and then `smc_poll` continues.
Now, let's break this down. Line 2883 of `smc_poll`: `if (smc->use_fallback)`. Line 2898 in the `else` block: `} else if (smc->use_fallback) {` The KCSAN report is reporting a race on this line. If the first read is false, and then a state transition happens, and now the read is true. The issue is really the `WRITE` on the `use_fallback` flag not being atomic with the subsequent `READ`. Without proper memory barriers, this means that different CPUs or threads could have inconsistent views of the `use_fallback` flag's value. Without synchronization, the compiler can optimize away one of the reads.
If `smc_poll` sees `use_fallback` as `true`, it delegates to the TCP socket (the `clcsock`) using `smc->clcsock->ops->poll(file, smc->clcsock, wait)`. This *could* be a problem. This means there's a switchover to TCP. I then need to make sure that callbacks are correct. The key is in `smc_fback_replace_callbacks`. This switches out the socket operations and ensures the data ready and write space callbacks point to the `clcsock`'s code.
The question is, what happens if this switchover isn't fully complete when the `clcsock`'s `poll` function gets called? `tcp_poll`, which is the `clcsock->ops->poll` function, uses the file descriptor's `wait_queue`. This means that `poll` could add its waiter to the wait queue for the old `smc_sock`, or it could have already added to the queue of the `clcsock`.
So, *initially*, the `smc_sock`'s callbacks are in place (while in the `smc_poll` method). When `smc_switch_to_fallback` happens it replaces these callbacks. But the `tcp_poll` routine just uses the wait queue to wake up the poll. So, even if the callbacks haven't been swapped out, the waiters will still get woken up.
Now, this seems fine. I need to double check that this won't lead to a NULL pointer dereference or the `clcsock` being released early. It won't. I've considered that scenario. The `smc_sock` and the `clcsock` *must* exist as long as the file descriptor exists. `smc_clcsock_release` and `smc_release` are well synchronized.
Even if `use_fallback` might return the incorrect boolean value, it will *not* cause a crash. Because the poll mechanism has a race breaker and it
|
| 23/2 |
2026/02/23 14:50 |
tool |
codesearch-find-references |
0m
Args: map[Name:smc_clcsock_release]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__smc_release SourceFile:net/smc/af_smc.c SourceLine:304] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smc_close_active_abort SourceFile:net/smc/smc_close.c SourceLine:182] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:smc_close_passive_work SourceFile:net/smc/smc_close.c SourceLine:443]] TruncatedOutput:false]
|
| 24/2 |
2026/02/23 14:50 |
llm |
expert |
0m
Model:
Tokens:
input: 35000
output: 48
thoughts: 51
Thoughts: Okay, let's see, what did I miss? Hang on a second... Ah, yes! I skipped over a few key functions: `__smc_release`, `smc_close_active_abort`, and `smc_close_passive_work`. Right, I knew something felt incomplete.
**Focusing on smc_close_active_abort**
Now, before I dive too deeply, let's zoom in on `smc_close_active_abort`. That function is crucial, I need to understand this part. Let me see where I am.
|
| 25/2 |
2026/02/23 14:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/smc_close.c IncludeLines:true Name:smc_close_active_abort]
Results: map[SourceCode: 125: /* terminate smc socket abnormally - active abort
126: * link group is terminated, i.e. RDMA communication no longer possible
127: */
128: void smc_close_active_abort(struct smc_sock *smc)
129: {
130: struct sock *sk = &smc->sk;
131: bool release_clcsock = false;
132:
133: if (sk->sk_state != SMC_INIT && smc->clcsock && smc->clcsock->sk) {
134: sk->sk_err = ECONNABORTED;
135: if (smc->clcsock && smc->clcsock->sk)
136: tcp_abort(smc->clcsock->sk, ECONNABORTED);
137: }
138: switch (sk->sk_state) {
139: case SMC_ACTIVE:
140: case SMC_APPCLOSEWAIT1:
141: case SMC_APPCLOSEWAIT2:
142: sk->sk_state = SMC_PEERABORTWAIT;
143: smc_close_cancel_work(smc);
144: if (sk->sk_state != SMC_PEERABORTWAIT)
145: break;
146: sk->sk_state = SMC_CLOSED;
147: sock_put(sk); /* (postponed) passive closing */
148: break;
149: case SMC_PEERCLOSEWAIT1:
150: case SMC_PEERCLOSEWAIT2:
151: case SMC_PEERFINCLOSEWAIT:
152: sk->sk_state = SMC_PEERABORTWAIT;
153: smc_close_cancel_work(smc);
154: if (sk->sk_state != SMC_PEERABORTWAIT)
155: break;
156: sk->sk_state = SMC_CLOSED;
157: smc_conn_free(&smc->conn);
158: release_clcsock = true;
159: sock_put(sk); /* passive closing */
160: break;
161: case SMC_PROCESSABORT:
162: case SMC_APPFINCLOSEWAIT:
163: sk->sk_state = SMC_PEERABORTWAIT;
164: smc_close_cancel_work(smc);
165: if (sk->sk_state != SMC_PEERABORTWAIT)
166: break;
167: sk->sk_state = SMC_CLOSED;
168: smc_conn_free(&smc->conn);
169: release_clcsock = true;
170: break;
171: case SMC_INIT:
172: case SMC_PEERABORTWAIT:
173: case SMC_CLOSED:
174: break;
175: }
176:
177: smc_sock_set_flag(sk, SOCK_DEAD);
178: sk->sk_state_change(sk);
179:
180: if (release_clcsock) {
181: release_sock(sk);
182: smc_clcsock_release(smc);
183: lock_sock(sk);
184: }
185: }
SourceFile:net/smc/smc_close.c]
|
| 26/2 |
2026/02/23 14:50 |
llm |
expert |
0m
Model:
Tokens:
input: 36214
output: 48
thoughts: 367
Thoughts: **Analyzing a Potential Race Condition in SMC Connection Closure**
Okay, so I'm thinking through this potential issue with the SMC connection management. It seems `smc_close_active_abort` can call `smc_clcsock_release`, which makes sense because it's called when RDMA communication becomes unavailable. My concern is, could `smc_close_active_abort` be called while `smc_poll` is still running? That *could* be a race condition. But, generally, `smc_close_active_abort` is invoked during connection teardown, so it's probably unlikely.
Wait a second, `smc_poll` checks `use_fallback`, which indicates whether to utilize TCP fallback. When RDMA is active, `use_fallback` is `false`. So, if `smc_close_active_abort` *is* called, does it then set `use_fallback` to `true`? No, it doesn't appear to. Instead, it sets `sk->sk_state = SMC_CLOSED`. Okay, so let me consider how this plays out.
If `use_fallback` is `false`, meaning we're using RDMA, `smc_poll` utilizes SMC logic. The SMC logic checks `sk->sk_state`. Specifically, that code snippet... if `sk->sk_state != SMC_CLOSED`, it waits. If it *is* `SMC_CLOSED`, it returns `EPOLLHUP`. So, if `use_fallback` is `false`, it looks like we're safe. `smc_poll` will catch the change in state and handle it appropriately.
Now, what if `use_fallback` is `true`? Well, the scenario probably doesn't apply. If `use_fallback` is already `true`, it indicates we're *already* in fallback mode, using TCP, so RDMA link group termination wouldn't affect us in this way. We're not using RDMA in fallback mode, so we should be fine. I should also check `smc_close_passive_work`, just to be certain.
|
| 27/2 |
2026/02/23 14:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/smc/smc_close.c IncludeLines:true Name:smc_close_passive_work]
Results: map[SourceCode: 352: /* Either some kind of closing has been received: peer_conn_closed,
353: * peer_conn_abort, or peer_done_writing
354: * or the link group of the connection terminates abnormally.
355: */
356: static void smc_close_passive_work(struct work_struct *work)
357: {
358: struct smc_connection *conn = container_of(work,
359: struct smc_connection,
360: close_work);
361: struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
362: struct smc_cdc_conn_state_flags *rxflags;
363: bool release_clcsock = false;
364: struct sock *sk = &smc->sk;
365: int old_state;
366:
367: lock_sock(sk);
368: old_state = sk->sk_state;
369:
370: rxflags = &conn->local_rx_ctrl.conn_state_flags;
371: if (rxflags->peer_conn_abort) {
372: /* peer has not received all data */
373: smc_close_passive_abort_received(smc);
374: release_sock(sk);
375: cancel_delayed_work_sync(&conn->tx_work);
376: lock_sock(sk);
377: goto wakeup;
378: }
379:
380: switch (sk->sk_state) {
381: case SMC_INIT:
382: sk->sk_state = SMC_APPCLOSEWAIT1;
383: break;
384: case SMC_ACTIVE:
385: sk->sk_state = SMC_APPCLOSEWAIT1;
386: /* postpone sock_put() for passive closing to cover
387: * received SEND_SHUTDOWN as well
388: */
389: break;
390: case SMC_PEERCLOSEWAIT1:
391: if (rxflags->peer_done_writing)
392: sk->sk_state = SMC_PEERCLOSEWAIT2;
393: fallthrough;
394: /* to check for closing */
395: case SMC_PEERCLOSEWAIT2:
396: if (!smc_cdc_rxed_any_close(conn))
397: break;
398: if (sock_flag(sk, SOCK_DEAD) &&
399: smc_close_sent_any_close(conn)) {
400: /* smc_release has already been called locally */
401: sk->sk_state = SMC_CLOSED;
402: } else {
403: /* just shutdown, but not yet closed locally */
404: sk->sk_state = SMC_APPFINCLOSEWAIT;
405: }
406: sock_put(sk); /* passive closing */
407: break;
408: case SMC_PEERFINCLOSEWAIT:
409: if (smc_cdc_rxed_any_close(conn)) {
410: sk->sk_state = SMC_CLOSED;
411: sock_put(sk); /* passive closing */
412: }
413: break;
414: case SMC_APPCLOSEWAIT1:
415: case SMC_APPCLOSEWAIT2:
416: /* postpone sock_put() for passive closing to cover
417: * received SEND_SHUTDOWN as well
418: */
419: break;
420: case SMC_APPFINCLOSEWAIT:
421: case SMC_PEERABORTWAIT:
422: case SMC_PROCESSABORT:
423: case SMC_CLOSED:
424: /* nothing to do, add tracing in future patch */
425: break;
426: }
427:
428: wakeup:
429: sk->sk_data_ready(sk); /* wakeup blocked rcvbuf consumers */
430: sk->sk_write_space(sk); /* wakeup blocked sndbuf producers */
431:
432: if (old_state != sk->sk_state) {
433: sk->sk_state_change(sk);
434: if ((sk->sk_state == SMC_CLOSED) &&
435: (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) {
436: smc_conn_free(conn);
437: if (smc->clcsock)
438: release_clcsock = true;
439: }
440: }
441: release_sock(sk);
442: if (release_clcsock)
443: smc_clcsock_release(smc);
444: sock_put(sk); /* sock_hold done by schedulers of close_work */
445: }
SourceFile:net/smc/smc_close.c]
|
| 28/2 |
2026/02/23 14:50 |
llm |
expert |
0m
Model:
Tokens:
input: 38555
output: 19
thoughts: 457
Thoughts: **Analyzing the smc_close_passive_work and smc_poll interactions**
Okay, let's break this down. `smc_close_passive_work` calls `smc_clcsock_release`, but only under specific conditions. It checks for `sock_flag(sk, SOCK_DEAD)` or if `!sk->sk_socket`. Now, `SOCK_DEAD` is set in `smc_release`, and the `!sk->sk_socket` condition also indicates socket closure.
The key is to understand the timing of these flags relative to `smc_poll`. If `smc_poll` is active, it should have a valid reference to the `socket` and `file`. Therefore, `SOCK_DEAD` shouldn't be set *yet*, or at the very least, the socket should still be valid.
But wait a minute, I see now. Looking at the code for `smc_release`, specifically, lines 211-212, `sock_orphan(sk)` sets `SOCK_DEAD` at the very *beginning* of the function!
```c
188: static int smc_release(struct socket *sock)
189: {
190: struct sock *sk = sock->sk;
191: struct smc_sock *smc;
...
202: smc = smc_sk(sk);
...
211: sock_hold(sk);
212: sock_orphan(sk);
```
However, `smc_release` is called when the *last* reference to the `struct socket` is gone. If `smc_poll` is running, then it has a reference, therefore preventing the socket from being orphaned.
Ah, but does `vfs_poll` even hold a reference to the `socket`? It doesn't seem to. It's called from a syscall that *already* has a reference to the `file`, which, in turn, holds a reference to the `socket`. This guarantees the `socket` can't be released while `smc_poll` is using it.
So, logically, `smc_clcsock_release` cannot be invoked while `smc_poll` is running. This means `smc->clcsock` is safe to access from within `smc_poll`.
The only remaining potential race condition is on the `use_fallback` flag, which I've concluded is not problematic.
Therefore, I'm confident in my conclusion and will provide the final answer.
|
| 29/2 |
2026/02/23 14:50 |
tool |
set-results |
0m
Args: map[Benign:true Confident:true]
Results: map[Benign:true Confident:true]
|
| 30/2 |
2026/02/23 14:50 |
llm |
expert |
0m
Model:
Tokens:
input: 39624
output: 672
thoughts: 333
Thoughts: **Analyzing the Benign Nature of This Data Race**
Okay, so I've been looking at this data race involving the `use_fallback` flag within this SMC socket implementation, and I'm pretty confident it's benign. Here's my breakdown:
First, `use_fallback` is basically a simple boolean. It acts as a switch, telling the SMC socket whether to just use its own logic, or to delegate operations to the underlying TCP socket (`clcsock`). The race comes into play during the transition where SMC decides RDMA isn't viable, and the socket needs to fall back to TCP.
What makes this benign is that the transition from `false` to `true` is a one-way street. Once the SMC decides to go TCP, it stays that way. `smc_poll` is the function handling this transition, specifically checking the flag. Even if `smc_poll` misses this change due to the race, it's not a catastrophic failure. It'll either keep using the SMC-specific logic (which is still okay, just maybe not optimal, for a short period), or it'll delegate to `clcsock`.
Critically, the `clcsock` itself is initialized when the `smc_sock` is created, and it remains valid until the `smc_sock` is destroyed. Because `smc_poll` is called on an active socket, represented by a file descriptor, I'm guaranteed that if `use_fallback` *is* true, `clcsock` will also be valid. No null pointer dereferences or anything like that.
Importantly, this race isn't leading to the kinds of problems we *really* worry about. No memory corruption, no crashes, no permanent hangs. Think about it: `poll` is inherently racy. The SMC implementation has to account for that, and it does. The implementation includes appropriate wakeups after the fallback transition, so any threads waiting on the socket will get a notification and will see the updated `use_fallback` state in the *next* `poll` call.
Finally, while using `READ_ONCE`/`WRITE_ONCE` to provide explicit memory ordering would be good hygiene to satisfy KCSAN, its absence *isn't* making this race harmful in a way that risks system instability. This isn't a critical section where missing an update would lead to chaos. It's a flag that can be temporarily stale, without catastrophic consequences. So, yeah, I'm comfortable labeling this one as benign.
|