Skip to content

Commit 2d2d4f6

Browse files
Leo YangPaolo Abeni
Leo Yang
authored and
Paolo Abeni
committed
mctp i3c: fix MCTP I3C driver multi-thread issue
We found a timeout problem with the pldm command on our system. The reason is that the MCTP-I3C driver has a race condition when receiving multiple-packet messages in multi-thread, resulting in a wrong packet order problem. We identified this problem by adding a debug message to the mctp_i3c_read function. According to the MCTP spec, a multiple-packet message must be composed in sequence, and if there is a wrong sequence, the whole message will be discarded and wait for the next SOM. For example, SOM → Pkt Seq #2 → Pkt Seq #1 → Pkt Seq #3 → EOM. Therefore, we try to solve this problem by adding a mutex to the mctp_i3c_read function. Before the modification, when a command requesting a multiple-packet message response is sent consecutively, an error usually occurs within 100 loops. After the mutex, it can go through 40000 loops without any error, and it seems to run well. Fixes: c8755b2 ("mctp i3c: MCTP I3C driver") Signed-off-by: Leo Yang <[email protected]> Link: https://patch.msgid.link/[email protected] [[email protected]: dropped already answered question from changelog] Signed-off-by: Paolo Abeni <[email protected]>
1 parent d1bf27c commit 2d2d4f6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/net/mctp/mctp-i3c.c

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
125125

126126
xfer.data.in = skb_put(skb, mi->mrl);
127127

128+
/* Make sure netif_rx() is read in the same order as i3c. */
129+
mutex_lock(&mi->lock);
128130
rc = i3c_device_do_priv_xfers(mi->i3c, &xfer, 1);
129131
if (rc < 0)
130132
goto err;
@@ -166,8 +168,10 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
166168
stats->rx_dropped++;
167169
}
168170

171+
mutex_unlock(&mi->lock);
169172
return 0;
170173
err:
174+
mutex_unlock(&mi->lock);
171175
kfree_skb(skb);
172176
return rc;
173177
}

0 commit comments

Comments
 (0)