Commit 9cbd48d5 authored by Jeremy Kerr's avatar Jeremy Kerr Committed by Jakub Kicinski

mctp i2c: don't count unused / invalid keys for flow release

We're currently hitting the WARN_ON in mctp_i2c_flow_release:

    if (midev->release_count > midev->i2c_lock_count) {
        WARN_ONCE(1, "release count overflow");

This may be hit if we expire a flow before sending the first packet it
contains - as we will not be pairing the increment of release_count
(performed on flow release) with the i2c lock operation (only
performed on actual TX).

To fix this, only release a flow if we've encountered it previously (ie,
dev_flow_state does not indicate NEW), as we will mark the flow as
ACTIVE at the same time as accounting for the i2c lock operation. We
also need to add an INVALID flow state, to indicate when we've done the
release.

Fixes: f5b8abf9 ("mctp i2c: MCTP I2C binding driver")
Reported-by: default avatarJian Zhang <zhangjian.3032@bytedance.com>
Tested-by: default avatarJian Zhang <zhangjian.3032@bytedance.com>
Signed-off-by: default avatarJeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/20221110053135.329071-1-jk@codeconstruct.com.auSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 0834ced6
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
enum { enum {
MCTP_I2C_FLOW_STATE_NEW = 0, MCTP_I2C_FLOW_STATE_NEW = 0,
MCTP_I2C_FLOW_STATE_ACTIVE, MCTP_I2C_FLOW_STATE_ACTIVE,
MCTP_I2C_FLOW_STATE_INVALID,
}; };
/* List of all struct mctp_i2c_client /* List of all struct mctp_i2c_client
...@@ -374,12 +375,18 @@ mctp_i2c_get_tx_flow_state(struct mctp_i2c_dev *midev, struct sk_buff *skb) ...@@ -374,12 +375,18 @@ mctp_i2c_get_tx_flow_state(struct mctp_i2c_dev *midev, struct sk_buff *skb)
*/ */
if (!key->valid) { if (!key->valid) {
state = MCTP_I2C_TX_FLOW_INVALID; state = MCTP_I2C_TX_FLOW_INVALID;
} else {
} else if (key->dev_flow_state == MCTP_I2C_FLOW_STATE_NEW) { switch (key->dev_flow_state) {
case MCTP_I2C_FLOW_STATE_NEW:
key->dev_flow_state = MCTP_I2C_FLOW_STATE_ACTIVE; key->dev_flow_state = MCTP_I2C_FLOW_STATE_ACTIVE;
state = MCTP_I2C_TX_FLOW_NEW; state = MCTP_I2C_TX_FLOW_NEW;
} else { break;
case MCTP_I2C_FLOW_STATE_ACTIVE:
state = MCTP_I2C_TX_FLOW_EXISTING; state = MCTP_I2C_TX_FLOW_EXISTING;
break;
default:
state = MCTP_I2C_TX_FLOW_INVALID;
}
} }
spin_unlock_irqrestore(&key->lock, flags); spin_unlock_irqrestore(&key->lock, flags);
...@@ -617,21 +624,31 @@ static void mctp_i2c_release_flow(struct mctp_dev *mdev, ...@@ -617,21 +624,31 @@ static void mctp_i2c_release_flow(struct mctp_dev *mdev,
{ {
struct mctp_i2c_dev *midev = netdev_priv(mdev->dev); struct mctp_i2c_dev *midev = netdev_priv(mdev->dev);
bool queue_release = false;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&midev->lock, flags); spin_lock_irqsave(&midev->lock, flags);
/* if we have seen the flow/key previously, we need to pair the
* original lock with a release
*/
if (key->dev_flow_state == MCTP_I2C_FLOW_STATE_ACTIVE) {
midev->release_count++; midev->release_count++;
queue_release = true;
}
key->dev_flow_state = MCTP_I2C_FLOW_STATE_INVALID;
spin_unlock_irqrestore(&midev->lock, flags); spin_unlock_irqrestore(&midev->lock, flags);
if (queue_release) {
/* Ensure we have a release operation queued, through the fake /* Ensure we have a release operation queued, through the fake
* marker skb * marker skb
*/ */
spin_lock(&midev->tx_queue.lock); spin_lock(&midev->tx_queue.lock);
if (!midev->unlock_marker.next) if (!midev->unlock_marker.next)
__skb_queue_tail(&midev->tx_queue, &midev->unlock_marker); __skb_queue_tail(&midev->tx_queue,
&midev->unlock_marker);
spin_unlock(&midev->tx_queue.lock); spin_unlock(&midev->tx_queue.lock);
wake_up(&midev->tx_wq); wake_up(&midev->tx_wq);
}
} }
static const struct net_device_ops mctp_i2c_ops = { static const struct net_device_ops mctp_i2c_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment