mctp i3c: fix MCTP I3C driver multi-thread issue
authorLeo Yang <leo.yang.sy0@gmail.com>
Tue, 7 Jan 2025 03:15:30 +0000 (11:15 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 9 Jan 2025 10:52:38 +0000 (11:52 +0100)
commit2d2d4f60ed266a8f340a721102d035252606980b
tree1e61242f1fca123c3a9b3aaff6c0dfb527bf7db5
parentd1bf27c4e1768d4733143f26962a5c68ea8bd03c
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: c8755b29b58e ("mctp i3c: MCTP I3C driver")
Signed-off-by: Leo Yang <Leo-Yang@quantatw.com>
Link: https://patch.msgid.link/20250107031529.3296094-1-Leo-Yang@quantatw.com
[pabeni@redhat.com: dropped already answered question from changelog]
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/mctp/mctp-i3c.c