Skip to contentSkip to conversation

mctp i3c: fix MCTP I3C driver multi-thread issue

PATCH Applied Leo Yang 3 participants 3 messages Jan 7, 2025 – Jan 9, 2025

Subsystems (3)
lore
Share & tools
lore

Leo Yang

author
#0 lore raw

PATCH v2 1/1 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.

But I'm a little worried about the performance of mutex in high load situation (as spec seems to allow different endpoints to respond at the same time), do you think this is a feasible solution?

Fixes c8755b29b58e ("mctp i3c: MCTP I3C driver")

---
Change in v2:
1. Add Fixes tag.
2. Add mutex comment.
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
---

 drivers/net/mctp/mctp-i3c.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/mctp/mctp-i3c.c +4 -0
index 9adad59b8676..d247fe483c58 100644
@@ -125,6 +125,8 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
 
 	xfer.data.in = skb_put(skb, mi->mrl);
 
+	/* Make sure netif_rx() is read in the same order as i3c. */
+	mutex_lock(&mi->lock);
 	rc = i3c_device_do_priv_xfers(mi->i3c, &xfer, 1);
 	if (rc < 0)
 		goto err;
@@ -166,8 +168,10 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
 		stats->rx_dropped++;
 	}
 
+	mutex_unlock(&mi->lock);
 	return 0;
 err:
+	mutex_unlock(&mi->lock);
 	kfree_skb(skb);
 	return rc;
 }
Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 19 lines · Leo Yang

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.

Quoted 3 lines

But I'm a little worried about the performance of mutex in high load situation (as spec seems to allow different endpoints to respond at the same time), do you think this is a feasible solution?

For the record, I'm taking the liberty of dropping the above paragraph from the changelog, as the question IMHO should have been placed after the --- separator, has been already replied and repost just for this change would consume more time from everyone.

Cheers,

Paolo

#2 lore raw
In reply to Leo Yang
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Tue, 7 Jan 2025 11:15:30 +0800 you wrote:

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.

[...]

Here is the summary with links:
- [net,v2] mctp i3c: fix MCTP I3C driver multi-thread issue

    https://git.kernel.org/netdev/net/c/2d2d4f60ed26

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html