Skip to content

Commit b4f029f

Browse files
committed
Merge branch 'MCTP-tag-control-interface'
Jeremy Kerr says: ==================== MCTP tag control interface This series implements a small interface for userspace-controlled message tag allocation for the MCTP protocol. Rather than leaving the kernel to allocate per-message tag values, userspace can explicitly allocate (and release) message tags through two new ioctls: SIOCMCTPALLOCTAG and SIOCMCTPDROPTAG. In order to do this, we first introduce some minor changes to the tag handling, including a couple of new tests for the route input paths. As always, any comments/queries/etc are most welcome. v2: - make mctp_lookup_prealloc_tag static - minor checkpatch formatting fixes ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents aa4725c + 63ed1aa commit b4f029f

File tree

7 files changed

+489
-68
lines changed

7 files changed

+489
-68
lines changed

Documentation/networking/mctp.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,54 @@ remote address is already known, or the message does not require a reply.
212212
Like the send calls, sockets will only receive responses to requests they have
213213
sent (TO=1) and may only respond (TO=0) to requests they have received.
214214

215+
``ioctl(SIOCMCTPALLOCTAG)`` and ``ioctl(SIOCMCTPDROPTAG)``
216+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
217+
218+
These tags give applications more control over MCTP message tags, by allocating
219+
(and dropping) tag values explicitly, rather than the kernel automatically
220+
allocating a per-message tag at ``sendmsg()`` time.
221+
222+
In general, you will only need to use these ioctls if your MCTP protocol does
223+
not fit the usual request/response model. For example, if you need to persist
224+
tags across multiple requests, or a request may generate more than one response.
225+
In these cases, the ioctls allow you to decouple the tag allocation (and
226+
release) from individual message send and receive operations.
227+
228+
Both ioctls are passed a pointer to a ``struct mctp_ioc_tag_ctl``:
229+
230+
.. code-block:: C
231+
232+
struct mctp_ioc_tag_ctl {
233+
mctp_eid_t peer_addr;
234+
__u8 tag;
235+
__u16 flags;
236+
};
237+
238+
``SIOCMCTPALLOCTAG`` allocates a tag for a specific peer, which an application
239+
can use in future ``sendmsg()`` calls. The application populates the
240+
``peer_addr`` member with the remote EID. Other fields must be zero.
241+
242+
On return, the ``tag`` member will be populated with the allocated tag value.
243+
The allocated tag will have the following tag bits set:
244+
245+
- ``MCTP_TAG_OWNER``: it only makes sense to allocate tags if you're the tag
246+
owner
247+
248+
- ``MCTP_TAG_PREALLOC``: to indicate to ``sendmsg()`` that this is a
249+
preallocated tag.
250+
251+
- ... and the actual tag value, within the least-significant three bits
252+
(``MCTP_TAG_MASK``). Note that zero is a valid tag value.
253+
254+
The tag value should be used as-is for the ``smctp_tag`` member of ``struct
255+
sockaddr_mctp``.
256+
257+
``SIOCMCTPDROPTAG`` releases a tag that has been previously allocated by a
258+
``SIOCMCTPALLOCTAG`` ioctl. The ``peer_addr`` must be the same as used for the
259+
allocation, and the ``tag`` value must match exactly the tag returned from the
260+
allocation (including the ``MCTP_TAG_OWNER`` and ``MCTP_TAG_PREALLOC`` bits).
261+
The ``flags`` field must be zero.
262+
215263
Kernel internals
216264
================
217265

include/net/mctp.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ static inline bool mctp_address_ok(mctp_eid_t eid)
4545
return eid >= 8 && eid < 255;
4646
}
4747

48+
static inline bool mctp_address_matches(mctp_eid_t match, mctp_eid_t eid)
49+
{
50+
return match == eid || match == MCTP_ADDR_ANY;
51+
}
52+
4853
static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
4954
{
5055
return (struct mctp_hdr *)skb_network_header(skb);
@@ -121,7 +126,7 @@ struct mctp_sock {
121126
*/
122127
struct mctp_sk_key {
123128
mctp_eid_t peer_addr;
124-
mctp_eid_t local_addr;
129+
mctp_eid_t local_addr; /* MCTP_ADDR_ANY for local owned tags */
125130
__u8 tag; /* incoming tag match; invert TO for local */
126131

127132
/* we hold a ref to sk when set */
@@ -158,6 +163,12 @@ struct mctp_sk_key {
158163
*/
159164
unsigned long dev_flow_state;
160165
struct mctp_dev *dev;
166+
167+
/* a tag allocated with SIOCMCTPALLOCTAG ioctl will not expire
168+
* automatically on timeout or response, instead SIOCMCTPDROPTAG
169+
* is used.
170+
*/
171+
bool manual_alloc;
161172
};
162173

163174
struct mctp_skb_cb {
@@ -234,6 +245,9 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
234245
struct sk_buff *skb, mctp_eid_t daddr, u8 req_tag);
235246

236247
void mctp_key_unref(struct mctp_sk_key *key);
248+
struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
249+
mctp_eid_t daddr, mctp_eid_t saddr,
250+
bool manual, u8 *tagp);
237251

238252
/* routing <--> device interface */
239253
unsigned int mctp_default_net(struct net *net);

include/trace/events/mctp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ enum {
1515
MCTP_TRACE_KEY_REPLIED,
1616
MCTP_TRACE_KEY_INVALIDATED,
1717
MCTP_TRACE_KEY_CLOSED,
18+
MCTP_TRACE_KEY_DROPPED,
1819
};
1920
#endif /* __TRACE_MCTP_ENUMS */
2021

2122
TRACE_DEFINE_ENUM(MCTP_TRACE_KEY_TIMEOUT);
2223
TRACE_DEFINE_ENUM(MCTP_TRACE_KEY_REPLIED);
2324
TRACE_DEFINE_ENUM(MCTP_TRACE_KEY_INVALIDATED);
2425
TRACE_DEFINE_ENUM(MCTP_TRACE_KEY_CLOSED);
26+
TRACE_DEFINE_ENUM(MCTP_TRACE_KEY_DROPPED);
2527

2628
TRACE_EVENT(mctp_key_acquire,
2729
TP_PROTO(const struct mctp_sk_key *key),
@@ -66,7 +68,8 @@ TRACE_EVENT(mctp_key_release,
6668
{ MCTP_TRACE_KEY_TIMEOUT, "timeout" },
6769
{ MCTP_TRACE_KEY_REPLIED, "replied" },
6870
{ MCTP_TRACE_KEY_INVALIDATED, "invalidated" },
69-
{ MCTP_TRACE_KEY_CLOSED, "closed" })
71+
{ MCTP_TRACE_KEY_CLOSED, "closed" },
72+
{ MCTP_TRACE_KEY_DROPPED, "dropped" })
7073
)
7174
);
7275

include/uapi/linux/mctp.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,25 @@ struct sockaddr_mctp_ext {
4444

4545
#define MCTP_TAG_MASK 0x07
4646
#define MCTP_TAG_OWNER 0x08
47+
#define MCTP_TAG_PREALLOC 0x10
4748

4849
#define MCTP_OPT_ADDR_EXT 1
4950

51+
#define SIOCMCTPALLOCTAG (SIOCPROTOPRIVATE + 0)
52+
#define SIOCMCTPDROPTAG (SIOCPROTOPRIVATE + 1)
53+
54+
struct mctp_ioc_tag_ctl {
55+
mctp_eid_t peer_addr;
56+
57+
/* For SIOCMCTPALLOCTAG: must be passed as zero, kernel will
58+
* populate with the allocated tag value. Returned tag value will
59+
* always have TO and PREALLOC set.
60+
*
61+
* For SIOCMCTPDROPTAG: userspace provides tag value to drop, from
62+
* a prior SIOCMCTPALLOCTAG call (and so must have TO and PREALLOC set).
63+
*/
64+
__u8 tag;
65+
__u16 flags;
66+
};
67+
5068
#endif /* __UAPI_MCTP_H */

0 commit comments

Comments
 (0)