Skip to contentSkip to conversation

MCTP flow support

PATCH Applied Jeremy Kerr 2 participants 5 messages Oct 29, 2021

Subsystems (3)
lore
Share & tools
lore

Jeremy Kerr

author maintainer
#0 lore raw

v2 cover MCTP flow support

For certain MCTP transport bindings, the binding driver will need to be aware of request/response pairing. For example, the i2c binding may need to set multiplexer configuration when expecting a response from a device behind a mux.

This series implements a mechanism for informing the driver about these flows, so it can implement transport-specific behaviour when a flow is in progress (ie, a response is expected, and/or we time-out on that expectation). We use a skb extension to notify the driver about the presence of a flow, and a new dev->ops callback to notify about a flow's destruction.

Cheers,

Jeremy

---
v2:
- add cover letter
- fix CONFIG combinations when MCTP_FLOWS=n

Jeremy Kerr (3):
mctp: Return new key from mctp_alloc_local_tag
mctp: Add flow extension to skb
mctp: Pass flow data & flow release events to drivers

 include/linux/skbuff.h   |  3 ++
 include/net/mctp.h       | 13 +++++++
 include/net/mctpdevice.h | 16 ++++++++
 net/core/skbuff.c        | 19 +++++++++
 net/mctp/Kconfig         |  7 +++-
 net/mctp/device.c        | 51 ++++++++++++++++++++++++
 net/mctp/route.c         | 83 +++++++++++++++++++++++++++++++++-------
 7 files changed, 177 insertions(+), 15 deletions(-)
Signature · 1 line
2.33.0
author maintainer
#1 lore raw

PATCH v2 1/3 mctp: Return new key from mctp_alloc_local_tag

In a future change, we will want the key available for future use after allocating a new tag. This change returns the key from mctp_alloc_local_tag, rather than just key->tag.

---
 net/mctp/route.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
net/mctp/route.c +16 -12
index c23ab3547ee5..82cc10a2fb0c 100644
@@ -532,14 +532,14 @@ static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,
 /* Allocate a locally-owned tag value for (saddr, daddr), and reserve
  * it for the socket msk
  */
-static int mctp_alloc_local_tag(struct mctp_sock *msk,
-				mctp_eid_t saddr, mctp_eid_t daddr, u8 *tagp)
+static struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
+						mctp_eid_t saddr,
+						mctp_eid_t daddr, u8 *tagp)
 {
 	struct net *net = sock_net(&msk->sk);
 	struct netns_mctp *mns = &net->mctp;
 	struct mctp_sk_key *key, *tmp;
 	unsigned long flags;
-	int rc = -EAGAIN;
 	u8 tagbits;
 
 	/* for NULL destination EIDs, we may get a response from any peer */
@@ -549,7 +549,7 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk,
 	/* be optimistic, alloc now */
 	key = mctp_key_alloc(msk, saddr, daddr, 0, GFP_KERNEL);
 	if (!key)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	/* 8 possible tag values */
 	tagbits = 0xff;
@@ -591,18 +591,16 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk,
 		trace_mctp_key_acquire(key);
 
 		*tagp = key->tag;
-		/* done with the key in this scope */
-		mctp_key_unref(key);
-		key = NULL;
-		rc = 0;
 	}
 
 	spin_unlock_irqrestore(&mns->keys_lock, flags);
 
-	if (!tagbits)
+	if (!tagbits) {
 		kfree(key);
+		return ERR_PTR(-EBUSY);
+	}
 
-	return rc;
+	return key;
 }
 
 /* routing lookups */
@@ -740,6 +738,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
 	struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk);
 	struct mctp_skb_cb *cb = mctp_cb(skb);
 	struct mctp_route tmp_rt;
+	struct mctp_sk_key *key;
 	struct net_device *dev;
 	struct mctp_hdr *hdr;
 	unsigned long flags;
@@ -799,11 +798,16 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
 		goto out_release;
 
 	if (req_tag & MCTP_HDR_FLAG_TO) {
-		rc = mctp_alloc_local_tag(msk, saddr, daddr, &tag);
-		if (rc)
+		key = mctp_alloc_local_tag(msk, saddr, daddr, &tag);
+		if (IS_ERR(key)) {
+			rc = PTR_ERR(key);
 			goto out_release;
+		}
+		/* done with the key in this scope */
+		mctp_key_unref(key);
 		tag |= MCTP_HDR_FLAG_TO;
 	} else {
+		key = NULL;
 		tag = req_tag;
 	}
 
Signature · 1 line
2.33.0
author maintainer
#2 lore raw

PATCH v2 2/3 mctp: Add flow extension to skb

In reply to Jeremy Kerr

This change adds a new skb extension for MCTP, to represent a request/response flow.

The intention is to use this in a later change to allow i2c controllers to correctly configure a multiplexer over a flow.

Since we have a cleanup function in the core path (if an extension is present), we'll need to make CONFIG_MCTP a bool, rather than a tristate.

Includes a fix for a build warning with clang:

---
v2:
- #ifdef CONFIG_MCTP, rather than #if
- fix CONFIG_SKB_EXTENSIONS && !CONFIG_MCTP_FLOWS build

---
 include/linux/skbuff.h |  3 +++
 include/net/mctp.h     |  7 +++++++
 net/core/skbuff.c      | 19 +++++++++++++++++++
 net/mctp/Kconfig       |  7 ++++++-
 4 files changed, 35 insertions(+), 1 deletion(-)
include/linux/skbuff.h +3 -0
index cb96f1e6460c..0bd6520329f6 100644
@@ -4243,6 +4243,9 @@ enum skb_ext_id {
 #endif
 #if IS_ENABLED(CONFIG_MPTCP)
 	SKB_EXT_MPTCP,
+#endif
+#if IS_ENABLED(CONFIG_MCTP_FLOWS)
+	SKB_EXT_MCTP,
 #endif
 	SKB_EXT_NUM, /* must be last */
 };
include/net/mctp.h +7 -0
index 23bec708f4c7..7a5ba801703c 100644
@@ -189,6 +189,13 @@ static inline struct mctp_skb_cb *mctp_cb(struct sk_buff *skb)
 	return (void *)(skb->cb);
 }
 
+/* If CONFIG_MCTP_FLOWS, we may add one of these as a SKB extension,
+ * indicating the flow to the device driver.
+ */
+struct mctp_flow {
+	struct mctp_sk_key *key;
+};
+
 /* Route definition.
  *
  * These are held in the pernet->mctp.routes list, with RCU protection for
net/core/skbuff.c +19 -0
index 74601bbc56ac..b948fd1c6f75 100644
@@ -70,6 +70,7 @@
 #include <net/xfrm.h>
 #include <net/mpls.h>
 #include <net/mptcp.h>
+#include <net/mctp.h>
 #include <net/page_pool.h>
 
 #include <linux/uaccess.h>
@@ -4430,6 +4431,9 @@ static const u8 skb_ext_type_len[] = {
 #if IS_ENABLED(CONFIG_MPTCP)
 	[SKB_EXT_MPTCP] = SKB_EXT_CHUNKSIZEOF(struct mptcp_ext),
 #endif
+#if IS_ENABLED(CONFIG_MCTP_FLOWS)
+	[SKB_EXT_MCTP] = SKB_EXT_CHUNKSIZEOF(struct mctp_flow),
+#endif
 };
 
 static __always_inline unsigned int skb_ext_total_length(void)
@@ -4446,6 +4450,9 @@ static __always_inline unsigned int skb_ext_total_length(void)
 #endif
 #if IS_ENABLED(CONFIG_MPTCP)
 		skb_ext_type_len[SKB_EXT_MPTCP] +
+#endif
+#if IS_ENABLED(CONFIG_MCTP_FLOWS)
+		skb_ext_type_len[SKB_EXT_MCTP] +
 #endif
 		0;
 }
@@ -6519,6 +6526,14 @@ static void skb_ext_put_sp(struct sec_path *sp)
 }
 #endif
 
+#ifdef CONFIG_MCTP_FLOWS
+static void skb_ext_put_mctp(struct mctp_flow *flow)
+{
+	if (flow->key)
+		mctp_key_unref(flow->key);
+}
+#endif
+
 void __skb_ext_del(struct sk_buff *skb, enum skb_ext_id id)
 {
 	struct skb_ext *ext = skb->extensions;
@@ -6554,6 +6569,10 @@ void __skb_ext_put(struct skb_ext *ext)
 	if (__skb_ext_exist(ext, SKB_EXT_SEC_PATH))
 		skb_ext_put_sp(skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH));
 #endif
+#ifdef CONFIG_MCTP_FLOWS
+	if (__skb_ext_exist(ext, SKB_EXT_MCTP))
+		skb_ext_put_mctp(skb_ext_get_ptr(ext, SKB_EXT_MCTP));
+#endif
 
 	kmem_cache_free(skbuff_ext_cache, ext);
 }
net/mctp/Kconfig +6 -1
index 868c92272cbd..3a5c0e70da77 100644
@@ -1,7 +1,7 @@
 
 menuconfig MCTP
 	depends on NET
-	tristate "MCTP core protocol support"
+	bool "MCTP core protocol support"
 	help
 	  Management Component Transport Protocol (MCTP) is an in-system
 	  protocol for communicating between management controllers and
@@ -16,3 +16,8 @@ config MCTP_TEST
         bool "MCTP core tests" if !KUNIT_ALL_TESTS
         depends on MCTP=y && KUNIT=y
         default KUNIT_ALL_TESTS
+
+config MCTP_FLOWS
+	bool
+	depends on MCTP
+	select SKB_EXTENSIONS
Signature · 1 line
2.33.0
author maintainer
#3 lore raw

PATCH v2 3/3 mctp: Pass flow data & flow release events to drivers

In reply to Jeremy Kerr

Now that we have an extension for MCTP data in skbs, populate the flow when a key has been created for the packet, and add a device driver operation to inform of flow destruction.

Includes a fix for a warning with test builds:

---
v2:
- forward-declare struct mctp_sk_key

---
 include/net/mctp.h       |  6 +++++
 include/net/mctpdevice.h | 16 ++++++++++++
 net/mctp/device.c        | 51 +++++++++++++++++++++++++++++++++++++
 net/mctp/route.c         | 55 ++++++++++++++++++++++++++++++++++++++--
 4 files changed, 126 insertions(+), 2 deletions(-)
include/net/mctp.h +6 -0
index 7a5ba801703c..7e35ec79b909 100644
@@ -152,6 +152,12 @@ struct mctp_sk_key {
 
 	/* expiry timeout; valid (above) cleared on expiry */
 	unsigned long	expiry;
+
+	/* free to use for device flow state tracking. Initialised to
+	 * zero on initial key creation
+	 */
+	unsigned long	dev_flow_state;
+	struct mctp_dev	*dev;
 };
 
 struct mctp_skb_cb {
include/net/mctpdevice.h +16 -0
index 3a439463f055..5c0d04b5c12c 100644
@@ -14,6 +14,8 @@
 #include <linux/types.h>
 #include <linux/refcount.h>
 
+struct mctp_sk_key;
+
 struct mctp_dev {
 	struct net_device	*dev;
 
@@ -21,6 +23,8 @@ struct mctp_dev {
 
 	unsigned int		net;
 
+	const struct mctp_netdev_ops *ops;
+
 	/* Only modified under RTNL. Reads have addrs_lock held */
 	u8			*addrs;
 	size_t			num_addrs;
@@ -29,12 +33,24 @@ struct mctp_dev {
 	struct rcu_head		rcu;
 };
 
+struct mctp_netdev_ops {
+	void			(*release_flow)(struct mctp_dev *dev,
+						struct mctp_sk_key *key);
+};
+
 #define MCTP_INITIAL_DEFAULT_NET	1
 
 struct mctp_dev *mctp_dev_get_rtnl(const struct net_device *dev);
 struct mctp_dev *__mctp_dev_get(const struct net_device *dev);
 
+int mctp_register_netdev(struct net_device *dev,
+			 const struct mctp_netdev_ops *ops);
+void mctp_unregister_netdev(struct net_device *dev);
+
 void mctp_dev_hold(struct mctp_dev *mdev);
 void mctp_dev_put(struct mctp_dev *mdev);
 
+void mctp_dev_set_key(struct mctp_dev *dev, struct mctp_sk_key *key);
+void mctp_dev_release_key(struct mctp_dev *dev, struct mctp_sk_key *key);
+
 #endif /* __NET_MCTPDEVICE_H */
net/mctp/device.c +51 -0

63 lines not on this page · raw message

net/mctp/route.c +53 -2

91 lines not on this page · raw message

Signature · 1 line
2.33.0
#4 lore raw
In reply to Jeremy Kerr
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 5 lines · On Fri, 29 Oct 2021 11:01:42 +0800 you wrote:

For certain MCTP transport bindings, the binding driver will need to be aware of request/response pairing. For example, the i2c binding may need to set multiplexer configuration when expecting a response from a device behind a mux.

Quoted 8 lines

This series implements a mechanism for informing the driver about these flows, so it can implement transport-specific behaviour when a flow is in progress (ie, a response is expected, and/or we time-out on that expectation). We use a skb extension to notify the driver about the presence of a flow, and a new dev->ops callback to notify about a flow's destruction.

[...]

Here is the summary with links:
- [net-next,v2,1/3] mctp: Return new key from mctp_alloc_local_tag

    https://git.kernel.org/netdev/net-next/c/212c10c3c658
  - [net-next,v2,2/3] mctp: Add flow extension to skb
    https://git.kernel.org/netdev/net-next/c/78476d315e19
  - [net-next,v2,3/3] mctp: Pass flow data & flow release events to drivers
    https://git.kernel.org/netdev/net-next/c/67737c457281

You are awesome, thank you!

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